From d75bcf7ff21503b530c6b23cd3039397aa96cd04 Mon Sep 17 00:00:00 2001 From: chayleaf Date: Wed, 5 Jul 2023 15:31:40 +0700 Subject: [PATCH] windows stuff --- .github/workflows/build.yml | 5 ++ Cargo.lock | 2 +- src/ffi.rs | 36 ++++++++++++- src/lib.rs | 101 +++++++++++++++++++++++------------- 4 files changed, 106 insertions(+), 38 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6a3584e..99ea4c2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,6 +19,11 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v3 + - name: rs-action + uses: chayleaf/rs-actions@konigsberg + with: + publish-release: true + target: i686-pc-windows-msvc - name: rs-action uses: chayleaf/rs-actions@konigsberg with: diff --git a/Cargo.lock b/Cargo.lock index e8797b4..794624f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -335,7 +335,7 @@ dependencies = [ [[package]] name = "konigsberg" -version = "0.1.0" +version = "0.2.0" dependencies = [ "libloading", "object", diff --git a/src/ffi.rs b/src/ffi.rs index 898e8d5..7cfa8df 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -54,14 +54,48 @@ unsafe fn lib() -> &'static libloading::Library { #[cfg(target_os = "macos")] { libloading::Library::new("./libsteam_api.orig.dylib") + .or_else(|_| libloading::Library::new("./libsteam_api_orig.dylib")) + .or_else(|_| libloading::Library::new("libsteam_api.orig.dylib")) + .or_else(|_| libloading::Library::new("libsteam_api_orig.dylib")) + .or_else(|_| libloading::Library::new("steam_api.orig.dylib")) + .or_else(|_| libloading::Library::new("steam_api_orig.dylib")) + .or_else(|_| libloading::Library::new("steam_api.orig")) + .or_else(|_| libloading::Library::new("steam_api_orig")) } - #[cfg(target_os = "windows")] + #[cfg(all(target_os = "windows", not(target_pointer_width = "64")))] { libloading::Library::new("./steam_api.orig.dll") + .or_else(|_| libloading::Library::new("./steam_api_orig.dll")) + .or_else(|_| libloading::Library::new("steam_api.orig.dll")) + .or_else(|_| libloading::Library::new("steam_api_orig.dll")) + .or_else(|_| libloading::Library::new("steam_api.orig")) + .or_else(|_| libloading::Library::new("steam_api_orig")) + } + #[cfg(all(target_os = "windows", target_pointer_width = "64"))] + { + libloading::Library::new("./steam_api64.orig.dll") + .or_else(|_| libloading::Library::new("./steam_api64_orig.dll")) + .or_else(|_| libloading::Library::new("steam_api64.orig.dll")) + .or_else(|_| libloading::Library::new("steam_api64_orig.dll")) + .or_else(|_| libloading::Library::new("steam_api64.orig")) + .or_else(|_| libloading::Library::new("steam_api64_orig")) + .or_else(|_| libloading::Library::new("./steam_api.orig.dll")) + .or_else(|_| libloading::Library::new("./steam_api_orig.dll")) + .or_else(|_| libloading::Library::new("steam_api.orig.dll")) + .or_else(|_| libloading::Library::new("steam_api_orig.dll")) + .or_else(|_| libloading::Library::new("steam_api.orig")) + .or_else(|_| libloading::Library::new("steam_api_orig")) } #[cfg(all(not(target_os = "windows"), not(target_os = "macos")))] { libloading::Library::new("./libsteam_api.orig.so") + .or_else(|_| libloading::Library::new("./libsteam_api_orig.so")) + .or_else(|_| libloading::Library::new("libsteam_api.orig.so")) + .or_else(|_| libloading::Library::new("libsteam_api_orig.so")) + .or_else(|_| libloading::Library::new("steam_api.orig.so")) + .or_else(|_| libloading::Library::new("steam_api_orig.so")) + .or_else(|_| libloading::Library::new("steam_api.orig")) + .or_else(|_| libloading::Library::new("steam_api_orig")) } } .expect("failed to load steam api lib") diff --git a/src/lib.rs b/src/lib.rs index 7d9968d..aed0b23 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,12 +38,12 @@ unsafe fn parse_ver(ver: *const c_char) -> Option { } #[allow(clippy::missing_safety_doc)] -#[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] +#[cfg(any(not(target_os = "windows"), not(target_pointer_width = "32")))] unsafe extern "C" fn b_is_dlc_installed(_this: *mut c_void, _app_id: AppId_t) -> bool { true } #[allow(clippy::missing_safety_doc)] -#[cfg(all(target_os = "windows", target_arch = "x86"))] +#[cfg(all(target_os = "windows", target_pointer_width = "32"))] unsafe extern "fastcall" fn b_is_dlc_installed( _this: *mut c_void, _edx: usize, @@ -51,7 +51,7 @@ unsafe extern "fastcall" fn b_is_dlc_installed( ) -> bool { true } -#[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] +#[cfg(any(not(target_os = "windows"), not(target_pointer_width = "32")))] #[allow(clippy::missing_safety_doc, improper_ctypes_definitions)] unsafe extern "C" fn user_has_license_for_app( _this: *mut c_void, @@ -60,7 +60,7 @@ unsafe extern "C" fn user_has_license_for_app( ) -> EUserHasLicenseForAppResult { EUserHasLicenseForAppResult::k_EUserHasLicenseResultHasLicense } -#[cfg(all(target_os = "windows", target_arch = "x86"))] +#[cfg(all(target_os = "windows", target_pointer_width = "32"))] #[allow(clippy::missing_safety_doc, improper_ctypes_definitions)] unsafe extern "fastcall" fn user_has_license_for_app( _this: *mut c_void, @@ -73,21 +73,23 @@ unsafe extern "fastcall" fn user_has_license_for_app( #[derive(Copy, Clone)] struct OrigSteamClientFns { - #[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] + #[cfg(any(not(target_os = "windows"), not(target_pointer_width = "32")))] generic: Option< unsafe extern "C" fn(*mut c_void, HSteamUser, HSteamPipe, *const c_char) -> *mut c_void, >, - #[cfg(all(target_os = "windows", target_arch = "x86"))] - generic: unsafe extern "fastcall" fn( - *mut c_void, - usize, - HSteamUser, - HSteamPipe, - *const c_char, - ) -> *mut c_void, - #[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] + #[cfg(all(target_os = "windows", target_pointer_width = "32"))] + generic: Option< + unsafe extern "fastcall" fn( + *mut c_void, + usize, + HSteamUser, + HSteamPipe, + *const c_char, + ) -> *mut c_void, + >, + #[cfg(any(not(target_os = "windows"), not(target_pointer_width = "32")))] apps: unsafe extern "C" fn(*mut c_void, HSteamUser, HSteamPipe, *const c_char) -> *mut c_void, - #[cfg(all(target_os = "windows", target_arch = "x86"))] + #[cfg(all(target_os = "windows", target_pointer_width = "32"))] apps: unsafe extern "fastcall" fn( *mut c_void, usize, @@ -95,9 +97,9 @@ struct OrigSteamClientFns { HSteamPipe, *const c_char, ) -> *mut c_void, - #[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] + #[cfg(any(not(target_os = "windows"), not(target_pointer_width = "32")))] user: unsafe extern "C" fn(*mut c_void, HSteamUser, HSteamPipe, *const c_char) -> *mut c_void, - #[cfg(all(target_os = "windows", target_arch = "x86"))] + #[cfg(all(target_os = "windows", target_pointer_width = "32"))] user: unsafe extern "fastcall" fn( *mut c_void, usize, @@ -138,12 +140,21 @@ unsafe fn steam_client_common( }) }) }) - .map(|func| func(this, steam_user, steam_pipe, ver)) + .map(|func| { + func( + this, + #[cfg(all(target_os = "windows", target_pointer_width = "32"))] + 0, + steam_user, + steam_pipe, + ver, + ) + }) .unwrap_or(std::ptr::null_mut()), ) } -#[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] +#[cfg(any(not(target_os = "windows"), not(target_pointer_width = "32")))] #[allow(clippy::missing_safety_doc)] unsafe extern "C" fn get_i_steam_generic_interface( this: *mut c_void, @@ -153,7 +164,7 @@ unsafe extern "C" fn get_i_steam_generic_interface( ) -> *mut c_void { steam_client_common(this, steam_user, steam_pipe, ver, SteamClientFn::Generic) } -#[cfg(all(target_os = "windows", target_arch = "x86"))] +#[cfg(all(target_os = "windows", target_pointer_width = "32"))] #[allow(clippy::missing_safety_doc)] unsafe extern "fastcall" fn get_i_steam_generic_interface( this: *mut c_void, @@ -164,7 +175,7 @@ unsafe extern "fastcall" fn get_i_steam_generic_interface( ) -> *mut c_void { steam_client_common(this, steam_user, steam_pipe, ver, SteamClientFn::Generic) } -#[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] +#[cfg(any(not(target_os = "windows"), not(target_pointer_width = "32")))] #[allow(clippy::missing_safety_doc)] unsafe extern "C" fn get_i_steam_user( this: *mut c_void, @@ -174,7 +185,7 @@ unsafe extern "C" fn get_i_steam_user( ) -> *mut c_void { steam_client_common(this, steam_user, steam_pipe, ver, SteamClientFn::User) } -#[cfg(all(target_os = "windows", target_arch = "x86"))] +#[cfg(all(target_os = "windows", target_pointer_width = "32"))] #[allow(clippy::missing_safety_doc)] unsafe extern "fastcall" fn get_i_steam_user( this: *mut c_void, @@ -185,7 +196,7 @@ unsafe extern "fastcall" fn get_i_steam_user( ) -> *mut c_void { steam_client_common(this, steam_user, steam_pipe, ver, SteamClientFn::User) } -#[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] +#[cfg(any(not(target_os = "windows"), not(target_pointer_width = "32")))] #[allow(clippy::missing_safety_doc)] unsafe extern "C" fn get_i_steam_apps( this: *mut c_void, @@ -195,7 +206,7 @@ unsafe extern "C" fn get_i_steam_apps( ) -> *mut c_void { steam_client_common(this, steam_user, steam_pipe, ver, SteamClientFn::Apps) } -#[cfg(all(target_os = "windows", target_arch = "x86"))] +#[cfg(all(target_os = "windows", target_pointer_width = "32"))] #[allow(clippy::missing_safety_doc)] unsafe extern "fastcall" fn get_i_steam_apps( this: *mut c_void, @@ -250,12 +261,15 @@ unsafe fn patch_ptr(ver: Option, ret: *mut c_void) -> *mut c_void { // this is issubscribedapp, same sig as isdlcinstalled ( 6, - #[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] + #[cfg(any( + not(target_os = "windows"), + not(target_pointer_width = "32") + ))] std::mem::transmute(Some( b_is_dlc_installed as unsafe extern "C" fn(*mut c_void, AppId_t) -> bool, )), - #[cfg(all(target_os = "windows", target_arch = "x86"))] + #[cfg(all(target_os = "windows", target_pointer_width = "32"))] std::mem::transmute(Some( b_is_dlc_installed as unsafe extern "fastcall" fn( @@ -270,12 +284,15 @@ unsafe fn patch_ptr(ver: Option, ret: *mut c_void) -> *mut c_void { if n >= 3 { patches.push(( 7, - #[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] + #[cfg(any( + not(target_os = "windows"), + not(target_pointer_width = "32") + ))] std::mem::transmute(Some( b_is_dlc_installed as unsafe extern "C" fn(*mut c_void, AppId_t) -> bool, )), - #[cfg(all(target_os = "windows", target_arch = "x86"))] + #[cfg(all(target_os = "windows", target_pointer_width = "32"))] std::mem::transmute(Some( b_is_dlc_installed as unsafe extern "fastcall" fn( @@ -299,7 +316,10 @@ unsafe fn patch_ptr(ver: Option, ret: *mut c_void) -> *mut c_void { 13..=14 => 16, 15.. => 17, }, - #[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] + #[cfg(any( + not(target_os = "windows"), + not(target_pointer_width = "32") + ))] std::mem::transmute(Some( user_has_license_for_app as unsafe extern "C" fn( @@ -309,7 +329,7 @@ unsafe fn patch_ptr(ver: Option, ret: *mut c_void) -> *mut c_void { ) -> EUserHasLicenseForAppResult, )), - #[cfg(all(target_os = "windows", target_arch = "x86"))] + #[cfg(all(target_os = "windows", target_pointer_width = "32"))] std::mem::transmute(Some( user_has_license_for_app as unsafe extern "fastcall" fn( @@ -346,7 +366,10 @@ unsafe fn patch_ptr(ver: Option, ret: *mut c_void) -> *mut c_void { let mut patches = vec![ ( offset_apps, - #[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] + #[cfg(any( + not(target_os = "windows"), + not(target_pointer_width = "32") + ))] std::mem::transmute(Some( get_i_steam_apps as unsafe extern "C" fn( @@ -357,7 +380,7 @@ unsafe fn patch_ptr(ver: Option, ret: *mut c_void) -> *mut c_void { ) -> *mut c_void, )), - #[cfg(all(target_os = "windows", target_arch = "x86"))] + #[cfg(all(target_os = "windows", target_pointer_width = "32"))] std::mem::transmute(Some( get_i_steam_apps as unsafe extern "fastcall" fn( @@ -372,7 +395,10 @@ unsafe fn patch_ptr(ver: Option, ret: *mut c_void) -> *mut c_void { ), ( offset_user, - #[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] + #[cfg(any( + not(target_os = "windows"), + not(target_pointer_width = "32") + ))] std::mem::transmute(Some( get_i_steam_user as unsafe extern "C" fn( @@ -383,7 +409,7 @@ unsafe fn patch_ptr(ver: Option, ret: *mut c_void) -> *mut c_void { ) -> *mut c_void, )), - #[cfg(all(target_os = "windows", target_arch = "x86"))] + #[cfg(all(target_os = "windows", target_pointer_width = "32"))] std::mem::transmute(Some( get_i_steam_user as unsafe extern "fastcall" fn( @@ -400,7 +426,10 @@ unsafe fn patch_ptr(ver: Option, ret: *mut c_void) -> *mut c_void { if let Some(offset_generic) = offset_generic { patches.push(( offset_generic, - #[cfg(any(not(target_os = "windows"), not(target_arch = "x86")))] + #[cfg(any( + not(target_os = "windows"), + not(target_pointer_width = "32") + ))] std::mem::transmute(Some( get_i_steam_generic_interface as unsafe extern "C" fn( @@ -411,7 +440,7 @@ unsafe fn patch_ptr(ver: Option, ret: *mut c_void) -> *mut c_void { ) -> *mut c_void, )), - #[cfg(all(target_os = "windows", target_arch = "x86"))] + #[cfg(all(target_os = "windows", target_pointer_width = "32"))] std::mem::transmute(Some( get_i_steam_generic_interface as unsafe extern "fastcall" fn(