Repository navigation
iw3 replaceFunc - #233
Merged
Merged
iw3 replaceFunc#233
Conversation
michaeloliverx
force-pushed
the
iw3-replaceFunc
branch
from
October 6, 2026 11:44
5063313 to
4df38fc
Compare
Owner
|
Refactored some stuff, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: Add GSC replaceFunc support for IW3 multiplayer
Summary
This change adds a new GSC builtin, replaceFunc, that allows one GSC function
to be replaced by another function at runtime. It is intended for mods that
need to override or extend existing script behavior without editing the
original function directly.
What replaceFunc does
replaceFunc takes two function references:
The first function is the function to intercept, and the second function is
the function that should run in its place. The replacement is registered by
the compiled code positions of both functions. When the script VM is about to
execute a registered original function, the VM hook resolves that code
position to the replacement code position and continues execution from the
replacement function.
This makes it possible for a mod to redirect existing script callbacks or
functions while leaving the original game script files unchanged.
Implementation details
function is called.
behavior easy to verify during development.
Game and VM lifecycle
Replacement entries are only valid for the current script VM/game state. All
registered replacements are cleared during the script shutdown hook, before
the original shutdown routine continues. This is important because compiled
GSC code positions can become invalid after a game or map is shut down.
The cleanup runs every time the current game is shut down, so old replacement
functions do not carry over into a new game. Each new game starts with a clean
replacement table and can register its own mappings safely. Clearing the map
removes the old replacement registrations; it does not modify or delete the
original GSC functions.
Status
The implementation works perfectly in its intended use: functions register
correctly, calls are redirected through the VM to their replacements, invalid
arguments are rejected with a diagnostic, and all old replacement entries are
cleared when the game shuts down before the next game starts.
This keeps replaceFunc reliable across map/game transitions and prevents stale
function pointers from being reused by a later script VM instance.