Skip to content

Commit

Permalink
Added support for 0.3.7 R2
Browse files Browse the repository at this point in the history
- now plugin shouldn't crash if loaded with invalid server version, just
memory hacking functions shouldn't work
  • Loading branch information
kurta9999 committed Jul 13, 2015
1 parent 92cccd2 commit 1c73512
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 92 deletions.
7 changes: 4 additions & 3 deletions src/Addresses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ DWORD CAddress::FUNC_Logprintf_03ZR2_2 = 0x00487310;
DWORD CAddress::FUNC_Logprintf_03ZR3 = 0x00487460;
DWORD CAddress::FUNC_Logprintf_03ZR4 = 0x004875F0;
DWORD CAddress::FUNC_Logprintf_037 = 0x0048A0B0;
DWORD CAddress::FUNC_Logprintf_037_R2 = 0x0048C860;
#else
DWORD CAddress::FUNC_Logprintf_03Z = 0x080A7440;
DWORD CAddress::FUNC_Logprintf_03ZR2_2 = 0x080A77D0;
DWORD CAddress::FUNC_Logprintf_03ZR3 = 0x080A78E0;
DWORD CAddress::FUNC_Logprintf_03ZR4 = 0x80A7A90;
DWORD CAddress::FUNC_Logprintf_037 = 0x080A9000;
DWORD CAddress::FUNC_Logprintf_037_R2 = 0x080A91D0;
#endif

// Pointers
Expand Down Expand Up @@ -120,8 +122,7 @@ void CAddress::Initialize(eSAMPVersion sampVersion)
}
}
#endif

#ifdef print_addresses
/*
logprintf("VAR_pRestartWaitTime: %X", VAR_pRestartWaitTime);
logprintf("FUNC_CConsole__AddStringVariable: %X", FUNC_CConsole__AddStringVariable);
Expand All @@ -146,7 +147,7 @@ void CAddress::Initialize(eSAMPVersion sampVersion)
logprintf("ADDR_CNetGame_GMX_PckupDelete: %X", ADDR_CNetGame_GMX_PckupDelete);
logprintf("FUNC_format_amxstring: %X", FUNC_format_amxstring);
#endif
*/
// Unlock restart wait time
if (VAR_pRestartWaitTime)
Unlock((void*)VAR_pRestartWaitTime, 4);
Expand Down
2 changes: 2 additions & 0 deletions src/Addresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ enum eSAMPVersion
{
SAMP_VERSION_UNKNOWN,
SAMP_VERSION_037,
SAMP_VERSION_037_R2,

SAMP_VERSION_SKIPPED,
};
Expand All @@ -61,6 +62,7 @@ class CAddress
static DWORD FUNC_Logprintf_03ZR3;
static DWORD FUNC_Logprintf_03ZR4;
static DWORD FUNC_Logprintf_037;
static DWORD FUNC_Logprintf_037_R2;

