Skip to main content

First-person aiming

Verified via reverse engineering

Traced in FarCry2_server (symbols) and mapped into Dunia.dll (Steam v1.03). Addresses without a binary named are Steam Dunia.dll. FCSE's address library maps every one of them to GOG.

Verified in a running game

Moving the eye through the camera's positional offset moves it relative to the gun, not the gun along with it: down a G3's iron sights, the rear sight moves further than the front one. Measured with Aiming Overhaul's sway on retail GOG v1.03.

Down the sights​

The pawn's effective data holds one flag for it: bit 3 (0x08) of the byte at +4. CPawn:: GetEffectiveData (0x1007E1C0) is *(pawn + 0x10) + 0x2D0.

CPawnBeautifier::UpdateEffectiveIronSight (server 0x09008E80) copies the flag over from the desired data only while all of these hold: the pawn's state machine is in the AllowIronsight group, the primary track is equipped, the weapon is not jammed, the pawn is not jumping, it is under 0.5 m from the ground, and the weapon's bCanIronsight is set. When the flag changes, it sends the weapon the IRONSIGHT_ON or IRONSIGHT_OFF event.

CPlayerBiofeedback::UpdateIronsightBreathing (server 0x08740120) is sound only: a mixing preset while down the sights, and the breath sounds after fTimeInIronsightBeforeBreathing. Nothing moves.

The first-person camera​

CCameraPawnComponent is the camera entity attached to the player's pawn. Its Update (0x10693C00) runs, in order:

  1. UpdateDebugOffset (0x10693A00) sets the camera entity's local position: the weapon's CameraOffset, or CameraOffsetIronsight down the sights, plus the component's DebugOffset.
  2. UpdateCameraOffset (0x10693490, __thiscall(float seconds, CPawn* pawn)) fills an angular offset and a positional offset from the pawn's effective data. That is the recoil kick: a new kick is blended back to zero over its time. Camera shake angles are added on top every frame.
  3. The scene camera's orientation is the look angle times the angular offset. Its position is the entity's position plus the positional offset rotated by that orientation, so the positional offset is in the view's own axes: x right, y ahead, z up.
FieldSteam Dunia.dllserver
DebugOffset+0xC4+0x9C
angular offset (radians)+0xD0+0xA8
positional offset (metres)+0xE8+0xC0

Update is entered through the component's second base, at this + 4, and calls both helpers on this. The offsets above are from this, which is also what the accessor below returns.

The angular offset is pitch, roll and yaw, up positive for pitch, copied from the effective data's +0x2C with the camera shake at +0x128 added. Update turns it into a quaternion with the same euler order as CEntity::SetEuler (0x100677C0, on this + 0xD0) and multiplies it onto body part 0's rotation, so it turns the view about its own axes and leaves the body, the arms and the gun where they are. Once placed, the scene camera, ModifySceneCamera (0x10504CE0) on this, holds the eye's world position at +0x08.

Measured in a running game

Pitch and roll added to the angular offset after UpdateCameraOffset, and taken off again once Update returns, turned the scene camera's angles at +0x6C (pitch, roll, yaw) by the same amounts to within 0.0002 rad, frame by frame through a burst. Retail GOG v1.03, from Aiming Overhaul.

Most branches of UpdateCameraOffset rewrite the positional offset every frame. The one that is blending an angular kick back leaves it alone, so anything added to it has to be taken out again before the next call.

Seen in a running game

With the eye moved 10.6 cm ahead toward an AS50's scope, each shot's recoil left the weapon wholly undrawn for about a third of a second while its sight picture stayed up. Retail GOG v1.03, from an FCSE plugin logging the weapon's draws.

The field of view​

CCameraPawnComponent::UpdateCurrentFOV (0x10692E30, server 0x08951870, __thiscall(CPawn* pawn, float seconds)) is called from Update after the camera offset. It works out this frame's field of view, in radians, at the component's +0x108:

  1. It starts from the unaimed field of view at +0x70.
  2. It blends toward a second eased field of view by that one's weight.
  3. It blends that toward the iron sights' field of view by their weight.
  4. It adds a Perlin noise term, kept at +0x11C.

The skills, *(pawn + 0x10) + 0xD8 (0x1007E1F0, the server's CPawn::GetSkills), hold two CPawnFOV transitions, at +0x08 and +0x24. Each has a time, a curve, a field of view and the weight its curve has reached, eased every frame by BeautifierMaths::UpdateFOV (server 0x09007370):

FieldOffset in the pawn's data
iron-sight weight+0xF0
iron-sight field of view+0xF4
second weight+0x10C
second field of view+0x110

A transition is on while the byte at its +0x05 is set. The monocular's OnEquip (server 0x08901530) sets the first one's and fills it with its own time, curve and field of view, and OnUnequip clears it. Map Overhaul reads its sheet close the same way, with the map out (seen in game).

CWeapon::OnEquip (server 0x08F49D00) fills the first transition from the weapon's iron-sight properties: its fIronsightTransitionTime, its transition curve, and its fIronsightFOV (+0xE4 in the weapon's properties). A scoped weapon's zoom is that same transition, so the whole view zooms in as the scope comes up.

Update then hands +0x108 to the scene camera at +0x28, and the unaimed +0x70 as its typical field of view at +0x30. A debug field of view at +0x10C takes both instead while it is above nought. Update reads these through its own this, the component's second base, 4 bytes on.

The console variable gfx_widescreenmode decides which way that angle is applied to a wide screen. With x and y the half-extents of the projection at unit distance and fov the camera's angle (0x103ff2c0 in the GOG build, RE-verified):

ModeProjection
0 (default)x = tan(fov/2), y = x / aspect — the angle is horizontal
1y = tan(fov/2) · 0.75, x = y · aspect — the angle is a 4:3 screen's horizontal one
2y = tan(fov/2) · 0.5625, x = y · aspect — the angle is a 16:9 screen's horizontal one

Any other value leaves the projection unchanged. The render profile's ForceWidescreen letterboxes a screen narrower than 16:9 into a centred 16:9 band.

From the console​

