| 1 | #include <string.h>
|
|---|
| 2 |
|
|---|
| 3 | #include "Daodan.h"
|
|---|
| 4 | #include "Daodan_Patch.h"
|
|---|
| 5 | #include "Daodan_Utility.h"
|
|---|
| 6 | #include "Daodan_Win32.h"
|
|---|
| 7 | #include "Daodan_Cheater.h"
|
|---|
| 8 | #include "Daodan_Persistence.h"
|
|---|
| 9 |
|
|---|
| 10 | #include "Oni.h"
|
|---|
| 11 | #include "Oni_Persistence.h"
|
|---|
| 12 |
|
|---|
| 13 | #include "BFW_Utility.h"
|
|---|
| 14 |
|
|---|
| 15 | #include "oni_gl.h"
|
|---|
| 16 | #include "daodan_gl.h"
|
|---|
| 17 |
|
|---|
| 18 | #include "inifile.h"
|
|---|
| 19 |
|
|---|
| 20 | HMODULE DDrDLLModule;
|
|---|
| 21 | HMODULE DDrONiModule;
|
|---|
| 22 |
|
|---|
| 23 | bool patch_fonttexturecache = true;
|
|---|
| 24 | bool patch_largetextures = true;
|
|---|
| 25 | bool patch_pathfinding = true;
|
|---|
| 26 | bool patch_projaware = true;
|
|---|
| 27 | bool patch_wpfadetime = true;
|
|---|
| 28 | bool patch_kickguns = false;
|
|---|
| 29 | bool patch_cooldowntimer = true;
|
|---|
| 30 | bool patch_throwtest = false;
|
|---|
| 31 | bool patch_alttab = true;
|
|---|
| 32 | bool patch_particledisablebit = false;
|
|---|
| 33 | bool patch_multibyte = true;
|
|---|
| 34 | bool patch_cheattable = true;
|
|---|
| 35 |
|
|---|
| 36 | bool patch_safeprintf = true;
|
|---|
| 37 | bool patch_daodandisplayenum = true;
|
|---|
| 38 | bool patch_usegettickcount = true;
|
|---|
| 39 | bool patch_usedaodangl = false;
|
|---|
| 40 |
|
|---|
| 41 | bool DDrPatch_Init()
|
|---|
| 42 | {
|
|---|
| 43 | DDrStartupMessage("patching engine");
|
|---|
| 44 |
|
|---|
| 45 | // Font texture cache doubled
|
|---|
| 46 | if (patch_fonttexturecache)
|
|---|
| 47 | {
|
|---|
| 48 | DDrPatch_Byte (OniExe + 0x00020ea7, 0x20);
|
|---|
| 49 | DDrPatch_Byte (OniExe + 0x00020f4a, 0x40);
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | // Now supports textures up to 512x512
|
|---|
| 53 | if (patch_largetextures)
|
|---|
| 54 | DDrPatch_Byte (OniExe + 0x00005251, 0x10);
|
|---|
| 55 |
|
|---|
| 56 | // Non-"_Final" levels are now valid
|
|---|
| 57 | DDrPatch_Byte (OniExe + 0x000206a8, 0x01);
|
|---|
| 58 |
|
|---|
| 59 | // Pathfinding grid cache size x8
|
|---|
| 60 | if (patch_pathfinding)
|
|---|
| 61 | {
|
|---|
| 62 | DDrPatch_Byte (OniExe + 0x0010b03b, 0x20);
|
|---|
| 63 | DDrPatch_Byte (OniExe + 0x0010b04c, 0x20);
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | // Projectile awareness fixed
|
|---|
| 67 | if (patch_projaware)
|
|---|
| 68 | {
|
|---|
| 69 | DDrPatch_Byte (OniExe + 0x0009c07c, 0x6c);
|
|---|
| 70 | DDrPatch_Byte (OniExe + 0x0009c080, 0x70);
|
|---|
| 71 | DDrPatch_Byte (OniExe + 0x0009c084, 0x74);
|
|---|
| 72 | DDrPatch_Byte (OniExe + 0x0009c110, 0x6c);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | // Forced DirectInput (for Windows NT)
|
|---|
| 76 | DDrPatch_Byte (OniExe + 0x00002e6d, 0xeb);
|
|---|
| 77 |
|
|---|
| 78 | if (patch_wpfadetime)
|
|---|
| 79 | {
|
|---|
| 80 | // Makes wp_fadetime actually have a function
|
|---|
| 81 | const char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 };
|
|---|
| 82 | DDrPatch_Const (OniExe + 0x0011a889, fadetime_patch);
|
|---|
| 83 | DDrPatch_Byte (OniExe + 0x0011a560, 0x31);
|
|---|
| 84 |
|
|---|
| 85 | // Sets the fadetime to 4800 by default
|
|---|
| 86 | DDrPatch_Int16 (OniExe + 0x0011ab0e, 0x12c0);
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 | // Hackish fix for Konoko not kicking guns
|
|---|
| 91 | if (patch_kickguns)
|
|---|
| 92 | {
|
|---|
| 93 | const char kickgun_patch[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0xC7, 0x05, 0x1C, 0xC9, 0x5E, 0x00, 0x70, 0xB8, 0x43, 0x00, 0xC7, 0x05, 0x20, 0xC9, 0x5E, 0x00, 0x20, 0xBE, 0x43 };
|
|---|
| 94 | DDrPatch_Const (OniExe + 0x000dc420, kickgun_patch);
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | // Cooldown timer exploit fix ^_^
|
|---|
| 98 | if (patch_cooldowntimer)
|
|---|
| 99 | {
|
|---|
| 100 | const char cooldown_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 };
|
|---|
| 101 | DDrPatch_Const (OniExe + 0x0011a825, cooldown_patch);
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | if (patch_throwtest)
|
|---|
| 105 | {
|
|---|
| 106 | const char throwtest_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 };
|
|---|
| 107 | DDrPatch_Const(OniExe + 0x000dc190, throwtest_patch);
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | // Disable UUrPlatform_Initalize/Terminate, this enables the Alt-Tab and the Windows key but has the possible side effect of allowing the screensaver to enable itself in-game.
|
|---|
| 111 | if (patch_alttab)
|
|---|
| 112 | {
|
|---|
| 113 | DDrPatch_Byte ((void*)UUrPlatform_Initialize, 0xC3);
|
|---|
| 114 | DDrPatch_Byte ((void*)UUrPlatform_Terminate, 0xC3);
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | // Unlocks particle action disabling/enabling bits for all events. (Will be controlled by a command line switch when I figure out how to do that without Win32 hacks.)
|
|---|
| 118 | if (patch_particledisablebit)
|
|---|
| 119 | DDrPatch_Int16 (OniExe + 0x001b184, 0x9090);
|
|---|
| 120 |
|
|---|
| 121 | // Multi-byte patch (multiple language support)
|
|---|
| 122 | if (patch_multibyte)
|
|---|
| 123 | {
|
|---|
| 124 | DDrPatch_Byte (OniExe + 0x0002d8f8, 0xeb);
|
|---|
| 125 | DDrPatch_Byte (OniExe + 0x0002d9ad, 0xeb);
|
|---|
| 126 | DDrPatch_Byte (OniExe + 0x0002dbe2, 0xeb);
|
|---|
| 127 | DDrPatch_Byte (OniExe + 0x0002dec3, 0xeb);
|
|---|
| 128 | DDrPatch_Byte (OniExe + 0x0002e2ab, 0xeb);
|
|---|
| 129 | DDrPatch_Byte (OniExe + 0x0002e2c4, 0xeb);
|
|---|
| 130 | DDrPatch_Byte (OniExe + 0x0002e379, 0xeb);
|
|---|
| 131 | DDrPatch_Byte (OniExe + 0x0002e48c, 0xeb);
|
|---|
| 132 | DDrPatch_Byte (OniExe + 0x0002e4d0, 0xeb);
|
|---|
| 133 | DDrPatch_Byte (OniExe + 0x0002e4f4, 0xeb);
|
|---|
| 134 | DDrPatch_Byte (OniExe + 0x0002e646, 0xeb);
|
|---|
| 135 | DDrPatch_Byte (OniExe + 0x0002e695, 0xeb);
|
|---|
| 136 | DDrPatch_Byte (OniExe + 0x0002e944, 0xeb);
|
|---|
| 137 | DDrPatch_Byte (OniExe + 0x0002e95d, 0xeb);
|
|---|
| 138 | DDrPatch_Byte (OniExe + 0x0002e98e, 0xeb);
|
|---|
| 139 | DDrPatch_Byte (OniExe + 0x0002e9dc, 0xeb);
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | // Cheat table patch
|
|---|
| 143 | if (patch_cheattable)
|
|---|
| 144 | {
|
|---|
| 145 | DDrPatch_Int32 (OniExe + 0x000f616b, (int)&DDr_CheatTable[0].name);
|
|---|
| 146 | DDrPatch_Int32 (OniExe + 0x000f617a, (int)&DDr_CheatTable[0].message_on);
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | return true;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | enum {s_unknown, s_patch, s_language} ini_section;
|
|---|
| 153 |
|
|---|
| 154 | bool DDrIniCallback(char* section, bool newsection, char* name, char* value)
|
|---|
| 155 | {
|
|---|
| 156 | if (newsection)
|
|---|
| 157 | {
|
|---|
| 158 | if (!stricmp(section, "patch"))
|
|---|
| 159 | ini_section = s_patch;
|
|---|
| 160 | else if (!stricmp(section, "language"))
|
|---|
| 161 | ini_section = s_language;
|
|---|
| 162 | else
|
|---|
| 163 | {
|
|---|
| 164 | ini_section = s_unknown;
|
|---|
| 165 | DDrStartupMessage("unrecognised ini section \"%s\"", section);
|
|---|
| 166 | }
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | switch (ini_section)
|
|---|
| 170 | {
|
|---|
| 171 | case s_patch:
|
|---|
| 172 | if (!stricmp(name, "fonttexturecache"))
|
|---|
| 173 | patch_fonttexturecache = !stricmp(value, "true");
|
|---|
| 174 | else if (!stricmp(name, "largetextures"))
|
|---|
| 175 | patch_largetextures = !stricmp(value, "true");
|
|---|
| 176 | else if (!stricmp(name, "pathfinding"))
|
|---|
| 177 | patch_pathfinding = !stricmp(value, "true");
|
|---|
| 178 | else if (!stricmp(name, "projaware"))
|
|---|
| 179 | patch_projaware = !stricmp(value, "true");
|
|---|
| 180 | else if (!stricmp(name, "wpfadetime"))
|
|---|
| 181 | patch_wpfadetime = !stricmp(value, "true");
|
|---|
| 182 | else if (!stricmp(name, "kickguns"))
|
|---|
| 183 | patch_kickguns = !stricmp(value, "true");
|
|---|
| 184 | else if (!stricmp(name, "cooldowntimer"))
|
|---|
| 185 | patch_cooldowntimer = !stricmp(value, "true");
|
|---|
| 186 | else if (!stricmp(name, "throwtest"))
|
|---|
| 187 | patch_throwtest = !stricmp(value, "true");
|
|---|
| 188 | else if (!stricmp(name, "alttab"))
|
|---|
| 189 | patch_alttab = !stricmp(value, "true");
|
|---|
| 190 | else if (!stricmp(name, "particledisablebit"))
|
|---|
| 191 | patch_particledisablebit = !stricmp(value, "true");
|
|---|
| 192 | else if (!stricmp(name, "multibyte"))
|
|---|
| 193 | patch_multibyte = !stricmp(value, "true");
|
|---|
| 194 | else if (!stricmp(name, "cheattable"))
|
|---|
| 195 | patch_cheattable = !stricmp(value, "true");
|
|---|
| 196 | else if (!stricmp(name, "safeprintf"))
|
|---|
| 197 | patch_safeprintf = !stricmp(value, "true");
|
|---|
| 198 | else if (!stricmp(name, "daodandisplayenum"))
|
|---|
| 199 | patch_daodandisplayenum = !stricmp(value, "true");
|
|---|
| 200 | else if (!stricmp(name, "usegettickcount"))
|
|---|
| 201 | patch_usegettickcount = !stricmp(value, "true");
|
|---|
| 202 | else if (!stricmp(name, "usedaodangl"))
|
|---|
| 203 | patch_usedaodangl = !stricmp(value, "true");
|
|---|
| 204 | else
|
|---|
| 205 | DDrStartupMessage("unrecognised patch \"%s\"", name);
|
|---|
| 206 | break;
|
|---|
| 207 | case s_language:
|
|---|
| 208 | if (!stricmp(name, "savepoint"))
|
|---|
| 209 | {
|
|---|
| 210 | char* str = strdup(value);
|
|---|
| 211 | DDrPatch_Int32(OniExe + 0x000fd730, (int)str);
|
|---|
| 212 | DDrPatch_Int32(OniExe + 0x000fd738, (int)str);
|
|---|
| 213 | }
|
|---|
| 214 | else if (!stricmp(name, "syndicatewarehouse"))
|
|---|
| 215 | {
|
|---|
| 216 | char* str = strdup(value);
|
|---|
| 217 | DDrPatch_Int32(OniExe + 0x000fd71a, (int)str);
|
|---|
| 218 | DDrPatch_Int32(OniExe + 0x0010ef75, (int)str);
|
|---|
| 219 | }
|
|---|
| 220 | else if (!stricmp(name, "damn"))
|
|---|
| 221 | DDrPatch_StrDup(OniExe + 0x0010fb6e, value);
|
|---|
| 222 | else if (!stricmp(name, "blam"))
|
|---|
| 223 | DDrPatch_StrDup(OniExe + 0x0010fb73, value);
|
|---|
| 224 | else
|
|---|
| 225 | DDrStartupMessage("unrecognised language item \"%s\"", name);
|
|---|
| 226 | break;
|
|---|
| 227 | default:
|
|---|
| 228 | break;
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | return true;
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | void DDrConfig()
|
|---|
| 235 | {
|
|---|
| 236 | if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES)
|
|---|
| 237 | {
|
|---|
| 238 | DDrStartupMessage("daodan.ini doesn't exist, creating");
|
|---|
| 239 | FILE* fp = fopen("daodan.ini", "w");
|
|---|
| 240 | if (fp)
|
|---|
| 241 | {
|
|---|
| 242 | fputs("[Options]\n", fp);
|
|---|
| 243 | fclose(fp);
|
|---|
| 244 | }
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | DDrStartupMessage("parsing daodan.ini...");
|
|---|
| 248 | if (!inifile_read("daodan.ini", DDrIniCallback))
|
|---|
| 249 | DDrStartupMessage("error reading daodan.ini, check your syntax!");
|
|---|
| 250 | DDrStartupMessage("finished parsing");
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | void __cdecl DDrMain(int argc, char* argv[])
|
|---|
| 254 | {
|
|---|
| 255 | DDrStartupMessage("daodan attached!");
|
|---|
| 256 | DDrConfig();
|
|---|
| 257 | DDrPatch_Init();
|
|---|
| 258 |
|
|---|
| 259 | // Safe startup message printer
|
|---|
| 260 | if (patch_safeprintf)
|
|---|
| 261 | DDrPatch_MakeJump(UUrStartupMessage, DDrStartupMessage);
|
|---|
| 262 |
|
|---|
| 263 | // Daodan device mode enumeration function
|
|---|
| 264 | if (patch_daodandisplayenum)
|
|---|
| 265 | DDrPatch_MakeJump(gl_enumerate_valid_display_modes, daodan_enumerate_valid_display_modes);
|
|---|
| 266 |
|
|---|
| 267 | // Performance patch
|
|---|
| 268 | if (patch_usegettickcount)
|
|---|
| 269 | {
|
|---|
| 270 | DDrPatch_MakeJump(UUrMachineTime_High, DDrMachineTime_High);
|
|---|
| 271 | DDrPatch_MakeJump(UUrMachineTime_High_Frequency, DDrMachineTime_High_Frequency);
|
|---|
| 272 | DDrPatch_MakeJump(UUrMachineTime_Sixtieths, DDrMachineTime_Sixtieths);
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | // Cheats always enabled
|
|---|
| 276 | DDrPatch_MakeJump(ONrPersist_GetWonGame, DDrPersist_GetWonGame);
|
|---|
| 277 |
|
|---|
| 278 | // Windowed mode
|
|---|
| 279 | if (patch_usedaodangl)
|
|---|
| 280 | {
|
|---|
| 281 | DDrPatch_MakeJump(ONrPlatform_Initialize, DDrPlatform_Initialize);
|
|---|
| 282 | DDrPatch_MakeJump(gl_platform_initialize, daodangl_platform_initialize);
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | init_daodan_gl();
|
|---|
| 286 |
|
|---|
| 287 | ONiMain(argc, argv);
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
|
|---|
| 291 | {
|
|---|
| 292 | switch (fdwReason)
|
|---|
| 293 | {
|
|---|
| 294 | case DLL_PROCESS_ATTACH:
|
|---|
| 295 | DDrDLLModule = hinstDLL;
|
|---|
| 296 | DDrONiModule = GetModuleHandle(NULL);
|
|---|
| 297 |
|
|---|
| 298 | DDrPatch_MakeCall(OniExe + 0x0010fb49, DDrMain);
|
|---|
| 299 |
|
|---|
| 300 | break;
|
|---|
| 301 | }
|
|---|
| 302 | return TRUE;
|
|---|
| 303 | }
|
|---|