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.
2026-04-27 21:15:01 +02:00
# include "remorse/runtime.h"
# include <fstream>
# include <iostream>
# include <regex>
# include <sstream>
2026-09-25 21:41:20 +02:00
# ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <crtdbg.h>
# include <cstdlib>
# include <cstring>
# include <cstdio>
# include <exception>
# endif
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.
2026-04-27 21:15:01 +02:00
namespace remorse {
namespace {
2026-09-25 21:41:20 +02:00
# ifdef _WIN32
void writeCrashMessage ( const char * message )
{
OutputDebugStringA ( message ) ;
const HANDLE errorOutput = GetStdHandle ( STD_ERROR_HANDLE ) ;
if ( errorOutput ! = nullptr & & errorOutput ! = INVALID_HANDLE_VALUE ) {
DWORD written = 0 ;
WriteFile ( errorOutput , message , static_cast < DWORD > ( std : : strlen ( message ) ) , & written , nullptr ) ;
}
}
LONG WINAPI reportUnhandledException ( EXCEPTION_POINTERS * exception )
{
char message [ 160 ] ;
std : : snprintf ( message , sizeof ( message ) , " Unhandled exception 0x%08lX at %p \n " ,
exception - > ExceptionRecord - > ExceptionCode , exception - > ExceptionRecord - > ExceptionAddress ) ;
writeCrashMessage ( message ) ;
return EXCEPTION_EXECUTE_HANDLER ;
}
void reportTermination ( ) noexcept
{
try {
if ( const auto error = std : : current_exception ( ) ) {
std : : rethrow_exception ( error ) ;
}
} catch ( const std : : exception & error ) {
char message [ 512 ] ;
std : : snprintf ( message , sizeof ( message ) , " Unhandled C++ exception: %s \n " , error . what ( ) ) ;
writeCrashMessage ( message ) ;
std : : _Exit ( EXIT_FAILURE ) ;
} catch ( . . . ) {
writeCrashMessage ( " Unhandled C++ exception of unknown type \n " ) ;
std : : _Exit ( EXIT_FAILURE ) ;
}
writeCrashMessage ( " Program terminated without an active exception \n " ) ;
std : : _Exit ( EXIT_FAILURE ) ;
}
# endif
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.
2026-04-27 21:15:01 +02:00
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
2026-09-25 21:41:20 +02:00
void installCrashDiagnostics ( )
{
# ifdef _WIN32
SetErrorMode ( GetErrorMode ( ) | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX ) ;
_set_abort_behavior ( 0 , _WRITE_ABORT_MSG | _CALL_REPORTFAULT ) ;
_set_error_mode ( _OUT_TO_STDERR ) ;
# ifdef _DEBUG
_CrtSetReportMode ( _CRT_ASSERT , _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE ) ;
_CrtSetReportFile ( _CRT_ASSERT , _CRTDBG_FILE_STDERR ) ;
_CrtSetReportMode ( _CRT_ERROR , _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE ) ;
_CrtSetReportFile ( _CRT_ERROR , _CRTDBG_FILE_STDERR ) ;
# endif
SetUnhandledExceptionFilter ( reportUnhandledException ) ;
std : : set_terminate ( reportTermination ) ;
# endif
}
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.
2026-04-27 21:15:01 +02:00
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 ' ;
2026-09-25 21:41:20 +02:00
std : : cout < < " Status: StandProcess Run, registered timer, and keyboard diagnostic callback active; original key queue, NPC services, and game loop not linked. \n " ;
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.
2026-04-27 21:15:01 +02:00
}
} // namespace remorse