source: Daodan/src/Patches/Patches.c@ 1007

Last change on this file since 1007 was 1000, checked in by alloc, 11 years ago

Daodan 3.7

File size: 22.8 KB
Line 
1#include <windows.h>
2
3#include "../Daodan.h"
4#include "BSL.h"
5#include "Cheater.h"
6#include "../Daodan_Config.h"
7#include "GL.h"
8#include "../Daodan_Patch.h"
9#include "Utility.h"
10#include "Win32.h"
11
12#include "../Oni/Oni.h"
13
14typedef int (__cdecl *CHINESEPROC)(DWORD ThreadId);
15
16// Hooked WMrSlider_SetRange() in ONiOGU_Options_InitDialog. Disables a gamma
17// slider in windowed mode.
18static void ONICALL DD_ONiOGU_GammaSlider_SetRange(void* window, int min_value, int max_value)
19{
20 ConfigOption_t* co = DDrConfig_GetOptOfType("graphics.gamma", C_BOOL);
21 WMrWindow_SetEnabled(window, M3gResolutionSwitch && co->value.intBoolVal);
22 WMrSlider_SetRange(window, min_value, max_value);
23}
24
25void 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
65uint8_t ONICALL DDrPersist_GetWonGame()
66{
67 return 1;
68}
69
70
71void ONICALL DDrShowResumeButton(void* window, int visibility)
72{
73 if (visibility)
74 WMrWindow_SetLocation(window, 150, 350);
75 WMrWindow_SetVisible(window, visibility);
76}
77
78
79/* Options always visible patch */
80void ONICALL DDrShowOptionsButton(void* window, int visibility)
81{
82 WMrWindow_SetVisible(window, 1);
83}
84
85void ONICALL DDrGame_Init()
86{
87 if (DDrConfig_GetOptOfType("modding.daodanbsl", C_BOOL)->value.intBoolVal)
88 SLrDaodan_Initialize();
89}
90
91
92//this was broken
93FILE** _UUgError_WarningFile = (FILE**)0x005711B4;
94FILE* ONICALL DDrPrintWarning(int filename, int linenumber, unsigned __int16 errornum, int message)
95{
96 FILE *v4; // eax@1
97 FILE *result; // eax@4
98 char v6[512]; // [sp+0h] [bp-100h]@1
99 FILE* UUgError_WarningFile = *_UUgError_WarningFile;
100
101 if (filename && message && (strlen((const char*)filename)+strlen((const char*)message))<420) {
102 sprintf(
103 v6,
104 "Error %x reported from File: %s, Line: %d (message follows) \r\n%s",
105 errornum,
106 (const char*)filename,
107 linenumber,
108 (const char*)message);
109
110 if ( UUgError_WarningFile
111 || (UUgError_WarningFile = oni_fopen("debugger.txt", "wb"), UUgError_WarningFile ) )
112 {
113 oni_fprintf(UUgError_WarningFile, "%s\r\n", v6);
114 oni_fflush(UUgError_WarningFile);
115 }
116 }
117 //oni_fprintf(stdout, v6);
118 //sprintf(&v6, "%s", message);
119 *_UUgError_WarningFile = UUgError_WarningFile;
120 result = UUgError_WarningFile;
121 return result;
122}
123
124_COrTextArea_Resize Oni_COrTextArea_Resize = (_COrTextArea_Resize)0;
125int16_t ONICALL DD_COrTextArea_Resize(void* inTextArea, UUtRect* inBounds, int16_t inNumTextEntries) {
126 if (inTextArea == COgCommandLine) {
127 inBounds->top -= 10;
128 } else if (inTextArea == COgConsoleLines) {
129 inBounds->bottom -= 10;
130 }
131 return Oni_COrTextArea_Resize(inTextArea, inBounds, inNumTextEntries);
132}
133
134#define IMcShade_Red (0xFFFF0000)
135#define IMcShade_Green (0xFF00FF00)
136#define IMcShade_Blue (0xFF0000FF)
137void ONICALL DD_OBJiTriggerVolume_Draw(OBJtObject* inObject, uint32_t inDrawFlags)
138{
139 UUtUns32 itr;
140 OBJtOSD_All *inOSD = (OBJtOSD_All *) inObject->object_data;
141 OBJtOSD_TriggerVolume *trigger_osd = &inOSD->osd.trigger_volume_osd;
142 M3tPoint3D *points = trigger_osd->volume.worldPoints;
143 UUtUns32 shade = 0xFFFFFF;
144
145 if (!OBJgTriggerVolume_Visible) {
146 return;
147 }
148
149 if (OBJrTriggerVolume_IntersectsCharacter(inObject, trigger_osd->team_mask, ONgGameState->PlayerCharacter)) {
150 shade = IMcShade_Red;
151 }
152 else
153 {
154 shade = IMcShade_Blue;
155 }
156
157 M3rGeom_Line_Light(points + 0, points + 1, shade);
158 M3rGeom_Line_Light(points + 1, points + 3, shade);
159 M3rGeom_Line_Light(points + 3, points + 2, shade);
160 M3rGeom_Line_Light(points + 2, points + 0, shade);
161
162 M3rGeom_Line_Light(points + 4, points + 5, shade);
163 M3rGeom_Line_Light(points + 5, points + 7, shade);
164 M3rGeom_Line_Light(points + 7, points + 6, shade);
165 M3rGeom_Line_Light(points + 6, points + 4, shade);
166
167 M3rGeom_Line_Light(points + 0, points + 4, shade);
168 M3rGeom_Line_Light(points + 1, points + 5, shade);
169 M3rGeom_Line_Light(points + 3, points + 7, shade);
170 M3rGeom_Line_Light(points + 2, points + 6, shade);
171}
172
173_ONrMechanics_Register Oni_ONrMechanics_Register = (_ONrMechanics_Register)0;
174int16_t ONICALL DD_ONrMechanics_Register(uint32_t inObjectType, uint32_t inObjectTypeIndex, char* inGroupName,
175 uint32_t inSizeInMemory, OBJtMethods* inObjectMethods, uint32_t inFlags, void* inMechanicsMethods)
176{
177 if (strcmp("Trigger Volume", inGroupName) == 0) {
178 inObjectMethods->rDraw = DD_OBJiTriggerVolume_Draw;
179 }
180 return Oni_ONrMechanics_Register(inObjectType, inObjectTypeIndex, inGroupName, inSizeInMemory, inObjectMethods, inFlags, inMechanicsMethods);
181}
182
183_ONrGameState_HandleUtilityInput Oni_ONrGameState_HandleUtilityInput = (_ONrGameState_HandleUtilityInput)0;
184void ONICALL DD_ONrGameState_HandleUtilityInput(const void* inInput)
185{
186 Oni_ONrGameState_HandleUtilityInput(inInput);
187
188 if (ONrDebugKey_WentDown(7)) {
189 OBJgTriggerVolume_Visible = !OBJgTriggerVolume_Visible;
190 }
191}
192
193
194// Enables d_regen script command. Instead of one global flag to only regenerate player each char has a flag to enable local regeneration
195void DD_Patch_Regeneration()
196{
197 // In: WPrInventory_Update
198 Character * Chr = 0;
199 int NoPath = (int)&(Chr[0].RegenHax) & 0x000000FF;
200 const unsigned char regen_patch[] =
201 {0x90, 0x90, 0x90, 0x90, 0x90, // mov al, _WPgRegenerationCheat -> NOOP
202 0x90, 0x90, // test al, al -> NOOP
203 0x90, 0x90, // jz short loc_51BB98 -> NOOP
204 0x8B, 0x86, (char)NoPath, 0x01, 0x00, 0x00, // mov eax, [esi+Character.field_1E8]
205 // -> mov eax, [esi+Character.RegenHax]
206 0x85, 0xC0, // test eax, eax
207 0x74, 0x21 // jnz 0x21 -> jz 0x21
208 };
209 DDrPatch_Const((char*)(OniExe + 0x0011BB64), regen_patch);
210}
211
212
213// Load chinese font DLL if available
214void DD_Patch_Chinese()
215{
216 if (GetFileAttributes("xfhsm_oni.dll") != INVALID_FILE_ATTRIBUTES)
217 {
218 HMODULE dll;
219 DWORD err;
220
221 STARTUPMESSAGE("Loading chinese DLL", 0);
222 dll = LoadLibrary("xfhsm_oni.dll");
223 err = GetLastError();
224 if( dll )
225 {
226 void* proc = GetProcAddress( dll, "InstallHook" );
227 if(proc)
228 {
229 ((CHINESEPROC)proc)(GetCurrentThreadId());
230 }
231 } else {
232 char msg[100];
233 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, msg, 100, NULL);
234 STARTUPMESSAGE("Loading DLL failed with error %i: %s", err, msg);
235 }
236 }
237}
238
239
240
241int DD_Patch_DebugNameTextureInit(short width, short height, int type, int allocated, int flags, char* name, void** output)
242{
243 //flags = (1 << 10);
244 type = 1;
245 //DDrPatch_Byte( 0x005EB83C + 3, 0xff );
246 DDrPatch_Int32((int*)(OniExe + 0x001EB83C), 0xFF000000 );
247 return M3rTextureMap_New(width, height, type, allocated, flags, name, output);
248}
249
250short DD_Patch_DebugNameShadeHack( Character* Char )
251{
252 return TSrContext_SetShade(*(void**)(OniExe + 0x001EB844), ONrCharacter_GetHealthShade( Char->Health, Char->MaxHealth ));
253}
254
255//Fix crappy ai2_shownames
256void DD_Patch_ShowNames()
257{
258 //Set distance above head to 4.0
259 DDrPatch_Int32((int*)(OniExe + 0x0008C998), 0x005296C8);
260 //texture height
261 DDrPatch_Byte((char*)(OniExe + 0x0008C9DF), 0x3F );
262 //texture width
263 DDrPatch_NOOP((char*)(OniExe + 0x0008C9CA), 6 );
264
265/*
266// Crashes game.
267 //Set the text color to whatever we like ;)
268 DDrPatch_NOOP((char*)(OniExe + 0x0008C898), 6 );
269 DDrPatch_Byte((char*)(OniExe + 0x0008C898), 0x8B );
270 DDrPatch_Byte((char*)(OniExe + 0x0008C899), 0xCE );
271
272 DDrPatch_MakeCall((void*)(OniExe + 0x0008C8A3), DD_Patch_DebugNameShadeHack);
273
274 //Make the background black for additive blending
275 DDrPatch_MakeCall((void*)(OniExe + 0x0008C802), DD_Patch_DebugNameTextureInit );
276*/
277}
278
279
280
281
282
283
284
285
286
287bool DD_Patch_Init()
288{
289 STARTUPMESSAGE("Patching engine", 0);
290
291 // Disable UUrPlatform_Initalize/Terminate, this enables the Alt-Tab and the
292 // Windows key but has the possible side effect of allowing the screensaver
293 // to enable itself in-game.
294 if (DDrConfig_GetOptOfType("windows.alttab", C_BOOL)->value.intBoolVal)
295 {
296 // 0xC3 = ret, so makes those functions just have a "ret" instruction at their start
297 DDrPatch_Byte((char*)UUrPlatform_Initialize, 0xC3);
298 DDrPatch_Byte((char*)UUrPlatform_Terminate, 0xC3);
299 }
300
301 // Textures using ARGB8888 can be used
302 if (DDrConfig_GetOptOfType("modding.argb8888", C_BOOL)->value.intBoolVal)
303 {
304 // Update conversion lookups in IMgConvertPixelType_List
305 DDrPatch_Byte((char*)(OniExe + 0x00135af0), 0x07);
306 DDrPatch_Byte((char*)(OniExe + 0x00135af4), 0x0B);
307 }
308
309 // Fix BinkBufferInit() call in BKrMovie_Play() to use GDI (DIB) blitting
310 // instead of DirectDraw; patch ONiRunGame to use the same method to play
311 // outro (ie., BKrMovie_Play() instead of ONrMovie_Play_Hardware() as the
312 // latter has problems on WINE).
313 if (DDrConfig_GetOptOfType("graphics.binkplay", C_BOOL)->value.intBoolVal)
314 {
315 // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION.
316 DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02);
317 // call ONrMovie_Play_Hardware -> call ONrMovie_Play
318 DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play);
319 }
320
321 if (DDrConfig_GetOptOfType("modding.d_regen", C_BOOL)->value.intBoolVal)
322 DD_Patch_Regeneration();
323
324 // Cheats always enabled
325 if (DDrConfig_GetOptOfType("gameplay.cheatsenabled", C_BOOL)->value.intBoolVal)
326 {
327 DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame);
328 }
329
330 // Use Daodan's own cheattable
331 if (DDrConfig_GetOptOfType("gameplay.cheattable", C_BOOL)->value.intBoolVal)
332 {
333 // In ONrGameState_HandleCheats: Replace pointers to orig cheattable
334 DDrPatch_Int32 ((int*)(OniExe + 0x000f616b), (int)&DDr_CheatTable[0].name);
335 DDrPatch_Int32 ((int*)(OniExe + 0x000f617a), (int)&DDr_CheatTable[0].message_on);
336
337 // ONrGameState_HandleCheats: Replace call to ONrCheater
338 DDrPatch_MakeCall((void*)(OniExe + 0x000f618f), (void*)DDrCheater);
339
340 // In: ONrGameState_DoCharacterFrame
341 // -> NOP; PUSH ebp; CALL FallingFrames
342 // Replace fall height frame counter (actually in-air frame counter) increase by a
343 // conditional one (only counted when inc_fallingframes)
344 DDrPatch_Int16((short*)(OniExe + 0x000deb45), 0x5590);
345 DDrPatch_MakeCall((void*)(OniExe + 0x000deb47), (void*)FallingFrames);
346
347 // At end of ONrUnlockLevel to init values on level loading
348 DDrPatch_MakeJump((void*)(OniExe + 0x0010f021), (void*)DDrCheater_LevelLoad);
349 }
350
351 if (DDrConfig_GetOptOfType("language.chinese", C_BOOL)->value.intBoolVal)
352 DD_Patch_Chinese();
353
354 // Limit cursor to Oni's window
355 if (DDrConfig_GetOptOfType("windows.clipcursor", C_BOOL)->value.intBoolVal)
356 {
357 // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook.
358 DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set);
359
360 // LIrMode_Set_Internal: replace LIrPlatform_Mode_Set call with our hook.
361 DDrPatch_MakeCall((void*)(OniExe + 0x00003fff), (void*) DD_LIrPlatform_Mode_Set);
362
363 // LIrTerminate: replace LIrPlatform_Terminate call with our hook.
364 DDrPatch_MakeCall((void*)(OniExe + 0x000004cb8), (void*) DD_LIrPlatform_Terminate);
365 }
366
367 // Disables weapon cooldown exploit
368 if (DDrConfig_GetOptOfType("gameplay.cooldowntimer", C_BOOL)->value.intBoolVal)
369 {
370 // In WPrRelease: NoOp 4 MOVs
371 DDrPatch_NOOP((char*)(OniExe + 0x0011a825), 22);
372 }
373
374 // Daodan device mode enumeration function
375 if (DDrConfig_GetOptOfType("graphics.displayenum", C_BOOL)->value.intBoolVal)
376 {
377 DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)DD_GLrEnumerateDisplayModes);
378 }
379
380 // Forced DirectInput (for Windows NT)
381 if (DDrConfig_GetOptOfType("windows.directinput", C_BOOL)->value.intBoolVal)
382 {
383 // LIrPlatform_Initialize: replace conditional jump by unconditional
384 DDrPatch_Byte((char*)(OniExe + 0x00002e6d), 0xeb);
385 }
386
387 // Disable Oni's command line parser so it doesn't interfere with ours
388 if (DDrConfig_GetOptOfType("windows.disablecmdline", C_BOOL)->value.intBoolVal)
389 {
390 // Replace start of OniParseCommandLine with XOR eax,eax; RET
391 DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0x00c3c033);
392 // NoOp first 51 byte in ONiMain, including tests and conditional exec of CLrGetCommandLine
393 DDrPatch_NOOP((char*)(OniExe + 0x000d3280), 51);
394 }
395
396 // Font texture cache doubled
397 if (DDrConfig_GetOptOfType("language.fonttexturecache", C_BOOL)->value.intBoolVal)
398 {
399 // Double two values in TMrGame_Initialize
400 DDrPatch_Byte((char*)(OniExe + 0x00020ea7), 0x20);
401 DDrPatch_Byte((char*)(OniExe + 0x00020f4a), 0x40);
402 }
403
404 // Allow HD screens on resolutions < 1024*768
405 if (DDrConfig_GetOptOfType("modding.hdscreens_lowres", C_BOOL)->value.intBoolVal)
406 {
407 DDrPatch_MakeJump((void*)M3rDraw_BigBitmap, (void*)DD_M3rDraw_BigBitmap);
408 }
409
410 // Allow for console to show on higher resolutions
411 if (DDrConfig_GetOptOfType("devmode.highres_console", C_BOOL)->value.intBoolVal)
412 {
413 Oni_COrTextArea_Resize = DDrPatch_MakeDetour((void*)COrTextArea_Resize, (void*)DD_COrTextArea_Resize);
414 }
415
416 // Hackish fix for Konoko not kicking guns
417 // Don't use this, it breaks stairs.
418 if (DDrConfig_GetOptOfType("gameplay.kickguns", C_BOOL)->value.intBoolVal)
419 {
420 // In ONrCharacter_EnablePhysics: Load different values to same addresses as before
421 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 };
422 DDrPatch_Const ((char*)(OniExe + 0x000dc420), kickgun_patch);
423 }
424
425 // Disable loading the vtuneapi.dll
426 if (DDrConfig_GetOptOfType("windows.killvtune", C_BOOL)->value.intBoolVal)
427 {
428 // Instantly return from UUrLoadVtuneAPI
429 DDrPatch_Byte((char*)(OniExe + 0x00026340), 0xC3);
430 }
431
432 // Now supports textures up to 512x512
433 if (DDrConfig_GetOptOfType("modding.largetextures", C_BOOL)->value.intBoolVal)
434 {
435 DDrPatch_Byte((char*)(OniExe + 0x00005251), 0x10);
436 }
437
438 // Non-"_Final" levels are now valid
439 if (DDrConfig_GetOptOfType("modding.levelplugins", C_BOOL)->value.intBoolVal)
440 {
441 // Patch in TMrUtility_LevelInfo_Get:
442 DDrPatch_Byte((char*)(OniExe + 0x000206a8), 0x01);
443 }
444
445 // Weapon on ground shown with name and magazine contents
446 if (DDrConfig_GetOptOfType("graphics.newweap", C_BOOL)->value.intBoolVal)
447 {
448 //Makes it always say "Received weapon_name."
449 //Needs check for loc_4DFC66
450 //DDrPatch_NOOP((char*)(OniExe + 0x000E4DF8),2);
451
452 //Adds Weapon name and ammo meter to pickup autoprompt (patches to ONrGameState_ProcessHeartbeat)
453 // Do not call WPrHasAmmo and ignore conditional jump:
454 DDrPatch_NOOP((char*)(OniExe + 0x000FAC73), 9);
455 // Do not load ecx with some magic value?
456 DDrPatch_NOOP((char*)(OniExe + 0x000FAC80), 5);
457 // Replace call to ONiGameState_FindAutoPromptMessage
458 DDrPatch_MakeCall((void*)(OniExe + 0xFAC85), (void*)DDrWeapon2Message);
459
460 //Moves location of colors
461 //DDrPatch_Int32((int*)(OniExe + 0x0002E3D5), (int)&DDrDSayColors );
462 //DDrPatch_Int32((int*)(OniExe + 0x0002E3DA), (int)&DDrDSayColors );
463 }
464
465 // Disable Multi-byte character awareness patch (multiple language support)
466 if (DDrConfig_GetOptOfType("language.nomultibyte", C_BOOL)->value.intBoolVal)
467 {
468 // TSiContext_DrawLine: Replace conditional jumps by unconditional ones
469 DDrPatch_Byte ((char*)(OniExe + 0x0002d8f8), 0xeb);
470 DDrPatch_Byte ((char*)(OniExe + 0x0002d9ad), 0xeb);
471 // TSiContext_DrawTextLine: same
472 DDrPatch_Byte ((char*)(OniExe + 0x0002dbe2), 0xeb);
473 DDrPatch_Byte ((char*)(OniExe + 0x0002dec3), 0xeb);
474 // TSrContext_FormatString: same
475 DDrPatch_Byte ((char*)(OniExe + 0x0002e2ab), 0xeb);
476 DDrPatch_Byte ((char*)(OniExe + 0x0002e2c4), 0xeb);
477 DDrPatch_Byte ((char*)(OniExe + 0x0002e379), 0xeb);
478 DDrPatch_Byte ((char*)(OniExe + 0x0002e48c), 0xeb);
479 DDrPatch_Byte ((char*)(OniExe + 0x0002e4d0), 0xeb);
480 DDrPatch_Byte ((char*)(OniExe + 0x0002e4f4), 0xeb);
481 DDrPatch_Byte ((char*)(OniExe + 0x0002e646), 0xeb);
482 DDrPatch_Byte ((char*)(OniExe + 0x0002e695), 0xeb);
483 // TSrContext_GetStringRect: same
484 DDrPatch_Byte ((char*)(OniExe + 0x0002e944), 0xeb);
485 DDrPatch_Byte ((char*)(OniExe + 0x0002e95d), 0xeb);
486 DDrPatch_Byte ((char*)(OniExe + 0x0002e98e), 0xeb);
487 DDrPatch_Byte ((char*)(OniExe + 0x0002e9dc), 0xeb);
488 }
489
490 // Fix options not visible in main menu when a game was started
491 if (DDrConfig_GetOptOfType("graphics.optionsvisible", C_BOOL)->value.intBoolVal)
492 {
493 // replace WMrWindow_SetVisible calls
494 DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton);
495 DDrPatch_MakeCall((void*)(OniExe + 0x000d2d43), DDrShowResumeButton);
496 }
497
498 // Pathfinding grid cache size x8
499 if (DDrConfig_GetOptOfType("gameplay.pathfinding", C_BOOL)->value.intBoolVal)
500 {
501 // Replaces conditional jump (je) with unconditional jump
502 const unsigned char pathfinding[2] = {0x90 , 0xE9 };
503 DDrPatch_Byte ((char*)(OniExe + 0x0010b03b), 0x20);
504 DDrPatch_Byte ((char*)(OniExe + 0x0010b04c), 0x20);
505
506 //other stuff
507 DDrPatch_Const((char*)(OniExe + 0x00040789), pathfinding);
508 }
509
510 // Projectile awareness fixed
511 if (DDrConfig_GetOptOfType("gameplay.projaware", C_BOOL)->value.intBoolVal)
512 {
513 DDrPatch_Byte ((char*)(OniExe + 0x0009c07c), 0x6c);
514 DDrPatch_Byte ((char*)(OniExe + 0x0009c080), 0x70);
515 DDrPatch_Byte ((char*)(OniExe + 0x0009c084), 0x74);
516 DDrPatch_Byte ((char*)(OniExe + 0x0009c110), 0x6c);
517 }
518
519 // Safe startup message printer
520 if (DDrConfig_GetOptOfType("windows.safeprintf", C_BOOL)->value.intBoolVal)
521 {
522 DDrPatch_MakeJump((void*)UUrStartupMessage, (void*)DDrStartupMessage);
523 }
524
525 // Show all (also enemies') lasersights
526 if (DDrConfig_GetOptOfType("graphics.showalllasersights", C_BOOL)->value.intBoolVal)
527 {
528 DDrPatch_NOOP((char*)(OniExe + 0x000E1957), 6 );
529 }
530
531 // Allow bsl-var show_triggervolumes or ctrl+shift+x (devmode) to work
532 if (DDrConfig_GetOptOfType("devmode.showtriggervolumes", C_BOOL)->value.intBoolVal)
533 {
534 Oni_ONrMechanics_Register = DDrPatch_MakeDetour((void*)ONrMechanics_Register, (void*)DD_ONrMechanics_Register);
535 Oni_ONrGameState_HandleUtilityInput = DDrPatch_MakeDetour((void*)ONrGameState_HandleUtilityInput, (void*)DD_ONrGameState_HandleUtilityInput);
536 }
537
538 // Experiment with allowing enemies to be thrown over railings
539 if (DDrConfig_GetOptOfType("gameplay.throwtest", C_BOOL)->value.intBoolVal)
540 {
541 DDrPatch_NOOP((char*)(OniExe + 0x000dc190), 10);
542 }
543
544 // DaodanGL with windowed mode support
545 if (DDrConfig_GetOptOfType("graphics.daodangl", C_BOOL)->value.intBoolVal)
546 {
547 // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect.
548 DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6);
549 DDrPatch_MakeCall((char*) OniExe + 0x00002dd6, (void*) GetClientRect);
550
551 // UUrWindow_GetSize: GetWindowRect -> GetClientRect.
552 DDrPatch_NOOP((char*) OniExe + 0x0002651c, 6);
553 DDrPatch_MakeCall((char*) OniExe + 0x0002651c, (void*) GetClientRect);
554
555 // LIrPlatform_PollInputForAction: fix GetCursorPos call to return client coordinates.
556 DDrPatch_NOOP((char*) OniExe + 0x000032cc, 6);
557 DDrPatch_MakeCall((char*) OniExe + 0x000032cc, (void*) DD_GetCursorPos);
558
559 // LIrPlatform_InputEvent_GetMouse: fix GetCursorPos call to return client coordinates.
560 DDrPatch_NOOP((char*) OniExe + 0x00002cc2, 6);
561 DDrPatch_MakeCall((char*) OniExe + 0x00002cc2, (void*) DD_GetCursorPos);
562
563 // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
564 DDrPatch_NOOP((char*) OniExe + 0x000032b7, 6);
565 DDrPatch_MakeCall((char*) OniExe + 0x000032b7, (void*) DD_SetCursorPos);
566
567 // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
568 DDrPatch_NOOP((char*) OniExe + 0x00003349, 6);
569 DDrPatch_MakeCall((char*) OniExe + 0x00003349, (void*) DD_SetCursorPos);
570
571 // Replace ONrPlatformInitialize.
572 DDrPatch_MakeJump((void*) ONrPlatform_Initialize, (void*) DD_ONrPlatform_Initialize);
573
574 // Replace gl_platform_initialize.
575 DDrPatch_MakeJump((void*) gl_platform_initialize, (void*) DD_GLrPlatform_Initialize);
576
577 // Replace gl_platform_dispose.
578 DDrPatch_MakeJump((void *) gl_platform_dispose, (void*) DD_GLrPlatform_Dispose);
579 }
580
581 // Performance patch
582 if (DDrConfig_GetOptOfType("windows.usegettickcount", C_BOOL)->value.intBoolVal)
583 {
584 DDrPatch_MakeJump((void*)UUrMachineTime_High, (void*)DDrMachineTime_High);
585 DDrPatch_MakeJump((void*)UUrMachineTime_High_Frequency, (void*)DDrMachineTime_High_Frequency);
586 DDrPatch_MakeJump((void*)UUrMachineTime_Sixtieths, (void*)DDrMachineTime_Sixtieths);
587 }
588
589 // Fix displaying the talking portraits in widescreen modes
590 if (DDrConfig_GetOptOfType("graphics.widescreenportraits", C_BOOL)->value.intBoolVal)
591 {
592 SLrDaodan_Patch();
593 }
594
595 // Adds working function for existing BSL command wp_fadetime, sets fade time to 4800
596 if (DDrConfig_GetOptOfType("gameplay.wpfadetime", C_BOOL)->value.intBoolVal)
597 {
598 // Makes wp_fadetime actually have a function (changes within WPrRelease)
599 // Patches end of function to instead of use a constant value for fadetime (12c0 = 4800) actually use value of wp_fadetime:
600 // orig: MOV [esi+0x46], 0x12c0 ; POP ebx ; POP esi ; ADD esp, 0x14 ; RET
601 // new: MOV bx, [0x627dc4] ; MOV [esi+0x46], bx ; POP ebx ; POP esi ; ADD esp, 0x14 ; RET
602 const unsigned char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 };
603 DDrPatch_Const ((char*)(OniExe + 0x0011a889), fadetime_patch);
604 // Fixes jump because of new length of code in patch
605 DDrPatch_Byte ((char*)(OniExe + 0x0011a560), 0x31);
606
607 // Sets the fadetime to 4800 by default (in WPrInitialize)
608 DDrPatch_Int16 ((short*)(OniExe + 0x0011ab0e), 4800);
609 }
610
611 // Adds new BSL functions
612 // Replaces an early unused call (OBJrLevel_Unload_Unknown_2) in ONiMain
613 DDrPatch_MakeCall((void*)(OniExe + 0x000d345a), (void*)DDrGame_Init);
614
615 // Disable gamma slider in options in windowed mode
616 // In ONiOGU_Options_Callback: Replace WMrSlider_SetRange
617 DDrPatch_MakeCall((void*)(OniExe + 0x000d262c), (void*)DD_ONiOGU_GammaSlider_SetRange);
618
619 // Fix the warning print method
620 // Replace UUrError_Report_Internal
621 DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning);
622
623 DD_Patch_ShowNames();
624
625 return true;
626}
627
Note: See TracBrowser for help on using the repository browser.