Skip to content

Commit

Permalink
getPlayerScriptDebugLevel (Client) (#3502)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico8340 authored Jun 30, 2024
1 parent f6f544e commit 8403da5
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Client/mods/deathmatch/logic/CClientPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class CClientPlayer final : public CClientPed
bool GetWasRecentlyInNetworkInterruption(uint uiMaxTicksAgo);
void SetIsInNetworkInterruption(bool bInNetworkInterruption);

std::uint8_t GetPlayerScriptDebugLevel() const noexcept { return m_scriptDebugLevel; }
void SetPlayerScriptDebugLevel(std::uint8_t level) noexcept { m_scriptDebugLevel = level; }

CVector m_vecPrevBulletSyncStart;
CVector m_vecPrevBulletSyncEnd;
uchar m_ucPrevBulletSyncOrderCounter;
Expand All @@ -136,6 +139,8 @@ class CClientPlayer final : public CClientPed
unsigned long m_ulTick;
bool m_bDoExtrapolatingAim;

std::uint8_t m_scriptDebugLevel{};

bool m_bForce;
CVector m_vecForcedMoveSpeed;
CVector m_vecForcedTurnSpeed;
Expand Down
8 changes: 8 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void CLuaPlayerDefs::LoadFunctions()
{"isPlayerHudComponentVisible", IsPlayerHudComponentVisible},
{"getPlayerMoney", GetPlayerMoney},
{"getPlayerWantedLevel", GetPlayerWantedLevel},
{"getPlayerScriptDebugLevel", ArgumentParser<GetPlayerScriptDebugLevel>},

// Player set funcs
{"showPlayerHudComponent", ShowPlayerHudComponent},
Expand Down Expand Up @@ -87,12 +88,14 @@ void CLuaPlayerDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "getTeam", "getPlayerTeam");
lua_classfunction(luaVM, "getNametagText", "getPlayerNametagText");
lua_classfunction(luaVM, "getNametagColor", "getPlayerNametagColor");
lua_classfunction(luaVM, "getScriptDebugLevel", "getPlayerScriptDebugLevel");

lua_classfunction(luaVM, "isNametagShowing", "isPlayerNametagShowing");

lua_classvariable(luaVM, "ping", NULL, "getPlayerPing");
lua_classvariable(luaVM, "name", NULL, "getPlayerName");
lua_classvariable(luaVM, "team", NULL, "getPlayerTeam");
lua_classvariable(luaVM, "debugLevel", nullptr, "getScriptDebugLevel");

This comment has been minimized.

Copy link
@tederis

tederis Jun 30, 2024

Member

It seems that there should be getPlayerScriptDebugLevel instead of getScriptDebugLevel.

This comment has been minimized.

Copy link
@Nico8340

Nico8340 Jun 30, 2024

Author Contributor

Thx

lua_classvariable(luaVM, "nametagText", "setPlayerNametagText", "getPlayerNametagText");
lua_classvariable(luaVM, "nametagShowing", "setPlayerNametagShowing", "isPlayerNametagShowing");

Expand Down Expand Up @@ -309,6 +312,11 @@ int CLuaPlayerDefs::GetPlayerWantedLevel(lua_State* luaVM)
return 1;
}

std::uint8_t CLuaPlayerDefs::GetPlayerScriptDebugLevel() noexcept
{
return g_pClientGame->GetPlayerManager()->GetLocalPlayer()->GetPlayerScriptDebugLevel();
}

int CLuaPlayerDefs::ShowPlayerHudComponent(lua_State* luaVM)
{
// bool showPlayerHudComponent ( string component, bool show )
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CLuaPlayerDefs : public CLuaDefs
LUA_DECLARE(GetPlayerTeam);
LUA_DECLARE(GetPlayerMoney);
LUA_DECLARE(GetPlayerWantedLevel);
static std::uint8_t GetPlayerScriptDebugLevel() noexcept;

// Player set
LUA_DECLARE(ShowPlayerHudComponent);
Expand Down
16 changes: 16 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CPlayerRPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void CPlayerRPCs::LoadFunctions()
AddHandler(SET_PLAYER_NAMETAG_SHOWING, SetPlayerNametagShowing, "SetPlayerNametagShowing");
AddHandler(SET_PLAYER_TEAM, SetPlayerTeam, "SetPlayerTeam");
AddHandler(TAKE_PLAYER_SCREEN_SHOT, TakePlayerScreenShot, "TakePlayerScreenShot");
AddHandler(SET_PLAYER_SCRIPT_DEBUG_LEVEL, SetPlayerScriptDebugLevel, "SetPlayerScriptDebugLevel");
}

