Add a way to configure which leaderboards are seen by the game.

This commit is contained in:
Mr_Goldberg 2019-08-03 18:55:08 -04:00
parent 7939796680
commit f4ab249f36
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
6 changed files with 92 additions and 9 deletions

View File

@ -72,6 +72,15 @@ The items.json syntax is simple, you SHOULD validate your .json file before tryi
You can use https://steamdb.info/ to list items and attributes they have and put them into your .json. You can use https://steamdb.info/ to list items and attributes they have and put them into your .json.
Keep in mind that some item are not valid to have in your inventory. For example, in PayDay2 all items below item_id 50000 will make your game crash. Keep in mind that some item are not valid to have in your inventory. For example, in PayDay2 all items below item_id 50000 will make your game crash.
Leaderboards:
By default the emulator assumes all leaderboards queried by the game (FindLeaderboard()) exist and creates them with the most common options (sort method descending, display type numeric)
In some games this default behavior doesn't work and so you may need to tweak which leaderboards the game sees.
To do that, you can put a leaderboards.txt file in the steam_settings folder.
An empty leaderboards.txt makes the emu behave as if any leaderboard queried by the game using FindLeaderboard does not exist.
The format is: LEADERBOARD_NAME=sort method=display type
For the sort methods: 0 = none, 1 = ascending, 2 = descending
For the display type: 0 = none, 1 = numeric, 2 = time seconds, 3 = milliseconds
An example can be found in steam_settings.EXAMPLE
Support for CPY steam_api(64).dll cracks: See the build in the experimental folder. Support for CPY steam_api(64).dll cracks: See the build in the experimental folder.

View File

@ -53,6 +53,7 @@ Settings::Settings(CSteamID steam_id, CGameID game_id, std::string name, std::st
this->unlockAllDLCs = true; this->unlockAllDLCs = true;
this->offline = offline; this->offline = offline;
this->create_unknown_leaderboards = true;
} }
CSteamID Settings::get_local_steam_id() CSteamID Settings::get_local_steam_id()
@ -193,3 +194,12 @@ std::string Settings::getAppInstallPath(AppId_t appID)
{ {
return app_paths[appID]; return app_paths[appID];
} }
void Settings::setLeaderboard(std::string leaderboard, enum ELeaderboardSortMethod sort_method, enum ELeaderboardDisplayType display_type)
{
Leaderboard_config leader;
leader.sort_method = sort_method;
leader.display_type = display_type;
leaderboards[leaderboard] = leader;
}

View File

