Skip to content

Commit

Permalink
- Added SetVehicleSpawnInfo
Browse files Browse the repository at this point in the history
- Improved hooks for RakServer::Send, RakServer::RPC
  • Loading branch information
kurta9999 committed Feb 5, 2016
1 parent 40235d5 commit b2281db
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 316 deletions.
24 changes: 9 additions & 15 deletions src/Addresses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ DWORD CAddress::FUNC_Packet_StatsUpdate = NULL;
DWORD CAddress::FUNC_format_amxstring = NULL;

// Others
DWORD CAddress::ADDR_CNetGame_GMX_GangZoneDelete = NULL;
DWORD CAddress::ADDR_CNetGame_GMX_PckupDelete = NULL;

DWORD CAddress::ADDR_GetNetworkStats_VerbosityLevel = NULL;
DWORD CAddress::ADDR_GetPlayerNetworkStats_VerbosityLevel = NULL;

Expand Down Expand Up @@ -89,18 +86,15 @@ void CAddress::Initialize(eSAMPVersion sampVersion)

FUNC_ContainsInvalidChars = FindPattern("\x8B\x4C\x24\x04\x8A\x01\x84\xC0", "xxxxxxxx");
FUNC_GetPacketID = FindPattern("\x8B\x44\x24\x04\x85\xC0\x75\x03\x0C\xFF\xC3", "xxxxxxx???x");

FUNC_CPlayer__SpawnForWorld = FindPattern("\x56\x8B\xF1\x8B\x86\x3B\x26\x00\x00\x85\xC0\x0F\x84", "xxxxx????xxxx");
FUNC_CVehicle__Respawn = FindPattern("\x53\x33\xC0\x56\x8B\xF1\x57\xB9\x10\x00\x00\x00\x8D\x7E\x0C", "xxxxxxxxx???xxx");
FUNC_CPlayerPool__HandleVehicleRespawn = FindPattern("\x53\x56\x57\x8B\x7C\x24\x10\x8D\xB1", "xxxxxx?xx");
FUNC_CPlayerPool__HandleVehicleRespawn = FindPattern("\x53\x55\x56\x8B\xF1\x8B\xAE\x68\x09", "xxxxxx?xx");

FUNC_ProcessQueryPacket = FindPattern("\x83\xEC\x24\x53\x55\x56\x57\x8B\x7C\x24", "xxxxxxxxxx");
FUNC_Packet_WeaponsUpdate = FindPattern("\x6A\xFF\x68\x00\x00\x00\x00\x64\xA1\x0\x0\x0\x0\x50\x64\x89\x25\x0\x0\x0\x0\x81\xEC\x2C\x01\x00\x00\x55\x56", "xx????xx????xxxx????xxxx??xx");
FUNC_Packet_StatsUpdate = FindPattern("\x6A\xFF\x68\x00\x00\x00\x00\x64\xA1\x00\x00\x00\x00\x50\x64\x89\x25\x00\x00\x00\x00\x81\xEC\x20\x01\x00\x00\x56\x57", "xxx????xx????xxxxxxxxxxx???xx");

ADDR_CNetGame_GMX_GangZoneDelete = FindPattern("\x83\xC4\x04\x89\x5E\x24", "xxxxxx") - 0x8;
ADDR_CNetGame_GMX_PckupDelete = FindPattern("\x83\xC4\x04\x89\x5E\x10", "xxxxxx") - 0x8;

ADDR_GetNetworkStats_VerbosityLevel = FindPattern("\x6A\x01\x8D\x4C\x0C", "xxxxx"); // 0x0047362A
ADDR_GetPlayerNetworkStats_VerbosityLevel = FindPattern("\x6A\x01\x8D\x44\x04", "xxxxx"); // 0x004730B9;

Expand Down Expand Up @@ -128,15 +122,18 @@ void CAddress::Initialize(eSAMPVersion sampVersion)
FUNC_GetPacketID = FindPattern("\x55\xB8\x00\x00\x00\x00\x89\xE5\x8B\x55\x00\x85\xD2", "xx????xxxx?xx");

FUNC_CPlayer__SpawnForWorld = FindPattern("\x55\x89\xE5\x56\x53\x83\xEC\x00\x8B\x75\x00\xA1\x00\x00\x00\x00", "xxxxxxx?xx?x????");
FUNC_CVehicle__Respawn = FindPattern("\x55\x31\xD2\x89\xE5\x57\xB9\x40\x00\x00\x00", "xxxxxxxxxxx");

