Skip to content

Commit

Permalink
Optimized and fixed fsr1, added possible fix to filmtweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Rex109 committed Nov 28, 2024
1 parent 6b45de8 commit edc7c58
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 9 deletions.
114 changes: 107 additions & 7 deletions cod4qol/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,110 @@ void game::hookedCL_Disconnect(int localClientNum)
return game::pCL_Disconnect(localClientNum);
}

void R_SetRenderTarget(int target)
{
const static uint32_t R_SetRenderTarget_func = 0x632B60;
const static uint32_t _gfxCmdBufSourceState = 0xD53F5F0;
const static uint32_t _gfxCmdBufSourceSource = 0xD5404F0;

__asm
{
pushad;
push _gfxCmdBufSourceSource;
push _gfxCmdBufSourceState;
mov eax, target;

call R_SetRenderTarget_func;
add esp, 8;
popad;
}
}

void R_Set2D()
{
const static uint32_t R_Set2D_func = 0x6336E0;
const static uint32_t _gfxCmdBufSourceState = 0xD53F5F0;

__asm
{
pushad;
mov edi, [_gfxCmdBufSourceState];
call R_Set2D_func;
popad;
}
}

void RB_DrawStretchPic(game::Material* material, float x, float y, float w, float h, float texcoord0, float texcoord1, float texcoord2, float texcoord3 /*-1 pushed*/)
{
const static uint32_t RB_DrawStretchPic_func = 0x610E10;
__asm
{
pushad;
mov eax, material;
push 0FFFFFFFFh;
sub esp, 20h;

fld texcoord3;
fstp[esp + 1Ch];

fld texcoord2;
fstp[esp + 18h];

fld texcoord1;
fstp[esp + 14h];

fld texcoord0;
fstp[esp + 10h];

fld h;
fstp[esp + 0Ch];

fld w;
fstp[esp + 8h];

fld y;
fstp[esp + 4h];

fld x;
fstp[esp];

call RB_DrawStretchPic_func;
add esp, 24h;
popad;
}
}

void applyFsr1(int a1)
{
float renderscale = commands::qol_renderscale->current.value;
if (commands::qol_renderscale->current.value != 1.0)

if (renderscale != 1.0)
{
const auto postfx_cas = game::Material_RegisterHandle("postfx_fsr1", 3);
game::RB_DrawFullScreenColoredQuad(postfx_cas, 0.0f, 0.0f, renderscale, renderscale, -1);
/*R_Set2D();
R_SetRenderTarget(game::GfxRenderTargetId::R_RENDERTARGET_RESOLVED_POST_SUN);
if (const auto material = game::rgp->postFxColorMaterial; material)
{
RB_DrawStretchPic(material, 0.0f, 0.0f, game::scrPlace->realViewableMax[0], game::scrPlace->realViewableMax[1], 0.0, 0.0, 1.0, 1.0);
}
game::RB_EndTessSurface();
R_SetRenderTarget(game::GfxRenderTargetId::R_RENDERTARGET_FRAME_BUFFER);*/

float centerX = 0.5f;
float centerY = 0.5f;

float halfWidth = 0.5f * renderscale;
float halfHeight = 0.5f * renderscale;

float s0 = centerX - halfWidth;
float t0 = centerY - halfHeight;
float s1 = centerX + halfWidth;
float t1 = centerY + halfHeight;

const auto postfx_fsr1 = game::Material_RegisterHandle("postfx_fsr1", 3);
game::RB_DrawFullScreenColoredQuad(postfx_fsr1, s0, t0, s1, t1, -1);
}
}

Expand All @@ -363,14 +460,17 @@ __declspec(naked) void game::hookedRB_DrawDebugPostEffects()
}
}

char game::hookedR_GenerateSortedDrawSurfs(GfxSceneParms* sceneParms, int a2, int a3)
char game::hookedR_GenerateSortedDrawSurfs(GfxSceneParms* sceneParams, int a2, int a3)
{
float renderscale = commands::qol_renderscale->current.value;

sceneParms->sceneViewport.width *= renderscale;
sceneParms->sceneViewport.height *= renderscale;
sceneParams->sceneViewport.width *= renderscale;
sceneParams->sceneViewport.height *= renderscale;

sceneParams->sceneViewport.x = (game::scrPlace->realViewableMax[0] - game::scrPlace->realViewableMax[0] * renderscale) / 2;
sceneParams->sceneViewport.y = (game::scrPlace->realViewableMax[1] - game::scrPlace->realViewableMax[1] * renderscale) / 2;

return game::pR_GenerateSortedDrawSurfs(sceneParms, a2, a3);
return game::pR_GenerateSortedDrawSurfs(sceneParams, a2, a3);
}

