Skip to content

Commit

Permalink
Merge branch 'master' into 200523_NewAccountEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
TracerDS authored Dec 31, 2023
2 parents 77d090d + 478fd54 commit a8708f1
Show file tree
Hide file tree
Showing 24 changed files with 2,132 additions and 1,898 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Create build artifacts
run: utils\premake5 compose_files

- uses: actions/upload-artifact@master
- uses: actions/upload-artifact@v3
with:
name: InstallFiles
path: InstallFiles/
Expand Down
4 changes: 3 additions & 1 deletion Client/core/CClientVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ void CClientVariables::LoadDefaults()
DEFAULT("browser_remote_javascript", true); // Execute javascript on remote websites?
DEFAULT("filter_duplicate_log_lines", true); // Filter duplicate log lines for debug view and clientscript.log
DEFAULT("always_show_transferbox", false); // Should the transfer box always be visible for downloads? (and ignore scripted control)
DEFAULT("allow_discord_rpc", true); // Enable Discord Rich Presence
DEFAULT("allow_discord_rpc", true); // Enable Discord Rich Presence
DEFAULT("discord_rpc_share_data", false); // Consistent Rich Presence data sharing
DEFAULT("discord_rpc_share_data_firsttime", false); // Display the user data sharing consent dialog box - for the first time
DEFAULT("_beta_qc_rightclick_command", _S("reconnect")); // Command to run when right clicking quick connect (beta - can be removed at any time)

if (!Exists("locale"))
Expand Down
20 changes: 20 additions & 0 deletions Client/core/CDiscordRichPresence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ void CDiscordRichPresence::SetPresencePartySize(int iSize, int iMax, bool bCusto
}
}

void CDiscordRichPresence::SetDiscordUserID(const std::string& strUserID)
{
if (CVARS_GET_VALUE<bool>("discord_rpc_share_data"))
m_strDiscordUserID = strUserID;
}

std::string CDiscordRichPresence::GetDiscordUserID() const
{
if (CVARS_GET_VALUE<bool>("discord_rpc_share_data"))
return m_strDiscordUserID;

return {};
};

#ifdef DISCORD_DISABLE_IO_THREAD
void CDiscordRichPresence::UpdatePresenceConnection()
{
Expand All @@ -290,15 +304,21 @@ void CDiscordRichPresence::UpdatePresenceConnection()
void CDiscordRichPresence::HandleDiscordReady(const DiscordUser* pDiscordUser)
{
if (const auto discord = g_pCore->GetDiscord(); discord && discord->IsDiscordRPCEnabled())
{
discord->SetDiscordClientConnected(true);
discord->SetDiscordUserID(pDiscordUser->userId);
}
}

void CDiscordRichPresence::HandleDiscordDisconnected(int iErrorCode, const char* szMessage)
{
WriteDebugEvent(SString("[DISCORD] Disconnected %s (error #%d)", szMessage, iErrorCode));

if (const auto discord = g_pCore->GetDiscord(); discord)
{
discord->SetDiscordUserID("");
discord->SetDiscordClientConnected(false);
}
}

void CDiscordRichPresence::HandleDiscordError(int iErrorCode, const char* szMessage)
Expand Down
3 changes: 3 additions & 0 deletions Client/core/CDiscordRichPresence.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CDiscordRichPresence : public CDiscordInterface
void SetAssetSmallData(const char* szAsset, const char* szAssetText);
void SetDiscordClientConnected(bool bConnected) { m_bConnected = bConnected; };
void SetPresencePartySize(int iSize, int iMax, bool bCustom);
void SetDiscordUserID(const std::string& strUserID);

bool ResetDiscordData();
bool SetPresenceState(const char* szState, bool bCustom);
Expand All @@ -47,13 +48,15 @@ class CDiscordRichPresence : public CDiscordInterface
bool IsDiscordClientConnected() const { return m_bConnected; };

std::string GetDiscordResourceName() const { return m_strDiscordCustomResourceName; };
std::string GetDiscordUserID() const;

// static handlers
static void HandleDiscordReady(const struct DiscordUser* pDiscordUser);
static void HandleDiscordDisconnected(int iErrorCode, const char* szMessage);
static void HandleDiscordError(int iErrorCode, const char* szMessage);

private:
std::string m_strDiscordUserID;
std::string m_strDiscordAppId;
std::string m_strDiscordAppAsset;
std::string m_strDiscordAppAssetText;
Expand Down
14 changes: 13 additions & 1 deletion Client/core/CMainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ CMainMenu::CMainMenu(CGUI* pManager)
discord->SetPresenceState(_("Main menu"), false);
discord->SetPresenceStartTimestamp(0);
}

