Skip to content

Commit 2a2b8cd

Browse files
committed
fix: 统一 Win32 FFI 签名,消除 clashing-extern-declarations 警告
1 parent 44583d5 commit 2a2b8cd

3 files changed

Lines changed: 72 additions & 130 deletions

File tree

src/d3d9/fps_osd.rs

Lines changed: 7 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ use std::ffi::c_void;
22
use std::ptr;
33
use std::sync::atomic::{AtomicU32, Ordering};
44

5+
use crate::hooks::autoplay::{
6+
BeginPaint, CreateFontA, CreateSolidBrush, CreateWindowExA, DefWindowProcA, DeleteObject,
7+
DrawTextW, EndPaint, FillRect, GetClientRect, GetModuleHandleA, InvalidateRect, RegisterClassA,
8+
SelectObject, SetBkMode, SetLayeredWindowAttributes, SetTextColor, ShowWindow,
9+
};
10+
use crate::hooks::autoplay::{PaintStruct, Rect, WndClassA};
11+
512
const WS_POPUP: u32 = 0x80000000;
613
const WS_EX_TOPMOST: u32 = 0x00000008;
714
const WS_EX_LAYERED: u32 = 0x00080000;
@@ -21,39 +28,6 @@ const OSD_WIDTH: i32 = 140;
2128
const OSD_HEIGHT: i32 = 30;
2229
const OSD_MARGIN: i32 = 12;
2330

