OpenCoD2-Plus
Call of Duty 2 client & server, rebuilt
Loading...
Searching...
No Matches
cod2snap Namespace Reference

Classes

class  ParseError
class  MsgReader
class  ServerState

Functions

 _fields (text)
 _zero (fields)
 read_playerstate_field (r, bits)
 read_delta_field (r, base, name, bits, plus_time=None)
 read_delta_struct (r, base, fields, plus_time=None)
 read_delta_fields (r, base, fields)
 read_hudelems (r)
 read_playerstate (r)
 grouped (values)

Variables

 SVC_DOWNLOAD
 SVC_SNAPSHOT
 SVC_EOF
 SVC_SNAPSHOT_PLUS
int PLUS_TIME_OFFSET_BITS = 11
int GENTITYNUM_BITS = 10
int MAX_GENTITIES = 1 << GENTITYNUM_BITS
int CLIENTNUM_BITS = 6
int MAX_STATS = 6
int MAX_OBJECTIVES = 16
int OBJECTIVE_STATE_BITS = 3
int HUDELEM_BITS = 5
int MAX_HUDELEMS = 31
int FLOAT_INT_BIAS = 1 << 12
int HUDELEM_COORD_BIAS = 1 << 9
int ET_PLAYER = 1
str _PS
str _ENTITY
str _CLIENT
str _OBJECTIVE = "origin[0] 0; origin[1] 0; origin[2] 0; icon 12; entNum 10; teamNum 4"
str _HUDELEM
 PLAYERSTATE_FIELDS = _fields(_PS)
 ENTITY_FIELDS = _fields(_ENTITY)
 CLIENT_FIELDS = _fields(_CLIENT)
 OBJECTIVE_FIELDS = _fields(_OBJECTIVE)
 HUDELEM_FIELDS = _fields(_HUDELEM)

Detailed Description

Parser for the messages a CoD2 server sends to a client, for tests.

It mirrors the server's writers (SV_SendClientGameState, SV_SendClientSnapshot,
SV_WriteSnapshotToClient and the MSG_WriteDelta* functions of msg_mp.cpp), so a
message that parses must end exactly on its svc_EOF. 1.0 and 1.3 write these
messages the same way; only the netchan differs, and cod2client handles that.

Only non-delta snapshots are read (the client sends CLC_MOVE_NO_DELTA): the
playerstate is a delta from a zeroed one, the entities deltas from their
gamestate baselines and the client states deltas from zeroed ones.

Function Documentation

◆ _fields()

cod2snap._fields ( text)
protected

◆ _zero()

cod2snap._zero ( fields)
protected

◆ grouped()

cod2snap.grouped ( values)
Joins the fields of one array into a list, so 'pos.trBase[0..2]' becomes
'pos.trBase': [x, y, z]; a client's name ints become its name string.

◆ read_delta_field()

cod2snap.read_delta_field ( r,
base,
name,
bits,
plus_time = None )
MSG_ReadDeltaField. The writer compares the field pointers, not the
values, so every field up to the last changed one has its changed bit set;
then a value that is zero is sent as a single 0 bit. plus_time is the time
of a Plus snapshot, whose pos.trTime can be an offset from it.

◆ read_delta_fields()

cod2snap.read_delta_fields ( r,
base,
fields )
MSG_ReadDeltaFields: one bit, then every field or none.

◆ read_delta_struct()

cod2snap.read_delta_struct ( r,
base,
fields,
plus_time = None )
MSG_ReadDeltaStruct after the index: returns None when the struct is
removed, else the new values (base updated with the first lc fields).

◆ read_hudelems()

cod2snap.read_hudelems ( r)

◆ read_playerstate()

cod2snap.read_playerstate ( r)
MSG_ReadDeltaPlayerstate from a zeroed playerstate.

◆ read_playerstate_field()

cod2snap.read_playerstate_field ( r,
bits )
MSG_WriteDeltaPlayerstate: no 'is zero' bit for floats and integers.

Variable Documentation

◆ _CLIENT

