source: Daodan/src/Daodan.c@ 446

Last change on this file since 446 was 445, checked in by rossy, 15 years ago

fixed sprintf

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