Add core functionality for loading and processing game assets

- Implemented palette loading from binary files in `palette.cpp`.
- Added runtime utilities for reading text and JSON files in `runtime.cpp`.
- Created shape archive handling in `shape_archive.cpp`, including frame parsing and pixel decoding.
- Introduced type flag loading functionality in `type_flags.cpp`.
- Developed tests for combat tactics, entity dispatch entries, file system operations, fixed maps, flex archives, glob archives, map rendering, palette loading, shape archives, and type flags.
- Added a Python script for importing Ghidra-exported function slices with reporting capabilities.
This commit is contained in:
MaddoScientisto 2026-04-27 21:15:01 +02:00
commit 8907604b84
41 changed files with 2889 additions and 0 deletions

View file

@ -0,0 +1,79 @@
#include "remorse/runtime.h"
#include <fstream>
#include <iostream>
#include <regex>
#include <sstream>
namespace remorse {
namespace {
std::string readTextFile(const std::filesystem::path& path)
{
std::ifstream input(path, std::ios::binary);
if (!input) {
return {};
}
std::ostringstream buffer;
buffer << input.rdbuf();
return buffer.str();
}
std::optional<std::string> readJsonString(const std::string& json, const char* key)
{
const std::regex pattern(std::string("\\\"") + key + "\\\"\\s*:\\s*\\\"([^\\\"]*)\\\"");
std::smatch match;
if (!std::regex_search(json, match, pattern)) {
return std::nullopt;
}
return match[1].str();
}
u32 readJsonU32(const std::string& json, const char* key)
{
const std::regex pattern(std::string("\\\"") + key + "\\\"\\s*:\\s*([0-9]+)");
std::smatch match;
if (!std::regex_search(json, match, pattern)) {
return 0;
}
return static_cast<u32>(std::stoul(match[1].str()));
}
} // namespace
std::optional<ExportManifestSummary> loadExportManifestSummary(const std::filesystem::path& manifestPath)
{
const std::string json = readTextFile(manifestPath);
if (json.empty()) {
return std::nullopt;
}
ExportManifestSummary summary;
summary.program = readJsonString(json, "program").value_or("unknown");
summary.outputRoot = readJsonString(json, "outputRoot").value_or("");
summary.functionFiles = readJsonU32(json, "functionFiles");
summary.fallbackFunctionFiles = readJsonU32(json, "fallbackFunctionFiles");
summary.globalBuckets = readJsonU32(json, "globalBuckets");
summary.globalDefinitions = readJsonU32(json, "globalDefinitions");
return summary;
}
std::filesystem::path defaultManifestPath(const std::filesystem::path& currentPath)
{
return currentPath / "exports" / "src_remorse" / "export_manifest.json";
}
void printStartupReport(const ExportManifestSummary& manifest)
{
std::cout << "Crusader: No Remorse rebuild harness\n";
std::cout << "Program: " << manifest.program << '\n';
std::cout << "Export root: " << manifest.outputRoot.string() << '\n';
std::cout << "Function files: " << manifest.functionFiles << '\n';
std::cout << "Fallback function files: " << manifest.fallbackFunctionFiles << '\n';
std::cout << "Global buckets: " << manifest.globalBuckets << '\n';
std::cout << "Global definitions: " << manifest.globalDefinitions << '\n';
std::cout << "Status: host runtime scaffold is alive; exported game code is not linked yet.\n";
}
} // namespace remorse