The retail Lua bindings Game:SetFPCameraOffsetX/Y/Z (0x1070C2E0 for X) set one axis of DebugOffset. Game:SetWeaponCameraOffsetX/Y/Z set one axis of the equipped weapon's CameraOffset, or of its CameraOffsetIronsight while down the sights. Both go through 0x1070C210, which returns the player's camera component. They are reachable with the console's # escape, for example #Game:SetFPCameraOffsetX(0.01) (see the developer console).

The look​

The camera's look angle and the direction a first-person shot leaves in both come from part 0 of the pawn's body: CPawnBody::GetBodyPartRot (server 0x08FD2B80) is the entity's orientation times one skeleton node's rotation.

CPawnInputListener::UpdateLook (0x10143C40, server 0x08FDE5C0, __thiscall) builds the look anew every frame. It runs from the listener's Update unless the pawn is in a vehicle, and sets the desired look to the effective look plus the mouse axes times the frame time. The listener's pawn is at +0x20.

The desired data is *(pawn + 0x10) + 0x140 (0x1007E1B0), and the effective data, laid out the same, is +0x2D0. Both hold the look in radians:

FieldOffset in either
pitch, up positive+0x38, again at +0x44
roll+0x3C, again at +0x48
yaw, left positive+0x40, again at +0x4C

UpdateLook reads the effective look from +0x54 instead while bit 2 (0x04) of the effective flags at +4 is set. It takes no arguments and returns with a plain RET. It writes the look to both copies and carries the effective roll over unchanged, since the mouse has no roll axis.

Seen in a running game

Adding the frame's change of an offset to both copies of the desired look after UpdateLook moves the view and the gun together, and the mouse turns on from wherever the offset left it. A slow breath-and-tremor offset read as a sway through iron sights and scopes alike. Where the shots went was not checked. Retail GOG v1.03, from Aiming Overhaul.

The player's sprint press is handled in CPawnInputListener's signal handler: on lock_sprint (or the pad's sprint), the call at 0x101447C1 fetches the desired data and the next instruction ORs 0x40 into its flags. EAX holds the signal there and ESI the listener. Jumping from that call to 0x101447CA, the handler's return, refuses the press.

Seen in a running game

Refusing the sprint press that way while the effective iron-sight bit is set keeps the player down the sights with sprint held. Retail GOG v1.03, from Aiming Overhaul.

Look speed while zoomed​

The mouse and the gamepad slow the turn while zoomed in different places, from different fields of the skills (0x1007E1F0).

The mouse's look curve (0x107D8B90, GOG 0x107CC2C0, in the mouse filter's vtable at 0x10EA9760) multiplies the turn by the zoom's field of view at +0x1C over 1.309 radians, the unzoomed one (0x10EA979C holds its inverse). It does so only while bit 3 (0x08) of the effective flags is set, which a gun sets down its sights. CWeaponFireStrategy::Update (server 0x08F8A5B0) copies that bit every frame into the zoom transition's on byte, +0x0D. The monocular's OnEquip sets the on byte and the field of view but never the bit, so in the retail game the monocular zooms while the mouse turns at the unzoomed speed. UFCP makes the curve test the on byte as well. RE-verified on Steam.

The gamepad's CActionMapPadFilter::ApplyIronSightSensitivity (0x107D8D10, server 0x08E99F90) multiplies the turn by a look speed blended from +0x40 to +0x44 by the zoom's progress at +0x18. Both start at 1. A weapon writes both (0x10131280): its own fLookSensitivityFactor (+0xCC in its properties) first, and its IronSight one (+0xD0) at full zoom. The monocular's use strategy (0x1072B170) writes only the second, from its fLookSensitivity at +0x50, beside its fFOV at +0x4C, so it eases in from whatever the last weapon left. RE-verified on Steam.

Retail weapons scale the gamepad's full-zoom speed with their field of view, about 0.3 per radian: 0.4 at a pistol's 1.309, 0.07 at the AS50's 0.2. The monocular zooms as far as the AS50 and ships with 0.1.

Holding the breath​

The player's stamina is a counter on the pawn entity's CFCXCountersComponentPlayer (found by CEntity::GetComponent with the CRC-32 of that name): the counter is at the component's +0x64, with the stamina left at its +0x10 and the most at +0x14. Health is the same kind of counter at the component's +0x44. The camera shake a blast causes is three angles in radians at +0x128, +0x12C and +0x130 of the pawn entity's CCameraShakeAndPadRumbleComponent, which the camera update (0x10693490) adds to its angular offset each frame. The player's biofeedback (0x106D0CA0) divides the two each frame and keeps the share at its own +0x9C. It compares that with fLowStaminaThreshold (+0x90, 0.25) and fMediumStaminaThreshold (+0x94, 0.5) to set the stamina sound switch, and plays its breathing below the medium threshold.

That breathing is 00455c76.spk: twelve breaths, each an exhale and then an inhale, picked by the stamina switch (00455C49: low 00455C4B or medium 00455C4A) and then by an infamy switch (00455C46: high 00455C47 or low 00455C48), 28 and 4 dB down. They play as sound type 6, Ono_Player. Aiming Overhaul cuts them into inhales and exhales for its own hold-breath banks.

The arms behind a turn​

The first-person body's only lag behind the look is a turn rate the animation reads. CPawnBeautifierFirst::ComputeAngularSpeed (0x1009FFC0, server 0x092E4FC0) takes the turn from the body's heading to the look's yaw this frame, in degrees a second, clamps it to ±185, eases it a tenth of the way each frame and keeps it at the beautifier's +0x58, nought below 1. Pitch has no such rate. UpdatePlayerMoveState (0x1009F2B0, server 0x092E6CC0) copies it to the skills' +0x58, which the flamethrower reads, and hands it to the animation's channel 28, PlayerAngularSpeed, through CAnimationComponent::SetFloat (0x1051F480). The load for that call is FLD [EBX+58h] at 0x1009F55B; loading nought there instead takes the slide away.

Measured in a running game

At 126° a second the channel slides the right hand 1.1 cm sideways against the view, with no turn, on the AK-47 and the Makarov alike. Looking up or down at the same rate moves it not at all. Retail GOG v1.03, from Aiming Overhaul's posed bones.

The first-person body​