int game::Cmd_Argc()
Expand Down
43 changes: 41 additions & 2 deletions cod4qol/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,40 @@ namespace game
GfxLight* primaryLights;
};

enum GfxRenderTargetId
{
R_RENDERTARGET_SAVED_SCREEN = 0x0,
R_RENDERTARGET_FRAME_BUFFER = 0x1,
R_RENDERTARGET_SCENE = 0x2,
R_RENDERTARGET_RESOLVED_POST_SUN = 0x3,
R_RENDERTARGET_RESOLVED_SCENE = 0x4,
R_RENDERTARGET_FLOAT_Z = 0x5,
R_RENDERTARGET_DYNAMICSHADOWS = 0x6,
R_RENDERTARGET_PINGPONG_0 = 0x7,
R_RENDERTARGET_PINGPONG_1 = 0x8,
R_RENDERTARGET_SHADOWCOOKIE = 0x9,
R_RENDERTARGET_SHADOWCOOKIE_BLUR = 0xA,
R_RENDERTARGET_POST_EFFECT_0 = 0xB,
R_RENDERTARGET_POST_EFFECT_1 = 0xC,
R_RENDERTARGET_SHADOWMAP_SUN = 0xD,
R_RENDERTARGET_SHADOWMAP_SPOT = 0xE,
R_RENDERTARGET_COUNT = 0xF,
R_RENDERTARGET_NONE = 0x10,
};

struct ScreenPlacement
{
float scaleVirtualToReal[2];
float scaleVirtualToFull[2];
float scaleRealToVirtual[2];
float virtualViewableMin[2];
float virtualViewableMax[2];
float realViewportSize[2];
float realViewableMin[2];
float realViewableMax[2];
float subScreenLeft;
};

inline bool startup = true;

const static DWORD cod4x_entry = (DWORD)GetModuleHandleA(COD4QOL_COD4X_MODULE);
Expand Down Expand Up @@ -1591,10 +1625,10 @@ namespace game

void hookedRB_DrawDebugPostEffects();

typedef char(*R_GenerateSortedDrawSurfs)(GfxSceneParms* sceneParms, int a2, int a3);
typedef char(*R_GenerateSortedDrawSurfs)(GfxSceneParms* sceneParams, int a2, int a3);
inline R_GenerateSortedDrawSurfs pR_GenerateSortedDrawSurfs;

char hookedR_GenerateSortedDrawSurfs(GfxSceneParms* sceneParms, int a2, int a3);
char hookedR_GenerateSortedDrawSurfs(GfxSceneParms* sceneParams, int a2, int a3);

int Cmd_Argc();
const char* Cmd_Argv(int arg);
Expand Down Expand Up @@ -1643,16 +1677,21 @@ namespace game
typedef Material*(*Material_RegisterHandle_t)(const char* fontName, int fontSize);
extern Material_RegisterHandle_t Material_RegisterHandle;

typedef void(*RB_EndTessSurface_t)();
extern RB_EndTessSurface_t RB_EndTessSurface;

inline void* Cmd_AddCommand_fnc;
inline game::CmdArgs* cmd_args = reinterpret_cast<game::CmdArgs*>(0x1410B40);
inline game::gclient_s* g_clients = reinterpret_cast<game::gclient_s*>(0x13255A8);
inline game::r_global_permanent_t* rgp = reinterpret_cast<game::r_global_permanent_t*>(0xCC98280);
inline game::ScreenPlacement* scrPlace = reinterpret_cast<game::ScreenPlacement*>(0xE34420);

inline game::Cmd_ExecuteSingleCommand_t Cmd_ExecuteSingleCommand = Cmd_ExecuteSingleCommand_t(0x4F9AB0);
inline game::Com_PrintMessage_t Com_PrintMessage = game::Com_PrintMessage_t(0x4FCA50);
inline game::DB_LoadXAssets_t DB_LoadXAssets = DB_LoadXAssets_t(0x48A2B0);
inline game::RB_DrawFullScreenColoredQuad_t RB_DrawFullScreenColoredQuad = RB_DrawFullScreenColoredQuad_t(0x6113E0);
inline game::Material_RegisterHandle_t Material_RegisterHandle = Material_RegisterHandle_t(0x5F2A80);
inline game::RB_EndTessSurface_t RB_EndTessSurface = RB_EndTessSurface_t(0x61A2F0);
inline game::Sys_CreateConsole_t Sys_CreateConsole;

inline game::Cvar_RegisterBool_t Cvar_RegisterBool;
Expand Down

0 comments on commit edc7c58

Please sign in to comment.