An 8-agent decomp-mapping workflow mapped every weapon-family ctor + fire/spawn path
(scratchpad/wave7_maps.txt). KEY IDENTITY CORRECTION via VDATA.h enum (base 3000=0xBB8):
the factory ctor-address comments were right but the built CLASS names were stubs/base --
0xBCD == ProjectileWeapon (was building the base MechWeapon stub)
0xBCE == GaussRifle (NOT MissileLauncher -- was a MissileLauncher stub)
0xBD0 == MissileLauncher (NOT BallisticWeapon -- was a BallisticWeapon stub)
Un-mislabeled + wired via Create<Class>Subsystem bridges (mirroring CreateEmitterSubsystem),
each static_assert-locked byte-exact on the now-locked MechWeapon(0x3F0)/Emitter(0x478) bases:
* ProjectileWeapon (0xBCD, @4bc3fc : MechWeapon, sizeof 0x448)
FIX: AmmoBinConnection was an empty 1-byte struct -> retyped to the binary's 0xC
SharedData::Connection (was making the object 8 bytes short, sliding
MissileLauncher's missileCount off 0x448).
* MissileLauncher (0xBD0, @4bcff0 : ProjectileWeapon, sizeof 0x44C)
FIX: deleted muzzleVelocity (ALIAS of inherited ProjectileWeapon launchVelocity@0x410)
and salvoCount (SHADOW of inherited MechWeapon damageData.burstCount@0x3d4),
keeping the single own field missileCount@0x448.
* GaussRifle (0xBCE, @4bdcb4 : Emitter, sizeof 0x484 = Emitter + Vector3D muzzleVelocity)
DEDICATED bridge (not CreateEmitter): its FireWeapon is a no-op (mov [eax+0x414],0) --
a non-functional weapon in this 1995 build. Also fixed GAUSS.CPP's discharge write
rechargeLevel -> currentLevel@0x414 (the binary writes this+0x414).
Phase A safe-stubs FireWeapon (consume round + recoil, NO spawn): the reconstructed
Projectile (@4be1bc, 0x340) + Missile (@4bf5b4, 0x368) ENTITY classes are NOT spawn-ready
(Entity-base phantom members overflow their New() alloc -> heap corruption; New() takes
(int)this instead of the 0xD4 descriptor; Entity base size unconfirmed 2007-vs-1995, the
Mech 0x638-vs-0x854 problem). The workflow's adversarial verify flagged the live spawn as a
heap-overflow hazard and recommended exactly this phasing. Phase B = the entity byte-exactness
+ descriptor build + New(MakeMessage*) so a fired shot becomes a flying entity that damages.
Factory now 18 of 20 cases wired to real ticking classes (remaining: SubsystemMessageManager
0xBD3 [WAVE 8], Gyroscope 0xBC4 [deferred]). Verified: Mad Cat (LRM/ballistic) + BLH construct
the real weapon classes + tick authentic charge/ammo/heat/recoil, DESTROYED-in-8, 0 crashes,
heapcheck-clean through construction. Energy weapons already damage via the mech4 beam path,
so combat is unaffected.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
281 lines
12 KiB
C++
281 lines
12 KiB
C++
//============================================================================//
|
|
// File: mislanch.cpp //
|
|
// Project: BattleTech //
|
|
// Contents: Weapon Which Launches a missile (MissileLauncher : ProjectileWeapon)//
|
|
//----------------------------------------------------------------------------//
|
|
// Copyright (C) 1995, Virtual World Entertainment, Inc. All Rights reserved //
|
|
// PROPRIETARY AND CONFIDENTIAL //
|
|
//============================================================================//
|
|
//
|
|
// RECONSTRUCTED from the shipped binary. Behaviour follows the Ghidra
|
|
// pseudo-C in part_013.c; member / method names follow the surviving
|
|
// MISLANCH.HPP, the resource-parser tag strings, and the reconstructed
|
|
// mechweap.hpp / heat.hpp siblings. Each non-trivial method cites the
|
|
// originating @ADDR.
|
|
//
|
|
// Class map for the projectile-weapon branch (resolved from vtable + ctor
|
|
// chaining + CreateStreamedSubsystem resource strings):
|
|
// ProjectileWeapon ctor @004bc3fc dtor @004bc688 vtable @0051242c
|
|
// CSS @004bc7cc (TracerInterval, AmmoBin,
|
|
// MinTimeOfFlight, MinJamChance,
|
|
// MinVoltagePercentToFire)
|
|
// MissileLauncher ctor @004bcff0 dtor @004bd060 vtable @00512570
|
|
// CSS @004bd08c (MissileCount, MuzzleVelocity)
|
|
//
|
|
// ProjectileWeapon (base) member offsets used below:
|
|
// @0x3ac this[0xeb] damageAmount (divided by missileCount in ctor)
|
|
// @0x3d4 this[0xf5] per-salvo count copy
|
|
// @0x3f0 this[0xfc] MinTimeOfFlight timer base
|
|
// @0x3fc this[0xff] MinJamChance
|
|
// @0x404 this[0x101] MinVoltagePercentToFire
|
|
// @0x40c this[0x103] MinTimeOfFlight
|
|
// @0x410 this[0x104] (MissileLauncher) muzzleVelocity (Vector3D)
|
|
// @0x418 this[0x106] jam-chance-derived scalar
|
|
// @0x438 this[0x10e] TracerInterval
|
|
// @0x43c this[0x10f] AmmoBin SharedData connection (FUN_004bcbb0)
|
|
// @0x448 this[0x112] (MissileLauncher) missileCount
|
|
//
|
|
// Helper-function name mapping:
|
|
// FUN_004bc3fc ProjectileWeapon base constructor
|
|
// FUN_004bc7cc ProjectileWeapon::CreateStreamedSubsystem
|
|
// FUN_004bcbb0 AmmoBin-connection ctor (SharedData, vtable @00512424)
|
|
// FUN_004b964c MechWeapon::TakeDamage FUN_004b9690 WriteUpdateRecord
|
|
// FUN_004bcabc ProjectileWeapon::HandleMessage (msg 2 -> jam alarm)
|
|
// FUN_004bc6c8 ProjectileWeapon::PrintState (Jammed/NoAmmo/Trigger...)
|
|
// FUN_004bcc60 spawn-a-Missile (FireWeapon path) FUN_004bf8bc Missile::New
|
|
// FUN_00408440 Point3D/Vector3D copy FUN_00404088/004040d8 resource get str/int
|
|
// FUN_00404088 ResourceFile::GetString FUN_00408944 parse Vector3D from text
|
|
// FUN_004084fc Vector3D approx-equal FUN_004dbb24 error-string append
|
|
//
|
|
|
|
#include <bt.hpp>
|
|
#pragma hdrstop
|
|
|
|
#if !defined(MISLANCH_HPP)
|
|
# include <mislanch.hpp>
|
|
#endif
|
|
#if !defined(MISSILE_HPP)
|
|
# include <missile.hpp>
|
|
#endif
|
|
#if !defined(AMMOBIN_HPP)
|
|
# include <ammobin.hpp>
|
|
#endif
|
|
#if !defined(TESTBT_HPP)
|
|
# include <testbt.hpp>
|
|
#endif
|
|
|
|
//###########################################################################
|
|
//###########################################################################
|
|
// MissileLauncher
|
|
//###########################################################################
|
|
//###########################################################################
|
|
|
|
//#############################################################################
|
|
// Shared Data Support
|
|
//
|
|
Derivation
|
|
MissileLauncher::ClassDerivations(
|
|
&ProjectileWeapon::ClassDerivations,
|
|
"MissileLauncher"
|
|
);
|
|
|
|
Receiver::MessageHandlerSet MissileLauncher::MessageHandlers;
|
|
Simulation::AttributeIndexSet MissileLauncher::AttributeIndex;
|
|
|
|
MissileLauncher::SharedData
|
|
MissileLauncher::DefaultData(
|
|
&MissileLauncher::ClassDerivations,
|
|
MissileLauncher::MessageHandlers,
|
|
MissileLauncher::AttributeIndex,
|
|
MissileLauncher::StateCount
|
|
);
|
|
|
|
//#############################################################################
|
|
// Construction
|
|
//
|
|
// @004bcff0 MissileLauncher::MissileLauncher(...)
|
|
//
|
|
// Chains the ProjectileWeapon base ctor, stamps the MissileLauncher vtable,
|
|
// then reads the two launcher resource fields and splits the damage budget
|
|
// evenly across the salvo so each spawned Missile carries
|
|
// damageAmount/missileCount.
|
|
//
|
|
MissileLauncher::MissileLauncher(
|
|
Mech *owner,
|
|
int subsystem_ID,
|
|
SubsystemResource *subsystem_resource,
|
|
SharedData &default_data)
|
|
:
|
|
// ProjectileWeapon base ctor (ammo bin, jam, tracer, targeting).
|
|
ProjectileWeapon(owner, subsystem_ID, subsystem_resource, default_data) // @004bc3fc
|
|
{
|
|
// vtable installed by the compiler (PTR_FUN_00512570)
|
|
|
|
missileCount = subsystem_resource->missileCount; // @0x448 resource +0x1d0
|
|
launchVelocity = subsystem_resource->muzzleVelocity; // @0x410 (inherited ProjectileWeapon slot; was aliased "muzzleVelocity")
|
|
|
|
// per-salvo count copy + per-missile damage (write the inherited Damage fields)
|
|
this->damageData.burstCount = missileCount; // @0x3d4 this[0xf5] (was shadow "salvoCount")
|
|
this->damageData.damageAmount /= (Scalar)missileCount; // @0x3ac this[0xeb] /= missileCount
|
|
}
|
|
|
|
//#############################################################################
|
|
// Destruction
|
|
//
|
|
// @004bd060 ~MissileLauncher() -- restores the launcher vtable, chains the
|
|
// ProjectileWeapon destructor (which releases the AmmoBin connection @00512424).
|
|
//
|
|
MissileLauncher::~MissileLauncher()
|
|
{
|
|
// vtable reset + base ~ProjectileWeapon chaining handled by the compiler.
|
|
}
|
|
|
|
//#############################################################################
|
|
// CreateStreamedSubsystem
|
|
//
|
|
// @004bd08c Reads MissileCount (+0x1d0) and MuzzleVelocity (+0x1d4) after
|
|
// chaining ProjectileWeapon::CreateStreamedSubsystem (@004bc7cc). Stamps the
|
|
// streamed-record class/size header bytes, then validates both fields,
|
|
// emitting "missing MissileCount!" / "missing MuzzleVelocity!" on failure.
|
|
//
|
|
Logical MissileLauncher::CreateStreamedSubsystem(
|
|
ResourceFile *resource_file,
|
|
NotationFile *model_file,
|
|
const char *model_name,
|
|
const char *subsystem_name,
|
|
SubsystemResource *subsystem_resource,
|
|
NotationFile *subsystem_file,
|
|
const ResourceDirectories *directories,
|
|
int passes)
|
|
{
|
|
// chain the ProjectileWeapon record parser (ammo/jam/tracer fields)
|
|
if (!ProjectileWeapon::CreateStreamedSubsystem(
|
|
resource_file, model_file, model_name, subsystem_name,
|
|
subsystem_resource, subsystem_file, directories, passes)) // @004bc7cc
|
|
return False;
|
|
|
|
// stamp streamed-record header (classID / size bytes @+0x20/+0x24)
|
|
// ... (record housekeeping, see @004bd08c) ...
|
|
|
|
if (passes == 1)
|
|
subsystem_resource->missileCount = -1; // sentinel
|
|
|
|
// "MissileCount" (+0x1d0)
|
|
if (!model_file->GetEntry(subsystem_name, "MissileCount",
|
|
&subsystem_resource->missileCount)
|
|
&& subsystem_resource->missileCount == -1)
|
|
{
|
|
DebugStream << subsystem_name << " missing MissileCount!" << endl; // @004bd08c
|
|
return False;
|
|
}
|
|
|
|
// "MuzzleVelocity" (+0x1d4, Vector3D parsed from text)
|
|
const char *text = "Unspecified";
|
|
Vector3D &mv = subsystem_resource->muzzleVelocity;
|
|
if (!model_file->GetEntry(subsystem_name, "MuzzleVelocity", &text)
|
|
&& (mv.x == 0.0f && mv.y == 0.0f && mv.z == 0.0f))
|
|
{
|
|
DebugStream << subsystem_name << " missing MuzzleVelocity!" << endl; // @004bd08c
|
|
return False;
|
|
}
|
|
if (strcmp(text, "Unspecified") != 0)
|
|
{
|
|
// FUN_00408944 -- parse a "x y z" Vector3D from the resource text.
|
|
float x = 0.0f, y = 0.0f, z = 0.0f;
|
|
if (sscanf(text, "%f %f %f", &x, &y, &z) == 3)
|
|
{
|
|
mv.x = x; mv.y = y; mv.z = z;
|
|
}
|
|
}
|
|
|
|
return True;
|
|
}
|
|
|
|
//#############################################################################
|
|
// FireWeapon (ProjectileWeapon spawn path, @004bcc60)
|
|
//
|
|
// Builds a streamed-entity spawn descriptor for a Missile (entity ClassID
|
|
// 0xBD0), seeded from this weapon's muzzle transform, the explosion model
|
|
// resource (this->explosionResourceID @0x3e4), the per-missile Damage block
|
|
// (this->damageData @0x3a8) and the owning Mech's target. The descriptor is
|
|
// handed to Missile::New (FUN_004bf8bc), which allocates the 0x368-byte
|
|
// entity and runs the Missile ctor (@004bf5b4). Heat from firing is added
|
|
// to the owner here (this->heatCostToFire -> owner heatLoad) when the weapon
|
|
// is heat-bearing (FUN_004ad7d4).
|
|
//
|
|
// NOTE: this body lives in the ProjectileWeapon address range and is shared
|
|
// by MissileLauncher; it is documented here because MISLANCH.HPP declares
|
|
// FireWeapon() as the launcher's protected entry point.
|
|
//
|
|
void MissileLauncher::FireWeapon()
|
|
{
|
|
Check(this);
|
|
|
|
// A salvo draws one ammo unit from the linked bin; a dry / not-ready bin
|
|
// latches NoAmmo (ConsumeRound) and aborts the launch.
|
|
if (!ConsumeRound()) // FUN_004bd4f4 (AmmoBin::FeedAmmo)
|
|
return;
|
|
|
|
// Begin the per-shot recharge cooldown (recoil bleeds to 0 before ReadyToFire).
|
|
recoil = rechargeRate;
|
|
|
|
// Resolve the muzzle / lead geometry (used to seed each missile's descriptor).
|
|
Point3D muzzle;
|
|
GetMuzzlePoint(muzzle); // @004b9948
|
|
damageData.burstCount = missileCount; // @0x3d4 (was shadow "salvoCount")
|
|
|
|
// ⚠ SPAWN DEFERRED (WAVE 7 Phase B): the shipped code loops missileCount times
|
|
// building a 0xD4-byte Missile MakeMessage (muzzle transform + lead + the 12-word
|
|
// Damage descriptor + launchVelocity + owner/target) and calls Missile::New
|
|
// (@004bf8bc -> ctor @004bf5b4, allocs 0x368). The Missile ENTITY class is not
|
|
// spawn-ready (Entity-base phantom members overflow the 0x368 alloc; New() takes
|
|
// (int)this instead of the descriptor) -> a live spawn would corrupt the heap. The
|
|
// launcher SUBSYSTEM ticks authentically (charge/ammo/heat/recoil, damage split
|
|
// across missileCount) but does NOT launch until the entity work lands. See
|
|
// scratchpad/wave7_maps.txt (Missile map) + docs/SUBSYS_PLAN.md.
|
|
// for (int i = 0; i < missileCount; ++i) Missile::New(&descriptor); // <-- Phase B
|
|
|
|
simulationFlags |= 0x1; // replication-dirty
|
|
Check_Fpu();
|
|
}
|
|
|
|
//#############################################################################
|
|
// TakeDamage / DeathReset
|
|
//
|
|
// TakeDamage inherits MechWeapon::TakeDamage (vtable slot 6, @004b964c).
|
|
// DeathReset chains the ProjectileWeapon ammo/feed reset (@004bbaf8).
|
|
//
|
|
void MissileLauncher::TakeDamage(Damage &damage)
|
|
{
|
|
MechWeapon::TakeDamage(damage); // @004b964c
|
|
}
|
|
|
|
void MissileLauncher::DeathReset(Logical /*full_reset*/)
|
|
{
|
|
ProjectileWeapon::ResetToInitialState(); // @004bbaf8 (best-effort)
|
|
}
|
|
|
|
//#############################################################################
|
|
// TestInstance -- inherits the ProjectileWeapon/MechWeapon base check.
|
|
//
|
|
Logical MissileLauncher::TestInstance() const
|
|
{
|
|
return ProjectileWeapon::TestInstance();
|
|
}
|
|
|
|
|
|
//===========================================================================//
|
|
// WAVE 7 factory bridge -- MissileLauncher (factory case 0xBD0, "BallisticWeapon"
|
|
// mislabel). VDATA.h enum: 0xBD0 == MissileLauncherClassID. The real class
|
|
// (ctor @004bcff0) is MissileLauncher : ProjectileWeapon (sizeof 0x44C); the
|
|
// factory built a BallisticWeapon RECON_SUBSYS stub. alloc 0x44C. Ticks its
|
|
// real per-frame sim (charge/ammo/heat, damage split across missileCount);
|
|
// FireWeapon consumes a round + recoils but DEFERS the missile spawn (Phase B).
|
|
//===========================================================================//
|
|
Subsystem *CreateMissileLauncherSubsystem(Mech *owner, int id, void *seg)
|
|
{
|
|
Check(sizeof(MissileLauncher) <= 0x44C);
|
|
return (Subsystem *) new (Memory::Allocate(0x44C))
|
|
MissileLauncher(owner, id, (MissileLauncher::SubsystemResource *)seg, MissileLauncher::DefaultData);
|
|
}
|