--- Daodan/src/Daodan.c 2009/05/28 10:33:59 326 +++ Daodan/src/Daodan.c 2009/06/09 12:00:41 346 @@ -1,19 +1,29 @@ +#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 "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 DDrPatch_Init() { + DDrStartupMessage("patching engine"); + // Font texture cache doubled DDrPatch_Byte (OniExe + 0x00020ea7, 0x20); DDrPatch_Byte (OniExe + 0x00020f4a, 0x40); @@ -64,11 +74,94 @@ bool DDrPatch_Init() // 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.) //DDrPatch_Int16 (OniExe + 0x001b184, 0x9090); + // Multi-byte patch (multiple language support) + 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 + DDrPatch_Int32 (OniExe + 0x000f616b, (int)&DDr_CheatTable[0].name); + DDrPatch_Int32 (OniExe + 0x000f617a, (int)&DDr_CheatTable[0].message_on); + return true; } +enum {s_unknown, s_language} ini_section; + +bool DDrIniCallback(char* section, bool newsection, char* name, char* value) +{ + if (newsection) + { + if (!stricmp(section, "language")) + ini_section = s_language; + else + { + ini_section = s_unknown; + DDrStartupMessage("unrecognised ini section \"%s\"", section); + } + } + + switch (ini_section) + { + case s_language: + if (!stricmp(name, "savepoint")) + { + DDrPatch_StrDup(OniExe + 0x000fd730, value); + DDrPatch_StrDup(OniExe + 0x000fd738, value); + } + else if (!stricmp(name, "syndicatewarehouse")) + { + DDrPatch_StrDup(OniExe + 0x000fd71a, value); + DDrPatch_StrDup(OniExe + 0x0010ef75, value); + } + else if (!stricmp(name, "blam")) + DDrPatch_StrDup(OniExe + 0x0010fb73, 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 __cdecl DDrMain(int argc, char* argv[]) { + DDrStartupMessage("daodan attached!"); + DDrConfig(); DDrPatch_Init(); // Safe startup message printer @@ -82,9 +175,12 @@ void __cdecl DDrMain(int argc, char* arg DDrPatch_MakeJump(UUrMachineTime_High_Frequency, DDrMachineTime_High_Frequency); DDrPatch_MakeJump(UUrMachineTime_Sixtieths, DDrMachineTime_Sixtieths); + // Cheats always enabled + DDrPatch_MakeJump(ONrPersist_GetWonGame, DDrPersist_GetWonGame); + // Windowed mode - DDrPatch_MakeJump(ONrPlatform_Initialize, DDrPlatform_Initialize); - DDrPatch_MakeJump(gl_platform_initialize, daodangl_platform_initialize); +// DDrPatch_MakeJump(ONrPlatform_Initialize, DDrPlatform_Initialize); +// DDrPatch_MakeJump(gl_platform_initialize, daodangl_platform_initialize); init_daodan_gl();