Vanilla-Conquer
Vanilla-Conquer copied to clipboard
[TD+RA] Numerous Remastered PlayerPtr Bugs (Often Manifests as Sound/GFX for Wrong Player)
I apologize in advance for the longwinded explanation. This is an ugly hairball of a bug cluster.
In legacy C&C and standalone Vanilla Conquer, multiplayer is done in a peer-to-peer manner. Input handling is done locally. The game commands resulting from input are sent over the wire to a synchronized event queue. Once events come out of the queue, the same code executes in parallel on every PC participating in the match. When there is something (south of the event queue) that should only happen for one particular player, that code is gated behind a comparison against PlayerPtr, which is a global HouseClass* that points to the local player (or against another variable that was previously set via comparison to PlayerPtr).
The Remastered GlyphX client does multiplayer in a client-server manner. Rather than add a peer-to-peer mode to the GlyphX client, Petroglyph chose to hacksaw C&C to make it work in a client-server paradigm. This was likely a mistake. Remastered LAN multiplayer goes something like this: One PC is randomly chosen to be the server; others are clients. The GlyphX clients send raw keyboard/mouse inputs to the server, which feeds them to the dll. On the server, PlayerPtr is generally pointed at the local player's house. For input handling functions and HouseClass::AI(), PlayerPtr is changed to the relevant player's house, and then changed back again to the server's house afterward. Unfortunately, there are about a billion places where there's a check against PlayerPtr occurring in code that Remastered only runs in the context of PlayerPtr pointing at the server's house.
The most obvious manifestations of this are sound/voice/graphical effects that play for the server's house instead of the house they're supposed to play for.
To fix this for a Remastered mod, you need to rewrite the conditional in terms of who own something (thus eliminating the reference to PlayerPtr), and then directly call some dll API function that gives you control over which player the function runs for. Vanilla Conquer will have a painful extra step of wrapping all these fixes into #ifdef statements to restrict them to Remastered, since the original code is (mostly) correct for peer-to-peer.
I've fixed a bunch of these in CFE Patch Redux, and yet I've probably overlooked more of them than I've fixed:
- RA Bugfixes for Clicked_As_Target() being called for wrong house, makes flash visible to wrong player (Buried in a huge commit, sorry!)
- TD Bugfixes for Clicked_As_Target() being called for wrong house, makes flash visible to wrong player
- Sound/voice for the wrong player bugfixes
- More sounds/voices for the wrong player bugfixes
- Even more sounds/voices for the wrong player bugfixes