source: Daodan/MSVC/Daodan.c@ 569

Last change on this file since 569 was 569, checked in by gumby, 15 years ago

Fixes, fixes, everywhere

File size: 22.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#include "Daodan_Console.h"
11
12#include "Daodan_WindowHack.h"
13
14#include "Oni.h"
15#include "Oni_Persistence.h"
16
17#include "BFW_Utility.h"
18
19#include "oni_gl.h"
20#include "daodan_gl.h"
21
22#include "inifile.h"
23
24HMODULE DDrDLLModule;
25HMODULE DDrONiModule;
26
27bool patch_fonttexturecache = true;
28bool patch_largetextures = true;
29bool patch_levelplugins = true;
30bool patch_pathfinding = true;
31bool patch_projaware = true;
32bool patch_directinput = true;
33bool patch_wpfadetime = true;
34bool patch_kickguns = false;
35bool patch_cooldowntimer = true;
36bool patch_throwtest = false;
37bool patch_alttab = true;
38bool patch_particledisablebit = false;
39bool patch_multibyte = false;
40bool patch_cheattable = true;
41bool patch_argb8888 = true;
42bool patch_killvtune = true;
43bool patch_getcmdline = true;
44bool patch_disablecmdline = true;
45
46bool patch_safeprintf = true;
47bool patch_daodandisplayenum = true;
48bool patch_usegettickcount = true;
49bool patch_cheatsenabled = true;
50bool patch_usedaodangl = true;
51bool patch_windowhack = false;
52bool patch_daodaninit = true;
53bool patch_bsl = true;
54bool patch_cheater = true;
55
56// bool patch_newweapon = true;
57
58bool opt_usedaodanbsl = true;
59bool opt_border = true;
60bool opt_shadow = false;
61bool opt_topmost = false;
62
63bool DDrPatch_Init()
64{
65 DDrStartupMessage("patching engine");
66
67 // Font texture cache doubled
68 if (patch_fonttexturecache)
69 {
70 DDrPatch_Byte(OniExe + 0x00020ea7, 0x20);
71 DDrPatch_Byte(OniExe + 0x00020f4a, 0x40);
72 }
73
74 // Now supports textures up to 512x512
75 if (patch_largetextures)
76 DDrPatch_Byte (OniExe + 0x00005251, 0x10);
77
78 // Non-"_Final" levels are now valid
79 if (patch_levelplugins)
80 DDrPatch_Byte (OniExe + 0x000206a8, 0x01);
81
82 // Pathfinding grid cache size x8
83 if (patch_pathfinding)
84 {
85 const char pathfinding[2] = {0x90 , 0xE9 };
86 DDrPatch_Byte (OniExe + 0x0010b03b, 0x20);
87 DDrPatch_Byte (OniExe + 0x0010b04c, 0x20);
88
89 //other stuff
90 DDrPatch_Const(0x440789, pathfinding);
91 }
92
93 // Projectile awareness fixed
94 if (patch_projaware)
95 {
96 DDrPatch_Byte (OniExe + 0x0009c07c, 0x6c);
97 DDrPatch_Byte (OniExe + 0x0009c080, 0x70);
98 DDrPatch_Byte (OniExe + 0x0009c084, 0x74);
99 DDrPatch_Byte (OniExe + 0x0009c110, 0x6c);
100 }
101
102 // Forced DirectInput (for Windows NT)
103 if (patch_directinput)
104 DDrPatch_Byte (OniExe + 0x00002e6d, 0xeb);
105
106 if (patch_wpfadetime)
107 {
108 // Makes wp_fadetime actually have a function
109 const char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 };
110 DDrPatch_Const (OniExe + 0x0011a889, fadetime_patch);
111 DDrPatch_Byte (OniExe + 0x0011a560, 0x31);
112
113 // Sets the fadetime to 4800 by default
114 DDrPatch_Int16 ((OniExe + 0x0011ab0e), 0x12c0);
115 }
116
117 // FIXME: add switches
118 //pathfinding fix
119
120
121
122
123 // Hackish fix for Konoko not kicking guns
124 // Don't use this, it breaks stairs.
125 if (patch_kickguns)
126 {
127 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 };
128 DDrPatch_Const (OniExe + 0x000dc420, kickgun_patch);
129 }
130
131 // Cooldown timer exploit fix ^_^
132 if (patch_cooldowntimer)
133 {
134 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 };
135 DDrPatch_Const (OniExe + 0x0011a825, cooldown_patch);
136 }
137
138 if (patch_throwtest)
139 {
140 const char throwtest_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 };
141 DDrPatch_Const(OniExe + 0x000dc190, throwtest_patch);
142 }
143
144 // 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.
145 if (patch_alttab)
146 {
147 DDrPatch_Byte ((void*)UUrPlatform_Initialize, 0xC3);
148 DDrPatch_Byte ((void*)UUrPlatform_Terminate, 0xC3);
149 }
150
151 // 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.)
152 if (patch_particledisablebit)
153 DDrPatch_Int16 (OniExe + 0x001b184, 0x9090);
154
155 // Multi-byte patch (multiple language support)
156 if (!patch_multibyte)
157 {
158 DDrPatch_Byte (OniExe + 0x0002d8f8, 0xeb);
159 DDrPatch_Byte (OniExe + 0x0002d9ad, 0xeb);
160 DDrPatch_Byte (OniExe + 0x0002dbe2, 0xeb);
161 DDrPatch_Byte (OniExe + 0x0002dec3, 0xeb);
162 DDrPatch_Byte (OniExe + 0x0002e2ab, 0xeb);
163 DDrPatch_Byte (OniExe + 0x0002e2c4, 0xeb);
164 DDrPatch_Byte (OniExe + 0x0002e379, 0xeb);
165 DDrPatch_Byte (OniExe + 0x0002e48c, 0xeb);
166 DDrPatch_Byte (OniExe + 0x0002e4d0, 0xeb);
167 DDrPatch_Byte (OniExe + 0x0002e4f4, 0xeb);
168 DDrPatch_Byte (OniExe + 0x0002e646, 0xeb);
169 DDrPatch_Byte (OniExe + 0x0002e695, 0xeb);
170 DDrPatch_Byte (OniExe + 0x0002e944, 0xeb);
171 DDrPatch_Byte (OniExe + 0x0002e95d, 0xeb);
172 DDrPatch_Byte (OniExe + 0x0002e98e, 0xeb);
173 DDrPatch_Byte (OniExe + 0x0002e9dc, 0xeb);
174 }
175
176 // Cheat table patch
177 if (patch_cheattable)
178 {
179 DDrPatch_Int32 (0x004f616b, (int)&DDr_CheatTable[0].name);
180 DDrPatch_Int32 (OniExe + 0x000f617a, (int)&DDr_CheatTable[0].message_on);
181 }
182
183 // ARGB8888 textures
184 if (patch_argb8888)
185 {
186 DDrPatch_Byte (OniExe + 0x00135af0, 0x07);
187 DDrPatch_Byte (OniExe + 0x00135af4, 0x0B);
188 }
189
190 //Test newweap patch
191// if (patch_newweapon) {
192
193 //Makes it always say "Recieved weapon_name."
194 //Needs check for loc_4DFC66
195 DDrPatch_NOOP( OniExe + 0x000E4DF8,2);
196
197 //Adds Weapon name and ammo meter to pickup autoprompt
198 DDrPatch_NOOP( OniExe + 0x000FAC73, 9);
199 DDrPatch_NOOP( OniExe + 0x000FAC80, 5);
200 DDrPatch_MakeCall( OniExe + 0xFAC85, DDrWeapon2Message);
201
202 //Moves location of colors
203 //DDrPatch_Int32( 0x0042E3D5, (int)&DDrDSayColors );
204 //DDrPatch_Int32( 0x0042E3DA, (int)&DDrDSayColors );
205// }
206
207 // Disable loading the vtuneapi.dll
208 if (patch_killvtune)
209 DDrPatch_Byte (OniExe + 0x00026340, 0xC3);
210
211 // Disable Oni's internal CLrGetCommandLine function (to eventually replace it with our own)
212 if (patch_getcmdline)
213 DDrPatch_NOOP (OniExe + 0x000d3280, 51);
214
215 // Disable Oni's command line parser so it doesn't interfere with ours
216 if (patch_disablecmdline)
217 DDrPatch_Int32 (OniExe + 0x000d3570, 0xc3c03366);
218
219 if (patch_bsl)
220 {
221 //Calculating the value of the needed offset is much more reliable when the compiler does it for you.
222
223 //TODO: fix moonshadow.
224 Character * Chr = 0;
225 int NoPath = (int)&(Chr[0].RegenHax) & 0x000000FF;
226 const char regen_patch[] =
227 {0x90, 0x90, 0x90, 0x90, 0x90, // mov al, _WPgRegenerationCheat -> NOOP
228 0x90, 0x90, // test al, al -> NOOP
229 0x90, 0x90, // jz short loc_51BB98 -> NOOP
230 0x8B, 0x86, (char)NoPath, 0x01, 0x00, 0x00, // mov eax, [esi+Character.field_1E8]
231 // -> mov eax, [esi+Character.RegenHax]
232 0x85, 0xC0, // test eax, eax
233 0x74, 0x21 // jnz 0x21 -> jz 0x21
234 };
235 DDrPatch_Const(0x0051BB64, regen_patch);
236 }
237
238
239 return true;
240}
241
242enum {s_unknown, s_options, s_patch, s_bsl, s_language} ini_section;
243
244bool DDrIniCallback(char* section, bool newsection, char* name, char* value)
245{
246 if (newsection)
247 {
248 if (!_stricmp(section, "options"))
249 ini_section = s_options;
250 else if (!_stricmp(section, "patch"))
251 ini_section = s_patch;
252 else if (!_stricmp(section, "bsl"))
253 ini_section = s_bsl;
254 else if (!_stricmp(section, "language"))
255 ini_section = s_language;
256 else
257 {
258 ini_section = s_unknown;
259 DDrStartupMessage("unrecognised section \"%s\"", section);
260 }
261 }
262
263 switch (ini_section)
264 {
265 case s_options:
266 if (!_stricmp(name, "usedaodanbsl"))
267 opt_usedaodanbsl = !_stricmp(inifile_cleanstr(value), "true");
268 else if (!_stricmp(name, "border"))
269 opt_border = !_stricmp(inifile_cleanstr(value), "true");
270 else if (!_stricmp(name, "shadow"))
271 opt_shadow = !_stricmp(inifile_cleanstr(value), "true");
272 else if (!_stricmp(name, "topmost"))
273 opt_topmost = !_stricmp(inifile_cleanstr(value), "true");
274 else if (!_stricmp(name, "multibyte"))
275 patch_multibyte = !_stricmp(inifile_cleanstr(value), "true");
276 else if (!_stricmp(name, "debug"))
277 AKgDebug_DebugMaps = !_stricmp(inifile_cleanstr(value), "true");
278 else if (!_stricmp(name, "debugfiles"))
279 BFgDebugFileEnable = !_stricmp(inifile_cleanstr(value), "true");
280 else if (!_stricmp(name, "findsounds"))
281 SSgSearchOnDisk = !_stricmp(inifile_cleanstr(value), "true");
282 else if (!_stricmp(name, "ignore_private_data"))
283 opt_ignore_private_data = !_stricmp(inifile_cleanstr(value), "true");
284 else if (!_stricmp(name, "sound"))
285 opt_sound = !_stricmp(inifile_cleanstr(value), "true");
286 else if (!_stricmp(name, "switch"))
287 M3gResolutionSwitch = !_stricmp(inifile_cleanstr(value), "true");
288 else
289 DDrStartupMessage("unrecognised option \"%s\"", name);
290 break;
291 case s_patch:
292 if (!_stricmp(name, "fonttexturecache"))
293 patch_fonttexturecache = !_stricmp(inifile_cleanstr(value), "true");
294 else if (!_stricmp(name, "largetextures"))
295 patch_largetextures = !_stricmp(inifile_cleanstr(value), "true");
296 else if (!_stricmp(name, "levelplugins"))
297 patch_levelplugins = !_stricmp(inifile_cleanstr(value), "true");
298 else if (!_stricmp(name, "pathfinding"))
299 patch_pathfinding = !_stricmp(inifile_cleanstr(value), "true");
300 else if (!_stricmp(name, "projaware"))
301 patch_projaware = !_stricmp(inifile_cleanstr(value), "true");
302 else if (!_stricmp(name, "directinput"))
303 patch_directinput = !_stricmp(inifile_cleanstr(value), "true");
304 else if (!_stricmp(name, "wpfadetime"))
305 patch_wpfadetime = !_stricmp(inifile_cleanstr(value), "true");
306 else if (!_stricmp(name, "kickguns"))
307 patch_kickguns = !_stricmp(inifile_cleanstr(value), "true");
308 else if (!_stricmp(name, "cooldowntimer"))
309 patch_cooldowntimer = !_stricmp(inifile_cleanstr(value), "true");
310 else if (!_stricmp(name, "throwtest"))
311 patch_throwtest = !_stricmp(inifile_cleanstr(value), "true");
312 else if (!_stricmp(name, "alttab"))
313 patch_alttab = !_stricmp(inifile_cleanstr(value), "true");
314 else if (!_stricmp(name, "particledisablebit"))
315 patch_particledisablebit = !_stricmp(inifile_cleanstr(value), "true");
316 else if (!_stricmp(name, "multibyte"))
317 patch_multibyte = !_stricmp(inifile_cleanstr(value), "true");
318 else if (!_stricmp(name, "cheattable"))
319 patch_cheattable = !_stricmp(inifile_cleanstr(value), "true");
320 else if (!_stricmp(name, "argb8888"))
321 patch_argb8888 = !_stricmp(inifile_cleanstr(value), "true");
322 else if (!_stricmp(name, "killvtune"))
323 patch_killvtune = !_stricmp(inifile_cleanstr(value), "true");
324 else if (!_stricmp(name, "getcmdline"))
325 patch_getcmdline = !_stricmp(inifile_cleanstr(value), "true");
326 else if (!_stricmp(name, "disablecmdline"))
327 patch_disablecmdline = !_stricmp(inifile_cleanstr(value), "true");
328 else if (!_stricmp(name, "safeprintf"))
329 patch_safeprintf = !_stricmp(inifile_cleanstr(value), "true");
330 else if (!_stricmp(name, "daodandisplayenum"))
331 patch_daodandisplayenum = !_stricmp(inifile_cleanstr(value), "true");
332 else if (!_stricmp(name, "usegettickcount"))
333 patch_usegettickcount = !_stricmp(inifile_cleanstr(value), "true");
334 else if (!_stricmp(name, "cheatsenabled"))
335 patch_cheatsenabled = !_stricmp(inifile_cleanstr(value), "true");
336 else if (!_stricmp(name, "usedaodangl"))
337 patch_usedaodangl = !_stricmp(inifile_cleanstr(value), "true");
338 else if (!_stricmp(name, "windowhack"))
339 patch_windowhack = !_stricmp(inifile_cleanstr(value), "true");
340 else if (!_stricmp(name, "daodaninit"))
341 patch_daodaninit = !_stricmp(inifile_cleanstr(value), "true");
342 else if (!_stricmp(name, "bsl"))
343 patch_bsl = !_stricmp(inifile_cleanstr(value), "true");
344 else if (!_stricmp(name, "cheater"))
345 patch_cheater = !_stricmp(inifile_cleanstr(value), "true");
346 else
347 DDrStartupMessage("unrecognised patch \"%s\"", name);
348 break;
349 case s_language:
350 if (!_stricmp(name, "savepoint"))
351 {
352 char* str = _strdup(value);
353 DDrPatch_Int32(OniExe + 0x000fd730, (int)str);
354 DDrPatch_Int32(OniExe + 0x000fd738, (int)str);
355 }
356 else if (!_stricmp(name, "syndicatewarehouse"))
357 {
358 char* str = _strdup(value);
359 DDrPatch_Int32(OniExe + 0x000fd71a, (int)str);
360 DDrPatch_Int32(OniExe + 0x0010ef75, (int)str);
361 }
362 else if (!_stricmp(name, "damn"))
363 DDrPatch__strdup(OniExe + 0x0010fb6e, value);
364 else if (!_stricmp(name, "blam"))
365 DDrPatch__strdup(OniExe + 0x0010fb73, value);
366 else if (!_stricmp(name, "shapeshifter_on"))
367 DDr_CheatTable[0].message_on = _strdup(value);
368 else if (!_stricmp(name, "shapeshifter_off"))
369 DDr_CheatTable[0].message_off = _strdup(value);
370 else if (!_stricmp(name, "liveforever_on"))
371 DDr_CheatTable[1].message_on = _strdup(value);
372 else if (!_stricmp(name, "liveforever_off"))
373 DDr_CheatTable[1].message_off = _strdup(value);
374 else if (!_stricmp(name, "touchofdeath_on"))
375 DDr_CheatTable[2].message_on = _strdup(value);
376 else if (!_stricmp(name, "touchofdeath_off"))
377 DDr_CheatTable[2].message_off = _strdup(value);
378 else if (!_stricmp(name, "canttouchthis_on"))
379 DDr_CheatTable[3].message_on = _strdup(value);
380 else if (!_stricmp(name, "canttouchthis_off"))
381 DDr_CheatTable[3].message_off = _strdup(value);
382 else if (!_stricmp(name, "fatloot_on"))
383 DDr_CheatTable[4].message_on = _strdup(value);
384 else if (!_stricmp(name, "glassworld_on"))
385 DDr_CheatTable[5].message_on = _strdup(value);
386 else if (!_stricmp(name, "glassworld_off"))
387 DDr_CheatTable[5].message_off = _strdup(value);
388 else if (!_stricmp(name, "winlevel_on"))
389 DDr_CheatTable[6].message_on = _strdup(value);
390 else if (!_stricmp(name, "loselevel_on"))
391 DDr_CheatTable[7].message_on = _strdup(value);
392 else if (!_stricmp(name, "bighead_on"))
393 DDr_CheatTable[8].message_on = _strdup(value);
394 else if (!_stricmp(name, "bighead_off"))
395 DDr_CheatTable[8].message_off = _strdup(value);
396 else if (!_stricmp(name, "minime_on"))
397 DDr_CheatTable[9].message_on = _strdup(value);
398 else if (!_stricmp(name, "minime_off"))
399 DDr_CheatTable[9].message_off = _strdup(value);
400 else if (!_stricmp(name, "superammo_on"))
401 DDr_CheatTable[10].message_on = _strdup(value);
402 else if (!_stricmp(name, "superammo_off"))
403 DDr_CheatTable[10].message_off = _strdup(value);
404 else if (!_stricmp(name, "devmode_on"))
405 {
406 char* str = _strdup(value);
407 DDr_CheatTable[11].message_on = str;
408 DDr_CheatTable[cheat_x].message_on = str;
409 }
410 else if (!_stricmp(name, "devmode_off"))
411 {
412 char* str = _strdup(value);
413 DDr_CheatTable[11].message_off = str;
414 DDr_CheatTable[cheat_x].message_off = str;
415 }
416 else if (!_stricmp(name, "reservoirdogs_on"))
417 DDr_CheatTable[12].message_on = _strdup(value);
418 else if (!_stricmp(name, "reservoirdogs_off"))
419 DDr_CheatTable[12].message_off = _strdup(value);
420 else if (!_stricmp(name, "roughjustice_on"))
421 DDr_CheatTable[13].message_on = _strdup(value);
422 else if (!_stricmp(name, "roughjustice_off"))
423 DDr_CheatTable[13].message_off = _strdup(value);
424 else if (!_stricmp(name, "chenille_on"))
425 DDr_CheatTable[14].message_on = _strdup(value);
426 else if (!_stricmp(name, "chenille_off"))
427 DDr_CheatTable[14].message_off = _strdup(value);
428 else if (!_stricmp(name, "behemoth_on"))
429 DDr_CheatTable[15].message_on = _strdup(value);
430 else if (!_stricmp(name, "behemoth_off"))
431 DDr_CheatTable[15].message_off = _strdup(value);
432 else if (!_stricmp(name, "elderrune_on"))
433 DDr_CheatTable[16].message_on = _strdup(value);
434 else if (!_stricmp(name, "elderrune_off"))
435 DDr_CheatTable[16].message_off = _strdup(value);
436 else if (!_stricmp(name, "moonshadow_on"))
437 DDr_CheatTable[17].message_on = _strdup(value);
438 else if (!_stricmp(name, "moonshadow_off"))
439 DDr_CheatTable[17].message_off = _strdup(value);
440 else if (!_stricmp(name, "munitionfrenzy_on"))
441 DDr_CheatTable[18].message_on = _strdup(value);
442 else if (!_stricmp(name, "fistsoflegend_on"))
443 DDr_CheatTable[19].message_on = _strdup(value);
444 else if (!_stricmp(name, "fistsoflegend_off"))
445 DDr_CheatTable[19].message_off = _strdup(value);
446 else if (!_stricmp(name, "killmequick_on"))
447 DDr_CheatTable[20].message_on = _strdup(value);
448 else if (!_stricmp(name, "killmequick_off"))
449 DDr_CheatTable[20].message_off = _strdup(value);
450 else if (!_stricmp(name, "carousel_on"))
451 DDr_CheatTable[21].message_on = _strdup(value);
452 else if (!_stricmp(name, "carousel_off"))
453 DDr_CheatTable[21].message_off = _strdup(value);
454 else
455 DDrStartupMessage("unrecognised language item \"%s\"", name);
456 break;
457 case s_bsl:
458 default:
459 break;
460 }
461
462 return true;
463}
464
465void DDrConfig()
466{
467/* if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES)
468 {
469 DDrStartupMessage("daodan.ini doesn't exist, creating");
470 FILE* fp = fopen("daodan.ini", "w");
471 if (fp)
472 {
473 fputs("[Options]\n", fp);
474 fclose(fp);
475 }
476 }
477
478 DDrStartupMessage("parsing daodan.ini...");
479 if (!inifile_read("daodan.ini", DDrIniCallback))
480 DDrStartupMessage("error reading daodan.ini, check your syntax!");*/
481 DDrStartupMessage("finished parsing");
482}
483
484void ONICALL DDrGame_Init()
485{
486 if (opt_usedaodanbsl)
487 SLrDaodan_Initalize();
488}
489
490void DDrException() {
491 int* i = 0;
492 *i = 1;
493}
494#include <stdio.h>
495
496//this was broken
497FILE** _UUgError_WarningFile = (FILE**)0x005711B4;
498FILE *__fastcall DDrPrintWarning(int filename, int linenumber, unsigned __int16 errornum, int message)
499{
500
501 FILE *v4; // eax@1
502 FILE *result; // eax@4
503 char v6[512]; // [sp+0h] [bp-100h]@1
504 FILE* UUgError_WarningFile = *_UUgError_WarningFile;
505 sprintf_s(
506 v6, 512,
507 "Error %x reported from File: %s, Line: %d (message follows) \r\n%s",
508 errornum,
509 filename,
510 linenumber,
511 message);
512
513 if ( UUgError_WarningFile
514 || (UUgError_WarningFile = oni_fopen("debugger.txt", "wb"), UUgError_WarningFile ) )
515 {
516 oni_fprintf(UUgError_WarningFile, "%s\r\n", v6);
517 oni_fflush(UUgError_WarningFile);
518 }
519 //oni_fprintf(stdout, v6);
520 //sprintf(&v6, "%s", message);
521 *_UUgError_WarningFile = UUgError_WarningFile;
522 result = UUgError_WarningFile;
523 return result;
524}
525
526void __cdecl DDrMain(int argc, char* argv[])
527{
528 int i;
529 char* section;
530 char* option;
531 bool falseoption;
532
533 DDrStartupMessage("daodan attached!");
534
535 opt_ignore_private_data = false;
536 opt_sound = true;
537
538 DDrConfig();
539 DDrStartupMessage("parsing command line...");
540 for (i = 1; i < argc; i ++)
541 {
542 if (argv[i][0] == '-')
543 {
544 section = argv[i] + 1;
545 if ((option = strchr(argv[i], '.')))
546 {
547 *option = '\0';
548 falseoption = (option[1] == 'n' || option[1] == 'N') && (option[2] = 'o' || option[2] == 'O');
549 if (i < (argc - 1) && argv[i + 1][0] != '-')
550 DDrIniCallback(section, true, option + 1, argv[++i]);
551 else
552 DDrIniCallback(section, true, option + (falseoption ? 3 : 1), (falseoption ? "false" : "true"));
553 *option = '.';
554 }
555 else
556 {
557 falseoption = (section[0] == 'n' || section[0] == 'N') && (section[1] = 'o' || section[1] == 'O');
558 ini_section = s_options;
559 if (i < (argc - 1) && argv[i + 1][0] != '-')
560 DDrIniCallback(NULL, false, section, argv[++i]);
561 else
562 DDrIniCallback(NULL, false, section + (falseoption ? 2 : 0), (falseoption ? "false" : "true"));
563 }
564 }
565 else
566 {
567 DDrStartupMessage("parse error \"%s\"", argv[i]);
568 break;
569 }
570 }
571 DDrStartupMessage("finished parsing");
572 DDrPatch_Init();
573
574 // Safe startup message printer
575 if (patch_safeprintf)
576 DDrPatch_MakeJump(UUrStartupMessage, DDrStartupMessage);
577
578 // Daodan device mode enumeration function
579 if (patch_daodandisplayenum)
580 DDrPatch_MakeJump(gl_enumerate_valid_display_modes, daodan_enumerate_valid_display_modes);
581
582 // Performance patch
583 if (patch_usegettickcount)
584 {
585 DDrPatch_MakeJump(UUrMachineTime_High, DDrMachineTime_High);
586 DDrPatch_MakeJump(UUrMachineTime_High_Frequency, DDrMachineTime_High_Frequency);
587 DDrPatch_MakeJump(UUrMachineTime_Sixtieths, DDrMachineTime_Sixtieths);
588 }
589
590 // Cheats always enabled
591 if (patch_cheatsenabled)
592 DDrPatch_MakeJump(ONrPersist_GetWonGame, DDrPersist_GetWonGame);
593//#if 0
594 // Windowed mode
595// if (patch_usedaodangl)
596 {
597 DDrPatch_NOOP((char*)0x004032B7, 6);
598 DDrPatch_MakeCall((char*)0x004032B7, LIiP_SetCursorPosHook);
599
600 DDrPatch_NOOP((char*)0x00403349, 6);
601 DDrPatch_MakeCall((char*)0x00403349, LIiP_SetCursorPosHook);
602 DDrPatch_MakeJump(ONrPlatform_Initialize, DDrPlatform_Initialize);
603 DDrPatch_MakeJump(gl_platform_initialize, daodangl_platform_initialize);
604 }
605//#endif
606 // Hacked windowed mode (for when daodangl isn't working properly)
607 //if (patch_windowhack)
608
609 // DDrWindowHack_Install();
610
611 if (patch_daodaninit)
612 DDrPatch_MakeCall(OniExe + 0x000d345a, DDrGame_Init);
613
614 // Patches for existing BSL functions
615 if (patch_bsl)
616 SLrDaodan_Patch();
617
618 if (patch_cheater)
619 {
620 DDrPatch_MakeCall(OniExe + 0x000f618f, DDrCheater);
621 DDrPatch_Int16(OniExe + 0x000deb45, 0x5590);
622#if 0
623 DDrPatch_MakeCall(OniExe + 0x000deb47, FallingFrames);
624#endif
625 DDrPatch_MakeJump(OniExe + 0x0010f021, DDrCheater_LevelLoad);
626 }
627
628 //DDrPatch_MakeJump(0x004378c0, DDrException);
629 DDrPatch_MakeJump(0x004245A0, DDrPrintWarning);
630 //init_daodan_gl();
631
632 ONiMain(argc, argv);
633}
634/*
635void DDrWrongExe()
636{
637 switch (MessageBox(NULL, "This version of the Daodan DLL is incompatible with your Oni.exe.\n"
638 "Click OK for more information. To continue using Oni without the patch, replace the downloaded binkw32.dll with the original.", "Daodan", MB_OKCANCEL | MB_ICONERROR))
639 {
640 case IDOK:
641 {
642 STARTUPINFO si;
643 PROCESS_INFORMATION pi;
644 FillMemory(&si, 0, sizeof(si));
645 FillMemory(&pi, 0, sizeof(pi));
646 si.cb = sizeof(si);
647 if (!CreateProcess(NULL, "cmd /c \"start http://wiki.oni2.net/Daodan_DLL\"", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
648 MessageBox(NULL, "", "", 0);
649 CloseHandle(pi.hProcess);
650 CloseHandle(pi.hThread);
651 }
652 default:
653 ExitProcess(0);
654 }
655}
656*/
657BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
658{
659 switch (fdwReason)
660 {
661 case DLL_PROCESS_ATTACH:
662 DDrDLLModule = hinstDLL;
663 DDrONiModule = GetModuleHandle(NULL);
664
665 if (*(uint32_t*)(OniExe + 0x0011acd0) == 0x09d36852)
666 DDrPatch_MakeCall(OniExe + 0x0010fb49, DDrMain);
667 else
668 ExitProcess(0);
669 break;
670 }
671 return TRUE;
672}
Note: See TracBrowser for help on using the repository browser.