paavohtl Claude Opus 4.6 commited on
Commit
4031a30
·
1 Parent(s): e76c9cf

feat: replace all 8 fixed-size RenderQueue enqueue methods with Rust

Browse files

Port DrawPixel, DrawScaled, DrawRect, DrawSpriteOffset, DrawBitmapGlobal,
and DrawTextboxLocal as full Rust replacements (joining existing
DrawSpriteGlobal/Local). Add per-command-type structs with size assertions,
generic RenderQueue::alloc<T>(), new usercall_trampoline! macro arms for
1-reg+3-stack, 1-reg+5-stack, 2-reg+5/6/7-stack, and rename RenderCommand
to DrawSpriteCmd.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

crates/openwa-types/src/address.rs CHANGED
@@ -160,7 +160,13 @@ pub mod va {
160
  pub const BLIT_SCREEN: u32 = 0x005A_2020;
161
  pub const RENDER_DRAWING_QUEUE: u32 = 0x0054_2350;
162
  pub const DRAW_LANDSCAPE: u32 = 0x005A_2790;
 
 
 
 
 
163
  pub const DRAW_SPRITE_GLOBAL: u32 = 0x0054_1FE0;
 
164
  pub const DRAW_BITMAP_GLOBAL: u32 = 0x0054_2170;
165
  pub const LOAD_SPRITE: u32 = 0x0052_3400;
166
  pub const CONSTRUCT_OPENGL_CPU: u32 = 0x005A_0850;
 
160
  pub const BLIT_SCREEN: u32 = 0x005A_2020;
161
  pub const RENDER_DRAWING_QUEUE: u32 = 0x0054_2350;
162
  pub const DRAW_LANDSCAPE: u32 = 0x005A_2790;
163
+ pub const DRAW_PIXEL: u32 = 0x0054_1D60;
164
+ pub const DRAW_LINE_STRIP: u32 = 0x0054_1DD0;
165
+ pub const DRAW_POLYGON: u32 = 0x0054_1E50;
166
+ pub const DRAW_SCALED: u32 = 0x0054_1ED0;
167
+ pub const DRAW_RECT: u32 = 0x0054_1F40;
168
  pub const DRAW_SPRITE_GLOBAL: u32 = 0x0054_1FE0;
169
+ pub const DRAW_SPRITE_OFFSET: u32 = 0x0054_20E0;
170
  pub const DRAW_BITMAP_GLOBAL: u32 = 0x0054_2170;
171
  pub const LOAD_SPRITE: u32 = 0x0052_3400;
172
  pub const CONSTRUCT_OPENGL_CPU: u32 = 0x005A_0850;
crates/openwa-types/src/render.rs CHANGED
@@ -5,7 +5,7 @@ use crate::task::Ptr32;
5
  /// Enqueued by DrawSpriteGlobal (type 4), DrawSpriteLocal (type 5),
6
  /// and other drawing functions.
7
  #[repr(C)]
8
- pub struct RenderCommand {
9
  /// Command type: 4 = sprite global (world-space), 5 = sprite local (screen-space)
10
  pub command_type: u32,
11
  pub layer: u32,
@@ -17,9 +17,9 @@ pub struct RenderCommand {
17
  pub frame: u32,
18
  }
19
 
20
- const _: () = assert!(core::mem::size_of::<RenderCommand>() == 0x18);
21
 
22
- /// Render queue — manages a downward-growing buffer of RenderCommand entries.
23
  ///
24
  /// Passed as `this` (ECX) to DrawSpriteGlobal/Local. The buffer area sits
25
  /// between offset 0x04 and the entry metadata at 0x10000+. Entries are
@@ -30,39 +30,140 @@ const _: () = assert!(core::mem::size_of::<RenderCommand>() == 0x18);
30
  pub struct RenderQueue {
31
  /// 0x00000: Buffer write offset (i32, decrements by 0x18 per entry)
32
  pub buffer_offset: i32,
33
- /// 0x00004 - 0x10003: Buffer area for RenderCommand entries
34
  pub _buffer: [u8; 0x10000],
35
  /// 0x10004: Number of enqueued entries (max 0x800)
36
  pub entry_count: u32,
37
- /// 0x10008: Pointer array — entry_ptrs[N] points to the N-th RenderCommand
38
  pub entry_ptrs: [Ptr32; 0x800],
39
  }
40
 
41
  impl RenderQueue {
42
- /// Allocate a new entry from the downward-growing buffer.
43
  ///
44
  /// Returns `None` if the queue is full (>= 0x800 entries or buffer exhausted).
45
  /// The returned reference is registered in `entry_ptrs` and `entry_count` is incremented.
46
- pub unsafe fn alloc_entry(&mut self) -> Option<&mut RenderCommand> {
47
  if self.entry_count >= 0x800 {
48
  return None;
49
  }
50
- let new_offset = self.buffer_offset - core::mem::size_of::<RenderCommand>() as i32;
51
  if new_offset < 0 {
52
  return None;
53
  }
54
  self.buffer_offset = new_offset;
55
 
56
- let entry = &mut *(self._buffer.as_mut_ptr().add(new_offset as usize)
57
- as *mut RenderCommand);
58
- self.entry_ptrs[self.entry_count as usize] = entry as *mut RenderCommand as u32;
59
  self.entry_count += 1;
60
  Some(entry)
61
  }
62
  }
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  /// Render command type constants.
65
  pub mod command_type {
 
 
 
66
  pub const DRAW_SPRITE_GLOBAL: u32 = 4;
67
  pub const DRAW_SPRITE_LOCAL: u32 = 5;
 
 
 
68
  }
 
5
  /// Enqueued by DrawSpriteGlobal (type 4), DrawSpriteLocal (type 5),
6
  /// and other drawing functions.
7
  #[repr(C)]
8
+ pub struct DrawSpriteCmd {
9
  /// Command type: 4 = sprite global (world-space), 5 = sprite local (screen-space)
10
  pub command_type: u32,
11
  pub layer: u32,
 
17
  pub frame: u32,
18
  }
19
 
20
+ const _: () = assert!(core::mem::size_of::<DrawSpriteCmd>() == 0x18);
21
 
22
+ /// Render queue — manages a downward-growing buffer of DrawSpriteCmd entries.
23
  ///
24
  /// Passed as `this` (ECX) to DrawSpriteGlobal/Local. The buffer area sits
25
  /// between offset 0x04 and the entry metadata at 0x10000+. Entries are
 
30
  pub struct RenderQueue {
31
  /// 0x00000: Buffer write offset (i32, decrements by 0x18 per entry)
32
  pub buffer_offset: i32,
33
+ /// 0x00004 - 0x10003: Buffer area for DrawSpriteCmd entries
34
  pub _buffer: [u8; 0x10000],
35
  /// 0x10004: Number of enqueued entries (max 0x800)
36
  pub entry_count: u32,
37
+ /// 0x10008: Pointer array — entry_ptrs[N] points to the N-th DrawSpriteCmd
38
  pub entry_ptrs: [Ptr32; 0x800],
39
  }
40
 
41
  impl RenderQueue {
42
+ /// Allocate a command of type `T` from the downward-growing buffer.
43
  ///
44
  /// Returns `None` if the queue is full (>= 0x800 entries or buffer exhausted).
45
  /// The returned reference is registered in `entry_ptrs` and `entry_count` is incremented.
46
+ pub unsafe fn alloc<T>(&mut self) -> Option<&mut T> {
47
  if self.entry_count >= 0x800 {
48
  return None;
49
  }
50
+ let new_offset = self.buffer_offset - core::mem::size_of::<T>() as i32;
51
  if new_offset < 0 {
52
  return None;
53
  }
54
  self.buffer_offset = new_offset;
55
 
56
+ let entry = &mut *(self._buffer.as_mut_ptr().add(new_offset as usize) as *mut T);
57
+ self.entry_ptrs[self.entry_count as usize] = entry as *mut T as u32;
 
58
  self.entry_count += 1;
59
  Some(entry)
60
  }
61
  }
62
 
63
+ /// Type 0xD — single pixel (0x18 bytes).
64
+ #[repr(C)]
65
+ pub struct DrawPixelCmd {
66
+ pub command_type: u32, // 0xD
67
+ pub layer: u32, // hardcoded 0x1B_0000
68
+ pub color: u32, // hardcoded 0xFF00_0000
69
+ pub x_pos: u32,
70
+ pub y_pos: u32,
71
+ pub flags: u8,
72
+ pub _pad: [u8; 3],
73
+ }
74
+
75
+ const _: () = assert!(core::mem::size_of::<DrawPixelCmd>() == 0x18);
76
+
77
+ /// Type 0xB — scaled sprite draw (0x1C = 28 bytes).
78
+ #[repr(C)]
79
+ pub struct DrawScaledCmd {
80
+ pub command_type: u32, // 0xB
81
+ pub layer: u32,
82
+ pub x_pos: u32,
83
+ pub y_pos: u32,
84
+ pub sprite_id: u32,
85
+ pub frame: u32,
86
+ pub _reserved: u32, // hardcoded 0
87
+ }
88
+
89
+ const _: () = assert!(core::mem::size_of::<DrawScaledCmd>() == 0x1C);
90
+
91
+ /// Type 0 — filled rectangle (0x20 = 32 bytes).
92
+ #[repr(C)]
93
+ pub struct DrawRectCmd {
94
+ pub command_type: u32, // 0
95
+ pub layer: u32,
96
+ pub color: u32,
97
+ pub x1: u32, // & 0xFFFF0000
98
+ pub y1: u32, // & 0xFFFF0000
99
+ pub x2: u32, // & 0xFFFF0000
100
+ pub y2: u32, // & 0xFFFF0000
101
+ pub y_clip: u32, // EDX & 0xFFFF0000
102
+ }
103
+
104
+ const _: () = assert!(core::mem::size_of::<DrawRectCmd>() == 0x20);
105
+
106
+ /// Type 6 — sprite with offset/scaling (0x24 = 36 bytes).
107
+ #[repr(C)]
108
+ pub struct DrawSpriteOffsetCmd {
109
+ pub command_type: u32, // 6
110
+ pub layer: u32,
111
+ pub sprite_id: u32,
112
+ pub x_pos: u32, // & 0xFFFF0000
113
+ pub y_pos: u32, // & 0xFFFF0000
114
+ pub _reserved: u32, // hardcoded 0
115
+ pub y_clip: u32, // EDX & 0xFFFF0000
116
+ pub param_7: u32,
117
+ pub param_8: u32,
118
+ }
119
+
120
+ const _: () = assert!(core::mem::size_of::<DrawSpriteOffsetCmd>() == 0x24);
121
+
122
+ /// Type 1 — bitmap global (0x28 = 40 bytes).
123
+ #[repr(C)]
124
+ pub struct DrawBitmapGlobalCmd {
125
+ pub command_type: u32, // 1
126
+ pub layer: u32,
127
+ pub x_pos: u32, // & 0xFFFF0000
128
+ pub y_pos: u32, // EDX & 0xFFFF0000
129
+ pub bitmap_ptr: u32,
130
+ pub _reserved: u32, // hardcoded 0
131
+ pub param_6: u32,
132
+ pub param_7: u32,
133
+ pub param_8: u32,
134
+ pub param_9: u32,
135
+ }
136
+
137
+ const _: () = assert!(core::mem::size_of::<DrawBitmapGlobalCmd>() == 0x28);
138
+
139
+ /// Type 2 — textbox local (0x34 = 52 bytes).
140
+ #[repr(C)]
141
+ pub struct DrawTextboxLocalCmd {
142
+ pub command_type: u32, // 2
143
+ pub layer: u32,
144
+ pub _reserved_2: u32, // hardcoded 0
145
+ pub x_pos: u32, // & 0xFFFF0000
146
+ pub y_pos: u32, // EDX & 0xFFFF0000
147
+ pub _reserved_5: u32, // hardcoded 0
148
+ pub _reserved_6: u32, // hardcoded 0
149
+ pub text_ptr: u32,
150
+ pub _reserved_8: u32, // hardcoded 0
151
+ pub _reserved_9: u32, // hardcoded 0
152
+ pub param_6: u32,
153
+ pub param_7: u32,
154
+ pub param_8: u32,
155
+ }
156
+
157
+ const _: () = assert!(core::mem::size_of::<DrawTextboxLocalCmd>() == 0x34);
158
+
159
  /// Render command type constants.
160
  pub mod command_type {
161
+ pub const DRAW_RECT: u32 = 0;
162
+ pub const DRAW_BITMAP_GLOBAL: u32 = 1;
163
+ pub const DRAW_TEXTBOX_LOCAL: u32 = 2;
164
  pub const DRAW_SPRITE_GLOBAL: u32 = 4;
165
  pub const DRAW_SPRITE_LOCAL: u32 = 5;
166
+ pub const DRAW_SPRITE_OFFSET: u32 = 6;
167
+ pub const DRAW_SCALED: u32 = 0xB;
168
+ pub const DRAW_PIXEL: u32 = 0xD;
169
  }
crates/openwa-wormkit/src/hook.rs CHANGED
@@ -57,6 +57,48 @@ macro_rules! usercall_trampoline {
57
  }
58
  };
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  // 2 register args, 1 stack param, ret N
61
  (fn $name:ident; impl_fn = $impl:path; regs = [$r1:ident, $r2:ident];
62
  stack_params = 1; ret_bytes = $ret:literal) => {
@@ -135,6 +177,78 @@ macro_rules! usercall_trampoline {
135
  }
136
  };
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  // 2 register args, 3 stack params, ret N
139
  (fn $name:ident; impl_fn = $impl:path; regs = [$r1:ident, $r2:ident];
140
  stack_params = 3; ret_bytes = $ret:literal) => {
 
57
  }
58
  };
