aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2022-01-31 00:19:36 +0000
committerGitHub <noreply@github.com>2022-01-31 00:19:36 +0000
commit186a4e2dbcb8a7c2f1a24f6657f0c5daa00a7fd5 (patch)
treeb5d45cea23a50f0ff453684cb20d5fed5fef8bf1
parenta589bb0082cbae6d326644292179c9427e76e795 (diff)
parent033c8989c28384529fef72e0e8e17e824ceac8d4 (diff)
downloadNorthstarLauncher-186a4e2dbcb8a7c2f1a24f6657f0c5daa00a7fd5.tar.gz
NorthstarLauncher-186a4e2dbcb8a7c2f1a24f6657f0c5daa00a7fd5.zip
Merge pull request #61 from emma-miler/cla
Added command line option for custom northstar directory
-rw-r--r--NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj2
-rw-r--r--NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters6
-rw-r--r--NorthstarDedicatedTest/bansystem.cpp9
-rw-r--r--NorthstarDedicatedTest/configurables.cpp32
-rw-r--r--NorthstarDedicatedTest/configurables.h7
-rw-r--r--NorthstarDedicatedTest/dllmain.cpp6
-rw-r--r--NorthstarDedicatedTest/filesystem.cpp4
-rw-r--r--NorthstarDedicatedTest/keyvalues.cpp2
-rw-r--r--NorthstarDedicatedTest/logging.cpp5
-rw-r--r--NorthstarDedicatedTest/modmanager.cpp22
-rw-r--r--NorthstarDedicatedTest/modmanager.h7
-rw-r--r--NorthstarDedicatedTest/pdef.h2
-rw-r--r--NorthstarDedicatedTest/scriptsrson.h2
-rw-r--r--NorthstarDedicatedTest/serverauthentication.cpp7
14 files changed, 89 insertions, 24 deletions
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
index a066cfaa..9fa7e9df 100644
--- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
+++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
@@ -114,6 +114,7 @@
<ClInclude Include="chatcommand.h" />
<ClInclude Include="clientauthhooks.h" />
<ClInclude Include="concommand.h" />
+ <ClInclude Include="configurables.h" />
<ClInclude Include="context.h" />
<ClInclude Include="convar.h" />
<ClInclude Include="dedicated.h" />
@@ -556,6 +557,7 @@
<ClCompile Include="chatcommand.cpp" />
<ClCompile Include="clientauthhooks.cpp" />
<ClCompile Include="concommand.cpp" />
+ <ClCompile Include="configurables.cpp" />
<ClCompile Include="context.cpp" />
<ClCompile Include="convar.cpp" />
<ClCompile Include="dedicated.cpp" />
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
index 8b18150a..67679462 100644
--- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
+++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
@@ -1446,6 +1446,9 @@
<ClInclude Include="bitbuf.h">
<Filter>Header Files\Shared</Filter>
</ClInclude>
+ <ClInclude Include="configurables.h">
+ <Filter>Header Files\Client</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
@@ -1577,6 +1580,9 @@
<ClCompile Include="buildainfile.cpp">
<Filter>Source Files\Server</Filter>
</ClCompile>
+ <ClCompile Include="configurables.cpp">
+ <Filter>Source Files\Client</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<MASM Include="audio_asm.asm">
diff --git a/NorthstarDedicatedTest/bansystem.cpp b/NorthstarDedicatedTest/bansystem.cpp
index a4d994d0..b9e3fd33 100644
--- a/NorthstarDedicatedTest/bansystem.cpp
+++ b/NorthstarDedicatedTest/bansystem.cpp
@@ -5,14 +5,15 @@
#include "concommand.h"
#include "miscserverscript.h"
#include <filesystem>
+#include "configurables.h"
-const char* BANLIST_PATH = "R2Northstar/banlist.txt";
+const char* BANLIST_PATH_SUFFIX = "/banlist.txt";
ServerBanSystem* g_ServerBanSystem;
void ServerBanSystem::OpenBanlist()
{
- std::ifstream enabledModsStream(BANLIST_PATH);
+ std::ifstream enabledModsStream(GetNorthstarPrefix() + "/banlist.txt");
std::stringstream enabledModsStringStream;
if (!enabledModsStream.fail())
@@ -25,7 +26,7 @@ void ServerBanSystem::OpenBanlist()
}
// open write stream for banlist
- m_sBanlistStream.open(BANLIST_PATH, std::ofstream::out | std::ofstream::binary | std::ofstream::app);
+ m_sBanlistStream.open(GetNorthstarPrefix() + "/banlist.txt", std::ofstream::out | std::ofstream::binary | std::ofstream::app);
}
void ServerBanSystem::ClearBanlist()
@@ -34,7 +35,7 @@ void ServerBanSystem::ClearBanlist()
// reopen the file, don't provide std::ofstream::app so it clears on open
m_sBanlistStream.close();
- m_sBanlistStream.open(BANLIST_PATH, std::ofstream::out | std::ofstream::binary);
+ m_sBanlistStream.open(GetNorthstarPrefix() + "/banlist.txt", std::ofstream::out | std::ofstream::binary);
}
void ServerBanSystem::BanUID(uint64_t uid)
diff --git a/NorthstarDedicatedTest/configurables.cpp b/NorthstarDedicatedTest/configurables.cpp
new file mode 100644
index 00000000..7096b2e9
--- /dev/null
+++ b/NorthstarDedicatedTest/configurables.cpp
@@ -0,0 +1,32 @@
+#include <string>
+#include "pch.h"
+#include "configurables.h"
+
+std::string GetNorthstarPrefix() {
+ return NORTHSTAR_FOLDER_PREFIX;
+}
+
+void parseConfigurables() {
+ char* clachar = strstr(GetCommandLineA(), "-profile=");
+ if (clachar) {
+ std::string cla = std::string(clachar);
+ if (strncmp(cla.substr(9, 1).c_str(), "\"", 1)) {
+ int space = cla.find(" ");
+ std::string dirname = cla.substr(9, space - 9);
+ spdlog::info("Found profile in command line arguments: " + dirname);
+ NORTHSTAR_FOLDER_PREFIX = dirname;
+ }
+ else {
+ std::string quote = "\"";
+ int quote1 = cla.find(quote);
+ int quote2 = (cla.substr(quote1 + 1)).find(quote);
+ std::string dirname = cla.substr(quote1 + 1, quote2);
+ spdlog::info("Found profile in command line arguments: " + dirname);
+ NORTHSTAR_FOLDER_PREFIX = dirname;
+ }
+ }
+ else {
+ spdlog::info("Didnt' find profile in command line arguments. Using default: R2Northstar");
+ NORTHSTAR_FOLDER_PREFIX = "R2Northstar";
+ }
+} \ No newline at end of file
diff --git a/NorthstarDedicatedTest/configurables.h b/NorthstarDedicatedTest/configurables.h
new file mode 100644
index 00000000..cc98e15e
--- /dev/null
+++ b/NorthstarDedicatedTest/configurables.h
@@ -0,0 +1,7 @@
+#pragma once
+#include <string>
+
+static std::string NORTHSTAR_FOLDER_PREFIX;
+
+std::string GetNorthstarPrefix();
+void parseConfigurables();
diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp
index 2b5a65fa..0ada0531 100644
--- a/NorthstarDedicatedTest/dllmain.cpp
+++ b/NorthstarDedicatedTest/dllmain.cpp
@@ -33,6 +33,10 @@
#include "languagehooks.h"
#include "audio.h"
#include "buildainfile.h"
+#include "configurables.h"
+#include <string.h>
+#include "pch.h"
+
bool initialised = false;
@@ -75,6 +79,8 @@ bool InitialiseNorthstar()
initialised = true;
+ parseConfigurables();
+
SetEnvironmentVariableA("OPENSSL_ia32cap", "~0x200000200000000");
curl_global_init_mem(CURL_GLOBAL_DEFAULT, _malloc_base, _free_base, _realloc_base, _strdup_base, _calloc_base);
diff --git a/NorthstarDedicatedTest/filesystem.cpp b/NorthstarDedicatedTest/filesystem.cpp
index 1fe3ec9d..a8382db3 100644
--- a/NorthstarDedicatedTest/filesystem.cpp
+++ b/NorthstarDedicatedTest/filesystem.cpp
@@ -90,7 +90,7 @@ void SetNewModSearchPaths(Mod* mod)
}
}
else // push compiled to head
- addSearchPathOriginal(&*(*g_Filesystem), fs::absolute(COMPILED_ASSETS_PATH).string().c_str(), "GAME", PATH_ADD_TO_HEAD);
+ addSearchPathOriginal(&*(*g_Filesystem), fs::absolute(GetCompiledAssetsPath()).string().c_str(), "GAME", PATH_ADD_TO_HEAD);
}
@@ -148,7 +148,7 @@ void AddSearchPathHook(IFileSystem* fileSystem, const char* pPath, const char* p
if (!strcmp(pathID, "GAME") && currentModPath.compare(pPath) && addType == PATH_ADD_TO_HEAD)
{
addSearchPathOriginal(fileSystem, currentModPath.c_str(), "GAME", PATH_ADD_TO_HEAD);
- addSearchPathOriginal(fileSystem, COMPILED_ASSETS_PATH.string().c_str(), "GAME", PATH_ADD_TO_HEAD);
+ addSearchPathOriginal(fileSystem, GetCompiledAssetsPath().string().c_str(), "GAME", PATH_ADD_TO_HEAD);
}
}
diff --git a/NorthstarDedicatedTest/keyvalues.cpp b/NorthstarDedicatedTest/keyvalues.cpp
index b14ecf42..c1fefdd7 100644
--- a/NorthstarDedicatedTest/keyvalues.cpp
+++ b/NorthstarDedicatedTest/keyvalues.cpp
@@ -36,7 +36,7 @@ void ModManager::TryBuildKeyValues(const char* filename)
spdlog::info("Building KeyValues for file {}", filename);
std::string normalisedPath = fs::path(filename).lexically_normal().string();
- fs::path compiledPath = COMPILED_ASSETS_PATH / filename;
+ fs::path compiledPath = GetCompiledAssetsPath() / filename;
fs::path compiledDir = compiledPath.parent_path();
fs::create_directories(compiledDir);
diff --git a/NorthstarDedicatedTest/logging.cpp b/NorthstarDedicatedTest/logging.cpp
index 9fc39cde..136fdf9b 100644
--- a/NorthstarDedicatedTest/logging.cpp
+++ b/NorthstarDedicatedTest/logging.cpp
@@ -9,6 +9,7 @@
#include <sstream>
#include <Psapi.h>
#include <minidumpapiset.h>
+#include "configurables.h"
// This needs to be called after hooks are loaded so we can access the command line args
@@ -25,7 +26,7 @@ void CreateLogFiles()
tm currentTime = *std::localtime(&time);
std::stringstream stream;
- stream << std::put_time(&currentTime, "R2Northstar/logs/nslog%Y-%m-%d %H-%M-%S.txt");
+ stream << std::put_time(&currentTime, (GetNorthstarPrefix() + "/logs/nslog%Y-%m-%d %H-%M-%S.txt").c_str());
spdlog::default_logger()->sinks().push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(stream.str(), false));
spdlog::flush_on(spdlog::level::info);
}
@@ -175,7 +176,7 @@ long __stdcall ExceptionFilter(EXCEPTION_POINTERS* exceptionInfo)
time_t time = std::time(nullptr);
tm currentTime = *std::localtime(&time);
std::stringstream stream;
- stream << std::put_time(&currentTime, "R2Northstar/logs/nsdump%Y-%m-%d %H-%M-%S.dmp");
+ stream << std::put_time(&currentTime, (GetNorthstarPrefix() + "/logs/nsdump%Y-%m-%d %H-%M-%S.dmp").c_str());
auto hMinidumpFile = CreateFileA(stream.str().c_str(), GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (hMinidumpFile)
diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp
index 2e287dcd..0134057e 100644
--- a/NorthstarDedicatedTest/modmanager.cpp
+++ b/NorthstarDedicatedTest/modmanager.cpp
@@ -14,6 +14,7 @@
#include <sstream>
#include <vector>
#include "filesystem.h"
+#include "configurables.h"
ModManager* g_ModManager;
@@ -201,11 +202,11 @@ void ModManager::LoadMods()
std::vector<fs::path> modDirs;
// ensure dirs exist
- fs::remove_all(COMPILED_ASSETS_PATH);
- fs::create_directories(MOD_FOLDER_PATH);
+ fs::remove_all(GetCompiledAssetsPath());
+ fs::create_directories(GetModFolderPath());
// read enabled mods cfg
- std::ifstream enabledModsStream("R2Northstar/enabledmods.json");
+ std::ifstream enabledModsStream(GetNorthstarPrefix() + "/enabledmods.json");
std::stringstream enabledModsStringStream;
if (!enabledModsStream.fail())
@@ -220,7 +221,7 @@ void ModManager::LoadMods()
}
// get mod directories
- for (fs::directory_entry dir : fs::directory_iterator(MOD_FOLDER_PATH))
+ for (fs::directory_entry dir : fs::directory_iterator(GetModFolderPath()))
if (fs::exists(dir.path() / "mod.json"))
modDirs.push_back(dir.path());
@@ -405,7 +406,7 @@ void ModManager::UnloadMods()
{
// clean up stuff from mods before we unload
m_modFiles.clear();
- fs::remove_all(COMPILED_ASSETS_PATH);
+ fs::remove_all(GetCompiledAssetsPath());
g_CustomAudioManager.ClearAudioOverrides();
@@ -416,7 +417,7 @@ void ModManager::UnloadMods()
{
// remove all built kvs
for (std::pair<size_t, std::string> kvPaths : mod.KeyValues)
- fs::remove(COMPILED_ASSETS_PATH / fs::path(kvPaths.second).lexically_relative(mod.ModDirectory));
+ fs::remove(GetCompiledAssetsPath() / fs::path(kvPaths.second).lexically_relative(mod.ModDirectory));
mod.KeyValues.clear();
@@ -429,7 +430,7 @@ void ModManager::UnloadMods()
m_enabledModsCfg[mod.Name.c_str()].SetBool(mod.Enabled);
}
- std::ofstream writeStream("R2Northstar/enabledmods.json");
+ std::ofstream writeStream(GetNorthstarPrefix() + "/enabledmods.json");
rapidjson::OStreamWrapper writeStreamWrapper(writeStream);
rapidjson::Writer<rapidjson::OStreamWrapper> writer(writeStreamWrapper);
m_enabledModsCfg.Accept(writer);
@@ -473,4 +474,11 @@ void InitialiseModManager(HMODULE baseAddress)
g_ModManager = new ModManager;
RegisterConCommand("reload_mods", ReloadModsCommand, "idk", FCVAR_NONE);
+}
+
+fs::path GetModFolderPath() {
+ return fs::path(GetNorthstarPrefix() + MOD_FOLDER_SUFFIX);
+}
+fs::path GetCompiledAssetsPath() {
+ return fs::path(GetNorthstarPrefix() + COMPILED_ASSETS_SUFFIX);
} \ No newline at end of file
diff --git a/NorthstarDedicatedTest/modmanager.h b/NorthstarDedicatedTest/modmanager.h
index 20cb0a42..445d757e 100644
--- a/NorthstarDedicatedTest/modmanager.h
+++ b/NorthstarDedicatedTest/modmanager.h
@@ -8,10 +8,9 @@
namespace fs = std::filesystem;
-const fs::path MOD_FOLDER_PATH = "R2Northstar/mods";
+const std::string MOD_FOLDER_SUFFIX = "/mods";
const fs::path MOD_OVERRIDE_DIR = "mod";
-
-const fs::path COMPILED_ASSETS_PATH = "R2Northstar/runtime/compiled";
+const std::string COMPILED_ASSETS_SUFFIX = "/runtime/compiled";
struct ModConVar
{
@@ -124,5 +123,7 @@ public:
};
void InitialiseModManager(HMODULE baseAddress);
+fs::path GetModFolderPath();
+fs::path GetCompiledAssetsPath();
extern ModManager* g_ModManager; \ No newline at end of file
diff --git a/NorthstarDedicatedTest/pdef.h b/NorthstarDedicatedTest/pdef.h
index eb5f668b..ad85e372 100644
--- a/NorthstarDedicatedTest/pdef.h
+++ b/NorthstarDedicatedTest/pdef.h
@@ -1,4 +1,4 @@
#pragma once
-const fs::path MOD_PDEF_PATH = COMPILED_ASSETS_PATH / "cfg/server/persistent_player_data_version_231.pdef";
+const fs::path MOD_PDEF_PATH = GetCompiledAssetsPath() / "cfg/server/persistent_player_data_version_231.pdef";
const char* VPK_PDEF_PATH = "cfg/server/persistent_player_data_version_231.pdef"; \ No newline at end of file
diff --git a/NorthstarDedicatedTest/scriptsrson.h b/NorthstarDedicatedTest/scriptsrson.h
index 16e91fb8..30ab1304 100644
--- a/NorthstarDedicatedTest/scriptsrson.h
+++ b/NorthstarDedicatedTest/scriptsrson.h
@@ -1,4 +1,4 @@
#pragma once
-const fs::path MOD_SCRIPTS_RSON_PATH = COMPILED_ASSETS_PATH / "scripts/vscripts/scripts.rson";
+const fs::path MOD_SCRIPTS_RSON_PATH = GetCompiledAssetsPath() / "scripts/vscripts/scripts.rson";
const char* VPK_SCRIPTS_RSON_PATH = "scripts\\vscripts\\scripts.rson"; \ No newline at end of file
diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp
index d6a74008..5235761a 100644
--- a/NorthstarDedicatedTest/serverauthentication.cpp
+++ b/NorthstarDedicatedTest/serverauthentication.cpp
@@ -12,6 +12,7 @@
#include <fstream>
#include <filesystem>
#include <thread>
+#include "configurables.h"
const char* AUTHSERVER_VERIFY_STRING = "I am a northstar server!";
@@ -143,7 +144,7 @@ bool ServerAuthenticationManager::AuthenticatePlayer(void* player, int64_t uid,
// reset from disk if we're doing that
if (m_bForceReadLocalPlayerPersistenceFromDisk && !strcmp(authData.uid, g_LocalPlayerUserID))
{
- std::fstream pdataStream("R2Northstar/placeholder_playerdata.pdata", std::ios_base::in);
+ std::fstream pdataStream(GetNorthstarPrefix() + "/placeholder_playerdata.pdata", std::ios_base::in);
if (!pdataStream.fail())
{
@@ -183,13 +184,13 @@ bool ServerAuthenticationManager::AuthenticatePlayer(void* player, int64_t uid,
strcpy((char*)player + 0xF500, strUid.c_str());
// try reading pdata file for player
- std::string pdataPath = "R2Northstar/playerdata_";
+ std::string pdataPath = GetNorthstarPrefix() + "/playerdata_";
pdataPath += strUid;
pdataPath += ".pdata";
std::fstream pdataStream(pdataPath, std::ios_base::in);
if (pdataStream.fail()) // file doesn't exist, use placeholder
- pdataStream = std::fstream("R2Northstar/placeholder_playerdata.pdata");
+ pdataStream = std::fstream(GetNorthstarPrefix() + "/placeholder_playerdata.pdata");
// get file length
pdataStream.seekg(0, pdataStream.end);