feat: T4 add StringTable loader (#934)

* feat: T4 add string table loader

* chore: rename stringtable loaders to match style between games

* fix: make sure all games correctly interpret failed stringtable loading

---------

Co-authored-by: Jan Laupetin <[email protected]>
This commit is contained in:
mo
2026-07-26 00:40:02 +02:00
committed by GitHub
co-authored by Jan Laupetin
parent 76e5bb17a2
commit 0c66d1838e
12 changed files with 117 additions and 15 deletions
+1 -1
View File
@@ -153,7 +153,7 @@ using `Linker`):
| FxEffectDef | ❌ | ❌ | |
| FxImpactTable | ❌ | ❌ | |
| RawFile | ✅ | ✅ | |
| StringTable | ✅ | | |
| StringTable | ✅ | | |
| PackIndex | ❌ | ❌ | |
## T5 (Call of Duty: Black Ops)
+1 -1
View File
@@ -20,7 +20,7 @@
#include "PhysPreset/RawLoaderPhysPresetIW3.h"
#include "RawFile/AssetLoaderRawFileIW3.h"
#include "Sound/LoaderSoundCurveIW3.h"
#include "StringTable/AssetLoaderStringTableIW3.h"
#include "StringTable/LoaderStringTableIW3.h"
#include "Weapon/WeaponGdtLoaderIW3.h"
#include "Weapon/WeaponRawLoaderIW3.h"
@@ -1,10 +1,8 @@
#include "AssetLoaderStringTableIW3.h"
#include "LoaderStringTableIW3.h"
#include "Game/IW3/IW3.h"
#include "StringTable/StringTableLoader.h"
#include <cstring>
using namespace IW3;
namespace
@@ -3,12 +3,8 @@
#include "Csv/CsvStream.h"
#include "Game/IW5/CommonIW5.h"
#include "Game/IW5/IW5.h"
#include "ObjLoading.h"
#include "Pool/GlobalAssetPool.h"
#include "StringTable/StringTableLoader.h"
#include <cstring>
using namespace IW5;
namespace
@@ -30,6 +26,8 @@ namespace
string_table::StringTableLoaderV2<StringTable, Common::StringTable_HashString> loader;
auto* stringTable = loader.LoadFromStream(assetName, m_memory, *file.m_stream);
if (!stringTable)
return AssetCreationResult::Failure();
return AssetCreationResult::Success(context.AddAsset<AssetStringTable>(assetName, stringTable));
}
+2
View File
@@ -14,6 +14,7 @@
#include "PhysPreset/GdtLoaderPhysPresetT4.h"
#include "PhysPreset/RawLoaderPhysPresetT4.h"
#include "RawFile/AssetLoaderRawFileT4.h"
#include "StringTable/LoaderStringTableT4.h"
#include "Weapon/FlameTableLoaderT4.h"
#include "Weapon/WeaponGdtLoaderT4.h"
#include "Weapon/WeaponRawLoaderT4.h"
@@ -108,6 +109,7 @@ namespace
collection.AddAssetCreator(phys_preset::CreateRawLoaderT4(memory, searchPath, zone));
collection.AddAssetCreator(phys_preset::CreateGdtLoaderT4(memory, gdt, zone));
collection.AddAssetCreator(raw_file::CreateLoaderT4(memory, searchPath));
collection.AddAssetCreator(string_table::CreateLoaderT4(memory, searchPath));
collection.AddAssetCreator(weapon::CreateRawLoaderT4(memory, searchPath, zone));
collection.AddAssetCreator(weapon::CreateGdtLoaderT4(memory, searchPath, gdt, zone));
@@ -0,0 +1,45 @@
#include "LoaderStringTableT4.h"
#include "Game/T4/T4.h"
#include "StringTable/StringTableLoader.h"
using namespace T4;
namespace
{
class StringTableLoader final : public AssetCreator<AssetStringTable>
{
public:
StringTableLoader(MemoryManager& memory, ISearchPath& searchPath)
: m_memory(memory),
m_search_path(searchPath)
{
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto file = m_search_path.Open(assetName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
string_table::StringTableLoaderV1<StringTable> loader;
auto* stringTable = loader.LoadFromStream(assetName, m_memory, *file.m_stream);
if (!stringTable)
return AssetCreationResult::Failure();
return AssetCreationResult::Success(context.AddAsset<AssetStringTable>(assetName, stringTable));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace string_table
{
std::unique_ptr<AssetCreator<AssetStringTable>> CreateLoaderT4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<StringTableLoader>(memory, searchPath);
}
} // namespace string_table
@@ -0,0 +1,13 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T4/T4.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace string_table
{
std::unique_ptr<AssetCreator<T4::AssetStringTable>> CreateLoaderT4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace string_table
@@ -4,8 +4,6 @@
#include "Game/T5/T5.h"
#include "StringTable/StringTableLoader.h"
#include <cstring>
using namespace T5;
namespace
@@ -27,6 +25,8 @@ namespace
string_table::StringTableLoaderV3<StringTable, Common::Com_HashString> loader;
auto* stringTable = loader.LoadFromStream(assetName, m_memory, *file.m_stream);
if (!stringTable)
return AssetCreationResult::Failure();
return AssetCreationResult::Success(context.AddAsset<AssetStringTable>(assetName, stringTable));
}
@@ -5,8 +5,6 @@
#include "Game/T6/T6.h"
#include "StringTable/StringTableLoader.h"
#include <cstring>
using namespace T6;
namespace
@@ -28,6 +26,8 @@ namespace
string_table::StringTableLoaderV3<StringTable, Common::Com_HashString> loader;
auto* stringTable = loader.LoadFromStream(assetName, m_memory, *file.m_stream);
if (!stringTable)
return AssetCreationResult::Failure();
return AssetCreationResult::Success(context.AddAsset<AssetStringTable>(assetName, stringTable));
}
@@ -1,6 +1,5 @@
#include "Game/IW3/StringTable/AssetLoaderStringTableIW3.h"
#include "Game/IW3/GameIW3.h"
#include "Game/IW3/StringTable/LoaderStringTableIW3.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
@@ -0,0 +1,47 @@
#include "Game/T4/StringTable/LoaderStringTableT4.h"
#include "Game/T4/GameT4.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
#include <catch2/catch_test_macros.hpp>
#include <string>
using namespace T4;
using namespace std::literals;
namespace
{
TEST_CASE("LoaderStringTable(T4): Can parse string table", "[t4][stringtable][assetloader]")
{
MockSearchPath searchPath;
searchPath.AddFileData("mp/cooltable.csv",
"test,data,lol\n"
"lorem,ipsum");
Zone zone("MockZone", 0, GameId::T4, GamePlatform::PC);
MemoryManager memory;
AssetCreatorCollection creatorCollection(zone);
IgnoredAssetLookup ignoredAssetLookup;
AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup);
auto loader = string_table::CreateLoaderT4(memory, searchPath);
auto result = loader->CreateAsset("mp/cooltable.csv", context);
REQUIRE(result.HasBeenSuccessful());
const auto* assetInfo = reinterpret_cast<XAssetInfo<StringTable>*>(result.GetAssetInfo());
const auto* stringTable = assetInfo->Asset();
REQUIRE(stringTable->name == "mp/cooltable.csv"s);
REQUIRE(stringTable->columnCount == 3);
REQUIRE(stringTable->rowCount == 2);
REQUIRE(stringTable->values[0] == "test"s);
REQUIRE(stringTable->values[1] == "data"s);
REQUIRE(stringTable->values[2] == "lol"s);
REQUIRE(stringTable->values[3] == "lorem"s);
REQUIRE(stringTable->values[4] == "ipsum"s);
REQUIRE(stringTable->values[5] == ""s);
}
} // namespace