Skip to content

Commit

Permalink
windows stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
chayleaf committed Jul 5, 2023
1 parent f5b1287 commit d75bcf7
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 35 additions & 1 deletion src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
101 changes: 65 additions & 36 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ unsafe fn parse_ver(ver: *const c_char) -> Option<Interface> {
}

#[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,
_app_id: AppId_t,
) -> 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,
Expand All @@ -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,
Expand All @@ -73,31 +73,33 @@ 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,
HSteamUser,
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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -250,12 +261,15 @@ unsafe fn patch_ptr(ver: Option<Interface>, 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(
Expand All @@ -270,12 +284,15 @@ unsafe fn patch_ptr(ver: Option<Interface>, 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(
Expand All @@ -299,7 +316,10 @@ unsafe fn patch_ptr(ver: Option<Interface>, 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(
Expand All @@ -309,7 +329,7 @@ unsafe fn patch_ptr(ver: Option<Interface>, 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(
Expand Down Expand Up @@ -346,7 +366,10 @@ unsafe fn patch_ptr(ver: Option<Interface>, 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(
Expand All @@ -357,7 +380,7 @@ unsafe fn patch_ptr(ver: Option<Interface>, 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(
Expand All @@ -372,7 +395,10 @@ unsafe fn patch_ptr(ver: Option<Interface>, 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(
Expand All @@ -383,7 +409,7 @@ unsafe fn patch_ptr(ver: Option<Interface>, 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(
Expand All @@ -400,7 +426,10 @@ unsafe fn patch_ptr(ver: Option<Interface>, 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(
Expand All @@ -411,7 +440,7 @@ unsafe fn patch_ptr(ver: Option<Interface>, 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(
Expand Down

0 comments on commit d75bcf7

Please sign in to comment.