Workaround

Allows users to fix external bugs and conflicts

Code: guthscp.workaround.meta

Realm: Shared


Description

For more information about creating a workaround, read this tutorial.


Properties

string name

Name of the workaround, used in the menu


guthscp.REALMS realm

Realm of the workaround, this define in which realm (server, client or both) the workaround should behave (allowing to call WORKAROUND:on_enabled and WORKAROUND:on_disabled accordingly). For example, if you want to fix a server-side hook, you should define the workaround on the server realm.


(internal) string id

Identifier of the workaround, used for registering in the system.


(internal) bool _is_enabled

Is the workaround currently enabled? Set by WORKAROUND:set_enabled.


(internal) bool _is_active

Is the workaround able to be enabled? Set to the result of WORKAROUND:init method when called by the workaround system.


Methods

(overridable) bool init()

Returns whenever the workaround should be active. This can informs that the workaround can't function due to a lack of a certain hook or dependency.

Called either during the GM:InitPostEntity hook or during hot reload.


(overridable) void on_enabled()

Called when the workaround is enabled on the targeted realm.


(overridable) void on_disabled()

Called when the workaround is disabled on the targeted realm.


bool register_hook( any slot, string name, any id )

Registers the current callback of the specified hook at given slot. Returns whether the hook has been found.


bool find_hook( any slot, string name, function<bool>( string, function ) condition )

Finds a hook matching the callback condition and register it at given slot. Useful for finding hooks with randomized identifiers. Returns whether the hook has been found.


bool override_hook( any slot, function callback )

Overrides the game hook's callback from slot. Doesn't modify the internal registery.


bool remove_hook( any slot )

Deletes the game hook's callback from slot. Doesn't modify the internal registery.


bool restore_hook( any slot )

Restores the game hook's callback at given slot to registered callback. Doesn't modify the internal registery.


bool is_enabled() const

Returns whenever the workaround is enabled.


bool is_active() const

Returns whenever the workaround is active.


void set_enabled( bool is_enabled )

Changes current state. Do nothing if in-active or if is_enabled matchs workaround's state. Calls WORKAROUND:on_enabled or WORKAROUND:on_disabled (depending on is_enabled) if the call's realm is matching targeted realm. Do not synchronizes or saves by itself.


void sync( Player ply = nil )

Synchronizes the workaround either to server (client-side), to ply or to all clients.


Last updated