// Store the pointer to the graphics subsystem
m_pGraphics = CGraphics::GetSingletonPtr();

Expand Down Expand Up @@ -683,6 +682,19 @@ void CMainMenu::Update()
}
#endif

if (WaitForMenu == 299)
{
if (!g_pCore->GetCVars()->GetValue("discord_rpc_share_data_firsttime", false)
&& g_pCore->GetCVars()->GetValue("allow_discord_rpc", false)
&& !g_pCore->GetCVars()->GetValue("discord_rpc_share_data", false))
{
m_Settings.ShowRichPresenceShareDataQuestionBox();
CVARS_SET("discord_rpc_share_data_firsttime", true);
}
else
CVARS_SET("discord_rpc_share_data_firsttime", true);
}

if (WaitForMenu < 300)
WaitForMenu++;
}
Expand Down
30 changes: 29 additions & 1 deletion Client/core/CSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4515,10 +4515,38 @@ bool CSettings::OnAllowExternalSoundsClick(CGUIElement* pElement)
//
bool CSettings::OnAllowDiscordRPC(CGUIElement* pElement)
{
g_pCore->GetDiscord()->SetDiscordRPCEnabled(m_pCheckBoxAllowDiscordRPC->GetSelected());
bool isEnabled = m_pCheckBoxAllowDiscordRPC->GetSelected();
g_pCore->GetDiscord()->SetDiscordRPCEnabled(isEnabled);

if (isEnabled)
ShowRichPresenceShareDataQuestionBox(); // show question box

return true;
}

static void ShowRichPresenceShareDataCallback(void* ptr, unsigned int uiButton)
{
CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->GetQuestionWindow()->Reset();

CVARS_SET("discord_rpc_share_data", static_cast<bool>(uiButton));
}

void CSettings::ShowRichPresenceShareDataQuestionBox() const
{
SStringX strMessage(
_("It seems that you have the Rich Presence connection option enabled."
"\nDo you want to allow servers to share their data?"
"\n\nThis includes yours unique ID identifier."));
CQuestionBox* pQuestionBox = CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->GetQuestionWindow();
pQuestionBox->Reset();
pQuestionBox->SetTitle(_("CONSENT TO ALLOW DATA SHARING"));
pQuestionBox->SetMessage(strMessage);
pQuestionBox->SetButton(0, _("No"));
pQuestionBox->SetButton(1, _("Yes"));
pQuestionBox->SetCallback(ShowRichPresenceShareDataCallback);
pQuestionBox->Show();
}

//
// CustomizedSAFiles
//
Expand Down
1 change: 1 addition & 0 deletions Client/core/CSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class CSettings
bool IsActive();

void SetSelectedIndex(unsigned int uiIndex);
void ShowRichPresenceShareDataQuestionBox() const;

protected:
const static int SecKeyNum = 3; // Number of secondary keys
Expand Down
31 changes: 30 additions & 1 deletion Client/game_sa/CPlaneSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,41 @@ class CPlaneSAInterface : public CAutomobileSAInterface
{
// + 2508 = undercarrige possition (float - 1.0 = up, 0.0 = down)
// fill this
public:
float m_fLeftRightSkid;
float m_fSteeringUpDown;
float m_fSteeringLeftRight;
float m_fAccelerationBreakStatus;
float m_fAccelerationBreakStatusPrev;
float m_fSteeringFactor;
float field_9A0;
float m_planeCreationHeading; // The heading when plane is created or placed on road properly
float m_maxAltitude;
float m_altitude;
float m_minAltitude;
float m_planeHeading;
float m_planeHeadingPrev;
float m_forwardZ;
uint32_t m_nStartedFlyingTime;
float m_fPropSpeed; // Rotor speed 0x09C4
float field_9C8;
float m_fLandingGearStatus;
int32_t m_planeDamageWave;
FxSystem_c** m_pGunParticles;
uint8_t m_nFiringMultiplier;
int32_t field_9DC;
int32_t field_9E0;
int32_t field_9E4;
FxSystem_c* m_apJettrusParticles[4];
FxSystem_c* m_pSmokeParticle;
uint32_t m_nSmokeTimer;
bool m_bSmokeEjectorEnabled;
};
static_assert(sizeof(CPlaneSAInterface) == 0xA04, "Invalid size for CPlaneSAInterface");