Whether the player is drawn as the first-person body is bit 7 (0x80) of the same byte in the pawn's desired data, *(pawn + 0x10) + 0x144, whose 0x40 bit is sprint. Two things read it:

  • CPawnBeautifierComponent::BuildTag (0x100E9230) picks the FirstPerson or ThirdPerson pose.
  • CPawn::UpdateMaterialMask (0x10080FC0) sets the full-body flag at *(pawn + 0x10) + 0x49A, and shows or hides the kit parts tagged FirstPerson.

Three cameras write it:

  • CCameraPawnComponent's activation (0x10693910) sets it.
  • CCameraThirdComponent's update (0x10695BC0) clears it and asks for the full body, while that camera is active.
  • The free camera's update sets it every frame from the camera's own flag at +0xCD, which camera_toggle_first_person flips.

CPawn::ViewModeChanged (0x100811C0) also hides, going into first person, everything the player carries, and shows it coming out: CInventoryViewPawn::SetVisible (0x101296A0) passes the flag to CEntity::SetIsVisible (0x104DDB20) for every item but the equipped gadget and the weapon in hand. Out of first person the map and the phone hang on the belt. Putting a gadget away (SInventoryViewPawnImpl::UnequipGadget, server 0x09001F10) binds it back to body part 7 and hides its entity, and equipping one (EquipGadget, server 0x09003C90) shows it.

The two models​

The player's CGraphicComponent holds two models: the full body, <name>.xbg, first, and the headless avatar, <name>_avatar.xbg, second. The model switch (0x1007FC80, server SPawnImpl::SetViewportID, __thiscall on the pawn's data with the player's viewport, RET 4) reads the data's +0x49A, which UpdateMaterialMask sets just before. UpdateMaterialMask has many callers: the view mode change, the load path (0x10082AF0), the first-person and third-person cameras, and the free camera on every update. For the full body the switch opens every viewport to the full body and hides the avatar. For first person it masks the full body out of the player's viewport, shows the avatar, and then discards the full body with RemoveObject(0), so retail never gets it back.

Each model has a scene instance helper, at the model's +0x34. On it, 0x10336B50 sets the viewports the model is drawn in (its instance's +0x98), and 0x10336B10 sets those it is drawn in the near depth range in (+0x90), the range the first-person gun is drawn in. The component keeps its near viewports at +0x12C, and 0x1051A6E0 (__fastcall on the component) puts them on every model. Its vt+0x98 (SetRenderInNearZ) does both. The view mode's last step (0x10080000) calls it, and so does 0x100810D0, which LaunchProjectile and other weapon code call. So in first person the avatar is drawn in front of the world, walls and ground included.

The skinning job (kernel 0x1061F3A0) calls 0x1061F200 (__cdecl) once for each skinned model. That call builds the model's own skin matrices from the skeleton's posed bones, through its own map of skin slots to bones, and through its mesh's inverse bind matrices. The component lists its skinned models at +0x120 (+0x124 of them), each entry with the slots' bones at +0x00, their count at +0x04 and the geometry resource at +0x14. The loaded mesh holds the inverse binds at +0x70, 4×4 each, and their count at +0x74. Their inverses are the mesh's rest pose, in the mesh's own axes: the hips at the origin, ahead along x, left along y.

Seen in a running game

On the player in first person, the hips (the first bone, the only one not held) are at the model's origin, on the ground. Spine, 0.098 m above the hips at rest, stands 1.093 m up, and 0.448 m crouched. Looking down swings it 0.36 m back and drops the eye from 1.66 m to 1.20 m. With the discard taken out and the full body shown, the chase camera at the wheel, then Vehicle Overhaul's, shows the full body with the third-person driving clips. Seen from the free camera in first person, the full body shown in every viewport and out of the near range is drawn whole, head included, in the first-person pose, as long as it is shown again after each model switch. Retail GOG v1.03, from Third Person.

The player's shadow​

CPawn::ViewModeChanged calls the graphic component's vt+0xA0 with !firstPerson. That is CGraphicComponent::SetCastShadow (0x1051A520, __thiscall, RET 4). It sets bit 2 of the component's +0x3C, and bit 0 of each model's scene instance at +0x18. So in first person the player casts no shadow at all.

A skinned model's bone matrices are uploaded once a frame and shared by every view that draws it. The render list builder (0x103C8CB0) queues one draw packet per sub-mesh for each view. The first view to reach a sub-mesh fills its bone constants through 0x103ED950, which copies each palette slot's skin matrix. The constants are then left alone until the skin changes. A model therefore cannot be skinned one way for the shadow maps and another for the camera. It can only have draws left out of some passes.

A loaded mesh's per-part sub-meshes, with their bone palettes, live only until CGeometryResource::ClientProcessRawData (0x1035F080) has turned them into scene objects. It then frees them and zeroes the mesh's +0x68. After that a draw's sub-mesh is reached through three handle pools, which FillRenderBuffers (0x105B8AE0) loads into ECX at +0x35, +0x48 and +0x5A. An object is (*(pool + 0x0C))[handle], where a handle is 8 bytes with the index first.

  • The geometry resource's scene object is at its +0x40 handle. Its details' handles are at +0x90, nearest first, with their count at +0x94.
  • A detail's sub-mesh handles are at +0x0C, with their count at +0x10. Its vertex resource is at +0x08.
  • A sub-mesh holds its palette at +0x20 (its count at +0x24), already turned into skin slots. Its material is at +0x32, its first index at +0x40, and its triangle count in the low 31 bits of +0x4C.
Seen in a running game

An experiment in Third Person, not kept, kept the shadow on and left the full body's sub-meshes skinned to no leg out of the passes drawn at the screen's size. The shadow cascades, at 6144×2048, kept them. The player's shadow fell whole, head and the raised arm included, and the view still showed only the legs. Retail GOG v1.03.

The body's animation out of first person​

Out of first person the player is animated as an NPC is. The PawnBeautifierRepository entity gives every pawn type CPawnBeautifierThird there. The pawn on foot is in the NPCs' MOVE state Pawn_Generic_Movement, with the layer Pawn_Generic_Aim (main_avatar.gosm.xml). Its third-person branch walks, jogs, runs and sprints on the mercenaries' 3rdge_fulb_* clips, picked by Speed and MentalState.

  • It never tests Stance, and the game has no crouch-walk clip, so moving crouched plays the standing legs.
  • Its jump clip is gated on IsMultiplayer.
  • CameraPlacement is the same for the player and an NPC there, so no rule can pick the player alone.

