Вопрос Discord rpc

Начинающий
Статус
Оффлайн
Регистрация
15 Окт 2021
Сообщения
46
Реакции[?]
5
Поинты[?]
2K
I am trying to make a discord RPC that shows live matches like In: Main Menu -> connecting -> then the map name but its being stuck on (In: main menu )
Plz send the help to my Discord thx cl_show_team_equipment


DiscordRpc.cpp:
#include "discord_rpc_init.h"
#include <ctime>
#include "../Configuration/Config.h"
#include "utils/csgo.hpp"
#include "..\sdk\interfaces\IVEngineClient.hpp"
#include "..\includes.hpp"

void Discord::Initialize()
{
    DiscordEventHandlers Handle;
    memset(&Handle, 0, sizeof(Handle));
    Discord_Initialize("", &Handle, 1, NULL);
}

void Discord::Update()
{
    DiscordRichPresence discordPresence;
    memset(&discordPresence, 0, sizeof(discordPresence));
    static auto elapsed = std::time(nullptr);

    std::string current_status = "in: main menu";
    if (!m_engine()->IsInGame() && m_engine()->IsConnected()) {
        current_status = "loading into game...";
    }
    else if (m_engine()->IsInGame()) {
        current_status = "playing on: ";
        current_status += m_engine()->GetLevelNameShort();
    }

    discordPresence.details = "";
    discordPresence.state = "";
    discordPresence.state = current_status.c_str();
    //discordPresence.startTimestamp = elapsed;
    discordPresence.largeImageKey = "";
    discordPresence.smallImageKey = "";
    discordPresence.button1_label = "";
    discordPresence.button1_url = "";
    discordPresence.button2_label = "";
    discordPresence.button2_url = "";
    Discord_UpdatePresence(&discordPresence);

}
 
Начинающий
Статус
Оффлайн
Регистрация
5 Авг 2021
Сообщения
71
Реакции[?]
12
Поинты[?]
11K
blud
I am trying to make a discord RPC that shows live matches like In: Main Menu -> connecting -> then the map name but its being stuck on (In: main menu )
Plz send the help to my Discord thx cl_show_team_equipment


DiscordRpc.cpp:
#include "discord_rpc_init.h"
#include <ctime>
#include "../Configuration/Config.h"
#include "utils/csgo.hpp"
#include "..\sdk\interfaces\IVEngineClient.hpp"
#include "..\includes.hpp"

void Discord::Initialize()
{
    DiscordEventHandlers Handle;
    memset(&Handle, 0, sizeof(Handle));
    Discord_Initialize("", &Handle, 1, NULL);
}

void Discord::Update()
{
    DiscordRichPresence discordPresence;
    memset(&discordPresence, 0, sizeof(discordPresence));
    static auto elapsed = std::time(nullptr);

    std::string current_status = "in: main menu";
    if (!m_engine()->IsInGame() && m_engine()->IsConnected()) {
        current_status = "loading into game...";
    }
    else if (m_engine()->IsInGame()) {
        current_status = "playing on: ";
        current_status += m_engine()->GetLevelNameShort();
    }

    discordPresence.details = "";
    discordPresence.state = "";
    discordPresence.state = current_status.c_str();
    //discordPresence.startTimestamp = elapsed;
    discordPresence.largeImageKey = "";
    discordPresence.smallImageKey = "";
    discordPresence.button1_label = "";
    discordPresence.button1_url = "";
    discordPresence.button2_label = "";
    discordPresence.button2_url = "";
    Discord_UpdatePresence(&discordPresence);

}
on a more serious note
RPC.cpp:
#include "rpc.h"


#include "..\misc\misc.h"
#include "..\misc\logs.h"

#include <cstring>
#include "../../discord includes/discord_register.h"
#include "../../discord includes/discord_rpc.h"
#include <mutex>

static float last_presence_update = 0.0f;
static int inject_timestamp = -1;
static bool is_initialized = false;

void discord_rpc::update() {
    if (inject_timestamp == -1)
        inject_timestamp = std::time(nullptr);

    if (is_initialized && !g_cfg.menu.discord) {
        Discord_ClearPresence();
        Discord_Shutdown();

        is_initialized = false;
        last_presence_update = 0.0f;
    }
    else if (!is_initialized && g_cfg.menu.discord) {
        DiscordEventHandlers handlers;

        memset(&handlers, 0, sizeof(handlers));

        // [USER=891005]@Todo[/USER]: support joining others' games
        // handlers.joinGame = handleDiscordJoinGame;
        // handlers.joinRequest = handleDiscordJoinRequest;

        Discord_Initialize("no lol", &handlers, true, nullptr);

        is_initialized = true;
        last_presence_update = 0.0f;
    }

    if (!is_initialized || m_globals()->m_realtime - last_presence_update < 15.0f)
        return;

    last_presence_update = m_globals()->m_realtime;

    DiscordRichPresence presence;

    memset(&presence, 0, sizeof(presence));

    presence.largeImageKey = "1";


    if (!m_engine()->IsInGame()) {
        presence.state = "In main menu";
        presence.details = std::string("Username: " + g_cfg.user.user_name).c_str();
    }
    else {
        // GetLevelName
        auto map_name = m_engine()->GetLevelNameShort();
        char presence_status_buffer[64];

        memset(presence_status_buffer, 0, sizeof(presence_status_buffer));
        discord_rpc::update();
        sprintf_s(presence_status_buffer, "In game: %s", map_name);
        presence.state = presence_status_buffer;
        presence.details = std::string("Username: " + g_cfg.user.user_name).c_str();
    }


    // presence.state = interfaces::engine_client->is_in_game() ? ("In game") : ("In main menu");
    presence.startTimestamp = inject_timestamp;
    presence.instance = 1;

    Discord_UpdatePresence(&presence);
}
 
Сверху Снизу