class CPlaneSA final : public virtual CPlane, public virtual CAutomobileSA
{
public:
CPlaneSA(CPlaneSAInterface* pInterface);

CPlaneSAInterface* GetPlaneInterface() { return reinterpret_cast<CPlaneSAInterface*>(GetInterface()); }
};
13 changes: 13 additions & 0 deletions Client/game_sa/CVehicleSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "CGameSA.h"
#include "CProjectileInfoSA.h"
#include "CTrainSA.h"
#include "CPlaneSA.h"
#include "CVehicleSA.h"
#include "CVisibilityPluginsSA.h"
#include "CWorldSA.h"
Expand Down Expand Up @@ -487,6 +488,18 @@ void CVehicleSA::SetTrainSpeed(float fSpeed)
pInterface->m_fTrainSpeed = fSpeed;
}

void CVehicleSA::SetPlaneRotorSpeed(float fSpeed)
{
auto pInterface = static_cast<CPlaneSAInterface*>(GetInterface());
pInterface->m_fPropSpeed = fSpeed;
}

float CVehicleSA::GetPlaneRotorSpeed()
{
auto pInterface = static_cast<CPlaneSAInterface*>(GetInterface());
return pInterface->m_fPropSpeed;
}

bool CVehicleSA::GetTrainDirection()
{
auto pInterface = static_cast<CTrainSAInterface*>(GetInterface());
Expand Down
3 changes: 3 additions & 0 deletions Client/game_sa/CVehicleSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
bool GetTyresDontBurst() { return GetVehicleInterface()->m_nVehicleFlags.bTyresDontBurst; };
unsigned short GetAdjustablePropertyValue() { return *reinterpret_cast<unsigned short*>(reinterpret_cast<unsigned long>(m_pInterface) + 2156); };
float GetHeliRotorSpeed() { return *reinterpret_cast<float*>(reinterpret_cast<unsigned int>(m_pInterface) + 2124); };
float GetPlaneRotorSpeed();

unsigned long GetExplodeTime() { return *reinterpret_cast<unsigned long*>(reinterpret_cast<unsigned int>(m_pInterface) + 1240); };

char GetNitroCount() { return GetVehicleInterface()->m_nNitroBoosts; }
Expand All @@ -565,6 +567,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
*reinterpret_cast<unsigned short*>(reinterpret_cast<unsigned int>(m_pInterface) + 2156) = usAdjustableProperty;
};
void SetHeliRotorSpeed(float fSpeed) { *reinterpret_cast<float*>(reinterpret_cast<unsigned int>(m_pInterface) + 2124) = fSpeed; };
void SetPlaneRotorSpeed(float fSpeed);
void SetExplodeTime(unsigned long ulTime) { *reinterpret_cast<unsigned long*>(reinterpret_cast<unsigned int>(m_pInterface) + 1240) = ulTime; };
void SetRadioStatus(bool bStatus) { *reinterpret_cast<unsigned char*>(reinterpret_cast<unsigned int>(m_pInterface) + 0x1D3) = bStatus; };

Expand Down
48 changes: 48 additions & 0 deletions Client/mods/deathmatch/logic/CClientVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ CClientVehicle::CClientVehicle(CClientManager* pManager, ElementID ID, unsigned
m_HeadLightColor = SColorRGBA(255, 255, 255, 255);
m_bHeliSearchLightVisible = false;
m_fHeliRotorSpeed = 0.0f;
m_fPlaneRotorSpeed = 0.0f;
m_bHasCustomHandling = false;
m_ucVariation = ucVariation;
m_ucVariation2 = ucVariation2;
Expand Down Expand Up @@ -1537,6 +1538,14 @@ float CClientVehicle::GetHeliRotorSpeed()
return m_fHeliRotorSpeed;
}

