Skip to content

Update 2.8.0

Burkino edited this page Jul 1, 2021 · 2 revisions

SX v2.8.0 released - changelog:

[+] This update adds ArgGuard, which is a new automated protection mechanism for metatable hooks which is designed to reduce code complexity required for them. See below for details.

In essence, ArgGuard will check if the arguments passed to a metatable hook are 'potentially valid' for that metamethod (do note the 'potentially valid' part - ArgGuard is a limited protection and is not a replacement for poor coding practices)

ArgGuard eliminates the need for using varargs for metamethod hooks where they weren't required before the detection wave hit last week. You can now safely use your old metamethod hooks, as long as they now use hookmetamethod (which is now implemented in C)

If ArgGuard detects invalid parameters are passed, it will skip over your hook and simply call the original function. Of course, some developers might want to handle all cases, in which case you can now pass false to the 4th parameter of hookmetamethod to disable this protection. By default, it is now enabled for all metamethod hooks.

Please note the limitations below:

- ArgGuard only checks for the arguments being *potentially* valid. This means currently, it will check for the minimum argument count and the self type being passed is consistent with the object passed as the first argument to hookmetamethod, along with checking that getnamecallmethod() is not nil in __namecall hooks.
- ArgGuard currenly only works for native types. Metamethods defined by game scripts/similar are not currently compatible with ArgGuard.
- ArgGuard is not a replacement for poor coding practices. Please do not think ArgGuard is magical or will protect you in all cases - its limited in scope and does not eliminate all methods. Please report any false-positives/false-negatives with ArgGuard to me though.

Now works with ArgGuard:

local OldIndex
OldIndex = hookmetamethod(game, "__index", function(Self, Index)
    return OldIndex(Self, Index)
end)

local OldNewIndex
OldNewIndex = hookmetamethod(game, "__newindex", function(Self, Index, Value)
    return OldNewIndex(Self, Index, Value)
end)

local OldNamecall
OldNamecall = hookmetamethod(game, "__namecall", function(Self, ...)
    return OldNamecall(Self, ...)
end)

https://v3rmillion.net/showthread.php?tid=1124390

Clone this wiki locally