From 65d25d92b0309ad39ef3c24aed77e4e4bce5bd4f Mon Sep 17 00:00:00 2001 From: PaulCombal Date: Mon, 17 Feb 2020 19:57:24 +0100 Subject: [PATCH] Printing with --ls works --- .vscode/launch.json | 2 +- src/cli/cli_funcs.cpp | 31 ++++++++++++++++++++++++------- src/common/functions.h | 9 ++++++++- src/json/yajlHelpers.cpp | 2 +- src/sockets/MyGameSocket.cpp | 3 +++ src/sockets/MyServerSocket.cpp | 2 ++ 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 28c66c0..d6568c4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/bin/samrewritten", - "args": ["206690", "--ls"], + "args": ["730", "--ls"], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [ diff --git a/src/cli/cli_funcs.cpp b/src/cli/cli_funcs.cpp index 4eb88e9..1130d60 100644 --- a/src/cli/cli_funcs.cpp +++ b/src/cli/cli_funcs.cpp @@ -2,6 +2,7 @@ #include "../controller/MySteam.h" #include "../globals.h" #include "../common/cxxopts.hpp" +#include "../common/functions.h" #include #include @@ -108,12 +109,6 @@ bool go_cli_mode(int argc, char* argv[]) { auto achievements = g_steam->get_achievements(); auto stats = g_steam->get_stats(); g_steam->quit_game(); - - for (auto stat : stats ) - { - std::cout << stat.id << std::endl; - } - if (result.count("sort") > 0) { @@ -128,7 +123,7 @@ bool go_cli_mode(int argc, char* argv[]) { // https://github.com/haarcuba/cpp-text-table -> worth? nah but best I've found - std::cout << "API Name \t\tName \t\tDescription \t\tUnlock rate \t\tUnlocked" << std::endl; + std::cout << "API Name \t\tName \t\tDescription \t\tUnlock rate \t\tUnlocked\n"; std::cout << "--------------------------------------------------------------" << std::endl; for ( Achievement_t& it : achievements ) { @@ -139,6 +134,28 @@ bool go_cli_mode(int argc, char* argv[]) { << it.global_achieved_rate << "% \t" << (it.achieved ? "✔️" : "❌") << std::endl; } + + std::cout << "\n"; + + if ( stats.size() == 0 ) + { + std::cout << "No stats found for this app.." << std::endl; + } + else + { + std::cout << "\nSTATS\n"; + std::cout << "API Name \t\tValue \t\t Increment Only\n"; + std::cout << "----------------------------------------" << std::endl; + for (auto stat : stats ) + { + std::cout + << stat.id << " \t" + << GET_STAT_VALUE(stat) << " \t" + << (stat.incrementonly ? "Yes" : "No") + << std::endl; + } + } + } if (result.count("unlock") > 0) diff --git a/src/common/functions.h b/src/common/functions.h index a922132..48c5f88 100644 --- a/src/common/functions.h +++ b/src/common/functions.h @@ -4,6 +4,13 @@ #include "../globals.h" #include "../../steam/steam_api.h" +/** + * Stats hold a value of type any, but can be either int or float. + * This macro casts the value to the right type. + * The cast types are the ones used by YAJL + */ +#define GET_STAT_VALUE(stat) (stat.type == UserStatType::Integer ? std::any_cast(stat.value) : std::any_cast(stat.value)) + /** * Wrapper for fork() */ @@ -64,4 +71,4 @@ void escape_html(std::string& data); * Show a regular dialog box. Return value is ignored for now, * but feel free to add functionnlitie to this */ -int zenity(const std::string text = "An internal error occurred, please open a Github issue with the console output to get it fixed!", const std::string type = "--error --no-wrap"); +int zenity(const std::string text = "An internal error occurred, please open a Github issue with the console output to get it fixed!", const std::string type = "--error --no-wrap"); \ No newline at end of file diff --git a/src/json/yajlHelpers.cpp b/src/json/yajlHelpers.cpp index 1bffafe..fc21e8e 100644 --- a/src/json/yajlHelpers.cpp +++ b/src/json/yajlHelpers.cpp @@ -121,7 +121,7 @@ encode_stat(yajl_gen handle, StatValue_t stat) { } else if ( stat.type == UserStatType::Float ) { - int value = std::any_cast(stat.value); + float value = std::any_cast(stat.value); yajl_gen_string_wrap(handle, STAT_VALUE_STR); if (yajl_gen_double(handle, value) != yajl_gen_status_ok) { diff --git a/src/sockets/MyGameSocket.cpp b/src/sockets/MyGameSocket.cpp index f4b70f8..4a715a0 100644 --- a/src/sockets/MyGameSocket.cpp +++ b/src/sockets/MyGameSocket.cpp @@ -255,7 +255,10 @@ MyGameSocket::OnGlobalStatsReceived(GlobalStatsReceived_t *callback, bool bIOFai std::cerr << "GlobalStatsReceived_t failed! Enum: " << callback->m_eResult << std::endl; } + #ifdef DEBUG_CERR std::cout << "Got stats, maybe I can do cool stuff with them, gotta check." << std::endl; + #endif + m_global_callback_received = true; } diff --git a/src/sockets/MyServerSocket.cpp b/src/sockets/MyServerSocket.cpp index 4e96697..3b28f3f 100644 --- a/src/sockets/MyServerSocket.cpp +++ b/src/sockets/MyServerSocket.cpp @@ -66,7 +66,9 @@ MyServerSocket::run_server() if (quit) { + #ifdef DEBUG_CERR std::cout << "Shutting down server safely." << std:: endl; + #endif // destruction of this object will take care of shutdown break; }