//
DWORD addr = FindPattern("\x55\x31\xD2\x89\xE5\x57\xB9\x40\x00\x00\x00", "xxxxxxxxxxx");
logprintf("addr: %x", addr);

FUNC_CVehicle__Respawn = 0x814B4C0;
FUNC_CPlayerPool__HandleVehicleRespawn = 0x80D1480;

FUNC_ProcessQueryPacket = FindPattern("\x81\xEC\xA8\x00\x00\x00\x89\x5D\xF4\x8B\x5D\x14\x89\x75\xF8", "xxxxxxxxxxxxxxx") - 0x3;
FUNC_Packet_WeaponsUpdate = FindPattern("\x55\x31\xC0\x89\xE5\x81\xEC\x58\x01\x00\x00", "xxxxxxxxxxx");
FUNC_Packet_StatsUpdate = FindPattern("\x55\x31\xD2\x89\xE5\x81\xEC\x58\x01\x00\x00\x89\x5D\xF4", "xxxxxxxxxxxxxx"); // 80AD430

ADDR_CNetGame_GMX_GangZoneDelete = NULL;
ADDR_CNetGame_GMX_PckupDelete = NULL;

ADDR_GetNetworkStats_VerbosityLevel = FindPattern("\xB8\x01\x00\x00\x00\x83\xD9\x03", "xxxxxxxx");
ADDR_GetPlayerNetworkStats_VerbosityLevel = FindPattern("\xBB\x01\x00\x00\x00\x83\xD9\x03", "xxxxxxxx"); // 080DD7FA

Expand Down Expand Up @@ -183,9 +180,6 @@ void CAddress::Initialize(eSAMPVersion sampVersion)
logprintf("FUNC_Packet_WeaponsUpdate: %X", FUNC_Packet_WeaponsUpdate);
logprintf("FUNC_Packet_StatsUpdate: %X", FUNC_Packet_StatsUpdate);

logprintf("ADDR_CNetGame_GMX_GangZoneDelete: %X", ADDR_CNetGame_GMX_GangZoneDelete);
logprintf("ADDR_CNetGame_GMX_PckupDelete: %X", ADDR_CNetGame_GMX_PckupDelete);

logprintf("ADDR_GetNetworkStats_VerbosityLevel: %X", ADDR_GetNetworkStats_VerbosityLevel);
logprintf("ADDR_GetPlayerNetworkStats_VerbosityLevel: %X", ADDR_GetPlayerNetworkStats_VerbosityLevel);

Expand Down
57 changes: 0 additions & 57 deletions src/CCallbackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,61 +265,4 @@ void CCallbackManager::OnVehicleSpawn(WORD vehicleid)
amx_Exec(*iter, &ret, idx);
}
}
}

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

if (playerid >= 0 && playerid < MAX_PLAYERS)
{
#ifndef NEW_PICKUP_SYSTEM
pServer->AddPlayer(playerid);
#else
// Initialize pickups
if (pServer->AddPlayer(playerid))
pNetGame->pPickupPool->InitializeForPlayer(playerid);
#endif
}
return true;
}

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(static_cast<WORD>(playerid), static_cast<WORD>(forplayerid));
return true;
}

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

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

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

if (IsPlayerConnectedEx(playerid))
{
pPlayerData[playerid]->bControllable = true;
}
return true;
}
2 changes: 1 addition & 1 deletion src/CServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CServer::CServer(eSAMPVersion version)
// Initialize addresses
CAddress::Initialize(version);
// Initialize SAMP Function
CSAMPFunctions::Initialize();
CSAMPFunctions::PreInitialize();

// Initialize default valid name characters
for(BYTE i = '0'; i <= '9'; i++)
Expand Down
131 changes: 80 additions & 51 deletions src/Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ Packet_StatsUpdate_t CSAMPFunctions::pfn__Packet_StatsUpdate = NULL;

format_amxstring_t CSAMPFunctions::pfn__format_amxstring = NULL;

void CSAMPFunctions::Initialize()
RakNet__Send_t CSAMPFunctions::pfn__RakNet__Send = NULL;
RakNet__RPC_t CSAMPFunctions::pfn__RakNet__RPC = NULL;

void CSAMPFunctions::PreInitialize()
{
pfn__CConsole__AddStringVariable = (CConsole__AddStringVariable_t)(CAddress::FUNC_CConsole__AddStringVariable);
pfn__CConsole__GetStringVariable = (CConsole__GetStringVariable_t)(CAddress::FUNC_CConsole__GetStringVariable);
Expand All @@ -47,6 +50,34 @@ void CSAMPFunctions::Initialize()
pfn__format_amxstring = (format_amxstring_t)(CAddress::FUNC_format_amxstring);
}

void CSAMPFunctions::PostInitialize()
{
// Get pNetGame
int (*pfn_GetNetGame)(void) = (int(*)(void))ppPluginData[PLUGIN_DATA_NETGAME];
pNetGame = (CNetGame*)pfn_GetNetGame();

// Get pConsole
int (*pfn_GetConsole)(void) = (int(*)(void))ppPluginData[PLUGIN_DATA_CONSOLE];
pConsole = (void*)pfn_GetConsole();

// Get pRakServer
int (*pfn_GetRakServer)(void) = (int(*)(void))ppPluginData[PLUGIN_DATA_RAKSERVER];
pRakServer = (RakServer*)pfn_GetRakServer();

// Init Send, RPC hook
int *pRakServer_VTBL = ((int*)(*(void**)pRakServer));
//logprintf("pRakServer_VTBL: %x", pRakServer_VTBL);

Unlock((void*)&pRakServer_VTBL[RAKNET_SEND_OFFSET], 4);
Unlock((void*)&pRakServer_VTBL[RAKNET_RPC_OFFSET], 4);

pfn__RakNet__Send = (RakNet__Send_t)(pRakServer_VTBL[RAKNET_SEND_OFFSET]);
pfn__RakNet__RPC = (RakNet__RPC_t)(pRakServer_VTBL[RAKNET_RPC_OFFSET]);

pRakServer_VTBL[RAKNET_SEND_OFFSET] = (int)CHookRakServer::Send;
pRakServer_VTBL[RAKNET_RPC_OFFSET] = (int)CHookRakServer::RPC_2;
}

