Skip to content

Commit

Permalink
Implemented FSR1 Upscaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Rex109 committed Nov 27, 2024
1 parent f546d6e commit 6ed6a51
Show file tree
Hide file tree
Showing 13 changed files with 396 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cod4qol/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ void commands::InitializeCommands()

qol_debugreflections = game::Cvar_RegisterBool("qol_debugreflections", 0, game::dvar_flags::saved, "Enable red reflections, useful for fixing reflections on custom maps. Requires map restart.");

qol_renderscale = game::Cvar_RegisterFloat("qol_renderscale", 1.0f, 0.1f, 1.0f, game::dvar_flags::saved, "Render scale.");

std::cout << "Commands initialized!" << std::endl;
}

Expand Down
1 change: 1 addition & 0 deletions cod4qol/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace commands
inline game::dvar_s* qol_enableautobhop;
inline game::dvar_s* qol_show_mainmenuinfo;
inline game::dvar_s* qol_debugreflections;
inline game::dvar_s* qol_renderscale;

void InitializeCommands();

Expand Down
37 changes: 37 additions & 0 deletions cod4qol/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,42 @@ void game::hookedCL_Disconnect(int localClientNum)
return game::pCL_Disconnect(localClientNum);
}

void applyFsr1(int a1)
{
float renderscale = commands::qol_renderscale->current.value;
if (commands::qol_renderscale->current.value != 1.0)
{
const auto postfx_cas = game::Material_RegisterHandle("postfx_fsr1", 3);
game::RB_DrawFullScreenColoredQuad(postfx_cas, 0.0f, 0.0f, renderscale, renderscale, -1);
}
}

__declspec(naked) void game::hookedRB_DrawDebugPostEffects()
{
const static uint32_t retn_addr = 0x64AD75;

__asm
{
pushad;
push esi;
call applyFsr1;
add esp, 4;
popad;

jmp retn_addr;
}
}

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

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

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

int game::Cmd_Argc()
{
return game::cmd_args->argc[game::cmd_args->nesting];
Expand Down Expand Up @@ -402,5 +438,6 @@ void game::SetCoD4xFunctionOffsets()
Cvar_RegisterBool = Cvar_RegisterBool_t(offsets::GetOffset("Cvar_RegisterBool"));
Cvar_RegisterEnum = Cvar_RegisterEnum_t(offsets::GetOffset("Cvar_RegisterEnum"));
Cvar_RegisterString = Cvar_RegisterString_t(offsets::GetOffset("Cvar_RegisterString"));
Cvar_RegisterFloat = Cvar_RegisterFloat_t(offsets::GetOffset("Cvar_RegisterFloat"));
FS_AddSingleIwdFileForGameDirectory = FS_AddSingleIwdFileForGameDirectory_t(offsets::GetOffset("FS_AddSingleIwdFileForGameDirectory"));
}
79 changes: 79 additions & 0 deletions cod4qol/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,63 @@ namespace game
int savedScreenTimes[4];
};

typedef struct
{
byte enabled;
byte pad[3];
float bloomCutoff;
float bloomDesaturation;
float bloomIntensity;
float radius;
}GfxGlow;

typedef struct
{
byte enabled;
byte pad[3];
float brightness;
float contrast;
float desaturation;
byte invert;
byte pad2[3];
float tintDark[3];
float tintLight[3];
}GfxFilm;

typedef struct
{
float viewModelStart;
float viewModelEnd;
float nearStart;
float nearEnd;
float farStart;
float farEnd;
float nearBlur;
float farBlur;
}GfxDepthOfField;

struct GfxViewport
{
int x;
int y;
int width;
int height;
};

struct GfxSceneParms
{
int localClientNum;
float blurRadius;
GfxDepthOfField dof;
GfxFilm film;
GfxGlow glow;
bool isRenderingFullScreen;
GfxViewport sceneViewport;
GfxViewport displayViewport;
GfxViewport scissorViewport;
GfxLight* primaryLights;
};

inline bool startup = true;

const static DWORD cod4x_entry = (DWORD)GetModuleHandleA(COD4QOL_COD4X_MODULE);
Expand Down Expand Up @@ -1529,6 +1586,16 @@ namespace game

void hookedCL_Disconnect(int localClientNum);

typedef void(*RB_DrawDebugPostEffects)();
inline RB_DrawDebugPostEffects pRB_DrawDebugPostEffects;

void hookedRB_DrawDebugPostEffects();

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

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

int Cmd_Argc();
const char* Cmd_Argv(int arg);
HMODULE GetCurrentModule();
Expand Down Expand Up @@ -1564,9 +1631,18 @@ namespace game
typedef game::dvar_s* (*Cvar_RegisterString_t)(const char* name, const char* string, game::dvar_flags flags, const char* description);
extern Cvar_RegisterString_t Cvar_RegisterString;

typedef game::dvar_s* (*Cvar_RegisterFloat_t)(const char* name, float val, float min, float max, unsigned short flags, const char* description);
extern Cvar_RegisterFloat_t Cvar_RegisterFloat;

typedef bool(*FS_AddSingleIwdFileForGameDirectory_t)(const char* pakfile, const char* basename, const char* gamename);
extern FS_AddSingleIwdFileForGameDirectory_t FS_AddSingleIwdFileForGameDirectory;

typedef void(*RB_DrawFullScreenColoredQuad_t)(Material*, float s0, float t0, float s1, float t1, int color);
extern RB_DrawFullScreenColoredQuad_t RB_DrawFullScreenColoredQuad;

typedef Material*(*Material_RegisterHandle_t)(const char* fontName, int fontSize);
extern Material_RegisterHandle_t Material_RegisterHandle;

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);
Expand All @@ -1575,11 +1651,14 @@ namespace game
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::Sys_CreateConsole_t Sys_CreateConsole;

inline game::Cvar_RegisterBool_t Cvar_RegisterBool;
inline game::Cvar_RegisterEnum_t Cvar_RegisterEnum;
inline game::Cvar_RegisterString_t Cvar_RegisterString;
inline game::Cvar_RegisterFloat_t Cvar_RegisterFloat;

inline game::FS_AddSingleIwdFileForGameDirectory_t FS_AddSingleIwdFileForGameDirectory;

Expand Down
8 changes: 8 additions & 0 deletions cod4qol/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ void hooks::InitializeHooks()
game::pCL_Disconnect = (game::CL_Disconnect)(0x4696B0);
hooks::install(&(PVOID&)game::pCL_Disconnect, (PBYTE)game::hookedCL_Disconnect);

//RB_DrawDebugPostEffects
game::pRB_DrawDebugPostEffects = (game::RB_DrawDebugPostEffects)(0x64AD70);
hooks::install(&(PVOID&)game::pRB_DrawDebugPostEffects, (PBYTE)game::hookedRB_DrawDebugPostEffects);

//R_GenerateSortedDrawSurfs
game::pR_GenerateSortedDrawSurfs = (game::R_GenerateSortedDrawSurfs)(0x5F98E0);
hooks::install(&(PVOID&)game::pR_GenerateSortedDrawSurfs, (PBYTE)game::hookedR_GenerateSortedDrawSurfs);

std::cout << "Hooks installed!" << std::endl;
}

Expand Down
1 change: 1 addition & 0 deletions cod4qol/offsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void offsets::InitOffsets()
AddOffset("Cvar_RegisterBool", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x60BE0)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x2D8F2)} });
AddOffset("Cvar_RegisterEnum", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x60640)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x2DCAF)} });
AddOffset("Cvar_RegisterString", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x60960)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x2D87D)} });
AddOffset("Cvar_RegisterFloat", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x0)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x2D9DA)} });
AddOffset("FS_AddSingleIwdFileForGameDirectory", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x2E310)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x3867C)} });

//Strings
Expand Down
Binary file added mod/cod4qol/material_properties/postfx_fsr1
Binary file not shown.
Binary file added mod/cod4qol/materials/postfx_fsr1
Binary file not shown.
1 change: 1 addition & 0 deletions mod/cod4qol/mod.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ material,discord_icon
material,github_icon
material,kofi_icon
material,youtube_icon
material,postfx_fsr1

menufile,ui/options_game_pc.menu
menufile,ui/options_graphics_defaults.menu
Expand Down
Binary file modified mod/cod4qol/mod.ff
Binary file not shown.
Loading

0 comments on commit 6ed6a51

Please sign in to comment.