@ -33,6 +33,11 @@ struct Mod_entry {
std::string path; std::string path;
}; };
struct Leaderboard_config {
enum ELeaderboardSortMethod sort_method;
enum ELeaderboardDisplayType display_type;
};
class Settings { class Settings {
CSteamID steam_id; CSteamID steam_id;
CGameID game_id; CGameID game_id;
@ -44,6 +49,8 @@ class Settings {
std::vector<struct DLC_entry> DLCs; std::vector<struct DLC_entry> DLCs;
std::vector<struct Mod_entry> mods; std::vector<struct Mod_entry> mods;
std::map<AppId_t, std::string> app_paths; std::map<AppId_t, std::string> app_paths;
std::map<std::string, Leaderboard_config> leaderboards;
bool create_unknown_leaderboards;
public: public:
#ifdef LOBBY_CONNECT #ifdef LOBBY_CONNECT
@ -78,6 +85,12 @@ public:
Mod_entry getMod(PublishedFileId_t id); Mod_entry getMod(PublishedFileId_t id);
bool isModInstalled(PublishedFileId_t id); bool isModInstalled(PublishedFileId_t id);
std::set<PublishedFileId_t> modSet(); std::set<PublishedFileId_t> modSet();
//leaderboards
void setLeaderboard(std::string leaderboard, enum ELeaderboardSortMethod sort_method, enum ELeaderboardDisplayType display_type);
std::map<std::string, Leaderboard_config> getLeaderboards() { return leaderboards; }
void setCreateUnknownLeaderboards(bool enable) {create_unknown_leaderboards = enable;}
bool createUnknownLeaderboards() { return create_unknown_leaderboards; }
}; };
#endif #endif

View File

@ -278,6 +278,47 @@ Steam_Client::Steam_Client()
} }
} }
{
std::string dlc_config_path = Local_Storage::get_game_settings_path() + "leaderboards.txt";
std::ifstream input( dlc_config_path );
if (input.is_open()) {
settings_client->setCreateUnknownLeaderboards(false);
settings_server->setCreateUnknownLeaderboards(false);
for( std::string line; getline( input, line ); ) {
if (!line.empty() && line[line.length()-1] == '\n') {
line.erase(line.length()-1);
}
if (!line.empty() && line[line.length()-1] == '\r') {
line.erase(line.length()-1);
}
std::string leaderboard;
unsigned int sort_method = 0;
unsigned int display_type = 0;
std::size_t deliminator = line.find("=");
if (deliminator != 0 && deliminator != std::string::npos && deliminator != line.size()) {
leaderboard = line.substr(0, deliminator);
std::size_t deliminator2 = line.find("=", deliminator + 1);
if (deliminator2 != std::string::npos && deliminator2 != line.size()) {
sort_method = stol(line.substr(deliminator + 1, deliminator2));
display_type = stol(line.substr(deliminator2 + 1));
}
}
if (leaderboard.size() && sort_method <= k_ELeaderboardSortMethodDescending && display_type <= k_ELeaderboardDisplayTypeTimeMilliSeconds) {
PRINT_DEBUG("Adding leaderboard: %s|%u|%u\n", leaderboard.c_str(), sort_method, display_type);
settings_client->setLeaderboard(leaderboard, (ELeaderboardSortMethod)sort_method, (ELeaderboardDisplayType)display_type);
settings_server->setLeaderboard(leaderboard, (ELeaderboardSortMethod)sort_method, (ELeaderboardDisplayType)display_type);
} else {
PRINT_DEBUG("Error adding leaderboard for: %s, are sort method %u or display type %u valid?\n", leaderboard.c_str(), sort_method, display_type);
}
}
}
}
{ {
std::string mod_path = Local_Storage::get_game_settings_path() + "mods"; std::string mod_path = Local_Storage::get_game_settings_path() + "mods";
std::vector<std::string> paths = Local_Storage::get_filenames_path(mod_path); std::vector<std::string> paths = Local_Storage::get_filenames_path(mod_path);

View File

@ -109,6 +109,7 @@ bool GetStat( const char *pchName, float *pData )
bool SetStat( const char *pchName, int32 nData ) bool SetStat( const char *pchName, int32 nData )
{ {
PRINT_DEBUG("SetStat int32 %s\n", pchName); PRINT_DEBUG("SetStat int32 %s\n", pchName);
if (!pchName) return false;
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
return local_storage->store_data(STATS_STORAGE_FOLDER, pchName, (char* )&nData, sizeof(nData)) == sizeof(nData); return local_storage->store_data(STATS_STORAGE_FOLDER, pchName, (char* )&nData, sizeof(nData)) == sizeof(nData);
@ -117,6 +118,7 @@ bool SetStat( const char *pchName, int32 nData )
bool SetStat( const char *pchName, float fData ) bool SetStat( const char *pchName, float fData )
{ {
PRINT_DEBUG("SetStat float %s\n", pchName); PRINT_DEBUG("SetStat float %s\n", pchName);
if (!pchName) return false;
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
return local_storage->store_data(STATS_STORAGE_FOLDER, pchName, (char* )&fData, sizeof(fData)) == sizeof(fData); return local_storage->store_data(STATS_STORAGE_FOLDER, pchName, (char* )&fData, sizeof(fData)) == sizeof(fData);
@ -368,14 +370,19 @@ SteamAPICall_t FindLeaderboard( const char *pchLeaderboardName )
{ {
PRINT_DEBUG("FindLeaderboard %s\n", pchLeaderboardName); PRINT_DEBUG("FindLeaderboard %s\n", pchLeaderboardName);
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
//TODO: figure out a way to get real leaderboard info
/* auto settings_Leaderboards = settings->getLeaderboards();
if (settings_Leaderboards.count(pchLeaderboardName)) {
auto config = settings_Leaderboards[pchLeaderboardName];
return FindOrCreateLeaderboard(pchLeaderboardName, config.sort_method, config.display_type);
} else if (settings->createUnknownLeaderboards()) {
return FindOrCreateLeaderboard(pchLeaderboardName, k_ELeaderboardSortMethodDescending, k_ELeaderboardDisplayTypeNumeric);
} else {
LeaderboardFindResult_t data; LeaderboardFindResult_t data;
data.m_hSteamLeaderboard = find_leaderboard(pchLeaderboardName);; data.m_hSteamLeaderboard = find_leaderboard(pchLeaderboardName);;
data.m_bLeaderboardFound = !!data.m_hSteamLeaderboard; data.m_bLeaderboardFound = !!data.m_hSteamLeaderboard;
return callback_results->addCallResult(data.k_iCallback, &data, sizeof(data)); return callback_results->addCallResult(data.k_iCallback, &data, sizeof(data));
*/ }
return FindOrCreateLeaderboard(pchLeaderboardName, k_ELeaderboardSortMethodDescending, k_ELeaderboardDisplayTypeNumeric);
} }
@ -446,7 +453,7 @@ STEAM_METHOD_DESC(Downloads leaderboard entries for an arbitrary set of users -
SteamAPICall_t DownloadLeaderboardEntriesForUsers( SteamLeaderboard_t hSteamLeaderboard, SteamAPICall_t DownloadLeaderboardEntriesForUsers( SteamLeaderboard_t hSteamLeaderboard,
STEAM_ARRAY_COUNT_D(cUsers, Array of users to retrieve) CSteamID *prgUsers, int cUsers ) STEAM_ARRAY_COUNT_D(cUsers, Array of users to retrieve) CSteamID *prgUsers, int cUsers )
{ {
PRINT_DEBUG("DownloadLeaderboardEntriesForUsers\n"); PRINT_DEBUG("DownloadLeaderboardEntriesForUsers %i %llu\n", cUsers, cUsers > 0 ? prgUsers[0].ConvertToUint64() : 0);
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
LeaderboardScoresDownloaded_t data; LeaderboardScoresDownloaded_t data;
data.m_hSteamLeaderboard = hSteamLeaderboard; data.m_hSteamLeaderboard = hSteamLeaderboard;

View File

@ -0,0 +1,3 @@
LEADERBOARD1=0=0
LEADERBOARDX=1=1
LEADERBOARDTEST=0=0