Skip to content

Commit

Permalink
Fix a bug that incorrect function pointer was sometimes found in Rend…
Browse files Browse the repository at this point in the history
…erer.dll by accident, which would spam "Info String: Keys and values must be valid UTF8 strings" in game console.
  • Loading branch information
hzqst committed Jan 7, 2023
1 parent d4b63c2 commit b9a07a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
22 changes: 16 additions & 6 deletions Plugins/Renderer/gl_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#define R_SETUPFRAME_SIG "\xA1\x2A\x2A\x2A\x2A\x83\xEC\x18\x83\xF8\x01\x0F\x8E\x2A\x2A\x2A\x2A\xD9\x05\x2A\x2A\x2A\x2A\xD8\x1D\x2A\x2A\x2A\x2A\xDF\xE0\xF6\xC4\x2A\x2A\x2A\x68"
#define R_SETUPFRAME_SIG2 "\x8B\x0D\x2A\x2A\x2A\x2A\x83\xEC\x18\x33\xC0\x83\xF9\x01\x0F\x9F\xC0\x50\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xA1"
#define R_SETUPFRAME_SIG_NEW "\x55\x8B\xEC\x83\xEC\x18\x8B\x0D\x2A\x2A\x2A\x2A\x33\xC0\x83\xF9\x01\x0F\x9F\xC0\x50\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xA1"
#define R_SETUPFRAME_SIG_SVENGINE "\x83\xEC\x2A\xA1\x2A\x2A\x2A\x2A\x33\xC4\x89\x44\x24\x2A\x33\xC0\x83\x3D\x2A\x2A\x2A\x2A\x01\x0F\x9F\xC0\x50\xE8"

#define GL_BIND_SIG "\x8B\x44\x24\x04\x8B\x0D\x2A\x2A\x2A\x2A\x56\x8B\xF0\xC1\xFE\x10\x25\xFF\xFF\x00\x00\x4E\x3B\xC8"
#define GL_BIND_SIG_NEW "\x55\x8B\xEC\x8B\x45\x08\x8B\x0D\x2A\x2A\x2A\x2A\x56\x8B\xF0\xC1\xFE\x10\x25\xFF\xFF\x00\x00\x4E\x3B\xC8"
Expand Down Expand Up @@ -323,7 +324,8 @@ void R_FillAddress(void)
}
if (g_iEngineType == ENGINE_SVENGINE)
{
gRefFuncs.R_SetupFrame = NULL;//might be inlined
gRefFuncs.R_SetupFrame = (void(*)(void))Search_Pattern(R_SETUPFRAME_SIG_SVENGINE);
//inlined ? Still find
}
else
{
Expand Down Expand Up @@ -3098,14 +3100,22 @@ void R_FillAddress(void)
gDevOverview = (decltype(gDevOverview))(*(DWORD *)(addr + 9) - 0xC);
}

if (1)
#define R_SETUPFRAME_CALL_SIG "\x0F\x9F\xC0\x50\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8"
if (gRefFuncs.R_SetupFrame)
{
addr = (DWORD)Search_Pattern_From(gRefFuncs.R_SetupFrame, R_SETUPFRAME_CALL_SIG);
Sig_AddrNotFound(R_SetupFrame_Call);
gRefFuncs.R_ForceCVars = (decltype(gRefFuncs.R_ForceCVars))GetCallAddress(addr + 3 + 1);
gRefFuncs.R_CheckVariables = (decltype(gRefFuncs.R_CheckVariables))GetCallAddress(addr + 3 + 1 + 5);
gRefFuncs.R_AnimateLight = (decltype(gRefFuncs.R_AnimateLight))GetCallAddress(addr + 3 + 1 + 5 + 5);
}
else
{
#define R_SETUPFRAME_CALL_SIG "\x50\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A"
addr = (DWORD)Search_Pattern(R_SETUPFRAME_CALL_SIG);
Sig_AddrNotFound(R_SetupFrame_Call);
gRefFuncs.R_ForceCVars = (decltype(gRefFuncs.R_ForceCVars))GetCallAddress(addr + 1);
gRefFuncs.R_CheckVariables = (decltype(gRefFuncs.R_CheckVariables))GetCallAddress(addr + 1 + 5);
gRefFuncs.R_AnimateLight = (decltype(gRefFuncs.R_AnimateLight))GetCallAddress(addr + 1 + 5 + 5);
gRefFuncs.R_ForceCVars = (decltype(gRefFuncs.R_ForceCVars))GetCallAddress(addr + 3 + 1);
gRefFuncs.R_CheckVariables = (decltype(gRefFuncs.R_CheckVariables))GetCallAddress(addr + 3 + 1 + 5);
gRefFuncs.R_AnimateLight = (decltype(gRefFuncs.R_AnimateLight))GetCallAddress(addr + 3 + 1 + 5 + 5);
}

if (1)
Expand Down
8 changes: 3 additions & 5 deletions Plugins/Renderer/gl_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ void GL_FreeShaders(void)

void GL_CheckShaderError(GLuint shader, const char *code, const char *filename)
{
//gEngfuncs.Con_DPrintf("GL_CheckShaderError...");

int iStatus;
glGetShaderiv(shader, GL_COMPILE_STATUS, &iStatus);

Expand Down Expand Up @@ -63,7 +61,7 @@ GLuint R_CompileShaderObject(int type, const char *code, const char *filename)
snprintf(filepath, 255, "logs\\%s", filename);
filepath[255] = 0;

gEngfuncs.Con_DPrintf("writing %s...", filepath);
//gEngfuncs.Con_DPrintf("writing %s...", filepath);

auto FileHandle = g_pFileSystem->Open(filepath, "wb");
if (FileHandle)
Expand Down Expand Up @@ -230,7 +228,7 @@ GLuint R_CompileShaderFileEx(
g_pMetaHookAPI->SysError("R_CompileShaderFileEx: %s file not found!", vsfile);
}

gEngfuncs.Con_DPrintf("R_CompileShaderFileEx: compiling %s...", vsfile);
gEngfuncs.Con_DPrintf("R_CompileShaderFileEx: compiling %s...\n", vsfile);

std::string vs(vscode);

Expand All @@ -248,7 +246,7 @@ GLuint R_CompileShaderFileEx(
g_pMetaHookAPI->SysError("R_CompileShaderFileEx: %s file not found!", fsfile);
}

gEngfuncs.Con_DPrintf("R_CompileShaderFileEx: compiling %s...", fsfile);
gEngfuncs.Con_DPrintf("R_CompileShaderFileEx: compiling %s...\n", fsfile);

std::string fs(fscode);

Expand Down

0 comments on commit b9a07a3

Please sign in to comment.