Skip to content

Commit

Permalink
add is_airbone prop
Browse files Browse the repository at this point in the history
  • Loading branch information
LaihoE committed Aug 3, 2024
1 parent 8cdf50d commit 1ed70c5
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
60 changes: 60 additions & 0 deletions src/parser/src/e2e_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ pub fn _create_ge_tests() {
"is_alive".to_string(),
"user_id".to_string(),
"agent_skin".to_string(),
"is_airborne".to_string(),
];

let wanted_events = vec!["all".to_string()];
Expand Down Expand Up @@ -667,6 +668,7 @@ pub fn _create_tests() {
"is_alive".to_string(),
"user_id".to_string(),
"agent_skin".to_string(),
"is_airborne".to_string(),
];
let huf = create_huffman_lookup_table();

Expand Down Expand Up @@ -717,6 +719,7 @@ pub fn _create_tests() {
custom.insert(STEAMID_ID, "steamid");
custom.insert(NAME_ID, "name");
custom.insert(WEAPON_STICKERS_ID, "weapon_stickers");
custom.insert(IS_AIRBORNE_ID, "is_airborne");

for (k, v) in d.df {
if let Some(real_name) = d.prop_controller.id_to_name.get(&k) {
Expand Down Expand Up @@ -1032,6 +1035,7 @@ fn create_data() -> (DemoOutput, PropController, BTreeMap<String, Vec<GameEvent>
"weapon_stickers".to_string(),
"weapon_float".to_string(),
"weapon_paint_seed".to_string(),
"is_airborne".to_string(),
];

let wanted_events = vec![];
Expand Down Expand Up @@ -1309,6 +1313,62 @@ mod tests {
let prop_id = out.1.name_to_id[prop.0];
assert_eq!(out.0.df[&prop_id], prop.1);
}
#[test]
fn is_airborne() {
let prop = (
"is_airborne",
PropColumn {
data: Some(Bool(
[
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(true),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(true),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
Some(false),
]
.to_vec(),
)),
num_nones: 0,
},
);
assert_eq!(out.0.df[&IS_AIRBORNE_ID], prop.1);
}

#[test]
fn CCSPlayerController_m_nQuestProgressReason() {
let prop = (
Expand Down
11 changes: 11 additions & 0 deletions src/parser/src/first_pass/prop_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub const PLAYER_Y_ID: u32 = 100000017;
pub const PLAYER_Z_ID: u32 = 100000018;
pub const WEAPON_STICKERS_ID: u32 = 100000019;
pub const INVENTORY_AS_IDS_ID: u32 = 100000020;
pub const IS_AIRBORNE_ID: u32 = 100000021;

pub const WEAPON_SKIN_ID: u32 = 10000000;
pub const WEAPON_PAINT_SEED: u32 = 10000001;
Expand Down Expand Up @@ -337,6 +338,15 @@ impl PropController {
is_player_prop: true,
});
}
if self.wanted_player_props.contains(&("is_airborne".to_string())) {
self.prop_infos.push(PropInfo {
id: IS_AIRBORNE_ID,
prop_type: PropType::Custom,
prop_name: "is_airborne".to_string(),
prop_friendly_name: "is_airborne".to_string(),
is_player_prop: true,
});
}
self.prop_infos.push(PropInfo {
id: TICK_ID,
prop_type: PropType::Tick,
Expand Down Expand Up @@ -518,6 +528,7 @@ impl PropController {
"CCSPlayerPawn.m_lifeState" => self.special_ids.life_state = Some(id),
"CCSPlayerController.m_nPawnCharacterDefIndex" => self.special_ids.agent_skin_idx = Some(id),
"CCSPlayerPawn.m_bInBuyZone" => self.special_ids.in_buy_zone = Some(id),
"CCSPlayerPawn.m_hGroundEntity" => self.special_ids.is_airborn = Some(id),
_ => {}
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/parser/src/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,6 @@ pub static TYPEHM: phf::Map<&'static str, PropType> = phf_map! {
"CCSPlayerPawn.m_vHeadConstraintOffset" => PropType::Player,
"CCSPlayerPawn.m_angEyeAngles" => PropType::Player,
"CCSPlayerPawn.m_fFlags" => PropType::Player,
"CCSPlayerPawn.m_hGroundEntity" => PropType::Player,
"CCSPlayerPawn.CBodyComponentBaseAnimGraph.m_flLastTeleportTime" => PropType::Player,
"CCSPlayerPawn.m_flCreateTime" => PropType::Player,
"CCSPlayerPawn.m_bClientSideRagdoll" => PropType::Player,
Expand Down Expand Up @@ -2409,6 +2408,7 @@ pub static TYPEHM: phf::Map<&'static str, PropType> = phf_map! {
"weapon_paint_seed" => PropType::Custom,
"weapon_float" => PropType::Custom,
"weapon_stickers" => PropType::Custom,
"is_airborne" => PropType::Custom,
// Weapon
"m_flAnimTime" => PropType::Weapon,
"m_flSimulationTime"=> PropType::Weapon,
Expand Down Expand Up @@ -2873,6 +2873,7 @@ pub static FRIENDLY_NAMES_MAPPING: phf::Map<&'static str, &'static str> = phf_ma
"next_primary_attack_tick_ratio"=> "m_flNextPrimaryAttackTickRatio",
"next_secondary_attack_tick" => "m_nNextSecondaryAttackTick",
"next_secondary_attack_tick_ratio"=> "m_flNextSecondaryAttackTickRatio",
"is_airborne" => "is_airborne",
};

pub static GRENADE_FRIENDLY_NAMES: phf::Map<&'static str, &'static str> = phf_map! {
Expand Down
13 changes: 13 additions & 0 deletions src/parser/src/second_pass/collect_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub enum PropType {
// DONT KNOW IF THESE ARE CORRECT. SEEMS TO GIVE CORRECT VALUES
const CELL_BITS: i32 = 9;
const MAX_COORD: f32 = (1 << 14) as f32;
// https://github.com/markus-wa/demoinfocs-golang/blob/master/pkg/demoinfocs/constants/constants.go#L11
const IS_AIRBORNE_CONST: u32 = 0xFFFFFF;

#[derive(Debug, Clone)]
pub struct ProjectileRecord {
Expand Down Expand Up @@ -442,6 +444,7 @@ impl<'a> SecondPassParser<'a> {
"entity_id" => return Ok(Variant::I32(*entity_id)),
"is_alive" => return self.find_is_alive(entity_id),
"user_id" => return self.get_userid(player),
"is_airborne" => self.find_is_airborne(player),
"agent_skin" => return self.find_agent_skin(player),
_ => Err(PropCollectionError::UnknownCustomPropName),
}
Expand All @@ -454,6 +457,16 @@ impl<'a> SecondPassParser<'a> {
}
Err(PropCollectionError::UseridNotFound)
}
pub fn find_is_airborne(&self, player: &PlayerMetaData) -> Result<Variant, PropCollectionError> {
if let Some(player_entity_id) = &player.player_entity_id {
if let Some(id) = self.prop_controller.special_ids.is_airborn {
if let Ok(Variant::U32(airborn_h)) = self.get_prop_from_ent(&id, &player_entity_id) {
return Ok(Variant::Bool(airborn_h == IS_AIRBORNE_CONST));
}
}
}
Ok(Variant::Bool(false))
}
pub fn find_skin_float(&self, player: &PlayerMetaData) -> Result<Variant, PropCollectionError> {
if let Some(player_entity_id) = &player.player_entity_id {
return self.find_weapon_prop(&WEAPON_FLOAT, &player_entity_id);
Expand Down
3 changes: 3 additions & 0 deletions src/parser/src/second_pass/parser_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ pub struct SpecialIDs {
pub weapon_purchase_count: Option<u32>,
pub in_buy_zone: Option<u32>,
pub custom_name: Option<u32>,

pub is_airborn: Option<u32>,
}
impl SpecialIDs {
pub fn new() -> Self {
Expand Down Expand Up @@ -308,6 +310,7 @@ impl SpecialIDs {
weapon_purchase_count: None,
in_buy_zone: None,
custom_name: None,
is_airborn: None,
}
}
}
Expand Down

0 comments on commit 1ed70c5

Please sign in to comment.