Repository navigation
Add RTTI-powered dynamic natives - #2598
Closed
adriansmares wants to merge 2 commits into
Closed
adriansmares wants to merge 2 commits into
adriansmares wants to merge 2 commits into
Conversation
adriansmares
force-pushed
the
users/adriansmares/NOTICKET/feature/syntax-exploration-trimmed
branch
from
October 28, 2026 00:54
e8574ee to
5acf7e8
Compare
adriansmares
force-pushed
the
users/adriansmares/NOTICKET/feature/syntax-exploration-trimmed
branch
from
October 28, 2026 01:06
5acf7e8 to
854d0e8
Compare
Member
|
This is not how this should be done. You are hardcoding all sorts of implementation details about the bytecode format. It's not type-safe and does not properly use the runtime mechanisms in the VM. Please wait for actual language support. |
Contributor
Author
|
I shouldn't have opened the PR at all, as it was not meant to be merged, in retrospective. I wanted to explore how feasible it is to implement the simpler Sorry for the noise. |
adriansmares
deleted the
users/adriansmares/NOTICKET/feature/syntax-exploration-trimmed
branch
October 28, 2026 11:21
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.
Dynamic natives currently have to be registered by hand with
CreateNativeinAskPluginLoad2, and implemented as an untypedNativeCall(Handle plugin, int numParams)callback that unpacks its arguments withGetNativeCell,GetNativeStringandGetNativeArray. Withint64and 64-bitAddress, callers pass 64-bit arguments by reference and pass a hidden first argument for 64-bit return values, which shifts the remaining parameter indices.Allow plugins to declare a dynamic native directly as a typed
publicfunction prefixed with__native_(or__native_<Methodmap>__<Method>for methodmap natives):Before calling
AskPluginLoad2, scan the plugin's.publicstable for__native_functions, decode their signature from.rtti.methodsand.rtti.data, and register the stripped native name (MyPlugin_AddGold, orMethodmap.Methodwhen matching a classdef or enum in RTTI). When called, marshal the caller's stack frame onto the targetIPluginFunctionaccording to the RTTI signature—handling cells, by-reference parameters,constand mutable strings, arrays, enum structs,int64values, references and hidden return slots, and variadic arguments—while keepings_curcallerands_curparamsset soFormatNativeStringandIsNativeParamNull*still work inside the callee. A__native_function with a(Handle, int)signature falls back toFakeNativeRouter.Because
Addressis declared astypedef Address = int64in SourceMod 1.13+ andspcompresolves typedefs to their underlying type before emitting.rtti.data,Addressandint64both encode ascb::kInt64in the provider's.rtti.methods. When called by a plugin compiled before SourceMod 1.13 (!UsesInt64Address), inspect the caller'srtti.nativesentry for the native: if the caller compiled that parameter or return slot asenum Address(cb::kEnumpointing to"Address"in.rtti.enums), widen or narrow the 32-bit cell (throwing an error if a 64-bit address does not fit in 32 bits), and otherwise report a signature mismatch error rather than silently truncating anint64to a cell.Also add multi-plugin suite support to the
hl2sdk-mockCI workflow so provider and consumer test plugins underplugins/testsuite/mock/multi/<suite>/are compiled and loaded together on x86 and x86_64.