1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use crate::{
    helpers::{IntoHash, Hash},
    sdk,
};

#[derive(Debug)]
pub struct WeaponModelInfo {
    pub hash: Hash,
    pub name: String,
    pub model_name: String,
    pub model_hash: Hash,
    pub ammo_type_hash: Hash,
    pub ammo_type: String,
    pub ammo_model_name: String,
    pub ammo_model_hash: Hash,
    pub default_max_ammo_mp: i32,
    pub skill_above_50_max_ammo_mp: i32,
    pub max_skill_max_ammo_mp: i32,
    pub bonus_max_ammo_mp: i32,
}

impl WeaponModelInfo {
    pub fn get_by_hash(hash: impl IntoHash) -> Option<Self> {
        let ptr = unsafe { sdk::ICore::GetWeaponModelByHash(hash.into_hash()) };

        if !unsafe { sdk::is_weapon_model_info_valid(ptr) } {
            return None;
        }

        let (
            mut hash,
            mut model_hash,
            mut ammo_type_hash,
            mut ammo_model_hash,
            mut default_max_ammo_mp,
            mut skill_above_50_max_ammo_mp,
            mut max_skill_max_ammo_mp,
            mut bonus_max_ammo_mp,
        ) = Default::default();

        unsafe {
            sdk::read_weapon_model_info(
                ptr,
                &mut hash,
                &mut model_hash,
                &mut ammo_type_hash,
                &mut ammo_model_hash,
                &mut default_max_ammo_mp,
                &mut skill_above_50_max_ammo_mp,
                &mut max_skill_max_ammo_mp,
                &mut bonus_max_ammo_mp,
            )
        }

        Some(Self {
            hash,
            name: unsafe { sdk::read_weapon_model_info_name(ptr) }.to_string(),
            model_name: unsafe { sdk::read_weapon_model_info_model_name(ptr) }.to_string(),
            model_hash,
            ammo_type_hash,
            ammo_type: unsafe { sdk::read_weapon_model_info_ammo_type(ptr) }.to_string(),
            ammo_model_name: unsafe { sdk::read_weapon_model_info_ammo_model_name(ptr) }
                .to_string(),
            ammo_model_hash,
            default_max_ammo_mp,
            skill_above_50_max_ammo_mp,
            max_skill_max_ammo_mp,
            bonus_max_ammo_mp,
        })
    }
}