diff --git a/saco/main.h b/saco/main.h index afbf6d6..c6d4035 100644 --- a/saco/main.h +++ b/saco/main.h @@ -33,12 +33,14 @@ typedef struct _GAME_SETTINGS { #include "../raknet/RakClientInterface.h" #include "../raknet/RakNetworkFactory.h" +#include "../raknet/BitStream.h" #include "../raknet/PacketEnumerations.h" #include "../raknet/SAMPRPC.h" #include "../raknet/GetTime.h" #include "net/localplayer.h" #include "net/remoteplayer.h" +#include "net/netplayer.h" #include "net/netrpc.h" #include "net/actorpool.h" #include "net/playerpool.h" diff --git a/saco/net/netplayer.cpp b/saco/net/netplayer.cpp new file mode 100644 index 0000000..139597f --- /dev/null +++ b/saco/net/netplayer.cpp @@ -0,0 +1,2 @@ + + diff --git a/saco/net/netplayer.h b/saco/net/netplayer.h new file mode 100644 index 0000000..43979af --- /dev/null +++ b/saco/net/netplayer.h @@ -0,0 +1,20 @@ + +#pragma once + +#include + +//---------------------------------------------------- + +class CNetPlayer +{ +public: + //char _gap0[48]; + char _gap0[4]; + int field_4; + BOOL m_bIsNPC; + int field_C; + CRemotePlayer *m_pRemotePlayer; + std::string m_PlayerName; +}; + +//---------------------------------------------------- diff --git a/saco/net/playerpool.cpp b/saco/net/playerpool.cpp index aed84e5..07655be 100644 --- a/saco/net/playerpool.cpp +++ b/saco/net/playerpool.cpp @@ -7,7 +7,7 @@ CPlayerPool::CPlayerPool() { // loop through and initialize all net players to null and slot states to false for(PLAYERID playerId = 0; playerId < MAX_PLAYERS; playerId++) { - field_1F8A[playerId] = 0; + m_pPlayers[playerId] = NULL; field_2A[playerId] = 0; } m_pLocalPlayer = new CLocalPlayer(); diff --git a/saco/net/playerpool.h b/saco/net/playerpool.h index ac240ea..a477e4a 100644 --- a/saco/net/playerpool.h +++ b/saco/net/playerpool.h @@ -17,11 +17,20 @@ private: char _gapFDA[4016]; - int field_1F8A[MAX_PLAYERS]; + CNetPlayer *m_pPlayers[MAX_PLAYERS]; int field_2F3A; public: + void SetLocalPlayerName(PCHAR szName) { field_6 = szName; }; + PCHAR GetLocalPlayerName() { return (PCHAR)field_6.c_str(); }; + void SetPlayerName(PLAYERID playerId, PCHAR szName) { + if(playerId > MAX_PLAYERS) return; + CNetPlayer* pPlayer = m_pPlayers[playerId]; + if(!pPlayer) return; + pPlayer->m_PlayerName = szName; + } + CLocalPlayer * GetLocalPlayer() { return m_pLocalPlayer; }; CPlayerPool(); diff --git a/saco/net/scriptrpc.cpp b/saco/net/scriptrpc.cpp index 0819c33..dce234d 100644 --- a/saco/net/scriptrpc.cpp +++ b/saco/net/scriptrpc.cpp @@ -60,7 +60,6 @@ void ScrUnk70(RPCParameters *rpcParams) {} void ScrSetSpawnInfo(RPCParameters *rpcParams) {} void ScrUnk45(RPCParameters *rpcParams) {} void ScrUnk99(RPCParameters *rpcParams) {} -void ScrUnk0B(RPCParameters *rpcParams) {} void ScrSetPlayerPos(RPCParameters *rpcParams) {} void ScrUnk0D(RPCParameters *rpcParams) {} void ScrUnk0E(RPCParameters *rpcParams) {} @@ -108,6 +107,40 @@ void ScrHideMenu(RPCParameters *rpcParams) {} //---------------------------------------------------- +void ScrSetPlayerName(RPCParameters *rpcParams) +{ + PCHAR Data = reinterpret_cast(rpcParams->input); + int iBitLength = rpcParams->numberOfBitsOfData; + PlayerID sender = rpcParams->sender; + + PLAYERID playerId; + BYTE byteNickLen; + char szNewName[MAX_PLAYER_NAME+1]; + BYTE byteSuccess; + + RakNet::BitStream bsData(Data,(iBitLength/8)+1,false); + + CPlayerPool *pPlayerPool = pNetGame->GetPlayerPool(); + + bsData.Read(playerId); + bsData.Read(byteNickLen); + + if(byteNickLen > MAX_PLAYER_NAME) return; + + bsData.Read(szNewName, byteNickLen); + bsData.Read(byteSuccess); + + szNewName[byteNickLen] = '\0'; + + if (byteSuccess == 1) pPlayerPool->SetPlayerName(playerId, szNewName); + + // Extra addition which we need to do if this is the local player; + if( pPlayerPool->GetLocalPlayerID() == playerId ) + pPlayerPool->SetLocalPlayerName( szNewName ); +} + +//---------------------------------------------------- + void ScrSetCameraPos(RPCParameters *rpcParams) { PCHAR Data = reinterpret_cast(rpcParams->input); @@ -205,7 +238,7 @@ void RegisterScriptRPCs(RakClientInterface* pRakClient) REGISTER_STATIC_RPC(pRakClient, ScrSetSpawnInfo); REGISTER_STATIC_RPC(pRakClient, ScrUnk45); REGISTER_STATIC_RPC(pRakClient, ScrUnk99); - REGISTER_STATIC_RPC(pRakClient, ScrUnk0B); + REGISTER_STATIC_RPC(pRakClient, ScrSetPlayerName); REGISTER_STATIC_RPC(pRakClient, ScrSetPlayerPos); REGISTER_STATIC_RPC(pRakClient, ScrUnk0D); REGISTER_STATIC_RPC(pRakClient, ScrUnk0E); @@ -312,7 +345,7 @@ void UnRegisterScriptRPCs(RakClientInterface* pRakClient) UNREGISTER_STATIC_RPC(pRakClient, ScrUnk2B); UNREGISTER_STATIC_RPC(pRakClient, ScrSetSpawnInfo); UNREGISTER_STATIC_RPC(pRakClient, ScrUnk45); - UNREGISTER_STATIC_RPC(pRakClient, ScrUnk0B); + UNREGISTER_STATIC_RPC(pRakClient, ScrSetPlayerName); UNREGISTER_STATIC_RPC(pRakClient, ScrUnk99); UNREGISTER_STATIC_RPC(pRakClient, ScrSetPlayerPos); UNREGISTER_STATIC_RPC(pRakClient, ScrUnk0D); diff --git a/saco/saco.vcproj b/saco/saco.vcproj index 18e26b7..4977ea3 100644 --- a/saco/saco.vcproj +++ b/saco/saco.vcproj @@ -317,6 +317,12 @@ + + + +