From c0503c1327dcc0716e004ff53398b781b4d0ee9f Mon Sep 17 00:00:00 2001 From: Floogle <18466542+skyfloogle@users.noreply.github.com> Date: Sun, 14 Apr 2024 23:30:01 +0200 Subject: [PATCH] install extensions to install folder if possible --- src/lib.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index d1ac101..0f42105 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -508,6 +508,30 @@ unsafe extern "fastcall" fn make_new_folder(_: u32, path_ptr: *const u16) { project_watcher::unwatch(); } +#[naked] +unsafe extern "C" fn install_extensions_to_exedir_if_possible() { + unsafe extern "fastcall" fn inj(out: &mut UStr, localappdata: *const u16) { + let mut exe_path = PathBuf::from(std::env::args().next().unwrap()); + exe_path.pop(); + exe_path.push("extensions"); + if !matches!(std::fs::metadata(&exe_path).map(|md| md.permissions().readonly()), Ok(false)) { + // exe path's extensions are read only, give up and use localappdata + let _: u32 = delphi_call!(0x407f0c, out, localappdata); + } else { + // add a trailing slash + exe_path.push(""); + let exe_path_ustr = UStr::new(exe_path); + let _: u32 = delphi_call!(0x407f0c, out, exe_path_ustr.0); + } + } + asm!( + "mov ecx, eax", + "jmp {}", + sym inj, + options(noreturn), + ); +} + #[naked] unsafe extern "C" fn fix_tile_null_pointer() { asm!( @@ -2177,6 +2201,9 @@ unsafe fn injector() { // save new .gm82 projects to subfolder when using "save as" dialog patch_call(0x6e06b3, make_new_folder as _); + // install extensions to own directory if possible + patch_call(0x713cdf, install_extensions_to_exedir_if_possible as _); + // fix stupid null pointer error patch(0x68ef02, &[0xe9]); patch_call(0x68ef02, fix_tile_null_pointer as _);