ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/src/patches/Patches.c
Revision: 992
Committed: Sat Apr 5 10:19:11 2014 UTC (11 years, 6 months ago) by alloc
Content type: text/x-csrc
File size: 22558 byte(s)
Log Message:
Daodan: Removed unused MSVC tree, build folders; reorganized source layout; removed Flatline from current Daodan

File Contents

# Content
1 #include <windows.h>
2
3 #include "../Daodan.h"
4 #include "../Daodan_BSL.h"
5 #include "../Daodan_Cheater.h"
6 #include "../Daodan_Config.h"
7 #include "../Daodan_GL.h"
8 #include "../Daodan_Patch.h"
9 #include "../Daodan_Persistence.h"
10 #include "../Daodan_Utility.h"
11 #include "../Daodan_Win32.h"
12
13 #include "../Oni/Oni.h"
14
15 typedef int (__cdecl *CHINESEPROC)(DWORD ThreadId);
16
17 // Hooked WMrSlider_SetRange() in ONiOGU_Options_InitDialog. Disables a gamma
18 // slider in windowed mode.
19 static void ONICALL DD_ONiOGU_GammaSlider_SetRange(void* window, int min_value, int max_value)
20 {
21 WMrWindow_SetEnabled(window, M3gResolutionSwitch && opt_gamma);
22 WMrSlider_SetRange(window, min_value, max_value);
23 }
24
25 void ONICALL DD_M3rDraw_BigBitmap(M3tTextureMap_Big* inBigBitmap, const M3tPointScreen* inDestPoint, UUtUns16 inWidth, UUtUns16 inHeight, UUtUns32 inShade, UUtUns16 inAlpha) /* 0 - M3cMaxAlpha */
26 {
27 UUtUns16 x;
28 UUtUns16 y;
29
30 UUtUns16 index;
31 UUtUns16 remaining_width;
32 UUtUns16 remaining_height;
33
34 M3tPointScreen dest_point;
35 dest_point.z = inDestPoint->z;
36 dest_point.invW = inDestPoint->invW;
37
38 index = 0;
39 remaining_height = inHeight;
40 dest_point.y = (UUtInt16)((UUtUns16)inDestPoint->y);
41 for (y = 0; y < inBigBitmap->num_y; y++)
42 {
43 remaining_width = inWidth;
44 dest_point.x = (UUtInt16)((UUtUns16)inDestPoint->x);
45 for (x = 0; x < inBigBitmap->num_x; x++)
46 {
47 UUtUns16 width;
48 UUtUns16 height;
49
50 width = 256 < remaining_width ? 256 : remaining_width;
51 height = 256 < remaining_height ? 256 : remaining_height;
52
53 M3rDraw_Bitmap(inBigBitmap->textures[index], &dest_point, width, height, inShade, inAlpha);
54
55 dest_point.x += 256;
56 remaining_width -= 256;
57 index++;
58 }
59 dest_point.y += 256;
60 remaining_height -= 256;
61 }
62 }
63
64
65 void ONICALL DDrShowResumeButton(void* window, int visibility)
66 {
67 if (visibility)
68 WMrWindow_SetLocation(window, 150, 350);
69 WMrWindow_SetVisible(window, visibility);
70 }
71
72
73 /* Options always visible patch */
74 void ONICALL DDrShowOptionsButton(void* window, int visibility)
75 {
76 WMrWindow_SetVisible(window, 1);
77 }
78
79 void ONICALL DDrGame_Init()
80 {
81 if (opt_usedaodanbsl)
82 SLrDaodan_Initialize();
83 }
84
85
86 //this was broken
87 FILE** _UUgError_WarningFile = (FILE**)0x005711B4;
88 FILE* ONICALL DDrPrintWarning(int filename, int linenumber, unsigned __int16 errornum, int message)
89 {
90 FILE *v4; // eax@1
91 FILE *result; // eax@4
92 char v6[512]; // [sp+0h] [bp-100h]@1
93 FILE* UUgError_WarningFile = *_UUgError_WarningFile;
94
95 if (filename && message && (strlen((const char*)filename)+strlen((const char*)message))<420) {
96 sprintf(
97 v6,
98 "Error %x reported from File: %s, Line: %d (message follows) \r\n%s",
99 errornum,
100 (const char*)filename,
101 linenumber,
102 (const char*)message);
103
104 if ( UUgError_WarningFile
105 || (UUgError_WarningFile = oni_fopen("debugger.txt", "wb"), UUgError_WarningFile ) )
106 {
107 oni_fprintf(UUgError_WarningFile, "%s\r\n", v6);
108 oni_fflush(UUgError_WarningFile);
109 }
110 }
111 //oni_fprintf(stdout, v6);
112 //sprintf(&v6, "%s", message);
113 *_UUgError_WarningFile = UUgError_WarningFile;
114 result = UUgError_WarningFile;
115 return result;
116 }
117
118 _COrTextArea_Resize Oni_COrTextArea_Resize = (_COrTextArea_Resize)0;
119 int16_t ONICALL DD_COrTextArea_Resize(void* inTextArea, UUtRect* inBounds, int16_t inNumTextEntries) {
120 if (inTextArea == COgCommandLine) {
121 inBounds->top -= 10;
122 } else if (inTextArea == COgConsoleLines) {
123 inBounds->bottom -= 10;
124 }
125 return Oni_COrTextArea_Resize(inTextArea, inBounds, inNumTextEntries);
126 }
127
128 #define IMcShade_Red (0xFFFF0000)
129 #define IMcShade_Green (0xFF00FF00)
130 #define IMcShade_Blue (0xFF0000FF)
131 void ONICALL DD_OBJiTriggerVolume_Draw(OBJtObject* inObject, uint32_t inDrawFlags)
132 {
133 UUtUns32 itr;
134 OBJtOSD_All *inOSD = (OBJtOSD_All *) inObject->object_data;
135 OBJtOSD_TriggerVolume *trigger_osd = &inOSD->osd.trigger_volume_osd;
136 M3tPoint3D *points = trigger_osd->volume.worldPoints;
137 UUtUns32 shade = 0xFFFFFF;
138
139 if (!OBJgTriggerVolume_Visible) {
140 return;
141 }
142
143 if (OBJrTriggerVolume_IntersectsCharacter(inObject, trigger_osd->team_mask, ONgGameState->PlayerCharacter)) {
144 shade = IMcShade_Red;
145 }
146 else
147 {
148 shade = IMcShade_Blue;
149 }
150
151 M3rGeom_Line_Light(points + 0, points + 1, shade);
152 M3rGeom_Line_Light(points + 1, points + 3, shade);
153 M3rGeom_Line_Light(points + 3, points + 2, shade);
154 M3rGeom_Line_Light(points + 2, points + 0, shade);
155
156 M3rGeom_Line_Light(points + 4, points + 5, shade);
157 M3rGeom_Line_Light(points + 5, points + 7, shade);
158 M3rGeom_Line_Light(points + 7, points + 6, shade);
159 M3rGeom_Line_Light(points + 6, points + 4, shade);
160
161 M3rGeom_Line_Light(points + 0, points + 4, shade);
162 M3rGeom_Line_Light(points + 1, points + 5, shade);
163 M3rGeom_Line_Light(points + 3, points + 7, shade);
164 M3rGeom_Line_Light(points + 2, points + 6, shade);
165 }
166
167 _ONrMechanics_Register Oni_ONrMechanics_Register = (_ONrMechanics_Register)0;
168 int16_t ONICALL DD_ONrMechanics_Register(uint32_t inObjectType, uint32_t inObjectTypeIndex, char* inGroupName,
169 uint32_t inSizeInMemory, OBJtMethods* inObjectMethods, uint32_t inFlags, void* inMechanicsMethods)
170 {
171 if (strcmp("Trigger Volume", inGroupName) == 0) {
172 inObjectMethods->rDraw = DD_OBJiTriggerVolume_Draw;
173 }
174 return Oni_ONrMechanics_Register(inObjectType, inObjectTypeIndex, inGroupName, inSizeInMemory, inObjectMethods, inFlags, inMechanicsMethods);
175 }
176
177 _ONrGameState_HandleUtilityInput Oni_ONrGameState_HandleUtilityInput = (_ONrGameState_HandleUtilityInput)0;
178 void ONICALL DD_ONrGameState_HandleUtilityInput(const void* inInput)
179 {
180 Oni_ONrGameState_HandleUtilityInput(inInput);
181
182 if (ONrDebugKey_WentDown(7)) {
183 OBJgTriggerVolume_Visible = !OBJgTriggerVolume_Visible;
184 }
185 }
186
187
188 int DD_Patch_DebugNameTextureInit(short width, short height, int type, int allocated, int flags, char* name, void** output)
189 {
190 //flags = (1 << 10);
191 type = 1;
192 //DDrPatch_Byte( 0x005EB83C + 3, 0xff );
193 DDrPatch_Int32((int*)(OniExe + 0x001EB83C), 0xFF000000 );
194 return M3rTextureMap_New(width, height, type, allocated, flags, name, output);
195 }
196
197 short DD_Patch_DebugNameShadeHack( Character* Char )
198 {
199 return TSrContext_SetShade(*(void**)(OniExe + 0x001EB844), ONrCharacter_GetHealthShade( Char->Health, Char->MaxHealth ));
200 //return TSrContext_SetShade(*(void**)0x005EB844, 0xFFFFFFFF);
201 }
202
203
204 // Disable UUrPlatform_Initalize/Terminate, this enables the Alt-Tab and the
205 // Windows key but has the possible side effect of allowing the screensaver
206 // to enable itself in-game.
207 void DD_Patch_AltTab()
208 {
209 // 0xC3 = ret, so makes those functions just have a "ret" instruction at their start
210 DDrPatch_Byte ((char*)UUrPlatform_Initialize, 0xC3);
211 DDrPatch_Byte ((char*)UUrPlatform_Terminate, 0xC3);
212 }
213
214 // Textures using ARGB8888 can be used
215 void DD_Patch_ARGB8888()
216 {
217 DDrPatch_Byte ((char*)(OniExe + 0x00135af0), 0x07);
218 DDrPatch_Byte ((char*)(OniExe + 0x00135af4), 0x0B);
219 }
220
221 // Fix BinkBufferInit() call in BKrMovie_Play() to use GDI (DIB) blitting
222 // instead of DirectDraw; patch ONiRunGame to use the same method to play
223 // outro (ie., BKrMovie_Play() instead of ONrMovie_Play_Hardware() as the
224 // latter has problems on WINE).
225 void DD_Patch_BinkPlay()
226 {
227 // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION.
228 DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02);
229 // call ONrMovie_Play_Hardware -> call ONrMovie_Play
230 DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play);
231 }
232
233 // Enables d_regen (unfinished) and prevents fly-in portraits from being
234 // stretched when playing in widescreen resolutions.
235 void DD_Patch_BSL()
236 {
237 //Calculating the value of the needed offset is much more reliable when the compiler does it for you.
238
239 //TODO: fix moonshadow.
240 Character * Chr = 0;
241 int NoPath = (int)&(Chr[0].RegenHax) & 0x000000FF;
242 const unsigned char regen_patch[] =
243 {0x90, 0x90, 0x90, 0x90, 0x90, // mov al, _WPgRegenerationCheat -> NOOP
244 0x90, 0x90, // test al, al -> NOOP
245 0x90, 0x90, // jz short loc_51BB98 -> NOOP
246 0x8B, 0x86, (char)NoPath, 0x01, 0x00, 0x00, // mov eax, [esi+Character.field_1E8]
247 // -> mov eax, [esi+Character.RegenHax]
248 0x85, 0xC0, // test eax, eax
249 0x74, 0x21 // jnz 0x21 -> jz 0x21
250 };
251 DDrPatch_Const((char*)(OniExe + 0x0011BB64), regen_patch);
252
253 // Patches for existing BSL functions
254 SLrDaodan_Patch();
255 }
256
257 // Adds new cheat codes if cheattable is also enabled
258 void DD_Patch_Cheater()
259 {
260 DDrPatch_MakeCall((void*)(OniExe + 0x000f618f), (void*)DDrCheater);
261 DDrPatch_Int16((short*)(OniExe + 0x000deb45), 0x5590);
262 #if 1
263 DDrPatch_MakeCall((void*)(OniExe + 0x000deb47), (void*)FallingFrames);
264 #endif
265 DDrPatch_MakeJump((void*)(OniExe + 0x0010f021), (void*)DDrCheater_LevelLoad);
266 }
267
268 // Cheats always enabled
269 void DD_Patch_CheatsEnabled()
270 {
271 DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame);
272 }
273
274 // Use Daodan's own cheattable
275 void DD_Patch_CheatTable()
276 {
277 DDrPatch_Int32 ((int*)(OniExe + 0x000f616b), (int)&DDr_CheatTable[0].name);
278 DDrPatch_Int32 ((int*)(OniExe + 0x000f617a), (int)&DDr_CheatTable[0].message_on);
279 }
280
281 // Load chinese font DLL if available
282 void DD_Patch_Chinese()
283 {
284 if (GetFileAttributes("xfhsm_oni.dll") != INVALID_FILE_ATTRIBUTES)
285 {
286 HMODULE dll;
287 DWORD err;
288
289 DDrStartupMessage("Daodan: Loading chinese DLL");
290 dll = LoadLibrary("xfhsm_oni.dll");
291 err = GetLastError();
292 if( dll )
293 {
294 void* proc = GetProcAddress( dll, "InstallHook" );
295 if(proc)
296 {
297 ((CHINESEPROC)proc)(GetCurrentThreadId());
298 }
299 } else {
300 char msg[100];
301 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, msg, 100, NULL);
302 DDrStartupMessage("Daodan: Loading DLL failed with error %i: %s", err, msg);
303 }
304 }
305 }
306
307 // Limit cursor to Oni's window
308 void DD_Patch_ClipCursor()
309 {
310 // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook.
311 DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set);
312
313 // LIrMode_Set_Internal: replace LIrPlatform_Mode_Set call with our hook.
314 DDrPatch_MakeCall((void*)(OniExe + 0x00003fff), (void*) DD_LIrPlatform_Mode_Set);
315
316 // LIrTermiante: replace LIrPlatform_Terminate call with our hook.
317 DDrPatch_MakeCall((void*)(OniExe + 0x000004cb8), (void*) DD_LIrPlatform_Terminate);
318 }
319
320 // Disables weapon cooldown exploit
321 void DD_Patch_CooldownTimer()
322 {
323 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 };
324 DDrPatch_Const ((char*)(OniExe + 0x0011a825), cooldown_patch);
325 }
326
327 // Daodan device mode enumeration function
328 void DD_Patch_DaodanDisplayEnum()
329 {
330 DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)DD_GLrEnumerateDisplayModes);
331 }
332
333 // Adds new BSL functions
334 void DD_Patch_DaodanInit()
335 {
336 DDrPatch_MakeCall((void*)(OniExe + 0x000d345a), (void*)DDrGame_Init);
337 }
338
339 // Forced DirectInput (for Windows NT)
340 void DD_Patch_DirectInput()
341 {
342 DDrPatch_Byte((char*)(OniExe + 0x00002e6d), 0xeb);
343 }
344
345 // Disable Oni's command line parser so it doesn't interfere with ours
346 void DD_Patch_DisableCmdLine()
347 {
348 // Replace start of OniParseCommandLine with XOR ax,ax; RET
349 // DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0xc3c03366);
350 // Replace start of OniParseCommandLine with XOR eax,eax; RET
351 DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0x00c3c033);
352 }
353
354 // Font texture cache doubled
355 void DD_Patch_FontTextureCache()
356 {
357 DDrPatch_Byte((char*)(OniExe + 0x00020ea7), 0x20);
358 DDrPatch_Byte((char*)(OniExe + 0x00020f4a), 0x40);
359 }
360
361 // Disable Oni's internal CLrGetCommandLine function (to eventually replace it with our own)
362 void DD_Patch_GetCmdLine()
363 {
364 DDrPatch_NOOP ((char*)(OniExe + 0x000d3280), 51);
365 }
366
367 // Allow HD screens with resolution < 1024*768
368 void DD_Patch_HDScreens_LowRes()
369 {
370 DDrPatch_MakeJump((void*)M3rDraw_BigBitmap, (void*)DD_M3rDraw_BigBitmap);
371 }
372
373 void DD_Patch_HighresConsole() {
374 Oni_COrTextArea_Resize = DDrPatch_MakeDetour((void*)COrTextArea_Resize, (void*)DD_COrTextArea_Resize);
375 }
376
377 // Hackish fix for Konoko not kicking guns
378 // Don't use this, it breaks stairs.
379 void DD_Patch_KickGuns()
380 {
381 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 };
382 DDrPatch_Const ((char*)(OniExe + 0x000dc420), kickgun_patch);
383 }
384
385 // Disable loading the vtuneapi.dll
386 void DD_Patch_KillVTune()
387 {
388 DDrPatch_Byte ((char*)(OniExe + 0x00026340), 0xC3);
389 }
390
391 // Now supports textures up to 512x512
392 void DD_Patch_LargeTextures()
393 {
394 DDrPatch_Byte ((char*)(OniExe + 0x00005251), 0x10);
395 }
396
397 // Non-"_Final" levels are now valid
398 void DD_Patch_LevelPlugins()
399 {
400 DDrPatch_Byte ((char*)(OniExe + 0x000206a8), 0x01);
401 }
402
403 // Weapon on ground shown with name and magazine contents
404 void DD_Patch_NewWeap()
405 {
406 //Makes it always say "Received weapon_name."
407 //Needs check for loc_4DFC66
408 //DDrPatch_NOOP((char*)(OniExe + 0x000E4DF8),2);
409
410 //Adds Weapon name and ammo meter to pickup autoprompt
411 DDrPatch_NOOP((char*)(OniExe + 0x000FAC73), 9);
412 DDrPatch_NOOP((char*)(OniExe + 0x000FAC80), 5);
413 DDrPatch_MakeCall((void*)(OniExe + 0xFAC85), (void*)DDrWeapon2Message);
414
415 //Moves location of colors
416 //DDrPatch_Int32((int*)(OniExe + 0x0002E3D5), (int)&DDrDSayColors );
417 //DDrPatch_Int32((int*)(OniExe + 0x0002E3DA), (int)&DDrDSayColors );
418 }
419
420 // Disable Multi-byte character awareness patch (multiple language support)
421 void DD_Patch_NoMultiByte()
422 {
423 DDrPatch_Byte ((char*)(OniExe + 0x0002d8f8), 0xeb);
424 DDrPatch_Byte ((char*)(OniExe + 0x0002d9ad), 0xeb);
425 DDrPatch_Byte ((char*)(OniExe + 0x0002dbe2), 0xeb);
426 DDrPatch_Byte ((char*)(OniExe + 0x0002dec3), 0xeb);
427 DDrPatch_Byte ((char*)(OniExe + 0x0002e2ab), 0xeb);
428 DDrPatch_Byte ((char*)(OniExe + 0x0002e2c4), 0xeb);
429 DDrPatch_Byte ((char*)(OniExe + 0x0002e379), 0xeb);
430 DDrPatch_Byte ((char*)(OniExe + 0x0002e48c), 0xeb);
431 DDrPatch_Byte ((char*)(OniExe + 0x0002e4d0), 0xeb);
432 DDrPatch_Byte ((char*)(OniExe + 0x0002e4f4), 0xeb);
433 DDrPatch_Byte ((char*)(OniExe + 0x0002e646), 0xeb);
434 DDrPatch_Byte ((char*)(OniExe + 0x0002e695), 0xeb);
435 DDrPatch_Byte ((char*)(OniExe + 0x0002e944), 0xeb);
436 DDrPatch_Byte ((char*)(OniExe + 0x0002e95d), 0xeb);
437 DDrPatch_Byte ((char*)(OniExe + 0x0002e98e), 0xeb);
438 DDrPatch_Byte ((char*)(OniExe + 0x0002e9dc), 0xeb);
439 }
440
441 // Fix options not visible in main menu when a game was started
442 void DD_Patch_OptionsVisible()
443 {
444 DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton);
445 DDrPatch_MakeCall((void*)(OniExe + 0x000d2d43), DDrShowResumeButton);
446 }
447
448 // Unlocks particle action disabling/enabling bits for all events. (Will be
449 // controlled by a command line switch when I figure out how to do that without
450 // Win32 hacks.)
451 void DD_Patch_ParticleDisableBit()
452 {
453 DDrPatch_Int16 ((short*)(OniExe + 0x001b184), 0x9090);
454 }
455
456 // Pathfinding grid cache size x8
457 void DD_Patch_PathFinding()
458 {
459 const unsigned char pathfinding[2] = {0x90 , 0xE9 };
460 DDrPatch_Byte ((char*)(OniExe + 0x0010b03b), 0x20);
461 DDrPatch_Byte ((char*)(OniExe + 0x0010b04c), 0x20);
462
463 //other stuff
464 DDrPatch_Const((char*)(OniExe + 0x00040789), pathfinding);
465 }
466
467 // Projectile awareness fixed
468 void DD_Patch_ProjAware()
469 {
470 DDrPatch_Byte ((char*)(OniExe + 0x0009c07c), 0x6c);
471 DDrPatch_Byte ((char*)(OniExe + 0x0009c080), 0x70);
472 DDrPatch_Byte ((char*)(OniExe + 0x0009c084), 0x74);
473 DDrPatch_Byte ((char*)(OniExe + 0x0009c110), 0x6c);
474 }
475
476 // Safe startup message printer
477 void DD_Patch_SafePrintf()
478 {
479 DDrPatch_MakeJump((void*)UUrStartupMessage, (void*)DDrStartupMessage);
480 }
481
482 // Show all (also enemies') lasersights
483 void DD_Patch_ShowAllLasersights()
484 {
485 DDrPatch_NOOP((char*)(OniExe + 0x000E1957), 6 );
486 }
487
488 void DD_Patch_ShowTriggerVolumes()
489 {
490 Oni_ONrMechanics_Register = DDrPatch_MakeDetour((void*)ONrMechanics_Register, (void*)DD_ONrMechanics_Register);
491 Oni_ONrGameState_HandleUtilityInput = DDrPatch_MakeDetour((void*)ONrGameState_HandleUtilityInput, (void*)DD_ONrGameState_HandleUtilityInput);
492 }
493
494 // Experiment with allowing enemies to be thrown over railings
495 void DD_Patch_Throwtest()
496 {
497 const unsigned char throwtest_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 };
498 DDrPatch_Const((char*)(OniExe + 0x000dc190), throwtest_patch);
499 }
500
501 // DaodanGL with windowed mode support
502 void DD_Patch_UseDaodanGL()
503 {
504 // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect.
505 DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6);
506 DDrPatch_MakeCall((char*) OniExe + 0x00002dd6, (void*) GetClientRect);
507
508 // UUrWindow_GetSize: GetWindowRect -> GetClientRect.
509 DDrPatch_NOOP((char*) OniExe + 0x0002651c, 6);
510 DDrPatch_MakeCall((char*) OniExe + 0x0002651c, (void*) GetClientRect);
511
512 // LIrPlatform_PollInputForAction: fix GetCursorPos call to return client coordinates.
513 DDrPatch_NOOP((char*) OniExe + 0x000032cc, 6);
514 DDrPatch_MakeCall((char*) OniExe + 0x000032cc, (void*) DD_GetCursorPos);
515
516 // LIrPlatform_InputEvent_GetMouse: fix GetCursorPos call to return client coordinates.
517 DDrPatch_NOOP((char*) OniExe + 0x00002cc2, 6);
518 DDrPatch_MakeCall((char*) OniExe + 0x00002cc2, (void*) DD_GetCursorPos);
519
520 // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
521 DDrPatch_NOOP((char*) OniExe + 0x000032b7, 6);
522 DDrPatch_MakeCall((char*) OniExe + 0x000032b7, (void*) DD_SetCursorPos);
523
524 // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
525 DDrPatch_NOOP((char*) OniExe + 0x00003349, 6);
526 DDrPatch_MakeCall((char*) OniExe + 0x00003349, (void*) DD_SetCursorPos);
527
528 // Replace ONrPlatformInitialize.
529 DDrPatch_MakeJump((void*) ONrPlatform_Initialize, (void*) DD_ONrPlatform_Initialize);
530
531 // Replace gl_platform_initialize.
532 DDrPatch_MakeJump((void*) gl_platform_initialize, (void*) DD_GLrPlatform_Initialize);
533
534 // Replace gl_platform_dispose.
535 DDrPatch_MakeJump((void *) gl_platform_dispose, (void*) DD_GLrPlatform_Dispose);
536 }
537
538 // Performance patch
539 void DD_Patch_UseGetTickCount()
540 {
541 DDrPatch_MakeJump((void*)UUrMachineTime_High, (void*)DDrMachineTime_High);
542 DDrPatch_MakeJump((void*)UUrMachineTime_High_Frequency, (void*)DDrMachineTime_High_Frequency);
543 DDrPatch_MakeJump((void*)UUrMachineTime_Sixtieths, (void*)DDrMachineTime_Sixtieths);
544 }
545
546 // Adds working function for existing BSL command wp_fadetime, sets fade time to 4800
547 void DD_Patch_WpFadetime()
548 {
549 // Makes wp_fadetime actually have a function
550 const unsigned char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 };
551 DDrPatch_Const ((char*)(OniExe + 0x0011a889), fadetime_patch);
552 DDrPatch_Byte ((char*)(OniExe + 0x0011a560), 0x31);
553
554 // Sets the fadetime to 4800 by default
555 DDrPatch_Int16 ((short*)(OniExe + 0x0011ab0e), 0x12c0);
556 }
557
558 // Disable gamma slider in options in windowed mode
559 void DD_Patch_GammaSlider()
560 {
561 DDrPatch_MakeCall((void*)(OniExe + 0x000d262c), (void*)DD_ONiOGU_GammaSlider_SetRange);
562 }
563
564 // Fix the warning print method
565 void DD_Patch_PrintWarning()
566 {
567 DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning);
568 }
569
570 //Fix crappy ai2_shownames
571 void DD_Patch_ShowNames()
572 {
573 //Set distance above head to 4.0
574 DDrPatch_Int32((int*)(OniExe + 0x0008C998), 0x005296C8);
575 //texture height
576 DDrPatch_Byte((char*)(OniExe + 0x0008C9DF), 0x3F );
577 //texture width
578 DDrPatch_NOOP((char*)(OniExe + 0x0008C9CA), 6 );
579
580 /*
581 // Crashes game.
582 //Set the text color to whatever we like ;)
583 DDrPatch_NOOP((char*)(OniExe + 0x0008C898), 6 );
584 DDrPatch_Byte((char*)(OniExe + 0x0008C898), 0x8B );
585 DDrPatch_Byte((char*)(OniExe + 0x0008C899), 0xCE );
586
587 DDrPatch_MakeCall((void*)(OniExe + 0x0008C8A3), DD_Patch_DebugNameShadeHack);
588
589 //Make the background black for additive blending
590 DDrPatch_MakeCall((void*)(OniExe + 0x0008C802), DD_Patch_DebugNameTextureInit );
591 */
592 }
593
594 /*
595 void DD_Patch_ShowTriggerVolumes()
596 {
597 DDrPatch_Int32((int*)(OniExe + 0x000cc9bb+4), (uint32_t)DD_OBJiTriggerVolume_Draw);
598 }
599
600 void DD_Patch_ShowFlags()
601 {
602 DDrPatch_Int32((int*)(OniExe + 0x000c4ed4+4), (uint32_t)DD_OBJiFlag_Draw);
603 }
604 */
605
606 bool DD_Patch_Init()
607 {
608 DDrStartupMessage("Daodan: Patching engine");
609
610 if (patch_alttab)
611 DD_Patch_AltTab();
612
613 if (patch_argb8888)
614 DD_Patch_ARGB8888();
615
616 if (patch_binkplay)
617 DD_Patch_BinkPlay();
618
619 if (patch_bsl)
620 DD_Patch_BSL();
621
622 if (patch_cheater)
623 DD_Patch_Cheater();
624
625 if (patch_cheatsenabled)
626 DD_Patch_CheatsEnabled();
627
628 if (patch_cheattable)
629 DD_Patch_CheatTable();
630
631 if (patch_chinese)
632 DD_Patch_Chinese();
633
634 if (patch_clipcursor)
635 DD_Patch_ClipCursor();
636
637 if (patch_cooldowntimer)
638 DD_Patch_CooldownTimer();
639
640 if (patch_daodandisplayenum)
641 DD_Patch_DaodanDisplayEnum();
642
643 if (patch_directinput)
644 DD_Patch_DirectInput();
645
646 if (patch_disablecmdline)
647 DD_Patch_DisableCmdLine();
648
649 if (patch_fonttexturecache)
650 DD_Patch_FontTextureCache();
651
652 if (patch_getcmdline)
653 DD_Patch_GetCmdLine();
654
655 if (patch_hdscreens_lowres)
656 DD_Patch_HDScreens_LowRes();
657
658 if (patch_highres_console)
659 DD_Patch_HighresConsole();
660
661 if (patch_kickguns)
662 DD_Patch_KickGuns();
663
664 //if (patch_killvtune)
665 // DD_Patch_KillVTune();
666
667 if (patch_largetextures)
668 DD_Patch_LargeTextures();
669
670 if (patch_levelplugins)
671 DD_Patch_LevelPlugins();
672
673 if (patch_newweapon)
674 DD_Patch_NewWeap();
675
676 if (patch_nomultibyte)
677 DD_Patch_NoMultiByte();
678
679 if(patch_optionsvisible)
680 DD_Patch_OptionsVisible();
681
682 if (patch_particledisablebit)
683 DD_Patch_ParticleDisableBit();
684
685 if (patch_pathfinding)
686 DD_Patch_PathFinding();
687
688 if (patch_projaware)
689 DD_Patch_ProjAware();
690
691 if (patch_safeprintf)
692 DD_Patch_SafePrintf();
693
694 if (patch_showalllasersights)
695 DD_Patch_ShowAllLasersights();
696
697 if (patch_showtriggervolumes)
698 DD_Patch_ShowTriggerVolumes();
699
700 if (patch_throwtest)
701 DD_Patch_Throwtest();
702
703 if (patch_usedaodangl)
704 DD_Patch_UseDaodanGL();
705
706 if (patch_usegettickcount)
707 DD_Patch_UseGetTickCount();
708
709 if (patch_wpfadetime)
710 DD_Patch_WpFadetime();
711
712
713 DD_Patch_DaodanInit();
714
715 DD_Patch_GammaSlider();
716
717 DD_Patch_PrintWarning();
718
719 DD_Patch_ShowNames();
720
721 return true;
722 }
723