source: Daodan/MSVC/Daodan.c@ 576

Last change on this file since 576 was 574, checked in by gumby, 14 years ago
File size: 23.1 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 "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 = true;
53bool patch_windowhack = false;
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
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 //Flatline related stuff
238 DDrPatch_MakeCall(0x004FBCEA, DDrText_Hook);
239
240 DDrPatch_Int32( 0x004B24D2, FLrSpawnHack);
241
242 DDrPatch_NOOP(0x004C26CB, 6);
243 DDrPatch_MakeCall( 0x004C26CB, FLrHook_DoorOpen);
244 DDrPatch_MakeCall( 0x004EE3CF, FLrHook_ConsoleActivate);
245 return true;
246}
247
248enum {s_unknown, s_options, s_patch, s_bsl, s_language} ini_section;
249
250bool DDrIniCallback(char* section, bool newsection, char* name, char* value)
251{
252 if (newsection)
253 {
254 if (!_stricmp(section, "options"))
255 ini_section = s_options;
256 else if (!_stricmp(section, "patch"))
257 ini_section = s_patch;
258 else if (!_stricmp(section, "bsl"))
259 ini_section = s_bsl;
260 else if (!_stricmp(section, "language"))
261 ini_section = s_language;
262 else
263 {
264 ini_section = s_unknown;
265 DDrStartupMessage("unrecognised section \"%s\"", section);
266 }
267 }
268
269 switch (ini_section)
270 {
271 case s_options:
272 if (!_stricmp(name, "usedaodanbsl"))
273 opt_usedaodanbsl = !_stricmp(inifile_cleanstr(value), "true");
274 else if (!_stricmp(name, "border"))
275 opt_border = !_stricmp(inifile_cleanstr(value), "true");
276 else if (!_stricmp(name, "shadow"))
277 opt_shadow = !_stricmp(inifile_cleanstr(value), "true");
278 else if (!_stricmp(name, "topmost"))
279 opt_topmost = !_stricmp(inifile_cleanstr(value), "true");
280 else if (!_stricmp(name, "multibyte"))
281 patch_multibyte = !_stricmp(inifile_cleanstr(value), "true");
282 else if (!_stricmp(name, "debug"))
283 AKgDebug_DebugMaps = !_stricmp(inifile_cleanstr(value), "true");
284 else if (!_stricmp(name, "debugfiles"))
285 BFgDebugFileEnable = !_stricmp(inifile_cleanstr(value), "true");
286 else if (!_stricmp(name, "findsounds"))
287 SSgSearchOnDisk = !_stricmp(inifile_cleanstr(value), "true");
288 else if (!_stricmp(name, "ignore_private_data"))
289 opt_ignore_private_data = !_stricmp(inifile_cleanstr(value), "true");
290 else if (!_stricmp(name, "sound"))
291 opt_sound = !_stricmp(inifile_cleanstr(value), "true");
292 else if (!_stricmp(name, "switch"))
293 M3gResolutionSwitch = !_stricmp(inifile_cleanstr(value), "true");
294 //else if (!_stricmp(name, "devmode"))
295 //turn_dev_mode_on = !_stricmp(inifile_cleanstr(value), "true");
296 else
297 DDrStartupMessage("unrecognised option \"%s\"", name);
298 break;
299 case s_patch:
300 if (!_stricmp(name, "fonttexturecache"))
301 patch_fonttexturecache = !_stricmp(inifile_cleanstr(value), "true");
302 else if (!_stricmp(name, "largetextures"))
303 patch_largetextures = !_stricmp(inifile_cleanstr(value), "true");
304 else if (!_stricmp(name, "levelplugins"))
305 patch_levelplugins = !_stricmp(inifile_cleanstr(value), "true");
306 else if (!_stricmp(name, "pathfinding"))
307 patch_pathfinding = !_stricmp(inifile_cleanstr(value), "true");
308 else if (!_stricmp(name, "projaware"))
309 patch_projaware = !_stricmp(inifile_cleanstr(value), "true");
310 else if (!_stricmp(name, "directinput"))
311 patch_directinput = !_stricmp(inifile_cleanstr(value), "true");
312 else if (!_stricmp(name, "wpfadetime"))
313 patch_wpfadetime = !_stricmp(inifile_cleanstr(value), "true");
314 else if (!_stricmp(name, "kickguns"))
315 patch_kickguns = !_stricmp(inifile_cleanstr(value), "true");
316 else if (!_stricmp(name, "cooldowntimer"))
317 patch_cooldowntimer = !_stricmp(inifile_cleanstr(value), "true");
318 else if (!_stricmp(name, "throwtest"))
319 patch_throwtest = !_stricmp(inifile_cleanstr(value), "true");
320 else if (!_stricmp(name, "alttab"))
321 patch_alttab = !_stricmp(inifile_cleanstr(value), "true");
322 else if (!_stricmp(name, "particledisablebit"))
323 patch_particledisablebit = !_stricmp(inifile_cleanstr(value), "true");
324 else if (!_stricmp(name, "multibyte"))
325 patch_multibyte = !_stricmp(inifile_cleanstr(value), "true");
326 else if (!_stricmp(name, "cheattable"))
327 patch_cheattable = !_stricmp(inifile_cleanstr(value), "true");
328 else if (!_stricmp(name, "argb8888"))
329 patch_argb8888 = !_stricmp(inifile_cleanstr(value), "true");
330 else if (!_stricmp(name, "killvtune"))
331 patch_killvtune = !_stricmp(inifile_cleanstr(value), "true");
332 else if (!_stricmp(name, "getcmdline"))
333 patch_getcmdline = !_stricmp(inifile_cleanstr(value), "true");
334 else if (!_stricmp(name, "disablecmdline"))
335 patch_disablecmdline = !_stricmp(inifile_cleanstr(value), "true");
336 else if (!_stricmp(name, "safeprintf"))
337 patch_safeprintf = !_stricmp(inifile_cleanstr(value), "true");
338 else if (!_stricmp(name, "daodandisplayenum"))
339 patch_daodandisplayenum = !_stricmp(inifile_cleanstr(value), "true");
340 else if (!_stricmp(name, "usegettickcount"))
341 patch_usegettickcount = !_stricmp(inifile_cleanstr(value), "true");
342 else if (!_stricmp(name, "cheatsenabled"))
343 patch_cheatsenabled = !_stricmp(inifile_cleanstr(value), "true");
344 else if (!_stricmp(name, "usedaodangl"))
345 patch_usedaodangl = !_stricmp(inifile_cleanstr(value), "true");
346 else if (!_stricmp(name, "windowhack"))
347 patch_windowhack = !_stricmp(inifile_cleanstr(value), "true");
348 else if (!_stricmp(name, "daodaninit"))
349 patch_daodaninit = !_stricmp(inifile_cleanstr(value), "true");
350 else if (!_stricmp(name, "bsl"))
351 patch_bsl = !_stricmp(inifile_cleanstr(value), "true");
352 else if (!_stricmp(name, "cheater"))
353 patch_cheater = !_stricmp(inifile_cleanstr(value), "true");
354 else if (!_stricmp(name, "newweap"))
355 patch_newweapon = !_stricmp(inifile_cleanstr(value), "true");
356 else
357 DDrStartupMessage("unrecognised patch \"%s\"", name);
358 break;
359 case s_language:
360 if (!_stricmp(name, "savepoint"))
361 {
362 char* str = _strdup(value);
363 DDrPatch_Int32(OniExe + 0x000fd730, (int)str);
364 DDrPatch_Int32(OniExe + 0x000fd738, (int)str);
365 }
366 else if (!_stricmp(name, "syndicatewarehouse"))
367 {
368 char* str = _strdup(value);
369 DDrPatch_Int32(OniExe + 0x000fd71a, (int)str);
370 DDrPatch_Int32(OniExe + 0x0010ef75, (int)str);
371 }
372 else if (!_stricmp(name, "damn"))
373 DDrPatch__strdup(OniExe + 0x0010fb6e, value);
374 else if (!_stricmp(name, "blam"))
375 DDrPatch__strdup(OniExe + 0x0010fb73, value);
376 else if (!_stricmp(name, "shapeshifter_on"))
377 DDr_CheatTable[0].message_on = _strdup(value);
378 else if (!_stricmp(name, "shapeshifter_off"))
379 DDr_CheatTable[0].message_off = _strdup(value);
380 else if (!_stricmp(name, "liveforever_on"))
381 DDr_CheatTable[1].message_on = _strdup(value);
382 else if (!_stricmp(name, "liveforever_off"))
383 DDr_CheatTable[1].message_off = _strdup(value);
384 else if (!_stricmp(name, "touchofdeath_on"))
385 DDr_CheatTable[2].message_on = _strdup(value);
386 else if (!_stricmp(name, "touchofdeath_off"))
387 DDr_CheatTable[2].message_off = _strdup(value);
388 else if (!_stricmp(name, "canttouchthis_on"))
389 DDr_CheatTable[3].message_on = _strdup(value);
390 else if (!_stricmp(name, "canttouchthis_off"))
391 DDr_CheatTable[3].message_off = _strdup(value);
392 else if (!_stricmp(name, "fatloot_on"))
393 DDr_CheatTable[4].message_on = _strdup(value);
394 else if (!_stricmp(name, "glassworld_on"))
395 DDr_CheatTable[5].message_on = _strdup(value);
396 else if (!_stricmp(name, "glassworld_off"))
397 DDr_CheatTable[5].message_off = _strdup(value);
398 else if (!_stricmp(name, "winlevel_on"))
399 DDr_CheatTable[6].message_on = _strdup(value);
400 else if (!_stricmp(name, "loselevel_on"))
401 DDr_CheatTable[7].message_on = _strdup(value);
402 else if (!_stricmp(name, "bighead_on"))
403 DDr_CheatTable[8].message_on = _strdup(value);
404 else if (!_stricmp(name, "bighead_off"))
405 DDr_CheatTable[8].message_off = _strdup(value);
406 else if (!_stricmp(name, "minime_on"))
407 DDr_CheatTable[9].message_on = _strdup(value);
408 else if (!_stricmp(name, "minime_off"))
409 DDr_CheatTable[9].message_off = _strdup(value);
410 else if (!_stricmp(name, "superammo_on"))
411 DDr_CheatTable[10].message_on = _strdup(value);
412 else if (!_stricmp(name, "superammo_off"))
413 DDr_CheatTable[10].message_off = _strdup(value);
414 else if (!_stricmp(name, "devmode_on"))
415 {
416 char* str = _strdup(value);
417 DDr_CheatTable[11].message_on = str;
418 DDr_CheatTable[cheat_x].message_on = str;
419 }
420 else if (!_stricmp(name, "devmode_off"))
421 {
422 char* str = _strdup(value);
423 DDr_CheatTable[11].message_off = str;
424 DDr_CheatTable[cheat_x].message_off = str;
425 }
426 else if (!_stricmp(name, "reservoirdogs_on"))
427 DDr_CheatTable[12].message_on = _strdup(value);
428 else if (!_stricmp(name, "reservoirdogs_off"))
429 DDr_CheatTable[12].message_off = _strdup(value);
430 else if (!_stricmp(name, "roughjustice_on"))
431 DDr_CheatTable[13].message_on = _strdup(value);
432 else if (!_stricmp(name, "roughjustice_off"))
433 DDr_CheatTable[13].message_off = _strdup(value);
434 else if (!_stricmp(name, "chenille_on"))
435 DDr_CheatTable[14].message_on = _strdup(value);
436 else if (!_stricmp(name, "chenille_off"))
437 DDr_CheatTable[14].message_off = _strdup(value);
438 else if (!_stricmp(name, "behemoth_on"))
439 DDr_CheatTable[15].message_on = _strdup(value);
440 else if (!_stricmp(name, "behemoth_off"))
441 DDr_CheatTable[15].message_off = _strdup(value);
442 else if (!_stricmp(name, "elderrune_on"))
443 DDr_CheatTable[16].message_on = _strdup(value);
444 else if (!_stricmp(name, "elderrune_off"))
445 DDr_CheatTable[16].message_off = _strdup(value);
446 else if (!_stricmp(name, "moonshadow_on"))
447 DDr_CheatTable[17].message_on = _strdup(value);
448 else if (!_stricmp(name, "moonshadow_off"))
449 DDr_CheatTable[17].message_off = _strdup(value);
450 else if (!_stricmp(name, "munitionfrenzy_on"))
451 DDr_CheatTable[18].message_on = _strdup(value);
452 else if (!_stricmp(name, "fistsoflegend_on"))
453 DDr_CheatTable[19].message_on = _strdup(value);
454 else if (!_stricmp(name, "fistsoflegend_off"))
455 DDr_CheatTable[19].message_off = _strdup(value);
456 else if (!_stricmp(name, "killmequick_on"))
457 DDr_CheatTable[20].message_on = _strdup(value);
458 else if (!_stricmp(name, "killmequick_off"))
459 DDr_CheatTable[20].message_off = _strdup(value);
460 else if (!_stricmp(name, "carousel_on"))
461 DDr_CheatTable[21].message_on = _strdup(value);
462 else if (!_stricmp(name, "carousel_off"))
463 DDr_CheatTable[21].message_off = _strdup(value);
464 else
465 DDrStartupMessage("unrecognised language item \"%s\"", name);
466 break;
467 case s_bsl:
468 default:
469 break;
470 }
471
472 return true;
473}
474
475void DDrConfig()
476{
477
478 if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES)
479 {
480 FILE* fp;
481 DDrStartupMessage("daodan.ini doesn't exist, creating");
482 fp = fopen("daodan.ini", "w");
483 if (fp)
484 {
485 fputs("[Options]\n", fp);
486 fclose(fp);
487 }
488 }
489
490 DDrStartupMessage("parsing daodan.ini...");
491 if (!inifile_read("daodan.ini", DDrIniCallback))
492 DDrStartupMessage("error reading daodan.ini, check your syntax!");
493 DDrStartupMessage("finished parsing");
494}
495
496void ONICALL DDrGame_Init()
497{
498 if (opt_usedaodanbsl)
499 SLrDaodan_Initalize();
500}
501
502void DDrException() {
503 int* i = 0;
504 *i = 1;
505}
506#include <stdio.h>
507
508//this was broken
509FILE** _UUgError_WarningFile = (FILE**)0x005711B4;
510FILE *__fastcall DDrPrintWarning(int filename, int linenumber, unsigned __int16 errornum, int message)
511{
512
513 FILE *v4; // eax@1
514 FILE *result; // eax@4
515 char v6[512]; // [sp+0h] [bp-100h]@1
516 FILE* UUgError_WarningFile = *_UUgError_WarningFile;
517 sprintf_s(
518 v6, 512,
519 "Error %x reported from File: %s, Line: %d (message follows) \r\n%s",
520 errornum,
521 filename,
522 linenumber,
523 message);
524
525 if ( UUgError_WarningFile
526 || (UUgError_WarningFile = oni_fopen("debugger.txt", "wb"), UUgError_WarningFile ) )
527 {
528 oni_fprintf(UUgError_WarningFile, "%s\r\n", v6);
529 oni_fflush(UUgError_WarningFile);
530 }
531 //oni_fprintf(stdout, v6);
532 //sprintf(&v6, "%s", message);
533 *_UUgError_WarningFile = UUgError_WarningFile;
534 result = UUgError_WarningFile;
535 return result;
536}
537
538void __cdecl DDrMain(int argc, char* argv[])
539{
540 int i;
541 char* section;
542 char* option;
543 bool falseoption;
544
545 DDrStartupMessage("daodan attached!");
546
547 opt_ignore_private_data = false;
548 opt_sound = true;
549
550 DDrConfig();
551 DDrStartupMessage("parsing command line...");
552 for (i = 1; i < argc; i ++)
553 {
554 if (argv[i][0] == '-')
555 {
556 section = argv[i] + 1;
557 if ((option = strchr(argv[i], '.')))
558 {
559 *option = '\0';
560 falseoption = (option[1] == 'n' || option[1] == 'N') && (option[2] = 'o' || option[2] == 'O');
561 if (i < (argc - 1) && argv[i + 1][0] != '-')
562 DDrIniCallback(section, true, option + 1, argv[++i]);
563 else
564 DDrIniCallback(section, true, option + (falseoption ? 3 : 1), (falseoption ? "false" : "true"));
565 *option = '.';
566 }
567 else
568 {
569 falseoption = (section[0] == 'n' || section[0] == 'N') && (section[1] = 'o' || section[1] == 'O');
570 ini_section = s_options;
571 if (i < (argc - 1) && argv[i + 1][0] != '-')
572 DDrIniCallback(NULL, false, section, argv[++i]);
573 else
574 DDrIniCallback(NULL, false, section + (falseoption ? 2 : 0), (falseoption ? "false" : "true"));
575 }
576 }
577 else
578 {
579 DDrStartupMessage("parse error \"%s\"", argv[i]);
580 break;
581 }
582 }
583 DDrStartupMessage("finished parsing");
584 DDrPatch_Init();
585
586 // Safe startup message printer
587 if (patch_safeprintf)
588 DDrPatch_MakeJump(UUrStartupMessage, DDrStartupMessage);
589
590 // Daodan device mode enumeration function
591 if (patch_daodandisplayenum)
592 DDrPatch_MakeJump(gl_enumerate_valid_display_modes, daodan_enumerate_valid_display_modes);
593
594 // Performance patch
595 if (patch_usegettickcount)
596 {
597 DDrPatch_MakeJump(UUrMachineTime_High, DDrMachineTime_High);
598 DDrPatch_MakeJump(UUrMachineTime_High_Frequency, DDrMachineTime_High_Frequency);
599 DDrPatch_MakeJump(UUrMachineTime_Sixtieths, DDrMachineTime_Sixtieths);
600 }
601
602 // Cheats always enabled
603 if (patch_cheatsenabled)
604 DDrPatch_MakeJump(ONrPersist_GetWonGame, DDrPersist_GetWonGame);
605
606 // Windowed mode
607 if (patch_usedaodangl)
608 {
609 DDrPatch_NOOP((char*)0x004032B7, 6);
610 DDrPatch_MakeCall((char*)0x004032B7, LIiP_SetCursorPosHook);
611
612 DDrPatch_NOOP((char*)0x00403349, 6);
613 DDrPatch_MakeCall((char*)0x00403349, LIiP_SetCursorPosHook);
614 DDrPatch_MakeJump(ONrPlatform_Initialize, DDrPlatform_Initialize);
615 DDrPatch_MakeJump(gl_platform_initialize, daodangl_platform_initialize);
616 }
617 // Hacked windowed mode (for when daodangl isn't working properly)
618 else if (patch_windowhack)
619 DDrWindowHack_Install();
620
621 if (patch_daodaninit)
622 DDrPatch_MakeCall(OniExe + 0x000d345a, DDrGame_Init);
623
624 // Patches for existing BSL functions
625 if (patch_bsl)
626 SLrDaodan_Patch();
627
628 if (patch_cheater)
629 {
630 DDrPatch_MakeCall(OniExe + 0x000f618f, DDrCheater);
631 DDrPatch_Int16(OniExe + 0x000deb45, 0x5590);
632#if 0
633 DDrPatch_MakeCall(OniExe + 0x000deb47, FallingFrames);
634#endif
635 DDrPatch_MakeJump(OniExe + 0x0010f021, DDrCheater_LevelLoad);
636 }
637
638 //DDrPatch_MakeJump(0x004378c0, DDrException);
639 DDrPatch_MakeJump(0x004245A0, DDrPrintWarning);
640 //init_daodan_gl();
641
642 ONiMain(argc, argv);
643}
644/*
645void DDrWrongExe()
646{
647 switch (MessageBox(NULL, "This version of the Daodan DLL is incompatible with your Oni.exe.\n"
648 "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))
649 {
650 case IDOK:
651 {
652 STARTUPINFO si;
653 PROCESS_INFORMATION pi;
654 FillMemory(&si, 0, sizeof(si));
655 FillMemory(&pi, 0, sizeof(pi));
656 si.cb = sizeof(si);
657 if (!CreateProcess(NULL, "cmd /c \"start http://wiki.oni2.net/Daodan_DLL\"", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
658 MessageBox(NULL, "", "", 0);
659 CloseHandle(pi.hProcess);
660 CloseHandle(pi.hThread);
661 }
662 default:
663 ExitProcess(0);
664 }
665}
666*/
667BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
668{
669 switch (fdwReason)
670 {
671 case DLL_PROCESS_ATTACH:
672 DDrDLLModule = hinstDLL;
673 DDrONiModule = GetModuleHandle(NULL);
674
675 if (*(uint32_t*)(OniExe + 0x0011acd0) == 0x09d36852)
676 DDrPatch_MakeCall(OniExe + 0x0010fb49, DDrMain);
677 else
678 ExitProcess(0);
679 break;
680 }
681 return TRUE;
682}
Note: See TracBrowser for help on using the repository browser.