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 466 by rossy, Sat Oct 17 11:49:49 2009 UTC vs.
Revision 838 by alloc, Mon Apr 29 16:29:16 2013 UTC

# Line 1 | Line 1
1 + #include <windows.h>
2   #include <string.h>
3 + #include <stdio.h>
4  
5   #include "Daodan.h"
6   #include "Daodan_Patch.h"
# Line 7 | Line 9
9   #include "Daodan_Cheater.h"
10   #include "Daodan_Persistence.h"
11   #include "Daodan_BSL.h"
12 <
13 < #include "Daodan_WindowHack.h"
12 > #include "Daodan_Console.h"
13 > #include "Daodan_Config.h"
14  
15   #include "Oni.h"
14 #include "Oni_Persistence.h"
15
16 #include "BFW_Utility.h"
17
18 #include "oni_gl.h"
19 #include "daodan_gl.h"
16  
17 < #include "inifile.h"
17 > #include "Oni_GL.h"
18 > #include "Daodan_GL.h"
19  
20   HMODULE DDrDLLModule;
21   HMODULE DDrONiModule;
22  
23 < bool patch_fonttexturecache = true;
24 < bool patch_largetextures = true;
25 < bool patch_levelplugins = true;
26 < bool patch_pathfinding = true;
27 < bool patch_projaware = true;
28 < bool patch_directinput = true;
29 < bool patch_wpfadetime = true;
30 < bool patch_kickguns = false;
31 < bool patch_cooldowntimer = true;
32 < bool patch_throwtest = false;
33 < bool patch_alttab = true;
34 < bool patch_particledisablebit = false;
35 < bool patch_multibyte = false;
36 < bool patch_cheattable = true;
37 < bool patch_argb8888 = true;
38 < bool patch_killvtune = true;
39 < bool patch_getcmdline = true;
40 < bool patch_disablecmdline = true;
41 <
42 < bool patch_safeprintf = true;
43 < bool patch_daodandisplayenum = true;
44 < bool patch_usegettickcount = true;
45 < bool patch_cheatsenabled = true;
46 < bool patch_usedaodangl = false;
47 < bool patch_windowhack = true;
48 < bool patch_daodaninit = true;
49 < bool patch_bsl = true;
50 < bool patch_cheater = true;
23 > typedef int (__cdecl *CHINESEPROC)(DWORD ThreadId);
24 >
25 > // Hooked WMrSlider_SetRange() in ONiOGU_Options_InitDialog. Disables a gamma
26 > // slider in windowed mode.
27 > static void ONICALL DD_ONiOGU_GammaSlider_SetRange(WMtWindow* window, int min_value, int max_value)
28 > {
29 >        WMrWindow_SetEnabled(window, M3gResolutionSwitch && opt_gamma);
30 >        WMrSlider_SetRange(window, min_value, max_value);
31 > }
32 >
33 > void ONICALL DDrShowResumeButton(WMtWindow* window, int visibility)
34 > {
35 >        if (visibility)
36 >                WMrWindow_SetLocation(window, 150, 350);
37 >        WMrWindow_SetVisible(window, visibility);
38 > }
39 >
40 >
41 > /* Options always visible patch */
42 > void ONICALL DDrShowOptionsButton(WMtWindow* window, int visibility)
43 > {
44 >        WMrWindow_SetVisible(window, 1);
45 > }
46 >
47 > void ONICALL DDrGame_Init()
48 > {
49 >        if (opt_usedaodanbsl)
50 >                SLrDaodan_Initialize();
51 > }
52 >
53 >
54 > //this was broken
55 > FILE** _UUgError_WarningFile = (FILE**)0x005711B4;
56 > FILE *__fastcall DDrPrintWarning(int filename, int linenumber, unsigned __int16 errornum, int message)
57 > {
58 >
59 >        FILE *v4; // eax@1
60 >        FILE *result; // eax@4
61 >        char v6[512]; // [sp+0h] [bp-100h]@1
62 >        FILE* UUgError_WarningFile = *_UUgError_WarningFile;
63 >
64 >        if (filename && message && (strlen((const char*)filename)+strlen((const char*)message))<420) {
65 >                sprintf(
66 >                        v6,
67 >                        "Error %x reported from File: %s, Line: %d (message follows) \r\n%s",
68 >                        errornum,
69 >                        (const char*)filename,
70 >                        linenumber,
71 >                        (const char*)message);
72 >
73 >                if ( UUgError_WarningFile
74 >                        || (UUgError_WarningFile = oni_fopen("debugger.txt", "wb"), UUgError_WarningFile ) )
75 >                {
76 >                        oni_fprintf(UUgError_WarningFile, "%s\r\n", v6);
77 >                        oni_fflush(UUgError_WarningFile);
78 >                }
79 >        }
80 >        //oni_fprintf(stdout, v6);
81 >        //sprintf(&v6, "%s", message);
82 >        *_UUgError_WarningFile = UUgError_WarningFile;
83 >        result = UUgError_WarningFile;
84 >        return result;
85 > }
86  
55 bool opt_usedaodanbsl = true;
87  
88   bool DDrPatch_Init()
89   {
90 <        DDrStartupMessage("patching engine");
90 >        DDrStartupMessage("Daodan: Patching engine");
91          
92          // Font texture cache doubled
93          if (patch_fonttexturecache)
94          {
95 <                DDrPatch_Byte  (OniExe + 0x00020ea7, 0x20);
96 <                DDrPatch_Byte  (OniExe + 0x00020f4a, 0x40);
95 >                DDrPatch_Byte((char*)(OniExe + 0x00020ea7), 0x20);
96 >                DDrPatch_Byte((char*)(OniExe + 0x00020f4a), 0x40);
97          }
98          
99          // Now supports textures up to 512x512
100          if (patch_largetextures)
101 <                DDrPatch_Byte  (OniExe + 0x00005251, 0x10);
101 >                DDrPatch_Byte  ((char*)(OniExe + 0x00005251), 0x10);
102          
103          // Non-"_Final" levels are now valid
104          if (patch_levelplugins)
105 <                DDrPatch_Byte  (OniExe + 0x000206a8, 0x01);
105 >                DDrPatch_Byte  ((char*)(OniExe + 0x000206a8), 0x01);
106          
107          // Pathfinding grid cache size x8
108          if (patch_pathfinding)
109          {
110 <                DDrPatch_Byte  (OniExe + 0x0010b03b, 0x20);
111 <                DDrPatch_Byte  (OniExe + 0x0010b04c, 0x20);
110 >                const unsigned char pathfinding[2] = {0x90 , 0xE9 };
111 >                DDrPatch_Byte  ((char*)(OniExe + 0x0010b03b), 0x20);
112 >                DDrPatch_Byte  ((char*)(OniExe + 0x0010b04c), 0x20);
113 >
114 >                //other stuff
115 >                DDrPatch_Const((char*)(OniExe + 0x00040789), pathfinding);
116          }
117          
118          // Projectile awareness fixed
119          if (patch_projaware)
120          {
121 <                DDrPatch_Byte  (OniExe + 0x0009c07c, 0x6c);
122 <                DDrPatch_Byte  (OniExe + 0x0009c080, 0x70);
123 <                DDrPatch_Byte  (OniExe + 0x0009c084, 0x74);
124 <                DDrPatch_Byte  (OniExe + 0x0009c110, 0x6c);
121 >                DDrPatch_Byte  ((char*)(OniExe + 0x0009c07c), 0x6c);
122 >                DDrPatch_Byte  ((char*)(OniExe + 0x0009c080), 0x70);
123 >                DDrPatch_Byte  ((char*)(OniExe + 0x0009c084), 0x74);
124 >                DDrPatch_Byte  ((char*)(OniExe + 0x0009c110), 0x6c);
125          }
126          
127          // Forced DirectInput (for Windows NT)
128          if (patch_directinput)
129 <                DDrPatch_Byte  (OniExe + 0x00002e6d, 0xeb);
130 <        
129 >                DDrPatch_Byte((char*)(OniExe + 0x00002e6d), 0xeb);
130 >
131          if (patch_wpfadetime)
132          {
133                  // Makes wp_fadetime actually have a function
134 <                const char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 };
135 <                DDrPatch_Const (OniExe + 0x0011a889, fadetime_patch);
136 <                DDrPatch_Byte  (OniExe + 0x0011a560, 0x31);
134 >                const unsigned char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 };
135 >                DDrPatch_Const ((char*)(OniExe + 0x0011a889), fadetime_patch);
136 >                DDrPatch_Byte  ((char*)(OniExe + 0x0011a560), 0x31);
137                  
138                  // Sets the fadetime to 4800 by default
139 <                DDrPatch_Int16 (OniExe + 0x0011ab0e, 0x12c0);
139 >                DDrPatch_Int16 ((short*)(OniExe + 0x0011ab0e), 0x12c0);
140          }
141          
142 +        // FIXME: add switches
143 +        //pathfinding fix
144 +
145 +        
146 +
147          
148          // Hackish fix for Konoko not kicking guns
149 +        // Don't use this, it breaks stairs.
150          if (patch_kickguns)
151          {
152 <                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 };
153 <                DDrPatch_Const (OniExe + 0x000dc420, kickgun_patch);
152 >                const unsigned 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 };
153 >                DDrPatch_Const ((char*)(OniExe + 0x000dc420), kickgun_patch);
154          }
155          
156          // Cooldown timer exploit fix ^_^
157          if (patch_cooldowntimer)
158          {
159 <                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 };
160 <                DDrPatch_Const (OniExe + 0x0011a825, cooldown_patch);
159 >                const unsigned 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 };
160 >                DDrPatch_Const ((char*)(OniExe + 0x0011a825), cooldown_patch);
161          }
162          
163          if (patch_throwtest)
164          {
165 <                const char throwtest_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 };
166 <                DDrPatch_Const(OniExe + 0x000dc190, throwtest_patch);
165 >                const unsigned char throwtest_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 };
166 >                DDrPatch_Const((char*)(OniExe + 0x000dc190), throwtest_patch);
167          }
168          
169          // 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.
170          if (patch_alttab)
171          {
172 <                DDrPatch_Byte  ((void*)UUrPlatform_Initialize, 0xC3);
173 <                DDrPatch_Byte  ((void*)UUrPlatform_Terminate, 0xC3);
172 >                // 0xC3 = ret, so makes those functions just have a "ret" instruction at their start
173 >                DDrPatch_Byte  ((char*)UUrPlatform_Initialize, 0xC3);
174 >                DDrPatch_Byte  ((char*)UUrPlatform_Terminate, 0xC3);
175          }
176          
177          // 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.)
178          if (patch_particledisablebit)
179 <                DDrPatch_Int16 (OniExe + 0x001b184, 0x9090);
179 >                DDrPatch_Int16 ((short*)(OniExe + 0x001b184), 0x9090);
180          
181          // Multi-byte patch (multiple language support)
182          if (!patch_multibyte)
183          {
184 <                DDrPatch_Byte  (OniExe + 0x0002d8f8, 0xeb);
185 <                DDrPatch_Byte  (OniExe + 0x0002d9ad, 0xeb);
186 <                DDrPatch_Byte  (OniExe + 0x0002dbe2, 0xeb);
187 <                DDrPatch_Byte  (OniExe + 0x0002dec3, 0xeb);
188 <                DDrPatch_Byte  (OniExe + 0x0002e2ab, 0xeb);
189 <                DDrPatch_Byte  (OniExe + 0x0002e2c4, 0xeb);
190 <                DDrPatch_Byte  (OniExe + 0x0002e379, 0xeb);
191 <                DDrPatch_Byte  (OniExe + 0x0002e48c, 0xeb);
192 <                DDrPatch_Byte  (OniExe + 0x0002e4d0, 0xeb);
193 <                DDrPatch_Byte  (OniExe + 0x0002e4f4, 0xeb);
194 <                DDrPatch_Byte  (OniExe + 0x0002e646, 0xeb);
195 <                DDrPatch_Byte  (OniExe + 0x0002e695, 0xeb);
196 <                DDrPatch_Byte  (OniExe + 0x0002e944, 0xeb);
197 <                DDrPatch_Byte  (OniExe + 0x0002e95d, 0xeb);
198 <                DDrPatch_Byte  (OniExe + 0x0002e98e, 0xeb);
199 <                DDrPatch_Byte  (OniExe + 0x0002e9dc, 0xeb);
184 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002d8f8), 0xeb);
185 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002d9ad), 0xeb);
186 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002dbe2), 0xeb);
187 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002dec3), 0xeb);
188 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e2ab), 0xeb);
189 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e2c4), 0xeb);
190 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e379), 0xeb);
191 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e48c), 0xeb);
192 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e4d0), 0xeb);
193 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e4f4), 0xeb);
194 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e646), 0xeb);
195 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e695), 0xeb);
196 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e944), 0xeb);
197 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e95d), 0xeb);
198 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e98e), 0xeb);
199 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e9dc), 0xeb);
200          }
201          
202          // Cheat table patch
203          if (patch_cheattable)
204          {
205 <                DDrPatch_Int32 (OniExe + 0x000f616b, (int)&DDr_CheatTable[0].name);
206 <                DDrPatch_Int32 (OniExe + 0x000f617a, (int)&DDr_CheatTable[0].message_on);
205 >                DDrPatch_Int32 ((int*)(OniExe + 0x000f616b), (int)&DDr_CheatTable[0].name);
206 >                DDrPatch_Int32 ((int*)(OniExe + 0x000f617a), (int)&DDr_CheatTable[0].message_on);
207          }
208          
209          // ARGB8888 textures
210          if (patch_argb8888)
211          {
212 <                DDrPatch_Byte  (OniExe + 0x00135af0, 0x07);
213 <                DDrPatch_Byte  (OniExe + 0x00135af4, 0x0B);
212 >                DDrPatch_Byte  ((char*)(OniExe + 0x00135af0), 0x07);
213 >                DDrPatch_Byte  ((char*)(OniExe + 0x00135af4), 0x0B);
214 >        }
215 >
216 >        //Test newweap patch
217 >        if (patch_newweapon) {
218 >                
219 >                //Makes it always say "Received weapon_name."
220 >                //Needs check for loc_4DFC66
221 >                //DDrPatch_NOOP((char*)(OniExe + 0x000E4DF8),2);
222 >
223 >                //Adds Weapon name and ammo meter to pickup autoprompt
224 >                DDrPatch_NOOP((char*)(OniExe + 0x000FAC73), 9);
225 >                DDrPatch_NOOP((char*)(OniExe + 0x000FAC80), 5);
226 >                DDrPatch_MakeCall((void*)(OniExe + 0xFAC85), (void*)DDrWeapon2Message);
227 >                
228 >                //Moves location of colors
229 >                //DDrPatch_Int32((int*)(OniExe + 0x0002E3D5), (int)&DDrDSayColors );
230 >                //DDrPatch_Int32((int*)(OniExe + 0x0002E3DA), (int)&DDrDSayColors );
231          }
232          
233          // Disable loading the vtuneapi.dll
234 <        if (patch_killvtune)
235 <                DDrPatch_Byte  (OniExe + 0x00026340, 0xC3);
234 >        //if (patch_killvtune)
235 >                //DDrPatch_Byte  ((char*)(OniExe + 0x00026340), 0xC3);
236          
237          // Disable Oni's internal CLrGetCommandLine function (to eventually replace it with our own)
238          if (patch_getcmdline)
239 <                DDrPatch_NOOP  (OniExe + 0x000d3280, 51);
239 >                DDrPatch_NOOP  ((char*)(OniExe + 0x000d3280), 51);
240          
241          // Disable Oni's command line parser so it doesn't interfere with ours
242          if (patch_disablecmdline)
243 <                DDrPatch_Int32 (OniExe + 0x000d3570, 0xc3c03366);
243 >                DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0xc3c03366);
244          
245 <        return true;
187 < }
188 <
189 < enum {s_unknown, s_options, s_patch, s_bsl, s_language} ini_section;
190 <
191 < bool DDrIniCallback(char* section, bool newsection, char* name, char* value)
192 < {
193 <        if (newsection)
245 >        if (patch_bsl)
246          {
247 <                if (!stricmp(section, "options"))
248 <                        ini_section = s_options;
249 <                else if (!stricmp(section, "patch"))
250 <                        ini_section = s_patch;
251 <                else if (!stricmp(section, "bsl"))
252 <                        ini_section = s_bsl;
253 <                else if (!stricmp(section, "language"))
254 <                        ini_section = s_language;
255 <                else
256 <                {
257 <                        ini_section = s_unknown;
258 <                        DDrStartupMessage("unrecognised section \"%s\"", section);
259 <                }
247 >                //Calculating the value of the needed offset is much more reliable when the compiler does it for you.
248 >
249 >                //TODO: fix moonshadow.
250 >                Character * Chr = 0;
251 >                int NoPath = (int)&(Chr[0].RegenHax) & 0x000000FF;
252 >                const unsigned char regen_patch[] =
253 >                {0x90, 0x90, 0x90, 0x90, 0x90,                          // mov    al, _WPgRegenerationCheat     -> NOOP
254 >                0x90, 0x90,                                                                     // test   al, al                                        -> NOOP
255 >                0x90, 0x90,                                                                     // jz     short loc_51BB98                      -> NOOP
256 >                0x8B, 0x86, (char)NoPath, 0x01, 0x00, 0x00, // mov     eax, [esi+Character.field_1E8]
257 >                                                                                                        //      -> mov     eax, [esi+Character.RegenHax]
258 >                0x85, 0xC0,                                                                     // test eax, eax
259 >                0x74, 0x21                                                                      // jnz 0x21 -> jz 0x21
260 >                };      
261 >                DDrPatch_Const((char*)(OniExe + 0x0011BB64), regen_patch);
262          }
263          
264 <        switch (ini_section)
264 >        if(patch_chinese)
265          {
266 <                case s_options:
267 <                        if (!stricmp(name, "usedaodanbsl"))
268 <                                opt_usedaodanbsl = !stricmp(inifile_cleanstr(value), "true");
269 <                        else if (!stricmp(name, "debug"))
270 <                                AKgDebug_DebugMaps = !stricmp(inifile_cleanstr(value), "true");
271 <                        else if (!stricmp(name, "debugfiles"))
272 <                                BFgDebugFileEnable = !stricmp(inifile_cleanstr(value), "true");
273 <                        else if (!stricmp(name, "findsounds"))
274 <                                SSgSearchOnDisk = !stricmp(inifile_cleanstr(value), "true");
221 <                        else if (!stricmp(name, "ignore_private_data"))
222 <                                opt_ignore_private_data = !stricmp(inifile_cleanstr(value), "true");
223 <                        else if (!stricmp(name, "sound"))
224 <                                opt_sound = !stricmp(inifile_cleanstr(value), "true");
225 <                        else if (!stricmp(name, "switch"))
226 <                                M3gResolutionSwitch = !stricmp(inifile_cleanstr(value), "true");
227 <                        else
228 <                                DDrStartupMessage("unrecognised option \"%s\"", name);
229 <                        break;
230 <                case s_patch:
231 <                        if (!stricmp(name, "fonttexturecache"))
232 <                                patch_fonttexturecache = !stricmp(inifile_cleanstr(value), "true");
233 <                        else if (!stricmp(name, "largetextures"))
234 <                                patch_largetextures = !stricmp(inifile_cleanstr(value), "true");
235 <                        else if (!stricmp(name, "levelplugins"))
236 <                                patch_levelplugins = !stricmp(inifile_cleanstr(value), "true");
237 <                        else if (!stricmp(name, "pathfinding"))
238 <                                patch_pathfinding = !stricmp(inifile_cleanstr(value), "true");
239 <                        else if (!stricmp(name, "projaware"))
240 <                                patch_projaware = !stricmp(inifile_cleanstr(value), "true");
241 <                        else if (!stricmp(name, "directinput"))
242 <                                patch_directinput = !stricmp(inifile_cleanstr(value), "true");
243 <                        else if (!stricmp(name, "wpfadetime"))
244 <                                patch_wpfadetime = !stricmp(inifile_cleanstr(value), "true");
245 <                        else if (!stricmp(name, "kickguns"))
246 <                                patch_kickguns = !stricmp(inifile_cleanstr(value), "true");
247 <                        else if (!stricmp(name, "cooldowntimer"))
248 <                                patch_cooldowntimer = !stricmp(inifile_cleanstr(value), "true");
249 <                        else if (!stricmp(name, "throwtest"))
250 <                                patch_throwtest = !stricmp(inifile_cleanstr(value), "true");
251 <                        else if (!stricmp(name, "alttab"))
252 <                                patch_alttab = !stricmp(inifile_cleanstr(value), "true");
253 <                        else if (!stricmp(name, "particledisablebit"))
254 <                                patch_particledisablebit = !stricmp(inifile_cleanstr(value), "true");
255 <                        else if (!stricmp(name, "multibyte"))
256 <                                patch_multibyte = !stricmp(inifile_cleanstr(value), "true");
257 <                        else if (!stricmp(name, "cheattable"))
258 <                                patch_cheattable = !stricmp(inifile_cleanstr(value), "true");
259 <                        else if (!stricmp(name, "argb8888"))
260 <                                patch_argb8888 = !stricmp(inifile_cleanstr(value), "true");
261 <                        else if (!stricmp(name, "killvtune"))
262 <                                patch_killvtune = !stricmp(inifile_cleanstr(value), "true");
263 <                        else if (!stricmp(name, "getcmdline"))
264 <                                patch_getcmdline = !stricmp(inifile_cleanstr(value), "true");
265 <                        else if (!stricmp(name, "disablecmdline"))
266 <                                patch_disablecmdline = !stricmp(inifile_cleanstr(value), "true");
267 <                        else if (!stricmp(name, "safeprintf"))
268 <                                patch_safeprintf = !stricmp(inifile_cleanstr(value), "true");
269 <                        else if (!stricmp(name, "daodandisplayenum"))
270 <                                patch_daodandisplayenum = !stricmp(inifile_cleanstr(value), "true");
271 <                        else if (!stricmp(name, "usegettickcount"))
272 <                                patch_usegettickcount = !stricmp(inifile_cleanstr(value), "true");
273 <                        else if (!stricmp(name, "cheatsenabled"))
274 <                                patch_cheatsenabled = !stricmp(inifile_cleanstr(value), "true");
275 <                        else if (!stricmp(name, "usedaodangl"))
276 <                                patch_usedaodangl = !stricmp(inifile_cleanstr(value), "true");
277 <                        else if (!stricmp(name, "windowhack"))
278 <                                patch_windowhack = !stricmp(inifile_cleanstr(value), "true");
279 <                        else if (!stricmp(name, "daodaninit"))
280 <                                patch_daodaninit = !stricmp(inifile_cleanstr(value), "true");
281 <                        else if (!stricmp(name, "bsl"))
282 <                                patch_bsl = !stricmp(inifile_cleanstr(value), "true");
283 <                        else if (!stricmp(name, "cheater"))
284 <                                patch_cheater = !stricmp(inifile_cleanstr(value), "true");
285 <                        else
286 <                                DDrStartupMessage("unrecognised patch \"%s\"", name);
287 <                        break;
288 <                case s_language:
289 <                        if (!stricmp(name, "savepoint"))
290 <                        {
291 <                                char* str = strdup(value);
292 <                                DDrPatch_Int32(OniExe + 0x000fd730, (int)str);
293 <                                DDrPatch_Int32(OniExe + 0x000fd738, (int)str);
294 <                        }
295 <                        else if (!stricmp(name, "syndicatewarehouse"))
296 <                        {
297 <                                char* str = strdup(value);
298 <                                DDrPatch_Int32(OniExe + 0x000fd71a, (int)str);
299 <                                DDrPatch_Int32(OniExe + 0x0010ef75, (int)str);
300 <                        }
301 <                        else if (!stricmp(name, "damn"))
302 <                                DDrPatch_StrDup(OniExe + 0x0010fb6e, value);
303 <                        else if (!stricmp(name, "blam"))
304 <                                DDrPatch_StrDup(OniExe + 0x0010fb73, value);
305 <                        else if (!stricmp(name, "shapeshifter_on"))
306 <                                DDr_CheatTable[0].message_on = strdup(value);
307 <                        else if (!stricmp(name, "shapeshifter_off"))
308 <                                DDr_CheatTable[0].message_off = strdup(value);
309 <                        else if (!stricmp(name, "liveforever_on"))
310 <                                DDr_CheatTable[1].message_on = strdup(value);
311 <                        else if (!stricmp(name, "liveforever_off"))
312 <                                DDr_CheatTable[1].message_off = strdup(value);
313 <                        else if (!stricmp(name, "touchofdeath_on"))
314 <                                DDr_CheatTable[2].message_on = strdup(value);
315 <                        else if (!stricmp(name, "touchofdeath_off"))
316 <                                DDr_CheatTable[2].message_off = strdup(value);
317 <                        else if (!stricmp(name, "canttouchthis_on"))
318 <                                DDr_CheatTable[3].message_on = strdup(value);
319 <                        else if (!stricmp(name, "canttouchthis_off"))
320 <                                DDr_CheatTable[3].message_off = strdup(value);
321 <                        else if (!stricmp(name, "fatloot_on"))
322 <                                DDr_CheatTable[4].message_on = strdup(value);
323 <                        else if (!stricmp(name, "glassworld_on"))
324 <                                DDr_CheatTable[5].message_on = strdup(value);
325 <                        else if (!stricmp(name, "glassworld_off"))
326 <                                DDr_CheatTable[5].message_off = strdup(value);
327 <                        else if (!stricmp(name, "winlevel_on"))
328 <                                DDr_CheatTable[6].message_on = strdup(value);
329 <                        else if (!stricmp(name, "loselevel_on"))
330 <                                DDr_CheatTable[7].message_on = strdup(value);
331 <                        else if (!stricmp(name, "bighead_on"))
332 <                                DDr_CheatTable[8].message_on = strdup(value);
333 <                        else if (!stricmp(name, "bighead_off"))
334 <                                DDr_CheatTable[8].message_off = strdup(value);
335 <                        else if (!stricmp(name, "minime_on"))
336 <                                DDr_CheatTable[9].message_on = strdup(value);
337 <                        else if (!stricmp(name, "minime_off"))
338 <                                DDr_CheatTable[9].message_off = strdup(value);
339 <                        else if (!stricmp(name, "superammo_on"))
340 <                                DDr_CheatTable[10].message_on = strdup(value);
341 <                        else if (!stricmp(name, "superammo_off"))
342 <                                DDr_CheatTable[10].message_off = strdup(value);
343 <                        else if (!stricmp(name, "devmode_on"))
344 <                        {
345 <                                char* str = strdup(value);
346 <                                DDr_CheatTable[11].message_on = str;
347 <                                DDr_CheatTable[cheat_x].message_on = str;
348 <                        }
349 <                        else if (!stricmp(name, "devmode_off"))
266 >                if (GetFileAttributes("xfhsm_oni.dll") != INVALID_FILE_ATTRIBUTES)
267 >                {
268 >                        HMODULE dll;
269 >                        DWORD err;
270 >
271 >                        DDrStartupMessage("Daodan: Loading chinese DLL");
272 >                        dll = LoadLibrary("xfhsm_oni.dll");
273 >                        err = GetLastError();
274 >                        if( dll )
275                          {
276 <                                char* str = strdup(value);
277 <                                DDr_CheatTable[11].message_off = str;
278 <                                DDr_CheatTable[cheat_x].message_off = str;
276 >                                void* proc = GetProcAddress( dll, "InstallHook" );
277 >                                if(proc)
278 >                                {
279 >                                        ((CHINESEPROC)proc)(GetCurrentThreadId());
280 >                                }
281 >                        } else {
282 >                                char msg[100];
283 >                                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, msg, 100, NULL);
284 >                                DDrStartupMessage("Daodan: Loading DLL failed with error %i: %s", err, msg);
285                          }
286 <                        else if (!stricmp(name, "reservoirdogs_on"))
356 <                                DDr_CheatTable[12].message_on = strdup(value);
357 <                        else if (!stricmp(name, "reservoirdogs_off"))
358 <                                DDr_CheatTable[12].message_off = strdup(value);
359 <                        else if (!stricmp(name, "roughjustice_on"))
360 <                                DDr_CheatTable[13].message_on = strdup(value);
361 <                        else if (!stricmp(name, "roughjustice_off"))
362 <                                DDr_CheatTable[13].message_off = strdup(value);
363 <                        else if (!stricmp(name, "chenille_on"))
364 <                                DDr_CheatTable[14].message_on = strdup(value);
365 <                        else if (!stricmp(name, "chenille_off"))
366 <                                DDr_CheatTable[14].message_off = strdup(value);
367 <                        else if (!stricmp(name, "behemoth_on"))
368 <                                DDr_CheatTable[15].message_on = strdup(value);
369 <                        else if (!stricmp(name, "behemoth_off"))
370 <                                DDr_CheatTable[15].message_off = strdup(value);
371 <                        else if (!stricmp(name, "elderrune_on"))
372 <                                DDr_CheatTable[16].message_on = strdup(value);
373 <                        else if (!stricmp(name, "elderrune_off"))
374 <                                DDr_CheatTable[16].message_off = strdup(value);
375 <                        else if (!stricmp(name, "moonshadow_on"))
376 <                                DDr_CheatTable[17].message_on = strdup(value);
377 <                        else if (!stricmp(name, "moonshadow_off"))
378 <                                DDr_CheatTable[17].message_off = strdup(value);
379 <                        else if (!stricmp(name, "munitionfrenzy_on"))
380 <                                DDr_CheatTable[18].message_on = strdup(value);
381 <                        else if (!stricmp(name, "fistsoflegend_on"))
382 <                                DDr_CheatTable[19].message_on = strdup(value);
383 <                        else if (!stricmp(name, "fistsoflegend_off"))
384 <                                DDr_CheatTable[19].message_off = strdup(value);
385 <                        else if (!stricmp(name, "killmequick_on"))
386 <                                DDr_CheatTable[20].message_on = strdup(value);
387 <                        else if (!stricmp(name, "killmequick_off"))
388 <                                DDr_CheatTable[20].message_off = strdup(value);
389 <                        else if (!stricmp(name, "carousel_on"))
390 <                                DDr_CheatTable[21].message_on = strdup(value);
391 <                        else if (!stricmp(name, "carousel_off"))
392 <                                DDr_CheatTable[21].message_off = strdup(value);
393 <                        else
394 <                                DDrStartupMessage("unrecognised language item \"%s\"", name);
395 <                        break;
396 <                case s_bsl:
397 <                default:
398 <                        break;
286 >                }
287          }
400        
401        return true;
402 }
288  
289 < void DDrConfig()
290 < {
406 <        if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES)
289 >        //Fix crappy ai2_shownames
290 >        if(1)
291          {
292 <                DDrStartupMessage("daodan.ini doesn't exist, creating");
293 <                FILE* fp = fopen("daodan.ini", "w");
294 <                if (fp)
295 <                {
296 <                        fputs("[Options]\n", fp);
297 <                        fclose(fp);
298 <                }
292 >                //Set distance above head to 4.0
293 >                DDrPatch_Int32((int*)(OniExe + 0x0008C998), 0x005296C8);
294 >                //texture height
295 >                DDrPatch_Byte((char*)(OniExe + 0x0008C9DF), 0x3F );
296 >                //texture       width
297 >                DDrPatch_NOOP((char*)(OniExe + 0x0008C9CA), 6 );
298 >                //Set the text color to whatever we like ;)
299 >                DDrPatch_NOOP((char*)(OniExe + 0x0008C898), 6 );
300 >                DDrPatch_Byte((char*)(OniExe + 0x0008C898), 0x8B );
301 >                DDrPatch_Byte((char*)(OniExe + 0x0008C899), 0xCE );
302 > //FLATLINE?             DDrPatch_MakeCall((void*)(OniExe + 0x0008C8A3), FLrHook_DebugNameShadeHack);
303 >                
304 >                //Make the background black for additive blending
305 > //FLATLINE?             DDrPatch_MakeCall((void*)(OniExe + 0x0008C802), FLrHook_DebugNameTextureInit );
306          }
416        
417        DDrStartupMessage("parsing daodan.ini...");
418        if (!inifile_read("daodan.ini", DDrIniCallback))
419                DDrStartupMessage("error reading daodan.ini, check your syntax!");
420        DDrStartupMessage("finished parsing");
421 }
307  
308 < void ONICALL DDrGame_Init()
309 < {
310 <        if (opt_usedaodanbsl)
311 <                SLrDaodan_Initalize();
312 < }
308 >        if(1)
309 >        {
310 >                //DDrPatch_NOOP((char*)(OniExe + 0x000E1957), 6 );
311 >                //DDrPatch_MakeCall((void*)(OniExe + 0x000E17F6), FLrHook_Lasers );
312 >        }
313  
314 < void __cdecl DDrMain(int argc, char* argv[])
315 < {
431 <        DDrStartupMessage("daodan attached!");
432 <        
433 <        opt_ignore_private_data = false;
434 <        opt_sound = true;
314 >        //Flatline related stuff
315 > //      DDrPatch_MakeCall((void*)(OniExe + 0x000FBCEA), DDrText_Hook);
316          
317 <        DDrConfig();
318 <        DDrStartupMessage("parsing command line...");
319 <        int i;
320 <        char* section;
321 <        char* option;
322 <        bool falseoption;
323 <        for (i = 1; i < argc; i ++)
317 > //FLATLINE?     DDrPatch_Int32((int*)(OniExe + 0x000B24D2), FLrSpawnHack);
318 >
319 > //FLATLINE?     DDrPatch_NOOP((char*)(OniExe + 0x000C26CB), 6);
320 >
321 > //FLATLINE?     DDrPatch_MakeCall((void*)(OniExe + 0x000C26CB), FLrHook_DoorOpen);
322 > //FLATLINE?     DDrPatch_MakeCall((void*)(OniExe + 0x000EE3CF), FLrHook_ConsoleActivate);
323 >
324 >
325 >        // Fix options not visible in main menu when a game was started
326 >        if(patch_optionsvisible)
327          {
328 <                if (argv[i][0] == '-')
329 <                {
446 <                        section = argv[i] + 1;
447 <                        if ((option = strchr(argv[i], '.')))
448 <                        {
449 <                                *option = '\0';
450 <                                falseoption = (option[1] == 'n' || option[1] == 'N') && (option[2] = 'o' || option[2] == 'O');
451 <                                if (i < (argc - 1) && argv[i + 1][0] != '-')
452 <                                        DDrIniCallback(section, true, option + (falseoption ? 3 : 1), argv[++i]);
453 <                                else
454 <                                        DDrIniCallback(section, true, option + (falseoption ? 3 : 1), (falseoption ? "false" : "true"));
455 <                                *option = '.';
456 <                        }
457 <                        else
458 <                        {
459 <                                falseoption = (section[0] == 'n' || section[0] == 'N') && (section[1] = 'o' || section[1] == 'O');
460 <                                ini_section = s_options;
461 <                                if (i < (argc - 1) && argv[i + 1][0] != '-')
462 <                                        DDrIniCallback(NULL, false, section + (falseoption ? 2 : 0), argv[++i]);
463 <                                else
464 <                                        DDrIniCallback(NULL, false, section + (falseoption ? 2 : 0), (falseoption ? "false" : "true"));
465 <                        }
466 <                }
467 <                else
468 <                {
469 <                        DDrStartupMessage("parse error \"%s\"", argv[i]);
470 <                        break;
471 <                }
328 >                DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton);
329 >                DDrPatch_MakeCall((void*)(OniExe + 0x000d2d43), DDrShowResumeButton);
330          }
331 <        DDrStartupMessage("finished parsing");
332 <        DDrPatch_Init();
333 <        
331 >
332 >        // Fix BinkBufferInit() call in BKrMovie_Play() to use GDI (DIB) blitting
333 >        // instead of DirectDraw; patch ONiRunGame to use the same method to play
334 >        // outro (ie., BKrMovie_Play() instead of ONrMovie_Play_Hardware() as the
335 >        // latter has problems on WINE).
336 >        if (patch_binkplay)
337 >        {
338 >                // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION.
339 >                DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02);
340 >                // call ONrMovie_Play_Hardware -> call ONrMovie_Play
341 >                DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play);
342 >        }
343 >
344 >        // Patch a gamma slider in Options dialog (unconditionally).
345 >        // ONiOGU_Options_InitDialog: replace WMrSlider_SetRange(gammaSliderWindow, ...)
346 >        // call with our hook function.
347 >        DDrPatch_MakeCall((void*)(OniExe + 0x000d262c), (void*)DD_ONiOGU_GammaSlider_SetRange);
348 >
349          // Safe startup message printer
350          if (patch_safeprintf)
351 <                DDrPatch_MakeJump(UUrStartupMessage, DDrStartupMessage);
351 >                DDrPatch_MakeJump((void*)UUrStartupMessage, (void*)DDrStartupMessage);
352          
353          // Daodan device mode enumeration function
354          if (patch_daodandisplayenum)
355 <                DDrPatch_MakeJump(gl_enumerate_valid_display_modes, daodan_enumerate_valid_display_modes);
355 >                DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)DD_GLrEnumerateDisplayModes);
356          
357          // Performance patch
358          if (patch_usegettickcount)
359          {
360 <                DDrPatch_MakeJump(UUrMachineTime_High, DDrMachineTime_High);
361 <                DDrPatch_MakeJump(UUrMachineTime_High_Frequency, DDrMachineTime_High_Frequency);
362 <                DDrPatch_MakeJump(UUrMachineTime_Sixtieths, DDrMachineTime_Sixtieths);
360 >                DDrPatch_MakeJump((void*)UUrMachineTime_High, (void*)DDrMachineTime_High);
361 >                DDrPatch_MakeJump((void*)UUrMachineTime_High_Frequency, (void*)DDrMachineTime_High_Frequency);
362 >                DDrPatch_MakeJump((void*)UUrMachineTime_Sixtieths, (void*)DDrMachineTime_Sixtieths);
363          }
364 <        
364 >
365          // Cheats always enabled
366          if (patch_cheatsenabled)
367 <                DDrPatch_MakeJump(ONrPersist_GetWonGame, DDrPersist_GetWonGame);
368 <        
369 <        // Windowed mode
367 >                DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame);
368 >
369 >        // DaodanGL with windowed mode support.
370          if (patch_usedaodangl)
371          {
372 <                DDrPatch_MakeJump(ONrPlatform_Initialize, DDrPlatform_Initialize);
373 <                DDrPatch_MakeJump(gl_platform_initialize, daodangl_platform_initialize);
372 >                // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect.
373 >                DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6);
374 >                DDrPatch_MakeCall((char*) OniExe + 0x00002dd6, (void*) GetClientRect);
375 >
376 >                // UUrWindow_GetSize: GetWindowRect -> GetClientRect.
377 >                DDrPatch_NOOP((char*) OniExe + 0x0002651c, 6);
378 >                DDrPatch_MakeCall((char*) OniExe + 0x0002651c, (void*) GetClientRect);
379 >
380 >                // LIrPlatform_PollInputForAction: fix GetCursorPos call to return client coordinates.
381 >                DDrPatch_NOOP((char*) OniExe + 0x000032cc, 6);
382 >                DDrPatch_MakeCall((char*) OniExe + 0x000032cc, (void*) DD_GetCursorPos);
383 >
384 >                // LIrPlatform_InputEvent_GetMouse: fix GetCursorPos call to return client coordinates.
385 >                DDrPatch_NOOP((char*) OniExe + 0x00002cc2, 6);
386 >                DDrPatch_MakeCall((char*) OniExe + 0x00002cc2, (void*) DD_GetCursorPos);
387 >
388 >                // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
389 >                DDrPatch_NOOP((char*) OniExe + 0x000032b7, 6);
390 >                DDrPatch_MakeCall((char*) OniExe + 0x000032b7, (void*) DD_SetCursorPos);
391 >
392 >                // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
393 >                DDrPatch_NOOP((char*) OniExe + 0x00003349, 6);
394 >                DDrPatch_MakeCall((char*) OniExe + 0x00003349, (void*) DD_SetCursorPos);
395 >
396 >                // Replace ONrPlatformInitialize.
397 >                DDrPatch_MakeJump((void*) ONrPlatform_Initialize, (void*) DD_ONrPlatform_Initialize);
398 >
399 >                // Replace gl_platform_initialize.
400 >                DDrPatch_MakeJump((void*) gl_platform_initialize, (void*) DD_GLrPlatform_Initialize);
401 >
402 >                // Replace gl_platform_dispose.
403 >                DDrPatch_MakeJump((void *) gl_platform_dispose, (void*) DD_GLrPlatform_Dispose);
404 >        }
405 >
406 >        if (patch_clipcursor)
407 >        {
408 >                // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook.
409 >                DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set);
410 >
411 >                // LIrMode_Set_Internal: replace LIrPlatform_Mode_Set call with our hook.
412 >                DDrPatch_MakeCall((void*)(OniExe + 0x00003fff), (void*) DD_LIrPlatform_Mode_Set);
413 >                
414 >                // LIrTermiante: replace LIrPlatform_Terminate call with our hook.
415 >                DDrPatch_MakeCall((void*)(OniExe + 0x000004cb8), (void*) DD_LIrPlatform_Terminate);
416          }
417 <        
503 <        // Hacked windowed mode (for when daodangl isn't working properly)
504 <        if (patch_windowhack)
505 <                DDrWindowHack_Install();
417 >
418          
419          if (patch_daodaninit)
420 <                DDrPatch_MakeCall(OniExe + 0x000d345a, DDrGame_Init);
420 >                DDrPatch_MakeCall((void*)(OniExe + 0x000d345a), (void*)DDrGame_Init);
421          
422          // Patches for existing BSL functions
423          if (patch_bsl)
424                  SLrDaodan_Patch();
425 <        
425 >                
426          if (patch_cheater)
427          {
428 <                DDrPatch_MakeCall(OniExe + 0x000f618f, DDrCheater);
429 <                DDrPatch_Int16(OniExe + 0x000deb45, 0x5590);
430 <                DDrPatch_MakeCall(OniExe + 0x000deb47, FallingFrames);
431 <                DDrPatch_MakeJump(OniExe + 0x0010f021, DDrCheater_LevelLoad);
428 >                DDrPatch_MakeCall((void*)(OniExe + 0x000f618f), (void*)DDrCheater);
429 >                DDrPatch_Int16((short*)(OniExe + 0x000deb45), 0x5590);
430 > #if 1
431 >                DDrPatch_MakeCall((void*)(OniExe + 0x000deb47), (void*)FallingFrames);
432 > #endif
433 >                DDrPatch_MakeJump((void*)(OniExe + 0x0010f021), (void*)DDrCheater_LevelLoad);
434          }
435 +
436 +        DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning);
437 +
438 +
439 +        return true;
440 + }
441 +
442 +
443 + void DDrException() {
444 +        int* i = 0;
445 +        *i = 1;
446 + }
447 +
448 + void __cdecl DDrMain(int argc, char* argv[])
449 + {
450 +        DDrStartupMessage("Daodan: Daodan attached!");
451 +        
452 +        // Tell Oni to not load non levelX_final-files by default:
453 +        opt_ignore_private_data = false;
454 +
455 +        // Enable sound by default:
456 +        opt_sound = true;
457 +        
458 +        DDrConfig(argc, argv);
459 +
460 +        DDrPatch_Init();
461          
522        init_daodan_gl();
462          
463          ONiMain(argc, argv);
464   }
# Line 554 | Line 493 | BOOL WINAPI DllMain(HINSTANCE hinstDLL,
493                          DDrDLLModule = hinstDLL;
494                          DDrONiModule = GetModuleHandle(NULL);
495                          
496 <                        if (*(uint32_t*)((void*)OniExe + 0x0011acd0) == 0x09d36852)
497 <                                DDrPatch_MakeCall(OniExe + 0x0010fb49, DDrMain);
496 >                        if (*(uint32_t*)(OniExe + 0x0011acd0) == 0x09d36852)
497 >                                DDrPatch_MakeCall((void*)(OniExe + 0x0010fb49), (void*)DDrMain);
498                          else
499                                  ExitProcess(0);
500                          break;

Diff Legend

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