mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
const props in analyser
This commit is contained in:
parent
2c1dc17e49
commit
eaa8d1f495
2 changed files with 49 additions and 36 deletions
|
|
@ -68,6 +68,7 @@ impl Default for Team {
|
||||||
Debug, Clone, Serialize, Copy, PartialEq, Eq, Hash, TryFromPrimitive, Display, FromStr,
|
Debug, Clone, Serialize, Copy, PartialEq, Eq, Hash, TryFromPrimitive, Display, FromStr,
|
||||||
)]
|
)]
|
||||||
#[display(style = "lowercase")]
|
#[display(style = "lowercase")]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Class {
|
pub enum Class {
|
||||||
Other = 0,
|
Other = 0,
|
||||||
|
|
|
||||||
|
|
@ -263,46 +263,58 @@ impl GameStateAnalyser {
|
||||||
pub fn handle_player_entity(&mut self, entity: &PacketEntity) {
|
pub fn handle_player_entity(&mut self, entity: &PacketEntity) {
|
||||||
let player = self.state.get_or_create_player(entity.entity_index);
|
let player = self.state.get_or_create_player(entity.entity_index);
|
||||||
|
|
||||||
|
const HEALTH_PROP: SendPropIdentifier =
|
||||||
|
SendPropIdentifier::new("DT_BasePlayer", "m_iHealth");
|
||||||
|
const MAX_HEALTH_PROP: SendPropIdentifier =
|
||||||
|
SendPropIdentifier::new("DT_BasePlayer", "m_iMaxHealth");
|
||||||
|
const LIFE_STATE_PROP: SendPropIdentifier =
|
||||||
|
SendPropIdentifier::new("DT_BasePlayer", "m_lifeState");
|
||||||
|
|
||||||
|
const LOCAL_ORIGIN: SendPropIdentifier =
|
||||||
|
SendPropIdentifier::new("DT_TFLocalPlayerExclusive", "m_vecOrigin");
|
||||||
|
const NON_LOCAL_ORIGIN: SendPropIdentifier =
|
||||||
|
SendPropIdentifier::new("DT_TFNonLocalPlayerExclusive", "m_vecOrigin");
|
||||||
|
const LOCAL_ORIGIN_Z: SendPropIdentifier =
|
||||||
|
SendPropIdentifier::new("DT_TFLocalPlayerExclusive", "m_vecOrigin[2]");
|
||||||
|
const NON_LOCAL_ORIGIN_Z: SendPropIdentifier =
|
||||||
|
SendPropIdentifier::new("DT_TFNonLocalPlayerExclusive", "m_vecOrigin[2]");
|
||||||
|
const LOCAL_EYE_ANGLES: SendPropIdentifier =
|
||||||
|
SendPropIdentifier::new("DT_TFLocalPlayerExclusive", "m_angEyeAngles[1]");
|
||||||
|
const NON_LOCAL_EYE_ANGLES: SendPropIdentifier =
|
||||||
|
SendPropIdentifier::new("DT_TFNonLocalPlayerExclusive", "m_angEyeAngles[1]");
|
||||||
|
const LOCAL_PITCH_ANGLES: SendPropIdentifier =
|
||||||
|
SendPropIdentifier::new("DT_TFLocalPlayerExclusive", "m_angEyeAngles[0]");
|
||||||
|
const NON_LOCAL_PITCH_ANGLES: SendPropIdentifier =
|
||||||
|
SendPropIdentifier::new("DT_TFNonLocalPlayerExclusive", "m_angEyeAngles[0]");
|
||||||
|
|
||||||
for prop in entity.props() {
|
for prop in entity.props() {
|
||||||
if let Some((table_name, prop_name)) = self.prop_names.get(&prop.identifier) {
|
match prop.identifier {
|
||||||
match table_name.as_str() {
|
HEALTH_PROP => {
|
||||||
"DT_BasePlayer" => match prop_name.as_str() {
|
|
||||||
"m_iHealth" => {
|
|
||||||
player.health = i64::try_from(&prop.value).unwrap_or_default() as u16
|
player.health = i64::try_from(&prop.value).unwrap_or_default() as u16
|
||||||
}
|
}
|
||||||
"m_iMaxHealth" => {
|
MAX_HEALTH_PROP => {
|
||||||
player.max_health =
|
player.max_health = i64::try_from(&prop.value).unwrap_or_default() as u16
|
||||||
i64::try_from(&prop.value).unwrap_or_default() as u16
|
|
||||||
}
|
}
|
||||||
"m_lifeState" => {
|
LIFE_STATE_PROP => {
|
||||||
player.state =
|
player.state = PlayerState::new(i64::try_from(&prop.value).unwrap_or_default())
|
||||||
PlayerState::new(i64::try_from(&prop.value).unwrap_or_default())
|
|
||||||
}
|
}
|
||||||
_ => {}
|
LOCAL_ORIGIN | NON_LOCAL_ORIGIN => {
|
||||||
},
|
|
||||||
"DT_TFLocalPlayerExclusive" | "DT_TFNonLocalPlayerExclusive" => {
|
|
||||||
match prop_name.as_str() {
|
|
||||||
"m_vecOrigin" => {
|
|
||||||
let pos_xy = VectorXY::try_from(&prop.value).unwrap_or_default();
|
let pos_xy = VectorXY::try_from(&prop.value).unwrap_or_default();
|
||||||
player.position.x = pos_xy.x;
|
player.position.x = pos_xy.x;
|
||||||
player.position.y = pos_xy.y;
|
player.position.y = pos_xy.y;
|
||||||
}
|
}
|
||||||
"m_vecOrigin[2]" => {
|
LOCAL_ORIGIN_Z | NON_LOCAL_ORIGIN_Z => {
|
||||||
player.position.z = f32::try_from(&prop.value).unwrap_or_default()
|
player.position.z = f32::try_from(&prop.value).unwrap_or_default()
|
||||||
}
|
}
|
||||||
"m_angEyeAngles[1]" => {
|
LOCAL_EYE_ANGLES | NON_LOCAL_EYE_ANGLES => {
|
||||||
player.view_angle = f32::try_from(&prop.value).unwrap_or_default()
|
player.view_angle = f32::try_from(&prop.value).unwrap_or_default()
|
||||||
}
|
}
|
||||||
"m_angEyeAngles[0]" => {
|
LOCAL_PITCH_ANGLES | NON_LOCAL_PITCH_ANGLES => {
|
||||||
player.pitch_angle = f32::try_from(&prop.value).unwrap_or_default()
|
player.pitch_angle = f32::try_from(&prop.value).unwrap_or_default()
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_world_entity(&mut self, entity: &PacketEntity) {
|
pub fn handle_world_entity(&mut self, entity: &PacketEntity) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue