Compare commits

..

4 Commits

Author SHA1 Message Date
Mr_Goldberg 19015c097c
Hopefully this fixes the SteamAPI_ISteamGameServer_GetPublicIP function 2021-04-09 14:53:20 -04:00
Mr_Goldberg c48526d49a
Fix possible crash. 2021-04-09 14:52:45 -04:00
Mr_Goldberg dc95076faa
Achievement names are now treated as case insensitive.
This should fix achievements in a few games.
2021-04-02 23:42:22 -04:00
Mr_Goldberg 8a5e49251c
Remove hex symbols in overlay chat window. 2021-04-02 23:40:54 -04:00
8 changed files with 68 additions and 43 deletions

View File

@ -136,7 +136,7 @@ Steam_Client *get_steam_clientserver_old()
static bool steamclient_has_ipv6_functions_flag; static bool steamclient_has_ipv6_functions_flag;
bool steamclient_has_ipv6_functions() bool steamclient_has_ipv6_functions()
{ {
return steamclient_has_ipv6_functions_flag; return steamclient_has_ipv6_functions_flag || get_steam_client()->gameserver_has_ipv6_functions;
} }
static void *create_client_interface(const char *ver) static void *create_client_interface(const char *ver)

View File

@ -5843,13 +5843,14 @@ STEAMAPI_API SteamAPICall_t SteamAPI_ISteamGameServer_GetServerReputation( IStea
return self->GetServerReputation(); return self->GetServerReputation();
} }
STEAMAPI_API uint32 SteamAPI_ISteamGameServer_GetPublicIP( intptr_t instancePtr, void *instancePtr_possible ) STEAMAPI_API void *SteamAPI_ISteamGameServer_GetPublicIP( intptr_t instancePtr, void *instancePtr_possible )
{ {
//TODO: check if this actually works (ret value changed from uint32 to struct) //abuse call convention rules to get this working.
if (steamclient_has_ipv6_functions()) { if (steamclient_has_ipv6_functions()) {
return ((ISteamGameServer012 *)instancePtr_possible)->GetPublicIP_old(); get_steam_client()->steam_gameserver->GetPublicIP_fix((SteamIPAddress_t *)instancePtr);
return (void *)instancePtr;
} else { } else {
return ((ISteamGameServer012 *)instancePtr)->GetPublicIP_old(); return (void *)((ISteamGameServer012 *)instancePtr)->GetPublicIP_old();
} }
} }

View File

@ -109,6 +109,8 @@ Steam_Client::Steam_Client()
steam_gameserver_game_coordinator = new Steam_Game_Coordinator(settings_server, network, callback_results_server, callbacks_server, run_every_runcb); steam_gameserver_game_coordinator = new Steam_Game_Coordinator(settings_server, network, callback_results_server, callbacks_server, run_every_runcb);
steam_masterserver_updater = new Steam_Masterserver_Updater(settings_server, network, callback_results_server, callbacks_server, run_every_runcb); steam_masterserver_updater = new Steam_Masterserver_Updater(settings_server, network, callback_results_server, callbacks_server, run_every_runcb);
gameserver_has_ipv6_functions = false;
last_cb_run = 0; last_cb_run = 0;
PRINT_DEBUG("client init end\n"); PRINT_DEBUG("client init end\n");
} }
@ -303,8 +305,10 @@ ISteamGameServer *Steam_Client::GetISteamGameServer( HSteamUser hSteamUser, HSte
} else if (strcmp(pchVersion, "SteamGameServer012") == 0) { } else if (strcmp(pchVersion, "SteamGameServer012") == 0) {
return (ISteamGameServer *)(void *)(ISteamGameServer012 *)steam_gameserver; return (ISteamGameServer *)(void *)(ISteamGameServer012 *)steam_gameserver;
} else if (strcmp(pchVersion, STEAMGAMESERVER_INTERFACE_VERSION) == 0) { } else if (strcmp(pchVersion, STEAMGAMESERVER_INTERFACE_VERSION) == 0) {
gameserver_has_ipv6_functions = true;
return (ISteamGameServer *)(void *)(ISteamGameServer *)steam_gameserver; return (ISteamGameServer *)(void *)(ISteamGameServer *)steam_gameserver;
} else { } else {
gameserver_has_ipv6_functions = true;
return (ISteamGameServer *)(void *)(ISteamGameServer *)steam_gameserver; return (ISteamGameServer *)(void *)(ISteamGameServer *)steam_gameserver;
} }