59
 
60
+ // 1 register arg, 3 stack params, ret N
61
+ (fn $name:ident; impl_fn = $impl:path; reg = $reg:ident;
62
+ stack_params = 3; ret_bytes = $ret:literal) => {
63
+ #[unsafe(naked)]
64
+ unsafe extern "C" fn $name() {
65
+ core::arch::naked_asm!(
66
+ "push edx",
67
+ "push [esp+16]",
68
+ "push [esp+16]",
69
+ "push [esp+16]",
70
+ concat!("push ", stringify!($reg)),
71
+ "call {impl_fn}",
72
+ "add esp, 16",
73
+ "pop edx",
74
+ concat!("ret ", $ret),
75
+ impl_fn = sym $impl,
76
+ );
77
+ }
78
+ };
79
+
80
+ // 1 register arg, 5 stack params, ret N
81
+ (fn $name:ident; impl_fn = $impl:path; reg = $reg:ident;
82
+ stack_params = 5; ret_bytes = $ret:literal) => {
83
+ #[unsafe(naked)]
84
+ unsafe extern "C" fn $name() {
85
+ core::arch::naked_asm!(
86
+ "push edx",
87
+ "push [esp+24]",
88
+ "push [esp+24]",
89
+ "push [esp+24]",
90
+ "push [esp+24]",
91
+ "push [esp+24]",
92
+ concat!("push ", stringify!($reg)),
93
+ "call {impl_fn}",
94
+ "add esp, 24",
95
+ "pop edx",
96
+ concat!("ret ", $ret),
97
+ impl_fn = sym $impl,
98
+ );
99
+ }
100
+ };
101
+
102
  // 2 register args, 1 stack param, ret N