CPawnBeautifierThird::UpdatePlayerMoveState (server 0x09012660) sets AimStance from the effective flags' bit 0 (Normal) and bit 3 (IronSight). CPawnBeautifierFirst::Activate (server 0x092E49B0) sets bit 0 of the desired flags and MentalState Combat, and nothing clears either. So out of first person the player carries the gun up as an NPC advancing while aiming does. The free camera's debug player mode (dbg_force_multiplayer_pms in CCameraFreeComponent::Update, server 0x0894E100) switches the same two: Relax clears the bit and sets MentalState 0, Combat sets both back.

CPawnBeautifierThird::UpdateEffectiveFromDesire (server 0x0900FD60) copies the desired flags to the effective ones and sets the effective look:

Desired flagsEffective look
0x02 setthe desired look, +0x38 (+0x54 with 0x04), which the mouse drives
0x02 clear, gun upthe aim angles, +0x44
0x02 clear, gun downthe entity's own facing

So with the gun carried down, a look that follows the mouse needs 0x02.

This was read in the server build and the MOVE data. Crouched in third person, the body was seen standing and jogging. Retail GOG v1.03, from Third Person.

The gun near walls​

The engine never moves the gun out of a wall. It draws it in a depth range of its own, so a gun pushed into a wall is drawn whole in front of it.

CPhysicsSystem::CastRay (0x1048DD30, __thiscall on *(void**)0x11613D60, RET 0x18) takes the start, the vector to the end, a hits vector {hits, count, capacity}, a CPhysQueryFilter, an object to skip and flags. The editor's ComputeDropDistance (0x1083DCA0) calls it so, with flags 5: the closest hit only, and nothing cast outside the world. Each hit is 0x30 bytes, its world position first. The filter is built by 0x1048EC40 from a layer mask and a group; a hits vector whose capacity's bit 0 is clear is freed with the engine's free (0x10228AD0).

CWeaponState::CanFire(float) (0x1012EC50, RET 4) decides every shot, the player's and the AI's. The weapon is at the state's +0x00, and CEquipmentBase::GetWielder (0x10156BA0) on it gives the pawn holding it.

Lowering the desired look by an angle (see the look) and raising the camera's angular pitch at +0xD0 by the same angle swings the arms and the gun down, but the view does not hold still. The eye hangs from the Camera bone, which the animation bends down and forward with the look's pitch. And the look's offset goes in during the input's UpdateLook, before the camera update that works out the frame's swing, so the angular pitch runs a frame ahead of the look. Turning the arms' bones down instead (see the body's skeleton) leaves the look, and so the view, alone. A shot still points along the look (see where a first-person shot goes), so it has to be turned down with the gun.

Measured in a running game

From the hip with an AK-47, the look swung 0.6 rad down that way took the eye 17 cm down and 7 cm ahead, and the view's pitch dipped by up to 0.05 rad and rose by up to 0.075 rad while the swing moved. The arms' bones turned 0.6 rad down about a point between the shoulders took the gun out of the picture with the view's angles, which CSimpleCamera::SetAngles keeps at the scene camera's +0x6C, and the eye unchanged, to 0.00001 rad and 0.1 mm. Retail GOG v1.03, from Aiming Overhaul.

Seen in a running game

Aiming Overhaul casts layer mask 0x43B from the eye along the view, swings the gun down as the room ahead shrinks, clears the desired iron-sight bit and refuses CanFire for the player's weapon while it is down. The player neither aims nor fires until the gun comes back up. Retail GOG v1.03.

CastRay was called from the camera update every frame for this, and up to a few dozen times a second more for leaning, without trouble.

Walking, sprinting and jumping​

CPawnInputListener::UpdateSpeed (0x10143DE0, server 0x08FDF2D0, __fastcall on the listener) sets the velocity the player wants each frame, in the desired data's +0xB0. Walking, its size eases toward the body's top speed, fWalkingMaxSpeed or fWalkingMaxSpeedCrouch times the weapon's fMoveSpeedFactor (+0xD4 in its properties from the hip, +0xD8 down the sights; 1 and 0.5 on the AK-47), by fWalkingAcceleration a second when that is faster and fWalkingDeceleration when it is slower. With no move key held the wanted speed is nought, and the velocity is set to nought at once: deceleration only slows the player toward a slower pace, such as a walk out of a sprint. Its direction follows the keys at once. Sprinting, the speed is archSprintCurve's value at the seconds since the sprint began, kept at the listener's +0x1C, again without easing. 0x1010D690 (__thiscall on the pawn's body, the seconds, RET 4) reads that curve, and UpdateSpeed is its only caller. The direction is made unit length before the curve's speed is put on it, so the weapon's factor never reaches a sprint. fSprintingDeceleration is read by none of the functions that take the pawn's body.

Whether a jump is under way is two bytes of the pawn's data, *(pawn + 0x10): +0x49B, set as it leaves the ground, and +0x49C, set as it ends; CPawn::IsPerformingJump (0x1007E250) is the first set and the second clear. How far the pawn is above the ground, in metres, is the float at +0x4A4 (0x1007E240).

Measured in a running game

With retail data a walk reaches 3.8 m/s in 0.15 s, and a sprint climbs from it to 9.0 m/s by 0.9 s and falls back to 6.3 m/s from 1.8 s. Letting go of the keys stops either within two frames. A standing jump rises 1.0 m and is 0.66 s in the air, landing at 4.4 m/s, with +0x49B set throughout. The view's bone hardly moves walking, 0.9 cm sideways and 0.5 cm up and down, and the right hand 2 to 3 cm against it. Sprinting carries the gun 45° to 75° off its aim, and it is back 0.25 s after the sprint ends; a shot fires at once all the same. Retail GOG v1.03, from Aiming Overhaul's trace.

Leaning​

The player cannot lean. The cover stances the animation graph has a channel for (31, CoverStance: none, leaning left, leaning right, leaning up, blind firing) are fed from *(pawn + 0x10) + 0x3F0, the effective data's +0x120, by the beautifier's animation update (0x100AC190), but the player's graph has no clips for them.

