From fd94cced1f434107a18ca3b171a4211107fd2a21 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Thu, 30 Jul 2026 10:53:38 -0400 Subject: Cleanup new IntPtr spam Signed-off-by: Andrew Opalach --- Plugin.cs | 152 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 77 insertions(+), 75 deletions(-) diff --git a/Plugin.cs b/Plugin.cs index 6547a0a..f05fbee 100755 --- a/Plugin.cs +++ b/Plugin.cs @@ -76,6 +76,8 @@ namespace WorldTuningTool #endif } + private static nint lton(long l) { unchecked { return (nint)l; } } + private static byte ByteFlag(bool f) { return f ? (byte)0x1 : (byte)0x0; } private static Vector4 ColorVectorFromInt(int c) @@ -1466,8 +1468,8 @@ namespace WorldTuningTool private static Parameter[] contactShadowParameters = { newParameter("Fake Light Intensity", 0xEC40, ParameterType.FLOAT), // MonsterHunterWorld.exe+1B18711 - mov [rbx+0000EC44],3F800000 (Other unknown reference). - newParameter("Fake Light Intensity (Gameplay)", new IntPtr(0x141B1A19F) + 0x6, ParameterType.PATCH_FLOAT), - newParameter("Fake Light Blend", new IntPtr(0x141CDE0CE) + 0x6, ParameterType.PATCH_FLOAT), + newParameter("Fake Light Intensity (Gameplay)", lton(0x141B1A19F) + 0x6, ParameterType.PATCH_FLOAT), + newParameter("Fake Light Blend", lton(0x141CDE0CE) + 0x6, ParameterType.PATCH_FLOAT), newParameter("Force Disable Contact Shadows", 0xB4ED, ParameterType.BOOL), newParameter("Facial Contact Shadows Enabled", 0xB4EE, ParameterType.BOOL), newParameter("Facial Contact Shadows Enable Noise", 0xB501, ParameterType.BOOL), @@ -2186,7 +2188,7 @@ namespace WorldTuningTool removeFromScene = new NativeAction(0x142228F10); updateLights = Hook.Create(0x141F88F30, UpdateLightsHook); - IntPtr addr = PatternScanner.FindFirst(Pattern.FromString("48 89 5C 24 10 48 89 74 24 18 48 89 7C 24 20 55 41 56 41 57 48 8B EC 48 83 EC 30 48 8B FA 48 8B D9 E8 AA B6 C1 FF 48 8B 47 10 48 8D 57 50")); + nint addr = PatternScanner.FindFirst(Pattern.FromString("48 89 5C 24 10 48 89 74 24 18 48 89 7C 24 20 55 41 56 41 57 48 8B EC 48 83 EC 30 48 8B FA 48 8B D9 E8 AA B6 C1 FF 48 8B 47 10 48 8D 57 50")); Assert(addr == 0x141AB2260); // nint, nint updateShadowParams = Hook.Create(addr, UpdateShadowParamsHook); staticShadowParams = Hook.Create(0x1416D94F0, StaticShadowParamsHook); // nint, nint @@ -2211,9 +2213,9 @@ namespace WorldTuningTool shadowRes1_2 = new Patch(addr + 0x68, [0x59]); // movss -> mulss. shadowRes1_3 = new Patch(addr + 0x77, [0x59]); // movss -> mulss. #if OVERSIZED_SHADOW_MAP - shadowRes1_4 = new Patch(new nint(0x142288AAA) + 0x4, [0x7A, 0x97, 0xF8, 0x00]); // Limit 4.0 -> 6.0. + shadowRes1_4 = new Patch(lton(0x142288AAA) + 0x4, [0x7A, 0x97, 0xF8, 0x00]); // Limit 4.0 -> 6.0. #else - shadowRes1_4 = new Patch(new nint(0x142288AAA) + 0x4, [0x9E]); // Limit 4.0 -> 5.0. + shadowRes1_4 = new Patch(lton(0x142288AAA) + 0x4, [0x9E]); // Limit 4.0 -> 5.0. #endif addr = PatternScanner.FindFirst(Pattern.FromString("89 91 00 55 00 00 83 FA 05 77 41 48 63 C2 4C 8D 05 ?? ?? ?? ?? 41 8B 94 80 84 8B 28 02 49 03 D0 FF E2 B8 00 08 00 00")); Assert(addr == 0x142288B00); @@ -2240,32 +2242,32 @@ namespace WorldTuningTool // time (area change/createLightingObject() vs change of Volume Quality setting). It's also rendered // in a seperate pass that happens after the initial volume rendering. So keep that in mind if inspecting // a frame in renderdoc. - volumeSars1 = new Patch(new IntPtr(0x1424D0159), [0x90, 0x90]); - volumeSars2 = new Patch(new IntPtr(0x1424D01A0), [0x90, 0x90]); - volumeSars3 = new Patch(new IntPtr(0x1424D01C6), [0x90, 0x90]); - volumeSars4 = new Patch(new IntPtr(0x1424D0219), [0x90, 0x90]); - volumeSars5 = new Patch(new IntPtr(0x1424D0242), [0x90, 0x90]); - volumeSars6 = new Patch(new IntPtr(0x1424D029D), [0x90, 0x90]); - volumeSars7 = new Patch(new IntPtr(0x1424D02C6), [0x90, 0x90]); - volumeSars8 = new Patch(new IntPtr(0x1424D0321), [0x90, 0x90]); - volumeSars9 = new Patch(new IntPtr(0x1424D034A), [0x90, 0x90]); + volumeSars1 = new Patch(lton(0x1424D0159), [0x90, 0x90]); + volumeSars2 = new Patch(lton(0x1424D01A0), [0x90, 0x90]); + volumeSars3 = new Patch(lton(0x1424D01C6), [0x90, 0x90]); + volumeSars4 = new Patch(lton(0x1424D0219), [0x90, 0x90]); + volumeSars5 = new Patch(lton(0x1424D0242), [0x90, 0x90]); + volumeSars6 = new Patch(lton(0x1424D029D), [0x90, 0x90]); + volumeSars7 = new Patch(lton(0x1424D02C6), [0x90, 0x90]); + volumeSars8 = new Patch(lton(0x1424D0321), [0x90, 0x90]); + volumeSars9 = new Patch(lton(0x1424D034A), [0x90, 0x90]); /* As far as I can tell, this is limited by buffers created cpu-side. Seems like * it would be an extremely hard change. - froxelRes1 = new Patch(new IntPtr(0x142384F15) + 0x1, [0x02]); // 4 -> 2 - froxelRes2 = new Patch(new IntPtr(0x142389711) + 0x1, [0x02]); // 4 -> 2 - froxelRes3 = new Patch(new IntPtr(0x142389878) + 0x1, [0x02]); // 4 -> 2 - froxelRes4 = new Patch(new IntPtr(0x14238989E) + 0x1, [0x02]); // 4 -> 2 - froxelRes5 = new Patch(new IntPtr(0x1423898D8) + 0x1, [0x02]); // 4 -> 2 - froxelRes6 = new Patch(new IntPtr(0x14238992B) + 0x1, [0x02]); // 4 -> 2 - froxelRes7 = new Patch(new IntPtr(0x14238FED1) + 0x4, [0x7B, 0xFF, 0xAB, 0x00]); // 0.25 -> 0.50 - froxelRes8 = new Patch(new IntPtr(0x14239009C) + 0x4, [0xB0, 0xFD, 0xAB, 0X00]); // 0.25 -> 0.50 + froxelRes1 = new Patch(lton(0x142384F15) + 0x1, [0x02]); // 4 -> 2 + froxelRes2 = new Patch(lton(0x142389711) + 0x1, [0x02]); // 4 -> 2 + froxelRes3 = new Patch(lton(0x142389878) + 0x1, [0x02]); // 4 -> 2 + froxelRes4 = new Patch(lton(0x14238989E) + 0x1, [0x02]); // 4 -> 2 + froxelRes5 = new Patch(lton(0x1423898D8) + 0x1, [0x02]); // 4 -> 2 + froxelRes6 = new Patch(lton(0x14238992B) + 0x1, [0x02]); // 4 -> 2 + froxelRes7 = new Patch(lton(0x14238FED1) + 0x4, [0x7B, 0xFF, 0xAB, 0x00]); // 0.25 -> 0.50 + froxelRes8 = new Patch(lton(0x14239009C) + 0x4, [0xB0, 0xFD, 0xAB, 0X00]); // 0.25 -> 0.50 */ /* Would require a complicated shader edit to maybe work. Similar to SSLR. - checkerRes1 = new Patch(new IntPtr(0x14238580D) + 0x4, [0x43]); // 0.5 -> 1.0 - checkerRes2 = new Patch(new IntPtr(0x14238FFC3) + 0x4, [0x8D]); // 0.5 -> 1.0 + checkerRes1 = new Patch(lton(0x14238580D) + 0x4, [0x43]); // 0.5 -> 1.0 + checkerRes2 = new Patch(lton(0x14238FFC3) + 0x4, [0x8D]); // 0.5 -> 1.0 */ - value2ForVolumeQuality = new Patch(new IntPtr(0x142389652), [0xB8, 0x02, 0x00, 0x00, 0x00, 0x90]); + value2ForVolumeQuality = new Patch(lton(0x142389652), [0xB8, 0x02, 0x00, 0x00, 0x00, 0x90]); // Gameplay. addr = PatternScanner.FindFirst(Pattern.FromString("80 BB 34 EC 00 00 00 88 8B 31 EC 00 00 C6 83 30 EC 00 00 00 74 1C C6 83 34 EC 00 00 00 48 8B 0D 68 4B 4F 03 80 B9 58 02 00 00 00 75 05 E8 5A F5 01 00 48 8B CB E8 E2 05 00 00 83 BB DC EB 00 00 06 74 0A C7 83 DC EB 00 00 06 00 00 00")); @@ -2283,15 +2285,15 @@ namespace WorldTuningTool defaultViewModeLODLimit_2 = new Patch(addr + 0x24, [0x07]); // Talking to NPC. - defaultViewModeLODLimit_3 = new Patch(new IntPtr(0x14128F1AC) + 0x1, [0x07]); - defaultViewModeLODLimit_4 = new Patch(new IntPtr(0x14128F1AC) + 0xF, [0x07]); + defaultViewModeLODLimit_3 = new Patch(lton(0x14128F1AC) + 0x1, [0x07]); + defaultViewModeLODLimit_4 = new Patch(lton(0x14128F1AC) + 0xF, [0x07]); addr = PatternScanner.FindFirst(Pattern.FromString("74 4D 33 C0 48 81 C1 00 02 00 00 F3 0F 10 11 0F 2F CA 72 0C FF C0 48 83 C1 04 83 F8 03 72 EC C3")); Assert(addr == 0x1426D89CA); addressHigherValueForFoliageSway = new Patch(addr + 0x7, [0x04]); // Found using mFrameSkipNum annotation from MHW-DTI-Dumps. - zeroFrameSkip = new Patch(new IntPtr(0x142246948), [0x31, 0xC0, 0x90, 0x90, 0x90, 0x90]); + zeroFrameSkip = new Patch(lton(0x142246948), [0x31, 0xC0, 0x90, 0x90, 0x90, 0x90]); // The game will crash when trying to switch to the FULL_RES path for SSR. It's likley because // it tries to access shaders that are not available in the game files. @@ -2301,78 +2303,78 @@ namespace WorldTuningTool // is that it's compiled out and that this method of increasing the SSR resolution can't work. /* // Attempt to forcefully enable FULL_RES path for SSR. - ssrFullRes1 = new Patch((nint)0x14228894D, [0x0F, 0x85, 0xB9, 0xAA, 0x30, 0x00]); - ssrFullRes1_1 = new Patch((nint)0x14259340C, [0xC6, 0x81, 0x28, 0x02, 0x00, 0x00, 0x00, 0x90, 0x90, 0x90]); - ssrFullRes2 = new Patch((nint)0x14228897D, [0x0F, 0x85, 0x99, 0xAA, 0x30, 0x00]); - ssrFullRes2_1 = new Patch((nint)0x14259341C, [0xC6, 0x81, 0x30, 0x02, 0x00, 0x00, 0x00, 0x90, 0x90, 0x90]); - ssrFullRes3 = new Patch((nint)0x1422889AD, [0x0F, 0x85, 0x79, 0xAA, 0x30, 0x00]); - ssrFullRes3_1 = new Patch((nint)0x14259342C, [0xC6, 0x81, 0x2C, 0x02, 0x00, 0x00, 0x00, 0x90, 0x90, 0x90]); - ssrFullRes4 = new Patch((nint)0x14259268C, [0x41, 0xC7, 0x86, 0x28, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0xC7, 0x86, 0x2C, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0xC7, 0x86, 0x30, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0xC7, 0x86, 0x34, 0x02, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x41, 0xC7, 0x86, 0x38, 0x02, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x41, 0xC6, 0x86, 0x3C, 0x02, 0x00, 0x00, 0x01]); + ssrFullRes1 = new Patch(lton(0x14228894D), [0x0F, 0x85, 0xB9, 0xAA, 0x30, 0x00]); + ssrFullRes1_1 = new Patch(lton(0x14259340C), [0xC6, 0x81, 0x28, 0x02, 0x00, 0x00, 0x00, 0x90, 0x90, 0x90]); + ssrFullRes2 = new Patch(lton(0x14228897D), [0x0F, 0x85, 0x99, 0xAA, 0x30, 0x00]); + ssrFullRes2_1 = new Patch(lton(0x14259341C), [0xC6, 0x81, 0x30, 0x02, 0x00, 0x00, 0x00, 0x90, 0x90, 0x90]); + ssrFullRes3 = new Patch(lton(0x1422889AD), [0x0F, 0x85, 0x79, 0xAA, 0x30, 0x00]); + ssrFullRes3_1 = new Patch(lton(0x14259342C), [0xC6, 0x81, 0x2C, 0x02, 0x00, 0x00, 0x00, 0x90, 0x90, 0x90]); + ssrFullRes4 = new Patch(lton(0x14259268C), [0x41, 0xC7, 0x86, 0x28, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0xC7, 0x86, 0x2C, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0xC7, 0x86, 0x30, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0xC7, 0x86, 0x34, 0x02, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x41, 0xC7, 0x86, 0x38, 0x02, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x41, 0xC6, 0x86, 0x3C, 0x02, 0x00, 0x00, 0x01]); */ // SSLR resolution factor 0.5 -> 1.0 (not related to fSSLRFactor or fSSLRScale). - ssrRes1 = new Patch(new IntPtr(0x1425926B8) + 0x9, [0x80]); - ssrRes2 = new Patch(new IntPtr(0x1425934C0) + 0x8, [0x80]); + ssrRes1 = new Patch(lton(0x1425926B8) + 0x9, [0x80]); + ssrRes2 = new Patch(lton(0x1425934C0) + 0x8, [0x80]); // Skip mip mapping pass (part of _FULL_RES). - ssrRes3 = new Patch(new IntPtr(0x142282B53), [0x31, 0xC0, 0x90, 0x90, 0x90]); + ssrRes3 = new Patch(lton(0x142282B53), [0x31, 0xC0, 0x90, 0x90, 0x90]); // Depth mips resolution. - ssrShr1 = new Patch(new IntPtr(0x14269DE47), [0x90, 0x90]); - ssrShr2 = new Patch(new IntPtr(0x14269DE54), [0x90, 0x90]); - ssrShr3 = new Patch(new IntPtr(0x14269E07A), [0x90, 0x90]); - ssrShr4 = new Patch(new IntPtr(0x14269E080), [0x90, 0x90]); + ssrShr1 = new Patch(lton(0x14269DE47), [0x90, 0x90]); + ssrShr2 = new Patch(lton(0x14269DE54), [0x90, 0x90]); + ssrShr3 = new Patch(lton(0x14269E07A), [0x90, 0x90]); + ssrShr4 = new Patch(lton(0x14269E080), [0x90, 0x90]); // Approximate depth mip resolution. - ssrShr5 = new Patch(new IntPtr(0x14269DED3) + 0x2, [0x3]); // 4 -> 3 - ssrShr6 = new Patch(new IntPtr(0x14269DEDA) + 0x3, [0x3]); + ssrShr5 = new Patch(lton(0x14269DED3) + 0x2, [0x3]); // 4 -> 3 + ssrShr6 = new Patch(lton(0x14269DEDA) + 0x3, [0x3]); // Depth mips pass 1 dispatch dimensions. - ssrSars1 = new Patch(new IntPtr(0x142282FD8) + 0x3, [0x3]); // 4 -> 3 - ssrSars2 = new Patch(new IntPtr(0x142282FE5) + 0x2, [0x3]); + ssrSars1 = new Patch(lton(0x142282FD8) + 0x3, [0x3]); // 4 -> 3 + ssrSars2 = new Patch(lton(0x142282FE5) + 0x2, [0x3]); // Depth mips pass 2 iRegion parameter. - ssrSars3 = new Patch(new IntPtr(0x142283014) + 0x3, [0x3]); - ssrSars4 = new Patch(new IntPtr(0x142283018) + 0x3, [0x3]); - ssrSars5 = new Patch(new IntPtr(0x14228301C) + 0x3, [0x3]); - ssrSars6 = new Patch(new IntPtr(0x142283020) + 0x2, [0x3]); + ssrSars3 = new Patch(lton(0x142283014) + 0x3, [0x3]); + ssrSars4 = new Patch(lton(0x142283018) + 0x3, [0x3]); + ssrSars5 = new Patch(lton(0x14228301C) + 0x3, [0x3]); + ssrSars6 = new Patch(lton(0x142283020) + 0x2, [0x3]); // Depth mips pass 2 dispatch dimensions. - ssrSars7 = new Patch(new IntPtr(0x1422832B3) + 0x3, [0x3]); - ssrSars8 = new Patch(new IntPtr(0x1422832C8) + 0x2, [0x3]); + ssrSars7 = new Patch(lton(0x1422832B3) + 0x3, [0x3]); + ssrSars8 = new Patch(lton(0x1422832C8) + 0x2, [0x3]); // Depth copy, for unknown use, viewport/scissor. - ssrSars9 = new Patch(new IntPtr(0x1423C5809), [0x90, 0x90]); - ssrSars10 = new Patch(new IntPtr(0x1423C5818), [0x90, 0x90]); - ssrSars11 = new Patch(new IntPtr(0x1423C5824), [0x90, 0x90]); - ssrSars12 = new Patch(new IntPtr(0x1423C5830), [0x90, 0x90]); - ssrSars13 = new Patch(new IntPtr(0x1423C5ABC), [0x90, 0x90]); - ssrSars14 = new Patch(new IntPtr(0x1423C5AF3), [0x90, 0x90]); + ssrSars9 = new Patch(lton(0x1423C5809), [0x90, 0x90]); + ssrSars10 = new Patch(lton(0x1423C5818), [0x90, 0x90]); + ssrSars11 = new Patch(lton(0x1423C5824), [0x90, 0x90]); + ssrSars12 = new Patch(lton(0x1423C5830), [0x90, 0x90]); + ssrSars13 = new Patch(lton(0x1423C5ABC), [0x90, 0x90]); + ssrSars14 = new Patch(lton(0x1423C5AF3), [0x90, 0x90]); // RayAppendBuffer dispatch dimensions, 4 -> 3 wasteful. - //new Patch(new IntPtr(0x14228C323) + 0x3, [0x3]); - //new Patch(new IntPtr(0x14228C32D) + 0x2, [0x3]); + //new Patch(lton(0x14228C323) + 0x3, [0x3]); + //new Patch(lton(0x14228C32D) + 0x2, [0x3]); // Clear trace buffer, 8 -> 7 wasteful - //new Patch(new IntPtr(0x14228C3F4) + 0x2, [0x7]); + //new Patch(lton(0x14228C3F4) + 0x2, [0x7]); // Approximate mip resolution. - ssrShr7 = new Patch(new IntPtr(0x142592EBA) + 0x2, [0x3]); // 4 -> 3 - ssrShr8 = new Patch(new IntPtr(0x142592ED0) + 0x2, [0x3]); + ssrShr7 = new Patch(lton(0x142592EBA) + 0x2, [0x3]); // 4 -> 3 + ssrShr8 = new Patch(lton(0x142592ED0) + 0x2, [0x3]); // Mips pass 1 dispatch dimensions. - ssrSars15 = new Patch(new IntPtr(0x142283626) + 0x3, [0x03]); // 4 -> 3 - ssrSars16 = new Patch(new IntPtr(0x142283633) + 0x2, [0x03]); + ssrSars15 = new Patch(lton(0x142283626) + 0x3, [0x03]); // 4 -> 3 + ssrSars16 = new Patch(lton(0x142283633) + 0x2, [0x03]); // Mips pass 2 iRegion parameter. - ssrSars17 = new Patch(new IntPtr(0x142283667) + 0x2, [0x03]); - ssrSars18 = new Patch(new IntPtr(0x14228366A) + 0x3, [0x03]); - ssrSars19 = new Patch(new IntPtr(0x14228366E) + 0x3, [0x03]); - ssrSars20 = new Patch(new IntPtr(0x142283672) + 0x3, [0x03]); + ssrSars17 = new Patch(lton(0x142283667) + 0x2, [0x03]); + ssrSars18 = new Patch(lton(0x14228366A) + 0x3, [0x03]); + ssrSars19 = new Patch(lton(0x14228366E) + 0x3, [0x03]); + ssrSars20 = new Patch(lton(0x142283672) + 0x3, [0x03]); // Mips pass 2 dispatch dimensions. - ssrSars21 = new Patch(new IntPtr(0x1422838E7) + 0x3, [0x03]); - ssrSars22 = new Patch(new IntPtr(0x1422838FC) + 0x2, [0x03]); + ssrSars21 = new Patch(lton(0x1422838E7) + 0x3, [0x03]); + ssrSars22 = new Patch(lton(0x1422838FC) + 0x2, [0x03]); // Mips blur dispatch dimensions. - ssrSars23 = new Patch(new IntPtr(0x1422839B0), [0x8D, 0x0E, 0x44, 0x8D, 0x76, 0x01, 0x90]); + ssrSars23 = new Patch(lton(0x1422839B0), [0x8D, 0x0E, 0x44, 0x8D, 0x76, 0x01, 0x90]); // Resolve pass, 4 -> 3 wasteful. - //new Patch(new IntPtr(0x14228686D) + 0x3, [0x3]); - //new Patch(new IntPtr(0x142286877) + 0x2, [0x3]); + //new Patch(lton(0x14228686D) + 0x3, [0x3]); + //new Patch(lton(0x142286877) + 0x2, [0x3]); - forceSSLRTemporalReset = new Patch(new IntPtr(0x14228CE53), [0xB9, 0x01, 0x00, 0x00, 0x00, 0x90, 0x90]); + forceSSLRTemporalReset = new Patch(lton(0x14228CE53), [0xB9, 0x01, 0x00, 0x00, 0x00, 0x90, 0x90]); return new PluginData(); } -- cgit v1.2.3-101-g0448