dsr/
dsr.rs

1// This file is part of the mem-rs distribution (https://github.com/FrankvdStam/mem-rs).
2// Copyright (c) 2022 Frank van der Stam.
3// https://github.com/FrankvdStam/mem-rs/blob/main/LICENSE
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, version 3.
8//
9// This program is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17use std::thread::sleep;
18use std::time::Duration;
19use mem_rs::prelude::*;
20
21struct Ds1
22{
23    process: Process,
24    game_data_man: Pointer,
25    ai_timer: Pointer,
26}
27
28impl Ds1
29{
30    pub fn new() -> Self
31    {
32        Ds1
33        {
34            process: Process::new("DarkSoulsRemastered.exe"),
35            game_data_man: Pointer::default(),
36            ai_timer: Pointer::default(),
37        }
38    }
39
40    pub fn get_in_game_time_milliseconds(&self) -> u32
41    {
42        return self.game_data_man.read_u32_rel(Some(0xa4));
43    }
44
45    pub fn get_ai_timer(&self) -> f32
46    {
47        return self.ai_timer.read_f32_rel(Some(0x24));
48    }
49
50    pub fn refresh(&mut self) -> Result<(), String>
51    {
52        if !self.process.is_attached()
53        {
54            self.process.refresh()?;
55            self.game_data_man = self.process.scan_rel("GameDataMan", "48 8b 05 ? ? ? ? 48 8b 50 10 48 89 54 24 60", 3, 7, vec![0])?;
56            self.ai_timer = self.process.scan_rel("AI Timer", "48 8b 0d ? ? ? ? 48 85 c9 74 0e 48 83 c1 28", 3, 7, vec![0])?;
57        }
58        else
59        {
60            self.process.refresh()?;
61        }
62        Ok(())
63    }
64
65    #[allow(dead_code)]
66    pub fn inject_soulmemory_rs(&self)
67    {
68        //self.process.inject_dll(r#"C:\soulmemory\soulmemory_rs.dll"#);
69        //self.process.inject_dll(r#"C:\projects\soulmemory-rs\target\x86_64-pc-windows-msvc\release\soulmemory_rs.dll"#);
70        self.process.inject_dll(r#"C:\projects\soulmemory-rs\target\x86_64-pc-windows-msvc\å\soulmemory_rs.dll"#).expect("TODO: panic message");
71    }
72}
73
74fn main()
75{
76    /*
77    let processes = Process::get_running_process_names();
78    for p in &processes
79    {
80        println!("{}", p);
81    }*/
82
83    let mut ds1 = Ds1::new();
84
85    loop
86    {
87        match ds1.refresh()
88        {
89            Ok(()) => {}
90            Err(e) => println!("{}", e)
91        }
92
93        //ds1.inject_soulmemory_rs();
94
95        println!("igt: {}", ds1.get_in_game_time_milliseconds());
96        println!("ai: {}", ds1.get_ai_timer());
97        sleep(Duration::from_secs(1));
98    }
99}