#include #include "Daodan.h" #include "Daodan_Patch.h" #include "Daodan_Utility.h" #include "Daodan_Win32.h" #include "Daodan_Cheater.h" #include "Daodan_Persistence.h" #include "Daodan_BSL.h" #include "Daodan_WindowHack.h" #include "Oni.h" #include "Oni_Persistence.h" #include "BFW_Utility.h" #include "oni_gl.h" #include "daodan_gl.h" #include "inifile.h" HMODULE DDrDLLModule; HMODULE DDrONiModule; bool patch_fonttexturecache = true; bool patch_largetextures = true; bool patch_levelplugins = true; bool patch_pathfinding = true; bool patch_projaware = true; bool patch_directinput = true; bool patch_wpfadetime = true; bool patch_kickguns = false; bool patch_cooldowntimer = true; bool patch_throwtest = false; bool patch_alttab = true; bool patch_particledisablebit = false; bool patch_multibyte = false; bool patch_cheattable = true; bool patch_argb8888 = true; bool patch_safeprintf = true; bool patch_daodandisplayenum = true; bool patch_usegettickcount = true; bool patch_cheatsenabled = true; bool patch_usedaodangl = false; bool patch_windowhack = true; bool patch_daodaninit = true; bool opt_usedaodanbsl = true; bool DDrPatch_Init() { DDrStartupMessage("patching engine"); // Font texture cache doubled if (patch_fonttexturecache) { DDrPatch_Byte (OniExe + 0x00020ea7, 0x20); DDrPatch_Byte (OniExe + 0x00020f4a, 0x40); } // Now supports textures up to 512x512 if (patch_largetextures) DDrPatch_Byte (OniExe + 0x00005251, 0x10); // Non-"_Final" levels are now valid if (patch_levelplugins) DDrPatch_Byte (OniExe + 0x000206a8, 0x01); // Pathfinding grid cache size x8 if (patch_pathfinding) { DDrPatch_Byte (OniExe + 0x0010b03b, 0x20); DDrPatch_Byte (OniExe + 0x0010b04c, 0x20); } // Projectile awareness fixed if (patch_projaware) { DDrPatch_Byte (OniExe + 0x0009c07c, 0x6c); DDrPatch_Byte (OniExe + 0x0009c080, 0x70); DDrPatch_Byte (OniExe + 0x0009c084, 0x74); DDrPatch_Byte (OniExe + 0x0009c110, 0x6c); } // Forced DirectInput (for Windows NT) if (patch_directinput) DDrPatch_Byte (OniExe + 0x00002e6d, 0xeb); if (patch_wpfadetime) { // Makes wp_fadetime actually have a function const char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 }; DDrPatch_Const (OniExe + 0x0011a889, fadetime_patch); DDrPatch_Byte (OniExe + 0x0011a560, 0x31); // Sets the fadetime to 4800 by default DDrPatch_Int16 (OniExe + 0x0011ab0e, 0x12c0); } // Hackish fix for Konoko not kicking guns if (patch_kickguns) { 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 }; DDrPatch_Const (OniExe + 0x000dc420, kickgun_patch); } // Cooldown timer exploit fix ^_^ if (patch_cooldowntimer) { 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 }; DDrPatch_Const (OniExe + 0x0011a825, cooldown_patch); } if (patch_throwtest) { const char throwtest_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }; DDrPatch_Const(OniExe + 0x000dc190, throwtest_patch); } // 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. if (patch_alttab) { DDrPatch_Byte ((void*)UUrPlatform_Initialize, 0xC3); DDrPatch_Byte ((void*)UUrPlatform_Terminate, 0xC3); } // 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.) if (patch_particledisablebit) DDrPatch_Int16 (OniExe + 0x001b184, 0x9090); // Multi-byte patch (multiple language support) if (!patch_multibyte) { DDrPatch_Byte (OniExe + 0x0002d8f8, 0xeb); DDrPatch_Byte (OniExe + 0x0002d9ad, 0xeb); DDrPatch_Byte (OniExe + 0x0002dbe2, 0xeb); DDrPatch_Byte (OniExe + 0x0002dec3, 0xeb); DDrPatch_Byte (OniExe + 0x0002e2ab, 0xeb); DDrPatch_Byte (OniExe + 0x0002e2c4, 0xeb); DDrPatch_Byte (OniExe + 0x0002e379, 0xeb); DDrPatch_Byte (OniExe + 0x0002e48c, 0xeb); DDrPatch_Byte (OniExe + 0x0002e4d0, 0xeb); DDrPatch_Byte (OniExe + 0x0002e4f4, 0xeb); DDrPatch_Byte (OniExe + 0x0002e646, 0xeb); DDrPatch_Byte (OniExe + 0x0002e695, 0xeb); DDrPatch_Byte (OniExe + 0x0002e944, 0xeb); DDrPatch_Byte (OniExe + 0x0002e95d, 0xeb); DDrPatch_Byte (OniExe + 0x0002e98e, 0xeb); DDrPatch_Byte (OniExe + 0x0002e9dc, 0xeb); } // Cheat table patch if (patch_cheattable) { DDrPatch_Int32 (OniExe + 0x000f616b, (int)&DDr_CheatTable[0].name); DDrPatch_Int32 (OniExe + 0x000f617a, (int)&DDr_CheatTable[0].message_on); } if (patch_argb8888) { DDrPatch_Byte (OniExe + 0x00135af0, 0x07); DDrPatch_Byte (OniExe + 0x00135af4, 0x0B); } return true; } enum {s_unknown, s_options, s_patch, s_bsl, s_language} ini_section; bool DDrIniCallback(char* section, bool newsection, char* name, char* value) { if (newsection) { if (!stricmp(section, "options")) ini_section = s_options; else if (!stricmp(section, "patch")) ini_section = s_patch; else if (!stricmp(section, "bsl")) ini_section = s_bsl; else if (!stricmp(section, "language")) ini_section = s_language; else { ini_section = s_unknown; DDrStartupMessage("unrecognised ini section \"%s\"", section); } } switch (ini_section) { case s_options: if (!stricmp(name, "usedaodanbsl")) opt_usedaodanbsl = !stricmp(value, "true"); break; case s_patch: if (!stricmp(name, "fonttexturecache")) patch_fonttexturecache = !stricmp(value, "true"); else if (!stricmp(name, "largetextures")) patch_largetextures = !stricmp(value, "true"); else if (!stricmp(name, "levelplugins")) patch_levelplugins = !stricmp(value, "true"); else if (!stricmp(name, "pathfinding")) patch_pathfinding = !stricmp(value, "true"); else if (!stricmp(name, "projaware")) patch_projaware = !stricmp(value, "true"); else if (!stricmp(name, "directinput")) patch_directinput = !stricmp(value, "true"); else if (!stricmp(name, "wpfadetime")) patch_wpfadetime = !stricmp(value, "true"); else if (!stricmp(name, "kickguns")) patch_kickguns = !stricmp(value, "true"); else if (!stricmp(name, "cooldowntimer")) patch_cooldowntimer = !stricmp(value, "true"); else if (!stricmp(name, "throwtest")) patch_throwtest = !stricmp(value, "true"); else if (!stricmp(name, "alttab")) patch_alttab = !stricmp(value, "true"); else if (!stricmp(name, "particledisablebit")) patch_particledisablebit = !stricmp(value, "true"); else if (!stricmp(name, "multibyte")) patch_multibyte = !stricmp(value, "true"); else if (!stricmp(name, "cheattable")) patch_cheattable = !stricmp(value, "true"); else if (!stricmp(name, "argb8888")) patch_argb8888 = !stricmp(value, "true"); else if (!stricmp(name, "safeprintf")) patch_safeprintf = !stricmp(value, "true"); else if (!stricmp(name, "daodandisplayenum")) patch_daodandisplayenum = !stricmp(value, "true"); else if (!stricmp(name, "usegettickcount")) patch_usegettickcount = !stricmp(value, "true"); else if (!stricmp(name, "cheatsenabled")) patch_cheatsenabled = !stricmp(value, "true"); else if (!stricmp(name, "usedaodangl")) patch_usedaodangl = !stricmp(value, "true"); else if (!stricmp(name, "windowhack")) patch_windowhack = !stricmp(value, "true"); else if (!stricmp(name, "daodaninit")) patch_daodaninit = !stricmp(value, "true"); else DDrStartupMessage("unrecognised patch \"%s\"", name); break; case s_bsl: break; case s_language: if (!stricmp(name, "savepoint")) { char* str = strdup(value); DDrPatch_Int32(OniExe + 0x000fd730, (int)str); DDrPatch_Int32(OniExe + 0x000fd738, (int)str); } else if (!stricmp(name, "syndicatewarehouse")) { char* str = strdup(value); DDrPatch_Int32(OniExe + 0x000fd71a, (int)str); DDrPatch_Int32(OniExe + 0x0010ef75, (int)str); } else if (!stricmp(name, "damn")) DDrPatch_StrDup(OniExe + 0x0010fb6e, value); else if (!stricmp(name, "blam")) DDrPatch_StrDup(OniExe + 0x0010fb73, value); else if (!stricmp(name, "shapeshifter_on")) DDr_CheatTable[0].message_on = strdup(value); else if (!stricmp(name, "shapeshifter_off")) DDr_CheatTable[0].message_off = strdup(value); else if (!stricmp(name, "liveforever_on")) DDr_CheatTable[1].message_on = strdup(value); else if (!stricmp(name, "liveforever_off")) DDr_CheatTable[1].message_off = strdup(value); else if (!stricmp(name, "touchofdeath_on")) DDr_CheatTable[2].message_on = strdup(value); else if (!stricmp(name, "touchofdeath_off")) DDr_CheatTable[2].message_off = strdup(value); else if (!stricmp(name, "canttouchthis_on")) DDr_CheatTable[3].message_on = strdup(value); else if (!stricmp(name, "canttouchthis_off")) DDr_CheatTable[3].message_off = strdup(value); else if (!stricmp(name, "fatloot_on")) DDr_CheatTable[4].message_on = strdup(value); else if (!stricmp(name, "glassworld_on")) DDr_CheatTable[5].message_on = strdup(value); else if (!stricmp(name, "glassworld_off")) DDr_CheatTable[5].message_off = strdup(value); else if (!stricmp(name, "winlevel_on")) DDr_CheatTable[6].message_on = strdup(value); else if (!stricmp(name, "loselevel_on")) DDr_CheatTable[7].message_on = strdup(value); else if (!stricmp(name, "bighead_on")) DDr_CheatTable[8].message_on = strdup(value); else if (!stricmp(name, "bighead_off")) DDr_CheatTable[8].message_off = strdup(value); else if (!stricmp(name, "minime_on")) DDr_CheatTable[9].message_on = strdup(value); else if (!stricmp(name, "minime_off")) DDr_CheatTable[9].message_off = strdup(value); else if (!stricmp(name, "superammo_on")) DDr_CheatTable[10].message_on = strdup(value); else if (!stricmp(name, "superammo_off")) DDr_CheatTable[10].message_off = strdup(value); else if (!stricmp(name, "devmode_on")) { char* str = strdup(value); DDr_CheatTable[11].message_on = str; DDr_CheatTable[cheat_devmodex].message_on = str; } else if (!stricmp(name, "devmode_off")) { char* str = strdup(value); DDr_CheatTable[11].message_off = str; DDr_CheatTable[cheat_devmodex].message_off = str; } else if (!stricmp(name, "reservoirdogs_on")) DDr_CheatTable[12].message_on = strdup(value); else if (!stricmp(name, "reservoirdogs_off")) DDr_CheatTable[12].message_off = strdup(value); else if (!stricmp(name, "roughjustice_on")) DDr_CheatTable[13].message_on = strdup(value); else if (!stricmp(name, "roughjustice_off")) DDr_CheatTable[13].message_off = strdup(value); else if (!stricmp(name, "chenille_on")) DDr_CheatTable[14].message_on = strdup(value); else if (!stricmp(name, "chenille_off")) DDr_CheatTable[14].message_off = strdup(value); else if (!stricmp(name, "behemoth_on")) DDr_CheatTable[15].message_on = strdup(value); else if (!stricmp(name, "behemoth_off")) DDr_CheatTable[15].message_off = strdup(value); else if (!stricmp(name, "elderrune_on")) DDr_CheatTable[16].message_on = strdup(value); else if (!stricmp(name, "elderrune_off")) DDr_CheatTable[16].message_off = strdup(value); else if (!stricmp(name, "moonshadow_on")) DDr_CheatTable[17].message_on = strdup(value); else if (!stricmp(name, "moonshadow_off")) DDr_CheatTable[17].message_off = strdup(value); else if (!stricmp(name, "munitionfrenzy_on")) DDr_CheatTable[18].message_on = strdup(value); else if (!stricmp(name, "fistsoflegend_on")) DDr_CheatTable[19].message_on = strdup(value); else if (!stricmp(name, "fistsoflegend_off")) DDr_CheatTable[19].message_off = strdup(value); else if (!stricmp(name, "killmequick_on")) DDr_CheatTable[20].message_on = strdup(value); else if (!stricmp(name, "killmequick_off")) DDr_CheatTable[20].message_off = strdup(value); else if (!stricmp(name, "carousel_on")) DDr_CheatTable[21].message_on = strdup(value); else if (!stricmp(name, "carousel_off")) DDr_CheatTable[21].message_off = strdup(value); else DDrStartupMessage("unrecognised language item \"%s\"", name); break; default: break; } return true; } void DDrConfig() { if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES) { DDrStartupMessage("daodan.ini doesn't exist, creating"); FILE* fp = fopen("daodan.ini", "w"); if (fp) { fputs("[Options]\n", fp); fclose(fp); } } DDrStartupMessage("parsing daodan.ini..."); if (!inifile_read("daodan.ini", DDrIniCallback)) DDrStartupMessage("error reading daodan.ini, check your syntax!"); DDrStartupMessage("finished parsing"); } void ONICALL DDrGame_Init() { if (opt_usedaodanbsl) SLrDaodan_Initalize(); } void __cdecl DDrMain(int argc, char* argv[]) { DDrStartupMessage("daodan attached!"); DDrConfig(); DDrPatch_Init(); // Safe startup message printer if (patch_safeprintf) DDrPatch_MakeJump(UUrStartupMessage, DDrStartupMessage); // Daodan device mode enumeration function if (patch_daodandisplayenum) DDrPatch_MakeJump(gl_enumerate_valid_display_modes, daodan_enumerate_valid_display_modes); // Performance patch if (patch_usegettickcount) { DDrPatch_MakeJump(UUrMachineTime_High, DDrMachineTime_High); DDrPatch_MakeJump(UUrMachineTime_High_Frequency, DDrMachineTime_High_Frequency); DDrPatch_MakeJump(UUrMachineTime_Sixtieths, DDrMachineTime_Sixtieths); } // Cheats always enabled if (patch_cheatsenabled) DDrPatch_MakeJump(ONrPersist_GetWonGame, DDrPersist_GetWonGame); // Windowed mode if (patch_usedaodangl) { DDrPatch_MakeJump(ONrPlatform_Initialize, DDrPlatform_Initialize); DDrPatch_MakeJump(gl_platform_initialize, daodangl_platform_initialize); } // Hacked windowed mode (for when daodangl isn't working properly) if (patch_windowhack) DDrWindowHack_Install(); if (patch_daodaninit) DDrPatch_MakeCall(OniExe + 0x000d345a, DDrGame_Init); init_daodan_gl(); ONiMain(argc, argv); } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: DDrDLLModule = hinstDLL; DDrONiModule = GetModuleHandle(NULL); DDrPatch_MakeCall(OniExe + 0x0010fb49, DDrMain); break; } return TRUE; }