Enhance vehicle color synchronization and rendering consistency#5000
Enhance vehicle color synchronization and rendering consistency#5000QueryOfficial wants to merge 3 commits into
Conversation
- Updated CVehicleSA::SetColor to synchronize GTA's palette indices with MTA's RGB cache, ensuring accurate color representation during rendering. - Modified CClientVehicle::Create to apply MTA colors before vehicle rendering, preventing default palette colors from being used prematurely. - Adjusted CMultiplayerSA::InitHooks to ensure correct color slot indexing for vehicle color hooks, addressing potential desynchronization issues. - Implemented safeguards in SaveVehColors to prevent color reuse from previous vehicles, ensuring accurate color data during vehicle creation. These changes improve the visual fidelity and consistency of vehicle colors across different game states.
- Updated the color slot indexing logic in CMultiplayerSA::InitHooks to ensure accurate mapping between GTA's palette indices and MTA's RGB cache. - Adjusted memory copy operations to correct offsets for setting vehicle color slots, enhancing synchronization and preventing potential desynchronization issues. These changes improve the consistency of vehicle color rendering across different game states.
Besides that looks good! |
|
Good points, thanks — dropped the redundant early Create() SetColor hunk and rewrote the root-cause comment to reflect that the movzx patch matters on non-SetupRender paths, not the SetupRender path where HOOK_VehCol already sets slot indices. Also removed the unnecessary m_colour1–4 sync in CVehicleSA::SetColor. |
- Removed outdated color synchronization logic from CVehicleSA::SetColor to streamline color setting. - Eliminated premature color application in CClientVehicle::Create to prevent default palette colors from being used before rendering. - Updated comments for clarity on vehicle color handling. These changes enhance the efficiency of vehicle color management and improve rendering consistency.
Summary
Fix vehicle colors 3 and 4 randomly disappearing after a vehicle streams out and back in.
MTA applies custom RGB vehicle colors by hooking GTA's
CVehicleModelInfo::SetEditableMaterialsCB. The hook writesvehColors[esi]onto editable materials, butesiwas a GTA palette index, not the color slot (0–3). That mismatch caused tertiary/quaternary materials to read the wrong entry from the sharedvehColorsbuffer—most notably quaternary (ms_currentCol[3] == 0) always usingvehColors[0](primary).This PR:
CMultiplayerSA.cpp– Patches the fourmovzx esi, ms_currentCol[n]sites inSetEditableMaterialsCBsoesiholds the slot index (0–3) beforeHOOK_VehColCBruns. Clears the globalvehColorsbuffer whenSaveVehColorscannot resolve an MTA vehicle, so stale colors from a previously rendered vehicle are not reused.CVehicleSA.cpp– UpdatesSetColorto syncm_colour1–m_colour4on the GTA vehicle interface from the RGB values, so engine paths that read palette indices (e.g.CVehicle::SetupRender) stay consistent after stream-in recreation.CClientVehicle.cpp– Applies saved MTA colors immediately afterAddVehicle/SetStoredPointerduringCreate(), before other setup that may trigger rendering, so the first post-stream-inSetupRenderdoes not use GTA's default palette colors.Colors 1 and 2 often appeared correct because secondary is hardcoded to palette index
1in the existing hook path, which accidentally matched slot1. Tertiary/quaternary had no such luck and failed intermittently depending on palette values and render order.Motivation
Fixes #4982.
Reported behaviour: after
setVehicleColorwith all four RGB colors, colors 1 and 2 remain correct while colors 3 and/or 4 can reset or vanish when the vehicle streams out and back in. The issue is intermittent because it depends on palette indices, shared global state, and timing around stream-in.Root cause:
HOOK_VehColCBtreatsesias avehColorsarray index, but GTA stores a palette table index inesiat that point. Quaternary materials always ended up with index0, so they showed the primary color or black instead of the intended RGB value.Test plan
setVehicleColor:setVehicleColor(veh, p1, p2, p3, p4)Checklist