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,22 @@
#pragma once
#include <array>
#include <filesystem>
#include <optional>
#include <string>
#include <vector>
#include "remorse/compat.h"
namespace remorse {
struct CombatTactic {
u32 index = 0;
std::string name;
std::array<u16, 4> blockOffsets{};
std::vector<u8> bytecode;
};
std::optional<std::vector<CombatTactic>> loadCombatTactics(const std::filesystem::path& path);
} // namespace remorse

View file

@ -0,0 +1,48 @@
#pragma once
namespace remorse {
using u8 = unsigned char;
using s8 = signed char;
using u16 = unsigned short;
using s16 = signed short;
using u32 = unsigned int;
using s32 = signed int;
static_assert(sizeof(u8) == 1, "u8 must be 8 bits");
static_assert(sizeof(u16) == 2, "u16 must be 16 bits");
static_assert(sizeof(u32) == 4, "u32 must be 32 bits");
struct FarPtr16 {
u16 offset;
u16 segment;
};
template <typename T>
struct FarPtr {
u16 offset;
u16 segment;
constexpr FarPtr16 raw() const noexcept
{
return FarPtr16{offset, segment};
}
};
#if defined(_MSC_VER)
#define CR_PACK_PUSH_1 __pragma(pack(push, 1))
#define CR_PACK_POP __pragma(pack(pop))
#define CR_PACKED
#else
#define CR_PACK_PUSH_1 _Pragma("pack(push, 1)")
#define CR_PACK_POP _Pragma("pack(pop)")
#define CR_PACKED __attribute__((packed))
#endif
#define CR_CDECL
#define CR_STDCALL
#define CR_THISCALL
#define CR_FARCALL
#define CR_VSLOT(index)
} // namespace remorse

View file

@ -0,0 +1,31 @@
#pragma once
#include "remorse/compat.h"
namespace remorse {
CR_PACK_PUSH_1
struct EntityDispatchEntryBase {
u8 bytes[0x32];
} CR_PACKED;
struct EntityDispatchEntryRuntimeState {
u8 bytes[0x18];
} CR_PACKED;
CR_PACK_POP
static_assert(sizeof(EntityDispatchEntryBase) == 0x32, "EntityDispatchEntryBase size must match allocation evidence");
class EntityDispatchEntry {
public:
static constexpr u16 initBaseSegment = 0x11e0;
static constexpr u16 initBaseOffset = 0x0000;
static EntityDispatchEntryBase* initBase(EntityDispatchEntryBase* entry);
static void setGroupId(EntityDispatchEntryBase& entry, u8 groupId);
static void incrementGroupId(EntityDispatchEntryBase& entry);
static void setSourceType(EntityDispatchEntryBase& entry, u16 sourceType);
static void setEventTypeChecked(EntityDispatchEntryBase& entry, u16 eventType);
};
} // namespace remorse

View file

@ -0,0 +1,20 @@
#pragma once
#include "remorse/compat.h"
using remorse::s16;
using remorse::s32;
using remorse::s8;
using remorse::u16;
using remorse::u32;
using remorse::u8;
using undefined = u8;
using undefined1 = u8;
using undefined2 = u16;
using undefined4 = u32;
using byte = u8;
using word = u16;
using uint = unsigned int;
using ulong = unsigned long;
using dword = u32;

View file

@ -0,0 +1,24 @@
#pragma once
#include <filesystem>
#include <optional>
#include <vector>
#include "remorse/compat.h"
namespace remorse {
struct GameDataRoot {
std::filesystem::path path;
bool hasExecutable = false;
bool hasConfig = false;
bool hasStaticData = false;
bool hasUsecode = false;
};
GameDataRoot inspectGameDataRoot(const std::filesystem::path& root);
std::optional<GameDataRoot> findGameDataRoot(const std::filesystem::path& start);
std::optional<std::filesystem::path> resolveGameDataPath(const GameDataRoot& root, const std::filesystem::path& relativePath);
std::optional<std::vector<u8>> readBinaryFile(const std::filesystem::path& path);
} // namespace remorse

View file

@ -0,0 +1,37 @@
#pragma once
#include <filesystem>
#include <optional>
#include <vector>
#include "remorse/compat.h"
namespace remorse {
struct FixedMapEntry {
u16 x = 0;
u16 y = 0;
u8 z = 0;
u16 shape = 0;
u8 frame = 0;
u16 flags = 0;
u16 quality = 0;
u8 npcNumber = 0;
u8 mapNumber = 0;
u16 next = 0;
};
struct FixedMap {
u32 index = 0;
std::vector<FixedMapEntry> entries;
};
struct FixedMapArchive {
u32 mapCount = 0;
std::vector<u8> bytes;
};
std::optional<FixedMapArchive> loadFixedMapArchive(const std::filesystem::path& path);
std::optional<FixedMap> loadFixedMap(const FixedMapArchive& archive, u32 mapIndex);
} // namespace remorse

View file

