source: Daodan/src/Daodan.c@ 695

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

Daodan: Fixed gamma ramp thing

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