#include "remorse/combat_tactics.h" #include "remorse/entity_dispatch_entry.h" #include "remorse/file_system.h" #include "remorse/flex_archive.h" #include "remorse/fixed_map.h" #include "remorse/glob_archive.h" #include "remorse/palette.h" #include "remorse/runtime.h" #include "remorse/type_flags.h" #include #include int main(int argc, char** argv) { remorse::installCrashDiagnostics(); const std::filesystem::path manifestPath = argc > 1 ? std::filesystem::path(argv[1]) : remorse::defaultManifestPath(std::filesystem::current_path()); const auto manifest = remorse::loadExportManifestSummary(manifestPath); if (!manifest) { std::cerr << "Could not read export manifest: " << manifestPath.string() << '\n'; return 2; } remorse::printStartupReport(*manifest); remorse::ProcessKernel kernel; remorse::u16 groupCounts[32]{}; const auto* entry = kernel.createProcess(1, groupCounts); std::cout << "Registered process ID: " << (entry ? entry->bytes[0x02] : 0) << '\n'; for (int index = 0; index < 3; ++index) { kernel.createProcess(1, groupCounts); } kernel.createSystemTimerProcess(1, groupCounts); kernel.createKeyboardProcess(1, groupCounts); kernel.createKeyDaemonProcess(1, groupCounts); kernel.terminateProcess(3, groupCounts); kernel.clearTerminatedProcesses(); auto* reused = kernel.createStandProcess(1, 1, groupCounts); std::cout << "Reused Stand process ID: " << (reused ? reused->base.bytes[0x02] : 0) << '\n'; remorse::NpcBehaviorServices npcServices{ [](remorse::u16, void*) { return false; }, [](remorse::u16, void*) -> remorse::u16 { return 0; }, [](remorse::u16, remorse::u16, void*) { return false; }, [](remorse::u16, void*) { return false; }, [](remorse::u16, remorse::u16, void*) {}, nullptr }; struct ScanContext { remorse::StandProcessEntry* standing; remorse::NpcBehaviorServices* npcServices; remorse::u32 timerTick; int hostCallbacks = 0; } scanContext{reused, &npcServices, 0}; for (int tick = 0; tick < 100; ++tick) { kernel.deliverSystemTimerEvent(); } scanContext.timerTick = kernel.systemTimerTick(); kernel.scanRunnableProcesses(1, [](remorse::EntityDispatchEntryBase& process, void* context) { auto& scan = *static_cast(context); if (process.bytes[0] == 0x0f && process.bytes[1] == 0x1f) { remorse::StandProcess::run(*scan.standing, *scan.npcServices, scan.timerTick); } else { ++scan.hostCallbacks; } }, &scanContext, scanContext.timerTick); std::cout << "Scheduler scan host callbacks: " << scanContext.hostCallbacks << '\n'; std::cout << "StandProcess Run sleep ticks: " << static_cast(reused->base.bytes[0x0e]) << '\n'; const auto gameDataRoot = remorse::findGameDataRoot(std::filesystem::current_path()); std::cout << "Game data root: " << (gameDataRoot ? gameDataRoot->path.string() : "not found") << '\n'; if (gameDataRoot) { const auto palettePath = remorse::resolveGameDataPath(*gameDataRoot, std::filesystem::path("STATIC") / "GAMEPAL.PAL"); const auto paletteBytes = palettePath ? remorse::readBinaryFile(*palettePath) : std::nullopt; std::cout << "GAMEPAL.PAL bytes: " << (paletteBytes ? paletteBytes->size() : 0) << '\n'; const auto palette = palettePath ? remorse::loadPalette256(*palettePath) : std::nullopt; std::cout << "GAMEPAL.PAL colors: " << (palette ? palette->colors.size() : 0) << '\n'; const auto combatPath = remorse::resolveGameDataPath(*gameDataRoot, std::filesystem::path("STATIC") / "COMBAT.DAT"); const auto combatArchive = combatPath ? remorse::loadFlexArchive(*combatPath) : std::nullopt; std::cout << "COMBAT.DAT populated entries: " << (combatArchive ? combatArchive->populatedEntries.size() : 0) << '\n'; const auto combatTactics = combatPath ? remorse::loadCombatTactics(*combatPath) : std::nullopt; std::cout << "COMBAT.DAT tactics: " << (combatTactics ? combatTactics->size() : 0) << '\n'; const auto fixedPath = remorse::resolveGameDataPath(*gameDataRoot, std::filesystem::path("STATIC") / "FIXED.DAT"); const auto fixedArchive = fixedPath ? remorse::loadFixedMapArchive(*fixedPath) : std::nullopt; std::cout << "FIXED.DAT maps: " << (fixedArchive ? fixedArchive->mapCount : 0) << '\n'; if (fixedArchive) { for (remorse::u32 index = 0; index < fixedArchive->mapCount; ++index) { const auto map = remorse::loadFixedMap(*fixedArchive, index); if (map && !map->entries.empty()) { std::cout << "FIXED.DAT first non-empty map: " << index << '\n'; std::cout << "FIXED.DAT first non-empty entries: " << map->entries.size() << '\n'; break; } } } const auto globPath = remorse::resolveGameDataPath(*gameDataRoot, std::filesystem::path("STATIC") / "GLOB.FLX"); const auto globObjects = globPath ? remorse::loadGlobObjects(*globPath) : std::nullopt; std::cout << "GLOB.FLX objects: " << (globObjects ? globObjects->size() : 0) << '\n'; const auto typeFlagPath = remorse::resolveGameDataPath(*gameDataRoot, std::filesystem::path("STATIC") / "TYPEFLAG.DAT"); const auto typeFlags = typeFlagPath ? remorse::loadTypeFlags(*typeFlagPath) : std::nullopt; std::cout << "TYPEFLAG.DAT shapes: " << (typeFlags ? typeFlags->size() : 0) << '\n'; } return 0; }