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 |
#include "Daodan_BSL.h" |
10 |
#include "Daodan_Console.h" |
11 |
|
12 |
#include "Daodan_WindowHack.h" |
13 |
|
14 |
#include "Oni.h" |
15 |
#include "Oni_Persistence.h" |
16 |
|
17 |
#include "BFW_Utility.h" |
18 |
|
19 |
#include "oni_gl.h" |
20 |
#include "daodan_gl.h" |
21 |
|
22 |
#include "inifile.h" |
23 |
|
24 |
HMODULE DDrDLLModule; |
25 |
HMODULE DDrONiModule; |
26 |
|
27 |
bool patch_fonttexturecache = true; |
28 |
bool patch_largetextures = true; |
29 |
bool patch_levelplugins = true; |
30 |
bool patch_pathfinding = true; |
31 |
bool patch_projaware = true; |
32 |
bool patch_directinput = true; |
33 |
bool patch_wpfadetime = true; |
34 |
bool patch_kickguns = false; |
35 |
bool patch_cooldowntimer = true; |
36 |
bool patch_throwtest = false; |
37 |
bool patch_alttab = true; |
38 |
bool patch_particledisablebit = false; |
39 |
bool patch_multibyte = false; |
40 |
bool patch_cheattable = true; |
41 |
bool patch_argb8888 = true; |
42 |
bool patch_killvtune = true; |
43 |
bool patch_getcmdline = true; |
44 |
bool patch_disablecmdline = true; |
45 |
|
46 |
bool patch_safeprintf = true; |
47 |
bool patch_daodandisplayenum = true; |
48 |
bool patch_usegettickcount = true; |
49 |
bool patch_cheatsenabled = true; |
50 |
bool patch_usedaodangl = true; |
51 |
bool patch_windowhack = false; |
52 |
bool patch_daodaninit = true; |
53 |
bool patch_bsl = true; |
54 |
bool patch_cheater = true; |
55 |
|
56 |
// bool patch_newweapon = true; |
57 |
|
58 |
bool opt_usedaodanbsl = true; |
59 |
bool opt_border = true; |
60 |
bool opt_shadow = false; |
61 |
bool opt_topmost = false; |
62 |
|
63 |
bool DDrPatch_Init() |
64 |
{ |
65 |
DDrStartupMessage("patching engine"); |
66 |
|
67 |
// Font texture cache doubled |
68 |
if (patch_fonttexturecache) |
69 |
{ |
70 |
DDrPatch_Byte (OniExe + 0x00020ea7, 0x20); |
71 |
DDrPatch_Byte (OniExe + 0x00020f4a, 0x40); |
72 |
} |
73 |
|
74 |
// Now supports textures up to 512x512 |
75 |
if (patch_largetextures) |
76 |
DDrPatch_Byte (OniExe + 0x00005251, 0x10); |
77 |
|
78 |
// Non-"_Final" levels are now valid |
79 |
if (patch_levelplugins) |
80 |
DDrPatch_Byte (OniExe + 0x000206a8, 0x01); |
81 |
|
82 |
// Pathfinding grid cache size x8 |
83 |
if (patch_pathfinding) |
84 |
{ |
85 |
DDrPatch_Byte (OniExe + 0x0010b03b, 0x20); |
86 |
DDrPatch_Byte (OniExe + 0x0010b04c, 0x20); |
87 |
} |
88 |
|
89 |
// Projectile awareness fixed |
90 |
if (patch_projaware) |
91 |
{ |
92 |
DDrPatch_Byte (OniExe + 0x0009c07c, 0x6c); |
93 |
DDrPatch_Byte (OniExe + 0x0009c080, 0x70); |
94 |
DDrPatch_Byte (OniExe + 0x0009c084, 0x74); |
95 |
DDrPatch_Byte (OniExe + 0x0009c110, 0x6c); |
96 |
} |
97 |
|
98 |
// Forced DirectInput (for Windows NT) |
99 |
if (patch_directinput) |
100 |
DDrPatch_Byte (OniExe + 0x00002e6d, 0xeb); |
101 |
|
102 |
if (patch_wpfadetime) |
103 |
{ |
104 |
// Makes wp_fadetime actually have a function |
105 |
const char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 }; |
106 |
DDrPatch_Const (OniExe + 0x0011a889, fadetime_patch); |
107 |
DDrPatch_Byte (OniExe + 0x0011a560, 0x31); |
108 |
|
109 |
// Sets the fadetime to 4800 by default |
110 |
DDrPatch_Int16 (OniExe + 0x0011ab0e, 0x12c0); |
111 |
} |
112 |
|
113 |
|
114 |
// Hackish fix for Konoko not kicking guns |
115 |
if (patch_kickguns) |
116 |
{ |
117 |
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 }; |
118 |
DDrPatch_Const (OniExe + 0x000dc420, kickgun_patch); |
119 |
} |
120 |
|
121 |
// Cooldown timer exploit fix ^_^ |
122 |
if (patch_cooldowntimer) |
123 |
{ |
124 |
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 }; |
125 |
DDrPatch_Const (OniExe + 0x0011a825, cooldown_patch); |
126 |
} |
127 |
|
128 |
if (patch_throwtest) |
129 |
{ |
130 |
const char throwtest_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }; |
131 |
DDrPatch_Const(OniExe + 0x000dc190, throwtest_patch); |
132 |
} |
133 |
|
134 |
// 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. |
135 |
if (patch_alttab) |
136 |
{ |
137 |
DDrPatch_Byte ((void*)UUrPlatform_Initialize, 0xC3); |
138 |
DDrPatch_Byte ((void*)UUrPlatform_Terminate, 0xC3); |
139 |
} |
140 |
|
141 |
// 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.) |
142 |
if (patch_particledisablebit) |
143 |
DDrPatch_Int16 (OniExe + 0x001b184, 0x9090); |
144 |
|
145 |
// Multi-byte patch (multiple language support) |
146 |
if (!patch_multibyte) |
147 |
{ |
148 |
DDrPatch_Byte (OniExe + 0x0002d8f8, 0xeb); |
149 |
DDrPatch_Byte (OniExe + 0x0002d9ad, 0xeb); |
150 |
DDrPatch_Byte (OniExe + 0x0002dbe2, 0xeb); |
151 |
DDrPatch_Byte (OniExe + 0x0002dec3, 0xeb); |
152 |
DDrPatch_Byte (OniExe + 0x0002e2ab, 0xeb); |
153 |
DDrPatch_Byte (OniExe + 0x0002e2c4, 0xeb); |
154 |
DDrPatch_Byte (OniExe + 0x0002e379, 0xeb); |
155 |
DDrPatch_Byte (OniExe + 0x0002e48c, 0xeb); |
156 |
DDrPatch_Byte (OniExe + 0x0002e4d0, 0xeb); |
157 |
DDrPatch_Byte (OniExe + 0x0002e4f4, 0xeb); |
158 |
DDrPatch_Byte (OniExe + 0x0002e646, 0xeb); |
159 |
DDrPatch_Byte (OniExe + 0x0002e695, 0xeb); |
160 |
DDrPatch_Byte (OniExe + 0x0002e944, 0xeb); |
161 |
DDrPatch_Byte (OniExe + 0x0002e95d, 0xeb); |
162 |
DDrPatch_Byte (OniExe + 0x0002e98e, 0xeb); |
163 |
DDrPatch_Byte (OniExe + 0x0002e9dc, 0xeb); |
164 |
} |
165 |
|
166 |
// Cheat table patch |
167 |
if (patch_cheattable) |
168 |
{ |
169 |
DDrPatch_Int32 (OniExe + 0x000f616b, (int)&DDr_CheatTable[0].name); |
170 |
DDrPatch_Int32 (OniExe + 0x000f617a, (int)&DDr_CheatTable[0].message_on); |
171 |
} |
172 |
|
173 |
// ARGB8888 textures |
174 |
if (patch_argb8888) |
175 |
{ |
176 |
DDrPatch_Byte (OniExe + 0x00135af0, 0x07); |
177 |
DDrPatch_Byte (OniExe + 0x00135af4, 0x0B); |
178 |
} |
179 |
|
180 |
//Test newweap patch |
181 |
// if (patch_newweapon) { |
182 |
|
183 |
//Makes it always say "Recieved weapon_name." |
184 |
//Needs check for loc_4DFC66 |
185 |
DDrPatch_NOOP( OniExe + 0x000E4DF8,2); |
186 |
|
187 |
//Adds Weapon name and ammo meter to pickup autoprompt |
188 |
DDrPatch_NOOP( OniExe + 0x000FAC73, 9); |
189 |
DDrPatch_NOOP( OniExe + 0x000FAC80, 5); |
190 |
DDrPatch_MakeCall( OniExe + 0xFAC85, DDrWeapon2Message); |
191 |
|
192 |
//Moves location of colors |
193 |
DDrPatch_Int32( OniExe + 0x0002E3D5, (int)&DDrDSayColors[0].Char ); |
194 |
DDrPatch_Int32( OniExe + 0x0002E3DA, (int)&DDrDSayColors[0].Char ); |
195 |
// } |
196 |
|
197 |
// Disable loading the vtuneapi.dll |
198 |
if (patch_killvtune) |
199 |
DDrPatch_Byte (OniExe + 0x00026340, 0xC3); |
200 |
|
201 |
// Disable Oni's internal CLrGetCommandLine function (to eventually replace it with our own) |
202 |
if (patch_getcmdline) |
203 |
DDrPatch_NOOP (OniExe + 0x000d3280, 51); |
204 |
|
205 |
// Disable Oni's command line parser so it doesn't interfere with ours |
206 |
if (patch_disablecmdline) |
207 |
DDrPatch_Int32 (OniExe + 0x000d3570, 0xc3c03366); |
208 |
|
209 |
return true; |
210 |
} |
211 |
|
212 |
enum {s_unknown, s_options, s_patch, s_bsl, s_language} ini_section; |
213 |
|
214 |
bool DDrIniCallback(char* section, bool newsection, char* name, char* value) |
215 |
{ |
216 |
if (newsection) |
217 |
{ |
218 |
if (!stricmp(section, "options")) |
219 |
ini_section = s_options; |
220 |
else if (!stricmp(section, "patch")) |
221 |
ini_section = s_patch; |
222 |
else if (!stricmp(section, "bsl")) |
223 |
ini_section = s_bsl; |
224 |
else if (!stricmp(section, "language")) |
225 |
ini_section = s_language; |
226 |
else |
227 |
{ |
228 |
ini_section = s_unknown; |
229 |
DDrStartupMessage("unrecognised section \"%s\"", section); |
230 |
} |
231 |
} |
232 |
|
233 |
switch (ini_section) |
234 |
{ |
235 |
case s_options: |
236 |
if (!stricmp(name, "usedaodanbsl")) |
237 |
opt_usedaodanbsl = !stricmp(inifile_cleanstr(value), "true"); |
238 |
else if (!stricmp(name, "border")) |
239 |
opt_border = !stricmp(inifile_cleanstr(value), "true"); |
240 |
else if (!stricmp(name, "shadow")) |
241 |
opt_shadow = !stricmp(inifile_cleanstr(value), "true"); |
242 |
else if (!stricmp(name, "topmost")) |
243 |
opt_topmost = !stricmp(inifile_cleanstr(value), "true"); |
244 |
else if (!stricmp(name, "multibyte")) |
245 |
patch_multibyte = !stricmp(inifile_cleanstr(value), "true"); |
246 |
else if (!stricmp(name, "debug")) |
247 |
AKgDebug_DebugMaps = !stricmp(inifile_cleanstr(value), "true"); |
248 |
else if (!stricmp(name, "debugfiles")) |
249 |
BFgDebugFileEnable = !stricmp(inifile_cleanstr(value), "true"); |
250 |
else if (!stricmp(name, "findsounds")) |
251 |
SSgSearchOnDisk = !stricmp(inifile_cleanstr(value), "true"); |
252 |
else if (!stricmp(name, "ignore_private_data")) |
253 |
opt_ignore_private_data = !stricmp(inifile_cleanstr(value), "true"); |
254 |
else if (!stricmp(name, "sound")) |
255 |
opt_sound = !stricmp(inifile_cleanstr(value), "true"); |
256 |
else if (!stricmp(name, "switch")) |
257 |
M3gResolutionSwitch = !stricmp(inifile_cleanstr(value), "true"); |
258 |
else |
259 |
DDrStartupMessage("unrecognised option \"%s\"", name); |
260 |
break; |
261 |
case s_patch: |
262 |
if (!stricmp(name, "fonttexturecache")) |
263 |
patch_fonttexturecache = !stricmp(inifile_cleanstr(value), "true"); |
264 |
else if (!stricmp(name, "largetextures")) |
265 |
patch_largetextures = !stricmp(inifile_cleanstr(value), "true"); |
266 |
else if (!stricmp(name, "levelplugins")) |
267 |
patch_levelplugins = !stricmp(inifile_cleanstr(value), "true"); |
268 |
else if (!stricmp(name, "pathfinding")) |
269 |
patch_pathfinding = !stricmp(inifile_cleanstr(value), "true"); |
270 |
else if (!stricmp(name, "projaware")) |
271 |
patch_projaware = !stricmp(inifile_cleanstr(value), "true"); |
272 |
else if (!stricmp(name, "directinput")) |
273 |
patch_directinput = !stricmp(inifile_cleanstr(value), "true"); |
274 |
else if (!stricmp(name, "wpfadetime")) |
275 |
patch_wpfadetime = !stricmp(inifile_cleanstr(value), "true"); |
276 |
else if (!stricmp(name, "kickguns")) |
277 |
patch_kickguns = !stricmp(inifile_cleanstr(value), "true"); |
278 |
else if (!stricmp(name, "cooldowntimer")) |
279 |
patch_cooldowntimer = !stricmp(inifile_cleanstr(value), "true"); |
280 |
else if (!stricmp(name, "throwtest")) |
281 |
patch_throwtest = !stricmp(inifile_cleanstr(value), "true"); |
282 |
else if (!stricmp(name, "alttab")) |
283 |
patch_alttab = !stricmp(inifile_cleanstr(value), "true"); |
284 |
else if (!stricmp(name, "particledisablebit")) |
285 |
patch_particledisablebit = !stricmp(inifile_cleanstr(value), "true"); |
286 |
else if (!stricmp(name, "multibyte")) |
287 |
patch_multibyte = !stricmp(inifile_cleanstr(value), "true"); |
288 |
else if (!stricmp(name, "cheattable")) |
289 |
patch_cheattable = !stricmp(inifile_cleanstr(value), "true"); |
290 |
else if (!stricmp(name, "argb8888")) |
291 |
patch_argb8888 = !stricmp(inifile_cleanstr(value), "true"); |
292 |
else if (!stricmp(name, "killvtune")) |
293 |
patch_killvtune = !stricmp(inifile_cleanstr(value), "true"); |
294 |
else if (!stricmp(name, "getcmdline")) |
295 |
patch_getcmdline = !stricmp(inifile_cleanstr(value), "true"); |
296 |
else if (!stricmp(name, "disablecmdline")) |
297 |
patch_disablecmdline = !stricmp(inifile_cleanstr(value), "true"); |
298 |
else if (!stricmp(name, "safeprintf")) |
299 |
patch_safeprintf = !stricmp(inifile_cleanstr(value), "true"); |
300 |
else if (!stricmp(name, "daodandisplayenum")) |
301 |
patch_daodandisplayenum = !stricmp(inifile_cleanstr(value), "true"); |
302 |
else if (!stricmp(name, "usegettickcount")) |
303 |
patch_usegettickcount = !stricmp(inifile_cleanstr(value), "true"); |
304 |
else if (!stricmp(name, "cheatsenabled")) |
305 |
patch_cheatsenabled = !stricmp(inifile_cleanstr(value), "true"); |
306 |
else if (!stricmp(name, "usedaodangl")) |
307 |
patch_usedaodangl = !stricmp(inifile_cleanstr(value), "true"); |
308 |
else if (!stricmp(name, "windowhack")) |
309 |
patch_windowhack = !stricmp(inifile_cleanstr(value), "true"); |
310 |
else if (!stricmp(name, "daodaninit")) |
311 |
patch_daodaninit = !stricmp(inifile_cleanstr(value), "true"); |
312 |
else if (!stricmp(name, "bsl")) |
313 |
patch_bsl = !stricmp(inifile_cleanstr(value), "true"); |
314 |
else if (!stricmp(name, "cheater")) |
315 |
patch_cheater = !stricmp(inifile_cleanstr(value), "true"); |
316 |
else |
317 |
DDrStartupMessage("unrecognised patch \"%s\"", name); |
318 |
break; |
319 |
case s_language: |
320 |
if (!stricmp(name, "savepoint")) |
321 |
{ |
322 |
char* str = strdup(value); |
323 |
DDrPatch_Int32(OniExe + 0x000fd730, (int)str); |
324 |
DDrPatch_Int32(OniExe + 0x000fd738, (int)str); |
325 |
} |
326 |
else if (!stricmp(name, "syndicatewarehouse")) |
327 |
{ |
328 |
char* str = strdup(value); |
329 |
DDrPatch_Int32(OniExe + 0x000fd71a, (int)str); |
330 |
DDrPatch_Int32(OniExe + 0x0010ef75, (int)str); |
331 |
} |
332 |
else if (!stricmp(name, "damn")) |
333 |
DDrPatch_StrDup(OniExe + 0x0010fb6e, value); |
334 |
else if (!stricmp(name, "blam")) |
335 |
DDrPatch_StrDup(OniExe + 0x0010fb73, value); |
336 |
else if (!stricmp(name, "shapeshifter_on")) |
337 |
DDr_CheatTable[0].message_on = strdup(value); |
338 |
else if (!stricmp(name, "shapeshifter_off")) |
339 |
DDr_CheatTable[0].message_off = strdup(value); |
340 |
else if (!stricmp(name, "liveforever_on")) |
341 |
DDr_CheatTable[1].message_on = strdup(value); |
342 |
else if (!stricmp(name, "liveforever_off")) |
343 |
DDr_CheatTable[1].message_off = strdup(value); |
344 |
else if (!stricmp(name, "touchofdeath_on")) |
345 |
DDr_CheatTable[2].message_on = strdup(value); |
346 |
else if (!stricmp(name, "touchofdeath_off")) |
347 |
DDr_CheatTable[2].message_off = strdup(value); |
348 |
else if (!stricmp(name, "canttouchthis_on")) |
349 |
DDr_CheatTable[3].message_on = strdup(value); |
350 |
else if (!stricmp(name, "canttouchthis_off")) |
351 |
DDr_CheatTable[3].message_off = strdup(value); |
352 |
else if (!stricmp(name, "fatloot_on")) |
353 |
DDr_CheatTable[4].message_on = strdup(value); |
354 |
else if (!stricmp(name, "glassworld_on")) |
355 |
DDr_CheatTable[5].message_on = strdup(value); |
356 |
else if (!stricmp(name, "glassworld_off")) |
357 |
DDr_CheatTable[5].message_off = strdup(value); |
358 |
else if (!stricmp(name, "winlevel_on")) |
359 |
DDr_CheatTable[6].message_on = strdup(value); |
360 |
else if (!stricmp(name, "loselevel_on")) |
361 |
DDr_CheatTable[7].message_on = strdup(value); |
362 |
else if (!stricmp(name, "bighead_on")) |
363 |
DDr_CheatTable[8].message_on = strdup(value); |
364 |
else if (!stricmp(name, "bighead_off")) |
365 |
DDr_CheatTable[8].message_off = strdup(value); |
366 |
else if (!stricmp(name, "minime_on")) |
367 |
DDr_CheatTable[9].message_on = strdup(value); |
368 |
else if (!stricmp(name, "minime_off")) |
369 |
DDr_CheatTable[9].message_off = strdup(value); |
370 |
else if (!stricmp(name, "superammo_on")) |
371 |
DDr_CheatTable[10].message_on = strdup(value); |
372 |
else if (!stricmp(name, "superammo_off")) |
373 |
DDr_CheatTable[10].message_off = strdup(value); |
374 |
else if (!stricmp(name, "devmode_on")) |
375 |
{ |
376 |
char* str = strdup(value); |
377 |
DDr_CheatTable[11].message_on = str; |
378 |
DDr_CheatTable[cheat_x].message_on = str; |
379 |
} |
380 |
else if (!stricmp(name, "devmode_off")) |
381 |
{ |
382 |
char* str = strdup(value); |
383 |
DDr_CheatTable[11].message_off = str; |
384 |
DDr_CheatTable[cheat_x].message_off = str; |
385 |
} |
386 |
else if (!stricmp(name, "reservoirdogs_on")) |
387 |
DDr_CheatTable[12].message_on = strdup(value); |
388 |
else if (!stricmp(name, "reservoirdogs_off")) |
389 |
DDr_CheatTable[12].message_off = strdup(value); |
390 |
else if (!stricmp(name, "roughjustice_on")) |
391 |
DDr_CheatTable[13].message_on = strdup(value); |
392 |
else if (!stricmp(name, "roughjustice_off")) |
393 |
DDr_CheatTable[13].message_off = strdup(value); |
394 |
else if (!stricmp(name, "chenille_on")) |
395 |
DDr_CheatTable[14].message_on = strdup(value); |
396 |
else if (!stricmp(name, "chenille_off")) |
397 |
DDr_CheatTable[14].message_off = strdup(value); |
398 |
else if (!stricmp(name, "behemoth_on")) |
399 |
DDr_CheatTable[15].message_on = strdup(value); |
400 |
else if (!stricmp(name, "behemoth_off")) |
401 |
DDr_CheatTable[15].message_off = strdup(value); |
402 |
else if (!stricmp(name, "elderrune_on")) |
403 |
DDr_CheatTable[16].message_on = strdup(value); |
404 |
else if (!stricmp(name, "elderrune_off")) |
405 |
DDr_CheatTable[16].message_off = strdup(value); |
406 |
else if (!stricmp(name, "moonshadow_on")) |
407 |
DDr_CheatTable[17].message_on = strdup(value); |
408 |
else if (!stricmp(name, "moonshadow_off")) |
409 |
DDr_CheatTable[17].message_off = strdup(value); |
410 |
else if (!stricmp(name, "munitionfrenzy_on")) |
411 |
DDr_CheatTable[18].message_on = strdup(value); |
412 |
else if (!stricmp(name, "fistsoflegend_on")) |
413 |
DDr_CheatTable[19].message_on = strdup(value); |
414 |
else if (!stricmp(name, "fistsoflegend_off")) |
415 |
DDr_CheatTable[19].message_off = strdup(value); |
416 |
else if (!stricmp(name, "killmequick_on")) |
417 |
DDr_CheatTable[20].message_on = strdup(value); |
418 |
else if (!stricmp(name, "killmequick_off")) |
419 |
DDr_CheatTable[20].message_off = strdup(value); |
420 |
else if (!stricmp(name, "carousel_on")) |
421 |
DDr_CheatTable[21].message_on = strdup(value); |
422 |
else if (!stricmp(name, "carousel_off")) |
423 |
DDr_CheatTable[21].message_off = strdup(value); |
424 |
else |
425 |
DDrStartupMessage("unrecognised language item \"%s\"", name); |
426 |
break; |
427 |
case s_bsl: |
428 |
default: |
429 |
break; |
430 |
} |
431 |
|
432 |
return true; |
433 |
} |
434 |
|
435 |
void DDrConfig() |
436 |
{ |
437 |
if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES) |
438 |
{ |
439 |
DDrStartupMessage("daodan.ini doesn't exist, creating"); |
440 |
FILE* fp = fopen("daodan.ini", "w"); |
441 |
if (fp) |
442 |
{ |
443 |
fputs("[Options]\n", fp); |
444 |
fclose(fp); |
445 |
} |
446 |
} |
447 |
|
448 |
DDrStartupMessage("parsing daodan.ini..."); |
449 |
if (!inifile_read("daodan.ini", DDrIniCallback)) |
450 |
DDrStartupMessage("error reading daodan.ini, check your syntax!"); |
451 |
DDrStartupMessage("finished parsing"); |
452 |
} |
453 |
|
454 |
void ONICALL DDrGame_Init() |
455 |
{ |
456 |
if (opt_usedaodanbsl) |
457 |
SLrDaodan_Initalize(); |
458 |
} |
459 |
|
460 |
void __cdecl DDrMain(int argc, char* argv[]) |
461 |
{ |
462 |
DDrStartupMessage("daodan attached!"); |
463 |
|
464 |
opt_ignore_private_data = false; |
465 |
opt_sound = true; |
466 |
|
467 |
DDrConfig(); |
468 |
DDrStartupMessage("parsing command line..."); |
469 |
int i; |
470 |
char* section; |
471 |
char* option; |
472 |
bool falseoption; |
473 |
for (i = 1; i < argc; i ++) |
474 |
{ |
475 |
if (argv[i][0] == '-') |
476 |
{ |
477 |
section = argv[i] + 1; |
478 |
if ((option = strchr(argv[i], '.'))) |
479 |
{ |
480 |
*option = '\0'; |
481 |
falseoption = (option[1] == 'n' || option[1] == 'N') && (option[2] = 'o' || option[2] == 'O'); |
482 |
if (i < (argc - 1) && argv[i + 1][0] != '-') |
483 |
DDrIniCallback(section, true, option + 1, argv[++i]); |
484 |
else |
485 |
DDrIniCallback(section, true, option + (falseoption ? 3 : 1), (falseoption ? "false" : "true")); |
486 |
*option = '.'; |
487 |
} |
488 |
else |
489 |
{ |
490 |
falseoption = (section[0] == 'n' || section[0] == 'N') && (section[1] = 'o' || section[1] == 'O'); |
491 |
ini_section = s_options; |
492 |
if (i < (argc - 1) && argv[i + 1][0] != '-') |
493 |
DDrIniCallback(NULL, false, section, argv[++i]); |
494 |
else |
495 |
DDrIniCallback(NULL, false, section + (falseoption ? 2 : 0), (falseoption ? "false" : "true")); |
496 |
} |
497 |
} |
498 |
else |
499 |
{ |
500 |
DDrStartupMessage("parse error \"%s\"", argv[i]); |
501 |
break; |
502 |
} |
503 |
} |
504 |
DDrStartupMessage("finished parsing"); |
505 |
DDrPatch_Init(); |
506 |
|
507 |
// Safe startup message printer |
508 |
if (patch_safeprintf) |
509 |
DDrPatch_MakeJump(UUrStartupMessage, DDrStartupMessage); |
510 |
|
511 |
// Daodan device mode enumeration function |
512 |
if (patch_daodandisplayenum) |
513 |
DDrPatch_MakeJump(gl_enumerate_valid_display_modes, daodan_enumerate_valid_display_modes); |
514 |
|
515 |
// Performance patch |
516 |
if (patch_usegettickcount) |
517 |
{ |
518 |
DDrPatch_MakeJump(UUrMachineTime_High, DDrMachineTime_High); |
519 |
DDrPatch_MakeJump(UUrMachineTime_High_Frequency, DDrMachineTime_High_Frequency); |
520 |
DDrPatch_MakeJump(UUrMachineTime_Sixtieths, DDrMachineTime_Sixtieths); |
521 |
} |
522 |
|
523 |
// Cheats always enabled |
524 |
if (patch_cheatsenabled) |
525 |
DDrPatch_MakeJump(ONrPersist_GetWonGame, DDrPersist_GetWonGame); |
526 |
|
527 |
// Windowed mode |
528 |
if (patch_usedaodangl) |
529 |
{ |
530 |
DDrPatch_MakeJump(ONrPlatform_Initialize, DDrPlatform_Initialize); |
531 |
DDrPatch_MakeJump(gl_platform_initialize, daodangl_platform_initialize); |
532 |
} |
533 |
|
534 |
// Hacked windowed mode (for when daodangl isn't working properly) |
535 |
if (patch_windowhack) |
536 |
DDrWindowHack_Install(); |
537 |
|
538 |
if (patch_daodaninit) |
539 |
DDrPatch_MakeCall(OniExe + 0x000d345a, DDrGame_Init); |
540 |
|
541 |
// Patches for existing BSL functions |
542 |
if (patch_bsl) |
543 |
SLrDaodan_Patch(); |
544 |
|
545 |
if (patch_cheater) |
546 |
{ |
547 |
DDrPatch_MakeCall(OniExe + 0x000f618f, DDrCheater); |
548 |
DDrPatch_Int16(OniExe + 0x000deb45, 0x5590); |
549 |
DDrPatch_MakeCall(OniExe + 0x000deb47, FallingFrames); |
550 |
DDrPatch_MakeJump(OniExe + 0x0010f021, DDrCheater_LevelLoad); |
551 |
} |
552 |
|
553 |
init_daodan_gl(); |
554 |
|
555 |
ONiMain(argc, argv); |
556 |
} |
557 |
/* |
558 |
void DDrWrongExe() |
559 |
{ |
560 |
switch (MessageBox(NULL, "This version of the Daodan DLL is incompatible with your Oni.exe.\n" |
561 |
"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)) |
562 |
{ |
563 |
case IDOK: |
564 |
{ |
565 |
STARTUPINFO si; |
566 |
PROCESS_INFORMATION pi; |
567 |
FillMemory(&si, 0, sizeof(si)); |
568 |
FillMemory(&pi, 0, sizeof(pi)); |
569 |
si.cb = sizeof(si); |
570 |
if (!CreateProcess(NULL, "cmd /c \"start http://wiki.oni2.net/Daodan_DLL\"", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) |
571 |
MessageBox(NULL, "", "", 0); |
572 |
CloseHandle(pi.hProcess); |
573 |
CloseHandle(pi.hThread); |
574 |
} |
575 |
default: |
576 |
ExitProcess(0); |
577 |
} |
578 |
} |
579 |
*/ |
580 |
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) |
581 |
{ |
582 |
switch (fdwReason) |
583 |
{ |
584 |
case DLL_PROCESS_ATTACH: |
585 |
DDrDLLModule = hinstDLL; |
586 |
DDrONiModule = GetModuleHandle(NULL); |
587 |
|
588 |
if (*(uint32_t*)((void*)OniExe + 0x0011acd0) == 0x09d36852) |
589 |
DDrPatch_MakeCall(OniExe + 0x0010fb49, DDrMain); |
590 |
else |
591 |
ExitProcess(0); |
592 |
break; |
593 |
} |
594 |
return TRUE; |
595 |
} |