Skip to content

Commit

Permalink
backport shader stuff to re0
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenAG committed Oct 23, 2023
1 parent 8927f14 commit 7b584d7
Show file tree
Hide file tree
Showing 3 changed files with 273 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
HideMouseCursorAfterMs = 5000
DoorSkip = 1
BorderlessWindowed = 1
LightSyncRGB = 1 // Only Logitech hardware is supported, requires Logitech G HUB app
LightSyncRGB = 1 // Only Logitech hardware is supported, requires Logitech G HUB app
DisableNoise = 0
DisableColorCorrection = 0
140 changes: 98 additions & 42 deletions source/ResidentEvil.FusionFix/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,12 @@ IDirect3DPixelShader9* __stdcall CreatePixelShaderHook(const DWORD** a1)
if (!a1)
return nullptr;

auto pDevice = (IDirect3DDevice9*)*(uint32_t*)(*(uint32_t*)pD3D9DeviceAddr + 152);
auto pDevice = *(IDirect3DDevice9**)(*(uint32_t*)pD3D9DeviceAddr + 152);
IDirect3DPixelShader9* pShader = nullptr;
pDevice->CreatePixelShader(a1[2], &pShader);

if (pShader != nullptr)
{
static constexpr unsigned char dummyShader[] = {
0x00, 0x03, 0xFF, 0xFF, 0xFE, 0xFF, 0x16, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1C, 0x00, 0x00, 0x00,
0x23, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5F, 0x33, 0x5F, 0x30, 0x00, 0x4D,
0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4C, 0x53,
0x4C, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6F, 0x6D, 0x70, 0x69, 0x6C, 0x65,
0x72, 0x20, 0x39, 0x2E, 0x32, 0x39, 0x2E, 0x39, 0x35, 0x32, 0x2E, 0x33, 0x31, 0x31, 0x31, 0x00,
0x51, 0x00, 0x00, 0x05, 0x00, 0x00, 0x0F, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0F, 0x80,
0x00, 0x00, 0x00, 0xA0, 0xFF, 0xFF, 0x00, 0x00
};

static std::vector<uint8_t> pbFunc;
UINT len;
pShader->GetFunction(nullptr, &len);
Expand All @@ -182,58 +170,126 @@ IDirect3DPixelShader9* __stdcall CreatePixelShaderHook(const DWORD** a1)
"dcl_2d s0\n"
"dcl_2d s1\n"
"texld r0, v0, s0\n"
"mov oC0, r0\n";
"mul r0.xyz, r0, r0\n"
"mov oC0.w, r0.w\n"
"mul r1.xyz, r0.y, c2\n"
"mad r1.xyz, r0.x, c1, r1\n"
"mad r1.xyz, r0.z, c3, r1\n"
"add r1.xyz, r1, c4\n"
"texld r2, r1.x, s1\n"
"mul r2.x, r2.x, r2.x\n"
"texld r3, r1.y, s1\n"
"texld r1, r1.z, s1\n"
"mul r2.z, r1.z, r1.z\n"
"mul r2.y, r3.y, r3.y\n"
"rsq r0.x, r0.x\n"
"rcp oC0.x, r0.x\n"
"rsq r0.x, r0.y\n"
"rsq r0.y, r0.z\n"
"rcp oC0.z, r0.y\n"
"rcp oC0.y, r0.x\n";

LPD3DXBUFFER pCode;
LPD3DXBUFFER pErrorMsgs;
LPDWORD shader_data;
auto result = D3DXAssembleShader(shader_text, strlen(shader_text), NULL, NULL, 0, &pCode, &pErrorMsgs);
if (FAILED(result)) {
shader_data = (DWORD*)&dummyShader[0];
}
shader_data = (DWORD*)pCode->GetBufferPointer();

IDirect3DPixelShader9* shader = nullptr;
result = pDevice->CreatePixelShader(shader_data, &shader);
if (FAILED(result)) {
return pShader;
}
else
if (SUCCEEDED(result))
{
pShader->Release();
return shader;
shader_data = (DWORD*)pCode->GetBufferPointer();
IDirect3DPixelShader9* shader = nullptr;
result = pDevice->CreatePixelShader(shader_data, &shader);
if (FAILED(result)) {
return pShader;
}
else
{
pShader->Release();
return shader;
}
}
}
else if (crc == 0x2C3893DD && bDisableNoise)
{
const char* shader_text =
"ps_3_0\n"
"def c0, -0.5, 1, -1, -0\n"
"def c7, 0.298999995, 0.587000012, 0.114, 0\n"
"def c8, -0.169, -0.331, 0.5, 0\n"
"def c9, 0.5, -0.419, -0.0810000002, 0\n"
"def c10, 1, 1.40199995, 0, 1.77199996\n"
"def c11, 1, -0.344000012, -0.713999987, 0\n"
"dcl_texcoord v0\n"
"dcl_2d s0\n"
"dcl_2d s1\n"
"dcl_2d s2\n"
"texld r0, v0, s2\n"
"mov oC0.xyz, r0\n"
"mov r0.x, c3.w\n"
"mov r0.y, v0.w\n"
"texld r0, r0, s0\n"
"add r0.x, r0.x, c0.x\n"
"dp2add r0.x, r0.x, c3.x, v0.x\n"
"add r0.y, c3.y, v0.y\n"
"rcp r1.x, c4.x\n"
"rcp r1.y, c4.y\n"
"mul r0.xy, r0, r1\n"
"frc r0.xy, r0\n"
"mov r1.y, c0.y\n"
"mad r0.zw, r0.xyxy, -c4.xyxy, r1.y\n"
"mul r0.xy, r0, c4\n"
"cmp r0.w, r0.w, c0.z, c0.w\n"
"cmp r0.w, r0.y, r0.w, c0.w\n"
"cmp r0.z, r0.z, r0.w, c0.w\n"
"cmp r0.z, r0.x, r0.z, c0.w\n"
"lrp r1.xz, r0.xyyw, c6.zyww, c6.xyyw\n"
"texld r2, r1.xzzw, s2\n"
"mul r0.xyw, r2.xyzz, r2.xyzz\n"
"cmp r0.xyz, r0.z, c5, r0.xyww\n"
"dp3 r0.w, r0, c7\n"
"mov r2, c2.xyxy\n"
"texld r3, r2, s0\n"
"texld r2, r2.zwzw, s0\n"
"add r1.xz, r2.yyzw, c0.x\n"
"add r1.w, r3.x, c0.x\n"
"add r2.x, r1.y, c3.z\n"
"mul r1.xzw, r1, r2.x\n"
"mov r2.x, r0.w\n"
"dp3 r0.w, r0, c8\n"
"dp3 r0.x, r0, c9\n"
"mov r2.z, r0.x\n"
"mov r2.y, r0.w\n"
"dp3 r0.y, r2, c11\n"
"dp2add r0.z, r2, c10.xwzw, c10.z\n"
"dp2add r0.x, r2.xzzw, c10, c10.z\n"
"rcp r0.w, c2.z\n"
"mul r1.xz, r0.w, v0.zyww\n"
"texld r2, r1.xzzw, s1\n"
"add r0.w, -r2.x, c0.y\n"
"mad r0.w, r0.w, -c2.w, r1.y\n"
"mul r0.xyz, r0.w, r0\n"
"rsq r0.x, r0.x\n"
"rcp oC0.x, r0.x\n"
"rsq r0.x, r0.y\n"
"rsq r0.y, r0.z\n"
"rcp oC0.z, r0.y\n"
"rcp oC0.y, r0.x\n"
"mov oC0.w, c0.y\n";

LPD3DXBUFFER pCode;
LPD3DXBUFFER pErrorMsgs;
LPDWORD shader_data;
auto result = D3DXAssembleShader(shader_text, strlen(shader_text), NULL, NULL, 0, &pCode, &pErrorMsgs);
if (FAILED(result)) {
shader_data = (DWORD*)&dummyShader[0];
}
shader_data = (DWORD*)pCode->GetBufferPointer();

IDirect3DPixelShader9* shader = nullptr;
result = pDevice->CreatePixelShader(shader_data, &shader);
if (FAILED(result)) {
return pShader;
}
else
if (SUCCEEDED(result))
{
pShader->Release();
return shader;
shader_data = (DWORD*)pCode->GetBufferPointer();
IDirect3DPixelShader9* shader = nullptr;
result = pDevice->CreatePixelShader(shader_data, &shader);
if (FAILED(result)) {
return pShader;
}
else
{
pShader->Release();
return shader;
}
}
}
}
Expand Down
Loading

0 comments on commit 7b584d7

Please sign in to comment.