better-modernized-combat / bmod-client

Freelancer: Better Modernized Combat (BMOD) is a modification for Freelancer, the 2003 space shooter by Digital Anvil. The core goal of the mod is to create a fun and compelling PvE experience for solo and group players in a multiplayer setting.
GNU General Public License v3.0
0 stars 0 forks source link

Multiple firepoint weapons not decrementing ammo correctly #126

Closed Beaglerush closed 3 months ago

Beaglerush commented 4 months ago

Weapons that have multiple firepoints on their model, like the Twin missile launchers or the Drone Mine, are not decrementing their ammo as you'd expect. The ammo goes down properly in the weapons window tracker in the bottom right, for instance a Twin missile launcher 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.

Not sure what causes this bug but it would be a good one to fix before 0.1 ends.

IrateRedKite commented 4 months ago

Upgrading this to P1. I hadn't noticed this behaviour, but it's a pretty big deal if it can be reproduced. Might not be something we can fix, but imo it's a fairly critical one

IrateRedKite commented 4 months ago

Possibly related to #62

IrateRedKite commented 4 months ago

Successfully replicated this behaviour. This occurs in SP as well and will require a client hook fix. @Lazrius is helping out with this one.

IrateRedKite commented 4 months ago

Moving this one to blocked. There's something not firing right in server.dll, but we were unable to detemine what. I've fired this one over to Adoxa et al in the hopes of getting a fix, but not promises on this one: https://the-starport.com/forums/topic/6289/vanilla-bug-with-multiple-fire-hardpoint-weapons

IrateRedKite commented 4 months ago

This is actually related to @Venemon's multi HPFire fix. For now I'm going to disable the offset and we can attach multiple HpFire sounds to the barrel flash FX.

IrateRedKite commented 4 months ago

Pushed fixes with 075a643e3f1f3e5098e3faf83d9e375cbbdba454 and 9ae2b04dfc0ede51a945c26164935edca6fe29d5, moving this to in review until 0.0.14 is merged. It'd be good to get the HpFire sound fixes for applicable weapons under here too. @Beaglerush, do you have a list of twin-firing weapons handy? I think it's pretty small right now.

IrateRedKite commented 4 months ago

Marking this one as resolved with 0.0.14. Have opened a new issue in #130 for the silent weapons.

Beaglerush commented 4 months ago

Thanks for the fix!

IrateRedKite commented 4 months ago

Full fix for all currently known multiple HpFire issues, courtesy of @Aingar and @BC46:

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);
Beaglerush commented 4 months ago

That's fantastic, thank you. Really relieved to have this.

IrateRedKite commented 4 months ago

Fix for this and other HpFire issues has been implemented in 0.0.14 with e6d88a01d7083e1614e04545adb36dc7b4e3086a

    Utils::Memory::PatchCallAddr(PCHAR(mod), 0xD9A9, PCHAR(HandlePlayerLauncherFire_Hook));
    Utils::Memory::PatchCallAddr(PCHAR(mod), 0xDC09, PCHAR(HandlePlayerLauncherFire_Hook));
    Utils::Memory::PatchCallAddr(PCHAR(mod), 0xE009, PCHAR(HandlePlayerLauncherFire_Hook));
    Utils::Memory::Patch(PBYTE(mod + 0xD913), SetProjectilesPerFire);