diff options
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r-- | NorthstarDedicatedTest/filesystem.cpp | 3 | ||||
-rw-r--r-- | NorthstarDedicatedTest/keyvalues.cpp | 26 | ||||
-rw-r--r-- | NorthstarDedicatedTest/masterserver.cpp | 18 | ||||
-rw-r--r-- | NorthstarDedicatedTest/misccommands.cpp | 2 | ||||
-rw-r--r-- | NorthstarDedicatedTest/misccommands.h | 1 | ||||
-rw-r--r-- | NorthstarDedicatedTest/modmanager.cpp | 36 | ||||
-rw-r--r-- | NorthstarDedicatedTest/modmanager.h | 4 | ||||
-rw-r--r-- | NorthstarDedicatedTest/pch.h | 3 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptmodmenu.cpp | 20 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptsrson.cpp | 4 |
10 files changed, 69 insertions, 48 deletions
diff --git a/NorthstarDedicatedTest/filesystem.cpp b/NorthstarDedicatedTest/filesystem.cpp index 127a9484..89eb9423 100644 --- a/NorthstarDedicatedTest/filesystem.cpp +++ b/NorthstarDedicatedTest/filesystem.cpp @@ -174,7 +174,8 @@ VPKData* MountVPKHook(IFileSystem* fileSystem, const char* vpkPath) for (std::string& vpkPath : mod.Vpks) { - spdlog::info(vpkPath); + // note: could potentially not mount these if they're already mounted? + spdlog::info("MountVPK {}", vpkPath); spdlog::info((void*)mountVPK(fileSystem, vpkPath.c_str())); } } diff --git a/NorthstarDedicatedTest/keyvalues.cpp b/NorthstarDedicatedTest/keyvalues.cpp index 7afad20c..cada5cbe 100644 --- a/NorthstarDedicatedTest/keyvalues.cpp +++ b/NorthstarDedicatedTest/keyvalues.cpp @@ -56,25 +56,23 @@ void ModManager::TryBuildKeyValues(const char* filename) continue; size_t fileHash = std::hash<std::string>{}(normalisedPath); - for (int j = 0; j < m_loadedMods[i].KeyValuesHash.size(); j++) + auto modKv = m_loadedMods[i].KeyValues.find(fileHash); + if (modKv != m_loadedMods[i].KeyValues.end()) { - if (fileHash == m_loadedMods[i].KeyValuesHash[j]) - { - // should result in smth along the lines of #include "mod_patch_5_mp_weapon_car.txt" + // should result in smth along the lines of #include "mod_patch_5_mp_weapon_car.txt" - std::string patchFilePath = "mod_patch_"; - patchFilePath += std::to_string(patchNum++); - patchFilePath += "_"; - patchFilePath += kvPath.filename().string(); + std::string patchFilePath = "mod_patch_"; + patchFilePath += std::to_string(patchNum++); + patchFilePath += "_"; + patchFilePath += kvPath.filename().string(); - newKvs += "#base \""; - newKvs += patchFilePath; - newKvs += "\"\n"; + newKvs += "#base \""; + newKvs += patchFilePath; + newKvs += "\"\n"; - fs::remove(compiledDir / patchFilePath); + fs::remove(compiledDir / patchFilePath); - fs::copy_file(m_loadedMods[i].ModDirectory / "keyvalues" / filename, compiledDir / patchFilePath); - } + fs::copy_file(m_loadedMods[i].ModDirectory / "keyvalues" / filename, compiledDir / patchFilePath); } } diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp index 495f2044..80d606eb 100644 --- a/NorthstarDedicatedTest/masterserver.cpp +++ b/NorthstarDedicatedTest/masterserver.cpp @@ -11,6 +11,7 @@ #include "rapidjson/writer.h" #include "rapidjson/error/en.h" #include "modmanager.h" +#include "misccommands.h" ConVar* Cvar_ns_masterserver_hostname; ConVar* Cvar_ns_masterserver_port; @@ -414,14 +415,15 @@ void MasterServerManager::AddSelfToServerList(int port, int authPort, char* name modinfoDoc.AddMember("Mods", rapidjson::Value(rapidjson::kArrayType), modinfoDoc.GetAllocator()); int currentModIndex = 0; - for (Mod mod : g_ModManager->m_loadedMods) + for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.RequiredOnClient) continue; modinfoDoc["Mods"].PushBack(rapidjson::Value(rapidjson::kObjectType), modinfoDoc.GetAllocator()); - modinfoDoc["Mods"][currentModIndex].AddMember("Name", rapidjson::StringRef(mod.Name.c_str()), modinfoDoc.GetAllocator()); - modinfoDoc["Mods"][currentModIndex].AddMember("Version", rapidjson::StringRef(mod.Version.c_str()), modinfoDoc.GetAllocator()); + modinfoDoc["Mods"][currentModIndex].AddMember("Name", rapidjson::StringRef(&mod.Name[0]), modinfoDoc.GetAllocator()); + modinfoDoc["Mods"][currentModIndex].AddMember("Version", rapidjson::StringRef(&mod.Version[0]), modinfoDoc.GetAllocator()); + modinfoDoc["Mods"][currentModIndex].AddMember("Pdiff", rapidjson::StringRef(&mod.Pdiff[0]), modinfoDoc.GetAllocator()); currentModIndex++; } @@ -619,15 +621,19 @@ void CHostState__State_NewGameHook(CHostState* hostState) Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec autoexec_ns_server", cmd_source_t::kCommandSrcCode); Cbuf_Execute(); + // need to do this to ensure + if (g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame) + SetCurrentPlaylist("tdm"); + + CHostState__State_NewGame(hostState); + int maxPlayers = 6; char* maxPlayersVar = GetCurrentPlaylistVar("max_players", true); if (maxPlayersVar) // GetCurrentPlaylistVar can return null so protect against this - std::stoi(maxPlayersVar); + maxPlayers = std::stoi(maxPlayersVar); g_MasterServerManager->AddSelfToServerList(Cvar_hostport->m_nValue, Cvar_ns_player_auth_port->m_nValue, Cvar_ns_server_name->m_pszString, Cvar_ns_server_desc->m_pszString, hostState->m_levelName, (char*)GetCurrentPlaylistName(), maxPlayers, Cvar_ns_server_password->m_pszString); g_ServerAuthenticationManager->StartPlayerAuthServer(); - - CHostState__State_NewGame(hostState); g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame = false; } diff --git a/NorthstarDedicatedTest/misccommands.cpp b/NorthstarDedicatedTest/misccommands.cpp index 27dbbbc4..cc6f816d 100644 --- a/NorthstarDedicatedTest/misccommands.cpp +++ b/NorthstarDedicatedTest/misccommands.cpp @@ -28,6 +28,8 @@ void EndSelfAuthAndLeaveToLobbyCommand(const CCommand& arg) Cbuf_Execute(); g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame = true; + // this won't set playlist correctly on remote clients, don't think they can set playlist until they've left which sorta fucks things + // should maybe set this in HostState_NewGame? SetCurrentPlaylist("tdm"); strcpy(g_pHostState->m_levelName, "mp_lobby"); g_pHostState->m_iNextState = HS_NEW_GAME; diff --git a/NorthstarDedicatedTest/misccommands.h b/NorthstarDedicatedTest/misccommands.h index c8de8ad2..cbd1df65 100644 --- a/NorthstarDedicatedTest/misccommands.h +++ b/NorthstarDedicatedTest/misccommands.h @@ -1,3 +1,2 @@ #pragma once - void AddMiscConCommands();
\ No newline at end of file diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp index c9796ac1..de06fb73 100644 --- a/NorthstarDedicatedTest/modmanager.cpp +++ b/NorthstarDedicatedTest/modmanager.cpp @@ -258,11 +258,11 @@ void ModManager::LoadMods() } // sort by load prio, lowest-highest - std::sort(m_loadedMods.begin(), m_loadedMods.end(), [](Mod a, Mod b) { + std::sort(m_loadedMods.begin(), m_loadedMods.end(), [](Mod& a, Mod& b) { return a.LoadPriority < b.LoadPriority; }); - for (Mod mod : m_loadedMods) + for (Mod& mod : m_loadedMods) { if (!mod.Enabled) continue; @@ -296,7 +296,6 @@ void ModManager::LoadMods() } } - // read keyvalues paths if (fs::exists(mod.ModDirectory / "keyvalues")) { @@ -305,11 +304,27 @@ void ModManager::LoadMods() if (fs::is_regular_file(file)) { std::string kvStr = file.path().lexically_relative(mod.ModDirectory / "keyvalues").lexically_normal().string(); - mod.KeyValuesHash.push_back(std::hash<std::string>{}(kvStr)); - mod.KeyValues.push_back(kvStr); + mod.KeyValues.insert(std::make_pair(std::hash<std::string>{}(kvStr), kvStr)); } } } + + // read pdiff + if (fs::exists(mod.ModDirectory / "mod.pdiff")) + { + std::ifstream pdiffStream(mod.ModDirectory / "mod.pdiff"); + + if (!pdiffStream.fail()) + { + std::stringstream pdiffStringStream; + while (pdiffStream.peek() != EOF) + pdiffStringStream << (char)pdiffStream.get(); + + pdiffStream.close(); + + mod.Pdiff = pdiffStringStream.str(); + } + } } // in a seperate loop because we register mod files in reverse order, since mods loaded later should have their files prioritised @@ -349,13 +364,12 @@ void ModManager::UnloadMods() if (!m_hasEnabledModsCfg) m_enabledModsCfg.SetObject(); - for (Mod mod : m_loadedMods) + for (Mod& mod : m_loadedMods) { // remove all built kvs - for (std::string kvPaths : mod.KeyValues) - fs::remove(COMPILED_ASSETS_PATH / fs::path(kvPaths).lexically_relative(mod.ModDirectory)); + for (std::pair<size_t, std::string> kvPaths : mod.KeyValues) + fs::remove(COMPILED_ASSETS_PATH / fs::path(kvPaths.second).lexically_relative(mod.ModDirectory)); - mod.KeyValuesHash.clear(); mod.KeyValues.clear(); // write to m_enabledModsCfg @@ -383,13 +397,13 @@ void ModManager::CompileAssetsForFile(const char* filename) else //if (!strcmp((filename + strlen(filename)) - 3, "txt")) // check if it's a .txt { // check if we should build keyvalues, depending on whether any of our mods have patch kvs for this file - for (Mod mod : m_loadedMods) + for (Mod& mod : m_loadedMods) { if (!mod.Enabled) continue; size_t fileHash = std::hash<std::string>{}(fs::path(filename).lexically_normal().string()); - if (std::find(mod.KeyValuesHash.begin(), mod.KeyValuesHash.end(), fileHash) != mod.KeyValuesHash.end()) + if (mod.KeyValues.find(fileHash) != mod.KeyValues.end()) { TryBuildKeyValues(filename); return; diff --git a/NorthstarDedicatedTest/modmanager.h b/NorthstarDedicatedTest/modmanager.h index e0f277e9..e1c246b1 100644 --- a/NorthstarDedicatedTest/modmanager.h +++ b/NorthstarDedicatedTest/modmanager.h @@ -77,8 +77,8 @@ public: // other files: std::vector<std::string> Vpks; - std::vector<std::string> KeyValues; - std::vector<size_t> KeyValuesHash; // size_t because we hash these filesnames: faster than string comp + std::unordered_map<size_t, std::string> KeyValues; + std::string Pdiff; // only need one per mod // other stuff diff --git a/NorthstarDedicatedTest/pch.h b/NorthstarDedicatedTest/pch.h index 19192f04..e0e46352 100644 --- a/NorthstarDedicatedTest/pch.h +++ b/NorthstarDedicatedTest/pch.h @@ -5,7 +5,8 @@ #define _CRT_SECURE_NO_WARNINGS #define RAPIDJSON_NOMEMBERITERATORCLASS // need this for rapidjson #define NOMINMAX // this too -#define _WINSOCK_DEPRECATED_NO_WARNINGS // temp because i'm very lazy and want to use inet_addr, remove later +#define _WINSOCK_DEPRECATED_NO_WARNINGS // temp because i'm very lazy and want to use inet_addr, remove later +#define RAPIDJSON_HAS_STDSTRING 1 // add headers that you want to pre-compile here #include <Windows.h> diff --git a/NorthstarDedicatedTest/scriptmodmenu.cpp b/NorthstarDedicatedTest/scriptmodmenu.cpp index 54e7d0e1..141fdf75 100644 --- a/NorthstarDedicatedTest/scriptmodmenu.cpp +++ b/NorthstarDedicatedTest/scriptmodmenu.cpp @@ -9,7 +9,7 @@ SQInteger SQ_GetModNames(void* sqvm) { ClientSq_newarray(sqvm, 0); - for (Mod mod : g_ModManager->m_loadedMods) + for (Mod& mod : g_ModManager->m_loadedMods) { ClientSq_pushstring(sqvm, mod.Name.c_str(), -1); ClientSq_arrayappend(sqvm, -2); @@ -24,7 +24,7 @@ SQInteger SQ_IsModEnabled(void* sqvm) const SQChar* modName = ClientSq_getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal - for (Mod mod : g_ModManager->m_loadedMods) + for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { @@ -43,7 +43,7 @@ SQInteger SQ_SetModEnabled(void* sqvm) const SQBool enabled = ClientSq_getbool(sqvm, 2); // manual lookup, not super performant but eh not a big deal - for (Mod mod : g_ModManager->m_loadedMods) + for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { @@ -61,7 +61,7 @@ SQInteger SQ_GetModDescription(void* sqvm) const SQChar* modName = ClientSq_getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal - for (Mod mod : g_ModManager->m_loadedMods) + for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { @@ -79,7 +79,7 @@ SQInteger SQ_GetModVersion(void* sqvm) const SQChar* modName = ClientSq_getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal - for (Mod mod : g_ModManager->m_loadedMods) + for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { @@ -97,7 +97,7 @@ SQInteger SQ_GetModDownloadLink(void* sqvm) const SQChar* modName = ClientSq_getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal - for (Mod mod : g_ModManager->m_loadedMods) + for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { @@ -115,7 +115,7 @@ SQInteger SQ_GetModLoadPriority(void* sqvm) const SQChar* modName = ClientSq_getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal - for (Mod mod : g_ModManager->m_loadedMods) + for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { @@ -133,7 +133,7 @@ SQInteger SQ_IsModRequiredOnClient(void* sqvm) const SQChar* modName = ClientSq_getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal - for (Mod mod : g_ModManager->m_loadedMods) + for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { @@ -152,7 +152,7 @@ SQInteger SQ_GetModConvars(void* sqvm) ClientSq_newarray(sqvm, 0); // manual lookup, not super performant but eh not a big deal - for (Mod mod : g_ModManager->m_loadedMods) + for (Mod& mod : g_ModManager->m_loadedMods) { if (!mod.Name.compare(modName)) { @@ -187,7 +187,7 @@ void InitialiseScriptModMenu(HMODULE baseAddress) g_UISquirrelManager->AddFuncRegistration("string", "NSGetModDescriptionByModName", "string modName", "Returns a given mod's description", SQ_GetModDescription); g_UISquirrelManager->AddFuncRegistration("string", "NSGetModVersionByModName", "string modName", "Returns a given mod's version", SQ_GetModVersion); g_UISquirrelManager->AddFuncRegistration("string", "NSGetModDownloadLinkByModName", "string modName", "Returns a given mod's download link", SQ_GetModDownloadLink); - g_UISquirrelManager->AddFuncRegistration("bool", "NSIsModRequiredOnClient", "string modName", "Returns whether a given mod is required on connecting clients", SQ_IsModEnabled); + g_UISquirrelManager->AddFuncRegistration("bool", "NSIsModRequiredOnClient", "string modName", "Returns whether a given mod is required on connecting clients", SQ_IsModRequiredOnClient); g_UISquirrelManager->AddFuncRegistration("int", "NSGetModLoadPriority", "string modName", "Returns a given mod's load priority", SQ_GetModLoadPriority); g_UISquirrelManager->AddFuncRegistration("array<string>", "NSGetModConvarsByModName", "string modName", "Returns the names of all a given mod's cvars", SQ_GetModConvars); diff --git a/NorthstarDedicatedTest/scriptsrson.cpp b/NorthstarDedicatedTest/scriptsrson.cpp index 0f6680a3..dbe4ddc1 100644 --- a/NorthstarDedicatedTest/scriptsrson.cpp +++ b/NorthstarDedicatedTest/scriptsrson.cpp @@ -17,7 +17,7 @@ void ModManager::BuildScriptsRson() std::string scriptsRson = ReadVPKOriginalFile(VPK_SCRIPTS_RSON_PATH); scriptsRson += "\n\n// START MODDED SCRIPT CONTENT\n\n"; // newline before we start custom stuff - for (Mod mod : m_loadedMods) + for (Mod& mod : m_loadedMods) { if (!mod.Enabled) continue; @@ -27,7 +27,7 @@ void ModManager::BuildScriptsRson() scriptsRson += mod.Name; scriptsRson += ":\n\n"; - for (ModScript script : mod.Scripts) + for (ModScript& script : mod.Scripts) { /* should create something with this format for each script When: "CONTEXT" |