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