source: Daodan/src/Daodan.c@ 444

Last change on this file since 444 was 439, checked in by rossy, 15 years ago

Daodan_BSL

File size: 14.6 KB
Line 
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#include "Daodan_BSL.h"
10
11#include "Daodan_WindowHack.h"
12
13#include "Oni.h"
14#include "Oni_Persistence.h"
15
16#include "BFW_Utility.h"
17
18#include "oni_gl.h"
19#include "daodan_gl.h"
20
21#include "inifile.h"
22
23HMODULE DDrDLLModule;
24HMODULE DDrONiModule;
25
26bool patch_fonttexturecache = true;
27bool patch_largetextures = true;
28bool patch_levelplugins = true;
29bool patch_pathfinding = true;
30bool patch_projaware = true;
31bool patch_directinput = true;
32bool patch_wpfadetime = true;
33bool patch_kickguns = false;
34bool patch_cooldowntimer = true;
35bool patch_throwtest = false;
36bool patch_alttab = true;
37bool patch_particledisablebit = false;
38bool patch_multibyte = false;
39bool patch_cheattable = true;
40bool patch_argb8888 = true;
41
42bool patch_safeprintf = true;
43bool patch_daodandisplayenum = true;
44bool patch_usegettickcount = true;
45bool patch_cheatsenabled = true;
46bool patch_usedaodangl = false;
47bool patch_windowhack = true;
48bool patch_daodaninit = true;
49
50bool opt_usedaodanbsl = true;
51
52bool DDrPatch_Init()
53{
54 DDrStartupMessage("patching engine");
55
56 // Font texture cache doubled
57 if (patch_fonttexturecache)
58 {
59 DDrPatch_Byte (OniExe + 0x00020ea7, 0x20);
60 DDrPatch_Byte (OniExe + 0x00020f4a, 0x40);
61 }
62
63 // Now supports textures up to 512x512
64 if (patch_largetextures)
65 DDrPatch_Byte (OniExe + 0x00005251, 0x10);
66
67 // Non-"_Final" levels are now valid
68 if (patch_levelplugins)
69 DDrPatch_Byte (OniExe + 0x000206a8, 0x01);
70
71 // Pathfinding grid cache size x8
72 if (patch_pathfinding)
73 {
74 DDrPatch_Byte (OniExe + 0x0010b03b, 0x20);
75 DDrPatch_Byte (OniExe + 0x0010b04c, 0x20);
76 }
77
78 // Projectile awareness fixed
79 if (patch_projaware)
80 {
81 DDrPatch_Byte (OniExe + 0x0009c07c, 0x6c);
82 DDrPatch_Byte (OniExe + 0x0009c080, 0x70);
83 DDrPatch_Byte (OniExe + 0x0009c084, 0x74);
84 DDrPatch_Byte (OniExe + 0x0009c110, 0x6c);
85 }
86
87 // Forced DirectInput (for Windows NT)
88 if (patch_directinput)
89 DDrPatch_Byte (OniExe + 0x00002e6d, 0xeb);
90
91 if (patch_wpfadetime)
92 {
93 // Makes wp_fadetime actually have a function
94 const char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 };
95 DDrPatch_Const (OniExe + 0x0011a889, fadetime_patch);
96 DDrPatch_Byte (OniExe + 0x0011a560, 0x31);
97
98 // Sets the fadetime to 4800 by default
99 DDrPatch_Int16 (OniExe + 0x0011ab0e, 0x12c0);
100 }
101
102
103 // Hackish fix for Konoko not kicking guns
104 if (patch_kickguns)
105 {
106 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 };
107 DDrPatch_Const (OniExe + 0x000dc420, kickgun_patch);
108 }
109
110 // Cooldown timer exploit fix ^_^
111 if (patch_cooldowntimer)
112 {
113 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 };
114 DDrPatch_Const (OniExe + 0x0011a825, cooldown_patch);
115 }
116
117 if (patch_throwtest)
118 {
119 const char throwtest_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 };
120 DDrPatch_Const(OniExe + 0x000dc190, throwtest_patch);
121 }
122
123 // 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.
124 if (patch_alttab)
125 {
126 DDrPatch_Byte ((void*)UUrPlatform_Initialize, 0xC3);
127 DDrPatch_Byte ((void*)UUrPlatform_Terminate, 0xC3);
128 }
129
130 // 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.)
131 if (patch_particledisablebit)
132 DDrPatch_Int16 (OniExe + 0x001b184, 0x9090);
133
134 // Multi-byte patch (multiple language support)
135 if (!patch_multibyte)
136 {
137 DDrPatch_Byte (OniExe + 0x0002d8f8, 0xeb);
138 DDrPatch_Byte (OniExe + 0x0002d9ad, 0xeb);
139 DDrPatch_Byte (OniExe + 0x0002dbe2, 0xeb);
140 DDrPatch_Byte (OniExe + 0x0002dec3, 0xeb);
141 DDrPatch_Byte (OniExe + 0x0002e2ab, 0xeb);
142 DDrPatch_Byte (OniExe + 0x0002e2c4, 0xeb);
143 DDrPatch_Byte (OniExe + 0x0002e379, 0xeb);
144 DDrPatch_Byte (OniExe + 0x0002e48c, 0xeb);
145 DDrPatch_Byte (OniExe + 0x0002e4d0, 0xeb);
146 DDrPatch_Byte (OniExe + 0x0002e4f4, 0xeb);
147 DDrPatch_Byte (OniExe + 0x0002e646, 0xeb);
148 DDrPatch_Byte (OniExe + 0x0002e695, 0xeb);
149 DDrPatch_Byte (OniExe + 0x0002e944, 0xeb);
150 DDrPatch_Byte (OniExe + 0x0002e95d, 0xeb);
151 DDrPatch_Byte (OniExe + 0x0002e98e, 0xeb);
152 DDrPatch_Byte (OniExe + 0x0002e9dc, 0xeb);
153 }
154
155 // Cheat table patch
156 if (patch_cheattable)
157 {
158 DDrPatch_Int32 (OniExe + 0x000f616b, (int)&DDr_CheatTable[0].name);
159 DDrPatch_Int32 (OniExe + 0x000f617a, (int)&DDr_CheatTable[0].message_on);
160 }
161
162 if (patch_argb8888)
163 {
164 DDrPatch_Byte (OniExe + 0x00135af0, 0x07);
165 DDrPatch_Byte (OniExe + 0x00135af4, 0x0B);
166 }
167
168 return true;
169}
170
171enum {s_unknown, s_options, s_patch, s_language} ini_section;
172
173bool DDrIniCallback(char* section, bool newsection, char* name, char* value)
174{
175 if (newsection)
176 {
177 if (!stricmp(section, "options"))
178 ini_section = s_options;
179 else if (!stricmp(section, "patch"))
180 ini_section = s_patch;
181 else if (!stricmp(section, "language"))
182 ini_section = s_language;
183 else
184 {
185 ini_section = s_unknown;
186 DDrStartupMessage("unrecognised ini section \"%s\"", section);
187 }
188 }
189
190 switch (ini_section)
191 {
192 case s_options:
193 if (!stricmp(name, "usedaodanbsl"))
194 opt_usedaodanbsl = !stricmp(value, "true");
195 break;
196 case s_patch:
197 if (!stricmp(name, "fonttexturecache"))
198 patch_fonttexturecache = !stricmp(value, "true");
199 else if (!stricmp(name, "largetextures"))
200 patch_largetextures = !stricmp(value, "true");
201 else if (!stricmp(name, "levelplugins"))
202 patch_levelplugins = !stricmp(value, "true");
203 else if (!stricmp(name, "pathfinding"))
204 patch_pathfinding = !stricmp(value, "true");
205 else if (!stricmp(name, "projaware"))
206 patch_projaware = !stricmp(value, "true");
207 else if (!stricmp(name, "directinput"))
208 patch_directinput = !stricmp(value, "true");
209 else if (!stricmp(name, "wpfadetime"))
210 patch_wpfadetime = !stricmp(value, "true");
211 else if (!stricmp(name, "kickguns"))
212 patch_kickguns = !stricmp(value, "true");
213 else if (!stricmp(name, "cooldowntimer"))
214 patch_cooldowntimer = !stricmp(value, "true");
215 else if (!stricmp(name, "throwtest"))
216 patch_throwtest = !stricmp(value, "true");
217 else if (!stricmp(name, "alttab"))
218 patch_alttab = !stricmp(value, "true");
219 else if (!stricmp(name, "particledisablebit"))
220 patch_particledisablebit = !stricmp(value, "true");
221 else if (!stricmp(name, "multibyte"))
222 patch_multibyte = !stricmp(value, "true");
223 else if (!stricmp(name, "cheattable"))
224 patch_cheattable = !stricmp(value, "true");
225 else if (!stricmp(name, "argb8888"))
226 patch_argb8888 = !stricmp(value, "true");
227 else if (!stricmp(name, "safeprintf"))
228 patch_safeprintf = !stricmp(value, "true");
229 else if (!stricmp(name, "daodandisplayenum"))
230 patch_daodandisplayenum = !stricmp(value, "true");
231 else if (!stricmp(name, "usegettickcount"))
232 patch_usegettickcount = !stricmp(value, "true");
233 else if (!stricmp(name, "cheatsenabled"))
234 patch_cheatsenabled = !stricmp(value, "true");
235 else if (!stricmp(name, "usedaodangl"))
236 patch_usedaodangl = !stricmp(value, "true");
237 else if (!stricmp(name, "windowhack"))
238 patch_windowhack = !stricmp(value, "true");
239 else if (!stricmp(name, "daodaninit"))
240 patch_daodaninit = !stricmp(value, "true");
241 else
242 DDrStartupMessage("unrecognised patch \"%s\"", name);
243 break;
244 case s_language:
245 if (!stricmp(name, "savepoint"))
246 {
247 char* str = strdup(value);
248 DDrPatch_Int32(OniExe + 0x000fd730, (int)str);
249 DDrPatch_Int32(OniExe + 0x000fd738, (int)str);
250 }
251 else if (!stricmp(name, "syndicatewarehouse"))
252 {
253 char* str = strdup(value);
254 DDrPatch_Int32(OniExe + 0x000fd71a, (int)str);
255 DDrPatch_Int32(OniExe + 0x0010ef75, (int)str);
256 }
257 else if (!stricmp(name, "damn"))
258 DDrPatch_StrDup(OniExe + 0x0010fb6e, value);
259 else if (!stricmp(name, "blam"))
260 DDrPatch_StrDup(OniExe + 0x0010fb73, value);
261 else if (!stricmp(name, "shapeshifter_on"))
262 DDr_CheatTable[0].message_on = strdup(value);
263 else if (!stricmp(name, "shapeshifter_off"))
264 DDr_CheatTable[0].message_off = strdup(value);
265 else if (!stricmp(name, "liveforever_on"))
266 DDr_CheatTable[1].message_on = strdup(value);
267 else if (!stricmp(name, "liveforever_off"))
268 DDr_CheatTable[1].message_off = strdup(value);
269 else if (!stricmp(name, "touchofdeath_on"))
270 DDr_CheatTable[2].message_on = strdup(value);
271 else if (!stricmp(name, "touchofdeath_off"))
272 DDr_CheatTable[2].message_off = strdup(value);
273 else if (!stricmp(name, "canttouchthis_on"))
274 DDr_CheatTable[3].message_on = strdup(value);
275 else if (!stricmp(name, "canttouchthis_off"))
276 DDr_CheatTable[3].message_off = strdup(value);
277 else if (!stricmp(name, "fatloot_on"))
278 DDr_CheatTable[4].message_on = strdup(value);
279 else if (!stricmp(name, "glassworld_on"))
280 DDr_CheatTable[5].message_on = strdup(value);
281 else if (!stricmp(name, "glassworld_off"))
282 DDr_CheatTable[5].message_off = strdup(value);
283 else if (!stricmp(name, "winlevel_on"))
284 DDr_CheatTable[6].message_on = strdup(value);
285 else if (!stricmp(name, "loselevel_on"))
286 DDr_CheatTable[7].message_on = strdup(value);
287 else if (!stricmp(name, "bighead_on"))
288 DDr_CheatTable[8].message_on = strdup(value);
289 else if (!stricmp(name, "bighead_off"))
290 DDr_CheatTable[8].message_off = strdup(value);
291 else if (!stricmp(name, "minime_on"))
292 DDr_CheatTable[9].message_on = strdup(value);
293 else if (!stricmp(name, "minime_off"))
294 DDr_CheatTable[9].message_off = strdup(value);
295 else if (!stricmp(name, "superammo_on"))
296 DDr_CheatTable[10].message_on = strdup(value);
297 else if (!stricmp(name, "superammo_off"))
298 DDr_CheatTable[10].message_off = strdup(value);
299 else if (!stricmp(name, "devmode_on"))
300 {
301 char* str = strdup(value);
302 DDr_CheatTable[11].message_on = str;
303 DDr_CheatTable[cheat_devmodex].message_on = str;
304 }
305 else if (!stricmp(name, "devmode_off"))
306 {
307 char* str = strdup(value);
308 DDr_CheatTable[11].message_off = str;
309 DDr_CheatTable[cheat_devmodex].message_off = str;
310 }
311 else if (!stricmp(name, "reservoirdogs_on"))
312 DDr_CheatTable[12].message_on = strdup(value);
313 else if (!stricmp(name, "reservoirdogs_off"))
314 DDr_CheatTable[12].message_off = strdup(value);
315 else if (!stricmp(name, "roughjustice_on"))
316 DDr_CheatTable[13].message_on = strdup(value);
317 else if (!stricmp(name, "roughjustice_off"))
318 DDr_CheatTable[13].message_off = strdup(value);
319 else if (!stricmp(name, "chenille_on"))
320 DDr_CheatTable[14].message_on = strdup(value);
321 else if (!stricmp(name, "chenille_off"))
322 DDr_CheatTable[14].message_off = strdup(value);
323 else if (!stricmp(name, "behemoth_on"))
324 DDr_CheatTable[15].message_on = strdup(value);
325 else if (!stricmp(name, "behemoth_off"))
326 DDr_CheatTable[15].message_off = strdup(value);
327 else if (!stricmp(name, "elderrune_on"))
328 DDr_CheatTable[16].message_on = strdup(value);
329 else if (!stricmp(name, "elderrune_off"))
330 DDr_CheatTable[16].message_off = strdup(value);
331 else if (!stricmp(name, "moonshadow_on"))
332 DDr_CheatTable[17].message_on = strdup(value);
333 else if (!stricmp(name, "moonshadow_off"))
334 DDr_CheatTable[17].message_off = strdup(value);
335 else if (!stricmp(name, "munitionfrenzy_on"))
336 DDr_CheatTable[18].message_on = strdup(value);
337 else if (!stricmp(name, "fistsoflegend_on"))
338 DDr_CheatTable[19].message_on = strdup(value);
339 else if (!stricmp(name, "fistsoflegend_off"))
340 DDr_CheatTable[19].message_off = strdup(value);
341 else if (!stricmp(name, "killmequick_on"))
342 DDr_CheatTable[20].message_on = strdup(value);
343 else if (!stricmp(name, "killmequick_off"))
344 DDr_CheatTable[20].message_off = strdup(value);
345 else if (!stricmp(name, "carousel_on"))
346 DDr_CheatTable[21].message_on = strdup(value);
347 else if (!stricmp(name, "carousel_off"))
348 DDr_CheatTable[21].message_off = strdup(value);
349 else
350 DDrStartupMessage("unrecognised language item \"%s\"", name);
351 break;
352 default:
353 break;
354 }
355
356 return true;
357}
358
359void DDrConfig()
360{
361 if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES)
362 {
363 DDrStartupMessage("daodan.ini doesn't exist, creating");
364 FILE* fp = fopen("daodan.ini", "w");
365 if (fp)
366 {
367 fputs("[Options]\n", fp);
368 fclose(fp);
369 }
370 }
371
372 DDrStartupMessage("parsing daodan.ini...");
373 if (!inifile_read("daodan.ini", DDrIniCallback))
374 DDrStartupMessage("error reading daodan.ini, check your syntax!");
375 DDrStartupMessage("finished parsing");
376}
377
378void ONICALL DDrGame_Init()
379{
380 if (opt_usedaodanbsl)
381 SLrDaodan_Initalize();
382}
383
384void __cdecl DDrMain(int argc, char* argv[])
385{
386 DDrStartupMessage("daodan attached!");
387 DDrConfig();
388 DDrPatch_Init();
389
390 // Safe startup message printer
391 if (patch_safeprintf)
392 DDrPatch_MakeJump(UUrStartupMessage, DDrStartupMessage);
393
394 // Daodan device mode enumeration function
395 if (patch_daodandisplayenum)
396 DDrPatch_MakeJump(gl_enumerate_valid_display_modes, daodan_enumerate_valid_display_modes);
397
398 // Performance patch
399 if (patch_usegettickcount)
400 {
401 DDrPatch_MakeJump(UUrMachineTime_High, DDrMachineTime_High);
402 DDrPatch_MakeJump(UUrMachineTime_High_Frequency, DDrMachineTime_High_Frequency);
403 DDrPatch_MakeJump(UUrMachineTime_Sixtieths, DDrMachineTime_Sixtieths);
404 }
405
406 // Cheats always enabled
407 if (patch_cheatsenabled)
408 DDrPatch_MakeJump(ONrPersist_GetWonGame, DDrPersist_GetWonGame);
409
410 // Windowed mode
411 if (patch_usedaodangl)
412 {
413 DDrPatch_MakeJump(ONrPlatform_Initialize, DDrPlatform_Initialize);
414 DDrPatch_MakeJump(gl_platform_initialize, daodangl_platform_initialize);
415 }
416
417 // Hacked windowed mode (for when daodangl isn't working properly)
418 if (patch_windowhack)
419 DDrWindowHack_Install();
420
421 if (patch_daodaninit)
422 DDrPatch_MakeCall(OniExe + 0x000d345a, DDrGame_Init);
423
424 init_daodan_gl();
425
426 ONiMain(argc, argv);
427}
428
429BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
430{
431 switch (fdwReason)
432 {
433 case DLL_PROCESS_ATTACH:
434 DDrDLLModule = hinstDLL;
435 DDrONiModule = GetModuleHandle(NULL);
436
437 DDrPatch_MakeCall(OniExe + 0x0010fb49, DDrMain);
438
439 break;
440 }
441 return TRUE;
442}
Note: See TracBrowser for help on using the repository browser.