Port overrides: replacing game functions¶
src/ holds the decompiled game, which rebuilds the PS2 executable byte for byte.
What the port adds or changes in the game's behaviour (the Lua mods' hooks, the
launcher's widescreen HUD, field of view and detail settings, the PC version's
keyboard, mouse and menu features, frame-rate fixes, the script tracing, the memory
diagnostics) lives in port/. Where that means changing a game function, the port
has its own version of the whole function, and src/ only marks the game's
definition as replaceable.
How it works¶
OBM_FN (src/openblood/replaceable.h) goes in front of the game's definition:
On the PS2 it is empty, so the matching build is unchanged. Everywhere else it is
__attribute__((weak)), and the port file defines the function again as usual:
// Port copy of 0x001fc3bc: ZScriptC::SchedUpdate (1344 bytes) (src/engine/eventsbase/scriptc.cpp)
void ZScriptC::SchedUpdate() {
// Port: a script that Lua replaced or disabled runs as Lua instead.
...
The linker takes the port's strong definition over the game's weak one, for every call and vtable slot, calls inside the game's own file included: the compiler can neither inline a weak function nor assume what it does. There is no build step and no flag; ELF, Mach-O and COFF all support weak definitions.
- Variables:
OBM_VARdoes the same for a variable (GuiControl, the action map with the PC version's keys). - File-static variables a port version uses are
OBM_STATICin the game unit:staticon the PS2, external elsewhere, so the port file declares themextern. - The game's body cannot be called from the port's version: a weak definition
has no second name. The port's version is a copy of the game's text with the
port's changes marked
// Port:, made from the non-PS2 branches of the game function. - Key functions: the file that defines a class's key function (its first
virtual function that is not inline) emits the class's vtable, so the port
defining one as a member would emit it a second time. The port's version is then
a member of a port subclass, carrying the game member's mangled name through
OBM_SYMBOL(port/engine/system/_sdl/portoverride.h). It keeps the member calling convention and the protected members; private ones go throughOBM_PRIVATE_MEMBER. A destructor's version returnsthis, as Apple's arm64 ABI passes it on tooperator delete.ZOpenWindow::Click,ZPressStart::Setup,ZBootCheck2::DoStateAction,ZDefaultButton::Click,ZGUIXMLReader2::startElementandZItem::~ZItemare done this way. - Private members elsewhere:
OBM_PRIVATE_MEMBER(tag, Class, Type, member)gives the port a member pointer to a private field or method through an explicit template instantiation (standard C++, no friend insrc/); read it withpObject->*OBM_PRIVATE(tag). - State the port needs that the game classes have no field for lives in the port
(a global, or a table keyed by the object, as the scenery LOD does in
engine/drawing/old/_sdl/viewoverridesdl.cpp).
port/overrides.json lists every replaced function and variable with the port file
that defines it and the hash of the game's text its version was made from.
tools/port/check_overrides.py fails when a listed definition lacks its marker,
when a marked definition in src/ is not listed, and when the game's text changed
since the port's version was made, so the port's is brought up to date; --update
records the new hashes (tools/tests/test_port_overrides.py runs it). Overloads of
one name are listed as Name, Name#2 and so on, each with a signature: text only
that overload's declaration contains (ZSoundGraph::TestRooms's
"uint32 lId1, uint32 lId2, bool bProbe" and "float *vListenerPos").
Link order. The game units link in the order tools/port/port_units.py prints.
The game depends on it, because static initializers run in link order: the
Action::ZStaticBinds of each unit add their action blocks in that order, and the
first block that binds a name owns it. The disc's HMControl.StatContinue
(tap(gc,cross)) must come before the newspaper's own StatisticsTestActions one
(tap(gc,a), a name the pad does not have), or Cross no longer leaves the newspaper.
What the port changes¶
| Area | Game functions | Port file |
|---|---|---|
| Scene scripts and the Lua mods | ZScriptC::PostLoad, Command, SchedUpdate, ScriptEngine::RunNoBreak (replaced); the scripts' SF.Input is the port's |
engine/eventsbase/_sdl/scriptcoverridesdl.cpp |
PC script changes (pc_scripts; native-scripts.md, pc-data.md) |
ZCheckVisible::UpdateVisible (replaced: with the setting, a decal that comes into view is sent with the PC's record, which carries the frame time; payload layouts). The script changes themselves are script patches, not overrides |
engine/eventsbase/_sdl/checkvisibleoverridesdl.cpp |
| Script lists | Zlist__Getref (replaced: a negative index returns 0 instead of reading the list block's header, which in the 64-bit port is no REF a script can hold; Script thunks) |
engine/ScriptInterfaces/_sdl/listoverridesdl.cpp |
| Mission outcome, kills, rating | ZHM3LevelControl::MissionCompleted, MissionFailed, CharacterKilled, WeaponUsed (replaced: the Lua mods hear of kills and the weapon each is credited to, and may decide the outcome); PortLiveRatingStats reads the counters |
hitman3/levelcontrol/_sdl/levelcontroloverridesdl.cpp |
| Difficulty, weapon fire | ZHM3DifficultySettings::GetDifficultySettings (replaced), ZHM3WeaponsControl::WeaponRoundFire (replaced: the Lua mods hear of each round) |
hitman3/hitman3/_sdl/difficultyoverridesdl.cpp, hitman3/characters/_sdl/weaponsoverridesdl.cpp |
| HUD | ZOSD::DrawBufferViewUpdate, ZInfoDisplay::Draw, Add, ZDrawBuffer::DrawSpriteArray (replaced) |
hitman3/gui/_sdl/osdoverridesdl.cpp, infodisplayoverridesdl.cpp, engine/drawing/old/_sdl/drawbufferoverridesdl.cpp |
| Renderer settings | ZOldViewBase::Update, AllocatePrimInstances, UpdateCamera, FindVisibleAndAddResourcesToView, GetVisibleGeomsRecur, CalcCameraExit, CalcTexturePrioity (PC-data blended dot3 records sort with the blended strips; PC rendering), ZHFlow::DrawBufferViewUpdate, ZHM3CameraEventCameraClass::UpdateViewportSize (replaced) |
engine/drawing/old/_sdl/viewoverridesdl.cpp, hitman3/background/_sdl/humanflowoverridesdl.cpp, hitman3/camera/_sdl/eventcameraoverridesdl.cpp |
| Character drop shadows | ZOldDrawBase::HandleShadows (replaced: in PC-data mode the lights whose record's light control has 0x4 cast none, as on the PC; PC rendering) |
engine/drawing/old/_sdl/drawoverridesdl.cpp |
| Memory diagnostics | ZItem constructor, destructor, NukeIt, PostLoad; ZPoolAllocLinkSortRefTab::CreateFreeStack, RemoveFreeStack; ZPoolAllocator::CheckAllPools, Alloc, ReportHighWaterMarks, ReportHighWaterMark (replaced) |
engine/system/_sdl/diagnosticsoverridesdl.cpp |
| PC key bindings (disc pad bindings merged with the keyboard's) | ZActionManager::ParseExp, ParseAsignment, LoadBindings, ZActionMapTree::Digital (replaced); the merge helpers live in sysinputsdl.cpp |
engine/system/_sdl/actionsoverridesdl.cpp |
| PC keys in play | GuiControl (data), ZGui::ClassFrameUpdate (replaced: weapon quick keys, cheat menu key), ZHM3InputControl::UpdateBaseMovementsConsole (replaced: run key; the modern layout's throw mode, drops after cut sequences and fast dismount, as in Reprisal), ZHitmanActionThrowItem::Update (replaced: the modern layout's throw mode and call-off) |
hitman3/gui/_sdl/guioverridesdl.cpp, hitman3/characters/_sdl/inputcontroloverridesdl.cpp, throwoverridesdl.cpp |
| Mouse and frame rate | ZHM3MovementControl::Update, SetTurn, SetMovementControlType, ZHitman3ControlBase::SetTurn (replaced: pad or mouse movement as on the PC, the stick's turn per 1/30 s), ZHM3CameraBinocular::UpdatePerturbation, ZHM3CameraScope::UpdatePerturbation (replaced: the sway decays per 1/30 s) |
hitman3/characters/_sdl/movementoverridesdl.cpp, hitman3/camera/_sdl/swayoverridesdl.cpp |
| Frame rates above 30 (frame-rate.md) and PC physics (enhancements.md) | CRagdoll2::Move, Activate, ConstrainedParticleSystem::MoveRagdoll (replaced: the PC version's frame guard; PC physics' sub-steps), CRigidBody::FrameUpdate, Move, Setup2, GetVertices, AddVertex, AddVertices (replaced: rest counters per 1/30 s; PC physics' relaxation passes and mesh vertices), ZCloth::DrawIt (replaced: one time step per frame; PC physics' 1/50 s step; the PC data's cloth written per strip element, pc-rendering.md) |
engine/fysix/_sdl/ragdolloverridesdl.cpp, rigidbodyoverridesdl.cpp, clothoverridesdl.cpp; the trace is physicstracesdl.cpp |
| Per-frame game code at frame rates above 30 (frame-rate.md) | ZBloodSplatters::ClassFrameUpdate, CIngameMap::FrameUpdate, ZOSD::UpdateTension, UpdateDisguiseBar, UpdateVisibilityBar, ZHM3CameraBase::AddPoseOffset, ZHM3Camera1stPerson::AddPoseOffset, ZHM3Actor::ClassFrameUpdate, ZHitman3::UpdateActorAimOffset, ZSimpleDisplay::UpdateFades, ZHM3LevelControlM13::FrameUpdate, ZWaterManager::FrameUpdate (replaced: decays, eases, steps and counters per 1/30 s through engine/system/_sdl/frameratesdl.h) |
engine/geomsbase/_sdl/bloodoverridesdl.cpp, hitman3/gui/_sdl/ingamemapoverridesdl.cpp, osdmetersoverridesdl.cpp, infodisplayfadesoverridesdl.cpp, hitman3/camera/_sdl/poseoffsetoverridesdl.cpp, hitman3/characters/_sdl/actorframerateoverridesdl.cpp, hitman3/levelcontrol/_sdl/levelcontrolm13overridesdl.cpp, engine/drawing/_sdl/wateroverridesdl.cpp |
| In-game menus' key labels | ZActionMenuBase::Draw, ConvertInputRefs, ZActionMenu::Init, ZPickupMenu::Init, ZDropDisplay::Init, Draw, ConvertInputRefs (replaced; the labels' state is a port table) |
hitman3/gui/_sdl/ingamemenusoverridesdl.cpp |
| Front-end menus | ZOpenWindow::Click (replaced: Enter is Start on the keyboard), ZPressStart::Setup, ZBootCheck::Update, ZBootCheck2::DoStateAction (replaced: no TVSettings window), ZDefaultButton::Click, ZLevelLinking::ReassignButtons (the profile's keyboard bindings), ZGUIXMLReader2::XMLParse, startElement, endElement (replaced: the PC menu blocks) |
hitman3/gui/_sdl/navigatorsoverridesdl.cpp, engine/zwindows/xmlinterface/readers/_sdl/guixmlreaderoverridesdl.cpp |
| Movies, prompts, loading, statistics | ZVideoPlayer::FrameUpdate (replaced: the PC skip key), ZGameData::GetIcon (replaced: key names and non-PlayStation pad buttons in prompts), ZHM3LevelControlM00::GetLocalisedText (replaced: the PC tutorials while the keyboard is in use), ZEngineDataBase::PurgePrimBuffer (replaced: keeps the loadout's meshes on a quick start), ZHM3GameData::GiveDefaultWeapons (replaced: the custom weapons' statistics fixes) |
engine/rendervideo/_sdl/videooverridesdl.cpp, engine/enginedata/_sdl/gamedataoverridesdl.cpp, hitman3/hitman3/_sdl/gamedataoverridesdl.cpp, hitman3/levelcontrol/_sdl/levelcontrolm00overridesdl.cpp |
| PC-data fonts | ZTTFONT::GetCharInfo (replaced: the PS2 pad button glyphs the PC fonts lack, from the port's icon texture; pc-data.md) |
engine/zwindows/_sdl/zttfontoverridesdl.cpp |
PC version fixes (pc_fixes, on with the PC version; Enhancements: PC version fixes) |
ZHitman3::IsItemActionInRange, CanPullOutFromInventory, CanUnpackSniper; ZHM3LevelControlM05::Init2, OpenGarage, CloseGarage; ZDefaultOptions::SetOption; zstring::to_upper, ZGameData::ZStringToUpper; ZSoundObject::GetCurrentRoom (replaced: each makes the PC version's change when Settings().bPcFixes is set and is the game's text otherwise) |
hitman3/characters/_sdl/pcfixesoverridesdl.cpp, hitman3/levelcontrol/_sdl/levelcontrolm05overridesdl.cpp, engine/zwindows/xmlinterface/system/_sdl/defaultoptionsoverridesdl.cpp, engine/zstdlib/_sdl/zstringoverridesdl.cpp, engine/audio/soundengine/_sdl/soundroomoverridesdl.cpp |
Scene text (pc_text and the PC-only interface keys; PC assets: PC text) |
ResourceCollection::LoadFile (replaced: with a PC installation, the disc's table merged key by key with the PC scene's, PcLocMerge in engine/system/_sdl/pcdata/pcloc.cpp) |
engine/enginedata/_sdl/localeoverridesdl.cpp |
PC mouse controls (pc_mouse, on with the PC version, acts only in keyboard and mouse play; Enhancements: PC mouse controls) |
CIngameMap::FrameUpdate (the PC's mouse branch, with the frame-rate work's pad branch), UpdateMapPosition, ZWeaponDetails::Update, ZWeaponSelector::SetupGraphics, Update, ZUpgradeSelector::Setup, Click, ZNavigator::readParams, ZNewButton::Update (through PortNewButton, its key function), ZButtonConfigurationList::Setup (replaced); the map's mouse buttons and the hidden-object hit walk are in the menu mouse |
hitman3/gui/_sdl/ingamemapoverridesdl.cpp, pcmouseoverridesdl.cpp, menumousesdl.cpp, menuportoverridesdl.cpp |
PC version tuning (pc_tuning, on with the PC version; Enhancements: PC version tuning) |
ZHitman3::LocalStateIK, ZHM3HitmanMovementGuide::InitializeClimbWindowGuide, ZHM3MovementClimbThroughWindow::GotControl, TerminateControl, ZLaserAim::DrawBufferViewUpdate; ZHM3Camera::ActivateCurrentCameraMode, DeactivateCurrentCameraMode, ZHM3CameraEventCameraClass::PushEvent; ZOSD::PIPTriedToStartUp, ZStatisticsTest::ControlMoveSmooth, ZHM3LevelControlM00::CaseFirstBriefing; CIngameMap::UpdateMapPosition and the pad pan of CIngameMap::FrameUpdate (replaced: each makes the PC version's change when Settings().bPcTuning is set and is the game's text otherwise) |
hitman3/characters/_sdl/pctuningoverridesdl.cpp, hitman3/camera/_sdl/pctuningcameraoverridesdl.cpp, hitman3/gui/_sdl/pctuningguioverridesdl.cpp, hitman3/gui/_sdl/ingamemapoverridesdl.cpp |
PC lighting (pc_lighting; Enhancements: PC lighting) |
ComputeStaticShadowMultiplier (replaced: with the setting, the PC's sampler, which gives the draw entry the PC data's projected shadows, and the multiplier eased per 1/30 s; otherwise the game's text); g_fStaticShadowSampleHeightLimit (OBM_STATIC, read by the port's sampler). The projections are drawn by engine/drawing/old/_sdl/staticprojectionsdl.cpp |
engine/drawing/_sdl/staticshadowoverridesdl.cpp |
| Mouse turn in first person | ZHitman3ControlMouseStrafe::UpdateTurn (replaced: the PC version's horizontal scale 0.18 instead of MOUSE_TURN_SCALE 0.05; Enhancements: Mouse turn) |
hitman3/characters/_sdl/mouseturnoverridesdl.cpp |
PC HUD size (pc_hud_size, the PC version; Enhancements: PC HUD size) |
ZOSD::InitElementPositions, ActionGetItem, EnableOSDElement (replaced: positions from the HUD area in window pixels), ZOSD::DrawBufferViewUpdate (places again on a new size; the crosshair and the security overlay in HUD units), the HUD camera's projection in ZCameraViewEntrySDL::UpdateMatrices, ZTextCredits::Update and ReleaseResources (replaced: the credits in window pixels) |
hitman3/gui/_sdl/pchudsdl.cpp, hudlayoutoverridesdl.cpp, osdoverridesdl.cpp, textcreditsoverridesdl.cpp, engine/drawing/old/_sdl/zoldviewsdl.cpp, gpusdl.cpp (GpuHudArea) |
PC HUD and menu layout (pc_layout, automatic with the PC installation's data; Enhancements: PC HUD and menu layout) |
ZOSD::InitElementPositions, DrawDisguiseBar, SetHitpoints, ZWeaponDisplay::Draw, ZContainerMenu::Draw, UpdateAllEntryPos, ZHM3Objectives::Setup, ZHM3ObjectivesBrief::Setup (key functions, port subclasses), ZHM3InfoList::Setup, ZHM3InventoryMenu::UpdateItemInfo, ZGUISlider::SetValue (key function, port subclass), readParams (replaced: the PC version's numbers while PortPcLayout() is true; the slider's DisplayAsFloat and FloatMultiplier are a port table by element); ZOSD::DrawBufferViewUpdate's first bar widths |
hitman3/gui/_sdl/hudlayoutoverridesdl.cpp, menulayoutoverridesdl.cpp, pclayoutsdl.cpp, engine/zwindows/xmlinterface/elements/_sdl/slideroverridesdl.cpp, hitman3/gui/_sdl/osdoverridesdl.cpp |
PC character shadow colour (pc_lighting; PC rendering) |
ZENVIRONMENT::ClassInit (replaced: with the PC lighting, in M00, M01, M04 and M05 each room environment's colour is copied into its character shadow environment, as the PC's 0x4e4bf0 does; otherwise the game's text) |
engine/geomsbase/_sdl/environmentoverridesdl.cpp |
| Menu line objects | ZResourceManager::SetupResourceGroups (replaced: the scene's LineObjs pool is topped up to the PC scenes' 116, so the keyboard configuration's dialog over the in-game list has its text; Enhancements) |
engine/zwindows/xmlinterface/system/_sdl/resourcemanageroverridesdl.cpp |
The pause map's icons need no override: hitman3/gui/_sdl/mapiconssdl.cpp reads the
map's private icon list and legend group.
Two port changes for the PC comparison need no override. The widescreen masks of the
overlay camera are a port renderer change: ZOldViewSDL::Clear blacks the picture's
sides before a full mask is drawn (hitman3/camera/_sdl/overlaywidescreensdl.cpp,
Render resolution and widescreen).
engine/debug/_sdl/pcfixestestsdl.cpp holds the OPENBLOOD_PCFIXES_TEST scenarios that
show each PC fix with the setting off and on; DebugUiApplyPending runs them, and
pclayouttestsdl.cpp's OPENBLOOD_PCLAYOUT_TEST scenario for the PC layout.
engine/debug/_sdl/pctuningtestsdl.cpp does the same for pc_tuning (OPENBLOOD_PCTUNING_TEST:
firstperson, binoculars, laser, window, climb, map, pip).