Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
- Added option to disable nightvision bugfix
- Added fix for sniper verticaly sync
- Fixed remote rcon crash at windows
- Moved GetPacketID from Hooks.cpp to Utils.cpp
- Model sizes has been updated
  • Loading branch information
kurta9999 committed Aug 24, 2015
1 parent d221087 commit b28b374
Show file tree
Hide file tree
Showing 10 changed files with 4,143 additions and 3,846 deletions.
4 changes: 2 additions & 2 deletions src/CCallbackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ bool CCallbackManager::OnServerMessage(char* message)
if (!ret) return 0;
}
}
return !!ret;
return static_cast<int>(ret) != 0;
}

bool CCallbackManager::OnRemoteRCONPacket(unsigned int binaryAddress, int port, char *password, bool success, char* command)
Expand All @@ -234,7 +234,7 @@ bool CCallbackManager::OnRemoteRCONPacket(unsigned int binaryAddress, int port,
if (!ret) return 0;
}
}
return !!ret;
return static_cast<int>(ret) != 0;
}

void CCallbackManager::OnPlayerStatsAndWeaponsUpdate(WORD playerid)
Expand Down
7,766 changes: 4,017 additions & 3,749 deletions src/CModelSizes.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/CServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CServer::CServer(eSAMPVersion version)
{
m_iTicks = 0;
m_iTickRate = 5;
m_bNightVisionFix = true;

memset(pPlayerData, NULL, MAX_PLAYERS);
bChangedVehicleColor.reset();
Expand Down
4 changes: 4 additions & 0 deletions src/CServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class CServer
void SetTickRate(int rate) { m_iTickRate = rate; }
int GetTickRate(void) { return m_iTickRate; }

void EnableNightVisionFix(bool enable) { m_bNightVisionFix = enable; }
bool IsNightVisionFixEnabled(void) { return m_bNightVisionFix; }

WORD GetMaxPlayers_();
WORD GetPlayerCount();
WORD GetNPCCount();
Expand Down Expand Up @@ -68,6 +71,7 @@ class CServer
eSAMPVersion m_Version;
int m_iTicks;
int m_iTickRate;
bool m_bNightVisionFix;

std::vector <char> m_vecValidNameCharacters;
};
Expand Down
142 changes: 68 additions & 74 deletions src/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,13 @@ bool HOOK_ContainsInvalidChars(char * szString)
}

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

// amx_Register hook for redirect natives
bool g_bNativesHooked = false;