void CPlayerRPCs::SetPlayerMoney(NetBitStreamInterface& bitStream)
Expand Down Expand Up @@ -168,3 +169,18 @@ void CPlayerRPCs::TakePlayerScreenShot(NetBitStreamInterface& bitStream)

m_pClientGame->TakePlayerScreenShot(usSizeX, usSizeY, strTag, ucQuality, uiMaxBandwidth, usMaxPacketSize, pResource, uiServerSentTime);
}

void CPlayerRPCs::SetPlayerScriptDebugLevel(NetBitStreamInterface& stream)
{
CClientPlayer* localPlayer = g_pClientGame->GetPlayerManager()->GetLocalPlayer();

if (!localPlayer)
return;

std::uint8_t scriptDebugLevel;

if (!stream.Read(scriptDebugLevel))
return;

localPlayer->SetPlayerScriptDebugLevel(scriptDebugLevel);
}
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/rpc/CPlayerRPCs.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ class CPlayerRPCs : public CRPCFunctions
DECLARE_ELEMENT_RPC(SetPlayerNametagShowing);
DECLARE_ELEMENT_RPC(SetPlayerTeam);
DECLARE_RPC(TakePlayerScreenShot);
DECLARE_RPC(SetPlayerScriptDebugLevel);
};
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ ADD_ENUM1(SET_DISCORD_JOIN_PARAMETERS)
ADD_ENUM1(SET_COLPOLYGON_HEIGHT)
ADD_ENUM1(SET_OBJECT_BREAKABLE)
ADD_ENUM1(BREAK_OBJECT)
ADD_ENUM1(SET_PLAYER_SCRIPT_DEBUG_LEVEL)
IMPLEMENT_ENUM_END("eElementRPCFunctions")

DECLARE_ENUM(CRPCFunctions::eRPCFunctions);
Expand Down
12 changes: 10 additions & 2 deletions Server/mods/deathmatch/logic/CPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "CBandwidthSettings.h"
#include "CUnoccupiedVehicleSync.h"
#include "CScriptDebugging.h"
#include "packets/CLuaPacket.h"
#include "packets/CConsoleEchoPacket.h"
#include "packets/CChatEchoPacket.h"
#include "CWeaponStatManager.h"
Expand Down Expand Up @@ -470,9 +471,16 @@ void CPlayer::RemoveAllSyncingObjects()
}
}

bool CPlayer::SetScriptDebugLevel(unsigned int uiLevel)
bool CPlayer::SetScriptDebugLevel(std::uint8_t level)
{
return m_pScriptDebugging->AddPlayer(*this, uiLevel);
if (!m_pScriptDebugging->AddPlayer(*this, level))
return false;

CPlayerBitStream BitStream(this);
BitStream.pBitStream->Write(level);

Send(CLuaPacket(SET_PLAYER_SCRIPT_DEBUG_LEVEL, *BitStream.pBitStream));
return true;
}

void CPlayer::SetDamageInfo(ElementID ElementID, unsigned char ucWeapon, unsigned char ucBodyPart)
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class CPlayer final : public CPed, public CClient
std::list<CObject*>::const_iterator IterSyncingObjectEnd() { return m_SyncingObjects.end(); };

unsigned int GetScriptDebugLevel() { return m_uiScriptDebugLevel; };
bool SetScriptDebugLevel(unsigned int uiLevel);
bool SetScriptDebugLevel(std::uint8_t level);

void SetDamageInfo(ElementID ElementID, unsigned char ucWeapon, unsigned char ucBodyPart);
void ValidateDamageInfo();
Expand Down
2 changes: 2 additions & 0 deletions Shared/sdk/net/rpc_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,7 @@ enum eElementRPCFunctions

BREAK_OBJECT,

SET_PLAYER_SCRIPT_DEBUG_LEVEL,

NUM_RPC_FUNCS // Add above this line
};

2 comments on commit 8403da5

@Dutchman101
Copy link
Member

@Dutchman101 Dutchman101 commented on 8403da5 Jun 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, this change causes a crash only on debug builds

Stack trace: https://pastebin.com/7x252vjt
By the stack trace, i suspect it's to do with this line in the diff: 8403da5#diff-046b12ac2ae9ac96f23a12d2ea8c2a7041f46f80c9d0cced88b5590e4752384fR98

I also PM'd @Nico8340, unless we can figure this out easily and quickly ill make an issue in a few days.

@tederis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, this change causes a crash only on debug builds

Stack trace: https://pastebin.com/7x252vjt By the stack trace, i suspect it's to do with this line in the diff: 8403da5#diff-046b12ac2ae9ac96f23a12d2ea8c2a7041f46f80c9d0cced88b5590e4752384fR98

I also PM'd @Nico8340, unless we can figure this out easily and quickly ill make an issue in a few days.

Fixed in #3524

Please sign in to comment.