From 091dd18d9eaad28818140628d3b1b23d2d275028 Mon Sep 17 00:00:00 2001 From: ulw-execute Date: Sat, 28 Nov 2026 03:42:33 -0500 Subject: [PATCH] chore(repo): layered source tree + CMake mingw toolchain + gamekdm.def --- .gitignore | 7 ++++- CMakeLists.txt | 31 ++++++++++++++++++++++ LICENSE | 14 ++++++++++ cmake/toolchain-mingw-i686.cmake | 38 +++++++++++++++++++++++++++ docs/provenance.md | 21 +++++++++++++++ export/gamekdm.def | 3 +++ include/abi/.gitkeep | 0 include/gk/manager.h | 6 +++++ include/gk/structs/.gitkeep | 0 include/gk/types.h | 45 ++++++++++++++++++++++++++++++++ orig/.gitkeep | 0 src/entry/gamemain.cpp | 6 +++++ src/game/.gitkeep | 0 src/gs/.gitkeep | 0 src/mm/.gitkeep | 0 src/movie/.gitkeep | 0 src/particle/.gitkeep | 0 src/platform/.gitkeep | 0 src/render/.gitkeep | 0 src/ui/.gitkeep | 0 src/util/.gitkeep | 0 tools/.gitkeep | 0 22 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 cmake/toolchain-mingw-i686.cmake create mode 100644 docs/provenance.md create mode 100644 export/gamekdm.def create mode 100644 include/abi/.gitkeep create mode 100644 include/gk/manager.h create mode 100644 include/gk/structs/.gitkeep create mode 100644 include/gk/types.h create mode 100644 orig/.gitkeep create mode 100644 src/entry/gamemain.cpp create mode 100644 src/game/.gitkeep create mode 100644 src/gs/.gitkeep create mode 100644 src/mm/.gitkeep create mode 100644 src/movie/.gitkeep create mode 100644 src/particle/.gitkeep create mode 100644 src/platform/.gitkeep create mode 100644 src/render/.gitkeep create mode 100644 src/ui/.gitkeep create mode 100644 src/util/.gitkeep create mode 100644 tools/.gitkeep diff --git a/.gitignore b/.gitignore index 72264f6..6c6c39a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,15 @@ .omo/ build/ -orig/ +orig/* +!orig/.gitkeep *.dll *.a *.o *.exe +*.i64 +*.idb +*.asm.txt +decompiled/ .venv/ venv/ __pycache__/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9fe22af --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.16) +project(gamekdm LANGUAGES C CXX) + +# 32-bit Windows DLL, built with the pinned i686-w64-mingw32 cross toolchain +# (see cmake/toolchain-mingw-i686.cmake, toolchain.lock). The real shipping +# gamekdm.dll's reconstructed source lands in src/* over subsequent tasks; +# today's target is a minimal stub so the layered tree + build + export +# table shape is proven before any real logic is reconstructed. + +add_library(gamekdm SHARED + src/entry/gamemain.cpp +) + +target_include_directories(gamekdm PRIVATE + ${CMAKE_SOURCE_DIR}/include +) + +set_target_properties(gamekdm PROPERTIES + OUTPUT_NAME "gamekdm" + PREFIX "" + SUFFIX ".dll" +) + +# Link with the hand-authored .def so ONLY gameMain is exported, at ordinal 1, +# matching the original DLL's export table (no CRT/C++ name-mangled exports). +target_link_options(gamekdm PRIVATE + "${CMAKE_SOURCE_DIR}/export/gamekdm.def" +) +set_target_properties(gamekdm PROPERTIES + LINK_DEPENDS "${CMAKE_SOURCE_DIR}/export/gamekdm.def" +) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5011e9b --- /dev/null +++ b/LICENSE @@ -0,0 +1,14 @@ +All Rights Reserved (placeholder, unlicensed) + +Copyright (c) 2026, the repository owner. All rights reserved. + +This repository's reconstructed source is PRIVATE and UNLICENSED for the +time being. No license to use, copy, modify, merge, publish, distribute, +sublicense, or sell any part of this repository is granted. The final +license for this project (if any) has not yet been decided by the owner. + +No third-party license text is incorporated into this file or this +repository by virtue of this placeholder. + +See docs/provenance.md for the origin of the reconstructed source and the +handling of original game binaries. diff --git a/cmake/toolchain-mingw-i686.cmake b/cmake/toolchain-mingw-i686.cmake new file mode 100644 index 0000000..87229f7 --- /dev/null +++ b/cmake/toolchain-mingw-i686.cmake @@ -0,0 +1,38 @@ +# CMake cross-compilation toolchain file for the Windows (32-bit) build of +# gamekdm.dll, targeting i686-w64-mingw32 with the pinned no-sudo Nix toolchain +# recorded in ../toolchain.lock (GCC 16.2.0, mingw-w64 14.0.0 headers/CRT). +# +# Usage (after `source ./activate.sh` to put the cross toolchain on PATH): +# cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-mingw-i686.cmake +# cmake --build build +# +# Pattern reused/adapted from ~/kinect/cmake/mingw-w64.cmake, fixed to the +# i686 (32-bit) target that matches the shipping gamekdm.dll's bitness +# (confirmed PE32 by `objdump -f` on the stub build; see task-2.log). + +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_SYSTEM_PROCESSOR x86) + +set(_gk_mingw_prefix i686-w64-mingw32) +set(CMAKE_C_COMPILER ${_gk_mingw_prefix}-gcc) +set(CMAKE_CXX_COMPILER ${_gk_mingw_prefix}-g++) +set(CMAKE_RC_COMPILER ${_gk_mingw_prefix}-windres) +set(CMAKE_RC_COMPILER_INIT ${_gk_mingw_prefix}-windres) + +find_program(CMAKE_DLLTOOL NAMES ${_gk_mingw_prefix}-dlltool dlltool) + +set(CMAKE_FIND_ROOT_PATH /usr/${_gk_mingw_prefix}) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +# GCC 16.2.0's i686-w64-mingw32 default link spec needs -lmcfgthread, which +# ships as its own Nix package (pkgsCross.mingw32.windows.mcfgthreads) rather +# than bundled with the gcc derivation itself; point the linker at its lib +# dir explicitly for every link (shared libs/DLLs and any executables alike). +# Store path pinned in ../toolchain.lock; keep in sync if the pin moves. +set(_gk_mcfgthread_lib "/nix/store/g72bh3mrbh6gkh59axd2199js9kccxfs-mcfgthread-i686-w64-mingw32-2.5.1/lib") + +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${_gk_mcfgthread_lib}") +set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${_gk_mcfgthread_lib}") +set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -L${_gk_mcfgthread_lib}") diff --git a/docs/provenance.md b/docs/provenance.md new file mode 100644 index 0000000..553dd40 --- /dev/null +++ b/docs/provenance.md @@ -0,0 +1,21 @@ +# Provenance + +This repository reconstructs source for `gamekdm.dll` as part of a +game-preservation / reverse-engineering effort. The reconstructed C/C++ +source under `src/` and `include/` is derived from static and dynamic +analysis (disassembly, decompiler output, runtime tracing) of a binary the +repository owner legally possesses. + +- `orig/` is where the original game binary (and any other original game + files needed as reconstruction input) is placed locally. It is gitignored + (except for its `.gitkeep` placeholder) and is never committed. +- Decompiler-generated intermediate dumps (disassembly listings, decompiler + project databases, raw pseudocode dumps) are working inputs only; they are + kept out of git (see `.gitignore`) and are not treated as the + authoritative source. The hand-reviewed, hand-named reconstruction checked + into `src/`/`include/` is authoritative. +- No original game binary, asset, or third-party copyrighted material is + ever committed to this repository. +- Licensing for this project's own reconstructed source is **TBD**: see + `LICENSE` for the current private/all-rights-reserved placeholder. The + owner has not yet decided on a final license. diff --git a/export/gamekdm.def b/export/gamekdm.def new file mode 100644 index 0000000..1c119b2 --- /dev/null +++ b/export/gamekdm.def @@ -0,0 +1,3 @@ +LIBRARY "gamekdm.dll" +EXPORTS + gameMain @1 diff --git a/include/abi/.gitkeep b/include/abi/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/include/gk/manager.h b/include/gk/manager.h new file mode 100644 index 0000000..7562167 --- /dev/null +++ b/include/gk/manager.h @@ -0,0 +1,6 @@ +#pragma once +// TODO(T7): the live manager struct (the central game-state/subsystem +// registry gamekdm.dll's entry point builds up and hands to subsystems) is +// reconstructed from static/dynamic analysis of orig/gamekdm.dll in task T7. +// This header is a placeholder so later tasks have a stable include path +// (include/gk/manager.h) to populate without reshuffling src/ includes. diff --git a/include/gk/structs/.gitkeep b/include/gk/structs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/include/gk/types.h b/include/gk/types.h new file mode 100644 index 0000000..8bd7dce --- /dev/null +++ b/include/gk/types.h @@ -0,0 +1,45 @@ +#pragma once +// gamekdm reconstructed-source types: fixed-width integer includes and +// MSVC-matching calling-convention / layout macros. The original gamekdm.dll +// was built with MSVC (cl.exe) for 32-bit Windows (__cdecl default, but many +// internal entry points/vtables use __stdcall or __thiscall); GCC/MinGW is +// ABI-compatible with these calling conventions on i686, so the macros below +// just name the convention explicitly at each declaration site so a reader +// (and a future llvm-mingw/clang-cl cross-check) can see which ABI a given +// function uses without guessing. + +#include +#include + +#if defined(__GNUC__) +# define GK_CDECL __attribute__((cdecl)) +# define GK_STDCALL __attribute__((stdcall)) +# define GK_THISCALL __attribute__((thiscall)) +#elif defined(_MSC_VER) +# define GK_CDECL __cdecl +# define GK_STDCALL __stdcall +# define GK_THISCALL __thiscall +#else +# error "gk/types.h: unsupported compiler for calling-convention macros" +#endif + +// MSVC-matching struct packing guidance: +// +// The original binary was compiled by MSVC with its default struct packing +// (natural alignment, i.e. #pragma pack(8) equivalent on x86 unless the +// source explicitly set a tighter pack). Any reconstructed struct in +// include/gk/structs/ that must match the original's binary layout (parsed +// from the binary via static/dynamic analysis in later tasks) MUST either: +// 1. rely on natural alignment matching MSVC's default (true for most +// int/float/pointer-only structs on x86), or +// 2. bracket itself with an explicit pack pragma reproducing MSVC's pack +// state at that point in the original translation unit, e.g.: +// +// #pragma pack(push, 1) +// struct SomePackedThing { /* ... */ }; +// #pragma pack(pop) +// +// GCC/Clang both honor `#pragma pack` identically to MSVC, so no GK_PACK_* +// macro is introduced here; use the pragma directly at each struct that +// needs it, and comment the source of the packing evidence (e.g. "offsets +// confirmed via Ghidra struct editor on orig/gamekdm.dll"). diff --git a/orig/.gitkeep b/orig/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/entry/gamemain.cpp b/src/entry/gamemain.cpp new file mode 100644 index 0000000..ff275fe --- /dev/null +++ b/src/entry/gamemain.cpp @@ -0,0 +1,6 @@ +#include "gk/types.h" + +extern "C" int gameMain(void* hInstance) { + (void)hInstance; + return 0; +} diff --git a/src/game/.gitkeep b/src/game/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/gs/.gitkeep b/src/gs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/mm/.gitkeep b/src/mm/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/movie/.gitkeep b/src/movie/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/particle/.gitkeep b/src/particle/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/platform/.gitkeep b/src/platform/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/render/.gitkeep b/src/render/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/ui/.gitkeep b/src/ui/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/util/.gitkeep b/src/util/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tools/.gitkeep b/tools/.gitkeep new file mode 100644 index 0000000..e69de29