Skip to content

Add snapshots patching plugin API#450

Open
ObelardO wants to merge 2 commits into
callofduty4x:masterfrom
ObelardO:snapshot-patch-api
Open

Add snapshots patching plugin API#450
ObelardO wants to merge 2 commits into
callofduty4x:masterfrom
ObelardO:snapshot-patch-api

Conversation

@ObelardO

@ObelardO ObelardO commented Jun 23, 2026

Copy link
Copy Markdown

Summary

  • Add minimal hook calls in SV_BuildClientSnapshot so plugins can modify outgoing per-client snapshots without rewriting snapshot build logic.
  • Implement snapshot patch dispatch in new plugin_snapshot_patching.c (registration, chained multi-plugin callbacks, sorted append for injected entities/clientStates).
  • Expose plugin API: three patch hooks (playerState, entity, clientState) with SNAPSHOT_PATCH_MODIFY / SNAPSHOT_PATCH_APPEND modes, plus archived client lookup helpers for killcam replay.

Design

  • sv_snapshot.c only calls thin wrappers; all plugin-specific logic lives in plugin_snapshot_patching.c.
  • Multiple plugins can register hooks; callbacks run in plugin slot order (chained MODIFY, each plugin may APPEND).
  • function_declarations.h and plugin_exports.c export register/unregister and Plugin_SV_GetArchived* helpers.

Test plan

  • Server builds on Windows/Linux
  • Plugin loads and registers snapshot patch callbacks without errors
  • Existing plugins unaffected when no snapshot patch is registered
  • Two plugins registering snapshot hooks both receive MODIFY/APPEND calls in order
  • Archived client origin/entity/state helpers return expected replay data during killcam

Notes

Companion plugin (FinalKillcamEntityCamera) lives on fork branch final-killcam-plugin and is intentionally not included in this PR.

@proxict

proxict commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Hi, could you please elaborate what your goal is with these changes?

@ObelardO

ObelardO commented Jul 6, 2026

Copy link
Copy Markdown
Author

Hi! I'm currently working on a couple of plugins for my server:

  1. An anti-cheat plugin that can modify outgoing snapshots. My goal is to strip redundant data, for instance, based on player distance.

  2. A final killcam plugin capable of replaying match events with specific modifications. For example, a third-person killcam for entities like explosives, vehicles, or killstreaks. The stock game has an issue where the killcam's camera angle is calculated client-side and is bound to the player watching the killcam rather than the player getting killed in it. To avoid modifying the client files, I'm using some entity-spoofing workarounds.

@Caball009

Caball009 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

These are very specific features that most server owners will have no use for. What's stopping you from using these changes just in your own fork?

the killcam's camera angle is calculated client-side

I don't think that's entirely accurate. What makes you say so?

@ObelardO

Copy link
Copy Markdown
Author

These are very specific features that most server owners will have no use for. What's stopping you from using these changes just in your own fork?

I understand your point, and that is exactly why I tried to keep the core codebase as untouched as possible. My main goal is to ensure my mod works out-of-the-box with the official CoD4x build. While the mod-specific features are highly customizable, I really want to avoid forcing my users to depend on a custom server build.

the killcam's camera angle is calculated client-side

I don't think that's entirely accurate. What makes you say so?

I might be mistaken, but here is what I’ve gathered from analyzing both the server and client source code, as well as testing:

  1. There is no final killcam in the stock game, and it wasn't originally designed for players to watch someone else's perspective or an external entity's view this way.
  2. Stock killcams only support entities like the helicopter and airstrike.
  3. For the helicopter and airstrike, the camera's Yaw axis aligns with the killing entity.
  4. The camera distance is controlled by the server via specific dvars.
  5. Horizontal axis rotation (pitch) seems to be handled natively on the client side, targeting the player who is currently watching the killcam. In the stock logic, the this is always the killed player, but in a final killcam, this is not the same player who was killed. For example, the camera ends up looking straight down at the ground if the killcam spectating player (who isn't the one who was killed) happens to be positioned behind the killer entity (explosive for ex.)

I could be wrong about the exact internal client logic, but based on my research, I managed to fix this entirely via a plugin, and it works perfectly. To achieve this without modifying the native client binary, I had to spoof/modify certain fields inside the snapshots on the server side specifically during the final killcam.

I am not insisting on these changes. I want to avoid maintaining a custom server build and, more importantly, ensure my mod doesn't depend on a specific server fork. That is why I kept modifications minimal, structuring them as additive API methods and callbacks in the snapshot pipeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants