Skip to content

Commit

Permalink
Merge branch 'main' into autohook/runframe.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Alystrasz authored Nov 6, 2024
2 parents 05c7457 + 10041ca commit c103135
Show file tree
Hide file tree
Showing 31 changed files with 848 additions and 351 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Configures dependabot

version: 2
updates:
# GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ include_directories(primedev/thirdparty)

# Targets
add_subdirectory(primedev)
# Forces Minizip to not use functions that are not available in Win 7 libraries.
if(WIN32)
target_compile_definitions(minizip PUBLIC -D_WIN32_WINNT=0x0601)
endif()
2 changes: 1 addition & 1 deletion primedev/Northstar.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ add_library(
"core/memalloc.cpp"
"core/memalloc.h"
"core/sourceinterface.cpp"
"core/sourceinterface.h"
"core/tier0.cpp"
"core/tier0.h"
"core/tier1.cpp"
Expand All @@ -69,6 +68,7 @@ add_library(
"engine/r2engine.cpp"
"engine/r2engine.h"
"engine/runframe.cpp"
"game/client/clientmode_shared.cpp"
"logging/crashhandler.cpp"
"logging/crashhandler.h"
"logging/logging.cpp"
Expand Down
40 changes: 40 additions & 0 deletions primedev/client/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,53 @@ static void __fastcall h_MilesLog(int level, const char* string)
spdlog::info("[MSS] {} - {}", level, string);
}

static void(__fastcall* o_pSub_18003EBD0)(DWORD dwThreadID, const char* threadName) = nullptr;
static void __fastcall h_Sub_18003EBD0(DWORD dwThreadID, const char* threadName)
{
HANDLE hThread = OpenThread(THREAD_SET_LIMITED_INFORMATION, FALSE, dwThreadID);

if (hThread != NULL)
{
// TODO: This "method" of "charset conversion" from string to wstring is abhorrent. Change it to a proper one
// as soon as Northstar has some helper function to do proper charset conversions.
auto tmp = std::string(threadName);
HRESULT WINAPI _SetThreadDescription(HANDLE hThread, PCWSTR lpThreadDescription);
_SetThreadDescription(hThread, std::wstring(tmp.begin(), tmp.end()).c_str());

CloseHandle(hThread);
}

o_pSub_18003EBD0(dwThreadID, threadName);
}

static char*(__fastcall* o_pSub_18003BC10)(void* a1, void* a2, void* a3, void* a4, void* a5, int a6) = nullptr;
static char* __fastcall h_Sub_18003BC10(void* a1, void* a2, void* a3, void* a4, void* a5, int a6)
{
HANDLE hThread;
char* ret = o_pSub_18003BC10(a1, a2, a3, a4, a5, a6);

if (ret != NULL && (hThread = reinterpret_cast<HANDLE>(*((uint64_t*)ret + 55))) != NULL)
{
HRESULT WINAPI _SetThreadDescription(HANDLE hThread, PCWSTR lpThreadDescription);
_SetThreadDescription(hThread, L"[Miles] WASAPI Service Thread");
}

return ret;
}

ON_DLL_LOAD("mileswin64.dll", MilesWin64_Audio, (CModule module))
{
o_pLoadSampleMetadata = module.Offset(0xF110).RCast<decltype(o_pLoadSampleMetadata)>();
HookAttach(&(PVOID&)o_pLoadSampleMetadata, (PVOID)h_LoadSampleMetadata);

o_pSub_1800294C0 = module.Offset(0x294C0).RCast<decltype(o_pSub_1800294C0)>();
HookAttach(&(PVOID&)o_pSub_1800294C0, (PVOID)h_Sub_1800294C0);

o_pSub_18003EBD0 = module.Offset(0x3EBD0).RCast<decltype(o_pSub_18003EBD0)>();
HookAttach(&(PVOID&)o_pSub_18003EBD0, (PVOID)h_Sub_18003EBD0);

o_pSub_18003BC10 = module.Offset(0x3BC10).RCast<decltype(o_pSub_18003BC10)>();
HookAttach(&(PVOID&)o_pSub_18003BC10, (PVOID)h_Sub_18003BC10);
}

ON_DLL_LOAD_RELIESON("engine.dll", MilesLogFuncHooks, ConVar, (CModule module))
Expand Down
1 change: 0 additions & 1 deletion primedev/core/convar/convar.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include "core/sourceinterface.h"
#include "core/math/color.h"
#include "cvar.h"
#include "concommand.h"
Expand Down
22 changes: 11 additions & 11 deletions primedev/core/filesystem/filesystem.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "filesystem.h"
#include "core/sourceinterface.h"
#include "core/tier1.h"
#include "mods/modmanager.h"

#include <iostream>
Expand All @@ -10,23 +10,23 @@ std::string sCurrentModPath;

ConVar* Cvar_ns_fs_log_reads;

SourceInterface<IFileSystem>* g_pFilesystem;
IFileSystem* g_pFilesystem;

std::string ReadVPKFile(const char* path)
{
// read scripts.rson file, todo: check if this can be overwritten
FileHandle_t fileHandle = (*g_pFilesystem)->m_vtable2->Open(&(*g_pFilesystem)->m_vtable2, path, "rb", "GAME", 0);
FileHandle_t fileHandle = g_pFilesystem->m_vtable2->Open(&g_pFilesystem->m_vtable2, path, "rb", "GAME", 0);

std::stringstream fileStream;
int bytesRead = 0;
char data[4096];
do
{
bytesRead = (*g_pFilesystem)->m_vtable2->Read(&(*g_pFilesystem)->m_vtable2, data, (int)std::size(data), fileHandle);
bytesRead = g_pFilesystem->m_vtable2->Read(&g_pFilesystem->m_vtable2, data, (int)std::size(data), fileHandle);
fileStream.write(data, bytesRead);
} while (bytesRead == std::size(data));

(*g_pFilesystem)->m_vtable2->Close(*g_pFilesystem, fileHandle);
g_pFilesystem->m_vtable2->Close(g_pFilesystem, fileHandle);

return fileStream.str();
}
Expand Down Expand Up @@ -65,12 +65,12 @@ void SetNewModSearchPaths(Mod* mod)
if ((fs::absolute(mod->m_ModDirectory) / MOD_OVERRIDE_DIR).string().compare(sCurrentModPath))
{
o_pAddSearchPath(
&*(*g_pFilesystem), (fs::absolute(mod->m_ModDirectory) / MOD_OVERRIDE_DIR).string().c_str(), "GAME", PATH_ADD_TO_HEAD);
g_pFilesystem, (fs::absolute(mod->m_ModDirectory) / MOD_OVERRIDE_DIR).string().c_str(), "GAME", PATH_ADD_TO_HEAD);
sCurrentModPath = (fs::absolute(mod->m_ModDirectory) / MOD_OVERRIDE_DIR).string();
}
}
else // push compiled to head
o_pAddSearchPath(&*(*g_pFilesystem), fs::absolute(GetCompiledAssetsPath()).string().c_str(), "GAME", PATH_ADD_TO_HEAD);
o_pAddSearchPath(g_pFilesystem, fs::absolute(GetCompiledAssetsPath()).string().c_str(), "GAME", PATH_ADD_TO_HEAD);
}

