diff --git a/src/common/rpc_register.cc b/src/common/rpc_register.cc index d42c998..ca6c064 100644 --- a/src/common/rpc_register.cc +++ b/src/common/rpc_register.cc @@ -3,18 +3,12 @@ #include #include #include -#include #include #include #include "../utils/utils.hh" #include "rpc_register.hh" -#if defined(__WINE__) - #define WIN32_LEAN_AND_MEAN - #include -#endif - // Add a desktop file and update some mime handlers so that xdg-open does the right thing. void rpc_wine::register_app(const char *app_id, const char *cmd) { const char *home_dir = getenv("HOME"); @@ -27,23 +21,12 @@ void rpc_wine::register_app(const char *app_id, const char *cmd) { } if (cmd == nullptr || !cmd[0]) { - #if defined(__WINE__) - wchar_t game_path[PATH_MAX]; - - unsigned int length = GetModuleFileNameW(nullptr, game_path, sizeof(game_path)); - if (length == 0) - return; - - char *buffer; - wcstombs(buffer, game_path, wcslen(game_path)); - cmd = buffer; - #else - char game_path[PATH_MAX]; - if (readlink("/proc/self/exe", game_path, sizeof(game_path)) <= 0) - return; - - cmd = game_path; - #endif + // FIXME: This will always point to Wine preloader instead of the actual game + char game_path[PATH_MAX]; + if (readlink("/proc/self/exe", game_path, sizeof(game_path)) <= 0) + return; + + cmd = game_path; } const char *desktop_file_format = "[Desktop Entry]\n" diff --git a/src/connections/connection.cc b/src/connections/connection.cc index 875f375..22201f8 100644 --- a/src/connections/connection.cc +++ b/src/connections/connection.cc @@ -20,7 +20,7 @@ rpc_wine::base_connection *rpc_wine::base_connection::create() { void rpc_wine::base_connection::destroy(rpc_wine::base_connection *&connection) { connection->close_connection(); - delete connection; + connection = nullptr; } bool rpc_wine::base_connection::open_connection() { diff --git a/src/connections/rpc_connection.cc b/src/connections/rpc_connection.cc index bb77bcb..de93b9e 100644 --- a/src/connections/rpc_connection.cc +++ b/src/connections/rpc_connection.cc @@ -14,7 +14,7 @@ rpc_wine::connection *rpc_wine::connection::create(const char *app_id) { void rpc_wine::connection::destroy(rpc_wine::connection *&connection) { connection->close_connection(); base_connection::destroy(connection->connection); - delete connection; + connection = nullptr; } void rpc_wine::connection::open_connection() { diff --git a/src/rpc_wine.cc b/src/rpc_wine.cc index c56d6d5..d169ca3 100644 --- a/src/rpc_wine.cc +++ b/src/rpc_wine.cc @@ -94,7 +94,7 @@ void rpcw_initialize(const char *app_id, discord_event_handlers *handlers, int a rpc_connection->on_connect = [](serialization::json_document &message) { rpcw_update_handlers(&queued_handlers); - memset(&connected_user, 0, sizeof(discord_user)); + memset(&connected_user, 0, sizeof(connected_user)); auto data = serialization::get_object_member(&message, "data"); auto user = serialization::get_object_member(data, "user"); @@ -103,6 +103,12 @@ void rpcw_initialize(const char *app_id, discord_event_handlers *handlers, int a const char *username = serialization::get_string_member(user, "username"); if (user_id != nullptr && username != nullptr) { + // This is pretty ghetto + connected_user.user_id = (char*) malloc(64); + connected_user.username = (char*) malloc(32); + connected_user.discrim = (char*) malloc(8); + connected_user.avatar = (char*) malloc(256); + strcpy(connected_user.user_id, user_id); strcpy(connected_user.username, username); diff --git a/src/serialization/allocators.cc b/src/serialization/allocators.cc index 614bd6a..37c91b2 100644 --- a/src/serialization/allocators.cc +++ b/src/serialization/allocators.cc @@ -1,5 +1,3 @@ -#include - #include "allocators.hh" rpc_wine::serialization::linear_allocator::linear_allocator(char *buffer, size_t size) { diff --git a/src/serialization/writers.cc b/src/serialization/writers.cc index 7fb8dd4..d57c229 100644 --- a/src/serialization/writers.cc +++ b/src/serialization/writers.cc @@ -38,7 +38,7 @@ void rpc_wine::serialization::write_optional_string(rpc_wine::serialization::jso } void rpc_wine::serialization::write_nonce(rpc_wine::serialization::json_writer &writer, int nonce) { - write_key(writer, "NONCE"); + write_key(writer, "nonce"); writer.String(std::to_string(nonce).c_str()); } diff --git a/src/serialization/writers.hh b/src/serialization/writers.hh index ef0354c..bc94a97 100644 --- a/src/serialization/writers.hh +++ b/src/serialization/writers.hh @@ -1,8 +1,8 @@ #ifndef RPC_WINE_WRITERS_HH #define RPC_WINE_WRITERS_HH -#include "serialization.hh" #include "../common/discord_defs.hh" +#include "serialization.hh" namespace rpc_wine::serialization {