void CSAMPFunctions::AddStringVariable(char *szRule, int flags, char *szString, void *changefunc)
{
pfn__CConsole__AddStringVariable(pConsole, szRule, flags, szString, changefunc);
Expand Down Expand Up @@ -127,81 +158,79 @@ char* CSAMPFunctions::format_amxstring(AMX *amx, cell *params, int parm, int &le
return pfn__format_amxstring(amx, params, parm, len);
}

bool CSAMPFunctions::Send(void* ppRakServer, RakNet::BitStream* parameters, PacketPriority priority, PacketReliability reliability, unsigned orderingChannel, PlayerID playerId, bool broadcast)
{
return pfn__RakNet__Send(ppRakServer, parameters, priority, reliability, orderingChannel, playerId, broadcast);
}

bool CSAMPFunctions::RPC(void* ppRakServer, int* uniqueID, RakNet::BitStream* parameters, PacketPriority priority, PacketReliability reliability, unsigned orderingChannel, PlayerID playerId, bool broadcast, bool shiftTimestamp)
{
return pfn__RakNet__RPC(ppRakServer, uniqueID, parameters, priority, reliability, orderingChannel, playerId, broadcast, shiftTimestamp);
}

void CSAMPFunctions::RespawnVehicle(CVehicle *pVehicle)
{
/*
memset(&pVehicle->vehMatrix, 0, sizeof(MATRIX4X4));
memset(&pVehicle->vecVelocity, 0, sizeof(CVector));
memset(&pVehicle->vecTurnSpeed, 0, sizeof(CVector));
memset(&pVehicle->vehModInfo, 0, sizeof(CVehicleModInfo));

pVehicle->vehModInfo.iColor1 = -1;
pVehicle->vehModInfo.iColor2 = -1;
pVehicle->vehMatrix.pos = pVehicle->customSpawn.vecPos;
pVehicle->vecPosition = pVehicle->customSpawn.vecPos;
pVehicle->vehLightStatus = 0;
pVehicle->fHealth = 1000.0f;
pVehicle->vehDoorStatus = 0;
pVehicle->vehTireStatus = 0;
pVehicle->vehPanelStatus = 0;
pVehicle->vehLightStatus = 0;
pVehicle->vehTireStatus = 0;
pVehicle->bDead = 0;
pVehicle->bDeathNotification = 0;
pVehicle->bOccupied = 0;
pVehicle->vehRespawnTick = GetTickCount();
pVehicle->vehOccupiedTick = GetTickCount();
pVehicle->vehParamEx.alarm = -1;
pVehicle->vehParamEx.bonnet = -1;
pVehicle->vehParamEx.boot = -1;
pVehicle->vehParamEx.doors = -1;
pVehicle->vehParamEx.engine = -1;
pVehicle->vehParamEx.lights = -1;
pVehicle->vehParamEx.objective = -1;
pVehicle->vehOccupiedTick = GetTickCount();
if (pNetGame && pNetGame->pPlayerPool)
pfn__CPlayerPool__HandleVehicleRespawn(pNetGame->pPlayerPool, pVehicle->wVehicleID);
pVehicle->vehParamEx.siren = -1;
pVehicle->vehParamEx.door_driver = -1;
pVehicle->vehParamEx.door_passenger = -1;
pVehicle->vehParamEx.door_backleft = -1;
pVehicle->vehParamEx.door_backright = -1;
pVehicle->vehParamEx.window_driver = -1;
pVehicle->vehParamEx.window_passenger = -1;
pVehicle->vehParamEx.window_backleft = -1;
pVehicle->vehParamEx.window_backright = -1;
// logprintf("respawned vehicle: %d", pVehicle->wVehicleID);

// Check if vehicle has custom spawn
std::map<int, CVehicleSpawn>::iterator v = pServer->vehicleSpawnData.find(pVehicle->wVehicleID);
if(v == pServer->vehicleSpawnData.end())
{
CCallbackManager::OnVehicleSpawn(pVehicle->wVehicleID);

}
else // Törlés és létrehozás de ez kurvára nem kész itt
// If yes, then re-create the vehicle at different location
else
{
RakNet::BitStream bsVehicleSpawn;
CVehicleModInfo CarModInfo;
memset(&CarModInfo,0,sizeof(CVehicleModInfo));
bsVehicleSpawn.Write(pVehicle->wVehicleID);
bsVehicleSpawn.Write(spawn.iModelID);
bsVehicleSpawn.Write(spawn.vecPos);
bsVehicleSpawn.Write(spawn.fRot);
bsVehicleSpawn.Write(spawn.iColor1);
bsVehicleSpawn.Write(spawn.iColor2);
bsVehicleSpawn.Write((float)1000.0f);
// now add spawn co-ords and rotation
bsVehicleSpawn.Write(spawn.vecPos);
bsVehicleSpawn.Write(spawn.fRot);
bsVehicleSpawn.Write(spawn.iInterior);
if(pVehicle->szNumberplate[0] == '\0') {
bsVehicleSpawn.Write(false);
} else {
bsVehicleSpawn.Write(true);
bsVehicleSpawn.Write((PCHAR)pVehicle->szNumberplate, 9);
}
if(!memcmp((void *)&CarModInfo,(void *)&CarModInfo,sizeof(CVehicleModInfo))) {
bsVehicleSpawn.Write(false);
} else {
bsVehicleSpawn.Write(true);
bsVehicleSpawn.Write((PCHAR)&CarModInfo, sizeof(CarModInfo));
}
pServer->vehicleSpawnData.erase(pVehicle->wVehicleID);
pVehicle->customSpawn.iModelID = v->second.iModelID;
pVehicle->customSpawn.vecPos = v->second.vecPos;
pVehicle->customSpawn.fRot = v->second.fRot;
pVehicle->customSpawn.iColor1 = v->second.iColor1;
pVehicle->customSpawn.iColor2 = v->second.iColor2;
pVehicle->customSpawn.iRespawnTime = v->second.iRespawnTime;
pVehicle->customSpawn.iInterior = v->second.iInterior;

// logprintf("custom vehicle spawn respawned %d", pVehicle->wVehicleID);
pServer->vehicleSpawnData.erase(v);
}
*/

pVehicle->vehModInfo.iColor1 = pVehicle->customSpawn.iColor1;
pVehicle->vehModInfo.iColor2 = pVehicle->customSpawn.iColor2;
pVehicle->vehMatrix.pos = pVehicle->customSpawn.vecPos;
pVehicle->vecPosition = pVehicle->customSpawn.vecPos;

if (pNetGame && pNetGame->pPlayerPool)
pfn__CPlayerPool__HandleVehicleRespawn(pNetGame->pPlayerPool, pVehicle->wVehicleID);

CCallbackManager::OnVehicleSpawn(pVehicle->wVehicleID);
}
Loading

0 comments on commit b2281db

Please sign in to comment.