bool TryReplaceFile(const char* pPath, bool shouldCompile)
Expand Down Expand Up @@ -167,12 +167,12 @@ ON_DLL_LOAD("filesystem_stdio.dll", Filesystem, (CModule module))
o_pCBaseFileSystem__OpenEx = module.Offset(0x15F50).RCast<decltype(o_pCBaseFileSystem__OpenEx)>();
HookAttach(&(PVOID&)o_pCBaseFileSystem__OpenEx, (PVOID)h_CBaseFileSystem__OpenEx);

g_pFilesystem = new SourceInterface<IFileSystem>("filesystem_stdio.dll", "VFileSystem017");
g_pFilesystem = Sys_GetFactoryPtr("filesystem_stdio.dll", "VFileSystem017").RCast<IFileSystem*>();

o_pAddSearchPath = reinterpret_cast<decltype(o_pAddSearchPath)>((*g_pFilesystem)->m_vtable->AddSearchPath);
o_pAddSearchPath = reinterpret_cast<decltype(o_pAddSearchPath)>(g_pFilesystem->m_vtable->AddSearchPath);
HookAttach(&(PVOID&)o_pAddSearchPath, (PVOID)h_AddSearchPath);
o_pReadFromCache = reinterpret_cast<decltype(o_pReadFromCache)>((*g_pFilesystem)->m_vtable->ReadFromCache);
o_pReadFromCache = reinterpret_cast<decltype(o_pReadFromCache)>(g_pFilesystem->m_vtable->ReadFromCache);
HookAttach(&(PVOID&)o_pReadFromCache, (PVOID)h_ReadFromCache);
o_pMountVPK = reinterpret_cast<decltype(o_pMountVPK)>((*g_pFilesystem)->m_vtable->MountVPK);
o_pMountVPK = reinterpret_cast<decltype(o_pMountVPK)>(g_pFilesystem->m_vtable->MountVPK);
HookAttach(&(PVOID&)o_pMountVPK, (PVOID)h_MountVPK);
}
3 changes: 1 addition & 2 deletions primedev/core/filesystem/filesystem.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include "core/sourceinterface.h"

// taken from ttf2sdk
typedef void* FileHandle_t;
Expand Down Expand Up @@ -48,7 +47,7 @@ class IFileSystem
VTable2* m_vtable2;
};

extern SourceInterface<IFileSystem>* g_pFilesystem;
extern IFileSystem* g_pFilesystem;

std::string ReadVPKFile(const char* path);
std::string ReadVPKOriginalFile(const char* path);
Loading

0 comments on commit c103135

Please sign in to comment.