Skip to content

Commit

Permalink
Depth buffer fix and x86 support
Browse files Browse the repository at this point in the history
Excluded effects(particles, trails, etc.) from depth buffer
  • Loading branch information
devonium committed Mar 25, 2023
1 parent e65f6ed commit c5b78db
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 63 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
### 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

### How to compile
[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"
```
2 changes: 1 addition & 1 deletion premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions source/chromium_fix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#ifdef CHROMIUM
#undef strdup
#include <tier0/memdbgoff.h>
#endif
14 changes: 8 additions & 6 deletions source/d3dxdefs.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#include "chromium_fix.h"
#include <combaseapi.h>
#include <igamesystem.h>
#include <regex>
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion source/sigscan.cpp → source/e_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "sigscan.h"
#include "e_utils.h"
#include <Windows.h>
#include <scanning/symbolfinder.hpp>
#include <detouring/hook.hpp>
Expand Down
57 changes: 57 additions & 0 deletions source/e_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once
#include <Windows.h>
#include <scanning/symbolfinder.hpp>
#include <detouring/hook.hpp>

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<name##_decl>();}\
rettype __fastcall name##_detour(thistype _this, void* edx, __VA_ARGS__)

#define Setup_Hook(name, targ) \
{ \
Detouring::Hook::Target target(reinterpret_cast<void*>(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
23 changes: 22 additions & 1 deletion source/f_vmatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
}
Expand Down
12 changes: 11 additions & 1 deletion source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "chromium_fix.h"
#include <mathlib/ssemath.h>
#include "f_mathlib.h"
#include "shaderlib.h"
Expand All @@ -10,7 +11,7 @@
#include <scanning/symbolfinder.hpp>
#include <detouring/hook.hpp>
#include "f_igamesystem.h"
#include <sigscan.h>
#include <e_utils.h>
#include <Color.h>
#include "version.h"
#include "Windows.h"
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit c5b78db

Please sign in to comment.