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:
parent
6ca3b18c3e
commit
8907604b84
41 changed files with 2889 additions and 0 deletions
23
rebuild/remorse/tests/combat_tactics_tests.cpp
Normal file
23
rebuild/remorse/tests/combat_tactics_tests.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include "remorse/combat_tactics.h"
|
||||
#include "remorse/file_system.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <filesystem>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto root = remorse::findGameDataRoot(std::filesystem::current_path());
|
||||
assert(root.has_value());
|
||||
|
||||
const auto combatPath = remorse::resolveGameDataPath(*root, std::filesystem::path("STATIC") / "COMBAT.DAT");
|
||||
assert(combatPath.has_value());
|
||||
|
||||
const auto tactics = remorse::loadCombatTactics(*combatPath);
|
||||
assert(tactics.has_value());
|
||||
assert(tactics->size() == 14);
|
||||
assert((*tactics)[0].name == "Dumb");
|
||||
assert((*tactics)[0].blockOffsets[0] == 0x002c);
|
||||
assert((*tactics)[0].blockOffsets[1] == 0x0031);
|
||||
assert(!(*tactics)[0].bytecode.empty());
|
||||
return 0;
|
||||
}
|
||||
26
rebuild/remorse/tests/entity_dispatch_entry_tests.cpp
Normal file
26
rebuild/remorse/tests/entity_dispatch_entry_tests.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include "remorse/entity_dispatch_entry.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
remorse::EntityDispatchEntryBase entry{};
|
||||
remorse::EntityDispatchEntry::initBase(&entry);
|
||||
|
||||
remorse::EntityDispatchEntry::setSourceType(entry, 0x1234);
|
||||
assert(entry.bytes[0x04] == 0x34);
|
||||
assert(entry.bytes[0x05] == 0x12);
|
||||
|
||||
remorse::EntityDispatchEntry::setEventTypeChecked(entry, 0x00f2);
|
||||
assert(entry.bytes[0x06] == 0xf2);
|
||||
assert(entry.bytes[0x07] == 0x00);
|
||||
|
||||
entry.bytes[0x08] = 0xe0;
|
||||
remorse::EntityDispatchEntry::setGroupId(entry, 0x23);
|
||||
assert(entry.bytes[0x08] == 0xe3);
|
||||
|
||||
remorse::EntityDispatchEntry::incrementGroupId(entry);
|
||||
assert(entry.bytes[0x08] == 0xe4);
|
||||
|
||||
return 0;
|
||||
}
|
||||
24
rebuild/remorse/tests/file_system_tests.cpp
Normal file
24
rebuild/remorse/tests/file_system_tests.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include "remorse/file_system.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <filesystem>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto root = remorse::findGameDataRoot(std::filesystem::current_path());
|
||||
assert(root.has_value());
|
||||
assert(root->hasExecutable);
|
||||
assert(root->hasStaticData);
|
||||
assert(root->hasUsecode);
|
||||
|
||||
const auto palettePath = remorse::resolveGameDataPath(*root, std::filesystem::path("static") / "gamepal.pal");
|
||||
assert(palettePath.has_value());
|
||||
|
||||
const auto paletteBytes = remorse::readBinaryFile(*palettePath);
|
||||
assert(paletteBytes.has_value());
|
||||
assert(!paletteBytes->empty());
|
||||
|
||||
const auto blockedParent = remorse::resolveGameDataPath(*root, std::filesystem::path("..") / "CRUSADER.EXE");
|
||||
assert(!blockedParent.has_value());
|
||||
return 0;
|
||||
}
|
||||
37
rebuild/remorse/tests/fixed_map_tests.cpp
Normal file
37
rebuild/remorse/tests/fixed_map_tests.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include "remorse/file_system.h"
|
||||
#include "remorse/fixed_map.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <filesystem>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto root = remorse::findGameDataRoot(std::filesystem::current_path());
|
||||
assert(root.has_value());
|
||||
|
||||
const auto fixedPath = remorse::resolveGameDataPath(*root, std::filesystem::path("STATIC") / "FIXED.DAT");
|
||||
assert(fixedPath.has_value());
|
||||
|
||||
const auto archive = remorse::loadFixedMapArchive(*fixedPath);
|
||||
assert(archive.has_value());
|
||||
assert(archive->mapCount > 0);
|
||||
|
||||
const auto firstMap = remorse::loadFixedMap(*archive, 0);
|
||||
assert(firstMap.has_value());
|
||||
assert(firstMap->index == 0);
|
||||
|
||||
bool foundNonEmptyMap = false;
|
||||
for (remorse::u32 index = 0; index < archive->mapCount; ++index) {
|
||||
const auto map = remorse::loadFixedMap(*archive, index);
|
||||
assert(map.has_value());
|
||||
if (!map->entries.empty()) {
|
||||
foundNonEmptyMap = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(foundNonEmptyMap);
|
||||
|
||||
const auto outOfRange = remorse::loadFixedMap(*archive, archive->mapCount);
|
||||
assert(!outOfRange.has_value());
|
||||
return 0;
|
||||
}
|
||||
27
rebuild/remorse/tests/flex_archive_tests.cpp
Normal file
27
rebuild/remorse/tests/flex_archive_tests.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "remorse/file_system.h"
|
||||
#include "remorse/flex_archive.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <filesystem>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto root = remorse::findGameDataRoot(std::filesystem::current_path());
|
||||
assert(root.has_value());
|
||||
|
||||
const auto combatPath = remorse::resolveGameDataPath(*root, std::filesystem::path("STATIC") / "COMBAT.DAT");
|
||||
assert(combatPath.has_value());
|
||||
|
||||
const auto archive = remorse::loadFlexArchive(*combatPath);
|
||||
assert(archive.has_value());
|
||||
assert(archive->populatedEntries.size() == 14);
|
||||
|
||||
const auto firstEntry = remorse::readFlexEntry(*archive, 0);
|
||||
assert(firstEntry.has_value());
|
||||
assert(firstEntry->size() == 0x4f);
|
||||
assert((*firstEntry)[0] == 'D');
|
||||
assert((*firstEntry)[1] == 'u');
|
||||
assert((*firstEntry)[2] == 'm');
|
||||
assert((*firstEntry)[3] == 'b');
|
||||
return 0;
|
||||
}
|
||||
28
rebuild/remorse/tests/glob_archive_tests.cpp
Normal file
28
rebuild/remorse/tests/glob_archive_tests.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include "remorse/file_system.h"
|
||||
#include "remorse/glob_archive.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <filesystem>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto root = remorse::findGameDataRoot(std::filesystem::current_path());
|
||||
assert(root.has_value());
|
||||
|
||||
const auto globPath = remorse::resolveGameDataPath(*root, std::filesystem::path("STATIC") / "GLOB.FLX");
|
||||
assert(globPath.has_value());
|
||||
|
||||
const auto objects = remorse::loadGlobObjects(*globPath);
|
||||
assert(objects.has_value());
|
||||
assert(!objects->empty());
|
||||
|
||||
bool foundObjectWithEntries = false;
|
||||
for (const remorse::GlobObject& object : *objects) {
|
||||
if (!object.entries.empty()) {
|
||||
foundObjectWithEntries = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(foundObjectWithEntries);
|
||||
return 0;
|
||||
}
|
||||
25
rebuild/remorse/tests/map_renderer_tests.cpp
Normal file
25
rebuild/remorse/tests/map_renderer_tests.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include "remorse/file_system.h"
|
||||
#include "remorse/map_renderer.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <filesystem>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto root = remorse::findGameDataRoot(std::filesystem::current_path());
|
||||
assert(root.has_value());
|
||||
|
||||
remorse::MapRenderOptions options;
|
||||
options.mapIndex = 1;
|
||||
options.maxWidth = 320;
|
||||
options.maxHeight = 200;
|
||||
|
||||
const auto image = remorse::renderMapPreview(*root, options);
|
||||
assert(image.has_value());
|
||||
assert(image->width > 0);
|
||||
assert(image->height > 0);
|
||||
assert(!image->pixels.empty());
|
||||
assert(image->decodedItemCount > 0);
|
||||
assert(image->paintedItemCount > 0);
|
||||
return 0;
|
||||
}
|
||||
19
rebuild/remorse/tests/palette_tests.cpp
Normal file
19
rebuild/remorse/tests/palette_tests.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include "remorse/file_system.h"
|
||||
#include "remorse/palette.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <filesystem>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto root = remorse::findGameDataRoot(std::filesystem::current_path());
|
||||
assert(root.has_value());
|
||||
|
||||
const auto palettePath = remorse::resolveGameDataPath(*root, std::filesystem::path("STATIC") / "GAMEPAL.PAL");
|
||||
assert(palettePath.has_value());
|
||||
|
||||
const auto palette = remorse::loadPalette256(*palettePath);
|
||||
assert(palette.has_value());
|
||||
assert(palette->colors.size() == 256);
|
||||
return 0;
|
||||
}
|
||||
30
rebuild/remorse/tests/shape_archive_tests.cpp
Normal file
30
rebuild/remorse/tests/shape_archive_tests.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include "remorse/file_system.h"
|
||||
#include "remorse/shape_archive.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <filesystem>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto root = remorse::findGameDataRoot(std::filesystem::current_path());
|
||||
assert(root.has_value());
|
||||
|
||||
const auto shapesPath = remorse::resolveGameDataPath(*root, std::filesystem::path("STATIC") / "SHAPES.FLX");
|
||||
assert(shapesPath.has_value());
|
||||
|
||||
const auto archive = remorse::loadShapeArchive(*shapesPath);
|
||||
assert(archive.has_value());
|
||||
|
||||
bool decodedFrame = false;
|
||||
for (remorse::u32 shape = 0; shape < archive->archive.entryCount; ++shape) {
|
||||
const auto frame = remorse::decodeShapeFrame(*archive, shape, 0);
|
||||
if (frame && !frame->pixels.empty()) {
|
||||
assert(frame->frame.width > 0);
|
||||
assert(frame->frame.height > 0);
|
||||
decodedFrame = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(decodedFrame);
|
||||
return 0;
|
||||
}
|
||||
28
rebuild/remorse/tests/type_flags_tests.cpp
Normal file
28
rebuild/remorse/tests/type_flags_tests.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include "remorse/file_system.h"
|
||||
#include "remorse/type_flags.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <filesystem>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto root = remorse::findGameDataRoot(std::filesystem::current_path());
|
||||
assert(root.has_value());
|
||||
|
||||
const auto typeFlagPath = remorse::resolveGameDataPath(*root, std::filesystem::path("STATIC") / "TYPEFLAG.DAT");
|
||||
assert(typeFlagPath.has_value());
|
||||
|
||||
const auto infos = remorse::loadTypeFlags(*typeFlagPath);
|
||||
assert(infos.has_value());
|
||||
assert(infos->size() == 2048);
|
||||
|
||||
bool foundGlobFamily = false;
|
||||
for (const remorse::ShapeTypeInfo& info : *infos) {
|
||||
if (info.family == 3) {
|
||||
foundGlobFamily = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(foundGlobFamily);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue