source: Daodan/src/Daodan.c@ 691

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

Daodan: Cleaning up code (a few comments, old commented out stuff removed), ugly wine-crash fix for DaodanGL

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