str cod2snap._CLIENT
protected
Initial value:
1= """
2team 2; name[0] 32; name[4] 32; modelindex 8; attachModelIndex[1] 8;
3attachModelIndex[0] 8; name[8] 32; name[12] 32; name[16] 32; name[20] 32;
4name[24] 32; name[28] 32; attachTagIndex[5] 5; attachTagIndex[0] 5;
5attachTagIndex[1] 5; attachTagIndex[2] 5; attachTagIndex[3] 5;
6attachTagIndex[4] 5; attachModelIndex[2] 8; attachModelIndex[3] 8;
7attachModelIndex[4] 8; attachModelIndex[5] 8
8"""

◆ _ENTITY

str cod2snap._ENTITY
protected
Initial value:
1= """
2pos.trTime 32; pos.trBase[1] 0; pos.trBase[0] 0; pos.trDelta[0] 0;
3pos.trDelta[1] 0; angles2[1] 0; apos.trBase[1] -100; pos.trDelta[2] 0;
4pos.trBase[2] 0; apos.trBase[0] -100; eventSequence 8; legsAnim 10; eType 8;
5eFlags 24; otherEntityNum 10; surfType 8; eventParm 8; scale 8; clientNum 8;
6torsoAnim 10; groundEntityNum 10; events[0] 8; events[1] 8; events[2] 8;
7angles2[0] 0; events[3] 8; apos.trBase[2] -100; pos.trType 8; fWaistPitch 0;
8fTorsoPitch 0; apos.trTime 32; solid 24; apos.trDelta[0] 0; apos.trType 8;
9animMovetype 4; fTorsoHeight 0; apos.trDelta[2] 0; weapon 7; index 10;
10apos.trDelta[1] 0; eventParms[0] 8; eventParms[1] 8; eventParms[2] 8;
11eventParms[3] 8; iHeadIcon 4; pos.trDuration 32; iHeadIconTeam 2; time 32;
12leanf 0; attackerEntityNum 10; time2 32; loopSound 8; origin2[2] 0;
13origin2[0] 0; origin2[1] 0; angles2[2] 0; constantLight 32;
14apos.trDuration 32; dmgFlags 32
15"""

◆ _HUDELEM

str cod2snap._HUDELEM
protected
Initial value:
1= """
2y -99; type 4; color.rgba 32; x -99; alignScreen 6; fontScale 0;
3materialIndex 8; width 10; height 10; fadeStartTime 32; fromColor.rgba 32;
4fadeTime 16; value 0; time 32; z -99; alignOrg 4; sort 0; text 8; font 4;
5scaleStartTime 32; scaleTime 16; fromHeight 10; label 8; fromWidth 10;
6moveStartTime 32; moveTime 16; fromX -99; fromY -99; fromAlignScreen 6;
7fromAlignOrg 4; duration 32; foreground 1
8"""

◆ _OBJECTIVE

str cod2snap._OBJECTIVE = "origin[0] 0; origin[1] 0; origin[2] 0; icon 12; entNum 10; teamNum 4"
protected

◆ _PS