View File

@ -139,6 +139,8 @@ public:
unsigned steam_pipe_counter = 1; unsigned steam_pipe_counter = 1;
std::map<HSteamPipe, enum Steam_Pipe> steam_pipes; std::map<HSteamPipe, enum Steam_Pipe> steam_pipes;
bool gameserver_has_ipv6_functions;
Steam_Client(); Steam_Client();
~Steam_Client(); ~Steam_Client();
// Creates a communication pipe to the Steam client. // Creates a communication pipe to the Steam client.

View File

@ -559,6 +559,12 @@ SteamIPAddress_t Steam_GameServer::GetPublicIP()
return ip; return ip;
} }
void Steam_GameServer::GetPublicIP_fix(SteamIPAddress_t *out)
{
PRINT_DEBUG("GetPublicIP_fix\n");
if (out) *out = GetPublicIP();
}
// These are in GameSocketShare mode, where instead of ISteamGameServer creating its own // These are in GameSocketShare mode, where instead of ISteamGameServer creating its own
// socket to talk to the master server on, it lets the game use its socket to forward messages // socket to talk to the master server on, it lets the game use its socket to forward messages
// back and forth. This prevents us from requiring server ops to open up yet another port // back and forth. This prevents us from requiring server ops to open up yet another port

View File

@ -278,6 +278,7 @@ public:
// connect to // connect to
uint32 GetPublicIP_old(); uint32 GetPublicIP_old();
SteamIPAddress_t GetPublicIP(); SteamIPAddress_t GetPublicIP();
void GetPublicIP_fix(SteamIPAddress_t *out);
// These are in GameSocketShare mode, where instead of ISteamGameServer creating its own // These are in GameSocketShare mode, where instead of ISteamGameServer creating its own
// socket to talk to the master server on, it lets the game use its socket to forward messages // socket to talk to the master server on, it lets the game use its socket to forward messages

View File

