Skip to content

Commit

Permalink
Merge branch 'main' into feat/overhaul-mod-loading-locations
Browse files Browse the repository at this point in the history
  • Loading branch information
GeckoEidechse authored Aug 25, 2024
2 parents fff09b8 + 5aae421 commit 5472a36
Show file tree
Hide file tree
Showing 25 changed files with 401 additions and 459 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AccessModifierOffset: -4
AlignTrailingComments: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: Inline
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: No
Expand Down
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

# Folder rename
f9bc3c9d1834cb8bd5f872b749b057c33e8b0102

# Clang format change: one-line inline functions
5b2c608b22ba272e4ab1a45adc1f43b60b1aea79
3 changes: 2 additions & 1 deletion .github/workflows/merge-conflict-auto-label.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Merge Conflict Auto Label
on:
workflow_dispatch: # Manual run
push:
branches:
- main
schedule:
- cron: "10 21 * * *"
- cron: "10 21 * * *" # Runs at 21:10; time was chosen based on contributor activity and low GitHub Actions cron load.

jobs:
triage:
Expand Down
3 changes: 3 additions & 0 deletions primedev/Northstar.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ add_library(
"dedicated/dedicatedlogtoclient.cpp"
"dedicated/dedicatedlogtoclient.h"
"dedicated/dedicatedmaterialsystem.cpp"
"engine/gl_matsysiface.cpp"
"engine/host.cpp"
"engine/hoststate.cpp"
"engine/hoststate.h"
Expand Down Expand Up @@ -161,6 +162,8 @@ add_library(
"util/version.h"
"util/wininfo.cpp"
"util/wininfo.h"
"windows/libsys.cpp"
"windows/libsys.h"
"dllmain.cpp"
"ns_version.h"
"Northstar.def"
Expand Down
25 changes: 5 additions & 20 deletions primedev/client/debugoverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ struct OverlayBase_t

struct OverlayLine_t : public OverlayBase_t
{
OverlayLine_t()
{
m_Type = OVERLAY_LINE;
}
OverlayLine_t() { m_Type = OVERLAY_LINE; }

Vector3 origin;
Vector3 dest;
Expand All @@ -57,10 +54,7 @@ struct OverlayLine_t : public OverlayBase_t

struct OverlayBox_t : public OverlayBase_t
{
OverlayBox_t()
{
m_Type = OVERLAY_BOX;
}
OverlayBox_t() { m_Type = OVERLAY_BOX; }

Vector3 origin;
Vector3 mins;
Expand All @@ -74,10 +68,7 @@ struct OverlayBox_t : public OverlayBase_t

struct OverlayTriangle_t : public OverlayBase_t
{
OverlayTriangle_t()
{
m_Type = OVERLAY_TRIANGLE;
}
OverlayTriangle_t() { m_Type = OVERLAY_TRIANGLE; }

Vector3 p1;
Vector3 p2;
Expand All @@ -91,10 +82,7 @@ struct OverlayTriangle_t : public OverlayBase_t

struct OverlaySweptBox_t : public OverlayBase_t
{
OverlaySweptBox_t()
{
m_Type = OVERLAY_SWEPT_BOX;
}
OverlaySweptBox_t() { m_Type = OVERLAY_SWEPT_BOX; }

Vector3 start;
Vector3 end;
Expand All @@ -109,10 +97,7 @@ struct OverlaySweptBox_t : public OverlayBase_t

struct OverlaySphere_t : public OverlayBase_t
{
OverlaySphere_t()
{
m_Type = OVERLAY_SPHERE;
}
OverlaySphere_t() { m_Type = OVERLAY_SPHERE; }

Vector3 vOrigin;
float flRadius;
Expand Down
85 changes: 4 additions & 81 deletions primedev/core/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <filesystem>
#include <Psapi.h>

#define XINPUT1_3_DLL "XInput1_3.dll"

namespace fs = std::filesystem;

AUTOHOOK_INIT()
Expand Down Expand Up @@ -392,87 +390,12 @@ void CallAllPendingDLLLoadCallbacks()
}
}

// clang-format off
AUTOHOOK_ABSOLUTEADDR(_LoadLibraryExA, (LPVOID)LoadLibraryExA,
HMODULE, WINAPI, (LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags))
// clang-format on
{
HMODULE moduleAddress;

LPCSTR lpLibFileNameEnd = lpLibFileName + strlen(lpLibFileName);
LPCSTR lpLibName = lpLibFileNameEnd - strlen(XINPUT1_3_DLL);

// replace xinput dll with one that has ASLR
if (lpLibFileName <= lpLibName && !strncmp(lpLibName, XINPUT1_3_DLL, strlen(XINPUT1_3_DLL) + 1))
{
moduleAddress = _LoadLibraryExA("XInput9_1_0.dll", hFile, dwFlags);

if (!moduleAddress)
{
MessageBoxA(0, "Could not find XInput9_1_0.dll", "Northstar", MB_ICONERROR);
exit(EXIT_FAILURE);

return nullptr;
}
}
else
moduleAddress = _LoadLibraryExA(lpLibFileName, hFile, dwFlags);

if (moduleAddress)
{
CallLoadLibraryACallbacks(lpLibFileName, moduleAddress);
g_pPluginManager->InformDllLoad(moduleAddress, fs::path(lpLibFileName));
}

return moduleAddress;
}

// clang-format off
AUTOHOOK_ABSOLUTEADDR(_LoadLibraryA, (LPVOID)LoadLibraryA,
HMODULE, WINAPI, (LPCSTR lpLibFileName))
// clang-format on
{
HMODULE moduleAddress = _LoadLibraryA(lpLibFileName);

if (moduleAddress)
CallLoadLibraryACallbacks(lpLibFileName, moduleAddress);

return moduleAddress;
}

// clang-format off
AUTOHOOK_ABSOLUTEADDR(_LoadLibraryExW, (LPVOID)LoadLibraryExW,
HMODULE, WINAPI, (LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags))
// clang-format on
{
HMODULE moduleAddress = _LoadLibraryExW(lpLibFileName, hFile, dwFlags);

if (moduleAddress)
CallLoadLibraryWCallbacks(lpLibFileName, moduleAddress);

return moduleAddress;
}

// clang-format off
AUTOHOOK_ABSOLUTEADDR(_LoadLibraryW, (LPVOID)LoadLibraryW,
HMODULE, WINAPI, (LPCWSTR lpLibFileName))
// clang-format on
{
HMODULE moduleAddress = _LoadLibraryW(lpLibFileName);

if (moduleAddress)
{
CallLoadLibraryWCallbacks(lpLibFileName, moduleAddress);
g_pPluginManager->InformDllLoad(moduleAddress, fs::path(lpLibFileName));
}

return moduleAddress;
}

void InstallInitialHooks()
void HookSys_Init()
{
if (MH_Initialize() != MH_OK)
{
spdlog::error("MH_Initialize (minhook initialization) failed");

}
// todo: remove remaining instances of autohook in this file
AUTOHOOK_DISPATCH()
}
33 changes: 28 additions & 5 deletions primedev/core/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,33 @@
#include <string>
#include <iostream>

void InstallInitialHooks();
//-----------------------------------------------------------------------------
// Purpose: Init minhook
//-----------------------------------------------------------------------------
void HookSys_Init();

//-----------------------------------------------------------------------------
// Purpose: MH_MakeHook wrapper
// Input : *ppOriginal - Original function being detoured
// pDetour - Detour function
//-----------------------------------------------------------------------------
inline void HookAttach(PVOID* ppOriginal, PVOID pDetour)
{
PVOID pAddr = *ppOriginal;
if (MH_CreateHook(pAddr, pDetour, ppOriginal) == MH_OK)
{
if (MH_EnableHook(pAddr) != MH_OK)
{
spdlog::error("Failed enabling a function hook!");
}
}
else
{
spdlog::error("Failed creating a function hook!");
}
}

void CallLoadLibraryACallbacks(LPCSTR lpLibFileName, HMODULE moduleAddress);

typedef void (*DllLoadCallbackFuncType)(CModule moduleAddress);
void AddDllLoadCallback(std::string dll, DllLoadCallbackFuncType callback, std::string tag = "", std::vector<std::string> reliesOn = {});
Expand Down Expand Up @@ -301,10 +327,7 @@ class __autovar
pAutohook->vars.push_back(this);
}

void Dispatch()
{
*m_pTarget = (void*)ParseDLLOffsetString(m_pAddrString);
}
void Dispatch() { *m_pTarget = (void*)ParseDLLOffsetString(m_pAddrString); }
};

// VAR_AT(engine.dll+0x404, ConVar*, Cvar_host_timescale)
Expand Down
Loading

0 comments on commit 5472a36

Please sign in to comment.