24-
#[repr(C)]
25-
struct WndClassA {
26-
style: u32,
27-
wnd_proc: unsafe extern "system" fn(usize, u32, usize, isize) -> isize,
28-
cls_extra: i32,
29-
wnd_extra: i32,
30-
instance: usize,
31-
icon: usize,
32-
cursor: usize,
33-
background: usize,
34-
menu_name: *const u8,
35-
class_name: *const u8,
36-
}
37-
38-
#[repr(C)]
39-
struct PaintStruct {
40-
hdc: *mut c_void,
41-
erase: i32,
42-
rc_paint: Rect,
43-
restore: i32,
44-
inc_update: i32,
45-
reserved: [u8; 32],
46-
}
47-
48-
#[repr(C)]
49-
#[derive(Clone, Copy)]
50-
struct Rect {
51-
left: i32,
52-
top: i32,
53-
right: i32,
54-
bottom: i32,
55-
}
56-
5731
static mut OSD_HWND: usize = 0;
5832
static mut INITIALIZED: bool = false;
5933
static FRAME_COUNT: AtomicU32 = AtomicU32::new(0);
@@ -126,7 +100,6 @@ unsafe extern "system" fn osd_wndproc(hwnd: usize, msg: u32, wp: usize, lp: isiz
126100
let mut rect: Rect = std::mem::zeroed();
127101
GetClientRect(hwnd, &mut rect);
128102

129-
// BGR: R=62 G=62 B=66 → 0x423E3E
130103
let bg_brush = CreateSolidBrush(0x00423E3E);
131104
FillRect(hdc, &rect, bg_brush);
132105
DeleteObject(bg_brush);
@@ -158,39 +131,4 @@ unsafe extern "system" fn osd_wndproc(hwnd: usize, msg: u32, wp: usize, lp: isiz
158131
extern "system" {
159132
fn QueryPerformanceCounter(count: *mut i64) -> i32;
160133
fn QueryPerformanceFrequency(freq: *mut i64) -> i32;
161-
fn GetModuleHandleA(name: *const u8) -> usize;
162-
}
163-
164-
#[link(name = "user32")]
165-
extern "system" {
166-
fn RegisterClassA(wc: *const WndClassA) -> u16;
167-
fn CreateWindowExA(
168-
ex_style: u32, class: *const u8, name: *const u8, style: u32,
169-
x: i32, y: i32, w: i32, h: i32,
170-
parent: usize, menu: usize, instance: usize, param: *const u8,
171-
) -> usize;
172-
fn ShowWindow(hwnd: usize, cmd: i32) -> i32;
173-
fn SetLayeredWindowAttributes(hwnd: usize, key: u32, alpha: u8, flags: u32) -> i32;
174-
fn DefWindowProcA(hwnd: usize, msg: u32, wp: usize, lp: isize) -> isize;
175-
fn BeginPaint(hwnd: usize, ps: *mut PaintStruct) -> *mut c_void;
176-
fn EndPaint(hwnd: usize, ps: *const PaintStruct) -> i32;
177-
fn GetClientRect(hwnd: usize, rect: *mut Rect) -> i32;
178-
fn InvalidateRect(hwnd: usize, rect: *const c_void, erase: i32) -> i32;
179-
}
180-
181-
#[link(name = "gdi32")]
182-
extern "system" {
183-
fn CreateSolidBrush(color: u32) -> *mut c_void;
184-
fn CreateFontA(
185-
h: i32, w: i32, esc: i32, orient: i32, weight: i32,
186-
italic: u32, underline: u32, strikeout: u32, charset: u32,
187-
out_prec: u32, clip_prec: u32, quality: u32, pitch: u32,
188-
face: *const u8,
189-
) -> *mut c_void;
190-
fn SelectObject(hdc: *mut c_void, obj: *mut c_void) -> *mut c_void;
191-
fn DeleteObject(obj: *mut c_void) -> i32;
192-
fn SetBkMode(hdc: *mut c_void, mode: i32) -> i32;
193-
fn SetTextColor(hdc: *mut c_void, color: u32) -> u32;
194-
fn FillRect(hdc: *mut c_void, rect: *const Rect, brush: *mut c_void) -> i32;
195-
fn DrawTextW(hdc: *mut c_void, text: *const u16, count: i32, rect: *mut Rect, format: u32) -> i32;
196134
}

src/d3d9/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,21 @@ fn init_d3d9_proxy(api: &Api, config: &Config) {
4646

4747
unsafe fn get_proxy_api() -> Option<*const D3D9ProxyAPI> {
4848
let d3d9 = GetModuleHandleA(b"d3d9.dll\0".as_ptr());
49-
if d3d9.is_null() {
49+
if d3d9 == 0 {
5050
return None;
5151
}
5252
let proc = GetProcAddress(d3d9, b"d3d9proxy_get_api\0".as_ptr());
53-
let get_api: GetAPIFn = std::mem::transmute(proc?);
53+
if proc.is_null() {
54+
return None;
55+
}
56+
let proc = proc as *const ();
57+
let get_api: GetAPIFn = std::mem::transmute(proc);
5458
let api = get_api();
5559
(!api.is_null()).then_some(api)
5660
}
5761

5862
#[link(name = "kernel32")]
5963
extern "system" {
60-
fn GetModuleHandleA(name: *const u8) -> *mut c_void;
61-
fn GetProcAddress(module: *mut c_void, name: *const u8) -> Option<unsafe extern "system" fn() -> isize>;
64+
fn GetModuleHandleA(name: *const u8) -> usize;
65+
fn GetProcAddress(module: usize, name: *const u8) -> *const c_void;
6266
}

src/hooks/autoplay.rs

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ static mut ORIG_JUDGE: usize = 0;
1919

2020
#[link(name = "kernel32")]
2121
extern "system" {
22-
fn CreateThread(
22+
pub fn CreateThread(
2323
attrs: *const c_void,
2424
stack_size: usize,
2525
start: Option<unsafe extern "system" fn(*mut c_void) -> u32>,
2626
param: *const c_void,
2727
flags: u32,
2828
id: *mut u32,
2929
) -> usize;
30-
fn Sleep(ms: u32);
31-
fn GetModuleHandleA(module_name: *const u8) -> usize;
30+
pub fn Sleep(ms: u32);
31+
pub fn GetModuleHandleA(module_name: *const u8) -> usize;
3232
}
3333

3434
#[link(name = "user32")]
3535
extern "system" {
36-
fn GetAsyncKeyState(vkey: i32) -> i16;
37-
fn CreateWindowExA(
36+
pub fn GetAsyncKeyState(vkey: i32) -> i16;
37+
pub fn CreateWindowExA(
3838
ex_style: u32,
3939
class_name: *const u8,
4040
window_name: *const u8,
@@ -48,28 +48,28 @@ extern "system" {
4848
instance: usize,
4949
param: *const c_void,
5050
) -> usize;
51-
fn RegisterClassA(wc: *const WndClassA) -> u16;
52-
fn DefWindowProcA(hwnd: usize, msg: u32, wp: usize, lp: isize) -> isize;
53-
fn ShowWindow(hwnd: usize, cmd: i32) -> i32;
54-
fn SetLayeredWindowAttributes(hwnd: usize, cr_key: u32, alpha: u8, flags: u32) -> i32;
55-
fn BeginPaint(hwnd: usize, ps: *mut PaintStruct) -> usize;
56-
fn EndPaint(hwnd: usize, ps: *const PaintStruct) -> i32;
57-
fn GetClientRect(hwnd: usize, rect: *mut Rect) -> i32;
58-
fn InvalidateRect(hwnd: usize, rect: *const Rect, erase: i32) -> i32;
59-
fn FillRect(hdc: usize, rect: *const Rect, brush: usize) -> i32;
60-
fn DrawTextW(hdc: usize, text: *const u16, count: i32, rect: *mut Rect, format: u32) -> i32;
61-
fn GetSystemMetrics(index: i32) -> i32;
62-
fn SetWindowPos(hwnd: usize, insert_after: usize, x: i32, y: i32, cx: i32, cy: i32, flags: u32) -> i32;
63-
fn PeekMessageA(msg: *mut Msg, hwnd: usize, min: u32, max: u32, remove: u32) -> i32;
64-
fn TranslateMessage(msg: *const Msg) -> i32;
65-
fn DispatchMessageA(msg: *const Msg) -> isize;
51+
pub fn RegisterClassA(wc: *const WndClassA) -> u16;
52+
pub fn DefWindowProcA(hwnd: usize, msg: u32, wp: usize, lp: isize) -> isize;
53+
pub fn ShowWindow(hwnd: usize, cmd: i32) -> i32;
54+
pub fn SetLayeredWindowAttributes(hwnd: usize, cr_key: u32, alpha: u8, flags: u32) -> i32;
55+
pub fn BeginPaint(hwnd: usize, ps: *mut PaintStruct) -> usize;
56+
pub fn EndPaint(hwnd: usize, ps: *const PaintStruct) -> i32;
57+
pub fn GetClientRect(hwnd: usize, rect: *mut Rect) -> i32;
58+
pub fn InvalidateRect(hwnd: usize, rect: *const Rect, erase: i32) -> i32;
59+
pub fn FillRect(hdc: usize, rect: *const Rect, brush: usize) -> i32;
60+
pub fn DrawTextW(hdc: usize, text: *const u16, count: i32, rect: *mut Rect, format: u32) -> i32;
61+
pub fn GetSystemMetrics(index: i32) -> i32;
62+
pub fn SetWindowPos(hwnd: usize, insert_after: usize, x: i32, y: i32, cx: i32, cy: i32, flags: u32) -> i32;
63+
pub fn PeekMessageA(msg: *mut Msg, hwnd: usize, min: u32, max: u32, remove: u32) -> i32;
64+
pub fn TranslateMessage(msg: *const Msg) -> i32;
65+
pub fn DispatchMessageA(msg: *const Msg) -> isize;
6666
}
6767

6868
#[link(name = "gdi32")]
6969
extern "system" {
70-
fn SetBkMode(hdc: usize, mode: i32) -> i32;
71-
fn SetTextColor(hdc: usize, color: u32) -> u32;
72-
fn CreateFontA(
70+
pub fn SetBkMode(hdc: usize, mode: i32) -> i32;
71+
pub fn SetTextColor(hdc: usize, color: u32) -> u32;
72+
pub fn CreateFontA(
7373
h: i32,
7474
w: i32,
7575
esc: i32,
@@ -85,57 +85,57 @@ extern "system" {
8585
pitch: u32,
8686
face: *const u8,
8787
) -> usize;
88-
fn SelectObject(hdc: usize, obj: usize) -> usize;
89-
fn DeleteObject(obj: usize) -> i32;
90-
fn CreateSolidBrush(color: u32) -> usize;
88+
pub fn SelectObject(hdc: usize, obj: usize) -> usize;
89+
pub fn DeleteObject(obj: usize) -> i32;
90+
pub fn CreateSolidBrush(color: u32) -> usize;
9191
}
9292

9393
const DT_CENTER: u32 = 0x01;
9494
const DT_VCENTER: u32 = 0x04;
9595
const DT_SINGLELINE: u32 = 0x20;
9696

9797
#[repr(C)]
98-
struct WndClassA {
99-
style: u32,
100-
wnd_proc: unsafe extern "system" fn(usize, u32, usize, isize) -> isize,
101-
cls_extra: i32,
102-
wnd_extra: i32,
103-
instance: usize,
104-
icon: usize,
105-
cursor: usize,
106-
background: usize,
107-
menu_name: *const u8,
108-
class_name: *const u8,
98+
pub struct WndClassA {
99+
pub style: u32,
100+
pub wnd_proc: unsafe extern "system" fn(usize, u32, usize, isize) -> isize,
101+
pub cls_extra: i32,
102+
pub wnd_extra: i32,
103+
pub instance: usize,
104+
pub icon: usize,
105+
pub cursor: usize,
106+
pub background: usize,
107+
pub menu_name: *const u8,
108+
pub class_name: *const u8,
109109
}
110110

111111
#[repr(C)]
112-
struct PaintStruct {
113-
hdc: usize,
114-
erase: i32,
115-
rc_paint: Rect,
116-
restore: i32,
117-
inc_update: i32,
118-
rgb_reserved: [u8; 32],
112+
pub struct PaintStruct {
113+
pub hdc: usize,
114+
pub erase: i32,
115+
pub rc_paint: Rect,
116+
pub restore: i32,
117+
pub inc_update: i32,
118+
pub rgb_reserved: [u8; 32],
119119
}
120120

121121
#[repr(C)]
122122
#[derive(Clone, Copy)]
123-
struct Rect {
124-
left: i32,
125-
top: i32,
126-
right: i32,
127-
bottom: i32,
123+
pub struct Rect {
124+
pub left: i32,
125+
pub top: i32,
126+
pub right: i32,
127+
pub bottom: i32,
128128
}
129129

130130
#[repr(C)]
131-
struct Msg {
132-
hwnd: usize,
133-
message: u32,
134-
wparam: usize,
135-
lparam: isize,
136-
time: u32,
137-
pt_x: i32,
138-
pt_y: i32,
131+
pub struct Msg {
132+
pub hwnd: usize,
133+
pub message: u32,
134+
pub wparam: usize,
135+
pub lparam: isize,
136+
pub time: u32,
137+
pub pt_x: i32,
138+
pub pt_y: i32,
139139
}
140140

141141
const WM_PAINT: u32 = 0x000F;

0 commit comments

Comments
 (0)