rosu_memory_lib/reader/user/stable/
memory.rs

1use crate::reader::structs::State;
2use crate::reader::user::common::UserInfo;
3use crate::reader::user::stable::offset::USER_PROFILE_OFFSET;
4use crate::Error;
5use rosu_mem::process::{Process, ProcessTraits};
6
7pub fn get_user_profile_base(p: &Process, state: &mut State) -> Result<i32, Error> {
8    Ok(p.read_i32(p.read_i32(state.addresses.user_profile + USER_PROFILE_OFFSET.ptr)?)?)
9}
10
11pub fn get_user_id(p: &Process, state: &mut State) -> Result<i32, Error> {
12    let user_profile_base = get_user_profile_base(p, state)?;
13    Ok(p.read_i32(user_profile_base + USER_PROFILE_OFFSET.id)?)
14}
15
16pub fn get_user_bancho_status(p: &Process, state: &mut State) -> Result<i32, Error> {
17    let user_profile_base = get_user_profile_base(p, state)?;
18    Ok(p.read_i32(user_profile_base + USER_PROFILE_OFFSET.bancho_status)?)
19}
20
21pub fn get_user_country_code(p: &Process, state: &mut State) -> Result<i32, Error> {
22    let user_profile_base = get_user_profile_base(p, state)?;
23    Ok(p.read_i32(user_profile_base + USER_PROFILE_OFFSET.country_code)?)
24}
25
26pub fn get_user_username(p: &Process, state: &mut State) -> Result<String, Error> {
27    let user_profile_base = get_user_profile_base(p, state)?;
28    let username_ptr = p.read_i32(user_profile_base + USER_PROFILE_OFFSET.username)?;
29    Ok(p.read_string(username_ptr)?)
30}
31
32pub fn get_user_pp(p: &Process, state: &mut State) -> Result<i32, Error> {
33    let user_profile_base = get_user_profile_base(p, state)?;
34    Ok(p.read_i32(user_profile_base + USER_PROFILE_OFFSET.pp)?)
35}
36
37pub fn get_user_rankedscore(p: &Process, state: &mut State) -> Result<i64, Error> {
38    let user_profile_base = get_user_profile_base(p, state)?;
39    Ok(p.read_i64(user_profile_base + USER_PROFILE_OFFSET.rankedscore)?)
40}
41
42pub fn get_user_level(p: &Process, state: &mut State) -> Result<f32, Error> {
43    let user_profile_base = get_user_profile_base(p, state)?;
44    Ok(p.read_f32(user_profile_base + USER_PROFILE_OFFSET.level)?)
45}
46
47pub fn get_user_playcount(p: &Process, state: &mut State) -> Result<i32, Error> {
48    let user_profile_base = get_user_profile_base(p, state)?;
49    Ok(p.read_i32(user_profile_base + USER_PROFILE_OFFSET.playcount)?)
50}
51
52pub fn get_user_rank(p: &Process, state: &mut State) -> Result<i32, Error> {
53    let user_profile_base = get_user_profile_base(p, state)?;
54    Ok(p.read_i32(user_profile_base + USER_PROFILE_OFFSET.rank)?)
55}
56
57pub fn get_user_playmode(p: &Process, state: &mut State) -> Result<i32, Error> {
58    let user_profile_base = get_user_profile_base(p, state)?;
59    Ok(p.read_i32(user_profile_base + USER_PROFILE_OFFSET.playmode)?)
60}
61
62pub fn get_user_accuracy(p: &Process, state: &mut State) -> Result<f64, Error> {
63    let user_profile_base = get_user_profile_base(p, state)?;
64    Ok(p.read_f64(user_profile_base + USER_PROFILE_OFFSET.accuracy)?)
65}
66
67pub fn get_user_info(p: &Process, state: &mut State) -> Result<UserInfo, Error> {
68    let user_profile_base = get_user_profile_base(p, state)?;
69
70    let user_profile = UserInfo {
71        id: p.read_i32(user_profile_base + USER_PROFILE_OFFSET.id)?,
72        username: p.read_string(p.read_i32(user_profile_base + USER_PROFILE_OFFSET.username)?)?, // TODO: need a fix idk how it show weirdly
73        pp: p.read_i32(user_profile_base + USER_PROFILE_OFFSET.pp)?,
74        rankedscore: p.read_i64(user_profile_base + USER_PROFILE_OFFSET.rankedscore)?,
75        level: p.read_f32(user_profile_base + USER_PROFILE_OFFSET.level)?,
76        playcount: p.read_i32(user_profile_base + USER_PROFILE_OFFSET.playcount)?,
77        rank: p.read_i32(user_profile_base + USER_PROFILE_OFFSET.rank)?,
78        playmode: p.read_i32(user_profile_base + USER_PROFILE_OFFSET.playmode)?,
79        accuracy: p.read_f64(user_profile_base + USER_PROFILE_OFFSET.accuracy)?,
80        country_code: p.read_i32(user_profile_base + USER_PROFILE_OFFSET.country_code)?,
81        bancho_status: p.read_i32(user_profile_base + USER_PROFILE_OFFSET.bancho_status)?,
82    };
83    Ok(user_profile)
84}