str cod2snap._PS
protected
Initial value:
1= """
2commandTime 32; origin[1] 0; origin[0] 0; bobCycle 8; viewangles[1] -100;
3origin[2] 0; velocity[1] 0; velocity[0] 0; viewangles[0] -100; movementDir -8;
4velocity[2] 0; eventSequence 8; legsAnim 10; aimSpreadScale 0; weaponTime -16;
5pm_flags 27; events[0] 8; events[1] 8; events[2] 8; events[3] 8; weapAnim 10;
6viewHeightCurrent 0; torsoTimer 16; torsoAnim 10; eFlags 24; fWeaponPosFrac 0;
7holdBreathScale 0; weaponstate 5; viewHeightTarget -8; weaponDelay -16;
8legsTimer 16; viewHeightLerpTarget -8; groundEntityNum 10; pm_time -16;
9eventParms[3] 8; eventParms[1] 8; eventParms[0] 8; eventParms[2] 8; weapon 7;
10weapons[0] 32; viewHeightLerpDown 1; weaponslots[0] 32; delta_angles[0] 16;
11delta_angles[1] 16; cursorHintString -8; offHandIndex 7; clientNum 8;
12viewlocked_entNum 16; viewmodelIndex 8; viewHeightLerpTime 32; speed 16;
13mins[1] 0; mins[0] 0; maxs[2] 0; maxs[1] 0; maxs[0] 0; gravity 16;
14damageTimer 16; cursorHint 8; mantleState.flags 4; flinchYaw 16; fWaistPitch 0;
15mantleState.timer 32; fTorsoPitch 0; proneTorsoPitch 0; holdBreathTimer 16;
16jumpTime 32; viewangles[2] -100; foliageSoundTime 32; weapons[1] 32;
17damageEvent 8; damageDuration 16; damageYaw 8; proneDirection 0;
18proneDirectionPitch 0; mantleState.yaw 0; mantleState.transIndex 4;
19fTorsoHeight 0; damagePitch 8; jumpOriginZ 0; pm_type 8; viewlocked 8;
20weaponrechamber[0] 32; vLadderVec[0] 0; weaponslots[4] 32;
21weaponRestrictKickTime -16; vLadderVec[1] 0; viewAngleClampRange[1] 0;
22viewAngleClampRange[0] 0; viewAngleClampBase[1] 0; weaponrechamber[1] 32;
23leanf 0; damageCount 7; grenadeTimeLeft -16; deltaTime 32; shellshockTime 32;
24shellshockIndex 4; shellshockDuration 16; vLadderVec[2] 0; delta_angles[2] 16;
25viewHeightLerpPosAdj 0; mins[2] 0; viewAngleClampBase[0] 0; adsDelayTime 32;
26iCompassFriendInfo 32
27"""

◆ CLIENT_FIELDS

cod2snap.CLIENT_FIELDS = _fields(_CLIENT)

◆ CLIENTNUM_BITS

int cod2snap.CLIENTNUM_BITS = 6

◆ ENTITY_FIELDS

cod2snap.ENTITY_FIELDS = _fields(_ENTITY)

◆ ET_PLAYER

int cod2snap.ET_PLAYER = 1

◆ FLOAT_INT_BIAS

int cod2snap.FLOAT_INT_BIAS = 1 << 12

◆ GENTITYNUM_BITS

int cod2snap.GENTITYNUM_BITS = 10

◆ HUDELEM_BITS

int cod2snap.HUDELEM_BITS = 5

◆ HUDELEM_COORD_BIAS

int cod2snap.HUDELEM_COORD_BIAS = 1 << 9

◆ HUDELEM_FIELDS

cod2snap.HUDELEM_FIELDS = _fields(_HUDELEM)

◆ MAX_GENTITIES

int cod2snap.MAX_GENTITIES = 1 << GENTITYNUM_BITS

◆ MAX_HUDELEMS

int cod2snap.MAX_HUDELEMS = 31

◆ MAX_OBJECTIVES

int cod2snap.MAX_OBJECTIVES = 16

◆ MAX_STATS

int cod2snap.MAX_STATS = 6

◆ OBJECTIVE_FIELDS

cod2snap.OBJECTIVE_FIELDS = _fields(_OBJECTIVE)

◆ OBJECTIVE_STATE_BITS

int cod2snap.OBJECTIVE_STATE_BITS = 3

◆ PLAYERSTATE_FIELDS

cod2snap.PLAYERSTATE_FIELDS = _fields(_PS)

◆ PLUS_TIME_OFFSET_BITS

int cod2snap.PLUS_TIME_OFFSET_BITS = 11

◆ SVC_DOWNLOAD

cod2snap.SVC_DOWNLOAD

◆ SVC_EOF

cod2snap.SVC_EOF

◆ SVC_SNAPSHOT

cod2snap.SVC_SNAPSHOT

◆ SVC_SNAPSHOT_PLUS

cod2snap.SVC_SNAPSHOT_PLUS