diff --git a/BetterDeferred/MCPatches.cpp b/BetterDeferred/MCPatches.cpp index 74e868d..7822a37 100644 --- a/BetterDeferred/MCPatches.cpp +++ b/BetterDeferred/MCPatches.cpp @@ -7,19 +7,50 @@ void MCPatches_Init() { printf("%s\n", __FUNCTION__); //mce::framebuilder::bgfxbridge::DeferredMinecraftFrameRenderer::frame - uintptr_t normalsRasterTextureFormatPtr = FindSignature("48 8D 8D ?? ?? ?? ?? E8 ?? ?? ?? ?? 0F 10 B5 ?? ?? ?? ?? 0F 11 B5 ?? ?? ?? ?? 8B 9D ?? ?? ?? ?? 89 9D ?? ?? ?? ?? C7 85 ?? ?? ?? ?? ?? ?? ?? ??"); - if (normalsRasterTextureFormatPtr) { - DWORD oldProtect, tmp; - VirtualProtect((void*)normalsRasterTextureFormatPtr, 48, PAGE_READWRITE, &oldProtect); - char* p = (char*)normalsRasterTextureFormatPtr; - if (p[44] == (char)mce::TextureFormat::R16G16_SNORM || p[44] == (char)mce::TextureFormat::R8G8_UNORM) { - p[44] = (char)mce::TextureFormat::R16G16B16A16_FLOAT; + { + mce::TextureFormat* textureFormatPtr = nullptr; + uintptr_t ptr = FindSignature( + "48 8D 8D ?? ?? ?? ?? " + "E8 ?? ?? ?? ?? " + "0F 10 B5 ?? ?? ?? ?? " + "0F 11 B5 ?? ?? ?? ?? " + "8B 9D ?? ?? ?? ?? " + "89 9D ?? ?? ?? ?? " + "C7 85 ?? ?? ?? ?? ?? ?? ?? ??" + ); + textureFormatPtr = (mce::TextureFormat*)(ptr + 44); + + if (!ptr) { + ptr = FindSignature( + "48 8D 8D ?? ?? ?? ?? " + "E8 ?? ?? ?? ?? " + "0F 10 ?? ?? ?? ?? ?? " + "0F 11 ?? ?? ?? ?? ?? " + "F2 0F 10 ?? ?? ?? ?? ?? " + "F2 0F 11 ?? ?? ?? ?? ?? " + "8B 9D ?? ?? ?? ?? " + "89 9D ?? ?? ?? ?? " + "C7 85 ?? ?? ?? ?? ?? ?? ?? ??" + ); + textureFormatPtr = (mce::TextureFormat*)(ptr + 60); + } + + if (ptr && textureFormatPtr) { + DWORD oldProtect, tmp; + VirtualProtect(textureFormatPtr, sizeof(mce::TextureFormat), PAGE_READWRITE, &oldProtect); + + mce::TextureFormat textureFormat = *textureFormatPtr; + if (textureFormat == mce::TextureFormat::R16G16_SNORM || textureFormat == mce::TextureFormat::R8G8_UNORM) { + *textureFormatPtr = mce::TextureFormat::R16G16B16A16_FLOAT; + } else { + printf("Failed to patch mce::framebuilder::bgfxbridge::DeferredMinecraftFrameRenderer::frame\n"); + } + + VirtualProtect(textureFormatPtr, sizeof(mce::TextureFormat), oldProtect, &tmp); } else { printf("Failed to patch mce::framebuilder::bgfxbridge::DeferredMinecraftFrameRenderer::frame\n"); } - VirtualProtect((void*)normalsRasterTextureFormatPtr, 48, oldProtect, &tmp); - } else { - printf("Failed to patch mce::framebuilder::bgfxbridge::DeferredMinecraftFrameRenderer::frame\n"); } + } diff --git a/README.md b/README.md index 0f43904..3418e8b 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,4 @@ 4. 在MC中安装任意光线追踪资源包,并在视频设置中打开`光线追踪` ## 最低要求 -- Direct3D 12 +- Direct3D 12 (FeatureLevel >= 12.0) diff --git a/RTX2Deferred/MCHooks.cpp b/RTX2Deferred/MCHooks.cpp index 131a305..fdeb0c3 100644 --- a/RTX2Deferred/MCHooks.cpp +++ b/RTX2Deferred/MCHooks.cpp @@ -1,6 +1,8 @@ #include "HookAPI.h" #include "MCHooks.h" +int setLightingModelIndex = 8; + void (*RayTracingOptions_setLightingModel)(void* self, int lightingModel) = nullptr; void RayTracingOptions_setLightingModel_Hook(void* self, int lightingModel) { if (lightingModel == 2) { //RTX @@ -14,7 +16,7 @@ DeclareHook(RayTracingOptions_isRayTracingAvailable, bool, void* self) { bool result = original(self); Unhook(RayTracingOptions_isRayTracingAvailable); - ReplaceVtable(*(void**)self, 8, (void**)&RayTracingOptions_setLightingModel, RayTracingOptions_setLightingModel_Hook); + ReplaceVtable(*(void**)self, setLightingModelIndex, (void**)&RayTracingOptions_setLightingModel, RayTracingOptions_setLightingModel_Hook); RayTracingOptions_setLightingModel(self, 1); return result; } @@ -31,9 +33,24 @@ void MCHooks_Init() { uintptr_t isRayTracingAvailablePtr = FindSignature("40 53 48 83 EC 20 48 8B 01 48 8B D9 FF 50 08 84 C0 74 22 48 8B 03 48 8B CB FF 50 10 84 C0 74 15 48 8B 03 48 8B CB FF 50 18 84 C0 74 08 B0 01 48 83 C4 20 5B C3 32 C0 48 83 C4 20 5B C3"); if (!isRayTracingAvailablePtr) { isRayTracingAvailablePtr = FindSignature("40 53 48 83 EC 20 48 8B 01 48 8B D9 48 8B 40 08 ?? ?? ?? ?? ?? ?? 84 C0 74 30 48 8B 03 48 8B CB 48 8B 40 10 ?? ?? ?? ?? ?? ?? 84 C0 74 1C 48 8B 03 48 8B CB 48 8B 40 18 ?? ?? ?? ?? ?? ?? 84 C0 74 08 B0 01 48 83 C4 20 5B C3 32 C0 48 83 C4 20 5B C3"); + setLightingModelIndex = 8; } if (!isRayTracingAvailablePtr) { isRayTracingAvailablePtr = FindSignature("40 53 48 83 EC 20 48 8B 01 48 8B D9 48 8B 40 08 ?? ?? ?? ?? ?? ?? 84 C0 74 30 48 8B 03 48 8B CB 48 8B 40 28 ?? ?? ?? ?? ?? ?? 84 C0 74 1C 48 8B 03 48 8B CB 48 8B 40 10 ?? ?? ?? ?? ?? ?? 84 C0 74 08 B0 01 48 83 C4 20 5B C3 32 C0 48 83 C4 20 5B C3 "); + setLightingModelIndex = 8; + } + if (!isRayTracingAvailablePtr) { + isRayTracingAvailablePtr = FindSignature( + "40 53" + "48 83 EC 20" + "48 8B 01" + "48 8B D9" + "48 8B 40 08" + "?? ?? ?? ?? ?? ??" + "84 C0" + "74 30" + ); + setLightingModelIndex = 9; } if (isRayTracingAvailablePtr) { Hook(RayTracingOptions_isRayTracingAvailable, (void*)isRayTracingAvailablePtr); diff --git a/RTX2Deferred/MCPatches.cpp b/RTX2Deferred/MCPatches.cpp index 8644344..3732ca5 100644 --- a/RTX2Deferred/MCPatches.cpp +++ b/RTX2Deferred/MCPatches.cpp @@ -5,7 +5,7 @@ void MCPatches_Init() { printf("%s\n", __FUNCTION__); //bgfx::d3d12rtx::RendererContextD3D12RTX::init - uintptr_t ptr = FindSignature("83 BE D4 02 00 00 65 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 83 BE D4 02 00 00 65"); + uintptr_t ptr = FindSignature("83 BE ?? 02 00 00 65 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 83 BE ?? 02 00 00 65"); if (ptr) { DWORD oldProtect, tmp; VirtualProtect((void*)ptr, 60, PAGE_READWRITE, &oldProtect);