Skip to content

Commit

Permalink
fix rain
Browse files Browse the repository at this point in the history
  • Loading branch information
Zolika1351 committed Sep 6, 2023
1 parent 9d5163c commit d002639
Showing 1 changed file with 29 additions and 44 deletions.
73 changes: 29 additions & 44 deletions source/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,8 +1298,8 @@ void Init()
pattern = hook::pattern("80 3D ? ? ? ? 00 53 8A 5C 24 1C");
bLoadscreenShown = *pattern.get_first<uint8_t*>(2);

pattern = hook::pattern("8B 54 24 04 8B 42 08 85 C0");
injector::MakeJMP(pattern.get_first(0), sub_411F50, true);
//pattern = hook::pattern("8B 54 24 04 8B 42 08 85 C0");
//injector::MakeJMP(pattern.get_first(0), sub_411F50, true);
}

if (fScriptCutsceneFovLimit)
Expand Down Expand Up @@ -1626,8 +1626,8 @@ void Init()

static UINT oldCascadesWidth = 0;
static UINT oldCascadesHeight = 0;
static IDirect3DTexture9** ppHDRTexQuarter = nullptr;
static IDirect3DTexture9* pHDRTexQuarter = nullptr;
static IDirect3DDevice9* pD3DDevice = nullptr;

//sway, z-fighting fix
{
Expand Down Expand Up @@ -1755,20 +1755,11 @@ void Init()
// 1080
if (!pattern.empty())
{
static auto loc_429427 = injector::GetBranchDestination(pattern.get_first(0x24)).as_int();
struct CreateTextureHook
{
void operator()(injector::reg_pack& regs)
static HRESULT __stdcall CreateTexture(IDirect3DDevice9* device, UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle)
{
regs.eax = *(uint32_t*)(regs.eax + 0x11AC);

UINT& Width = *(UINT*)(regs.edi + 0x14);
UINT& Height = *(UINT*)(regs.edi + 0x18);
UINT& Levels = *(UINT*)(regs.edi + 0x20);
DWORD& Usage = *(DWORD*)(regs.edi + 0x0C);
D3DFORMAT& Format = *(D3DFORMAT*)(regs.edi + 0x24);
D3DPOOL& Pool = *(D3DPOOL*)(regs.edi + 0x10);
IDirect3DTexture9** ppTexture = (IDirect3DTexture9**)(regs.edi + 0x40);

if (bFixCascadedShadowMapResolution)
{
if (Format == D3DFORMAT(D3DFMT_R16F) && Height >= 256 && Width == Height * 4 && Levels == 1)
Expand All @@ -1781,47 +1772,35 @@ void Init()
}
}

auto ret = pD3DDevice->CreateTexture(Width, Height, Levels, Usage, Format, Pool, ppTexture, pSharedHandle);

if (bFixRainDrops && Format == D3DFMT_A16B16G16R16F && Width == (gRect.right - gRect.left) / nRainDropsBlur &&
Height == (gRect.bottom - gRect.top) / nRainDropsBlur && ppTexture != nullptr) {
ppHDRTexQuarter = ppTexture;
pHDRTexQuarter = *ppTexture;
}

return ret;
}
};
injector::MakeInline<CreateTextureHook>(pattern.get_first(0), pattern.get_first(6));

static auto loc_429427 = injector::GetBranchDestination(pattern.get_first(0x24)).as_int();
struct CreateTextureHook2
{
void operator()(injector::reg_pack& regs)
{
if (ppHDRTexQuarter) {
pHDRTexQuarter = *ppHDRTexQuarter;
ppHDRTexQuarter = nullptr;
}
pD3DDevice = *(IDirect3DDevice9**)(regs.eax + 0x11AC);

*(uintptr_t*)(regs.esp - 4) = loc_429427;
regs.eax = (uint32_t)pD3DDevice;
regs.edx = (uint32_t)CreateTexture;
}
};
injector::MakeInline<CreateTextureHook2>(pattern.get_first(0x24));
injector::MakeInline<CreateTextureHook>(pattern.get_first(0), pattern.get_first(0xB));
}
// 1070
else
{
pattern = hook::pattern("8B 80 AC 11 00 00 8B 08 6A 00 8D 9F 8C 00 00 00 53 52 8B 57 58 52 8B 57 0C 52 8B 57 20 52 8B 57 10 52 8B 57");
static auto loc_429427 = injector::GetBranchDestination(pattern.get_first(0x2A)).as_int();
struct CreateTextureHook
{
void operator()(injector::reg_pack& regs)
static HRESULT __stdcall CreateTexture(IDirect3DDevice9* device, UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle)
{
regs.eax = *(uint32_t*)(regs.eax + 0x11AC);

UINT& Width = *(UINT*)(regs.edi + 0x14);
UINT& Height = *(UINT*)(regs.edi + 0x10);
UINT& Levels = *(UINT*)(regs.edi + 0x20);
DWORD& Usage = *(DWORD*)(regs.edi + 0x0C);
D3DFORMAT& Format = *(D3DFORMAT*)(regs.edi + 0x58);
D3DPOOL& Pool = *(D3DPOOL*)(regs.edi + 0x54);
IDirect3DTexture9** ppTexture = (IDirect3DTexture9**)(regs.edi + 0x8C);

if (bFixCascadedShadowMapResolution)
{
if (Format == D3DFORMAT(D3DFMT_R16F) && Height >= 256 && Width == Height * 4 && Levels == 1)
Expand All @@ -1834,24 +1813,30 @@ void Init()
}
}

auto ret = pD3DDevice->CreateTexture(Width, Height, Levels, Usage, Format, Pool, ppTexture, pSharedHandle);

if (bFixRainDrops && Format == D3DFMT_A16B16G16R16F && Width == (gRect.right - gRect.left) / nRainDropsBlur &&
Height == (gRect.bottom - gRect.top) / nRainDropsBlur && ppTexture != nullptr) {
ppHDRTexQuarter = ppTexture;
pHDRTexQuarter = *ppTexture;
}

return ret;
}

void operator()(injector::reg_pack& regs)
{
pD3DDevice = *(IDirect3DDevice9**)(regs.eax + 0x11AC);

regs.eax = (uint32_t)pD3DDevice;
}
};
injector::MakeInline<CreateTextureHook>(pattern.get_first(0), pattern.get_first(6));

static auto loc_429427 = injector::GetBranchDestination(pattern.get_first(0x2A)).as_int();
struct CreateTextureHook2
{
void operator()(injector::reg_pack& regs)
{
if (ppHDRTexQuarter) {
pHDRTexQuarter = *ppHDRTexQuarter;
ppHDRTexQuarter = nullptr;
}

regs.eax = (uint32_t)CreateTextureHook::CreateTexture;
*(uintptr_t*)(regs.esp - 4) = loc_429427;
}
};
Expand Down

0 comments on commit d002639

Please sign in to comment.