Add secure m2p loader with runtime key enforcement

This commit is contained in:
server
2026-04-14 12:12:23 +02:00
parent 0c2d6c7c9c
commit 229c809b96
8 changed files with 719 additions and 6 deletions

View File

@@ -14,6 +14,7 @@
#include "EterBase/lzo.h"
#include "PackLib/PackManager.h"
#include "PackLib/M2PackRuntimeKeyProvider.h"
#include <filesystem>
#include <format>
@@ -57,6 +58,33 @@ bool PackInitialize(const char * c_pszFolder)
if (_access(c_pszFolder, 0) != 0)
return false;
auto AddPreferredPack = [c_pszFolder](const std::string& packName, bool required) -> bool
{
const std::string m2Path = std::format("{}/{}.m2p", c_pszFolder, packName);
const std::string legacyPath = std::format("{}/{}.pck", c_pszFolder, packName);
if (_access(m2Path.c_str(), 0) == 0)
{
Tracef("PackInitialize: Loading %s\n", m2Path.c_str());
if (CPackManager::instance().AddPack(m2Path))
return true;
TraceError("PackInitialize: Failed to load %s", m2Path.c_str());
return false;
}
if (_access(legacyPath.c_str(), 0) == 0)
{
Tracef("PackInitialize: Loading %s\n", legacyPath.c_str());
if (CPackManager::instance().AddPack(legacyPath))
return true;
TraceError("PackInitialize: Failed to load %s", legacyPath.c_str());
}
return !required;
};
std::vector<std::string> packFiles = {
"patch1",
"season3_eu",
@@ -149,18 +177,16 @@ bool PackInitialize(const char * c_pszFolder)
"uiloading",
};
Tracef("PackInitialize: Loading root.pck\n");
DWORD dwStartTime = GetTickCount();
if (!CPackManager::instance().AddPack(std::format("{}/root.pck", c_pszFolder)))
if (!AddPreferredPack("root", true))
{
TraceError("Failed to load root.pck");
TraceError("Failed to load root pack");
return false;
}
Tracef("PackInitialize: Loading %d pack files...", packFiles.size());
for (const std::string& packFileName : packFiles) {
Tracef("PackInitialize: Loading %s.pck\n", packFileName.c_str());
CPackManager::instance().AddPack(std::format("{}/{}.pck", c_pszFolder, packFileName));
AddPreferredPack(packFileName, false);
}
Tracef("PackInitialize: done. Time taken: %d ms\n", GetTickCount() - dwStartTime);
return true;
@@ -326,5 +352,7 @@ int Setup(LPSTR lpCmdLine)
Callback.Function = nullptr;
Callback.UserData = 0;
GrannySetLogCallback(&Callback);
InitializeM2PackRuntimeKeyProvider(lpCmdLine);
return 1;
}