Vanilla Bug with Multiple Fire Hardpoint Weapons
-
I’ve run up against a vanilla bug with weapons that have multiple HPFire hardpoints: They don’t properly decrement ammo as you’d expect!
The ammo goes down properly in the weapons window tracker in the bottom right, for instance a weapon with 2 HpFires will lower its ammo count by 2 every time you fire. However if you check your ship’s actual cargo or if you try to buy ammunition from a dock after, you’ll notice that the ammo only seems to be going down by 1 each time, no matter how many projectiles are being fired simultaneously each time.
Has anyone formulated a fix for this? The behaviour seems to be consistent between MP and SP, suggesting this is something in server.dll not firing quite right. @Laz and @Aingar have already taken a peek at this and unfortunately haven’t managed to get anywhere with it. Hoping that perhaps @adoxa or @BC46 might have some insight here that we’ve missed?
-
The eventual fix for this, courtesy of @BC46 and @Aingar turned out to be a bit more complicated. Posting it here for visibility:
struct SrvGun { void* vtable; CELauncher* launcher; }; DWORD server; UINT projectilesPerFire; typedef bool (__fastcall HandlePlayerLauncherFire)(SrvGun *srvGun, PVOID _edx, Vector *vector); bool __fastcall HandlePlayerLauncherFire_Hook(SrvGun *srvGun, PVOID _edx, Vector *vector) { projectilesPerFire = srvGun->launcher->GetProjectilesPerFire(); return ((HandlePlayerLauncherFire*) (server + 0xD840))(srvGun, _edx, vector); } __declspec(naked) void SetProjectilesPerFire() { __asm { push 0x3F800000 push [projectilesPerFire] mov eax, [server] add eax, 0xD91A jmp eax } }
server = (DWORD) GetModuleHandleA("server.dll"); Hook(server + 0xD9A9, (DWORD) HandlePlayerLauncherFire_Hook, 5); Hook(server + 0xDC09, (DWORD) HandlePlayerLauncherFire_Hook, 5); Hook(server + 0xE009, (DWORD) HandlePlayerLauncherFire_Hook, 5); Hook(server + 0xD913, (DWORD) SetProjectilesPerFire, 5, true);
This also fixes some serverside issues with ammo counts saving incorrectly on client reconnect,