Crusader_Decomp/rebuild/remorse/src/runtime.cpp

79 lines
2.5 KiB
C++
Raw Normal View History

#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