Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check c4 owner from c4 ent #43

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified src/node/tests/zipped_testdata.zip
Binary file not shown.
28 changes: 24 additions & 4 deletions src/parser/src/collect_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::maps::PAINTKITS;
use crate::maps::WEAPINDICIES;
use crate::parser_thread_settings::ParserThread;
use crate::prop_controller::PropInfo;
use crate::prop_controller::GRENADE_AMMO_ID;
use crate::prop_controller::MY_WEAPONS_OFFSET;
use crate::prop_controller::WEAPON_SKIN_ID;
use crate::variants::PropColumn;
Expand Down Expand Up @@ -524,18 +525,37 @@ impl ParserThread {
match weap_name {
// Check how many flashbangs player has (only prop that works like this)
&"flashbang" => {
if let Ok(Variant::U32(2)) = self.get_prop_from_ent(&987654, player_entid) {
if let Ok(Variant::U32(2)) = self.get_prop_from_ent(&GRENADE_AMMO_ID, player_entid) {
names.push(weap_name.to_string());
}
names.push(weap_name.to_string());
}
// c4 seems bugged. Find c4 entity and check owner from it.
&"c4" => {
if let Some(c4_owner_id) = self.find_c4_owner() {
if *player_entid == c4_owner_id {
names.push(weap_name.to_string());
}
}
}
_ => {
names.push(weap_name.to_string());
}
_ => {}
}
names.push(weap_name.to_string());
}
};
}
}

fn find_c4_owner(&self) -> Option<i32> {
if let Some(c4ent) = self.c4_entity_id {
if let Some(id) = self.prop_controller.special_ids.h_owner_entity {
if let Ok(Variant::U32(u)) = self.get_prop_from_ent(&id, &c4ent) {
return Some((u & 0x7FF) as i32);
}
}
}
None
}
pub fn find_weapon_original_owner(&self, entity_id: &i32) -> Result<Variant, PropCollectionError> {
let low_id = match self.prop_controller.special_ids.orig_own_low {
Some(id) => id,
Expand Down
5 changes: 4 additions & 1 deletion src/parser/src/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum EntityType {
Projectile,
Team,
Normal,
C4,
}
enum EntityCmd {
Delete,
Expand Down Expand Up @@ -104,7 +105,7 @@ impl ParserThread {
if self.is_debug_mode {
for (field_info, debug) in self.field_infos[..n_updates].iter().zip(&self.debug_fields) {
let result = bitreader.decode(&field_info.decoder, &self.qf_mapper)?;
if debug.field.full_name.contains("CCSPlayerPawn.m_bSpottedByMask") {
if debug.field.full_name.contains("m_hOwnerEntity") {
println!(
"{:?} {:?} {:?} {:?} {:?} {:?}",
debug.path, debug.field.full_name, result, self.tick, self.net_tick, field_info.prop_id
Expand Down Expand Up @@ -329,6 +330,7 @@ impl ParserThread {
self.projectiles.insert(*entity_id);
}
EntityType::Rules => self.rules_entity_id = Some(*entity_id),
EntityType::C4 => self.c4_entity_id = Some(*entity_id),
_ => {}
};
let entity = Entity {
Expand Down Expand Up @@ -359,6 +361,7 @@ impl ParserThread {
"CCSPlayerController" => return Ok(EntityType::PlayerController),
"CCSGameRulesProxy" => return Ok(EntityType::Rules),
"CCSTeam" => return Ok(EntityType::Team),
"CC4" => return Ok(EntityType::C4),
_ => {}
}
if class.name.contains("Projectile") {
Expand Down
6 changes: 3 additions & 3 deletions src/parser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::sync::Arc;
use std::time::Instant;

fn main() {
let wanted_props = vec!["CCSPlayerPawn.m_bSpottedByMask".to_string()];
let wanted_props = vec!["inventory".to_string()];
let before = Instant::now();
let dir = fs::read_dir("/home/laiho/Documents/demos/cs2/test3/").unwrap();
let mut c = 0;
Expand All @@ -34,8 +34,8 @@ fn main() {
bytes: Arc::new(BytesVariant::Mmap(mmap)),
wanted_player_props: wanted_props.clone(),
wanted_player_props_og_names: wanted_props.clone(),
//wanted_events: vec!["player_blind".to_string()],
wanted_events: vec![],
wanted_events: vec!["player_blind".to_string()],
//wanted_events: vec![],
wanted_other_props: vec![
"CCSTeam.m_iScore".to_string(),
"CCSTeam.m_szTeamname".to_string(),
Expand Down
5 changes: 5 additions & 0 deletions src/parser/src/parser_thread_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct ParserThread {
pub game_events: Vec<GameEvent>,
pub string_tables: Vec<StringTable>,
pub rules_entity_id: Option<i32>,
pub c4_entity_id: Option<i32>,
pub game_events_counter: AHashSet<String>,
pub baselines: AHashMap<u32, Vec<u8>, RandomState>,
pub field_infos: Vec<FieldInfo>,
Expand Down Expand Up @@ -179,6 +180,7 @@ impl ParserThread {
};
debug_vec_len
],
c4_entity_id: None,
stringtable_players: input.stringtable_players,
is_debug_mode: debug,
projectile_records: vec![],
Expand Down Expand Up @@ -266,10 +268,13 @@ pub struct SpecialIDs {
pub orig_own_low: Option<u32>,
pub orig_own_high: Option<u32>,
pub life_state: Option<u32>,

pub h_owner_entity: Option<u32>,
}
impl SpecialIDs {
pub fn new() -> Self {
SpecialIDs {
h_owner_entity: None,
teamnum: None,
player_name: None,
steamid: None,
Expand Down
1 change: 1 addition & 0 deletions src/parser/src/prop_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ impl PropController {
fn set_special_ids(&mut self, name: &str, is_grenade_or_weapon: bool, id: u32) {
if is_grenade_or_weapon {
match name {
"m_hOwnerEntity" => self.special_ids.h_owner_entity = Some(id),
"m_nOwnerId" => self.special_ids.grenade_owner_id = Some(id),
"CBodyComponentBaseAnimGraph.m_vecX" => self.special_ids.m_vec_x_grenade = Some(id),
"CBodyComponentBaseAnimGraph.m_vecY" => self.special_ids.m_vec_y_grenade = Some(id),
Expand Down
Binary file modified src/python/tests/zipped_testdata.zip
Binary file not shown.