diff --git a/Client/mods/deathmatch/logic/CClientPlayer.h b/Client/mods/deathmatch/logic/CClientPlayer.h index 15327790e0..bef1f26497 100644 --- a/Client/mods/deathmatch/logic/CClientPlayer.h +++ b/Client/mods/deathmatch/logic/CClientPlayer.h @@ -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; @@ -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; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp index 023b1c4191..b65f540bf3 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp @@ -28,6 +28,7 @@ void CLuaPlayerDefs::LoadFunctions() {"isPlayerHudComponentVisible", IsPlayerHudComponentVisible}, {"getPlayerMoney", GetPlayerMoney}, {"getPlayerWantedLevel", GetPlayerWantedLevel}, + {"getPlayerScriptDebugLevel", ArgumentParser}, // Player set funcs {"showPlayerHudComponent", ShowPlayerHudComponent}, @@ -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"); lua_classvariable(luaVM, "nametagText", "setPlayerNametagText", "getPlayerNametagText"); lua_classvariable(luaVM, "nametagShowing", "setPlayerNametagShowing", "isPlayerNametagShowing"); @@ -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 ) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h index fbe910c4ca..918acec6b6 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h @@ -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); diff --git a/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.cpp index 6756bace22..e8cda43283 100644 --- a/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.cpp @@ -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) @@ -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); +} diff --git a/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.h b/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.h index ec60fd2c35..c9ab8c3e28 100644 --- a/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.h +++ b/Client/mods/deathmatch/logic/rpc/CPlayerRPCs.h @@ -27,4 +27,5 @@ class CPlayerRPCs : public CRPCFunctions DECLARE_ELEMENT_RPC(SetPlayerNametagShowing); DECLARE_ELEMENT_RPC(SetPlayerTeam); DECLARE_RPC(TakePlayerScreenShot); + DECLARE_RPC(SetPlayerScriptDebugLevel); }; diff --git a/Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp b/Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp index 8ba4a7573f..2f9cfa8ce9 100644 --- a/Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp +++ b/Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp @@ -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); diff --git a/Server/mods/deathmatch/logic/CPlayer.cpp b/Server/mods/deathmatch/logic/CPlayer.cpp index 5d4fee6401..bf9d6b07d4 100644 --- a/Server/mods/deathmatch/logic/CPlayer.cpp +++ b/Server/mods/deathmatch/logic/CPlayer.cpp @@ -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" @@ -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) diff --git a/Server/mods/deathmatch/logic/CPlayer.h b/Server/mods/deathmatch/logic/CPlayer.h index bb64a6f51a..feded36e51 100644 --- a/Server/mods/deathmatch/logic/CPlayer.h +++ b/Server/mods/deathmatch/logic/CPlayer.h @@ -167,7 +167,7 @@ class CPlayer final : public CPed, public CClient std::list::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(); diff --git a/Shared/sdk/net/rpc_enums.h b/Shared/sdk/net/rpc_enums.h index 9441714939..e7cb590763 100644 --- a/Shared/sdk/net/rpc_enums.h +++ b/Shared/sdk/net/rpc_enums.h @@ -279,5 +279,7 @@ enum eElementRPCFunctions BREAK_OBJECT, + SET_PLAYER_SCRIPT_DEBUG_LEVEL, + NUM_RPC_FUNCS // Add above this line };