int AMXAPI HOOK_amx_Register(AMX *amx, AMX_NATIVE_INFO *nativelist, int number)
{
SubHook::ScopedRemove remove(&amx_Register_hook);

// amx_Register hook for redirect natives
static bool g_bNativesHooked = false;

if (!g_bNativesHooked && pServer)
{
int i = 0;
Expand Down Expand Up @@ -257,19 +256,6 @@ int AMXAPI HOOK_amx_Register(AMX *amx, AMX_NATIVE_INFO *nativelist, int number)

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

// GetPacketID hook
BYTE GetPacketID(Packet *p)
{
if (p == 0) return 255;

if ((unsigned char)p->data[0] == 36)
{
assert(p->length > sizeof(unsigned char) + sizeof(unsigned long));
return (unsigned char)p->data[sizeof(unsigned char) + sizeof(unsigned long)];
}
else return (unsigned char)p->data[0];
}

bool IsPlayerUpdatePacket(unsigned char packetId)
{
switch (packetId)
Expand Down Expand Up @@ -303,65 +289,66 @@ static BYTE HOOK_GetPacketID(Packet *p)
{
pPlayerData[playerid]->dwLastUpdateTick = GetTickCount();
pPlayerData[playerid]->bEverUpdated = true;

/*
// Based on JernejL's tutorial - http://forum.sa-mp.com/showthread.php?t=172085
DWORD dwDrunkNew = pPlayerPool->dwDrunkLevel[playerid];
logprintf("drunknew: %d", dwDrunkNew);
if (dwDrunkNew < 100)
{
RakNet::BitStream bs;
bs.Write(2000);
}

int drunk = 0x23;
pRakServer->RPC(&drunk, &bs, HIGH_PRIORITY, RELIABLE_ORDERED, 2, pRakServer->GetPlayerIDFromIndex(playerid), 0, 0);
}
else
switch(packetId)
{
case ID_PLAYER_SYNC:
{
logprintf("elsegeci: %d", pPlayerData[playerid]->dwLastDrunkLevel != dwDrunkNew);
if (pPlayerData[playerid]->dwLastDrunkLevel != dwDrunkNew)
CSyncData *pSyncData = reinterpret_cast<CSyncData*>(&p->data[1]);

if(pServer->IsNightVisionFixEnabled())
{
DWORD fps = pPlayerData[playerid]->dwLastDrunkLevel - dwDrunkNew;
logprintf("fps: %d", dwDrunkNew);
if (fps > 0 && fps < 300)
// Fix nightvision and infrared sync
if (pSyncData->byteWeapon == WEAPON_NIGHTVISION || pSyncData->byteWeapon == WEAPON_INFRARED)
{
pPlayerData[playerid]->dwFPS = fps;
pSyncData->wKeys &= ~4;
pSyncData->byteWeapon = 0;
}
pPlayerData[playerid]->dwLastDrunkLevel = dwDrunkNew;
}

// Store surfing info because server reset it when player surfing on player object
pPlayerData[playerid]->wSurfingInfo = pSyncData->wSurfingInfo;
break;
}
*/
}
case ID_AIM_SYNC:
{
CAimSyncData *pAim = reinterpret_cast<CAimSyncData*>(&p->data[1]);

if (packetId == ID_PLAYER_SYNC)
{
CSyncData *pSyncData = (CSyncData*)(&p->data[1]);
// Fix up, down aim sync
switch(pNetGame->pPlayerPool->pPlayer[playerid]->byteCurrentWeapon)
{
case WEAPON_SNIPER:
case WEAPON_ROCKETLAUNCHER:
case WEAPON_HEATSEEKER:
case WEAPON_CAMERA:
{
pAim->fZAim = -pAim->vecFront.fZ;

// Fix nightvision and infrared sync
if (pSyncData->byteWeapon == 44 || pSyncData->byteWeapon == 45)
if (pAim->fZAim > 1.0f)
{
pAim->fZAim = 1.0f;
}
else if (pAim->fZAim < -1.0f)
{
pAim->fZAim = -1.0f;
}
break;
}
}
break;
}
case ID_STATS_UPDATE:
{
pSyncData->wKeys &= ~4;
pSyncData->byteWeapon = 0;
pServer->Packet_StatsUpdate(p);
return 0xFF;
}
case ID_WEAPONS_UPDATE:
{
CSAMPFunctions::Packet_WeaponsUpdate(p);
CCallbackManager::OnPlayerStatsAndWeaponsUpdate(playerid);
return 0xFF;
}

// Store surfing info because server reset it when player surfing on player object
pPlayerData[playerid]->wSurfingInfo = pSyncData->wSurfingInfo;
}

// Stats and weapons update
if (packetId == ID_STATS_UPDATE)
{
pServer->Packet_StatsUpdate(p);
return 0xFF;
}

if (packetId == ID_WEAPONS_UPDATE)
{
CSAMPFunctions::Packet_WeaponsUpdate(p);
CCallbackManager::OnPlayerStatsAndWeaponsUpdate(playerid);
return 0xFF;
}
}
return packetId;
Expand Down Expand Up @@ -419,14 +406,11 @@ static void HOOK_logprintf(const char *msg, ...)
{
SubHook::ScopedRemove remove(&logprintf_hook);

static char buffer[1024];
char buffer[1024];
va_list arguments;
va_start(arguments, msg);
if(!msg[0]) return;

vsnprintf(buffer, sizeof(buffer), msg, arguments);
va_end(arguments);
if(!buffer[0]) return;

if(CCallbackManager::OnServerMessage(buffer))
logprintf(buffer);
Expand Down Expand Up @@ -531,6 +515,11 @@ int HOOK_ProcessQueryPacket(unsigned int binaryAddress, unsigned short port, cha
to.sin_port = htons(port);
to.sin_addr.s_addr = binaryAddress;

if (pServer->GetBoolVariable("logqueries"))
{
logprintf("[query:%c] from %s", data[10], inet_ntoa(in));
}

switch (data[10])
{
case 'p': // ping
Expand Down Expand Up @@ -726,11 +715,11 @@ int HOOK_ProcessQueryPacket(unsigned int binaryAddress, unsigned short port, cha
case 'x': // rcon
{
if (pRakServer && pRakServer->IsBanned(inet_ntoa(in))) return 1;

// We do not process these queries 'query' is 0
if (!pServer->GetBoolVariable("query") || !pServer->GetBoolVariable("rcon")) return 1;
if (CheckQueryFlood(binaryAddress)) return 1;

cur_sock = s;
cur_data = data;
cur_datalen = 11; // How much of the message we send back.
Expand All @@ -754,7 +743,7 @@ int HOOK_ProcessQueryPacket(unsigned int binaryAddress, unsigned short port, cha
memcpy(szPassword, data, wStrLen);
szPassword[wStrLen] = 0;
data += wStrLen;

if (!strcmp(szPassword, pServer->GetStringVariable("rcon_password")))
{
// Check there's enough data for another WORD
Expand All @@ -773,7 +762,7 @@ int HOOK_ProcessQueryPacket(unsigned int binaryAddress, unsigned short port, cha
free(szPassword);
goto cleanup; // Malformed packet! Haxy bastard!
}

// Read the command string
char* szCommand = (char*)malloc(wStrLen + 1);
memcpy(szCommand, data, wStrLen);
Expand Down Expand Up @@ -805,12 +794,13 @@ int HOOK_ProcessQueryPacket(unsigned int binaryAddress, unsigned short port, cha
CCallbackManager::OnRemoteRCONPacket(binaryAddress, port, szPassword, false, "NULL");
}
free(szPassword);

cleanup:
cur_datalen = 0;
cur_data = NULL;
cur_sock = INVALID_SOCKET;
break;

}
}
}
Expand Down Expand Up @@ -875,9 +865,13 @@ void InstallPostHooks()

// SetMaxPlayers() fix
pRakServer->Start(MAX_PLAYERS, 0, 5, static_cast<unsigned short>(pServer->GetIntVariable("port")), pServer->GetStringVariable("bind"));
/*
#ifdef _WIN32
logprintf_hook.Install((void*)ppPluginData[PLUGIN_DATA_LOGPRINTF], (void*)HOOK_logprintf);
#endif
*/
logprintf_hook.Install((void*)ppPluginData[PLUGIN_DATA_LOGPRINTF], (void*)HOOK_logprintf);

// Recreate GangZone pool
pNetGame->pGangZonePool = new CGangZonePool();

Expand Down
41 changes: 29 additions & 12 deletions src/Scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ static cell AMX_NATIVE_CALL Natives::SetPlayerPosForPlayer(AMX* amx, cell* param

int playerid = static_cast<int>(params[1]);
int posplayerid = static_cast<int>(params[2]);
bool forcesync = !!params[6];
bool forcesync = static_cast<int>(params[6]) != 0;
if (!IsPlayerConnectedEx(playerid) || !IsPlayerConnectedEx(posplayerid)) return 0;

SAFE_DELETE(pPlayerData[playerid]->vecCustomPos[posplayerid]);
Expand Down Expand Up @@ -3863,7 +3863,7 @@ static cell AMX_NATIVE_CALL Natives::PlayerTextDrawGetString( AMX* amx, cell* pa
if(!IsPlayerConnectedEx(playerid)) return 0;
if(textdrawid >= MAX_PLAYER_TEXT_DRAWS) return 0;

bool bIsValid = !!pNetGame->pPlayerPool->pPlayer[playerid]->pTextdraw->bSlotState[textdrawid];
bool bIsValid = static_cast<int>(pNetGame->pPlayerPool->pPlayer[playerid]->pTextdraw->bSlotState[textdrawid]) != 0;
if(!bIsValid) return 0;

const char *szText = (bIsValid) ? pNetGame->pPlayerPool->pPlayer[playerid]->pTextdraw->szFontText[textdrawid]: '\0';
Expand Down Expand Up @@ -4705,6 +4705,27 @@ static cell AMX_NATIVE_CALL Natives::YSF_GetTickRate( AMX* amx, cell* params )
return static_cast<cell>(pServer->GetTickRate());
}

// native YSF_EnableNightVisionFix(enable);
static cell AMX_NATIVE_CALL Natives::YSF_EnableNightVisionFix(AMX* amx, cell* params)
{
if (!pServer)
return 1;

CHECK_PARAMS(1, "YSF_EnableNightVisionFix");

pServer->EnableNightVisionFix(static_cast<int>(params[1]) != 0);
return 1;
}

// native YSF_IsNightVisionFixEnabled();
static cell AMX_NATIVE_CALL Natives::YSF_IsNightVisionFixEnabled(AMX* amx, cell* params)
{
if (!pServer)
return 1;

return static_cast<cell>(pServer->IsNightVisionFixEnabled());
}

static cell AMX_NATIVE_CALL Natives::YSF_GangZoneCreate(AMX *amx, cell *params)
{
CHECK_PARAMS(4, "GangZoneCreate");
Expand Down Expand Up @@ -5754,7 +5775,7 @@ static cell AMX_NATIVE_CALL Natives::SendRPC( AMX* amx, cell* params )
if(!pServer)
return 0;

bool bBroadcast = !!(params[1] == -1);
bool bBroadcast = static_cast<int>(params[1]) == -1;
int rpcid = static_cast<int>(params[2]);

PlayerID playerId = bBroadcast ? UNASSIGNED_PLAYER_ID : pRakServer->GetPlayerIDFromIndex(static_cast<int>(params[1]));
Expand Down Expand Up @@ -5833,7 +5854,7 @@ static cell AMX_NATIVE_CALL Natives::SendData( AMX* amx, cell* params )
if(!pServer)
return 0;

bool bBroadcast = !!(params[1] == -1);
bool bBroadcast = static_cast<int>(params[1]) == -1;
PlayerID playerId = bBroadcast ? UNASSIGNED_PLAYER_ID : pRakServer->GetPlayerIDFromIndex(static_cast<int>(params[1]));

if (playerId.binaryAddress == UNASSIGNED_PLAYER_ID.binaryAddress && !bBroadcast)
Expand Down Expand Up @@ -6294,14 +6315,10 @@ AMX_NATIVE_INFO YSINatives [] =

{ "SendRPC", Natives::SendRPC },
{ "SendData", Natives::SendData },
/*
{ "YSF_AddPlayer", Natives::YSF_AddPlayer },
{ "YSF_RemovePlayer", Natives::YSF_RemovePlayer },
{ "YSF_StreamIn", Natives::YSF_StreamIn },
{ "YSF_StreamOut", Natives::YSF_StreamOut },
*/
{"YSF_SetTickRate", Natives::YSF_SetTickRate},
{"YSF_GetTickRate", Natives::YSF_GetTickRate},
{ "YSF_SetTickRate", Natives::YSF_SetTickRate},
{ "YSF_GetTickRate", Natives::YSF_GetTickRate},
{ "YSF_EnableNightVisionFix", Natives::YSF_EnableNightVisionFix },
{ "YSF_IsNightVisionFixEnabled", Natives::YSF_IsNightVisionFixEnabled },
{ "AttachPlayerObjectToObject", Natives::AttachPlayerObjectToObject },

// Format functions
Expand Down
6 changes: 2 additions & 4 deletions src/Scripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,10 @@ namespace Natives
static cell AMX_NATIVE_CALL SendRPC(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL SendData(AMX *amx, cell *params);

static cell AMX_NATIVE_CALL YSF_AddPlayer(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL YSF_RemovePlayer(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL YSF_StreamIn(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL YSF_StreamOut(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL YSF_SetTickRate(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL YSF_GetTickRate(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL YSF_EnableNightVisionFix(AMX *amx, cell *params);
static cell AMX_NATIVE_CALL YSF_IsNightVisionFixEnabled(AMX *amx, cell *params);

static cell AMX_NATIVE_CALL AttachPlayerObjectToObject(AMX *amx, cell *params);

Expand Down
Loading

0 comments on commit b28b374

Please sign in to comment.