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

Fix problem with parse_grenades #48

Merged
merged 2 commits into from
Oct 24, 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
23 changes: 11 additions & 12 deletions src/parser/src/collect_data.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::entities::PlayerMetaData;
use super::variants::Variant;
use crate::maps::BUTTONMAP;
use crate::maps::GRENADE_FRIENDLY_NAMES;
use crate::maps::PAINTKITS;
use crate::maps::WEAPINDICIES;
use crate::parser_thread_settings::ParserThread;
Expand Down Expand Up @@ -258,25 +259,23 @@ impl ParserThread {
fn find_grenade_type(&self, entity_id: &i32) -> Option<String> {
if let Some(ent) = self.entities.get(&entity_id) {
if let Some(cls) = self.cls_by_id.get(&ent.cls_id).as_ref() {
if !cls.name.contains("Grenade") {
return None;
}
// remove extra from name: CSmokeGrenadeProjectile --> SmokeGrenade
// Todo maybe make names like this: smoke_grenade or just "smoke"
let mut clean_name = cls.name[1..].split_at(cls.name.len() - 11).0;
// Seems like the only exception
if clean_name == "BaseCSGrenade" {
clean_name = "HeGrenade"
match GRENADE_FRIENDLY_NAMES.get(&cls.name) {
Some(name) => return Some(name.to_string()),
None => {
return None;
}
}
return Some(clean_name.to_owned());
}
}
None
}

pub fn collect_projectiles(&mut self) {
for projectile_entid in &self.projectiles {
let grenade_type = self.find_grenade_type(projectile_entid);
let grenade_type = match self.find_grenade_type(projectile_entid) {
Some(t) => t,
None => continue,
};
let steamid = self.find_thrower_steamid(projectile_entid);
let name = self.find_thrower_name(projectile_entid);
let x = self.collect_cell_coordinate_grenade(CoordinateAxis::X, projectile_entid);
Expand Down Expand Up @@ -315,7 +314,7 @@ impl ParserThread {
y: float_y,
z: float_z,
tick: Some(self.tick),
grenade_type: grenade_type,
grenade_type: Some(grenade_type),
entity_id: Some(*projectile_entid),
});
}
Expand Down
6 changes: 5 additions & 1 deletion src/parser/src/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ 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("m_hOwnerEntity") {
if debug
.field
.full_name
.contains("CCSPlayerController_ActionTrackingServices.m_iDamage")
{
println!(
"{:?} {:?} {:?} {:?} {:?} {:?}",
debug.path, debug.field.full_name, result, self.tick, self.net_tick, field_info.prop_id
Expand Down
21 changes: 17 additions & 4 deletions src/parser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ fn main() {
break;
}

let file = File::open(path.unwrap().path()).unwrap();
/*
"CDecoyProjectile"
"CSmokeGrenadeProjectile"
"CMolotovProjectile"
"CBaseCSGrenadeProjectile"
"CFlashbang"
"CFlashbangProjectile"
*/

let file = File::open("/home/laiho/Documents/q.dem").unwrap();
//let file = File::open(path.unwrap().path()).unwrap();
let mmap = unsafe { MmapOptions::new().map(&file).unwrap() };
mmap.advise(memmap2::Advice::HugePage).unwrap();

Expand All @@ -34,8 +44,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 All @@ -48,7 +58,7 @@ fn main() {
],
parse_ents: true,
wanted_ticks: vec![],
parse_projectiles: false,
parse_projectiles: true,
only_header: false,
count_props: false,
only_convars: false,
Expand All @@ -57,6 +67,9 @@ fn main() {

let mut ds = Parser::new(settings);
let d = ds.parse_demo().unwrap();
for x in d.game_events_counter {
println!("{:?}", x);
}
println!("TOTAL {:?}", before.elapsed());
}
println!("TOTAL {:?}", before.elapsed());
Expand Down
9 changes: 9 additions & 0 deletions src/parser/src/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2022,3 +2022,12 @@ pub static FRIENDLY_NAMES_MAPPING: phf::Map<&'static str, &'static str> = phf_ma
"next_secondary_attack_tick" => "m_nNextSecondaryAttackTick",
"next_secondary_attack_tick_ratio"=> "m_flNextSecondaryAttackTickRatio",
};

pub static GRENADE_FRIENDLY_NAMES: phf::Map<&'static str, &'static str> = phf_map! {
"CDecoyProjectile" => "decoy",
"CSmokeGrenadeProjectile" => "smoke",
"CMolotovProjectile" => "molotov",
"CBaseCSGrenadeProjectile" => "he_grenade",
// "CFlashbang" => "flashbang",
"CFlashbangProjectile" => "flashbang_projectile",
};