Skip to content

Commit

Permalink
1.19.80 preview
Browse files Browse the repository at this point in the history
  • Loading branch information
ddf8196 committed Mar 12, 2023
1 parent 2e25c5c commit d0669d2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 deletions.
51 changes: 41 additions & 10 deletions BetterDeferred/MCPatches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

}

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
4. 在MC中安装任意光线追踪资源包,并在视频设置中打开`光线追踪`

## 最低要求
- Direct3D 12
- Direct3D 12 (FeatureLevel >= 12.0)
19 changes: 18 additions & 1 deletion RTX2Deferred/MCHooks.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion RTX2Deferred/MCPatches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d0669d2

Please sign in to comment.