refactor: add TeamArenaRef::from_ptr for typed construction
Browse filesAdd from_ptr(*mut TeamArenaState) alongside the existing from_raw(u32)
used by trampolines. fire_skip_go now constructs TeamArenaRef directly
from the typed DDGame.team_arena field pointer — no u32 cast.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
crates/openwa-core/src/engine/ddgame.rs
CHANGED
|
@@ -1902,10 +1902,10 @@ pub struct TeamArenaRef {
|
|
| 1902 |
}
|
| 1903 |
|
| 1904 |
impl TeamArenaRef {
|
| 1905 |
-
/// Wrap a raw
|
| 1906 |
///
|
| 1907 |
/// # Safety
|
| 1908 |
-
/// `base` must point to
|
| 1909 |
#[inline]
|
| 1910 |
pub unsafe fn from_raw(base: u32) -> Self {
|
| 1911 |
Self {
|
|
@@ -1913,6 +1913,17 @@ impl TeamArenaRef {
|
|
| 1913 |
}
|
| 1914 |
}
|
| 1915 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1916 |
/// Access the TeamArenaState fields (read-only).
|
| 1917 |
#[inline]
|
| 1918 |
pub unsafe fn state(&self) -> &TeamArenaState {
|
|
|
|
| 1902 |
}
|
| 1903 |
|
| 1904 |
impl TeamArenaRef {
|
| 1905 |
+
/// Wrap a raw integer pointer (for usercall trampoline register captures).
|
| 1906 |
///
|
| 1907 |
/// # Safety
|
| 1908 |
+
/// `base` must point to a valid TeamArenaState (DDGame + 0x4628).
|
| 1909 |
#[inline]
|
| 1910 |
pub unsafe fn from_raw(base: u32) -> Self {
|
| 1911 |
Self {
|
|
|
|
| 1913 |
}
|
| 1914 |
}
|
| 1915 |
|
| 1916 |
+
/// Wrap a typed pointer to TeamArenaState.
|
| 1917 |
+
///
|
| 1918 |
+
/// # Safety
|
| 1919 |
+
/// `arena` must point to a valid TeamArenaState within a live DDGame.
|
| 1920 |
+
#[inline]
|
| 1921 |
+
pub unsafe fn from_ptr(arena: *mut TeamArenaState) -> Self {
|
| 1922 |
+
Self {
|
| 1923 |
+
base: arena as *mut u8,
|
| 1924 |
+
}
|
| 1925 |
+
}
|
| 1926 |
+
|
| 1927 |
/// Access the TeamArenaState fields (read-only).
|
| 1928 |
#[inline]
|
| 1929 |
pub unsafe fn state(&self) -> &TeamArenaState {
|
crates/openwa-wormkit/src/replacements/weapon.rs
CHANGED
|
@@ -409,8 +409,7 @@ unsafe fn fire_skip_go(worm: *const CTaskWorm, entry: *const WeaponEntry) {
|
|
| 409 |
let bit_index = (*entry).fire_params._data[0] & 0x1F;
|
| 410 |
let bit = 1u32 << bit_index;
|
| 411 |
|
| 412 |
-
let
|
| 413 |
-
let arena = TeamArenaRef::from_raw(arena_ptr);
|
| 414 |
let header = arena.team_header_mut(team_index);
|
| 415 |
let flags = header.turn_action_flags;
|
| 416 |
|
|
|
|
| 409 |
let bit_index = (*entry).fire_params._data[0] & 0x1F;
|
| 410 |
let bit = 1u32 << bit_index;
|
| 411 |
|
| 412 |
+
let arena = TeamArenaRef::from_ptr(&raw mut (*ddgame).team_arena);
|
|
|
|
| 413 |
let header = arena.team_header_mut(team_index);
|
| 414 |
let flags = header.turn_action_flags;
|
| 415 |
|