@ -0,0 +1,26 @@
#pragma once
#include <filesystem>
#include <optional>
#include <vector>
#include "remorse/compat.h"
namespace remorse {
struct FlexEntry {
u32 index = 0;
u32 offset = 0;
u32 size = 0;
};
struct FlexArchive {
u32 entryCount = 0;
std::vector<FlexEntry> populatedEntries;
std::vector<u8> bytes;
};
std::optional<FlexArchive> loadFlexArchive(const std::filesystem::path& path);
std::optional<std::vector<u8>> readFlexEntry(const FlexArchive& archive, u32 index);
} // namespace remorse

View file

@ -0,0 +1,26 @@
#pragma once
#include <filesystem>
#include <optional>
#include <vector>
#include "remorse/compat.h"
namespace remorse {
struct GlobObjectEntry {
u8 x = 0;
u8 y = 0;
u8 z = 0;
u16 shape = 0;
u8 frame = 0;
};
struct GlobObject {
u32 index = 0;
std::vector<GlobObjectEntry> entries;
};
std::optional<std::vector<GlobObject>> loadGlobObjects(const std::filesystem::path& path);
} // namespace remorse

View file

@ -0,0 +1,47 @@
#pragma once
#include <filesystem>
#include <optional>
#include <vector>
#include "remorse/compat.h"
#include "remorse/file_system.h"
#include "remorse/palette.h"
namespace remorse {
struct WorldRect {
s32 minX = 0;
s32 minY = 0;
s32 maxX = 0;
s32 maxY = 0;
};
struct MapRenderOptions {
u32 mapIndex = 1;
u32 maxWidth = 1600;
u32 maxHeight = 900;
bool expandGlobs = true;
bool includeRoofs = false;
bool includeHiddenMarkers = false;
std::optional<WorldRect> worldRect;
};
struct RenderedMapImage {
u32 width = 0;
u32 height = 0;
u32 rawItemCount = 0;
u32 renderItemCount = 0;
u32 decodedItemCount = 0;
u32 paintedItemCount = 0;
s32 sourceLeft = 0;
s32 sourceTop = 0;
s32 fullWidth = 0;
s32 fullHeight = 0;
std::vector<RgbColor> pixels;
};
std::optional<RenderedMapImage> renderMapPreview(const GameDataRoot& root, const MapRenderOptions& options);
bool writeBmp24(const std::filesystem::path& path, const RenderedMapImage& image);
} // namespace remorse

View file

@ -0,0 +1,23 @@
#pragma once
#include <array>
#include <filesystem>
#include <optional>
#include "remorse/compat.h"
namespace remorse {
struct RgbColor {
u8 red = 0;
u8 green = 0;
u8 blue = 0;
};
struct Palette256 {
std::array<RgbColor, 256> colors{};
};
std::optional<Palette256> loadPalette256(const std::filesystem::path& path);
} // namespace remorse

View file

@ -0,0 +1,24 @@
#pragma once
#include <filesystem>
#include <optional>
#include <string>
#include "remorse/compat.h"
namespace remorse {
struct ExportManifestSummary {
std::string program;
std::filesystem::path outputRoot;
u32 functionFiles = 0;
u32 fallbackFunctionFiles = 0;
u32 globalBuckets = 0;
u32 globalDefinitions = 0;
};
std::optional<ExportManifestSummary> loadExportManifestSummary(const std::filesystem::path& manifestPath);
std::filesystem::path defaultManifestPath(const std::filesystem::path& currentPath);
void printStartupReport(const ExportManifestSummary& manifest);
} // namespace remorse

View file

@ -0,0 +1,35 @@
#pragma once
#include <filesystem>
#include <optional>
#include <vector>
#include "remorse/compat.h"
#include "remorse/flex_archive.h"
namespace remorse {
struct ShapeFrame {
bool compressed = false;
u32 width = 0;
u32 height = 0;
s32 xOffset = 0;
s32 yOffset = 0;
std::vector<u32> lineOffsets;
std::vector<u8> rleData;
};
struct DecodedShapeFrame {
ShapeFrame frame;
std::vector<s16> pixels;
};
struct ShapeArchive {
FlexArchive archive;
};
std::optional<ShapeArchive> loadShapeArchive(const std::filesystem::path& path);
std::optional<std::vector<ShapeFrame>> loadShapeFrames(const ShapeArchive& archive, u32 shapeIndex);
std::optional<DecodedShapeFrame> decodeShapeFrame(const ShapeArchive& archive, u32 shapeIndex, u32 frameIndex);
} // namespace remorse

View file

@ -0,0 +1,22 @@
#pragma once
#include <filesystem>
#include <optional>
#include <vector>
#include "remorse/compat.h"
namespace remorse {
struct ShapeTypeInfo {
u8 family = 0;
u32 flags = 0;
u8 x = 0;
u8 y = 0;
u8 z = 0;
u8 animationType = 0;
};
std::optional<std::vector<ShapeTypeInfo>> loadTypeFlags(const std::filesystem::path& path);
} // namespace remorse