source: Daodan/src/Daodan.c@ 692

Last change on this file since 692 was 692, checked in by alloc, 12 years ago

Daodan: Lots of cleanups (mostly unnecessary includes removed, empty files deleted, case of filenames corrected)

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