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 |
// Replace start of OniParseCommandLine with XOR ax,ax; RET |
353 |
// DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0xc3c03366); |
354 |
// Replace start of OniParseCommandLine with XOR eax,eax; RET |
355 |
DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0x00c3c033); |
356 |
} |
357 |
|
358 |
// Enable flatline multiplayer code |
359 |
void DD_Patch_Flatline() |
360 |
{ |
361 |
DDrPatch_MakeCall((void*)(OniExe + 0x000E17F6), FLrHook_Lasers ); |
362 |
|
363 |
//Flatline related stuff |
364 |
DDrPatch_MakeCall((void*)(OniExe + 0x000FBCEA), DDrText_Hook); |
365 |
|
366 |
DDrPatch_Int32((int*)(OniExe + 0x000B24D2), (unsigned int)FLrSpawnHack); |
367 |
|
368 |
DDrPatch_NOOP((char*)(OniExe + 0x000C26CB), 6); |
369 |
|
370 |
DDrPatch_MakeCall((void*)(OniExe + 0x000C26CB), FLrHook_DoorOpen); |
371 |
DDrPatch_MakeCall((void*)(OniExe + 0x000EE3CF), FLrHook_ConsoleActivate); |
372 |
} |
373 |
|
374 |
// Font texture cache doubled |
375 |
void DD_Patch_FontTextureCache() |
376 |
{ |
377 |
DDrPatch_Byte((char*)(OniExe + 0x00020ea7), 0x20); |
378 |
DDrPatch_Byte((char*)(OniExe + 0x00020f4a), 0x40); |
379 |
} |
380 |
|
381 |
// Disable Oni's internal CLrGetCommandLine function (to eventually replace it with our own) |
382 |
void DD_Patch_GetCmdLine() |
383 |
{ |
384 |
DDrPatch_NOOP ((char*)(OniExe + 0x000d3280), 51); |
385 |
} |
386 |
|
387 |
// Allow HD screens with resolution < 1024*768 |
388 |
void DD_Patch_HDScreens_LowRes() |
389 |
{ |
390 |
DDrPatch_MakeJump((void*)M3rDraw_BigBitmap, (void*)DD_M3rDraw_BigBitmap); |
391 |
} |
392 |
|
393 |
void DD_Patch_HighresConsole() { |
394 |
Oni_COrTextArea_Resize = DDrPatch_MakeDetour((void*)COrTextArea_Resize, (void*)DD_COrTextArea_Resize); |
395 |
} |
396 |
|
397 |
// Hackish fix for Konoko not kicking guns |
398 |
// Don't use this, it breaks stairs. |
399 |
void DD_Patch_KickGuns() |
400 |
{ |
401 |
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 }; |
402 |
DDrPatch_Const ((char*)(OniExe + 0x000dc420), kickgun_patch); |
403 |
} |
404 |
|
405 |
// Disable loading the vtuneapi.dll |
406 |
void DD_Patch_KillVTune() |
407 |
{ |
408 |
DDrPatch_Byte ((char*)(OniExe + 0x00026340), 0xC3); |
409 |
} |
410 |
|
411 |
// Now supports textures up to 512x512 |
412 |
void DD_Patch_LargeTextures() |
413 |
{ |
414 |
DDrPatch_Byte ((char*)(OniExe + 0x00005251), 0x10); |
415 |
} |
416 |
|
417 |
// Non-"_Final" levels are now valid |
418 |
void DD_Patch_LevelPlugins() |
419 |
{ |
420 |
DDrPatch_Byte ((char*)(OniExe + 0x000206a8), 0x01); |
421 |
} |
422 |
|
423 |
// Weapon on ground shown with name and magazine contents |
424 |
void DD_Patch_NewWeap() |
425 |
{ |
426 |
//Makes it always say "Received weapon_name." |
427 |
//Needs check for loc_4DFC66 |
428 |
//DDrPatch_NOOP((char*)(OniExe + 0x000E4DF8),2); |
429 |
|
430 |
//Adds Weapon name and ammo meter to pickup autoprompt |
431 |
DDrPatch_NOOP((char*)(OniExe + 0x000FAC73), 9); |
432 |
DDrPatch_NOOP((char*)(OniExe + 0x000FAC80), 5); |
433 |
DDrPatch_MakeCall((void*)(OniExe + 0xFAC85), (void*)DDrWeapon2Message); |
434 |
|
435 |
//Moves location of colors |
436 |
//DDrPatch_Int32((int*)(OniExe + 0x0002E3D5), (int)&DDrDSayColors ); |
437 |
//DDrPatch_Int32((int*)(OniExe + 0x0002E3DA), (int)&DDrDSayColors ); |
438 |
} |
439 |
|
440 |
// Disable Multi-byte character awareness patch (multiple language support) |
441 |
void DD_Patch_NoMultiByte() |
442 |
{ |
443 |
DDrPatch_Byte ((char*)(OniExe + 0x0002d8f8), 0xeb); |
444 |
DDrPatch_Byte ((char*)(OniExe + 0x0002d9ad), 0xeb); |
445 |
DDrPatch_Byte ((char*)(OniExe + 0x0002dbe2), 0xeb); |
446 |
DDrPatch_Byte ((char*)(OniExe + 0x0002dec3), 0xeb); |
447 |
DDrPatch_Byte ((char*)(OniExe + 0x0002e2ab), 0xeb); |
448 |
DDrPatch_Byte ((char*)(OniExe + 0x0002e2c4), 0xeb); |
449 |
DDrPatch_Byte ((char*)(OniExe + 0x0002e379), 0xeb); |
450 |
DDrPatch_Byte ((char*)(OniExe + 0x0002e48c), 0xeb); |
451 |
DDrPatch_Byte ((char*)(OniExe + 0x0002e4d0), 0xeb); |
452 |
DDrPatch_Byte ((char*)(OniExe + 0x0002e4f4), 0xeb); |
453 |
DDrPatch_Byte ((char*)(OniExe + 0x0002e646), 0xeb); |
454 |
DDrPatch_Byte ((char*)(OniExe + 0x0002e695), 0xeb); |
455 |
DDrPatch_Byte ((char*)(OniExe + 0x0002e944), 0xeb); |
456 |
DDrPatch_Byte ((char*)(OniExe + 0x0002e95d), 0xeb); |
457 |
DDrPatch_Byte ((char*)(OniExe + 0x0002e98e), 0xeb); |
458 |
DDrPatch_Byte ((char*)(OniExe + 0x0002e9dc), 0xeb); |
459 |
} |
460 |
|
461 |
// Fix options not visible in main menu when a game was started |
462 |
void DD_Patch_OptionsVisible() |
463 |
{ |
464 |
DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton); |
465 |
DDrPatch_MakeCall((void*)(OniExe + 0x000d2d43), DDrShowResumeButton); |
466 |
} |
467 |
|
468 |
// Unlocks particle action disabling/enabling bits for all events. (Will be |
469 |
// controlled by a command line switch when I figure out how to do that without |
470 |
// Win32 hacks.) |
471 |
void DD_Patch_ParticleDisableBit() |
472 |
{ |
473 |
DDrPatch_Int16 ((short*)(OniExe + 0x001b184), 0x9090); |
474 |
} |
475 |
|
476 |
// Pathfinding grid cache size x8 |
477 |
void DD_Patch_PathFinding() |
478 |
{ |
479 |
const unsigned char pathfinding[2] = {0x90 , 0xE9 }; |
480 |
DDrPatch_Byte ((char*)(OniExe + 0x0010b03b), 0x20); |
481 |
DDrPatch_Byte ((char*)(OniExe + 0x0010b04c), 0x20); |
482 |
|
483 |
//other stuff |
484 |
DDrPatch_Const((char*)(OniExe + 0x00040789), pathfinding); |
485 |
} |
486 |
|
487 |
// Projectile awareness fixed |
488 |
void DD_Patch_ProjAware() |
489 |
{ |
490 |
DDrPatch_Byte ((char*)(OniExe + 0x0009c07c), 0x6c); |
491 |
DDrPatch_Byte ((char*)(OniExe + 0x0009c080), 0x70); |
492 |
DDrPatch_Byte ((char*)(OniExe + 0x0009c084), 0x74); |
493 |
DDrPatch_Byte ((char*)(OniExe + 0x0009c110), 0x6c); |
494 |
} |
495 |
|
496 |
// Safe startup message printer |
497 |
void DD_Patch_SafePrintf() |
498 |
{ |
499 |
DDrPatch_MakeJump((void*)UUrStartupMessage, (void*)DDrStartupMessage); |
500 |
} |
501 |
|
502 |
// Show all (also enemies') lasersights |
503 |
void DD_Patch_ShowAllLasersights() |
504 |
{ |
505 |
DDrPatch_NOOP((char*)(OniExe + 0x000E1957), 6 ); |
506 |
} |
507 |
|
508 |
void DD_Patch_ShowTriggerVolumes() |
509 |
{ |
510 |
Oni_ONrMechanics_Register = DDrPatch_MakeDetour((void*)ONrMechanics_Register, (void*)DD_ONrMechanics_Register); |
511 |
Oni_ONrGameState_HandleUtilityInput = DDrPatch_MakeDetour((void*)ONrGameState_HandleUtilityInput, (void*)DD_ONrGameState_HandleUtilityInput); |
512 |
} |
513 |
|
514 |
// Experiment with allowing enemies to be thrown over railings |
515 |
void DD_Patch_Throwtest() |
516 |
{ |
517 |
const unsigned char throwtest_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }; |
518 |
DDrPatch_Const((char*)(OniExe + 0x000dc190), throwtest_patch); |
519 |
} |
520 |
|
521 |
// DaodanGL with windowed mode support |
522 |
void DD_Patch_UseDaodanGL() |
523 |
{ |
524 |
// LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect. |
525 |
DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6); |
526 |
DDrPatch_MakeCall((char*) OniExe + 0x00002dd6, (void*) GetClientRect); |
527 |
|
528 |
// UUrWindow_GetSize: GetWindowRect -> GetClientRect. |
529 |
DDrPatch_NOOP((char*) OniExe + 0x0002651c, 6); |
530 |
DDrPatch_MakeCall((char*) OniExe + 0x0002651c, (void*) GetClientRect); |
531 |
|
532 |
// LIrPlatform_PollInputForAction: fix GetCursorPos call to return client coordinates. |
533 |
DDrPatch_NOOP((char*) OniExe + 0x000032cc, 6); |
534 |
DDrPatch_MakeCall((char*) OniExe + 0x000032cc, (void*) DD_GetCursorPos); |
535 |
|
536 |
// LIrPlatform_InputEvent_GetMouse: fix GetCursorPos call to return client coordinates. |
537 |
DDrPatch_NOOP((char*) OniExe + 0x00002cc2, 6); |
538 |
DDrPatch_MakeCall((char*) OniExe + 0x00002cc2, (void*) DD_GetCursorPos); |
539 |
|
540 |
// LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates. |
541 |
DDrPatch_NOOP((char*) OniExe + 0x000032b7, 6); |
542 |
DDrPatch_MakeCall((char*) OniExe + 0x000032b7, (void*) DD_SetCursorPos); |
543 |
|
544 |
// LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates. |
545 |
DDrPatch_NOOP((char*) OniExe + 0x00003349, 6); |
546 |
DDrPatch_MakeCall((char*) OniExe + 0x00003349, (void*) DD_SetCursorPos); |
547 |
|
548 |
// Replace ONrPlatformInitialize. |
549 |
DDrPatch_MakeJump((void*) ONrPlatform_Initialize, (void*) DD_ONrPlatform_Initialize); |
550 |
|
551 |
// Replace gl_platform_initialize. |
552 |
DDrPatch_MakeJump((void*) gl_platform_initialize, (void*) DD_GLrPlatform_Initialize); |
553 |
|
554 |
// Replace gl_platform_dispose. |
555 |
DDrPatch_MakeJump((void *) gl_platform_dispose, (void*) DD_GLrPlatform_Dispose); |
556 |
} |
557 |
|
558 |
// Performance patch |
559 |
void DD_Patch_UseGetTickCount() |
560 |
{ |
561 |
DDrPatch_MakeJump((void*)UUrMachineTime_High, (void*)DDrMachineTime_High); |
562 |
DDrPatch_MakeJump((void*)UUrMachineTime_High_Frequency, (void*)DDrMachineTime_High_Frequency); |
563 |
DDrPatch_MakeJump((void*)UUrMachineTime_Sixtieths, (void*)DDrMachineTime_Sixtieths); |
564 |
} |
565 |
|
566 |
// Adds working function for existing BSL command wp_fadetime, sets fade time to 4800 |
567 |
void DD_Patch_WpFadetime() |
568 |
{ |
569 |
// Makes wp_fadetime actually have a function |
570 |
const unsigned char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 }; |
571 |
DDrPatch_Const ((char*)(OniExe + 0x0011a889), fadetime_patch); |
572 |
DDrPatch_Byte ((char*)(OniExe + 0x0011a560), 0x31); |
573 |
|
574 |
// Sets the fadetime to 4800 by default |
575 |
DDrPatch_Int16 ((short*)(OniExe + 0x0011ab0e), 0x12c0); |
576 |
} |
577 |
|
578 |
// Disable gamma slider in options in windowed mode |
579 |
void DD_Patch_GammaSlider() |
580 |
{ |
581 |
DDrPatch_MakeCall((void*)(OniExe + 0x000d262c), (void*)DD_ONiOGU_GammaSlider_SetRange); |
582 |
} |
583 |
|
584 |
// Fix the warning print method |
585 |
void DD_Patch_PrintWarning() |
586 |
{ |
587 |
DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning); |
588 |
} |
589 |
|
590 |
//Fix crappy ai2_shownames |
591 |
void DD_Patch_ShowNames() |
592 |
{ |
593 |
//Set distance above head to 4.0 |
594 |
DDrPatch_Int32((int*)(OniExe + 0x0008C998), 0x005296C8); |
595 |
//texture height |
596 |
DDrPatch_Byte((char*)(OniExe + 0x0008C9DF), 0x3F ); |
597 |
//texture width |
598 |
DDrPatch_NOOP((char*)(OniExe + 0x0008C9CA), 6 ); |
599 |
|
600 |
/* |
601 |
// Crashes game. |
602 |
//Set the text color to whatever we like ;) |
603 |
DDrPatch_NOOP((char*)(OniExe + 0x0008C898), 6 ); |
604 |
DDrPatch_Byte((char*)(OniExe + 0x0008C898), 0x8B ); |
605 |
DDrPatch_Byte((char*)(OniExe + 0x0008C899), 0xCE ); |
606 |
|
607 |
DDrPatch_MakeCall((void*)(OniExe + 0x0008C8A3), DD_Patch_DebugNameShadeHack); |
608 |
|
609 |
//Make the background black for additive blending |
610 |
DDrPatch_MakeCall((void*)(OniExe + 0x0008C802), DD_Patch_DebugNameTextureInit ); |
611 |
*/ |
612 |
} |
613 |
|
614 |
/* |
615 |
void DD_Patch_ShowTriggerVolumes() |
616 |
{ |
617 |
DDrPatch_Int32((int*)(OniExe + 0x000cc9bb+4), (uint32_t)DD_OBJiTriggerVolume_Draw); |
618 |
} |
619 |
|
620 |
void DD_Patch_ShowFlags() |
621 |
{ |
622 |
DDrPatch_Int32((int*)(OniExe + 0x000c4ed4+4), (uint32_t)DD_OBJiFlag_Draw); |
623 |
} |
624 |
*/ |
625 |
|
626 |
bool DD_Patch_Init() |
627 |
{ |
628 |
DDrStartupMessage("Daodan: Patching engine"); |
629 |
|
630 |
if (patch_alttab) |
631 |
DD_Patch_AltTab(); |
632 |
|
633 |
if (patch_argb8888) |
634 |
DD_Patch_ARGB8888(); |
635 |
|
636 |
if (patch_binkplay) |
637 |
DD_Patch_BinkPlay(); |
638 |
|
639 |
if (patch_bsl) |
640 |
DD_Patch_BSL(); |
641 |
|
642 |
if (patch_cheater) |
643 |
DD_Patch_Cheater(); |
644 |
|
645 |
if (patch_cheatsenabled) |
646 |
DD_Patch_CheatsEnabled(); |
647 |
|
648 |
if (patch_cheattable) |
649 |
DD_Patch_CheatTable(); |
650 |
|
651 |
if (patch_chinese) |
652 |
DD_Patch_Chinese(); |
653 |
|
654 |
if (patch_clipcursor) |
655 |
DD_Patch_ClipCursor(); |
656 |
|
657 |
if (patch_cooldowntimer) |
658 |
DD_Patch_CooldownTimer(); |
659 |
|
660 |
if (patch_daodandisplayenum) |
661 |
DD_Patch_DaodanDisplayEnum(); |
662 |
|
663 |
if (patch_directinput) |
664 |
DD_Patch_DirectInput(); |
665 |
|
666 |
if (patch_disablecmdline) |
667 |
DD_Patch_DisableCmdLine(); |
668 |
|
669 |
if (patch_fonttexturecache) |
670 |
DD_Patch_FontTextureCache(); |
671 |
|
672 |
if (patch_getcmdline) |
673 |
DD_Patch_GetCmdLine(); |
674 |
|
675 |
if (patch_hdscreens_lowres) |
676 |
DD_Patch_HDScreens_LowRes(); |
677 |
|
678 |
if (patch_highres_console) |
679 |
DD_Patch_HighresConsole(); |
680 |
|
681 |
if (patch_kickguns) |
682 |
DD_Patch_KickGuns(); |
683 |
|
684 |
//if (patch_killvtune) |
685 |
// DD_Patch_KillVTune(); |
686 |
|
687 |
if (patch_largetextures) |
688 |
DD_Patch_LargeTextures(); |
689 |
|
690 |
if (patch_levelplugins) |
691 |
DD_Patch_LevelPlugins(); |
692 |
|
693 |
if (patch_newweapon) |
694 |
DD_Patch_NewWeap(); |
695 |
|
696 |
if (patch_nomultibyte) |
697 |
DD_Patch_NoMultiByte(); |
698 |
|
699 |
if(patch_optionsvisible) |
700 |
DD_Patch_OptionsVisible(); |
701 |
|
702 |
if (patch_particledisablebit) |
703 |
DD_Patch_ParticleDisableBit(); |
704 |
|
705 |
if (patch_pathfinding) |
706 |
DD_Patch_PathFinding(); |
707 |
|
708 |
if (patch_projaware) |
709 |
DD_Patch_ProjAware(); |
710 |
|
711 |
if (patch_safeprintf) |
712 |
DD_Patch_SafePrintf(); |
713 |
|
714 |
if (patch_showalllasersights) |
715 |
DD_Patch_ShowAllLasersights(); |
716 |
|
717 |
if (patch_showtriggervolumes) |
718 |
DD_Patch_ShowTriggerVolumes(); |
719 |
|
720 |
if (patch_throwtest) |
721 |
DD_Patch_Throwtest(); |
722 |
|
723 |
if (patch_usedaodangl) |
724 |
DD_Patch_UseDaodanGL(); |
725 |
|
726 |
if (patch_usegettickcount) |
727 |
DD_Patch_UseGetTickCount(); |
728 |
|
729 |
if (patch_wpfadetime) |
730 |
DD_Patch_WpFadetime(); |
731 |
|
732 |
|
733 |
DD_Patch_DaodanInit(); |
734 |
|
735 |
DD_Patch_GammaSlider(); |
736 |
|
737 |
DD_Patch_PrintWarning(); |
738 |
|
739 |
|
740 |
DD_Patch_ShowNames(); |
741 |
/* |
742 |
DD_Patch_ShowTriggerVolumes(); |
743 |
DD_Patch_ShowFlags(); |
744 |
*/ |
745 |
if (patch_flatline) |
746 |
DD_Patch_Flatline(); |
747 |
|
748 |
return true; |
749 |
} |
750 |
|