diff --git a/README.md b/README.md index 2f58abd..1130442 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,15 @@ ### EGSM A module that enhances gmod with a thing that was asked for decades -Works only on the main branch +Works only on the main and x86 branch [Documentation](https://github.com/devonium/EGSM/wiki) + [Discord](https://discord.gg/X2Ay3cgW8T) ### How to install * Put [the dll](https://github.com/devonium/EGSM/releases) in garrysmod/lua/bin -* APPEND `require("egsm")` to garrysmod/lua/menu/menu.lua +* APPEND `require((BRANCH == "x86-64" or BRANCH == "chromium" ) and "egsm_chromium" or "egsm")` to garrysmod/lua/menu/menu.lua https://youtu.be/SlWGKU-mYRw @@ -16,8 +17,10 @@ https://youtu.be/SlWGKU-mYRw [garrysmod_common](https://github.com/danielga/garrysmod_common) ``` git clone --recursive https://github.com/danielga/garrysmod_common +git clone --recursive https://github.com/danielga/garrysmod_common -b "x86-64-support-sourcesdk" ``` ``` premake5 vs2017 --gmcommon="garrysmod_common_path" --autoinstall="gmod_lua_bin_path" +premake5 vs2017 --gmcommon="garrysmod_common_x86_64_path" --autoinstall="gmod_lua_bin_path --chromium=1" ``` diff --git a/premake5.lua b/premake5.lua index 898fe2e..feadac5 100644 --- a/premake5.lua +++ b/premake5.lua @@ -195,7 +195,7 @@ function CreateProject(config) end -CreateWorkspace({name = "egsm", abi_compatible = true}) +CreateWorkspace({name = (_OPTIONS.chromium and "egsm_chromium" or "egsm"), abi_compatible = true}) CreateProject({serverside = false}) IncludeLuaShared() IncludeDetouring() diff --git a/source/chromium_fix.h b/source/chromium_fix.h new file mode 100644 index 0000000..28800f7 --- /dev/null +++ b/source/chromium_fix.h @@ -0,0 +1,5 @@ +#pragma once +#ifdef CHROMIUM +#undef strdup +#include +#endif \ No newline at end of file diff --git a/source/d3dxdefs.h b/source/d3dxdefs.h index 9e82a40..d5492a6 100644 --- a/source/d3dxdefs.h +++ b/source/d3dxdefs.h @@ -1,5 +1,5 @@ #pragma once - +#include "chromium_fix.h" #include #include #include @@ -278,11 +278,13 @@ char* ProcessErrorMessge(const char* pProgram, const char* pErrorMessage, int li GetModuleFileName(NULL, execpath, MAX_PATH); V_StripFilename(execpath); // x86-x64 path fix - //int len = strlen(execpath); - //if (execpath[len - 1] == 'n' && execpath[len - 2] == 'i' && execpath[len - 3] == 'b') - //{ - // execpath[len - 4] = 0; - //} +#ifdef CHROMIUM + int len = strlen(execpath); + if (execpath[len - 1] == 'n' && execpath[len - 2] == 'i' && execpath[len - 3] == 'b') + { + execpath[len - 4] = 0; + } +#endif } int lline = 0; diff --git a/source/sigscan.cpp b/source/e_utils.cpp similarity index 98% rename from source/sigscan.cpp rename to source/e_utils.cpp index cb73d42..18f6ec0 100644 --- a/source/sigscan.cpp +++ b/source/e_utils.cpp @@ -1,4 +1,4 @@ -#include "sigscan.h" +#include "e_utils.h" #include #include #include diff --git a/source/e_utils.h b/source/e_utils.h new file mode 100644 index 0000000..19adc46 --- /dev/null +++ b/source/e_utils.h @@ -0,0 +1,57 @@ +#pragma once +#include +#include +#include + +struct DynLibInfo +{ + void* baseAddress; + size_t memorySize; +}; + +bool GetLibraryInfo(const void* handle, DynLibInfo& lib); +void* ScanSign(const void* handle, const char* sig, size_t len, const void* start = NULL); + +#define GetVTable(ptr) ((void***)ptr)[0] + +#define Define_thiscall_Hook(rettype, name, thistype, ...) \ + Detouring::Hook name##_hook; \ + typedef rettype (__thiscall* name##_decl)(thistype _this, __VA_ARGS__); \ + inline name##_decl name##_trampoline() { return name##_hook.GetTrampoline();}\ + rettype __fastcall name##_detour(thistype _this, void* edx, __VA_ARGS__) + +#define Setup_Hook(name, targ) \ +{ \ + Detouring::Hook::Target target(reinterpret_cast(targ)); \ + name##_hook.Create(target, name##_detour); \ + name##_hook.Enable(); \ +} + +#define HOOK_SIGN(x) x; + +#ifdef WIN64 +#define HOOK_SIGN_x32(x) +#define HOOK_SIGN_x64(x) x; +#else +#define HOOK_SIGN_x32(x) x; +#define HOOK_SIGN_x64(x) +#endif + +#ifdef CHROMIUM +#define HOOK_SIGN_M(x) + +#ifdef WIN64 +#define HOOK_SIGN_CHROMIUM_X64(x) x; +#define HOOK_SIGN_CHROMIUM_x32(x) +#else +#define HOOK_SIGN_CHROMIUM_X64(x) +#define HOOK_SIGN_CHROMIUM_X32(x) x; + +#endif +#define HOOK_SIGN_CHROMIUM(x) x; +#else +#define HOOK_SIGN_M(x) x; +#define HOOK_SIGN_CHROMIUM(x) +#define HOOK_SIGN_CHROMIUM_X64(x) +#define HOOK_SIGN_CHROMIUM_X32(x) +#endif \ No newline at end of file diff --git a/source/f_vmatrix.cpp b/source/f_vmatrix.cpp index 437d7fe..f975097 100644 --- a/source/f_vmatrix.cpp +++ b/source/f_vmatrix.cpp @@ -41,6 +41,28 @@ inline void _SSE_RSqrtInline(float a, float* out) } #endif +#ifdef WIN64 + +float FASTCALL pfVectorNormalize(Vector& vec) +{ +#ifdef _VPROF_MATHLIB + VPROF_BUDGET("_VectorNormalize", "Mathlib"); +#endif + Assert(s_bMathlibInitialized); + float radius = sqrtf(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z); + + // FLT_EPSILON is added to the radius to eliminate the possibility of divide by zero. + float iradius = 1.f / (radius + FLT_EPSILON); + + vec.x *= iradius; + vec.y *= iradius; + vec.z *= iradius; + + return radius; +} + +#endif + FORCEINLINE float VectorNormalize(Vector& vec) { #ifndef DEBUG // stop crashing my edit-and-continue! @@ -57,7 +79,6 @@ FORCEINLINE float VectorNormalize(Vector& vec) vec.z *= invlen; return sqrlen * invlen; #else - extern float (FASTCALL * pfVectorNormalize)(Vector & v); return (*pfVectorNormalize)(vec); #endif } diff --git a/source/main.cpp b/source/main.cpp index 3add580..1341deb 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,3 +1,4 @@ +#include "chromium_fix.h" #include #include "f_mathlib.h" #include "shaderlib.h" @@ -10,7 +11,7 @@ #include #include #include "f_igamesystem.h" -#include +#include #include #include "version.h" #include "Windows.h" @@ -150,11 +151,20 @@ GMOD_MODULE_OPEN() luaL_closestate_hk.Enable(); } const char lua_initclf_sign[] = + HOOK_SIGN_CHROMIUM_X32("55 8B EC 81 EC 18 02 00 00 53 68 ? ? ? ? 8B D9 FF 15 ? ? ? ? 83 C4 04 E8 ? ? ? ? 68 ? ? ? ? 51 8B C8 C7 04 24 33 33 73 3F 8B 10 FF 52 6C 83 3D ? ? ? ? ? 74 0E 68 ? ? ? ? FF 15 ? ? ? ? 83 C4 04 68 04 02 08 00 E8 ? ? ? ? 83 C4 04 85 C0 74 09 8B C8 E8 ? ? ? ? EB 02 33 C0 56 57 A3 ? ? ? ? E8 ? ? ? ? 6A 00 6A 00 8B C8 8B 10 FF 52 10 A3 ? ? ? ? FF 15 ? ? ? ? 8B ? ? ? ? ? 68") + HOOK_SIGN_CHROMIUM_X64("48 89 5C 24 08 48 89 74 24 10 57 48 81 EC 60 02 00 00 48 8B ? ? ? ? ? 48 33 C4 48 89 84 24 50 02 00 00 48 8B F1 48 8D ? ? ? ? ? FF 15 ? ? ? ? E8 ? ? ? ? F3 0F 10 ? ? ? ? ? 4C 8D ? ? ? ? ? 48 8B C8 48 8B 10 FF 92 D8 00 00 00 48 83 3D ? ? ? ? ? 74 0D 48 8D ? ? ? ? ? FF 15 ? ? ? ? B9 08 02 0C 00 E8 ? ? ? ? 48 85 C0 74 08 48 8B C8 E8 ? ? ? ? 48 89 ? ? ? ? ? E8 ? ? ? ? 45 33") + HOOK_SIGN_M("55 8B EC 81 EC 18 02 00 00 53 68 ? ? ? ? 8B D9 FF 15 ? ? ? ? 83 C4 04 E8 ? ? ? ? D9 05 ? ? ? ? 68 ? ? ? ? 51 8B 10 8B C8 D9 1C 24 FF 52 6C 83 3D ? ? ? ? ? 74 0B 68 ? ? ? ? FF 15 ? ? ? ? 68 04 02 08 00 E8 ? ? ? ? 83 C4 04 85 C0 74 09 8B C8 E8 ? ? ? ? EB 02 33 C0 56 57 A3 ? ? ? ? E8 ? ? ? ? 6A 00 6A 00 8B C8 8B 10 FF 52 10 A3 ? ? ? ? FF 15 ? ? ? ? 8B") +/* #ifdef CHROMIUM +#ifndef WIN64 "55 8B EC 81 EC 18 02 00 00 53 68 ? ? ? ? 8B D9 FF 15 ? ? ? ? 83 C4 04 E8 ? ? ? ? 68 ? ? ? ? 51 8B C8 C7 04 24 33 33 73 3F 8B 10 FF 52 6C 83 3D ? ? ? ? ? 74 0E 68 ? ? ? ? FF 15 ? ? ? ? 83 C4 04 68 04 02 08 00 E8 ? ? ? ? 83 C4 04 85 C0 74 09 8B C8 E8 ? ? ? ? EB 02 33 C0 56 57 A3 ? ? ? ? E8 ? ? ? ? 6A 00 6A 00 8B C8 8B 10 FF 52 10 A3 ? ? ? ? FF 15 ? ? ? ? 8B ? ? ? ? ? 68"; +#else + "48 89 5C 24 08 48 89 74 24 10 57 48 81 EC 60 02 00 00 48 8B ? ? ? ? ? 48 33 C4 48 89 84 24 50 02 00 00 48 8B F1 48 8D ? ? ? ? ? FF 15 ? ? ? ? E8 ? ? ? ? F3 0F 10 ? ? ? ? ? 4C 8D ? ? ? ? ? 48 8B C8 48 8B 10 FF 92 D8 00 00 00 48 83 3D ? ? ? ? ? 74 0D 48 8D ? ? ? ? ? FF 15 ? ? ? ? B9 08 02 0C 00 E8 ? ? ? ? 48 85 C0 74 08 48 8B C8 E8 ? ? ? ? 48 89 ? ? ? ? ? E8 ? ? ? ? 45 33"; +#endif #else "55 8B EC 81 EC 18 02 00 00 53 68 ? ? ? ? 8B D9 FF 15 ? ? ? ? 83 C4 04 E8 ? ? ? ? D9 05 ? ? ? ? 68 ? ? ? ? 51 8B 10 8B C8 D9 1C 24 FF 52 6C 83 3D ? ? ? ? ? 74 0B 68 ? ? ? ? FF 15 ? ? ? ? 68 04 02 08 00 E8 ? ? ? ? 83 C4 04 85 C0 74 09 8B C8 E8 ? ? ? ? EB 02 33 C0 56 57 A3 ? ? ? ? E8 ? ? ? ? 6A 00 6A 00 8B C8 8B 10 FF 52 10 A3 ? ? ? ? FF 15 ? ? ? ? 8B"; #endif +*/ auto lua_initclf = ScanSign(client, lua_initclf_sign, sizeof(lua_initclf_sign) - 1); if (!lua_initclf) diff --git a/source/shaderlib.cpp b/source/shaderlib.cpp index 67bc3b5..3669971 100644 --- a/source/shaderlib.cpp +++ b/source/shaderlib.cpp @@ -30,9 +30,10 @@ #include "d3dxdefs.h" #include #include -#include +#include #include "Windows.h" #include "DepthWrite.h" +#include "chromium_fix.h" using namespace GarrysMod::Lua; extern IShaderSystem* g_pSLShaderSystem; @@ -74,6 +75,7 @@ namespace ShaderLib auto currline = std::to_string(ar->currentline); LUA->PushFormattedString("%s:%s: shader compilation has failed %s\n%s", ar->short_src, currline.c_str(), name, error); currline.~basic_string(); + delete error; LUA->Error(); } @@ -235,7 +237,7 @@ namespace ShaderLib for (int i = 0; i < combosCount; i++) { IShaderBuffer* bf = (IShaderBuffer*)shaders[i]; - shaders[i] = g_pShaderManager->m_RawPixelShaderDict[(int)g_pShaderManager->CreatePixelShader(bf)]; + shaders[i] = g_pShaderManager->m_RawPixelShaderDict[(intp)g_pShaderManager->CreatePixelShader(bf)]; bf->Release(); } @@ -243,7 +245,6 @@ namespace ShaderLib { lookup.m_ShaderStaticCombos.m_pHardwareShaders = shaders; lookup.m_ShaderStaticCombos.m_nCount = combosCount; - g_pShaderManager->m_PixelShaderDict.AddToTail(lookup); } else @@ -332,7 +333,7 @@ namespace ShaderLib for (int i = 0; i < combosCount; i++) { IShaderBuffer* bf = (IShaderBuffer*)shaders[i]; - shaders[i] = g_pShaderManager->m_RawVertexShaderDict[(int)g_pShaderManager->CreateVertexShader(bf)]; + shaders[i] = g_pShaderManager->m_RawVertexShaderDict[(intp)g_pShaderManager->CreateVertexShader(bf)]; bf->Release(); } @@ -679,7 +680,7 @@ namespace ShaderLib CShaderManager::ShaderLookup_t* FindShader(const char* name, CUtlFixedLinkedList& list) { - int pshIndex = list.Head(); + intp pshIndex = list.Head(); while (pshIndex != list.InvalidIndex()) { CShaderManager::ShaderLookup_t* lookup = &list[pshIndex]; @@ -704,6 +705,7 @@ namespace ShaderLib if (u->Shader->PShader) { delete u->Shader->PShader; } shader->m_Flags = 0; u->Shader->PShader = strdup(name); + return 0; } @@ -719,6 +721,7 @@ namespace ShaderLib if (u->Shader->VShader) { delete u->Shader->VShader; } shader->m_Flags = 0; u->Shader->VShader = strdup(name); + return 0; } @@ -831,14 +834,48 @@ namespace ShaderLib return 0; } - typedef VertexShader_t(__thiscall* CShaderManager_SetVertexShaderDecl)(CShaderManager* _this, const char* pVertexShaderFile, int nStaticVshIndex, char* debugLabel); - - VertexShader_t __fastcall CreateVertexShader_detour(CShaderManager* _this, DWORD, const char* pVertexShaderFile, int nStaticVshIndex, char* debugLabel) + Define_thiscall_Hook(VertexShader_t, CShaderManager_CreateVertexShader, CShaderManager*, const char* pVertexShaderFile, int nStaticVshIndex, char* debugLabel) { g_pShaderManager = _this; return (int)INVALID_SHADER;// hook.GetTrampoline()(_this, pVertexShaderFile, nStaticVshIndex, debugLabel); } + Define_thiscall_Hook(void, CShaderManager_PurgeUnusedVertexAndPixelShaders, CShaderManager*) + { + if (!g_pShaderManager) { return; } + return; + } + + bool inDepthPass = false; + IMaterial* transpMat = NULL; + Define_thiscall_Hook(void, CMatRenderContextBase_Bind, void*, IMaterial* mat, void* data) + { + if (inDepthPass && strcmp(mat->GetShaderName(), "DepthWrite") != 0) + { + CMatRenderContextBase_Bind_trampoline()(_this, transpMat, NULL); + return; + } + CMatRenderContextBase_Bind_trampoline()(_this, mat, data); + return; + } + + Define_thiscall_Hook(void, CBaseWorldView_SSAO_DepthPass, void*) + { + if (!transpMat) + { + g_pCVar->FindVar("cl_drawspawneffect")->SetValue(0); + + auto pVMTKeyValues = new KeyValues("UnlitGeneric"); + pVMTKeyValues->SetString("$basetexture", "color/white"); + pVMTKeyValues->SetFloat("$alpha", 0); + transpMat = g_pMaterialSystem->CreateMaterial("egsm/transpmat", pVMTKeyValues); + } + inDepthPass = true; + CBaseWorldView_SSAO_DepthPass_trampoline()(_this); + inDepthPass = false; + return; + } + int MenuInit(GarrysMod::Lua::ILuaBase* LUA) { static Color msgc(100, 255, 100, 255); @@ -849,45 +886,98 @@ namespace ShaderLib if (!Sys_LoadInterface("materialsystem", "ShaderSystem002", NULL, (void**)&g_pSLShaderSystem)) { ShaderLibError("IShaderSystem == NULL"); } if (!Sys_LoadInterface("materialsystem", "VMaterialSystemConfig002", NULL, (void**)&g_pConfig)) { ShaderLibError("VMaterialSystemConfig002 == NULL"); } if (!Sys_LoadInterface("materialsystem", MATERIAL_SYSTEM_INTERFACE_VERSION, NULL, (void**)&g_pMaterialSystem)) { ShaderLibError("VMaterialSystem == NULL"); } - + g_pShaderShadow = (IShaderShadow*)(g_pMaterialSystem->QueryInterface(SHADERSHADOW_INTERFACE_VERSION)); - if (!g_pShaderShadow) { ShaderLibError("IShaderShadow == NULL"); } - + g_pShaderApi = (IShaderAPI*)(g_pMaterialSystem->QueryInterface(SHADERAPI_INTERFACE_VERSION)); g_pShaderDevice = (IShaderDevice*)(g_pMaterialSystem->QueryInterface(SHADER_DEVICE_INTERFACE_VERSION)); - if (!g_pShaderDevice) { ShaderLibError("IShaderDevice == NULL"); } + static SourceSDK::FactoryLoader icvar_loader("vstdlib", true, IS_SERVERSIDE, "bin/"); + g_pCVar = icvar_loader.GetInterface(CVAR_INTERFACE_VERSION); - g_pShaderApi = (IShaderAPI*)(g_pMaterialSystem->QueryInterface(SHADERAPI_INTERFACE_VERSION)); - if (!g_pShaderApi) { ShaderLibError("IShaderAPI == NULL"); } + if (!g_pShaderShadow) { ShaderLibError("IShaderShadow == NULL"); } + if (!g_pShaderDevice) { ShaderLibError("IShaderDevice == NULL"); } + if (!g_pShaderApi) { ShaderLibError("IShaderAPI == NULL"); } + if (!g_pCVar) { ShaderLibError("g_pCVar == NULL"); } auto shaderapidx = GetModuleHandle("shaderapidx9.dll"); if (!shaderapidx) { ShaderLibError("shaderapidx9.dll == NULL\n"); } auto d3dx9_40 = GetModuleHandle("D3DX9_40.dll"); - if (!d3dx9_40) { ShaderLibError("D3DX9_40.dll == NULL\n"); } - - static const char sign[] = "55 8B EC 8B 45 08 83 EC 28 56 57 8B F9 85 C0 0F 84 ? ? ? ? 50 8D 45 0A C7 45 EC 00 00 00 00 50 8D 4F 64 C7 45 F0 00 00 00 00 C7 45 E0 00 00 00 00 C7 45 E4 00 00 00 00 C7 45 E8 00 00 00 00 C7 45 FC 00 00 00 00 E8 ? ? ? ? 8B 77 18 8B 4D 0C 89 4D DC 66 8B 00 66 89 45 D8 85 F6 74 11 66 39 06 75 05"; - CShaderManager_SetVertexShaderDecl CShaderManager_SetVertexShader = (CShaderManager_SetVertexShaderDecl)ScanSign(shaderapidx, sign, sizeof(sign) - 1); - if (!CShaderManager_SetVertexShader) { ShaderLibError("CShaderManager::SetVertexShader == NULL\n"); return 0; } - - Detouring::Hook hook; - Detouring::Hook::Target target(reinterpret_cast(CShaderManager_SetVertexShader)); - hook.Create(target, CreateVertexShader_detour); - hook.Enable(); - g_pShaderShadow->SetVertexShader("HEREHEREHEREHERE", 1010); - hook.Destroy(); + if (!d3dx9_40) + { + d3dx9_40 = GetModuleHandle("D3DX9_42.dll"); + if (!d3dx9_40) + { + ShaderLibError("D3DX9_40.dll == NULL\nD3DX9_42.dll == NULL\n"); + } + } - if (!g_pShaderManager) { ShaderLibError("g_pShaderManager == NULL\n"); return 0; } + { + /* + #ifdef WIN64 + static const char sign[] = "48 8B C4 48 89 58 18 55 56 41 54 41 56 41 57 48 83 EC 60 4D 8B F9 41 8B F0 4C 8B F1 48 85 D2 0F 84 ? ? ? ? 0F 57 C0 4C 8B C2 45 33 E4 66 0F 7F 40 A8 48 8D 50 10 44 89 60 A0 48 81 C1 B0 00 00 00 E8 ? ? ? ? 49 8B 5E 20 0F B7 28 48 85 DB 74 17 66 39 2B 75 09 39 73 04 0F 84 ? ? ? ? 48 8B 5B 48 48"; + #else + static const char sign[] = "55 8B EC 8B 45 08 83 EC 28 56 57 8B F9 85 C0 0F 84 ? ? ? ? 50 8D 45 0A C7 45 EC 00 00 00 00 50 8D 4F 64 C7 45 F0 00 00 00 00 C7 45 E0 00 00 00 00 C7 45 E4 00 00 00 00 C7 45 E8 00 00 00 00 C7 45 FC 00 00 00 00 E8 ? ? ? ? 8B 77 18 8B 4D 0C 89 4D DC 66 8B 00 66 89 45 D8 85 F6 74 11 66 39 06 75 05"; + #endif + */ + static const char sign[] = + HOOK_SIGN_CHROMIUM_X64("48 8B C4 48 89 58 18 55 56 41 54 41 56 41 57 48 83 EC 60 4D 8B F9 41 8B F0 4C 8B F1 48 85 D2 0F 84 ? ? ? ? 0F 57 C0 4C 8B C2 45 33 E4 66 0F 7F 40 A8 48 8D 50 10 44 89 60 A0 48 81 C1 B0 00 00 00 E8 ? ? ? ? 49 8B 5E 20 0F B7 28 48 85 DB 74 17 66 39 2B 75 09 39 73 04 0F 84 ? ? ? ? 48 8B 5B 48 48") + HOOK_SIGN_x32("55 8B EC 8B 45 08 83 EC 28 56 57 8B F9 85 C0 0F 84 ? ? ? ? 50 8D 45 0A C7 45 EC 00 00 00 00 50 8D 4F 64 C7 45 F0 00 00 00 00 C7 45 E0 00 00 00 00 C7 45 E4 00 00 00 00 C7 45 E8 00 00 00 00 C7 45 FC 00 00 00 00 E8 ? ? ? ? 8B 77 18 8B 4D 0C 89 4D DC 66 8B 00 66 89 45 D8 85 F6 74 11 66 39 06 75 05") + + CShaderManager_CreateVertexShader_decl CShaderManager_SetVertexShader = (CShaderManager_CreateVertexShader_decl)ScanSign(shaderapidx, sign, sizeof(sign) - 1); + if (!CShaderManager_SetVertexShader) { ShaderLibError("CShaderManager::SetVertexShader == NULL\n"); return 0; } + + Setup_Hook(CShaderManager_CreateVertexShader, CShaderManager_SetVertexShader) + g_pShaderShadow->SetVertexShader("HEREHEREHEREHERE", 1010); + CShaderManager_CreateVertexShader_hook.Destroy(); + + if (!g_pShaderManager) { ShaderLibError("g_pShaderManager == NULL\n"); return 0; } + } D3DXCompileShader = (D3DXCompileShaderDecl*)GetProcAddress(d3dx9_40, "D3DXCompileShader"); if (!D3DXCompileShader) { ShaderLibError("D3DXCompileShader == NULL\n"); return 0; } g_pCShaderSystem = (CShaderSystem*)g_pSLShaderSystem; + auto clientdll = GetModuleHandle("client.dll"); + if (!clientdll) { ShaderLibError("client.dll == NULL\n"); } + + { + /* +#ifdef CHROMIUM + "55 8B EC 83 EC 08 53 8B D9 8B ? ? ? ? ? 8B 01 8B 40 2C FF D0 84 C0 0F 84 ? ? ? ? 8B ? ? ? ? ? 8B 81 0C 10 00 00 89 45 F8 85 C0 74 16 6A 04 6A 00 68 ? ? ? ? 6A 00 68 ? ? ? ? FF 15 ? ? ? ? 8B"; +#endif +*/ + static const char sign[] = + HOOK_SIGN("55 8B EC 83 EC 08 53 8B D9 8B ? ? ? ? ? 8B 01 8B 40 2C FF D0 84 C0 0F 84 ? ? ? ? 8B ? ? ? ? ? 8B 81 0C 10 00 00 89 45 F8 85 C0 74 16 6A 04 6A 00 68 ? ? ? ? 6A 00 68 ? ? ? ? FF 15 ? ? ? ? 8B") + + void* DepthPass = ScanSign(clientdll, sign, sizeof(sign) - 1); + if (!DepthPass) { ShaderLibError("CBaseWorldView::SSAO_DepthPass == NULL\n"); return 0; } + Setup_Hook(CBaseWorldView_SSAO_DepthPass, DepthPass) + } + + auto materialsystemdll = GetModuleHandle("materialsystem.dll"); + if (!materialsystemdll) { ShaderLibError("materialsystem.dll == NULL\n"); } + + { + /* +#ifdef CHROMIUM + "55 8B EC 56 57 8B F9 8B 4D 08 85 C9 75 14 68 ? ? ? ? FF 15 ? ? ? ? 8B ? ? ? ? ? 83 C4 04 8B 01 FF 90 78 01 00 00 8B 17 8B CF 8B F0 FF 92 2C 03 00 00 3B C6 74 2F 8B 06 8B CE 8B 80 E0 00 00 00 FF D0 84 C0 75 14 8B 06 8B CE FF 90 5C 01 00 00"; +#endif +*/ + static const char sign[] = + HOOK_SIGN_CHROMIUM_X32("55 8B EC 56 57 8B F9 8B 4D 08 85 C9 75 14 68 ? ? ? ? FF 15 ? ? ? ? 8B ? ? ? ? ? 83 C4 04 8B 01 FF 90 78 01 00 00 8B 17 8B CF 8B F0 FF 92 2C 03 00 00 3B C6 74 2F 8B 06 8B CE 8B 80 E0 00 00 00 FF D0 84 C0 75 14 8B 06 8B CE FF 90 5C 01 00 00") + HOOK_SIGN("55 8B EC 56 57 8B F9 8B 4D 08 85 C9 75 22 39 ? ? ? ? ? 0F 84 ? ? ? ? 68 ? ? ? ? FF 15 ? ? ? ? 8B ? ? ? ? ? 83 C4 04 EB 0D 8B 01 FF 75 0C FF 90 D4 00 00 00 8B F0 8B 06 8B CE 53 FF 90 78 01 00 00 8B D8 8B CB 8B 13 FF 92 E8 00 00 00 85 C0 0F 8F ? ? ? ? 8B") + + void* Bind = ScanSign(materialsystemdll, sign, sizeof(sign) - 1); + if (!Bind) { ShaderLibError("CMatRenderContextBase::Bind == NULL\n"); return 0; } + Setup_Hook(CMatRenderContextBase_Bind, Bind) + } + g_pShaderLibDLLIndex = g_pCShaderSystem->m_ShaderDLLs.AddToTail(); g_pShaderLibDLL = &g_pCShaderSystem->m_ShaderDLLs[g_pShaderLibDLLIndex]; g_pShaderLibDLL->m_pFileName = strdup("egsm_shaders.dll"); g_pShaderLibDLL->m_bModShaderDLL = true; - + //IShaderDynamicAPI* sapi = (IShaderDynamicAPI*)((IShaderAPI030*)(g_pShaderApi)); for (int i = 0; i < g_pCShaderSystem->m_ShaderDLLs.Count(); i++) @@ -903,12 +993,13 @@ namespace ShaderLib } } + Setup_Hook(CShaderManager_PurgeUnusedVertexAndPixelShaders, GetVTable(g_pShaderManager)[15]) + ConColorMsg(msgc, "-Succ\n"); } void LuaInit(GarrysMod::Lua::ILuaBase* LUA) { - //g_pShaderLibDLL->m_ShaderDict.Insert("DepthWrite", g_DepthWriteShader); int iW, iH; g_pMaterialSystem->GetBackBufferDimensions(iW, iH); @@ -1108,12 +1199,11 @@ namespace ShaderLib } - /* if (!g_pShaderManager) { return; } { - int pshIndex = g_pShaderManager->m_PixelShaderDict.Head(); - int pshIndexPrev = 0; + intp pshIndex = g_pShaderManager->m_PixelShaderDict.Head(); + intp pshIndexPrev = 0; while (pshIndex != g_pShaderManager->m_PixelShaderDict.InvalidIndex()) { CShaderManager::ShaderLookup_t& lookup = g_pShaderManager->m_PixelShaderDict[pshIndex]; @@ -1134,8 +1224,8 @@ namespace ShaderLib } { - int vshIndex = g_pShaderManager->m_VertexShaderDict.Head(); - int vshIndexPrev = 0; + intp vshIndex = g_pShaderManager->m_VertexShaderDict.Head(); + intp vshIndexPrev = 0; while (vshIndex != g_pShaderManager->m_VertexShaderDict.InvalidIndex()) { CShaderManager::ShaderLookup_t& lookup = g_pShaderManager->m_VertexShaderDict[vshIndex]; @@ -1154,7 +1244,7 @@ namespace ShaderLib } } } - */ + } } \ No newline at end of file diff --git a/source/shaderlib.h b/source/shaderlib.h index 2b13d8c..feb14b9 100644 --- a/source/shaderlib.h +++ b/source/shaderlib.h @@ -161,6 +161,11 @@ namespace ShaderLib return 0; } + virtual bool NeedsFullFrameBufferTexture(IMaterialVar** params, bool bCheckSpecificToThisFrame /* = true */) const + { + return true; + } + void OnInitShaderInstance(IMaterialVar** params, IShaderInit* pShaderInit, const char* pMaterialName) { for (int i = 0; i < PConstants.Count(); i++) @@ -253,7 +258,7 @@ namespace ShaderLib BOOL }; -#define GENStandardConstantType(_) _(EYE_POS) _(CURTIME) _(LIGHT_INFO) _(AMBIENT_CUBE) _(FOG_PARAMS) _(SHADER_CONTROLS) _(DIFFUSE_MODULATION) +#define GENStandardConstantType(_) _(EYE_POS) _(CURTIME) _(LIGHT_INFO) _(AMBIENT_CUBE) _(FOG_PARAMS) _(SHADER_CONTROLS) _(DIFFUSE_MODULATION) _(INVERSE_VIEWMATRIX) #define GENStandardConstantTypeEnum(v) v, struct ShaderConstantP { @@ -281,7 +286,7 @@ namespace ShaderLib }; LightState_t lightState; - + VMatrix viewMatrix, projectionMatrix, viewProjectionMatrix, inverseViewProjectionMatrix; RetValueType StdToValue(IShaderDynamicAPI* pShaderAPI, ShaderConstantP* param, IMaterialVar** params, int vsh) { switch (param->Param) @@ -314,6 +319,22 @@ namespace ShaderLib fVals[3] = IS_FLAG_SET(MATERIAL_VAR_VERTEXALPHA) ? 1 : 0; return FLOAT; break; + case ShaderConstantP::INVERSE_VIEWMATRIX: + + pShaderAPI->GetMatrix(MATERIAL_VIEW, viewMatrix.Base()); + pShaderAPI->GetMatrix(MATERIAL_PROJECTION, projectionMatrix.Base()); + MatrixMultiply(projectionMatrix, viewMatrix, viewProjectionMatrix); + MatrixInverseGeneral(viewProjectionMatrix, inverseViewProjectionMatrix); + if (vsh) + { + pShaderAPI->SetVertexShaderConstant(param->Index, inverseViewProjectionMatrix.Base(), 4); + } + else + { + pShaderAPI->SetPixelShaderConstant(param->Index, inverseViewProjectionMatrix.Base(), 4); + } + return NONE; + break; case ShaderConstantP::DIFFUSE_MODULATION: SetModulationPixelShaderDynamicState_LinearColorSpace(param->Index); return NONE; diff --git a/source/sigscan.h b/source/sigscan.h deleted file mode 100644 index c8d324e..0000000 --- a/source/sigscan.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include -#include -#include - -struct DynLibInfo -{ - void* baseAddress; - size_t memorySize; -}; - -bool GetLibraryInfo(const void* handle, DynLibInfo& lib); -void* ScanSign(const void* handle, const char* sig, size_t len, const void* start = NULL); \ No newline at end of file diff --git a/source/version.h b/source/version.h index c537f40..f3ac111 100644 --- a/source/version.h +++ b/source/version.h @@ -1 +1 @@ -#define EGSM_VERSION 3 \ No newline at end of file +#define EGSM_VERSION 4 \ No newline at end of file