103
  (fn $name:ident; impl_fn = $impl:path; regs = [$r1:ident, $r2:ident];
104
  stack_params = 1; ret_bytes = $ret:literal) => {
 
177
  }
178
  };
179
 
180
+ // 2 register args, 5 stack params, ret N
181
+ (fn $name:ident; impl_fn = $impl:path; regs = [$r1:ident, $r2:ident];
182
+ stack_params = 5; ret_bytes = $ret:literal) => {
183
+ #[unsafe(naked)]
184
+ unsafe extern "C" fn $name() {
185
+ core::arch::naked_asm!(
186
+ "push edx",
187
+ "push [esp+24]",
188
+ "push [esp+24]",
189
+ "push [esp+24]",
190
+ "push [esp+24]",
191
+ "push [esp+24]",
192
+ concat!("push ", stringify!($r2)),
193
+ concat!("push ", stringify!($r1)),
194
+ "call {impl_fn}",
195
+ "add esp, 28",
196
+ "pop edx",
197
+ concat!("ret ", $ret),
198
+ impl_fn = sym $impl,
199
+ );
200
+ }
201
+ };
202
+
203
+ // 2 register args, 6 stack params, ret N
204
+ (fn $name:ident; impl_fn = $impl:path; regs = [$r1:ident, $r2:ident];
205
+ stack_params = 6; ret_bytes = $ret:literal) => {
206
+ #[unsafe(naked)]
207
+ unsafe extern "C" fn $name() {
208
+ core::arch::naked_asm!(
209
+ "push edx",
210
+ "push [esp+28]",
211
+ "push [esp+28]",
212
+ "push [esp+28]",
213
+ "push [esp+28]",
214
+ "push [esp+28]",
215
+ "push [esp+28]",
216
+ concat!("push ", stringify!($r2)),
217
+ concat!("push ", stringify!($r1)),
218
+ "call {impl_fn}",
219
+ "add esp, 32",
220
+ "pop edx",
221
+ concat!("ret ", $ret),
222
+ impl_fn = sym $impl,
223
+ );
224
+ }
225
+ };
226
+
227
+ // 2 register args, 7 stack params, ret N
228
+ (fn $name:ident; impl_fn = $impl:path; regs = [$r1:ident, $r2:ident];
229
+ stack_params = 7; ret_bytes = $ret:literal) => {
230
+ #[unsafe(naked)]
231
+ unsafe extern "C" fn $name() {
232
+ core::arch::naked_asm!(
233
+ "push edx",
234
+ "push [esp+32]",
235
+ "push [esp+32]",
236
+ "push [esp+32]",
237
+ "push [esp+32]",
238
+ "push [esp+32]",
239
+ "push [esp+32]",
240
+ "push [esp+32]",
241
+ concat!("push ", stringify!($r2)),
242
+ concat!("push ", stringify!($r1)),
243
+ "call {impl_fn}",
244
+ "add esp, 36",
245
+ "pop edx",
246
+ concat!("ret ", $ret),
247
+ impl_fn = sym $impl,
248
+ );
249
+ }
250
+ };
251
+
252
  // 2 register args, 3 stack params, ret N