@ -66,6 +66,17 @@ unsigned int find_leaderboard(std::string name)
return 0; return 0;
} }
nlohmann::detail::iter_impl<nlohmann::json> defined_achievements_find(std::string key)
{
return std::find_if(defined_achievements.begin(), defined_achievements.end(), [key](nlohmann::json& item) {
std::string name = static_cast<std::string const&>(item["name"]);
return key.size() == name.size() && std::equal(name.begin(), name.end(), key.begin(),
[](char a, char b) {
return tolower(a) == tolower(b);
});
});
}
void load_achievements_db() void load_achievements_db()
{ {
std::string file_path = Local_Storage::get_game_settings_path() + achievements_user_file; std::string file_path = Local_Storage::get_game_settings_path() + achievements_user_file;
@ -227,10 +238,11 @@ bool GetAchievement( const char *pchName, bool *pbAchieved )
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
try { try {
auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName]( nlohmann::json &item ) { auto it = defined_achievements_find(pchName);
return item["name"].get<std::string>() == pchName; if (it == defined_achievements.end()) return false;
}); std::string pch_name = it->value("name", std::string());
auto ach = user_achievements.find(pchName);
auto ach = user_achievements.find(pch_name);
if (it != defined_achievements.end() && ach != user_achievements.end()) { if (it != defined_achievements.end() && ach != user_achievements.end()) {
if(pbAchieved != nullptr) *pbAchieved = (*ach)["earned"]; if(pbAchieved != nullptr) *pbAchieved = (*ach)["earned"];
return true; return true;
@ -249,13 +261,14 @@ bool SetAchievement( const char *pchName )
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
try { try {
auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) { auto it = defined_achievements_find(pchName);
return item["name"].get<std::string>() == pchName; if (it == defined_achievements.end()) return false;
}); std::string pch_name = it->value("name", std::string());
if (it != defined_achievements.end()) { if (it != defined_achievements.end()) {
if (user_achievements.find(pchName) == user_achievements.end() || user_achievements[pchName].value("earned", false) == false) { if (user_achievements.find(pch_name) == user_achievements.end() || user_achievements[pch_name].value("earned", false) == false) {
user_achievements[pchName]["earned"] = true; user_achievements[pch_name]["earned"] = true;
user_achievements[pchName]["earned_time"] = std::chrono::duration_cast<std::chrono::duration<uint32>>(std::chrono::system_clock::now().time_since_epoch()).count(); user_achievements[pch_name]["earned_time"] = std::chrono::duration_cast<std::chrono::duration<uint32>>(std::chrono::system_clock::now().time_since_epoch()).count();
#ifdef EMU_OVERLAY #ifdef EMU_OVERLAY
overlay->AddAchievementNotification(it.value()); overlay->AddAchievementNotification(it.value());
#endif #endif
@ -276,12 +289,13 @@ bool ClearAchievement( const char *pchName )
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
try { try {
auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) { auto it = defined_achievements_find(pchName);
return static_cast<std::string const&>(item["name"]) == pchName; if (it == defined_achievements.end()) return false;
}); std::string pch_name = it->value("name", std::string());
if (it != defined_achievements.end()) { if (it != defined_achievements.end()) {
user_achievements[pchName]["earned"] = false; user_achievements[pch_name]["earned"] = false;
user_achievements[pchName]["earned_time"] = static_cast<uint32>(0); user_achievements[pch_name]["earned_time"] = static_cast<uint32>(0);
save_achievements(); save_achievements();
return true; return true;
} }
@ -301,10 +315,11 @@ bool GetAchievementAndUnlockTime( const char *pchName, bool *pbAchieved, uint32
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
try { try {
auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) { auto it = defined_achievements_find(pchName);
return static_cast<std::string const&>(item["name"]) == pchName; if (it == defined_achievements.end()) return false;
}); std::string pch_name = it->value("name", std::string());
auto ach = user_achievements.find(pchName);
auto ach = user_achievements.find(pch_name);
if (it != defined_achievements.end() && ach != user_achievements.end()) { if (it != defined_achievements.end() && ach != user_achievements.end()) {
if(pbAchieved != nullptr) *pbAchieved = (*ach)["earned"]; if(pbAchieved != nullptr) *pbAchieved = (*ach)["earned"];
if(punUnlockTime != nullptr) *punUnlockTime = (*ach)["earned_time"]; if(punUnlockTime != nullptr) *punUnlockTime = (*ach)["earned_time"];
@ -367,9 +382,7 @@ const char * GetAchievementDisplayAttribute( const char *pchName, const char *pc
if (strcmp (pchKey, "name") == 0) { if (strcmp (pchKey, "name") == 0) {
try { try {
auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) { auto it = defined_achievements_find(pchName);
return static_cast<std::string const&>(item["name"]) == pchName;
});
if (it != defined_achievements.end()) { if (it != defined_achievements.end()) {
return it.value()["displayName"].get_ptr<std::string*>()->c_str(); return it.value()["displayName"].get_ptr<std::string*>()->c_str();
} }
@ -378,9 +391,7 @@ const char * GetAchievementDisplayAttribute( const char *pchName, const char *pc
if (strcmp (pchKey, "desc") == 0) { if (strcmp (pchKey, "desc") == 0) {
try { try {
auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) { auto it = defined_achievements_find(pchName);
return static_cast<std::string const&>(item["name"]) == pchName;
});
if (it != defined_achievements.end()) { if (it != defined_achievements.end()) {
return it.value()["description"].get_ptr<std::string*>()->c_str(); return it.value()["description"].get_ptr<std::string*>()->c_str();
} }
@ -389,9 +400,7 @@ const char * GetAchievementDisplayAttribute( const char *pchName, const char *pc
if (strcmp (pchKey, "hidden") == 0) { if (strcmp (pchKey, "hidden") == 0) {
try { try {
auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) { auto it = defined_achievements_find(pchName);
return static_cast<std::string const&>(item["name"]) == pchName;
});
if (it != defined_achievements.end()) { if (it != defined_achievements.end()) {
return it.value()["hidden"].get_ptr<std::string*>()->c_str(); return it.value()["hidden"].get_ptr<std::string*>()->c_str();
} }
@ -406,15 +415,17 @@ const char * GetAchievementDisplayAttribute( const char *pchName, const char *pc
// Calling this w/ N out of N progress will NOT set the achievement, the game must still do that. // Calling this w/ N out of N progress will NOT set the achievement, the game must still do that.
bool IndicateAchievementProgress( const char *pchName, uint32 nCurProgress, uint32 nMaxProgress ) bool IndicateAchievementProgress( const char *pchName, uint32 nCurProgress, uint32 nMaxProgress )
{ {
PRINT_DEBUG("IndicateAchievementProgress\n"); PRINT_DEBUG("IndicateAchievementProgress %s\n", pchName);
if (pchName == nullptr) return false; if (pchName == nullptr) return false;
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
try { try {
auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) { auto it = defined_achievements_find(pchName);
return static_cast<std::string const&>(item["name"]) == pchName; if (it == defined_achievements.end()) return false;
});
auto ach = user_achievements.find(pchName); std::string pch_name = it->value("name", std::string());
auto ach = user_achievements.find(pch_name);
if (it != defined_achievements.end()) { if (it != defined_achievements.end()) {
bool achieved = false; bool achieved = false;
if ( ach != user_achievements.end()) { if ( ach != user_achievements.end()) {
@ -424,14 +435,14 @@ bool IndicateAchievementProgress( const char *pchName, uint32 nCurProgress, uint
UserAchievementStored_t data = {}; UserAchievementStored_t data = {};
data.m_nGameID = settings->get_local_game_id().ToUint64(); data.m_nGameID = settings->get_local_game_id().ToUint64();
data.m_bGroupAchievement = false; data.m_bGroupAchievement = false;
strncpy(data.m_rgchAchievementName, pchName, k_cchStatNameMax); strncpy(data.m_rgchAchievementName, pch_name.c_str(), k_cchStatNameMax);
if (achieved) { if (achieved) {
data.m_nCurProgress = 0; data.m_nCurProgress = 0;
data.m_nMaxProgress = 0; data.m_nMaxProgress = 0;
} else { } else {
user_achievements[pchName]["progress"] = nCurProgress; user_achievements[pch_name]["progress"] = nCurProgress;
user_achievements[pchName]["max_progress"] = nMaxProgress; user_achievements[pch_name]["max_progress"] = nMaxProgress;
data.m_nCurProgress = nCurProgress; data.m_nCurProgress = nCurProgress;
data.m_nMaxProgress = nMaxProgress; data.m_nMaxProgress = nMaxProgress;
} }

View File

@ -698,7 +698,7 @@ void Steam_Overlay::Callback(Common_Message *msg)
{ {
Steam_Messages const& steam_message = msg->steam_messages(); Steam_Messages const& steam_message = msg->steam_messages();
// Change color to cyan for friend // Change color to cyan for friend
friend_info->second.chat_history.append("\x1""00FFFFFF", 9).append(steam_message.message()).append("\n", 1); friend_info->second.chat_history.append(steam_message.message()).append("\n", 1);
if (!(friend_info->second.window_state & window_state_show)) if (!(friend_info->second.window_state & window_state_show))
{ {
friend_info->second.window_state |= window_state_need_attention; friend_info->second.window_state |= window_state_need_attention;
@ -758,7 +758,7 @@ void Steam_Overlay::RunCallbacks()
msg.set_dest_id(friend_id); msg.set_dest_id(friend_id);
network->sendTo(&msg, true); network->sendTo(&msg, true);
friend_info->second.chat_history.append("\x1""00FF00FF", 9).append(input).append("\n", 1); friend_info->second.chat_history.append(input).append("\n", 1);
} }
*input = 0; // Reset the input field *input = 0; // Reset the input field
friend_info->second.window_state &= ~window_state_send_message; friend_info->second.window_state &= ~window_state_send_message;