ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/src/patches/Patches.c
Revision: 987
Committed: Wed Mar 19 12:44:30 2014 UTC (11 years, 6 months ago) by alloc
Content type: text/x-csrc
File size: 23154 byte(s)
Log Message:
Daodan: Made symbols const

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