253
  (fn $name:ident; impl_fn = $impl:path; regs = [$r1:ident, $r2:ident];
254
  stack_params = 3; ret_bytes = $ret:literal) => {
crates/openwa-wormkit/src/replacements/sprite.rs CHANGED
@@ -1,25 +1,111 @@
1
- //! Sprite drawing hooks — full Rust replacements.
2
  //!
3
- //! - DrawSpriteGlobal (0x541FE0): enqueue world-space sprite (command type 4)
4
- //! - DrawSpriteLocal (0x542060): enqueue screen-space sprite (command type 5)
5
- //!
6
- //! Both functions are __thiscall + EAX=y_pos (usercall), 4 stack params, RET 0x10.
7
 
8
  use openwa_types::address::va;
9
- use openwa_types::render::{command_type, RenderCommand, RenderQueue};
10
 
11
  use crate::hook::{self, usercall_trampoline};
12
 
13
  // ---------------------------------------------------------------------------
14
- // DrawSpriteGlobal — full Rust replacement
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  // ---------------------------------------------------------------------------
16
 
17
  usercall_trampoline!(fn trampoline_draw_sprite_global; impl_fn = draw_sprite_global_impl;
18
  regs = [eax, ecx]; stack_params = 4; ret_bytes = "0x10");
19
 
20
- /// Full Rust replacement for DrawSpriteGlobal (0x541FE0).
21
- ///
22
- /// Enqueues a render command (type 4, world-space) to the drawing queue.
23
  unsafe extern "cdecl" fn draw_sprite_global_impl(
24
  y_pos: u32,
25
  this: u32,
@@ -30,8 +116,8 @@ unsafe extern "cdecl" fn draw_sprite_global_impl(
30
  ) {
31
  let q = &mut *(this as *mut RenderQueue);
32
 
33
- if let Some(entry) = q.alloc_entry() {
34
- *entry = RenderCommand {
35
  command_type: command_type::DRAW_SPRITE_GLOBAL,
36
  layer,
37
  x_pos: x_pos & 0xFFFF0000,
@@ -43,15 +129,12 @@ unsafe extern "cdecl" fn draw_sprite_global_impl(
43
  }
44
 
45
  // ---------------------------------------------------------------------------
46
- // DrawSpriteLocal — full Rust replacement
47
  // ---------------------------------------------------------------------------
48
 
49
  usercall_trampoline!(fn trampoline_draw_sprite_local; impl_fn = draw_sprite_local_impl;
50
  regs = [eax, ecx]; stack_params = 4; ret_bytes = "0x10");
51
 
52
- /// Full Rust replacement for DrawSpriteLocal (0x542060).
53
- ///
54
- /// Enqueues a render command (type 5, screen-space) to the drawing queue.
55
  unsafe extern "cdecl" fn draw_sprite_local_impl(
56
  y_pos: u32,
57
  this: u32,
@@ -62,8 +145,8 @@ unsafe extern "cdecl" fn draw_sprite_local_impl(
62
  ) {
63
  let q = &mut *(this as *mut RenderQueue);
64
 
65
- if let Some(entry) = q.alloc_entry() {
66
- *entry = RenderCommand {
67
  command_type: command_type::DRAW_SPRITE_LOCAL,
68
  layer,
69
  x_pos: x_pos & 0xFFFF0000,
@@ -74,11 +157,137 @@ unsafe extern "cdecl" fn draw_sprite_local_impl(
74
  }
75
  }
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  // ---------------------------------------------------------------------------
78
  // Installation
79
  // ---------------------------------------------------------------------------
80
 
81
  pub unsafe fn install() -> Result<(), String> {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  let _ = hook::install(
83
  "DrawSpriteGlobal",
84
  va::DRAW_SPRITE_GLOBAL,
@@ -91,5 +300,23 @@ pub unsafe fn install() -> Result<(), String> {
91
  trampoline_draw_sprite_local as *const (),
92
  )?;
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  Ok(())
95
  }
 
1
+ //! RenderQueue enqueue hooks — full Rust replacements.
2
  //!
3
+ //! All functions enqueue commands to the RenderQueue's downward-growing buffer.
4
+ //! Calling conventions are __usercall variants with register + stack params.
 
 
5
 
6
  use openwa_types::address::va;
7
+ use openwa_types::render::*;
8
 
9
  use crate::hook::{self, usercall_trampoline};
10
 
11
  // ---------------------------------------------------------------------------
12
+ // DrawPixel (0x541D60) — type 0xD, EAX=this, 3 stack, RET 0xC
13
+ // ---------------------------------------------------------------------------
14
+
15
+ usercall_trampoline!(fn trampoline_draw_pixel; impl_fn = draw_pixel_impl;
16
+ reg = eax; stack_params = 3; ret_bytes = "0xC");
17
+
18
+ unsafe extern "cdecl" fn draw_pixel_impl(
19
+ this: u32,
20
+ x_pos: u32,
21
+ y_pos: u32,
22
+ flags: u32,
23
+ ) {
24
+ let q = &mut *(this as *mut RenderQueue);
25
+
26
+ if let Some(entry) = q.alloc::<DrawPixelCmd>() {
27
+ *entry = DrawPixelCmd {
28
+ command_type: command_type::DRAW_PIXEL,
29
+ layer: 0x1B_0000,
30
+ color: 0xFF00_0000,
31
+ x_pos,
32
+ y_pos,
33
+ flags: flags as u8,
34
+ _pad: [0; 3],
35
+ };
36
+ }
37
+ }
38
+
39
+ // ---------------------------------------------------------------------------
40
+ // DrawScaled (0x541ED0) — type 0xB, ECX=this, 5 stack, RET 0x14
41
+ // ---------------------------------------------------------------------------
42
+
43
+ usercall_trampoline!(fn trampoline_draw_scaled; impl_fn = draw_scaled_impl;
44
+ reg = ecx; stack_params = 5; ret_bytes = "0x14");
45
+
46
+ unsafe extern "cdecl" fn draw_scaled_impl(
47
+ this: u32,
48
+ layer: u32,
49
+ sprite_id: u32,
50
+ frame: u32,
51
+ x_pos: u32,
52
+ y_pos: u32,
53
+ ) {
54
+ let q = &mut *(this as *mut RenderQueue);
55
+
56
+ if let Some(entry) = q.alloc::<DrawScaledCmd>() {
57
+ *entry = DrawScaledCmd {
58
+ command_type: command_type::DRAW_SCALED,
59
+ layer,
60
+ x_pos,
61
+ y_pos,
62
+ sprite_id,
63
+ frame,
64
+ _reserved: 0,
65
+ };
66
+ }
67
+ }
68
+
69
+ // ---------------------------------------------------------------------------
70
+ // DrawRect (0x541F40) — type 0, ECX=this, EDX=y_clip, 6 stack, RET 0x18
71
+ // ---------------------------------------------------------------------------
72
+
73
+ usercall_trampoline!(fn trampoline_draw_rect; impl_fn = draw_rect_impl;
74
+ regs = [ecx, edx]; stack_params = 6; ret_bytes = "0x18");
75
+
76
+ unsafe extern "cdecl" fn draw_rect_impl(
77
+ this: u32,
78
+ y_clip: u32,
79
+ layer: u32,
80
+ x1: u32,
81
+ y1: u32,
82
+ x2: u32,
83
+ y2: u32,
84
+ color: u32,
85
+ ) {
86
+ let q = &mut *(this as *mut RenderQueue);
87
+
88
+ if let Some(entry) = q.alloc::<DrawRectCmd>() {
89
+ *entry = DrawRectCmd {
90
+ command_type: command_type::DRAW_RECT,
91
+ layer,
92
+ color,
93
+ x1: x1 & 0xFFFF0000,
94
+ y1: y1 & 0xFFFF0000,
95
+ x2: x2 & 0xFFFF0000,
96
+ y2: y2 & 0xFFFF0000,
97
+ y_clip: y_clip & 0xFFFF0000,
98
+ };
99
+ }
100
+ }
101
+
102
+ // ---------------------------------------------------------------------------
103
+ // DrawSpriteGlobal (0x541FE0) — type 4, EAX=y, ECX=this, 4 stack, RET 0x10
104
  // ---------------------------------------------------------------------------
105
 
106
  usercall_trampoline!(fn trampoline_draw_sprite_global; impl_fn = draw_sprite_global_impl;
107
  regs = [eax, ecx]; stack_params = 4; ret_bytes = "0x10");
108
 
 
 
 
109
  unsafe extern "cdecl" fn draw_sprite_global_impl(
110
  y_pos: u32,
111
  this: u32,
 
116
  ) {
117
  let q = &mut *(this as *mut RenderQueue);
118
 
119
+ if let Some(entry) = q.alloc::<DrawSpriteCmd>() {
120
+ *entry = DrawSpriteCmd {
121
  command_type: command_type::DRAW_SPRITE_GLOBAL,
122
  layer,
123
  x_pos: x_pos & 0xFFFF0000,
 
129
  }
130
 
131
  // ---------------------------------------------------------------------------
132
+ // DrawSpriteLocal (0x542060) — type 5, EAX=y, ECX=this, 4 stack, RET 0x10
133
  // ---------------------------------------------------------------------------
134
 
135
  usercall_trampoline!(fn trampoline_draw_sprite_local; impl_fn = draw_sprite_local_impl;
136
  regs = [eax, ecx]; stack_params = 4; ret_bytes = "0x10");
137
 
 
 
 
138
  unsafe extern "cdecl" fn draw_sprite_local_impl(
139
  y_pos: u32,
140
  this: u32,
 
145
  ) {
146
  let q = &mut *(this as *mut RenderQueue);
147
 
148
+ if let Some(entry) = q.alloc::<DrawSpriteCmd>() {
149
+ *entry = DrawSpriteCmd {
150
  command_type: command_type::DRAW_SPRITE_LOCAL,
151
  layer,
152
  x_pos: x_pos & 0xFFFF0000,
 
157
  }
158
  }
159
 
160
+ // ---------------------------------------------------------------------------
161
+ // DrawSpriteOffset (0x5420E0) — type 6, ECX=this, EDX=y_clip, 6 stack, RET 0x18
162
+ // ---------------------------------------------------------------------------
163
+
164
+ usercall_trampoline!(fn trampoline_draw_sprite_offset; impl_fn = draw_sprite_offset_impl;
165
+ regs = [ecx, edx]; stack_params = 6; ret_bytes = "0x18");
166
+
167
+ unsafe extern "cdecl" fn draw_sprite_offset_impl(
168
+ this: u32,
169
+ y_clip: u32,
170
+ layer: u32,
171
+ x_pos: u32,
172
+ y_pos: u32,
173
+ sprite_id: u32,
174
+ param_7: u32,
175
+ param_8: u32,
176
+ ) {
177
+ let q = &mut *(this as *mut RenderQueue);
178
+
179
+ if let Some(entry) = q.alloc::<DrawSpriteOffsetCmd>() {
180
+ *entry = DrawSpriteOffsetCmd {
181
+ command_type: command_type::DRAW_SPRITE_OFFSET,
182
+ layer,
183
+ sprite_id,
184
+ x_pos: x_pos & 0xFFFF0000,
185
+ y_pos: y_pos & 0xFFFF0000,
186
+ _reserved: 0,
187
+ y_clip: y_clip & 0xFFFF0000,
188
+ param_7,
189
+ param_8,
190
+ };
191
+ }
192
+ }
193
+
194
+ // ---------------------------------------------------------------------------
195
+ // DrawBitmapGlobal (0x542170) — type 1, ECX=this, EDX=y, 7 stack, RET 0x1C
196
+ // ---------------------------------------------------------------------------
197
+
198
+ usercall_trampoline!(fn trampoline_draw_bitmap_global; impl_fn = draw_bitmap_global_impl;
199
+ regs = [ecx, edx]; stack_params = 7; ret_bytes = "0x1C");
200
+
201
+ unsafe extern "cdecl" fn draw_bitmap_global_impl(
202
+ this: u32,
203
+ y_pos: u32,
204
+ layer: u32,
205
+ x_pos: u32,
206
+ bitmap_ptr: u32,
207
+ param_6: u32,
208
+ param_7: u32,
209
+ param_8: u32,
210
+ param_9: u32,
211
+ ) {
212
+ let q = &mut *(this as *mut RenderQueue);
213
+
214
+ if let Some(entry) = q.alloc::<DrawBitmapGlobalCmd>() {
215
+ *entry = DrawBitmapGlobalCmd {
216
+ command_type: command_type::DRAW_BITMAP_GLOBAL,
217
+ layer,
218
+ x_pos: x_pos & 0xFFFF0000,
219
+ y_pos: y_pos & 0xFFFF0000,
220
+ bitmap_ptr,
221
+ _reserved: 0,
222
+ param_6,
223
+ param_7,
224
+ param_8,
225
+ param_9,
226
+ };
227
+ }
228
+ }
229
+
230
+ // ---------------------------------------------------------------------------
231
+ // DrawTextboxLocal (0x542200) — type 2, ECX=this, EDX=y, 6 stack, RET 0x18
232
+ // ---------------------------------------------------------------------------
233
+
234
+ usercall_trampoline!(fn trampoline_draw_textbox_local; impl_fn = draw_textbox_local_impl;
235
+ regs = [ecx, edx]; stack_params = 6; ret_bytes = "0x18");
236
+
237
+ unsafe extern "cdecl" fn draw_textbox_local_impl(
238
+ this: u32,
239
+ y_pos: u32,
240
+ layer: u32,
241
+ x_pos: u32,
242
+ text_ptr: u32,
243
+ param_6: u32,
244
+ param_7: u32,
245
+ param_8: u32,
246
+ ) {
247
+ let q = &mut *(this as *mut RenderQueue);
248
+
249
+ if let Some(entry) = q.alloc::<DrawTextboxLocalCmd>() {
250
+ *entry = DrawTextboxLocalCmd {
251
+ command_type: command_type::DRAW_TEXTBOX_LOCAL,
252
+ layer,
253
+ _reserved_2: 0,
254
+ x_pos: x_pos & 0xFFFF0000,
255
+ y_pos: y_pos & 0xFFFF0000,
256
+ _reserved_5: 0,
257
+ _reserved_6: 0,
258
+ text_ptr,
259
+ _reserved_8: 0,
260
+ _reserved_9: 0,
261
+ param_6,
262
+ param_7,
263
+ param_8,
264
+ };
265
+ }
266
+ }
267
+
268
  // ---------------------------------------------------------------------------
269
  // Installation
270
  // ---------------------------------------------------------------------------
271
 
272
  pub unsafe fn install() -> Result<(), String> {
273
+ let _ = hook::install(
274
+ "DrawPixel",
275
+ va::DRAW_PIXEL,
276
+ trampoline_draw_pixel as *const (),
277
+ )?;
278
+
279
+ let _ = hook::install(
280
+ "DrawScaled",
281
+ va::DRAW_SCALED,
282
+ trampoline_draw_scaled as *const (),
283
+ )?;
284
+
285
+ let _ = hook::install(
286
+ "DrawRect",
287
+ va::DRAW_RECT,
288
+ trampoline_draw_rect as *const (),
289
+ )?;
290
+
291
  let _ = hook::install(
292
  "DrawSpriteGlobal",
293
  va::DRAW_SPRITE_GLOBAL,
 
300
  trampoline_draw_sprite_local as *const (),
301
  )?;
302
 
303
+ let _ = hook::install(
304
+ "DrawSpriteOffset",
305
+ va::DRAW_SPRITE_OFFSET,
306
+ trampoline_draw_sprite_offset as *const (),
307
+ )?;
308
+
309
+ let _ = hook::install(
310
+ "DrawBitmapGlobal",
311
+ va::DRAW_BITMAP_GLOBAL,
312
+ trampoline_draw_bitmap_global as *const (),
313
+ )?;
314
+
315
+ let _ = hook::install(
316
+ "DrawTextboxLocal",
317
+ va::DRAW_TEXTBOX_LOCAL,
318
+ trampoline_draw_textbox_local as *const (),
319
+ )?;
320
+
321
  Ok(())
322
  }