ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/src/Daodan.c
(Generate patch)

Comparing Daodan/src/Daodan.c (file contents):
Revision 342 by rossy, Sat Jun 6 13:23:59 2009 UTC vs.
Revision 473 by gumby, Fri Oct 30 07:41:39 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)