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