Skip to content

Commit

Permalink
Merge branch 'R2Northstar:main' into persistence-again-but-for-real-t…
Browse files Browse the repository at this point in the history
…his-time
  • Loading branch information
ASpoonPlaysGames authored Aug 26, 2023
2 parents 87724ff + 07e76e3 commit b7260df
Show file tree
Hide file tree
Showing 515 changed files with 1,613 additions and 71,067 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**/include/** linguist-vendored
**/thirdparty/** linguist-vendored
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'true'
- name: Setup msvc
uses: ilammy/msvc-dev-cmd@v1
- name: Configure cmake
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'true'
- name: Setup msvc
uses: ilammy/msvc-dev-cmd@v1
- name: Configure cmake
Expand Down
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[submodule "thirdparty/libcurl"]
path = thirdparty/libcurl
url = https://github.com/curl/curl
ignore = untracked
[submodule "thirdparty/minhook"]
path = thirdparty/minhook
url = https://github.com/TsudaKageyu/minhook
ignore = untracked
9 changes: 4 additions & 5 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ The following steps will allow you to compile your own NorthstarLauncher executa
*This guide assumes you have already installed Northstar as shown in [this page](https://r2northstar.gitbook.io/r2northstar-wiki/installing-northstar/basic-setup)*

### Steps
1. **Download the code** from the [R2Northstar/NorthstarLauncher](https://github.com/R2Northstar/NorthstarLauncher) repo
2. **Unzip the file.**
3. **Place the file somewhere memorable,** such as in your Documents directory
4. **Install Visual Studio 2022** from [this link](https://visualstudio.microsoft.com/downloads/). Northstar uses the vc2022 compiler, which is provided with Visual Studio. *You only need to download the Community edition.*
5. If you are prompted to download Workloads, check "Desktop Development with C++" If you are not prompted, don't worry, you'll be able to install this later on as well.
1. **Install Git** from [this link](https://git-scm.com)
2. **Clone** the [R2Northstar/NorthstarLauncher](https://github.com/R2Northstar/NorthstarLauncher) repo with submodules using this command `git clone --recurse-submodules https://github.com/R2Northstar/NorthstarLauncher.git`
3. **Install Visual Studio 2022** from [this link](https://visualstudio.microsoft.com/downloads/). Northstar uses the vc2022 compiler, which is provided with Visual Studio. *You only need to download the Community edition.*
4. If you are prompted to download Workloads, check "Desktop Development with C++" If you are not prompted, don't worry, you'll be able to install this later on as well.

![Desktop Development Workload](https://user-images.githubusercontent.com/40443620/147722260-b6ec90e9-7b74-4fb7-b512-680c039afaef.png)

Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.15)

project(Northstar CXX ASM_MASM)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()

# Language specs
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 17)
Expand All @@ -16,7 +21,11 @@ set(NS_BINARY_DIR ${CMAKE_BINARY_DIR}/game)
# and then link binaries in ${CMAKE_BINARY_DIR}/game. This means you can copy your
# game into ${CMAKE_BINARY_DIR}/game without it being cluttered up by cmake files.

message("NS: Building to ${NS_BINARY_DIR}")
message(STATUS "NS: Building to ${NS_BINARY_DIR}")


list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(utils)

# Targets
add_subdirectory(loader_wsock32_proxy)
Expand Down
24 changes: 18 additions & 6 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
{
{
"configurations": [
{
"name": "x64-Debug",
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "Debug",
"configurationType": "Release",
"buildRoot": "${projectDir}\\build",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ]
},
{
"name": "x64-RelWithDebInfo",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\build",
"installRoot": "${projectDir}\\out\\install\\${name}",
Expand All @@ -12,15 +23,16 @@
"ctestCommandArgs": ""
},
{
"name": "x64-Release",
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Release",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\build",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ]
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": []
}
]
}
14 changes: 10 additions & 4 deletions NorthstarDLL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# NorthstarDLL

find_package(minhook REQUIRED)
find_package(libcurl REQUIRED)

add_library(NorthstarDLL SHARED
"client/audio.cpp"
"client/audio.h"
Expand Down Expand Up @@ -77,6 +80,8 @@ add_library(NorthstarDLL SHARED
"mods/compiled/ns_persistence.h"
"mods/modmanager.cpp"
"mods/modmanager.h"
"mods/modsavefiles.cpp"
"mods/modsavefiles.h"
"plugins/plugin_abi.h"
"plugins/pluginbackend.cpp"
"plugins/pluginbackend.h"
Expand All @@ -96,6 +101,7 @@ add_library(NorthstarDLL SHARED
"scripts/scripthttprequesthandler.cpp"
"scripts/scripthttprequesthandler.h"
"scripts/scriptjson.cpp"
"scripts/scriptjson.h"
"scripts/scriptutility.cpp"
"server/auth/bansystem.cpp"
"server/auth/bansystem.h"
Expand Down Expand Up @@ -148,9 +154,9 @@ add_library(NorthstarDLL SHARED
"mods/compiled/ns_persistence.h")

target_link_libraries(NorthstarDLL PRIVATE
${CMAKE_SOURCE_DIR}/include/MinHook.x64.lib
${CMAKE_SOURCE_DIR}/include/libcurl/lib/libcurl_a.lib
Ws2_32.lib
minhook
libcurl
WS2_32.lib
Crypt32.lib
Cryptui.lib
dbghelp.lib
Expand All @@ -162,7 +168,7 @@ target_link_libraries(NorthstarDLL PRIVATE

target_include_directories(NorthstarDLL PRIVATE
${CMAKE_SOURCE_DIR}/NorthstarDLL
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/thirdparty
)

target_precompile_headers(NorthstarDLL PRIVATE pch.h)
Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/client/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,5 +502,5 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", AudioHooks, ConVar, (CModule module))
AUTOHOOK_DISPATCH()

Cvar_ns_print_played_sounds = new ConVar("ns_print_played_sounds", "0", FCVAR_NONE, "");
MilesStopAll = module.Offset(0x580850).As<MilesStopAll_Type>();
MilesStopAll = module.Offset(0x580850).RCast<MilesStopAll_Type>();
}
3 changes: 2 additions & 1 deletion NorthstarDLL/client/chatcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ void ConCommand_log(const CCommand& args)

ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", ClientChatCommand, ConCommand, (CModule module))
{
ClientSayText = module.Offset(0x54780).As<void(__fastcall*)(void* a1, const char* message, uint64_t isIngameChat, bool isTeamChat)>();
ClientSayText =
module.Offset(0x54780).RCast<void(__fastcall*)(void* a1, const char* message, uint64_t isIngameChat, bool isTeamChat)>();
RegisterConCommand("say", ConCommand_say, "Enters a message in public chat", FCVAR_CLIENTDLL);
RegisterConCommand("say_team", ConCommand_say_team, "Enters a message in team chat", FCVAR_CLIENTDLL);
RegisterConCommand("log", ConCommand_log, "Log a message to the local chat window", FCVAR_CLIENTDLL);
Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/client/clientauthhooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", ClientAuthHooks, ConVar, (CModule modu
{
AUTOHOOK_DISPATCH()

p3PToken = module.Offset(0x13979D80).As<char*>();
p3PToken = module.Offset(0x13979D80).RCast<char*>();

// this cvar will save to cfg once initially agreed with
Cvar_ns_has_agreed_to_send_token = new ConVar(
Expand Down
8 changes: 4 additions & 4 deletions NorthstarDLL/client/debugoverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", DebugOverlay, ConVar, (CModule module)
{
AUTOHOOK_DISPATCH()

RenderLine = module.Offset(0x192A70).As<RenderLineType>();
RenderBox = module.Offset(0x192520).As<RenderBoxType>();
RenderWireframeBox = module.Offset(0x193DA0).As<RenderBoxType>();
RenderLine = module.Offset(0x192A70).RCast<RenderLineType>();
RenderBox = module.Offset(0x192520).RCast<RenderBoxType>();
RenderWireframeBox = module.Offset(0x193DA0).RCast<RenderBoxType>();
sEngineModule = reinterpret_cast<HMODULE>(module.m_nAddress);

// not in g_pCVar->FindVar by this point for whatever reason, so have to get from memory
ConVar* Cvar_enable_debug_overlays = module.Offset(0x10DB0990).As<ConVar*>();
ConVar* Cvar_enable_debug_overlays = module.Offset(0x10DB0990).RCast<ConVar*>();
Cvar_enable_debug_overlays->SetValue(false);
Cvar_enable_debug_overlays->m_pszDefaultValue = (char*)"0";
Cvar_enable_debug_overlays->AddFlags(FCVAR_CHEAT);
Expand Down
10 changes: 5 additions & 5 deletions NorthstarDLL/client/localchatwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,10 @@ void LocalChatWriter::InsertDefaultFade()

ON_DLL_LOAD_CLIENT("client.dll", LocalChatWriter, (CModule module))
{
gGameSettings = module.Offset(0x11BAA48).As<CGameSettings**>();
gChatFadeLength = module.Offset(0x11BAB78).As<CGameFloatVar**>();
gChatFadeSustain = module.Offset(0x11BAC08).As<CGameFloatVar**>();
CHudChat::allHuds = module.Offset(0x11BA9E8).As<CHudChat**>();
gGameSettings = module.Offset(0x11BAA48).RCast<CGameSettings**>();
gChatFadeLength = module.Offset(0x11BAB78).RCast<CGameFloatVar**>();
gChatFadeSustain = module.Offset(0x11BAC08).RCast<CGameFloatVar**>();
CHudChat::allHuds = module.Offset(0x11BA9E8).RCast<CHudChat**>();

ConvertANSIToUnicode = module.Offset(0x7339A0).As<ConvertANSIToUnicodeType>();
ConvertANSIToUnicode = module.Offset(0x7339A0).RCast<ConvertANSIToUnicodeType>();
}
6 changes: 3 additions & 3 deletions NorthstarDLL/client/r2client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace R2

ON_DLL_LOAD("engine.dll", R2EngineClient, (CModule module))
{
g_pLocalPlayerUserID = module.Offset(0x13F8E688).As<char*>();
g_pLocalPlayerOriginToken = module.Offset(0x13979C80).As<char*>();
g_pLocalPlayerUserID = module.Offset(0x13F8E688).RCast<char*>();
g_pLocalPlayerOriginToken = module.Offset(0x13979C80).RCast<char*>();

GetBaseLocalClient = module.Offset(0x78200).As<GetBaseLocalClientType>();
GetBaseLocalClient = module.Offset(0x78200).RCast<GetBaseLocalClientType>();
}
4 changes: 2 additions & 2 deletions NorthstarDLL/core/convar/concommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ void RegisterConCommand(

ON_DLL_LOAD("engine.dll", ConCommand, (CModule module))
{
ConCommandConstructor = module.Offset(0x415F60).As<ConCommandConstructorType>();
ConCommandConstructor = module.Offset(0x415F60).RCast<ConCommandConstructorType>();
AddMiscConCommands();

g_pPluginCommunicationhandler->m_sEngineData.ConCommandConstructor = ConCommandConstructor;
g_pPluginCommunicationhandler->m_sEngineData.ConCommandConstructor = (void*)ConCommandConstructor;
}
16 changes: 8 additions & 8 deletions NorthstarDLL/core/convar/convar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ void* g_pIConVar_Vtable = nullptr;
//-----------------------------------------------------------------------------
ON_DLL_LOAD("engine.dll", ConVar, (CModule module))
{
conVarMalloc = module.Offset(0x415C20).As<ConVarMallocType>();
conVarRegister = module.Offset(0x417230).As<ConVarRegisterType>();
conVarMalloc = module.Offset(0x415C20).RCast<ConVarMallocType>();
conVarRegister = module.Offset(0x417230).RCast<ConVarRegisterType>();

g_pConVar_Vtable = module.Offset(0x67FD28);
g_pIConVar_Vtable = module.Offset(0x67FDC8);

R2::g_pCVarInterface = new SourceInterface<CCvar>("vstdlib.dll", "VEngineCvar007");
R2::g_pCVar = *R2::g_pCVarInterface;

g_pPluginCommunicationhandler->m_sEngineData.conVarMalloc = conVarMalloc;
g_pPluginCommunicationhandler->m_sEngineData.conVarRegister = conVarRegister;
g_pPluginCommunicationhandler->m_sEngineData.ConVar_Vtable = g_pConVar_Vtable;
g_pPluginCommunicationhandler->m_sEngineData.IConVar_Vtable = g_pIConVar_Vtable;
g_pPluginCommunicationhandler->m_sEngineData.conVarMalloc = (void*)conVarMalloc;
g_pPluginCommunicationhandler->m_sEngineData.conVarRegister = (void*)conVarRegister;
g_pPluginCommunicationhandler->m_sEngineData.ConVar_Vtable = (void*)g_pConVar_Vtable;
g_pPluginCommunicationhandler->m_sEngineData.IConVar_Vtable = (void*)g_pIConVar_Vtable;
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -80,7 +80,7 @@ ConVar::ConVar(
this->m_ConCommandBase.s_pConCommandBases = (ConCommandBase*)g_pIConVar_Vtable;

conVarMalloc(&this->m_pMalloc, 0, 0); // Allocate new memory for ConVar.
conVarRegister(this, pszName, pszDefaultValue, nFlags, pszHelpString, bMin, fMin, bMax, fMax, pCallback);
conVarRegister(this, pszName, pszDefaultValue, nFlags, pszHelpString, bMin, fMin, bMax, fMax, (void*)pCallback);
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -321,7 +321,7 @@ void ConVar::SetValue(const char* pszValue)
{
// Not a color, do the standard thing
float flNewValue = (float)atof(pszValue);
if (!isfinite(flNewValue))
if (!std::isfinite(flNewValue))
{
spdlog::warn("Warning: ConVar '{}' = '{}' is infinite, clamping value.\n", GetBaseName(), pszValue);
flNewValue = FLT_MAX;
Expand Down
8 changes: 3 additions & 5 deletions NorthstarDLL/core/filesystem/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ void SetNewModSearchPaths(Mod* mod)
{
if ((fs::absolute(mod->m_ModDirectory) / MOD_OVERRIDE_DIR).string().compare(sCurrentModPath))
{
NS::log::fs->info("Changing mod search path from {} to {}", sCurrentModPath, mod->m_ModDirectory.string());

AddSearchPath(
&*(*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();
Expand Down Expand Up @@ -179,7 +177,7 @@ ON_DLL_LOAD("filesystem_stdio.dll", Filesystem, (CModule module))

R2::g_pFilesystem = new SourceInterface<IFileSystem>("filesystem_stdio.dll", "VFileSystem017");

AddSearchPathHook.Dispatch((*g_pFilesystem)->m_vtable->AddSearchPath);
ReadFromCacheHook.Dispatch((*g_pFilesystem)->m_vtable->ReadFromCache);
MountVPKHook.Dispatch((*g_pFilesystem)->m_vtable->MountVPK);
AddSearchPathHook.Dispatch((LPVOID)(*g_pFilesystem)->m_vtable->AddSearchPath);
ReadFromCacheHook.Dispatch((LPVOID)(*g_pFilesystem)->m_vtable->ReadFromCache);
MountVPKHook.Dispatch((LPVOID)(*g_pFilesystem)->m_vtable->MountVPK);
}
14 changes: 1 addition & 13 deletions NorthstarDLL/core/filesystem/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,7 @@ OFFSET_STRUCT(VPKFileEntry)
// clang-format on
#pragma pack(pop)

#pragma pack(push, 1)
// clang-format off
struct VPKData
{
STRUCT_SIZE(0x50);
FIELDS(0x0,
char* directory;
char* filename;
char* extension;
)
};
// clang-format on
#pragma pack(pop)
struct VPKData;

enum SearchPathAdd_t
{
Expand Down
10 changes: 5 additions & 5 deletions NorthstarDLL/core/filesystem/rpakfilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ ON_DLL_LOAD("engine.dll", RpakFilesystem, (CModule module))

g_pPakLoadManager = new PakLoadManager;

g_pakLoadApi = module.Offset(0x5BED78).Deref().As<PakLoadFuncs*>();
pUnknownPakLoadSingleton = module.Offset(0x7C5E20).As<void**>();
g_pakLoadApi = module.Offset(0x5BED78).Deref().RCast<PakLoadFuncs*>();
pUnknownPakLoadSingleton = module.Offset(0x7C5E20).RCast<void**>();

LoadPakAsyncHook.Dispatch(g_pakLoadApi->LoadPakAsync);
UnloadPakHook.Dispatch(g_pakLoadApi->UnloadPak);
ReadFileAsyncHook.Dispatch(g_pakLoadApi->ReadFileAsync);
LoadPakAsyncHook.Dispatch((LPVOID*)g_pakLoadApi->LoadPakAsync);
UnloadPakHook.Dispatch((LPVOID*)g_pakLoadApi->UnloadPak);
ReadFileAsyncHook.Dispatch((LPVOID*)g_pakLoadApi->ReadFileAsync);
}
10 changes: 5 additions & 5 deletions NorthstarDLL/core/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void MakeHook(LPVOID pTarget, LPVOID pDetour, void* ppOriginal, const char* pFun
spdlog::error("MH_CreateHook failed for function {}", pStrippedFuncName);
}

AUTOHOOK_ABSOLUTEADDR(_GetCommandLineA, GetCommandLineA, LPSTR, WINAPI, ())
AUTOHOOK_ABSOLUTEADDR(_GetCommandLineA, (LPVOID)GetCommandLineA, LPSTR, WINAPI, ())
{
static char* cmdlineModified;
static char* cmdlineOrg;
Expand Down Expand Up @@ -386,7 +386,7 @@ void CallAllPendingDLLLoadCallbacks()
}

// clang-format off
AUTOHOOK_ABSOLUTEADDR(_LoadLibraryExA, LoadLibraryExA,
AUTOHOOK_ABSOLUTEADDR(_LoadLibraryExA, (LPVOID)LoadLibraryExA,
HMODULE, WINAPI, (LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags))
// clang-format on
{
Expand Down Expand Up @@ -415,7 +415,7 @@ HMODULE, WINAPI, (LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags))
}

// clang-format off
AUTOHOOK_ABSOLUTEADDR(_LoadLibraryA, LoadLibraryA,
AUTOHOOK_ABSOLUTEADDR(_LoadLibraryA, (LPVOID)LoadLibraryA,
HMODULE, WINAPI, (LPCSTR lpLibFileName))
// clang-format on
{
Expand All @@ -428,7 +428,7 @@ HMODULE, WINAPI, (LPCSTR lpLibFileName))
}

// clang-format off
AUTOHOOK_ABSOLUTEADDR(_LoadLibraryExW, LoadLibraryExW,
AUTOHOOK_ABSOLUTEADDR(_LoadLibraryExW, (LPVOID)LoadLibraryExW,
HMODULE, WINAPI, (LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags))
// clang-format on
{
Expand All @@ -441,7 +441,7 @@ HMODULE, WINAPI, (LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags))
}

// clang-format off
AUTOHOOK_ABSOLUTEADDR(_LoadLibraryW, LoadLibraryW,
AUTOHOOK_ABSOLUTEADDR(_LoadLibraryW, (LPVOID)LoadLibraryW,
HMODULE, WINAPI, (LPCWSTR lpLibFileName))
// clang-format on
{
Expand Down
Loading

0 comments on commit b7260df

Please sign in to comment.