mirror of
https://github.com/anticitizn/creamlinux.git
synced 2025-12-05 21:15:40 -05:00
update steamapi, add logging
This commit is contained in:
43
main.cpp
43
main.cpp
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "steam/steam_api.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "ini.h"
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
@@ -25,6 +26,7 @@ public:
|
||||
bool BIsCybercafe() { return false; }
|
||||
bool BIsVACBanned() { return false; }
|
||||
int GetDLCCount() {
|
||||
spdlog::info("ISteamApps->GetDLCCount called");
|
||||
auto count = dlcs.size();
|
||||
auto content = dlcs;
|
||||
return dlcs.size();
|
||||
@@ -78,6 +80,7 @@ public:
|
||||
bool GetDlcDownloadProgress(AppId_t nAppID, uint64* punBytesDownloaded, uint64* punBytesTotal) { return real_steamApps->GetDlcDownloadProgress(nAppID, punBytesDownloaded, punBytesTotal); }
|
||||
SteamAPICall_t GetFileDetails(const char* pszFileName) { return real_steamApps->GetFileDetails(pszFileName); }
|
||||
int GetLaunchCommandLine(char* pszCommandLine, int cubCommandLine) { return real_steamApps->GetLaunchCommandLine(pszCommandLine, cubCommandLine); }
|
||||
virtual bool BIsTimedTrial( uint32* punSecondsAllowed, uint32* punSecondsPlayed ) { return real_steamApps->BIsTimedTrial(punSecondsAllowed, punSecondsPlayed); }
|
||||
ISteamApps* real_steamApps;
|
||||
};
|
||||
class Hookey_SteamUser_Class : public ISteamUser {
|
||||
@@ -91,11 +94,11 @@ public:
|
||||
CSteamID GetSteamID() {
|
||||
return real_steamUser->GetSteamID();
|
||||
};
|
||||
int InitiateGameConnection( void *pAuthBlob, int cbMaxAuthBlob, CSteamID steamIDGameServer, uint32 unIPServer, uint16 usPortServer, bool bSecure ) {
|
||||
return real_steamUser->InitiateGameConnection(pAuthBlob, cbMaxAuthBlob, steamIDGameServer, unIPServer, usPortServer, bSecure);
|
||||
int InitiateGameConnection_DEPRECATED( void *pAuthBlob, int cbMaxAuthBlob, CSteamID steamIDGameServer, uint32 unIPServer, uint16 usPortServer, bool bSecure ) {
|
||||
return real_steamUser->InitiateGameConnection_DEPRECATED(pAuthBlob, cbMaxAuthBlob, steamIDGameServer, unIPServer, usPortServer, bSecure);
|
||||
};
|
||||
void TerminateGameConnection( uint32 unIPServer, uint16 usPortServer ) {
|
||||
return real_steamUser->TerminateGameConnection(unIPServer, usPortServer);
|
||||
void TerminateGameConnection_DEPRECATED( uint32 unIPServer, uint16 usPortServer ) {
|
||||
return real_steamUser->TerminateGameConnection_DEPRECATED(unIPServer, usPortServer);
|
||||
};
|
||||
void TrackAppUsageEvent( CGameID gameID, int eAppUsageEvent, const char *pchExtraInfo = "" ) {
|
||||
return real_steamUser->TrackAppUsageEvent(gameID, eAppUsageEvent, pchExtraInfo);
|
||||
@@ -134,13 +137,16 @@ public:
|
||||
return real_steamUser->CancelAuthTicket(hAuthTicket);
|
||||
};
|
||||
EUserHasLicenseForAppResult UserHasLicenseForApp( CSteamID steamID, AppId_t appID ) {
|
||||
spdlog::info("ISteamUser->UserHasLicenseForApp {} called", appID);
|
||||
auto reslt = std::find_if(
|
||||
std::begin(dlcs),
|
||||
std::end(dlcs),
|
||||
[&] (const tuple<int, string> a) { return std::get<0>(a) == appID; }) != std::end(dlcs);
|
||||
if (reslt) {
|
||||
spdlog::info("ISteamUser_UserHasLicenseForApp result: owned");
|
||||
return (EUserHasLicenseForAppResult)0;
|
||||
} else {
|
||||
spdlog::info("ISteamUser_UserHasLicenseForApp result: not owned");
|
||||
return (EUserHasLicenseForAppResult)2;
|
||||
}
|
||||
};
|
||||
@@ -179,6 +185,12 @@ public:
|
||||
};
|
||||
SteamAPICall_t GetMarketEligibility() {
|
||||
return real_steamUser->GetMarketEligibility();
|
||||
};
|
||||
virtual SteamAPICall_t GetDurationControl() {
|
||||
return real_steamUser->GetDurationControl();
|
||||
}
|
||||
virtual bool BSetDurationControlOnlineState( EDurationControlOnlineState eNewState ) {
|
||||
return real_steamUser->BSetDurationControlOnlineState(eNewState);
|
||||
};
|
||||
ISteamUser* real_steamUser;
|
||||
};
|
||||
@@ -209,20 +221,27 @@ ISteamUser* Hookey_SteamUser(ISteamUser* real_steamUser) {
|
||||
return Hookey_SteamUser(real_steamUser);
|
||||
}
|
||||
}
|
||||
|
||||
#define STEAMUSER_INTERFACE_VERSION_OLD "SteamUser020"
|
||||
extern "C" void* S_CALLTYPE SteamInternal_FindOrCreateUserInterface(HSteamUser hSteamUser, const char *pszVersion) {
|
||||
void* S_CALLTYPE (*real)(HSteamUser hSteamUser, const char *pszVersion);
|
||||
*(void**)(&real) = dlsym(RTLD_NEXT, "SteamInternal_FindOrCreateUserInterface");
|
||||
|
||||
spdlog::info("SteamInternal_FindOrCreateUserInterface called pszVersion: {}", pszVersion);
|
||||
// Steamapps Interface call is hooked here
|
||||
if (strstr(pszVersion, STEAMAPPS_INTERFACE_VERSION) == pszVersion) {
|
||||
ISteamApps* val = (ISteamApps*)real(hSteamUser, pszVersion);
|
||||
spdlog::info("SteamInternal_FindOrCreateUserInterface hooked ISteamApps");
|
||||
return Hookey_SteamApps(val);
|
||||
}
|
||||
|
||||
// Steamuser interface call is hooked here
|
||||
if (strstr(pszVersion, STEAMUSER_INTERFACE_VERSION) == pszVersion) {
|
||||
ISteamUser* val = (ISteamUser*)real(hSteamUser, pszVersion);
|
||||
spdlog::info("SteamInternal_FindOrCreateUserInterface ISteamUser hook");
|
||||
return Hookey_SteamUser(val);
|
||||
}
|
||||
if (strstr(pszVersion, STEAMUSER_INTERFACE_VERSION_OLD) == pszVersion) {
|
||||
ISteamUser* val = (ISteamUser*)real(hSteamUser, pszVersion);
|
||||
spdlog::info("SteamInternal_FindOrCreateUserInterface ISteamUser(legacy) hook");
|
||||
return Hookey_SteamUser(val);
|
||||
}
|
||||
auto val = real(hSteamUser, pszVersion);
|
||||
@@ -231,6 +250,7 @@ extern "C" void* S_CALLTYPE SteamInternal_FindOrCreateUserInterface(HSteamUser h
|
||||
|
||||
extern "C" EUserHasLicenseForAppResult SteamAPI_ISteamUser_UserHasLicenseForApp(CSteamID steamID, AppId_t appId) {
|
||||
// LOG(TRACE) << "SteamAPI_ISteamUser_UserHasLicenseForApp called!!" << endl;
|
||||
spdlog::info("ISteamUser_UserHasLicenseForApp called");
|
||||
return (EUserHasLicenseForAppResult)0;
|
||||
}
|
||||
|
||||
@@ -252,6 +272,7 @@ extern "C" bool SteamAPI_Init() {
|
||||
if (env != NULL) {
|
||||
creaminipath = env;
|
||||
}
|
||||
spdlog::info("Reading config from {}", creaminipath);
|
||||
mINI::INIFile file(creaminipath);
|
||||
|
||||
// Open ini file
|
||||
@@ -260,18 +281,16 @@ extern "C" bool SteamAPI_Init() {
|
||||
for (pair<string,string> entry : ini["dlc"]) {
|
||||
auto dlctuple = std::make_tuple(stoi(entry.first), entry.second);
|
||||
dlcs.push_back(dlctuple);
|
||||
spdlog::info("Added dlc with id: {0}, name: {1}", entry.first, entry.second);
|
||||
}
|
||||
#if DEBUG
|
||||
LOG(TRACE) << "SteamAPI_Init called" << endl;
|
||||
#endif
|
||||
spdlog::info("SteamAPI_Init called");
|
||||
// finish api call
|
||||
// the spaghetti below this comment is calling the original Init function
|
||||
// can probably be simplified but i'm no c++ expert
|
||||
bool (*real)();
|
||||
*(void**)(&real) = dlsym(RTLD_NEXT, "SteamAPI_Init");
|
||||
auto retval = real();
|
||||
#if DEBUG
|
||||
LOG(TRACE) << "SteamAPI_Init returned" << endl;
|
||||
#endif
|
||||
spdlog::info("SteamAPI_Init returned");
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user