CCameraPawnComponent::Update does not read the look's roll. It takes the camera's rotation from body part 0 (0x1010D850): that part's skeleton node, through the skeleton's vtable +0x78, times the pawn entity's own orientation. That orientation is the entity's 4×4 at +0x30, which CEntity::GetOrientation (0x104DDA00) turns into a quaternion.

Turning the entity​

CEntity::SetEuler (0x104E01C0) takes pitch, roll and yaw and rebuilds the basis as yaw about Z, after roll about the entity's own Y, after pitch about X, keeping its position. CEntity::GetEuler (0x104DF830, through 0x1006AEE0) decomposes a basis back into the same three the same way. A pawn faces along its Y row, with X to its right, so a roll leans it sideways and atan2(m[5], m[4]) - π/2 reads its heading whatever the roll. Rolling about X instead tips it forward or back.

Every orientation write ends in CEntity::SetMatrix (0x104DF440, __thiscall(const float* matrix, void* source), RET 8). It stores the matrix at +0x30, calls vt+0x4C on each of the entity's components but source, and moves the entities bound to it. It reads the matrix with aligned SSE loads, so a matrix handed to it must be 16-byte aligned: an unaligned stack copy faults as a read of 0xFFFFFFFF. A component is found by CEntity::GetComponent (0x104E2CC0, the CRC-32 of its class name); the player's physics is CCharacterPhysComponent.

When the body is read​

Within CEngine::Update, the pre-physics tick list runs first, then the physics step, then the physics post-step queue (0x1058D8F0, __thiscall(float seconds), RET 4), which calls each registered physics component's vt+0x90, then the post-physics tick list, which ends with the camera.

  • The pawn beautifier component's update (0x100EA050, __thiscall(seconds, mask) on the component's updatable at +0x10) runs in the pre-physics list. It applies the animation's root motion (0x100E9B80, which GetEulers the body, adds its turn and SetEulers it back), then calls its beautifiers' vt+0x80.
  • In the post-physics list something writes the player's matrix through SetMatrix once a frame, standing it upright, before the camera reads it.
  • The weapon entity's own matrix is written through SetMatrix only a handful of times in thirty frames. The gun is not drawn, and does not fire, from it.
Seen in a running game

Retail GOG v1.03, from an FCSE plugin logging the player's matrix and these calls twice a second while leaning: the beautifier's update ran once a frame for the player, the post-physics write once a frame, and the weapon's SetMatrix 0 to 5 times in 30 frames.

The body's skeleton​

The pawn's body is *(pawn + 0x10) + 4: its entity proxy at +0x04, its CGraphicComponent at +0x08, and the skeleton node of each body part from +0x10 (0x1007E1E0 returns it). The component's vt+0x78 returns its skeleton, embedded at the component's +0xE0. vt+0x7C returns it too but also marks it changed, which has the bones posed again this frame. The human rig hangs Camera, the view's bone, under Head, Neck, Spine2, Spine1 and Spine, and both arms off Spine2 (see the skeleton format).

The skeleton keeps its bones at +0x20 and their count at +0x2C; bit 0 of +0x30 marks them to be posed. A bone is 0xA0 bytes:

OffsetField
+0x00CRC-32 of the bone's name, case kept
+0x10its animated 4×4, against its parent
+0x50its posed 4×4, in the body's own axes: three axis rows, then its place
+0x90parent index, -1 for the root
+0x94held: set by hand, and left alone when posing

Posing (0x103322C0, __fastcall on the skeleton) runs only while bit 0 is set, and rebuilds every bone not held from its animated matrix and its parent's posed one. It is the synchronous path, for a skeleton's first build and the engine's own procedural bones (0x100C2FA0, for one), which read a posed matrix (0x10331F80), write it back held (0x10331F10), and pose again.

Every frame the posing is a job instead. The graphic component queues two, PS3-style, while anything has asked for the skeleton in the last 60 frames: each object declares its buffers as plain pointers (counts at the declaration's +0x00–+0x0C, the pointers from +0x14) and names a kernel taking the job's context, whose first field is that declaration.

  • SkeletonObjectJob (the object at the component's +0x40, kernel 0x1064EC50) is a copy of posing, run whether or not bit 0 is set. It declares the bones, then the skeleton.
  • The skin job (the object at +0x1C8, kernel 0x1061F3A0) is declared only while bit 0 is set. It builds each kit part's matrices from the posed ones, through the part's node-to-bone map.

Then the component's sync (0x1051B2A0) clears bit 0, moves the entities bound to it, and places its rigid parts from their bones.

Measured in a running game

On the player's first-person body (107 bones at run time) every bone but the first is held: the animation writes each posed matrix itself, before the skeleton's job, so the job's posing leaves them all alone. A posed matrix changed right after the job was still unchanged when the skin job read it and when the camera did, 60 frames in 60. Retail GOG v1.03, from Aiming Overhaul.

The camera turns with the Camera bone's posed matrix, and a shot's first-person origin (0x10112600) is that bone's place in the world (0x1010D780).

An entity bound to a bone is placed from that bone's posed matrix (0x105530F0, __thiscall on the parent's binding with the child's binding and the parent entity's matrix, RET 8): the child binding's +0x1C is the bone's index, and the parent's matrix times the bone's is written to the child's +0x40, which the entity is then placed from. The parent's matrix there is turned like the entity but, where the parent binding's +0xC5 is set, has its place left out. The parent binding lists its children as entity proxies at +0x2C, with their count at +0x30, and an entity's binding is at its +0x78. So the first-person camera's own binding is its component's entity, through the entity proxy at the component's +0x08, at +0x78: what tells it apart from a long gun hung from the same bone.

Measured in a running game

On the player: the first-person camera (cameras.Camera.First) hangs from Camera, the weapon in hand from R Hand, slung long guns from Spine2, a holstered pistol and the machete from a thigh, and the gadgets and grenades from Pelvis. Down the sights the AK47 moves to Camera, which lines its sights up on the eye; the Desert Eagle stays on R Hand. Retail GOG v1.03, from Aiming Overhaul.

Measured in a running game

The map out in the hands hangs from L Hand, its facing the hand's to the third decimal. Retail GOG v1.03, from Map Overhaul's probe.

The look's pitch is posed into the body, not laid over it. As the view pitches, Camera and Spine2 turn with it, so the arms and what they hold stay put on screen, while Pelvis stays level and slides back: 18 cm at 36° down, 36 cm at 73°. The eye drops with the head, 16 cm at 36° down (measured in a running game, GOG v1.03, Map Overhaul's probe). So turning Spine and everything below it but Camera back about the eye by the Camera bone's own pitch holds the arms level while the view looks past them; the legs, on Pelvis, are left alone (seen in game, Map Overhaul).

