Closed JernejL closed 5 years ago
I think this could be done by using SendLastSyncData
in OnPlayerUpdate
then returning 0. You'd need to add a native function to modify keys in the stored sync data (just like SetLastAnimationData
does for the anim).
That will send the data to players tho, and require a bit complex logic and overhead for implementing things like totally manual per-player player updates and that is really inconvinient.. a far better method would be a type of simple setplayerkeys reverse method to somehow alter sa-mp internal data before it's sent out.
Oh so you want to cancel only key updates?
yeah pretty much.. it's to prevent vehicle-bound weapons from firing into "protected" (spawn) areas, basically.. to nullify the keys sent to players incase the player is not allowed to do so.
Ah alright. SendLastSyncData
is for onfoot sync data, so that won't work. I don't remember exactly how it works, but I think the sync data isn't copied to pNetGame->pPlayerPool->pPlayer
until after OnPlayerUpdate
has finished, so modifying won't do anything.
I see 3 solutions:
GetPacketID
hook in hooks.cpp, but it would add some more weight to each player update.OnPlayerKeyStateChange
that's triggered from within the GetPacketID
hook, and make the newkeys
arg pass-by-ref.SetDisabledKeys(playerid, keys)
Every update, the player keys would be set to keys & ~disabledKeys[playerid]
.I can work with that, and also give it really good testing (including data about performance impact of it on the server) so whenever you can give me this to test - i will test it.
I mean, the SetDisabledKeys option.
Wouldn't this also work theoretically thru SetKeySyncBlocked?
The only problem then would be, that i wouldn't know when the player de-pressed the key, making it hard to guess when to re-enable keys syncing..
Yeah but you don't always want to block all keys.
I suppose a really simple way to do this is change SetKeySyncBlocked
to do SetDisabledKeys(playerid, -1)
then change the key sync logic to do & ~blockedKeys[playerid]
.
I mean, blocking all keys will cause things like braking and honking to lose sync while in a vehicle.
I did some tests.. apparently my HOOK_GetPacketID is never called. tests done on windows.
version = 0x0048c8d0
FUNC_GetPacketID = FindPattern("\x8B\x44\x24\x04\x85\xC0\x75\x03\x0C\xFF\xC3", "xxxxxxx???x");
printf(" %08x", FUNC_GetPacketID);
results:
FUNC_GetPacketID = 0x0048dbb0
it's never called.. i verified it - how do i debug this?
The address is for an old version. I fixed it on the Windows DLL published at releases, but never got around to pushing the code changes. I'll do it when I'm back home (where my PC is), but I'm not sure when that will be. Have a look at YSF for the correct address.
The address in kurta's YSF version is found with same method as this one.
https://github.com/kurta999/YSF/blob/5938cb319f5542aa148a098931f670efd829349e/src/Addresses.cpp#L67
The address is found as FUNC_GetPacketID = 0x0048dbb0 yet the hook is never called (i tried several ways to debug it)
The server version is detected as unknown, which disables most things. I pushed an update with the new address (new meaning 3 months ago).
I have removed the unknown version checks, since it didn't appear to affect how addresses are searched, so i just set it as a "generic version" so that things get called. Version only appears to affect getting the restartwaittimer variable anyways.
Anyways, the HOOK_GetPacketID is called, but it crashes when getting packetid:
packet pointer = 0x05e32a60 GetPacketID_hook = 00702a60
crash here: BYTE packetId = ((FUNC_GetPacketID)subhook_get_trampoline(GetPacketID_hook))(p);
[10:25:33] [debug] Server crashed due to an unknown error
error report:
SA-MP Server: 0.3.7-R2 Exception At Address: 0x00000000 Module: (Unknown)
Registers: EAX: 0x00000000 EBX: 0x00000000 ECX: 0x00000000 EDX: 0x00000000 ESI: 0x0018FCE0 EDI: 0x0018FE10 EBP: 0x0018FE10 ESP: 0x0018FCD8 EFLAGS: 0x00210202
Stack: +0000: 0x6189F1D5 0x05F32A60 0x01FD9E98 0x05F32A60 +0010: 0x00000000 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0020: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0030: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0040: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0050: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0060: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0070: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0080: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0090: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +00A0: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +00B0: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +00C0: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +00D0: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +00E0: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +00F0: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0100: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0110: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0120: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0130: 0xCCCCCCCC 0xCCCCCCCC 0x76A110FF 0x0049105C
Oh, yeah, maybe @Zeex knows. I noticed the trampoline functionality of subhook is buggy on Windows. In the fixed code (which unfortunately I don't have access to) I removed the trampoline and used subhook uninstall then install It's explained in the subhook repo.
On 23 okt. 2015, at 10:28, Jernej L. notifications@github.com wrote:
I have removed the unknown version checks, since it didn't appear to affect how addresses are searched, so i just set it as a "generic version" so that things get called.
Anyways, the HOOK_GetPacketID is called, but it crashes when getting packetid:
packet pointer = 0x05e32a60 GetPacketID_hook = 00702a60
crash here: BYTE packetId = ((FUNC_GetPacketID)subhook_get_trampoline(GetPacketID_hook))(p);
[10:25:33] [debug] Server crashed due to an unknown error
error report:
SA-MP Server: 0.3.7-R2 Exception At Address: 0x00000000 Module: (Unknown)
Registers: EAX: 0x00000000 EBX: 0x00000000 ECX: 0x00000000 EDX: 0x00000000 ESI: 0x0018FCE0 EDI: 0x0018FE10 EBP: 0x0018FE10 ESP: 0x0018FCD8 EFLAGS: 0x00210202
Stack: +0000: 0x6189F1D5 0x05F32A60 0x01FD9E98 0x05F32A60 +0010: 0x00000000 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0020: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0030: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0040: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0050: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0060: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0070: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0080: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0090: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +00A0: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +00B0: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +00C0: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +00D0: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +00E0: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +00F0: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0100: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0110: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0120: 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC 0xCCCCCCCC +0130: 0xCCCCCCCC 0xCCCCCCCC 0x76A110FF 0x0049105C
— Reply to this email directly or view it on GitHub.
I will wait for the commit fix.
It should work just fine on Windows now.
if possible, i would like to adapt this plugin to produce some kind of "setplayerkeys" functionality to desync key input depending on script's wishes (inside gamemode's onplayerupdate).
The main problem i have right now is, the current functionality in hooks.cpp can do it it when the packet arrives, but i need to do it after the packet is in sa-mp.
My pathetic and failed attempt was to do the following. I called this within onplayerupdate and it seemed to have no effect:
static cell AMX_NATIVE_CALL Natives::ClearPlayerKeys(AMX* amx, cell* params) { CHECK_PARAMS(1, "ClearPlayerKeys");
}