float CClientVehicle::GetPlaneRotorSpeed()
{
if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_PLANE)
return m_pVehicle->GetPlaneRotorSpeed();

return m_fPlaneRotorSpeed;
}

void CClientVehicle::SetHeliRotorSpeed(float fSpeed)
{
if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI)
Expand All @@ -1545,6 +1554,45 @@ void CClientVehicle::SetHeliRotorSpeed(float fSpeed)
m_fHeliRotorSpeed = fSpeed;
}

void CClientVehicle::SetPlaneRotorSpeed(float fSpeed)
{
if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_PLANE)
m_pVehicle->SetPlaneRotorSpeed(fSpeed);

m_fPlaneRotorSpeed = fSpeed;
}

bool CClientVehicle::GetRotorSpeed(float& speed)
{
if (m_eVehicleType == CLIENTVEHICLE_PLANE)
{
speed = GetPlaneRotorSpeed();
return true;
}
else if (m_eVehicleType == CLIENTVEHICLE_HELI)
{
speed = GetHeliRotorSpeed();
return true;
}

return false;
}

bool CClientVehicle::SetRotorSpeed(float fSpeed)
{
switch (m_eVehicleType)
{
case CLIENTVEHICLE_HELI:
SetHeliRotorSpeed(fSpeed);
return true;
case CLIENTVEHICLE_PLANE:
SetPlaneRotorSpeed(fSpeed);
return true;
default:
return false;
}
}

bool CClientVehicle::IsHeliSearchLightVisible()
{
if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI)
Expand Down
8 changes: 7 additions & 1 deletion Client/mods/deathmatch/logic/CClientVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,13 @@ class CClientVehicle : public CClientStreamElement

// TODO: Make the class remember on virtualization
float GetHeliRotorSpeed();
void SetHeliRotorSpeed(float fSpeed);
float GetPlaneRotorSpeed();

bool GetRotorSpeed(float&);
bool SetRotorSpeed(float);

void SetHeliRotorSpeed(float fSpeed);
void SetPlaneRotorSpeed(float fSpeed);
bool IsHeliSearchLightVisible();
void SetHeliSearchLightVisible(bool bVisible);

Expand Down Expand Up @@ -641,6 +646,7 @@ class CClientVehicle : public CClientStreamElement
bool m_bIsOnGround;
bool m_bHeliSearchLightVisible;
float m_fHeliRotorSpeed;
float m_fPlaneRotorSpeed;
const CHandlingEntry* m_pOriginalHandlingEntry = nullptr;
CHandlingEntry* m_pHandlingEntry = nullptr;
const CFlyingHandlingEntry* m_pOriginalFlyingHandlingEntry = nullptr;
Expand Down
12 changes: 11 additions & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void CLuaDiscordDefs::LoadFunctions()
{"setDiscordRichPresencePartySize", ArgumentParser<SetPartySize>},
{"resetDiscordRichPresenceData", ArgumentParser<ResetData>},
{"isDiscordRichPresenceConnected", ArgumentParser <IsDiscordRPCConnected>},

{"getDiscordRichPresenceUserID", ArgumentParser<GetDiscordUserID>},
};

// Add functions
Expand Down Expand Up @@ -266,3 +266,13 @@ bool CLuaDiscordDefs::IsDiscordRPCConnected()

return discord->IsDiscordClientConnected();
}

std::string CLuaDiscordDefs::GetDiscordUserID()
{
auto discord = g_pCore->GetDiscord();

if (!discord || !discord->IsDiscordRPCEnabled())
return {};

return discord->GetDiscordUserID();
}
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ class CLuaDiscordDefs : public CLuaDefs
static bool SetEndTime(unsigned long ulTime);
static bool SetPartySize(int iMin, int iMax);
static bool IsDiscordRPCConnected();

static std::string GetDiscordUserID();
};

Loading

0 comments on commit a8708f1

Please sign in to comment.