cod2_linux and cod2_win32.exe: the reconstructed engine, with local games
on OpenCoD2-Plus Server's server (ADR 0004).
| Item | Detail |
|---|---|
| Switch | none: every client (Linux, Windows on MinGW and the MSVC ABI, x64, web) links it; COD2_PLUS_CLIENT_SERVER is set when the configure builds a client |
| What it links | OpenCoD2-Plus Server's server, game, bgame and collision (src/qcommon/cm_*.cpp) built with LISTEN_SERVER, on the engine's core and xanim |
| Bridge | --module client_server: exports test/client_server_interface.txt, imports checked against test/client_server_abi.txt; src/compat/client_server_missing.cpp has what the engine lacks (libcod's critical sections and threads, Sys_SleepMSec, Com_GetBspLump, weapon info memory) |
| Blob guards | COD2_PLUS_GAME (server/game/bgame globals), COD2_PLUS_CM (cm, cm_world, g_traceThreadInfo); COD2_PLUS_SERVER only in the dedicated server |
LISTEN_SERVER |
keeps DEDICATED undefined, so OpenCoD2-Plus Server's server builds its client calls (CL_InitLoad, CL_MapLoading, CL_ShutdownAll, CL_StartLoading, CL_Disconnect) |
| 1.0 limit | the 1.0 client's core speaks protocol 115 only; libcod's multi-protocol server is not reachable from it |
The ABI files hold the engine side's 1.3 ABI, kept by hand (format in
scripts/engine_abi.py); they were recorded from a client still built with the
engine's own server.
| bgame | Used by | State |
|---|---|---|
engine src/PC/bgame (globals prefixed eng_) |
cgame: prediction, animation | bgs |
OpenCoD2-Plus Server src/bgame |
local server | level_bgs |
Prediction follows OpenCoD2-Plus Server line by line: bg_pmove.c, bg_slidemove.c,
bg_jump.c, bg_mantle.c, bg_weapons_pm.c, and its math in
bg_plus_math.c (bit-exact over 200,000 random inputs). Constants:
src/PC/bgame/bg_plus_consts.h, generated by scripts/bgame_plus_consts.py
from test/bgame_plus_consts.txt. Still the engine's: pmoveHandlers,
viewLerp, the jump/mantle dvars and the rest of bg_weapons.c. The
animation script bg_animation_mp.c follows OpenCoD2-Plus Server too, except its
parser, which was already 1.3's and parses alike
(scripts/anim_script_test.py compares the two).
cgame loads its own weapons and mantle anims, as with a remote server.
A server is not trusted; 1.3 trusted it. With COD2_FEATURE_NET_HARDENING (on
in every build), NetHardening_ServerMaySetCvar (src/PC/qcommon/net_hardening.c)
decides which dvars a server sets through systeminfo, v and the codinfo
configstrings: dvars flagged SYSTEMINFO or CODINFO always (the physics prediction
needs, such as jump_height and player_*, are CODINFO), never activeAction,
nextdemo, the download switches, fs_, sv_, net_, rcon and in_ names,
or other read-only and init dvars. A download's local name must be a relative
.iwd without .., and a redirect's URL http or https; a Plus server's plus:<name>, on a
Plus connection only, becomes http://<server ip>:<port>/<name>
(NetHardening_PlusUrl) with the same check on the name. A transfer shorter
than the size the server gave counts as failed.
Numbers that are wider on the wire than the arrays they index are bounded where
they enter: MSG_ReadBitsCompressLimit, MSG_ReadDeltaPlayerstate and
CL_ParseGamestate drop the client; CL_GetSnapshot drops an entity or a
playerstate value only a hostile server sends, before cgame sees it.
scripts/hostile_server_test.py sends a real client each of these.
CL_GetServerCommand (src/PC/client_mp/cl_cgame_mp.c) handles some letters
itself, as the 1.3 binary's switch at 0x4017fa; the rest reach
CG_ServerCommand (src/PC/cgame_mp/cg_servercmds_mp.c).
| Letter | Client | cgame |
|---|---|---|
w |
disconnect (with reason) | |
x, y, z |
big configstring: first, middle, last part (z re-runs as d) |
|
d |
configstring changed | configstring changed |
B, n |
map_restart: clear notify, cmds, flares | map_restart (B), with persist (n) |
b |
scores | |
c / e f / g |
announcement / game message / bold message | |
C |
equipped offhand |
CG_DrawActiveFrame calls CG_UpdateEntInfo (src/PC/cgame_mp/cg_ents_mp.c,
the binary's 0x4cfbb0) after renderingThirdPerson and before
CG_AddPacketEntities: for each snapshot entity it advances the DObj's
animation (CG_DObjUpdateInfo), processes notetracks and sets the position
for cg->time (CG_CalcEntityLerpPositions). Nothing else advances an
entity's body animation.
A shot's recoil (BG_WeaponFireRecoil, from CG_FireWeapon) adds to
cg->kickAVel. Right after CG_UpdateEntInfo, CG_KickAngles
(src/PC/cgame_mp/cg_view_mp.c, the binary's 0x4cec80) turns that speed into
cg->kickAngles, pulling them back to center at the weapon's
hipViewKickCenterSpeed or adsViewKickCenterSpeed (2400 with no weapon) in
5 ms steps, 10 degrees at most. It runs only while the next snapshot has
pm_flags & 0x800000; otherwise both are zeroed. CG_DrawActive sends the
kick angles plus cg->offsetAngles with the usercmd
(CL_SetUserCmdAimValues), so the view and the aim move together.
CG_DamageFeedback stores the hit's snapshot time in cg->damageTime and the
kick angles in v_dmg_pitch/v_dmg_roll; CG_CalcViewValues passes
damageTime and cg->time, both less ps->deltaTime, to
BG_CalculateViewAngles, as 1.3 (0x4cee35), which eases the view to the
kick in 100 ms and back in 400. COD2_TRACE_VIEWDAMAGE prints the added
angles in the second after a hit.
The eye's bob follows the same function, driven by cg->xyspeed, the
horizontal speed (BG_GetSpeed; 1.3 0x4cfa44): the vertical bob raises it, the
horizontal one moves it along the view's right (0x4cef6c), both capped by
bg_bobMax (a float dvar); a landing time ahead of the clock is put 450 ms
back (0x4cf0ca). COD2_TRACE_VIEWBOB prints the horizontal bob and where
it moved the eye.
After the view is copied to cg->viewModelOrigin/Axis/Angles (for the
view weapon), CG_ApplyViewAnimation (0x4cf730) multiplies the view by
the view weapon's tag_camera bone from the skeleton last drawn, so firing,
reloading and melee animations move the camera (every viewmodel animation
keys that bone; at rest it is the identity). COD2_TRACE_VIEWANIM prints
the bone's rotation and offset.
A shellshock's view kick (CG_UpdateShellShock) samples a 131-point noise
table, the binary's at 0x59e1e0, and CG_PerturbCamera (0x4d2320) turns
the view by the rotation with rows (1, viewDelta), up × it and it × that.
COD2_TRACE_PERTURB prints the turned axis's determinant.
CG_AddViewWeapon (src/PC/cgame_mp/cg_weapons.c, the binary's 0x4d6390)
copies the weapon's motion state from cg into a weaponState_t, runs
BG_CalculateWeaponAngles and writes vLastMoveAng, fLastIdleFactor,
vGunOffset and vGunSpeed back, so the gun kick spring, the idle factor and
the move lag carry over between frames. Its time base is ps->deltaTime.
The hand's position follows CG_CalculateWeaponPosition (0x4d5970): an
offset in the view model's frame (forward, left, up) from the lean (scaled
out while aiming down the sight), the move and stance offset
(CG_CalculateWeaponMovement, 0x4d53d0: the weapon's v*Move and
v*Ofs plus cg_gun_move_* and cg_gun_ofs_*, eased at its
fPosMoveRate) and the sway, turned to the world from cg->viewModelOrigin
and viewModelAngles; then the dip after a landing (landChange × 0.25,
150 ms down, 300 ms back) and cg_gun_x/_y/_z along the view axis. The
sway is scaled by the weapon's swayShellShockScale while a shellshock
fades. COD2_TRACE_VIEWWEAPON prints the hand's offset from the eye each
frame (scripts/view_weapon_test.py reads it).
CG_AddViewWeapon also keeps the aim state other code reads, as 1.3 does:
playerEntity.bPositionToADS (set when the aim starts from 0, cleared at 1,
0x4d5bc0) picks the weapon's zoom-in or zoom-out fractions for the field of
view (CG_GetViewFov), the reticle zoom (CG_GetWeapReticleZoom) and the
crosshair fade (CG_DrawCrosshair); cg->gunPitch
and gunYaw are the hand's absolute angles while aiming a weapon with
bADSPositionInfo and no overlay reticle, the view's otherwise
(CG_CalcCrosshairPosition); gunXOfs–gunZOfs are the hand's offset from
the eye scaled by the aim fraction.
As the 1.3 binary (IN_Frame 0x464b30, IN_MouseMove 0x4649c0), the SDL
event pump (src/unix/linux_input.c) keeps the mouse captured and the system
cursor hidden (SDL relative mode) in menus too; it lets the mouse go only when
the window loses focus or the console is open with r_fullscreen 0, and never captures it with in_mouse 0 (IN_WantMouse, src/unix/in_mouse.h). Menus'
cursor moves by the mouse's deltas (CL_MouseEvent → UI_MouseEvent), so it
does not depend on the window's size.
The engine's cgs_t and cg_t are laid out differently from the binary's; code
reaches their fields by name, never by the binary's raw offsets (corpse info,
media, fxs, bgs.clientinfo were all found reading 0x1000–0x1c180 bytes
short).
Written here, after the ones players know from CoD2x, whose code is not reused: it has no license, and it patches the running 1.3 binary.
| Dvar | Does |
|---|---|
sensitivity_MG |
multiplies the sensitivity on a turret; 1 is 1.3 |
cg_drawCompass |
0 hides the compass, its owner draws in CG_OwnerDraw |
cg_hudCompassOffsetX, cg_hudCompassOffsetY |
move the compass, in 640x480 units |
cg_drawSpectatedPlayerName |
0 hides "following" and the name when spectating |
com_freezeWatch |
seconds without a frame before the Windows client writes cod2_freeze_<pid>.txt with the main thread's stack, once per freeze; 0 is off. It only reports: a slow map load leaves one too |
r_water |
1 (default) draws water with our shader, waves that drift and a fresnel reflection of the map's sky, and with a depth texture (no antialiasing) a foaming shore and a refracted bottom; 0 is 1.3's, after vid_restart (renderer) |
cl_hideServerIp |
1 masks the digits of every IPv4 address the renderer draws, and of its port, for streaming: the scoreboard's server address, the console, menus, an edit field from the address's second dot. Done on the drawn copy in R_AddCmdDrawTextWithCursor (r_hide_address.h), so the server browser still joins with the real one; host names, logs and the window's title are not masked, and a dotted version such as 1.4.4 is. A server cannot set it |
loc_language |
French, German, Italian and Spanish (1–4) can be picked on an install that only has localized_english files: those stay in use (sounds, images, .str files) and the .str lines of the chosen language replace English where present (FS_LocalizedLanguageInUse). 1.3 fell back to English. Russian, Polish and the Asian languages still need their own files, as the stock fonts are Windows-1252. Set it with loc_language N then vid_restart, or a menu's uiScript updateLanguage; the stock multiplayer menus have no language list. A mod that ships a partial localized_<language> iwd turns that language's own files on and the english ones off, as 1.3 does |
cl_vehicleInvertPitch |
1 inverts the mouse's pitch (CL_MouseMove), for a vehicle mod to set with setClientCvar while a player flies, as with a stick: mouse down, nose up. Not archived, and m_pitch is left alone, so a disconnect in flight leaves no inverted mouse; CL_InitCGame and CG_MapRestart set it back to 0. Keys (+lookup, +lookdown) are not inverted. A player whose m_pitch is already inverted flies with the mouse the other way, normal for them |
com_writeConfig |
0 stops the automatic write of config_mp.cfg; the writeconfig command still works. Not archived, as nothing would save it: it goes in the config as set com_writeConfig 0, or on the command line. A server cannot set it |
The client holds 4096 dvars, against 1.3's 1280, which big mods reach, and a command buffer of 512 KB, against 64 KB, as exec needs the whole config_mp.cfg to fit. cl_maxpackets goes up to 125, one packet per frame at com_maxfps 125. snaps
stays at 30: the server caps it there, and at 40 Hz g_forceSnaps decides. There
is no raw mouse option: SDL's relative mode already reads Raw Input on Windows.
snd_driver.c is 1.3's driver and talks to Miles' AIL_* interface. Those
calls land in src/snd_sdl/ on both clients
(ADR 0012): the game's
mss32.dll and miles/ folder are not loaded.
| File | Does |
|---|---|
snd_ail.c |
the AIL_* functions, the SDL device, the callback, snd_stats |
snd_mix.c |
54 voices to PCM16 and the reverb send: resampling, saturation |
snd_wav.c |
WAV and IMA ADPCM, downsampling at load |
snd_spatial.c |
the volume, pan and distance law of msssoft.m3d |
snd_stream.c |
WAV and MP3 streams, one reader thread, a second of ring each |
snd_reverb.c |
the reverb bus and its table of 26 rooms |
Voices: 8 2D, 32 3D, 13 streams and raw, the handles being pointers into a
table of snd_ail.c. A stream or raw voice is fed in blocks of 256 frames into
a small window the mixer treats as a sample. AIL_end_sample leaves the voice
with no pointer, so the hunk can go. Streams must be closed by
SND_StopSounds(8): FS_Shutdown then closes their files under the reader,
which is why snd_driver.c closes a stream it does not start. snd_stats
prints the worst and last callback and the underruns.
SDL_AUDIODRIVER=disk SDL_DISKAUDIOFILE=out.raw writes what the device would
get, which is what scripts/sound_test.py measures.
Reverb is the one thing that only resembles Miles: a Freeverb-style bus (8 combs
and 4 allpasses a channel) with the public EAX presets, one row per name of
snd_roomStrings. Each voice sends its mix times its wet, which is what
SND_Update*ChannelReverb sets and where snd_enableReverb acts. The bus's own
level is the room's: in Miles setting a room sets that level too, and
SND_SetRoomtype's last call, AIL_set_3D_room_type, does so after the driver
set its levels. So generic is off, at any wet. The bus sleeps once a tail falls
below PCM16 for 0.6 s, which also keeps it from reaching denormals.
Draws with real Direct3D 9 by default (renderer.md); on Windows
the engine prints only to its console window, COD2_CONSOLE_STDOUT=1 copies
it to stdout. Under Wine: scripts/portable_wine.sh.