ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/src/patches/Patches.c
Revision: 984
Committed: Sun Mar 16 23:35:10 2014 UTC (11 years, 6 months ago) by alloc
Content type: text/x-csrc
File size: 22849 byte(s)
Log Message:
Daodan: TV code

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