The first-person body is drawn lined up on its Camera bone. Turn every bone but Camera about a point after the skeleton's job, and the arms and the gun turn on screen. Turn Camera with them, and the arms and the gun stay where they were in the world while the view turns.

Leaning by the bones​

Aiming Overhaul leans the player by bending the body's posed bones after the skeleton's job: Spine and every bone below it in the tree but Camera, about Spine's place, round the look's direction (the body's forward pitched by the effective look's pitch), and sliding them to the side along its X. Every bone of the player's body is held, so it bends those too, once per write of the animation, and marks the skeleton changed through vt+0x7C each frame the bend moves. What hangs from Camera, the first-person camera and a long gun down the sights, has its copy of the bone's matrix taken back into the body's axes, bent the same way, and turned back, which moves the eye. The view is rolled by the same angle at +0xD4; the roll is about the look's direction too, so a bend round it keeps the sights on the eye whatever the pitch.

Seen in a running game

The view, the arms and the gun lean together, slid and bent, a long gun down the sights included while turning, with a long gun's sights on the eye. Retail GOG v1.03, from Aiming Overhaul. Bending round the body's level forward, or moving the eye by the bone's move, puts a long gun's sights below the eye. The muzzle flash and a scope's sight picture were not checked.

Leans that fall short​

Six other ways of leaning the player, each seen in game on retail GOG v1.03, fall short: none leans the view, the arms and the gun, the muzzle and a scope's sight picture together.

  1. The pawn entity rolled from the camera update with SetEuler. The view rolls about its own axis and nothing else: the eye does not move, and the arms and the gun stay level with the world, so they tilt on screen. They were posed earlier in the frame, and the camera reads the entity's orientation lazily for body part 0.
  2. The camera's own roll and eye. The roll at +0xD4 and the eye at +0xE8 (turned into the rolled axes, since the positional offset is turned by the full camera rotation) lean the view cleanly. The gun is placed through c0–c3, the view's rotation times the projection, with the projection alone at c8–c11 (see the weapon's passes): giving each of its draws P · A · P⁻¹ · C in place of C, with A the view's roll and the eye's move in camera space, draws the arms and the gun exactly where they sit unleaned, so they lean with the view. A shot can be moved with the eye in the bullet strategy's first-person setup (0x10112600, __thiscall(pawn, origin, direction, ·), RET 0x10), which writes the origin from body part 0. But iron sights come up and a scope's sight picture never shows, and the muzzle flash stays where the gun is in the world. The SCOPE_HI part, a few centimetres ahead of the unleaned eye, is probably culled from the narrow magnified view; that is not confirmed.
  3. The pawn entity rolled right after the post-step, with SetPosition and SetEuler, which tell every component. The muzzle flash then follows the lean, but the body's heading turns on its own for as long as the lean is held, by up to a quarter turn, and the camera with it; and the post-physics write has stood it upright again by the time the camera reads it.
  4. The pawn rolled about its X row from the post-step, on every write. The body tips forward: the view rises and turns.
  5. The pawn rolled after the pre-physics beautifier and stood upright after the post-step. The roll is gone before anything is drawn: the beautifier runs before the physics.
  6. The pawn rolled after the post-step without the physics told (source its CCharacterPhysComponent), re-rolled after each of the engine's writes, both for the post-physics list only and for the whole frame. The matrix holds the roll when the camera reads it, every frame, yet the arms and the gun do not move at all, and the body does not turn.

From 3 and 6 the drawn body seems to follow the physics' own copy of the body, not the entity's matrix, and telling the physics of a tilt sets it turning the body. A physics component told of the lean only between the post-step and the next pre-physics tick list is untried.

Seen in a running game

Weapon entities leaned in the world on every SetMatrix move nothing visible, as the writes above predict. Moving the drawn gun by its draws alone, as in 2, keeps it in the player's hands only while the arms are moved with it: rewriting the arms' draws (40-byte skinned vertices) and not the weapon's (32-byte) leaves the gun behind.

A scope's sight picture​

CFCXWeapon::ShowHiResScope(bool) (0x106D3B80) swaps the weapon's SCOPE_HI part in and every other part out. It keeps its current state at +0x84, and bUseHiResScope at +0x85 decides whether it does anything at all.

CFCXWeapon derives from CWeapon at offset 0, so the equipped weapon is the object to read those two bytes from. CInventoryViewPawn::GetEquippedWeapon (0x10127DA0, __thiscall) returns it, and the pawn's inventory view is *(pawn + 0x10) + 0x4F0.

The weapon's entity is behind an entity proxy at +0x08, at the proxy's +0x0C, and the entity's name, a char* at its +0x14, is its archetype's: weapons.Primary.M16, weapons.Special.Dart_Rifle, and so on. The server's GetWeaponName (0x092F1730) reads the same chain.

When aiming stops, the iron-sight flag goes a few frames before +0x84 does, and the sight picture is drawn until +0x84 goes.

The DLC's crossbow (DLC1Weapons.DLC1.Crossbow) has +0x85 set, but its mesh is one part with no SCOPE_HI, and +0x84 stays nought however long it is aimed: the engine aims it as iron sights, down the scope on its own model (seen in game, GOG v1.03).

Where the scope is drawn from​

Verified via reverse engineering

Read out of ShowHiResScope, CGraphicComponentObject::SetIsVisible (0x10519010), the geometry loader (0x103D2E50, its SDOL chunk at 0x103D2700) and CGeometryResource::ClientProcessRawData (0x1035F080, server 0x097FB3F0). For all six scoped rifles, the counts this gives from the retail .xbg files are the ones Aiming Overhaul measured off their draws in a running game. The walk below has not yet been run in game.

ShowHiResScope takes the weapon entity's CGraphicComponent (CEntity::GetComponent, 0x104E2CC0, by the CRC-32 of the class name) and walks its parts: an array at +0x30, +0x34 of them. A part keeps the hash of its name at +0x0C, which is how SCOPE_HI is found, whether it is shown at +0x30, and at +0x34 a helper holding the part's CGeometryResource at +0x10. Every part of a weapon is drawn from the one resource, its .xbg.

The part's +0x2C is not its hidNodeNameLOD0, though SGraphicComponentObjectDescriptor:: RegisterProperties (0x10519510) registers that field at +0x2C of the descriptor: in a running game it held a heap pointer. When the engine builds a part from the mesh's file descriptor, it names the node of its nearest detail after the part with _LOD0 added (0x1051DE56).

The resource keeps the mesh as loaded at +0x38. In it:

Offset
+0x04, +0x08how many details there are, and the details, 0x24 bytes each, nearest first
+0x60the file's DIKS table, 8 bytes an entry: the CRC-32 of a node's name, such as SCOPE_HI_LOD0, then its part and node as two uint16

A detail:

Offset
+0x00, +0x04its vertex blocks, 16 bytes each: format, stride, vertex count, byte offset
+0x0C, +0x10its draws, 0x1C bytes each: vertex block, DIKS entry, cluster, first index, last vertex, byte offset
+0x18the distance it is drawn from
+0x1C, +0x20the resources holding its vertices and its indices

The loader makes both resources. The vertex one keeps the device's buffer at +0x0C, and that buffer keeps the IDirect3DVertexBuffer9 at +0x08: it is what the engine hands SetStreamSource (0x10430180). A draw's first index is the startIndex of its DrawIndexedPrimitive.

So the gun in first person is drawn from its nearest detail's vertex buffer, and the sight picture by the draws whose DIKS entry is SCOPE_HI_LOD0. The gun's depth pass joins draws that follow one another in the index buffer: the Dragunov's single 2,088-triangle draw there is three of its scope's, 1,008 + 936 + 144 triangles, and starts at the first one's index.

The weapon's events​

CFCXWeapon::OnEvent (0x106D3D00, __thiscall(CBaseEvent* event)) receives the weapon's events by name. The name is a std::string at the event's +0x08: its characters are at +0x0C, inline while the capacity at +0x20 is below 16, and its length is at +0x1C. For the weapon in hand these arrive:

EventWhen
IronSightOnFinishedthe raise to the sights ends
IronSightOffBeginthe sights start to go
PullTriggerthe trigger is pulled, once per pull
WeaponFiredeach round leaves, so more than once for one PullTrigger held
checkModeafter a shot, and as the sights come and go

The rounds in the clip are a count at +0x20 of the weapon's implementation, *(weapon + 0x24), and drop by one with each WeaponFired.

Whether the weapon fires a round a pull is 0x1012EEC0 (__thiscall, no arguments): it reads the fire mode's index at the properties' +0x44 and returns 1 for SingleShot and PrepareShot, 0 for FullAuto. The sound code picks its per-round or looped shots by it (automatic fire).

Seen in a running game

Retail GOG v1.03, from an FCSE plugin: the events above were logged, in that order, while firing through a scope, with the count beside them. Called on the weapon in hand, 0x1012EEC0 returned 0 for the AK-47 and the MAC-10 and 1 for the Makarov and the SPAS-12.

The scope's post effect​

The radial blur toward the screen's edges while a sniper scope is up is a post effect the weapon starts itself: its IronsightFX, which names PostFX.Sniper.RadialBlur, drawn by the PostEffect_RadialBlur shader.

  • CFCXWeapon::OnEvent (0x106D3D00, server 0x088D7700) asks CPostFxManager for it (RequestFX, 0x100B6D30) on the event that ends the raise. On the events that lower the scope it stops it (StopFX, 0x100B6EE0) and calls ShowHiResScope(false).
  • The effect's id is read from the weapon's properties at +0x128, through 0x100F4280. The properties are *(*(weapon + 0x24) + 4) (CWeapon::GetProperties, 0x1012E910).
  • An id of -1 means none: OnEvent then neither starts nor stops anything, and the scope comes and goes as before.

In data the field is the weapon's IronsightFX, a hash naming an effect in the post-effect database: ironsightfx on every retail weapon, FFFFFFFF for none. Aiming Overhaul's weapon data sets none on the scopes it draws itself.

Seen in a running game

Retail GOG v1.03, from an FCSE plugin: the names above came back for every weapon taken in hand. Of 21 scope-ups traced, +0x84 came on in the frame the iron sights' field-of-view weight reached one.

What that means for a weapon's mesh is in replacing a weapon.

Where a first-person shot goes​

CWeaponFireBulletStrategy::SetupShot1st (server 0x08F50BC0) starts the shot at the pawn's body part 0 and points it along that part's rotation, not the weapon's. It then bends the direction by CNoiseMaker::GetNoise (server 0x09008420), in degrees. That noise is scaled up while the pawn moves, by the time since the last shot and by the player's accuracy bonus.

The time since the last shot works through a timer on the strategy: the noise is multiplied by m + (1 − m) · t / T, with T the weapon's fBulletSpread_StabilizationTime and m its fBulletSpread_MinimumSpreadPercentage, and each shot sets t back to T. Where t runs down was not traced. Retail m is 1 on the AK-47, so it gets no bonus at all; it is 0.7 on the AR-16, 0.8 on the M249 and 0.85-0.9 on the G3 and FAL. Nothing grows the spread over a long burst.

GetActualSpreadData (0x1010EC30, server 0x08F4D690, __thiscall(pawn)) picks which noise: the jump one while in the air, the iron-sight ones once the ironsight flag is set and the pawn's skill value at +0x14 has reached 0.75, and the crouched or standing one by stance. The stance is an integer at the effective data's +0xA4, 1 while crouched; the client reads it the same way (0x1010EC79, after CPawn::GetEffectiveData), at the pawn data's +0x374. It returns its pick inside the fire data at the strategy's +0x50: +0x234 standing, +0x2A0 crouched, +0x30C down the sights, +0x378 crouched down the sights and +0x3E4 in the air. In retail data the four sniper rifles have no spread down the sights at all, and the iron-sighted guns about 0.4°.

CNoiseMaker is a Catmull-Rom curve through Gaussian keys of standard deviation fAmplitude, a new key every 1 / fFrequency seconds of game time. The retail BulletSpread_IronSight is 0.4° at 35 keys a second, so a shot's error is effectively random from one shot to the next rather than a drift you could see.

The accuracy bonus​

SetupShot1st (0x10112600) passes the noise's size through CPawn::GetBonus (0x1007E280, __thiscall(object, name, base, lowerIsBetter), returning the float on the FPU stack), with the weapon properties' name at +0x04 as the object and accuracy (0x93450383) as the name. CPawnBonusPlanManager::GetBonus (server 0x09086830) adds up that name's bonus for that object in every plan the player holds, caches the sum, and returns base − base · percent − additive when lower is better. Every gun's operation manual (<gun>_oper_manual in gamemodesconfig.xml's BonusService) gives accuracy and recoil 20 %, and its challenge (<gun>_challenge_bonus) 10 % each, so a manual leaves 0.8 of the noise. A plan's name does not always follow its gun's: de_oper_manual is the deserteagle's, mgl40_oper_manual the MGL140's.

CWeaponFireBulletStrategy::UpdateBulletSpread (0x1010ECC0) runs the same spread data, movement and bonus into the weapon's current spread, a float at the weapon state's +0x64 (the weapon's +0x24), without the time since the last shot. Where a shot goes comes from SetupShot1st alone. This was read in the server build and the Steam DLL, not yet seen in a running game.

A shot out of first person​

CWeaponFireBulletStrategy::SetupShot (0x10113230, server 0x08F52220) picks SetupShot1st (0x10112600) while the pawn's effective flags have the first-person bit 0x80, and SetupShot3rd (0x10112080, server 0x08F51860) otherwise. Both are __thiscall(pawn, origin out, direction out, a fourth it passes on). The bullet's own ray then goes through a filter on layers 0x5BB.

SetupShot3rd starts the shot at the weapon's own model, its node at the strategy's +0x50 or its whole object, and points it along that model's orientation, the barrel as the third-person animation holds it. An AI's shot is turned at its target instead. A player's gets no movement or iron-sight noise there; it gets random spread only if the fire data's +0x1B0 byte is set.

Seen in a running game

With the player out of first person, SetupShot1st never ran. Shots at the sand 5 m ahead landed about 67 px left of the screen's centre, from a camera 0.55 m right of the head. Aimed in SetupShot3rd from the muzzle at what lay under the screen's centre, they landed on it. Retail GOG v1.03, from Third Person.

The game's own crosshair is CGameConfig's HelpCrosshair, an int at the game profile's +0xC8 (look_HelpCrosshair on the console), beside the cheat flags in cheat flags and economy. The HUD finds its a_crosshair area in CFCXMainHudUI::InitCrosshairAreas (0x1080BB30) and asks every frame whether to draw it through CGameConfig::UseHelpCrosshair (0x10048860, __thiscall(difficulty), RET 4). That returns 0 on the hardest difficulty, 3, whatever the setting says, and the setting otherwise. Drawn, it is four ticks around the screen's centre, in first and third person alike.

How far apart they stand is the frame the HUD plays its crosshair area at, (100 − x) · spread · 0.125 held to 0-100, with x a second term not traced. The spread is CWeapon::GetCurrentSpread (0x1012EB40), the weapon state's +0x64, and the HUD's crosshair update (0x1080AF10) is its only caller. When the iron-sight flag changes, CFCXMainHudUI::ToggleIronSightCrosshair (server 0x08A4E7D0) plays the area from frame 11 down the sights and from frame 1 out of them.

Recoil​

Each shot, CWeapon::SWeaponImpl::Shoot (server 0x08F4C720) asks the weapons service for the gun's kick, CFCXWeaponsService::GetRecoilIntensity (server 0x087A0700). It reads fVerticalRecoilPerShot and fHorizontalRecoilPerShot at the weapon's reliability level, in degrees. It scales both by the pawn's recoil bonus and, down the sights, by fIronsightRecoilFactor, and passes on fRecoilAchieveTime. Shoot then sets the desired recoil to the effective recoil plus the vertical kick, capped at fRecoilMax degrees, and a yaw drawn evenly within the horizontal kick either side of the effective one, and raises the new-kick flag.

FieldDesired dataEffective dataPawn data
pitch, up positive, radians+0xD4+0xD4+0x214, +0x3A4
yaw, radians+0xD8+0xD8+0x218, +0x3A8
seconds to reach it+0xDC+0xDC+0x21C
new kick, a byte+0xE0+0xE0+0x220

CPawnBeautifierFirst::UpdateRecoil (0x100A0050, server 0x092E52C0, __thiscall(float seconds), its pawn at +0x10) consumes the flag. It blends the effective recoil from where it stands to the desired one over those seconds through a curve. It then takes a recovery time from CFCXWeaponsService::GetRecoilRecoveryTime (server 0x0879D630) and blends back to nought. That time is the RecoilRecoveryTable entry for the weapon's iRecoilRecoveryLevel, one entry further on outside the sights. A new kick in either phase starts again from where the recoil stands, so a burst climbs and the return begins after its last shot.

A mounted weapon's beautifier has its own (0x100A36B0), which copies the desired recoil straight over, and so does a vehicle passenger's (0x100AFA40).

UpdateLook spends a downward mouse pull on the desired recoil pitch first, while that is above nought. Only what is left moves the look, so pulling down never takes the aim below where the burst began.

Seen in a running game

Down a new AK-47's sights each kick was 0.0106 rad (1.1° × 0.55) up and within ±0.0038 rad sideways. A 15-round burst raised the view about 200 px and the game brought it back within 1.5 s. Taking each kick before UpdateRecoil runs, by setting the desired recoil to the effective one and clearing the flag, kept the recoil still. With the kick added to the look instead, the climb stayed. Retail GOG v1.03, from Aiming Overhaul.