source: Daodan/MSVC/Daodan.c@ 720

Last change on this file since 720 was 676, checked in by gumby, 12 years ago

Fixing default options

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