ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/MSVC/Daodan.c
Revision: 572
Committed: Sun Aug 29 19:13:47 2010 UTC (15 years, 1 month ago) by gumby
Content type: text/x-csrc
File size: 23358 byte(s)
Log Message:
Stuff

File Contents

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