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/file_system.h"
|
2026-09-25 21:41:20 +02:00
|
|
|
#include "remorse/runtime.h"
|
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 <cassert>
|
2026-09-25 21:41:20 +02:00
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <exception>
|
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 <filesystem>
|
2026-09-25 21:41:20 +02:00
|
|
|
#include <stdexcept>
|
|
|
|
|
#include <string>
|
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
|
|
|
|
2026-09-25 21:41:20 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
#include <crtdbg.h>
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
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
|
|
|
{
|
2026-09-25 21:41:20 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
if (argc == 2 && std::strcmp(argv[1], "--crash-probe") == 0) {
|
|
|
|
|
remorse::installCrashDiagnostics();
|
|
|
|
|
try {
|
|
|
|
|
throw std::runtime_error("diagnostic probe");
|
|
|
|
|
} catch (...) {
|
|
|
|
|
std::terminate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#ifdef _DEBUG
|
Add comprehensive tests for entity dispatch, file system, fixed map, flex archive, isometric controls, and crash setup
- Enhance `entity_dispatch_entry_tests.cpp` with additional assertions for event type checks, group ID increments, and error handling.
- Refactor `file_system_tests.cpp` to streamline probe execution and enhance output validation.
- Extend `fixed_map_tests.cpp` to cover retail map loading, item classification, and process creation scenarios.
- Introduce new checks in `flex_archive_tests.cpp` for usecode loading and event handling, ensuring robust validation of game data.
- Add tests in `isometric_controls_tests.cpp` for controller direction mapping based on scan codes.
- Implement `test_crash_setup.cpp` to initialize crash diagnostics for improved error handling during tests.
2026-09-26 15:36:11 +02:00
|
|
|
if (argc == 2 && std::strcmp(argv[1], "--assert-probe") == 0) {
|
|
|
|
|
assert(false && "diagnostic assert probe");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2026-09-25 21:41:20 +02:00
|
|
|
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_WNDW);
|
|
|
|
|
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW);
|
|
|
|
|
#endif
|
|
|
|
|
remorse::installCrashDiagnostics();
|
|
|
|
|
assert((GetErrorMode() & SEM_NOGPFAULTERRORBOX) != 0);
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
assert((_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_REPORT_MODE) & _CRTDBG_MODE_WNDW) == 0);
|
|
|
|
|
assert((_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_REPORT_MODE) & _CRTDBG_MODE_DEBUG) != 0);
|
|
|
|
|
assert((_CrtSetReportMode(_CRT_ERROR, _CRTDBG_REPORT_MODE) & _CRTDBG_MODE_WNDW) == 0);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
wchar_t executable[MAX_PATH]{};
|
|
|
|
|
if (GetModuleFileNameW(nullptr, executable, MAX_PATH) == 0) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
Add comprehensive tests for entity dispatch, file system, fixed map, flex archive, isometric controls, and crash setup
- Enhance `entity_dispatch_entry_tests.cpp` with additional assertions for event type checks, group ID increments, and error handling.
- Refactor `file_system_tests.cpp` to streamline probe execution and enhance output validation.
- Extend `fixed_map_tests.cpp` to cover retail map loading, item classification, and process creation scenarios.
- Introduce new checks in `flex_archive_tests.cpp` for usecode loading and event handling, ensuring robust validation of game data.
- Add tests in `isometric_controls_tests.cpp` for controller direction mapping based on scan codes.
- Implement `test_crash_setup.cpp` to initialize crash diagnostics for improved error handling during tests.
2026-09-26 15:36:11 +02:00
|
|
|
auto runProbe = [&](const wchar_t* option, const char* expectedOutput, bool expectExitOne) {
|
|
|
|
|
std::wstring commandLine = L"\"" + std::wstring(executable) + L"\" " + option;
|
|
|
|
|
SECURITY_ATTRIBUTES pipeSecurity{sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE};
|
|
|
|
|
HANDLE readPipe = nullptr;
|
|
|
|
|
HANDLE writePipe = nullptr;
|
|
|
|
|
if (!CreatePipe(&readPipe, &writePipe, &pipeSecurity, 0)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!SetHandleInformation(readPipe, HANDLE_FLAG_INHERIT, 0)) {
|
|
|
|
|
CloseHandle(readPipe);
|
|
|
|
|
CloseHandle(writePipe);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
STARTUPINFOW startup{};
|
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
|
startup.dwFlags = STARTF_USESTDHANDLES;
|
|
|
|
|
startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
|
startup.hStdOutput = writePipe;
|
|
|
|
|
startup.hStdError = writePipe;
|
|
|
|
|
PROCESS_INFORMATION child{};
|
|
|
|
|
if (!CreateProcessW(nullptr, commandLine.data(), nullptr, nullptr, TRUE, CREATE_NO_WINDOW,
|
|
|
|
|
nullptr, nullptr, &startup, &child)) {
|
|
|
|
|
CloseHandle(readPipe);
|
|
|
|
|
CloseHandle(writePipe);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-09-25 21:41:20 +02:00
|
|
|
CloseHandle(writePipe);
|
Add comprehensive tests for entity dispatch, file system, fixed map, flex archive, isometric controls, and crash setup
- Enhance `entity_dispatch_entry_tests.cpp` with additional assertions for event type checks, group ID increments, and error handling.
- Refactor `file_system_tests.cpp` to streamline probe execution and enhance output validation.
- Extend `fixed_map_tests.cpp` to cover retail map loading, item classification, and process creation scenarios.
- Introduce new checks in `flex_archive_tests.cpp` for usecode loading and event handling, ensuring robust validation of game data.
- Add tests in `isometric_controls_tests.cpp` for controller direction mapping based on scan codes.
- Implement `test_crash_setup.cpp` to initialize crash diagnostics for improved error handling during tests.
2026-09-26 15:36:11 +02:00
|
|
|
const DWORD waitResult = WaitForSingleObject(child.hProcess, 5000);
|
|
|
|
|
if (waitResult == WAIT_TIMEOUT) {
|
|
|
|
|
TerminateProcess(child.hProcess, 2);
|
|
|
|
|
WaitForSingleObject(child.hProcess, INFINITE);
|
|
|
|
|
}
|
|
|
|
|
char buffer[512];
|
|
|
|
|
DWORD count = 0;
|
|
|
|
|
std::string crashOutput;
|
|
|
|
|
while (ReadFile(readPipe, buffer, sizeof(buffer), &count, nullptr) && count != 0) {
|
|
|
|
|
crashOutput.append(buffer, count);
|
|
|
|
|
}
|
|
|
|
|
DWORD exitCode = 0;
|
|
|
|
|
const BOOL gotExitCode = GetExitCodeProcess(child.hProcess, &exitCode);
|
2026-09-25 21:41:20 +02:00
|
|
|
CloseHandle(readPipe);
|
Add comprehensive tests for entity dispatch, file system, fixed map, flex archive, isometric controls, and crash setup
- Enhance `entity_dispatch_entry_tests.cpp` with additional assertions for event type checks, group ID increments, and error handling.
- Refactor `file_system_tests.cpp` to streamline probe execution and enhance output validation.
- Extend `fixed_map_tests.cpp` to cover retail map loading, item classification, and process creation scenarios.
- Introduce new checks in `flex_archive_tests.cpp` for usecode loading and event handling, ensuring robust validation of game data.
- Add tests in `isometric_controls_tests.cpp` for controller direction mapping based on scan codes.
- Implement `test_crash_setup.cpp` to initialize crash diagnostics for improved error handling during tests.
2026-09-26 15:36:11 +02:00
|
|
|
CloseHandle(child.hThread);
|
|
|
|
|
CloseHandle(child.hProcess);
|
|
|
|
|
const bool passed = gotExitCode && waitResult == WAIT_OBJECT_0 &&
|
|
|
|
|
(expectExitOne ? exitCode == 1 : exitCode != 0) &&
|
|
|
|
|
crashOutput.find(expectedOutput) != std::string::npos;
|
|
|
|
|
if (!passed) {
|
|
|
|
|
std::fprintf(stderr, "Probe %ls wait=%lu exit=0x%08lX output=%s\n",
|
|
|
|
|
option, waitResult, exitCode, crashOutput.c_str());
|
|
|
|
|
}
|
|
|
|
|
return passed;
|
|
|
|
|
};
|
|
|
|
|
if (!runProbe(L"--crash-probe", "Unhandled C++ exception: diagnostic probe", true)
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
|| !runProbe(L"--assert-probe", "diagnostic assert probe", false)
|
|
|
|
|
#endif
|
|
|
|
|
) {
|
2026-09-25 21:41:20 +02:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
#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
|
|
|
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;
|
|
|
|
|
}
|