paavohtl Claude Opus 4.6 commited on
Commit
ab93fba
·
1 Parent(s): 24a8d66

feat: add Theme file I/O hooks (GetFileSize, Load, Save)

Browse files

New config.rs replacement module with three theme hooks using std::fs.
Error dialogs use MessageBoxA matching original AfxMessageBox behavior.

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

crates/openwa-wormkit/Cargo.toml CHANGED
@@ -13,4 +13,7 @@ openwa-lib = { path = "../openwa-lib" }
13
  minhook = "0.9"
14
 
15
  [target.'cfg(target_os = "windows")'.dependencies]
16
- windows-sys = { version = "0.59", features = ["Win32_System_Memory"] }
 
 
 
 
13
  minhook = "0.9"
14
 
15
  [target.'cfg(target_os = "windows")'.dependencies]
16
+ windows-sys = { version = "0.59", features = [
17
+ "Win32_System_Memory",
18
+ "Win32_UI_WindowsAndMessaging",
19
+ ] }
crates/openwa-wormkit/src/replacements/config.rs ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //! Configuration system hooks.
2
+ //!
3
+ //! Replaces WA.exe configuration functions with Rust implementations:
4
+ //! - Theme__GetFileSize (0x44BA80): theme file size query
5
+ //! - Theme__Load (0x44BB20): theme file read
6
+ //! - Theme__Save (0x44BBC0): theme file write
7
+
8
+ use openwa_types::address::va;
9
+
10
+ const THEME_PATH: &str = "data\\current.thm";
11
+
12
+ // ============================================================
13
+ // Theme__GetFileSize replacement (0x44BA80)
14
+ // ============================================================
15
+
16
+ /// Rust replacement for Theme__GetFileSize.
17
+ /// cdecl() -> u32 (file length, or 0 if missing)
18
+ unsafe extern "cdecl" fn hook_theme_get_file_size() -> u32 {
19
+ match std::fs::metadata(THEME_PATH) {
20
+ Ok(m) => m.len() as u32,
21
+ Err(_) => 0,
22
+ }
23
+ }
24
+
25
+ // ============================================================
26
+ // Theme__Load replacement (0x44BB20)
27
+ // ============================================================
28
+
29
+ /// Rust replacement for Theme__Load.
30
+ /// stdcall(dest_buffer: *mut u8)
31
+ unsafe extern "stdcall" fn hook_theme_load(dest: u32) {
32
+ match std::fs::read(THEME_PATH) {
33
+ Ok(data) => {
34
+ core::ptr::copy_nonoverlapping(data.as_ptr(), dest as *mut u8, data.len());
35
+ }
36
+ Err(_) => {
37
+ show_error_message("ERROR: NO CURRENT.THM FILE FOUND");
38
+ }
39
+ }
40
+ }
41
+
42
+ // ============================================================
43
+ // Theme__Save replacement (0x44BBC0)
44
+ // ============================================================
45
+
46
+ /// Rust replacement for Theme__Save.
47
+ /// stdcall(buffer: *const u8, size: u32)
48
+ unsafe extern "stdcall" fn hook_theme_save(buffer: u32, size: u32) {
49
+ let data = core::slice::from_raw_parts(buffer as *const u8, size as usize);
50
+ if let Err(_) = std::fs::write(THEME_PATH, data) {
51
+ show_error_message("ERROR: Could Not create CURRENT.THM File");
52
+ }
53
+ }
54
+
55
+ /// Show an error message box, matching AfxMessageBox behavior.
56
+ fn show_error_message(msg: &str) {
57
+ use windows_sys::Win32::UI::WindowsAndMessaging::*;
58
+ let mut msg_buf: Vec<u8> = msg.bytes().collect();
59
+ msg_buf.push(0);
60
+ unsafe {
61
+ MessageBoxA(core::ptr::null_mut(), msg_buf.as_ptr(), core::ptr::null(), MB_OK);
62
+ }
63
+ }
64
+
65
+ // ============================================================
66
+ // Hook installation
67
+ // ============================================================
68
+
69
+ pub fn install() -> Result<(), String> {
70
+ unsafe {
71
+ let _ = crate::hook::install(
72
+ "Theme__GetFileSize",
73
+ va::THEME_GET_FILE_SIZE,
74
+ hook_theme_get_file_size as *const (),
75
+ )?;
76
+
77
+ let _ = crate::hook::install(
78
+ "Theme__Load",
79
+ va::THEME_LOAD,
80
+ hook_theme_load as *const (),
81
+ )?;
82
+
83
+ let _ = crate::hook::install(
84
+ "Theme__Save",
85
+ va::THEME_SAVE,
86
+ hook_theme_save as *const (),
87
+ )?;
88
+ }
89
+
90
+ Ok(())
91
+ }
crates/openwa-wormkit/src/replacements/mod.rs CHANGED
@@ -1,8 +1,10 @@
 
1
  mod frontend;
2
  mod scheme;
3
 
4
  pub fn install_all() -> Result<(), String> {
5
  frontend::install()?;
6
  scheme::install()?;
 
7
  Ok(())
8
  }
 
1
+ mod config;
2
  mod frontend;
3
  mod scheme;
4
 
5
  pub fn install_all() -> Result<(), String> {
6
  frontend::install()?;
7
  scheme::install()?;
8
+ config::install()?;
9
  Ok(())
10
  }