Clean, self-contained extraction of the BattleTech-specific work from the
reverse-engineering workspace -- engine + game + content + build, with nothing
from Red Planet or the raw archive dumps. Builds green (Win32) and runs the
single-player drive->animate->target->fire->damage->destroy loop out of the box.
Layout:
engine/ MUNGA + MUNGA_L4 shared 2007 engine, carrying our BT render/loader
work (bgfload/L4D3D/L4VIDEO: BSL bit-slice decode, LOD/ground/shadow
models) + image codec; the minimal rp/ headers the audio HAL needs
game/ reconstructed BT logic + surviving-original BT source + fwd shims
+ WinMain launcher
content/ full runtime tree (BTL4.RES, VIDEO/, GAUGE/, AUDIO/, eggs, BTDPL.INI)
docs/ format specs + reconstruction ledgers
reference/ raw Ghidra pseudocode (recon source-of-truth) + decomp exporter
tools/ MP console emulator + map/resource scanners
One top-level CMake builds munga_engine lib + bt410_l4 game lib + btl4.exe.
All paths relativized (186 fwd shims + ~437 CMake abs paths -> repo-relative);
DXSDK is the one external, overridable via -DDXSDK. Verified: builds to a
byte-identical 2.27MB exe and runs combat (TARGET DESTROYED, 0 crashes) against
the bundled content.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
334 lines
6.8 KiB
C++
334 lines
6.8 KiB
C++
#pragma once
|
|
|
|
#include "memstrm.h"
|
|
#include "node.h"
|
|
#include "hash.h"
|
|
#include "tree.h"
|
|
#include "cstr.h"
|
|
|
|
class NotationFile;
|
|
class NameList;
|
|
class CString;
|
|
class ResourceFile;
|
|
class ResourceDescription;
|
|
|
|
//##########################################################################
|
|
//######################### ObjectStream #############################
|
|
//##########################################################################
|
|
|
|
class ObjectStream:
|
|
public DynamicMemoryStream
|
|
{
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Construction, Destruction and testing
|
|
//
|
|
public:
|
|
ObjectStream();
|
|
ObjectStream(
|
|
void *stream_start,
|
|
size_t stream_size
|
|
);
|
|
ObjectStream(ResourceDescription *resource_description);
|
|
~ObjectStream();
|
|
|
|
Logical
|
|
TestInstance() const;
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Object creation
|
|
//
|
|
public:
|
|
virtual void
|
|
CreateObjects();
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Notation file parsing
|
|
//
|
|
public:
|
|
virtual void
|
|
BuildFromNotationFile(
|
|
NotationFile *notation_file,
|
|
ResourceFile *resource_file
|
|
);
|
|
|
|
ResourceFile*
|
|
GetResourceFile()
|
|
{return resourceFile;}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Object ID generation
|
|
//
|
|
protected:
|
|
static ObjectID
|
|
MakeUniqueObjectID();
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Implementations
|
|
//
|
|
protected:
|
|
virtual RegisteredClass*
|
|
MakeObjectImplementation(Enumeration class_ID);
|
|
|
|
virtual void
|
|
CreatedObjectImplementation(
|
|
RegisteredClass *object,
|
|
ObjectID object_ID
|
|
);
|
|
|
|
virtual void
|
|
BuildFromPageImplementation(
|
|
NameList *name_list,
|
|
Enumeration class_ID,
|
|
ObjectID object_ID
|
|
);
|
|
|
|
virtual void
|
|
BuiltFromPageImplementation(
|
|
Enumeration class_ID,
|
|
ObjectID object_ID,
|
|
const CString &object_name_string
|
|
);
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Private methods
|
|
//
|
|
private:
|
|
void
|
|
ParseNotationFile(NotationFile *notation_file);
|
|
void
|
|
ReadIncludedFiles(NameList *entry_list);
|
|
void
|
|
ReadMacros(NameList *entry_list);
|
|
|
|
void
|
|
PerformMacroReplacement(NameList *entry_list);
|
|
CString
|
|
DeriveMacroValue(const CString &token_string);
|
|
void
|
|
CleanupMacroReplacement(NameList *entry_list);
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Private data
|
|
//
|
|
private:
|
|
typedef PlugOf<CString>
|
|
MacroValue;
|
|
typedef TreeOf<MacroValue*, CString>
|
|
MacroSocket;
|
|
typedef TreeIteratorOf<MacroValue*, CString>
|
|
MacroIterator;
|
|
|
|
static ObjectID
|
|
lastObjectID;
|
|
ResourceFile
|
|
*resourceFile;
|
|
MacroSocket
|
|
*macroSocket;
|
|
};
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ObjectIDPlug ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
typedef PlugOf<ObjectID>
|
|
ObjectIDPlug;
|
|
|
|
//##########################################################################
|
|
//###################### PlugStreamManager ###########################
|
|
//##########################################################################
|
|
|
|
class PlugStreamManager:
|
|
public Node
|
|
{
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Plug stream types
|
|
//
|
|
public:
|
|
typedef HashOf<Plug*, ObjectID>
|
|
PlugIndex;
|
|
|
|
typedef TreeOf<ObjectIDPlug*, CString>
|
|
ObjectIDIndex;
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Construction, Destruction and testing
|
|
//
|
|
public:
|
|
PlugStreamManager();
|
|
~PlugStreamManager();
|
|
|
|
Logical
|
|
TestInstance() const;
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Program termination
|
|
//
|
|
public:
|
|
void
|
|
Cleanup();
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Manager Accessors
|
|
//
|
|
public:
|
|
static void
|
|
AddPlug(
|
|
Plug *plug,
|
|
ObjectID object_ID
|
|
);
|
|
|
|
static Plug*
|
|
FindPlug(ObjectID object_ID);
|
|
|
|
static void
|
|
AddPlugName(
|
|
ObjectID object_ID,
|
|
const CString &object_name_string
|
|
);
|
|
|
|
static ObjectID
|
|
FindPlugName(const CString &object_name_string);
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Private data
|
|
//
|
|
private:
|
|
PlugIndex
|
|
plugIndex;
|
|
ObjectIDIndex
|
|
objectIDIndex;
|
|
|
|
static PlugStreamManager
|
|
plugStreamManager;
|
|
};
|
|
|
|
//##########################################################################
|
|
//########################## PlugStream ##############################
|
|
//##########################################################################
|
|
|
|
class PlugStream:
|
|
public ObjectStream
|
|
{
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Plug stream types
|
|
//
|
|
public:
|
|
typedef VChainOf<Plug*, ObjectID>
|
|
LocalPlugIndex;
|
|
|
|
typedef VChainOf<ObjectIDPlug*, CString>
|
|
LocalObjectIDIndex;
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Construction, Destruction and testing
|
|
//
|
|
public:
|
|
PlugStream();
|
|
PlugStream(
|
|
void *stream_start,
|
|
size_t stream_size
|
|
);
|
|
PlugStream(ResourceDescription *resource_description);
|
|
~PlugStream();
|
|
|
|
Logical
|
|
TestInstance() const;
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Object creation and utilities
|
|
//
|
|
public:
|
|
void
|
|
CreateObjects();
|
|
|
|
void
|
|
AddLocalPlug(
|
|
Plug *plug,
|
|
ObjectID object_ID
|
|
);
|
|
|
|
void
|
|
AddGlobalPlug(
|
|
Plug *plug,
|
|
ObjectID object_ID
|
|
);
|
|
|
|
Plug*
|
|
FindPlug(ObjectID object_ID);
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Notation file parsing
|
|
//
|
|
public:
|
|
void
|
|
BuildFromNotationFile(
|
|
NotationFile *notation_file,
|
|
ResourceFile *resource_file
|
|
);
|
|
|
|
void
|
|
AddLocalObjectID(
|
|
ObjectID object_ID,
|
|
const CString &object_name_string
|
|
);
|
|
|
|
void
|
|
AddGlobalObjectID(
|
|
ObjectID object_ID,
|
|
const CString &object_name_string
|
|
);
|
|
|
|
ObjectID
|
|
FindObjectID(const CString &object_name_string);
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Implementations
|
|
//
|
|
protected:
|
|
void
|
|
CreatedObjectImplementation(
|
|
RegisteredClass *object,
|
|
ObjectID object_ID
|
|
);
|
|
|
|
void
|
|
BuiltFromPageImplementation(
|
|
Enumeration class_ID,
|
|
ObjectID object_ID,
|
|
const CString &object_name_string
|
|
);
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Private data
|
|
//
|
|
private:
|
|
LocalPlugIndex
|
|
*localPlugIndex;
|
|
LocalObjectIDIndex
|
|
*localObjectIDIndex;
|
|
};
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PlugStream functions ~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
template <class T> void
|
|
PlugStream_ReadObjectIDAndFindPlug(
|
|
PlugStream *stream,
|
|
T** type_pointer
|
|
)
|
|
{
|
|
Check(stream);
|
|
Check_Pointer(type_pointer);
|
|
|
|
ObjectID object_ID;
|
|
Plug *plug;
|
|
|
|
MemoryStream_Read(stream, &object_ID);
|
|
plug = stream->FindPlug(object_ID);
|
|
*type_pointer = Cast_Object(T*, plug);
|
|
}
|
|
|
|
void
|
|
PlugStream_FindEntryAndWriteObjectID(
|
|
PlugStream *stream,
|
|
NameList *name_list,
|
|
const CString &entry_name
|
|
);
|