Skip to content

Commit

Permalink
Add some more default states (walking, driving, dead)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lpsd committed Oct 12, 2023
1 parent 488e7a1 commit fc9a35b
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Client/core/CSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3468,7 +3468,7 @@ void CSettings::SaveData()
discord->SetPresenceDetails(serverName.c_str(), false);
}

discord->SetPresenceState(state, false);
discord->SetPresenceState(state.c_str(), false);
}
}

Expand Down
42 changes: 42 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ CClientGame::CClientGame(bool bLocalPlay) : m_ServerInfo(new CServerInfo())
m_fGameSpeed = 1.0f;
m_lMoney = 0;
m_dwWanted = 0;
m_timeLastDiscordStateUpdate = 0;
m_lastWeaponSlot = WEAPONSLOT_MAX; // last stored weapon slot, for weapon slot syncing to server (sets to invalid value)
ResetAmmoInClip();

Expand Down Expand Up @@ -959,6 +960,38 @@ void CClientGame::DoPulsePostFrame()
m_LastClearTime.Reset();
}

// Check if we need to update the Discord Rich Presence state
if (time(nullptr) > m_timeLastDiscordStateUpdate + m_timeDiscordUpdateRate)
{
auto discord = g_pCore->GetDiscord();

if (discord && discord->IsDiscordRPCEnabled())
{
auto pLocalPlayer = g_pClientGame->GetLocalPlayer();

if (pLocalPlayer)
{
auto pVehicle = pLocalPlayer->GetOccupiedVehicle();

CVector position;
SString zoneName;

pLocalPlayer->GetPosition(position);
CStaticFunctionDefinitions::GetZoneName(position, zoneName, true);

if (pVehicle)
{
eClientVehicleType vehicleType = CClientVehicleManager::GetVehicleType(pVehicle->GetModel());
discord->SetPresenceState(SString("%s %s", g_vehicleTypePrefixes.at(vehicleType).c_str(), zoneName.c_str()), false);
}
else
discord->SetPresenceState(SString("Walking around %s", zoneName.c_str()), false);

m_timeLastDiscordStateUpdate = time(nullptr);
}
}
}

CClientPerfStatManager::GetSingleton()->DoPulse();
}

Expand Down Expand Up @@ -5554,6 +5587,15 @@ void CClientGame::DoWastedCheck(ElementID damagerID, unsigned char ucWeapon, uns
// Send the packet
g_pNet->SendPacket(PACKET_ID_PLAYER_WASTED, pBitStream, PACKET_PRIORITY_HIGH, PACKET_RELIABILITY_RELIABLE_ORDERED);
g_pNet->DeallocateNetBitStream(pBitStream);

auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
std::vector<std::string> states{"In a ditch", "En-route to hospital", "Meeting their maker", "Regretting their decisions", "Wasted"};
std::string state = states[rand() % states.size()];
discord->SetPresenceState(state.c_str(), false);
}

}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,9 @@ class CClientGame
AnimAssociations_type m_mapOfCustomAnimationAssociations;
// Key is the task and value is the CClientPed*
RunNamedAnimTask_type m_mapOfRunNamedAnimTasks;

const time_t m_timeDiscordUpdateRate = 20;
time_t m_timeLastDiscordStateUpdate;
};

extern CClientGame* g_pClientGame;
8 changes: 7 additions & 1 deletion Client/mods/deathmatch/logic/CClientVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CClientProjectile;

#define INVALID_PASSENGER_SEAT 0xFF
#define DEFAULT_VEHICLE_HEALTH 1000
#define MAX_VEHICLE_HEALTH 10000
#define MAX_VEHICLE_HEALTH 10000

enum eClientVehicleType
{
Expand Down Expand Up @@ -145,6 +145,12 @@ struct SVehicleComponentData
bool m_bVisible;
};

const std::map<eClientVehicleType, std::string> g_vehicleTypePrefixes{
{CLIENTVEHICLE_CAR, "Cruising around"}, {CLIENTVEHICLE_PLANE, "Flying around"}, {CLIENTVEHICLE_BIKE, "Riding around"},
{CLIENTVEHICLE_HELI, "Flying around"}, {CLIENTVEHICLE_BOAT, "Riding the waves of"}, {CLIENTVEHICLE_TRAIN, "Riding the train in"},
{CLIENTVEHICLE_TRAILER, "Doing weird stuff in"}, {CLIENTVEHICLE_BMX, "Bunny hopping around"}, {CLIENTVEHICLE_MONSTERTRUCK, "Monster truckin' around"},
{CLIENTVEHICLE_QUADBIKE, "Quaddin' around"}};

class CClientVehicle : public CClientStreamElement
{
DECLARE_CLASS(CClientVehicle, CClientStreamElement)
Expand Down
100 changes: 100 additions & 0 deletions Client/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,18 @@ void CPacketHandler::Packet_PlayerSpawn(NetBitStreamInterface& bitStream)

// Reset return position so we can't warp back to where we were if local player
g_pClientGame->m_pNetAPI->ResetReturnPosition();

auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pPlayer->GetPosition(position);
CStaticFunctionDefinitions::GetZoneName(position, zoneName, true);

discord->SetPresenceState(SString("Walking around %s", zoneName.c_str()), false);
}
}
else
{
Expand Down Expand Up @@ -1771,6 +1783,22 @@ void CPacketHandler::Packet_Vehicle_InOut(NetBitStreamInterface& bitStream)
Arguments2.PushElement(pPed); // player / ped
Arguments2.PushNumber(ucSeat); // seat
pVehicle->CallEvent("onClientVehicleEnter", Arguments2, true);

if (pPed->IsLocalPlayer())
{
auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pPed->GetPosition(position);
CStaticFunctionDefinitions::GetZoneName(position, zoneName, true);

eClientVehicleType vehicleType = CClientVehicleManager::GetVehicleType(pVehicle->GetModel());
discord->SetPresenceState(SString("%s %s", g_vehicleTypePrefixes.at(vehicleType).c_str(), zoneName.c_str()), false);
}
}
break;
}

Expand Down Expand Up @@ -1896,6 +1924,21 @@ void CPacketHandler::Packet_Vehicle_InOut(NetBitStreamInterface& bitStream)
Arguments2.PushNumber(ucSeat); // seat
Arguments2.PushBoolean(false); // jacker
pVehicle->CallEvent("onClientVehicleExit", Arguments2, true);

if (pPed->IsLocalPlayer())
{
auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pPed->GetPosition(position);
CStaticFunctionDefinitions::GetZoneName(position, zoneName, true);
discord->SetPresenceState(SString("Walking around %s", zoneName.c_str()), false);
}
}

break;
}

Expand Down Expand Up @@ -1943,6 +1986,22 @@ void CPacketHandler::Packet_Vehicle_InOut(NetBitStreamInterface& bitStream)
Arguments2.PushNumber(ucSeat); // seat
Arguments2.PushBoolean(false); // jacker
pVehicle->CallEvent("onClientVehicleExit", Arguments2, true);

if (pPed->IsLocalPlayer())
{
auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pPed->GetPosition(position);
CStaticFunctionDefinitions::GetZoneName(position, zoneName, true);

eClientVehicleType vehicleType = CClientVehicleManager::GetVehicleType(pVehicle->GetModel());
discord->SetPresenceState(SString("Walking around %s", zoneName.c_str()), false);
}
}
break;
}

Expand Down Expand Up @@ -1996,6 +2055,27 @@ void CPacketHandler::Packet_Vehicle_InOut(NetBitStreamInterface& bitStream)
Arguments2.PushNumber(ucSeat); // seat
Arguments2.PushNumber(ucDoor); // door
pVehicle->CallEvent("onClientVehicleStartExit", Arguments2, true);

if (pPed->IsLocalPlayer() || pJacked->IsLocalPlayer())
{
auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pPed->GetPosition(position);
CStaticFunctionDefinitions::GetZoneName(position, zoneName, true);

eClientVehicleType vehicleType = CClientVehicleManager::GetVehicleType(pVehicle->GetModel());

if (pPed->IsLocalPlayer())
discord->SetPresenceState(SString("%s %s", g_vehicleTypePrefixes.at(vehicleType).c_str(), zoneName.c_str()), false);
else if (pJacked->IsLocalPlayer())
discord->SetPresenceState(SString("Walking around %s", zoneName.c_str()), false);
}
}

break;
}

Expand Down Expand Up @@ -2084,6 +2164,26 @@ void CPacketHandler::Packet_Vehicle_InOut(NetBitStreamInterface& bitStream)
pInsidePed->CallEvent("onClientPlayerVehicleEnter", Arguments4, true);
else
pInsidePed->CallEvent("onClientPedVehicleEnter", Arguments4, true);

if (pInsidePed->IsLocalPlayer() || pOutsidePed->IsLocalPlayer())
{
auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pInsidePed->GetPosition(position);
CStaticFunctionDefinitions::GetZoneName(position, zoneName, true);

eClientVehicleType vehicleType = CClientVehicleManager::GetVehicleType(pVehicle->GetModel());

if (pInsidePed->IsLocalPlayer())
discord->SetPresenceState(SString("%s %s", g_vehicleTypePrefixes.at(vehicleType).c_str(), zoneName.c_str()), false);
else if (pOutsidePed->IsLocalPlayer())
discord->SetPresenceState(SString("Walking around %s", zoneName.c_str()), false);
}
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9813,6 +9813,24 @@ bool CStaticFunctionDefinitions::WarpPedIntoVehicle(CClientPed* pPed, CClientVeh
Arguments2.PushNumber(uiSeat); // seat
pVehicle->CallEvent("onClientVehicleEnter", Arguments2, true);

if (pPed->IsLocalPlayer())
{
auto discord = g_pCore->GetDiscord();
if (discord->IsDiscordRPCEnabled())
{
CVector position;
SString zoneName;

pPed->GetPosition(position);
GetZoneName(position, zoneName, true);

eClientVehicleType vehicleType = CClientVehicleManager::GetVehicleType(pVehicle->GetModel());
std::string vehiclePrefix = g_vehicleTypePrefixes.at(vehicleType);

discord->SetPresenceState(SString("%s %s", vehiclePrefix.c_str(), zoneName.c_str()), false);
}
}

return true;
}

Expand Down

0 comments on commit fc9a35b

Please sign in to comment.