Skip to content

Commit

Permalink
R10 - almost final update :D
Browse files Browse the repository at this point in the history
- Added SendInvalidPlayerSync to crash raksamp
- Added IsPlayerCheckpointActive, IsPlayerRaceCheckpointActive
- Fixed bug with IsPlayerConnected, this function will check 4byte of
playerid not only 2
- Improved hooking system, now hooks only will run from gamemode

TODO: Fix GetPlayerWeapon() bug which caused by
OnPlayerStatsAndWeaponsUpdate
  • Loading branch information
kurta9999 committed Nov 10, 2014
1 parent efa7d0b commit 7849779
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 85 deletions.
5 changes: 2 additions & 3 deletions src/CCallbackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ void CCallbackManager::OnPlayerStatsAndWeaponsUpdate(WORD playerid)
}
}
}


/*
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerConnect(int playerid)
{
if (playerid >= 0 && playerid < MAX_PLAYERS)
Expand All @@ -197,7 +196,7 @@ PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerConnect(int playerid)
}
return true;
}
/*
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerDisconnect(int playerid, int reason)
{
pServer->RemovePlayer(playerid);
Expand Down
2 changes: 1 addition & 1 deletion src/CGangZonePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "RPCs.h"
#include "Utils.h"

#ifndef WIN32
#ifndef _WIN32
#include <string.h>
#endif

Expand Down
65 changes: 37 additions & 28 deletions src/CPickupPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void CPickupPool::InitializeForPlayer(WORD playerid)
pPlayerData[playerid]->bClientPickupSlots.set(count, 1);

// If streaming is disabled, show pickup for player
if(!m_bStreamingEnabled) ShowPickup(count, playerid, *p->second);
if(!m_bStreamingEnabled) ShowPickup(count, playerid, p->second);
count++;
}
}
Expand Down Expand Up @@ -75,7 +75,11 @@ int CPickupPool::New(int modelid, int type, CVector vecPos, int world)
pPlayerData[i]->bClientPickupSlots.set(freeslot, 1);

// If streaming is disabled, show pickup for player
if(!m_bStreamingEnabled) ShowPickup(freeslot, i, *pPickup);
if(!m_bStreamingEnabled)
{
ShowPickup(freeslot, i, pPickup);
//pPlayerData[i]->bClientPickupStreamedIn[freeslot] = true;
}
}
return slot;
}
Expand Down Expand Up @@ -104,7 +108,7 @@ int CPickupPool::New(WORD playerid, int modelid, int type, CVector vecPos, int w
if(!pPlayerData[playerid]->bClientPickupSlots[x])
{
freeslot = x;
logprintf("freeslot player pickup %d - playerid: %d", x, playerid);
//logprintf("freeslot player pickup %d - playerid: %d", x, playerid);
break;
}
}
Expand All @@ -122,7 +126,11 @@ int CPickupPool::New(WORD playerid, int modelid, int type, CVector vecPos, int w
pPlayerData[playerid]->bClientPickupSlots.set(freeslot, true);

// If streaming is disabled, show pickup for player
if(!m_bStreamingEnabled) ShowPickup(freeslot, playerid, *pPickup);
if(!m_bStreamingEnabled)
{
ShowPickup(freeslot, playerid, pPickup);
//pPlayerData[playerid]->bClientPickupStreamedIn[freeslot] = true;
}
return slot;
}

Expand All @@ -138,25 +146,27 @@ void CPickupPool::Destroy(int pickupid)
// Skip unconnected players
if(!IsPlayerConnected(i)) continue;

bool bRestart = false;
for (PickupMap::iterator p = pPlayerData[i]->ClientPlayerPickups.begin(); p != pPlayerData[i]->ClientPlayerPickups.end(); p++)
{
bRestart = false;
if(p->second == it->second)
{
if(!m_bStreamingEnabled) HidePickup((int)p->first, i);
//logprintf("destroy pickup: playerid: %d, pickup %d, clientside: %d - pos: %f, %f, %f", i, pickupid, p->first, p->second->vecPos.fX, p->second->vecPos.fY, p->second->vecPos.fZ);

HidePickup((int)p->first, i);
pPlayerData[i]->bClientPickupStreamedIn[p->first] = false;

pPlayerData[i]->bClientPickupSlots.set(p->first, false);
pPlayerData[i]->ClientPlayerPickups.erase(p);
break;
}
}
}
}

// And finaly, remove pickup from server pool
m_bPickupSlots.set(pickupid, false);
SAFE_DELETE(it->second);
m_Pickups.erase(it);
// And finaly, remove pickup from server pool
m_bPickupSlots.set(pickupid, false);
SAFE_DELETE(it->second);
m_Pickups.erase(it);
}
}

void CPickupPool::Destroy(WORD playerid, int pickupid)
Expand All @@ -165,13 +175,11 @@ void CPickupPool::Destroy(WORD playerid, int pickupid)
PickupMap::iterator it = pPlayerData[playerid]->PlayerPickups.find(pickupid);
if(it != pPlayerData[playerid]->PlayerPickups.end())
{
bool bRestart = false;
for (PickupMap::iterator p = pPlayerData[playerid]->ClientPlayerPickups.begin(); p != pPlayerData[playerid]->ClientPlayerPickups.end(); bRestart ? (it = pPlayerData[playerid]->ClientPlayerPickups.begin()) : (it++))
for (PickupMap::iterator p = pPlayerData[playerid]->ClientPlayerPickups.begin(); p != pPlayerData[playerid]->ClientPlayerPickups.end(); p++)
{
bRestart = false;
if(p->second == it->second)
{
if(!m_bStreamingEnabled) HidePickup((int)p->first, playerid);
HidePickup((int)p->first, playerid);

pPlayerData[playerid]->bClientPickupSlots.set(p->first, false);
pPlayerData[playerid]->ClientPlayerPickups.erase(p);
Expand All @@ -181,21 +189,22 @@ void CPickupPool::Destroy(WORD playerid, int pickupid)
SAFE_DELETE(it->second);
pPlayerData[playerid]->PlayerPickups.erase(it);

bRestart = true;
pPlayerData[playerid]->bClientPickupStreamedIn[p->first] = false;
break;
}
}
}
}

void CPickupPool::ShowPickup(int pickupid, WORD playerid, CPickup pPickup)
void CPickupPool::ShowPickup(int pickupid, WORD playerid, CPickup *pPickup)
{
RakNet::BitStream bsPickup;
bsPickup.Write(pickupid);
bsPickup.Write(pPickup.iModel);
bsPickup.Write(pPickup.iType);
bsPickup.Write(pPickup.vecPos.fX);
bsPickup.Write(pPickup.vecPos.fY);
bsPickup.Write(pPickup.vecPos.fZ);
bsPickup.Write(pPickup->iModel);
bsPickup.Write(pPickup->iType);
bsPickup.Write(pPickup->vecPos.fX);
bsPickup.Write(pPickup->vecPos.fY);
bsPickup.Write(pPickup->vecPos.fZ);
pRakServer->RPC(&RPC_CreatePickup, &bsPickup, HIGH_PRIORITY, RELIABLE, 0, pRakServer->GetPlayerIDFromIndex(playerid), false, false);
}

Expand All @@ -213,7 +222,7 @@ bool CPickupPool::IsStreamed(WORD playerid, CPickup* pPickup)
if(p->second == pPickup)
return pPlayerData[playerid]->bClientPickupStreamedIn[p->first];
}
return 1;
return 0;
}

CPickup* CPickupPool::FindPickup(int pickupid)
Expand Down Expand Up @@ -272,15 +281,15 @@ void CPickupPool::Process(void)
{
if (pNetGame->pPlayerPool->dwVirtualWorld[playerid] == p->second->iWorld || p->second->iWorld == -1)
{
//logprintf("distance 1: %f - %d, world: %d", distance, playerid, p->second->iWorld);
//logprintf("streamin: %f - %d, world: %d (pickupid: %d)", distance, playerid, p->second->iWorld, p->first);
pPlayerData[playerid]->bClientPickupStreamedIn.set(p->first, true);

ShowPickup((int)p->first, playerid, *p->second);
ShowPickup((int)p->first, playerid, p->second);
}
}
else if ((distance > 300.0f || (pNetGame->pPlayerPool->dwVirtualWorld[playerid] != p->second->iWorld && p->second->iWorld != -1)) && pPlayerData[playerid]->bClientPickupStreamedIn[p->first])
else if ((distance >= 300.0f || (pNetGame->pPlayerPool->dwVirtualWorld[playerid] != p->second->iWorld && p->second->iWorld != -1)) && pPlayerData[playerid]->bClientPickupStreamedIn[p->first])
{
//logprintf("distance2: %f - %d", distance, playerid);
//logprintf("streamout: %f - %d (pickupid: %d)", distance, playerid, p->first);
pPlayerData[playerid]->bClientPickupStreamedIn.set(p->first, false);

HidePickup((int)p->first, playerid);
Expand Down
2 changes: 1 addition & 1 deletion src/CPickupPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CPickupPool
void SetStreamingEnabled(bool enabled);
bool IsStreamingEnabled(void);
private:
void ShowPickup(int pickupid, WORD playerid, CPickup pPickup);
void ShowPickup(int pickupid, WORD playerid, CPickup *pPickup);
void HidePickup(int pickupid, WORD playerid);

PickupMap m_Pickups;
Expand Down
8 changes: 5 additions & 3 deletions src/CPlayerData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
#include "main.h"
#include <map>

#ifndef WIN32
#ifndef _WIN32
#include <string.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#endif

CPlayerData::CPlayerData( WORD playerid )
Expand Down Expand Up @@ -117,7 +120,6 @@ bool CPlayerData::DestroyObject(WORD objectid)
void CPlayerData::Process(void)
{
// Process AFK detection
#ifdef WIN32
DWORD dwTickCount = GetTickCount();

if(bEverUpdated)
Expand All @@ -136,8 +138,8 @@ void CPlayerData::Process(void)
CCallbackManager::OnPlayerPauseStateChange(wPlayerID, bAFKState);
}
}
#endif

// Process gangzones
for(WORD zoneid = 0; zoneid != MAX_GANG_ZONES; zoneid++)
{
// If zone id is unused client side, then continue
Expand Down
73 changes: 71 additions & 2 deletions src/CServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

#include "Addresses.h"
#include "CPlayerData.h"
#include "CCallbackManager.h"
#include "Functions.h"
#include "RPCs.h"
#include "Utils.h"
#include "main.h"

#ifndef WIN32
#ifndef _WIN32
#include <cstring>
#endif
#include <stdio.h>
Expand Down Expand Up @@ -55,7 +56,7 @@ bool CServer::RemovePlayer(int playerid)

void CServer::Process()
{
if(++m_iTicks == 10)
if(++m_iTicks == 5)
{
m_iTicks = 0;
for(WORD playerid = 0; playerid != MAX_PLAYERS; playerid++)
Expand Down Expand Up @@ -273,4 +274,72 @@ bool CServer::IsValidNick(char *szName)
}
}
return true;
}

//----------------------------------------------------

void CServer::Packet_StatsUpdate(Packet *p)
{
RakNet::BitStream bsStats((unsigned char*)p->data, p->length, false);
CPlayerPool *pPlayerPool = pNetGame->pPlayerPool;
WORD playerid = p->playerIndex;
int money;
int drunklevel;
// BYTE bytePacketID;

bsStats.SetReadOffset(8);
bsStats.Read(money);
bsStats.Read(drunklevel);

if (!IsPlayerConnected(playerid)) return;

pPlayerPool->dwMoney[playerid] = money;
pPlayerPool->dwDrunkLevel[playerid] = drunklevel;

CCallbackManager::OnPlayerStatsAndWeaponsUpdate(playerid);
}

//----------------------------------------------------

void CServer::Packet_WeaponsUpdate(Packet *p)
{
RakNet::BitStream bsData((unsigned char*)p->data, p->length, false);

WORD playerid = p->playerIndex;
BYTE byteLength = p->length;
if (byteLength > 3)
byteLength = (byteLength - 3) >> 2;

if (!IsPlayerConnected(playerid)) return;
printf("Original: %d New: %d\n", p->length, byteLength);

CPlayer* pPlayer = pNetGame->pPlayerPool->pPlayer[playerid];

WORD wTarget;
BYTE byteIndex;
BYTE byteWeapon;
WORD wordAmmo;

bsData.SetReadOffset(8);
bsData.Read(wTarget);
pPlayer->wTargetId = wTarget;
logprintf("targetid: %d, byteLenghth: %d", byteLength);

while (byteLength)
{
logprintf("byteLength: %d", byteLength);
bsData.Read(byteIndex);
bsData.Read(byteWeapon);
bsData.Read(wordAmmo);
logprintf("%u %u %i", byteIndex, byteWeapon, wordAmmo);
if (byteIndex < 13)
{
logprintf("%d %d %d", byteIndex, byteWeapon, wordAmmo);
pPlayer->wWeaponAmmo[byteIndex] = wordAmmo;
pPlayer->byteWeaponId[byteIndex] = byteWeapon;
}
byteLength--;
}

CCallbackManager::OnPlayerStatsAndWeaponsUpdate(playerid);
}
5 changes: 5 additions & 0 deletions src/CServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class CNetGame;
class RakServer;
struct Packet;

#include "CTypes.h"
#include "Addresses.h"
Expand Down Expand Up @@ -34,6 +35,10 @@ class CServer
void AllowNickNameCharacter(char character, bool enable);
bool IsNickNameCharacterAllowed(char character);
bool IsValidNick(char *szName);

void Packet_WeaponsUpdate(Packet *p);
void Packet_StatsUpdate(Packet *p);

private:
eSAMPVersion m_Version;
float m_fGravity;
Expand Down
5 changes: 0 additions & 5 deletions src/CVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
#ifndef __CVector_H
#define __CVector_H

#ifdef WIN32
#include <windows.h>
#endif

#include <math.h>

#define FLOAT_EPSILON 0.0001f
Expand Down Expand Up @@ -43,7 +39,6 @@ class CVector
this->fZ = 0;
};


CVector ( float fX, float fY, float fZ)
{
this->fX = fX;
Expand Down
Loading

0 comments on commit 7849779

Please sign in to comment.