Skip to content

Commit e8bfa1b

Browse files
committed
WIP: Add Windows version support for 50.13 win64 ITCH
1 parent 04a83d9 commit e8bfa1b

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

src/config.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,17 @@ pub struct OffsetsMetadata {
5555

5656
#[allow(dead_code)]
5757
#[derive(Deserialize)]
58-
pub struct OffsetsValues {}
58+
pub struct OffsetsValues {
59+
pub enabler: Option<usize>,
60+
pub gps: Option<usize>,
61+
pub addst: Option<usize>,
62+
pub addst_top: Option<usize>,
63+
pub addst_flag: Option<usize>,
64+
pub erasescreen: Option<usize>,
65+
pub resize: Option<usize>,
66+
pub update_all: Option<usize>,
67+
pub update_tile: Option<usize>,
68+
}
5969

6070
#[allow(dead_code)]
6171
#[derive(Deserialize)]

src/global.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ pub static ENABLER: usize = unsafe {
1313
}
1414
};
1515

16+
#[cfg(target_os = "windows")]
17+
#[static_init::dynamic]
18+
pub static ENABLER: usize = {
19+
match CONFIG.offset.is_some() {
20+
true => utils::address(CONFIG.offset.as_ref().unwrap().enabler.unwrap()),
21+
false => 0 as usize,
22+
}
23+
};
24+
1625
#[cfg(target_os = "linux")]
1726
#[static_init::dynamic]
1827
pub static GPS: usize = unsafe {
@@ -21,3 +30,12 @@ pub static GPS: usize = unsafe {
2130
false => 0 as usize,
2231
}
2332
};
33+
34+
#[cfg(target_os = "windows")]
35+
#[static_init::dynamic]
36+
pub static GPS: usize = {
37+
match CONFIG.offset.is_some() {
38+
true => utils::address(CONFIG.offset.as_ref().unwrap().gps.unwrap()),
39+
false => 0 as usize,
40+
}
41+
};

src/hooks.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ fn translate(string: usize) -> (String, usize) {
7272
}
7373

7474
#[cfg_attr(target_os = "linux", hook(by_symbol))]
75+
#[cfg_attr(target_os = "windows", hook(by_offset))]
7576
fn addst(gps: usize, string: usize, just: u8, space: i32) {
7677
let (x, y) = gps_get_screen_coord(gps);
7778
let (content, width) = translate(string);
@@ -81,6 +82,7 @@ fn addst(gps: usize, string: usize, just: u8, space: i32) {
8182
}
8283

8384
#[cfg_attr(target_os = "linux", hook(by_symbol))]
85+
#[cfg_attr(target_os = "windows", hook(by_offset))]
8486
fn addst_top(gps: usize, string: usize, just: u8, space: i32) {
8587
let (x, y) = gps_get_screen_coord(gps);
8688
let (content, width) = translate(string);
@@ -90,6 +92,7 @@ fn addst_top(gps: usize, string: usize, just: u8, space: i32) {
9092
}
9193

9294
#[cfg_attr(target_os = "linux", hook(by_symbol))]
95+
#[cfg_attr(target_os = "windows", hook(by_offset))]
9396
fn addst_flag(gps: usize, string: usize, just: u8, space: i32, sflag: u32) {
9497
let (x, y) = gps_get_screen_coord(gps);
9598
let (content, width) = translate(string);
@@ -99,20 +102,32 @@ fn addst_flag(gps: usize, string: usize, just: u8, space: i32, sflag: u32) {
99102
}
100103

101104
#[cfg_attr(target_os = "linux", hook(by_symbol))]
105+
#[cfg_attr(target_os = "windows", hook(by_offset))]
102106
fn erasescreen(gps: usize) {
103107
unsafe { original!(gps) };
104108
SCREEN.write().clear();
105109
SCREEN_TOP.write().clear();
106110
}
107111

112+
#[cfg(target_os = "linux")]
108113
#[cfg_attr(target_os = "linux", hook(by_symbol))]
109114
fn resize(renderer: usize, w: u32, h: u32) {
110115
unsafe { original!(renderer, w, h) };
111116
SCREEN.write().resize(w, h);
112117
SCREEN_TOP.write().resize(w, h);
113118
}
114119

120+
// Windows function is optimized to inline function, so the signature is different
121+
#[cfg(target_os = "windows")]
122+
#[cfg_attr(target_os = "windows", hook(by_offset))]
123+
fn resize(renderer: usize, w: u32, h: u32, screen_x: u32, screen_y: u32, tile_dim_x: u32, tile_dim_y: u32) {
124+
unsafe { original!(renderer, w, h, screen_x, screen_y, tile_dim_x, tile_dim_y) };
125+
SCREEN.write().resize(w, h);
126+
SCREEN_TOP.write().resize(w, h);
127+
}
128+
115129
#[cfg_attr(target_os = "linux", hook(by_symbol))]
130+
#[cfg_attr(target_os = "windows", hook(by_offset))]
116131
fn update_all(renderer: usize) {
117132
unsafe { original!(renderer) };
118133
SCREEN_TOP.write().render(renderer);
@@ -123,10 +138,17 @@ struct Dimension {
123138
y: i32,
124139
}
125140

141+
// TODO: move to config
142+
#[cfg(target_os = "linux")]
143+
const DIMENSION_OFFSET: usize = 0xa00;
144+
#[cfg(target_os = "windows")]
145+
const DIMENSION_OFFSET: usize = 0x6cc;
146+
126147
#[cfg_attr(target_os = "linux", hook(by_symbol))]
148+
#[cfg_attr(target_os = "windows", hook(by_offset))]
127149
fn update_tile(renderer: usize, x: i32, y: i32) {
128150
unsafe { original!(renderer, x, y) };
129-
let dim = raw::deref::<Dimension>(GPS.to_owned() + 0xa00);
151+
let dim = raw::deref::<Dimension>(GPS.to_owned() + DIMENSION_OFFSET);
130152

131153
// hack to render text after the last update_tile in update_all
132154
// TODO: consider re-write update_all function completely according to g_src

src/screen.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ use crate::{font::FONT, raw};
77
const CANVAS_FONT_WIDTH: i32 = 8 * 2;
88
const CANVAS_FONT_HEIGHT: i32 = 12 * 2;
99

10+
// TODO: move to config
11+
#[cfg(target_os = "linux")]
12+
const SCREEN_INFO_OFFSET: usize = 0x160;
13+
#[cfg(target_os = "windows")]
14+
const SCREEN_INFO_OFFSET: usize = 0x168;
15+
1016
// TODO: consider to use bitflags crate
1117
#[allow(dead_code, non_camel_case_types)]
1218
#[repr(u32)]
@@ -160,7 +166,7 @@ impl Screen {
160166
}
161167

162168
let canvas = self.canvas_ptr as *mut sdl::SDL_Surface;
163-
let screen = raw::deref::<ScreenInfo>(renderer + 0x160);
169+
let screen = raw::deref::<ScreenInfo>(renderer + SCREEN_INFO_OFFSET);
164170

165171
unsafe {
166172
let sdl_renderer = raw::deref(renderer + 0x108);

0 commit comments

Comments
 (0)