// Pointers
static DWORD VAR_ppNetGame;
Expand Down
15 changes: 15 additions & 0 deletions src/CCallbackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ void CCallbackManager::OnVehicleSpawn(WORD vehicleid)

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerConnect(int playerid)
{
if(!pServer)
return true;

if (playerid >= 0 && playerid < MAX_PLAYERS)
{
bool ret = pServer->AddPlayer(playerid);
Expand All @@ -283,24 +286,36 @@ PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerConnect(int playerid)

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerDisconnect(int playerid, int reason)
{
if(!pServer)
return true;

pServer->RemovePlayer(playerid);
return true;
}

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerStreamIn(int playerid, int forplayerid)
{
if(!pServer)
return true;

pServer->OnPlayerStreamIn(playerid, forplayerid);
return true;
}

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerStreamOut(int playerid, int forplayerid)
{
if(!pServer)
return true;

pServer->OnPlayerStreamOut(playerid, forplayerid);
return true;
}

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerSpawn(int playerid)
{
if(!pServer)
return true;

if (IsPlayerConnectedEx(playerid))
{
pPlayerData[playerid]->bControllable = true;
Expand Down
93 changes: 6 additions & 87 deletions src/Scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4649,96 +4649,12 @@ static cell AMX_NATIVE_CALL Natives::SendRconCommandf( AMX* amx, cell* params )
return 1;
}

// native YSF_AddPlayer(playerid);
static cell AMX_NATIVE_CALL Natives::YSF_AddPlayer( AMX* amx, cell* params )
{
/*
// If unknown server version
if(!pServer)
return 0;
// We only allow to call this function from gamemode
if (&pNetGame->pGameModePool->m_amx != amx) return 0;
CHECK_PARAMS(1, "YSF_AddPlayer");
int playerid = (int)params[1];
PlayerID playerId = pRakServer->GetPlayerIDFromIndex(playerid);
// If player is not connected
if (playerId.binaryAddress == UNASSIGNED_PLAYER_ID.binaryAddress)
return 0;
cell ret = pServer->AddPlayer(playerid);
#ifdef NEW_PICKUP_SYSTEM
// Initialize pickups
if(ret)
pNetGame->pPickupPool->InitializeForPlayer(playerid);
#endif
*/
return 1;
}

// native YSF_RemovePlayer(playerid);
static cell AMX_NATIVE_CALL Natives::YSF_RemovePlayer( AMX* amx, cell* params )
{
/*
// If unknown server version
if(!pServer)
return 0;
// We only allow to call this function from gamemode
if (&pNetGame->pGameModePool->m_amx != amx) return 0;
CHECK_PARAMS(1, "YSF_RemovePlayer");
//logprintf("YSF_RemovePlayer - connected: %d, raknet geci: %d", pNetGame->pPlayerPool->bIsPlayerConnectedEx[(int)params[1]], pRakServer->GetPlayerIDFromIndex((int)params[1]).binaryAddress);
int playerid = (int)params[1];
pServer->RemovePlayer(playerid);
*/
return 1;
}

// native YSF_StreamIn(playerid, forplayerid);
static cell AMX_NATIVE_CALL Natives::YSF_StreamIn( AMX* amx, cell* params )
{
/*
// If unknown server version
if(!pServer)
return 0;
// We only allow to call this function from gamemode
if (&pNetGame->pGameModePool->m_amx != amx) return 0;
CHECK_PARAMS(2, "YSF_StreamIn");
pServer->OnPlayerStreamIn((WORD)params[1], (WORD)params[2]);
*/
return 1;
}

// native YSF_StreamOut(playerid, forplayerid);
static cell AMX_NATIVE_CALL Natives::YSF_StreamOut( AMX* amx, cell* params )
{
/*
// If unknown server version
if(!pServer)
return 0;
// We only allow to call this function from gamemode
if (&pNetGame->pGameModePool->m_amx != amx) return 0;
CHECK_PARAMS(2, "YSF_StreamOut");
pServer->OnPlayerStreamOut((WORD)params[1], (WORD)params[2]);
*/
return 1;
}

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

CHECK_PARAMS(1, "YSF_SetTickRate");

int rate = (int)params[1];
Expand All @@ -4751,6 +4667,9 @@ static cell AMX_NATIVE_CALL Natives::YSF_SetTickRate( AMX* amx, cell* params )
// native YSF_GetTickRate();
static cell AMX_NATIVE_CALL Natives::YSF_GetTickRate( AMX* amx, cell* params )
{
if(!pServer)
return 1;

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

Expand Down
11 changes: 9 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ PLUGIN_EXPORT bool PLUGIN_CALL Load(void ** ppData)
version = SAMP_VERSION_037;
strcpy(szVersion, "0.3.7");
}

else if (addr == CAddress::FUNC_Logprintf_037_R2)
{
version = SAMP_VERSION_037_R2;
strcpy(szVersion, "0.3.7 R2");
}
//logprintf("skipgeci: %d", GetServerCfgOption("ysf_skipversioncheck").c_str());

if (1)
Expand Down Expand Up @@ -161,5 +165,8 @@ PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX * amx)

PLUGIN_EXPORT void PLUGIN_CALL ProcessTick()
{
pServer->Process();
if(pServer)
{
pServer->Process();
}
}

0 comments on commit 1c73512

Please sign in to comment.