1 | #include <string.h>
|
---|
2 |
|
---|
3 | #include "Daodan.h"
|
---|
4 | #include "Daodan_Patch.h"
|
---|
5 | #include "Daodan_Utility.h"
|
---|
6 | #include "Daodan_Win32.h"
|
---|
7 | #include "Daodan_Cheater.h"
|
---|
8 | #include "Daodan_Persistence.h"
|
---|
9 |
|
---|
10 | #include "Oni.h"
|
---|
11 | #include "Oni_Persistence.h"
|
---|
12 |
|
---|
13 | #include "BFW_Utility.h"
|
---|
14 |
|
---|
15 | #include "oni_gl.h"
|
---|
16 | #include "daodan_gl.h"
|
---|
17 |
|
---|
18 | #include "inifile.h"
|
---|
19 |
|
---|
20 | HMODULE DDrDLLModule;
|
---|
21 | HMODULE DDrONiModule;
|
---|
22 |
|
---|
23 | bool DDrPatch_Init()
|
---|
24 | {
|
---|
25 | DDrStartupMessage("patching engine");
|
---|
26 |
|
---|
27 | // Font texture cache doubled
|
---|
28 | DDrPatch_Byte (OniExe + 0x00020ea7, 0x20);
|
---|
29 | DDrPatch_Byte (OniExe + 0x00020f4a, 0x40);
|
---|
30 |
|
---|
31 | // Now supports textures up to 512x512
|
---|
32 | DDrPatch_Byte (OniExe + 0x00005251, 0x10);
|
---|
33 |
|
---|
34 | // Non-"_Final" levels are now valid
|
---|
35 | DDrPatch_Byte (OniExe + 0x000206a8, 0x01);
|
---|
36 |
|
---|
37 | // Pathfinding grid cache size x8
|
---|
38 | DDrPatch_Byte (OniExe + 0x0010b03b, 0x20);
|
---|
39 | DDrPatch_Byte (OniExe + 0x0010b04c, 0x20);
|
---|
40 |
|
---|
41 | // Projectile awareness fixed
|
---|
42 | DDrPatch_Byte (OniExe + 0x0009c07c, 0x6c);
|
---|
43 | DDrPatch_Byte (OniExe + 0x0009c080, 0x70);
|
---|
44 | DDrPatch_Byte (OniExe + 0x0009c084, 0x74);
|
---|
45 | DDrPatch_Byte (OniExe + 0x0009c110, 0x6c);
|
---|
46 |
|
---|
47 | // Forced DirectInput (for Windows NT)
|
---|
48 | DDrPatch_Byte (OniExe + 0x00002e6d, 0xeb);
|
---|
49 |
|
---|
50 | // Makes wp_fadetime actually have a function
|
---|
51 | const char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 };
|
---|
52 | DDrPatch_Const (OniExe + 0x0011a889, fadetime_patch);
|
---|
53 | DDrPatch_Byte (OniExe + 0x0011a560, 0x31);
|
---|
54 |
|
---|
55 | // Sets the fadetime to 4800 by default
|
---|
56 | DDrPatch_Int16 (OniExe + 0x0011ab0e, 0x12c0);
|
---|
57 |
|
---|
58 |
|
---|
59 | // Hackish fix for Konoko not kicking guns
|
---|
60 | // 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 };
|
---|
61 | // DDrPatch_Const (OniExe + 0x000dc420, kickgun_patch);
|
---|
62 |
|
---|
63 | // Cooldown timer exploit fix ^_^
|
---|
64 | 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 };
|
---|
65 | DDrPatch_Const (OniExe + 0x0011a825, cooldown_patch);
|
---|
66 |
|
---|
67 | // const char throwtest_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 };
|
---|
68 | // DDrPatch_Const(OniExe + 0x000dc190, throwtest_patch);
|
---|
69 |
|
---|
70 | // 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.
|
---|
71 | DDrPatch_Byte ((void*)UUrPlatform_Initialize, 0xC3);
|
---|
72 | DDrPatch_Byte ((void*)UUrPlatform_Terminate, 0xC3);
|
---|
73 |
|
---|
74 | // 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.)
|
---|
75 | //DDrPatch_Int16 (OniExe + 0x001b184, 0x9090);
|
---|
76 |
|
---|
77 | // Multi-byte patch (multiple language support)
|
---|
78 | DDrPatch_Byte (OniExe + 0x0002d8f8, 0xeb);
|
---|
79 | DDrPatch_Byte (OniExe + 0x0002d9ad, 0xeb);
|
---|
80 | DDrPatch_Byte (OniExe + 0x0002dbe2, 0xeb);
|
---|
81 | DDrPatch_Byte (OniExe + 0x0002dec3, 0xeb);
|
---|
82 | DDrPatch_Byte (OniExe + 0x0002e2ab, 0xeb);
|
---|
83 | DDrPatch_Byte (OniExe + 0x0002e2c4, 0xeb);
|
---|
84 | DDrPatch_Byte (OniExe + 0x0002e379, 0xeb);
|
---|
85 | DDrPatch_Byte (OniExe + 0x0002e48c, 0xeb);
|
---|
86 | DDrPatch_Byte (OniExe + 0x0002e4d0, 0xeb);
|
---|
87 | DDrPatch_Byte (OniExe + 0x0002e4f4, 0xeb);
|
---|
88 | DDrPatch_Byte (OniExe + 0x0002e646, 0xeb);
|
---|
89 | DDrPatch_Byte (OniExe + 0x0002e695, 0xeb);
|
---|
90 | DDrPatch_Byte (OniExe + 0x0002e944, 0xeb);
|
---|
91 | DDrPatch_Byte (OniExe + 0x0002e95d, 0xeb);
|
---|
92 | DDrPatch_Byte (OniExe + 0x0002e98e, 0xeb);
|
---|
93 | DDrPatch_Byte (OniExe + 0x0002e9dc, 0xeb);
|
---|
94 |
|
---|
95 | // Cheat table patch
|
---|
96 | DDrPatch_Int32 (OniExe + 0x000f616b, (int)&DDr_CheatTable[0].name);
|
---|
97 | DDrPatch_Int32 (OniExe + 0x000f617a, (int)&DDr_CheatTable[0].message_on);
|
---|
98 |
|
---|
99 | return true;
|
---|
100 | }
|
---|
101 |
|
---|
102 | enum {s_unknown, s_language} ini_section;
|
---|
103 |
|
---|
104 | bool DDrIniCallback(char* section, bool newsection, char* name, char* value)
|
---|
105 | {
|
---|
106 | if (newsection)
|
---|
107 | {
|
---|
108 | if (!stricmp(section, "language"))
|
---|
109 | ini_section = s_language;
|
---|
110 | else
|
---|
111 | {
|
---|
112 | ini_section = s_unknown;
|
---|
113 | DDrStartupMessage("unrecognised ini section \"%s\"", section);
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | switch (ini_section)
|
---|
118 | {
|
---|
119 | case s_language:
|
---|
120 | if (!stricmp(name, "savepoint"))
|
---|
121 | {
|
---|
122 | DDrPatch_StrDup(OniExe + 0x000fd730, value);
|
---|
123 | DDrPatch_StrDup(OniExe + 0x000fd738, value);
|
---|
124 | }
|
---|
125 | else if (!stricmp(name, "syndicatewarehouse"))
|
---|
126 | {
|
---|
127 | DDrPatch_StrDup(OniExe + 0x000fd71a, value);
|
---|
128 | DDrPatch_StrDup(OniExe + 0x0010ef75, value);
|
---|
129 | }
|
---|
130 | else if (!stricmp(name, "blam"))
|
---|
131 | DDrPatch_StrDup(OniExe + 0x0010fb73, value);
|
---|
132 | else
|
---|
133 | DDrStartupMessage("unrecognised language item \"%s\"", name);
|
---|
134 | break;
|
---|
135 | default:
|
---|
136 | break;
|
---|
137 | }
|
---|
138 |
|
---|
139 | return true;
|
---|
140 | }
|
---|
141 |
|
---|
142 | void DDrConfig()
|
---|
143 | {
|
---|
144 | if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES)
|
---|
145 | {
|
---|
146 | DDrStartupMessage("daodan.ini doesn't exist, creating");
|
---|
147 | FILE* fp = fopen("daodan.ini", "w");
|
---|
148 | if (fp)
|
---|
149 | {
|
---|
150 | fputs("[Options]\n", fp);
|
---|
151 | fclose(fp);
|
---|
152 | }
|
---|
153 | }
|
---|
154 |
|
---|
155 | DDrStartupMessage("parsing daodan.ini...");
|
---|
156 | if (!inifile_read("daodan.ini", DDrIniCallback))
|
---|
157 | DDrStartupMessage("error reading daodan.ini, check your syntax!");
|
---|
158 | DDrStartupMessage("finished parsing");
|
---|
159 | }
|
---|
160 |
|
---|
161 | void __cdecl DDrMain(int argc, char* argv[])
|
---|
162 | {
|
---|
163 | DDrStartupMessage("daodan attached!");
|
---|
164 | DDrConfig();
|
---|
165 | DDrPatch_Init();
|
---|
166 |
|
---|
167 | // Safe startup message printer
|
---|
168 | DDrPatch_MakeJump(UUrStartupMessage, DDrStartupMessage);
|
---|
169 |
|
---|
170 | // Daodan device mode enumeration function
|
---|
171 | DDrPatch_MakeJump(gl_enumerate_valid_display_modes, daodan_enumerate_valid_display_modes);
|
---|
172 |
|
---|
173 | // Performance patch
|
---|
174 | DDrPatch_MakeJump(UUrMachineTime_High, DDrMachineTime_High);
|
---|
175 | DDrPatch_MakeJump(UUrMachineTime_High_Frequency, DDrMachineTime_High_Frequency);
|
---|
176 | DDrPatch_MakeJump(UUrMachineTime_Sixtieths, DDrMachineTime_Sixtieths);
|
---|
177 |
|
---|
178 | // Cheats always enabled
|
---|
179 | DDrPatch_MakeJump(ONrPersist_GetWonGame, DDrPersist_GetWonGame);
|
---|
180 |
|
---|
181 | // Windowed mode
|
---|
182 | // DDrPatch_MakeJump(ONrPlatform_Initialize, DDrPlatform_Initialize);
|
---|
183 | // DDrPatch_MakeJump(gl_platform_initialize, daodangl_platform_initialize);
|
---|
184 |
|
---|
185 | init_daodan_gl();
|
---|
186 |
|
---|
187 | ONiMain(argc, argv);
|
---|
188 | }
|
---|
189 |
|
---|
190 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
|
---|
191 | {
|
---|
192 | switch (fdwReason)
|
---|
193 | {
|
---|
194 | case DLL_PROCESS_ATTACH:
|
---|
195 | DDrDLLModule = hinstDLL;
|
---|
196 | DDrONiModule = GetModuleHandle(NULL);
|
---|
197 |
|
---|
198 | DDrPatch_MakeCall(OniExe + 0x0010fb49, DDrMain);
|
---|
199 |
|
---|
200 | break;
|
---|
201 | }
|
---|
202 | return TRUE;
|
---|
203 | }
|
---|