Difference between revisions of "AMX Mod X 1.75 Scripting Changes"
m (gaben) |
(Lots of changes in order to describe new natives/native changes - lots of mistakes?) |
||
Line 46: | Line 46: | ||
*The plugin cache is invalidated and the server is considered "loaded". | *The plugin cache is invalidated and the server is considered "loaded". | ||
− | =Register | + | =New Natives / Native Changes= |
− | The register_message set of natives, including | + | ==Register Message== |
+ | The <tt>register_message</tt> set of natives, including <tt>get/set_msg_block</tt>, has been moved to Core. This is to facilitate users who prefer to use FakeMeta, and like the simplicity and speed of using Engine's message interception functions. | ||
+ | <br /> | ||
+ | This change is backwards compatible. | ||
− | + | ==Argument Formatting== | |
+ | The <tt>format_args</tt> function is now replaced with a much faster, more compatible <tt>vformat</tt> function. Its usage is slightly different (read the include file, <tt>string.inc</tt>), but it accepts %L, whereas format_args does not. A quick example: | ||
+ | <pawn>debugprint(const fmt[], ...) | ||
+ | { | ||
+ | static temp[2048] | ||
+ | vformat(temp, sizeof(temp)-1, fmt, 2) | ||
+ | log_message("[DEBUG] %s", temp) | ||
+ | }</pawn> | ||
+ | |||
+ | ==Other Core Natives== | ||
+ | *<tt>register_plugin</tt> - Now returns a plugin id. | ||
+ | *<tt>get_amxx_verstring</tt> - Returns the AMX Mod X version string. | ||
+ | *<tt>get_weaponid</tt> - Gets a weapon id from a weapon name. | ||
+ | |||
+ | ==FakeMeta== | ||
+ | ===New Natives=== | ||
+ | *<tt>get_orig_retval</tt> - Gets the original return value of an engine or game DLL function. | ||
+ | *<tt>copy_infokey_buffer</tt> - Copies the given infobuffer pointer into output buffer. | ||
+ | *<tt>get/set_cd</tt> - Gets or sets members of a clientdata data structure (used with UpdateClientData). | ||
+ | *<tt>get/set_es</tt> - Gets or sets members of an entity_state data structure (used with AddToFullPack). | ||
+ | *<tt>get/set_uc</tt> - Gets or sets members of a usecmd data structure (used with CmdStart). | ||
+ | |||
+ | ===New Engine/GameDLL Functions=== | ||
+ | The <tt>register_forward</tt> native now allows for hooking a number of new functions from the engine or game DLL including: | ||
+ | *<tt>UpdateClientData</tt> | ||
+ | *<tt>AddToFullPack</tt> | ||
+ | *<tt>CmdStart</tt> | ||
+ | *<tt>CmdEnd</tt> | ||
+ | *<tt>CreateInstBaseline</tt> | ||
+ | *<tt>CreateBaseline</tt> | ||
+ | *<tt>GetInfoKeyBuffer</tt> | ||
+ | |||
+ | These functions can also be called via <tt>engfunc</tt> or <tt>dllfunc</tt>. | ||
+ | |||
+ | ===Breaking Changes=== | ||
+ | Using <tt>engfunc</tt> in order to call <tt>EngFunc_InfoKeyValue</tt>, <tt>EngFunc_SetKeyValue</tt>, or <tt>EngFunc_SetClientKeyValue</tt> now requires passing an infobuffer pointer. An infobuffer pointer can be obtained by calling <tt>EngFunc_GetInfoKeyBuffer</tt>. For example: | ||
+ | <pawn>some_function(id, name[]) | ||
+ | { | ||
+ | new infokey = engfunc(EngFunc_GetInfoKeyBuffer, id) | ||
+ | engfunc(EngFunc_SetClientKeyValue, id, infokey, "model", name) | ||
+ | }</pawn> | ||
+ | |||
+ | If you hook ClientUserInfoChanged via Fakemeta, an infobuffer pointer is now also forwarded to your function in addition to the client id. | ||
+ | |||
+ | ==Cstrike== | ||
+ | *<tt>cs_set_user_vip</tt> - Now takes two additional (but optional) parameters for determing whether or not the player model and scoreboard get updated. | ||
+ | |||
+ | ==New Stocks== | ||
+ | ===Engine=== | ||
+ | *<tt>IsInWorld</tt> - Checks if an entity is within the bounds of the world (from HLSDK). | ||
+ | |||
+ | ===FakeMeta=== | ||
+ | *<tt>DF_UpdateClientData</tt> - Calls UpdateClientData game DLL function. | ||
+ | *<tt>DF_AddToFullPack</tt> - Calls AddToFullPack game DLL function. | ||
+ | *<tt>DF_CmdStart</tt> - Calls CmdStart game DLL function. | ||
+ | *<tt>DF_CmdEnd</tt> - Calls CmdEnd game DLL function. | ||
+ | *<tt>DF_CreateBaseline</tt> - Calls CreateBaseline game DLL function. | ||
+ | *<tt>DF_CreateInstBaselines</tt> - Calls CreateInstancedBaselines game dll function. | ||
+ | *<tt>EF_CreateInstBaseline</tt> - Calls CreateInstancedBaseline engine function. | ||
+ | *<tt>EF_GetInfoKeyBuffer</tt> - Calls GetInfoKeyBuffer engine function. | ||
+ | |||
+ | ==New Constants== | ||
+ | Various sound constants (<tt>SND_SPAWNING</tt>, <tt>SND_STOP</tt>, <tt>SND_CHANGE_VOL</tt>, and <tt>SND_CHANGE_PITCH</tt>) from the HLSDK as well as a constant for pi were added to <tt>amxconst.inc</tt>. | ||
=Module API= | =Module API= | ||
Line 72: | Line 137: | ||
==MSVC8 Compatibility== | ==MSVC8 Compatibility== | ||
− | M/SDK Version 4 now contains preprocessor definitions for compatibility with Microsoft's Visual Studio 2005/8.0 (provided by [[User:Damaged Soul|Damaged Soul]]). These macros can be turned off in the <tt>moduleconfig.h</tt> file. | + | M/SDK Version 4 now contains preprocessor definitions for compatibility with Microsoft's Visual Studio 2005/8.0 (provided by [[User:Damaged Soul|Damaged Soul]]). These macros can be turned off in the <tt>moduleconfig.h</tt> file by uncommenting the definition of <tt>NO_MSVC8_AUTO_COMPAT</tt>. |
=Minor Changes= | =Minor Changes= | ||
==Compiler Defines== | ==Compiler Defines== | ||
Since <tt>__DATE__</tt> was fixed in 1.75, the macro <tt>__TIME__</tt> was also added. | Since <tt>__DATE__</tt> was fixed in 1.75, the macro <tt>__TIME__</tt> was also added. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
[[Category:AMX Mod X]] | [[Category:AMX Mod X]] |
Revision as of 09:48, 15 May 2006
The AMX Mod X 1.75 release made important changes. While backwards compatibility was kept, intended functionality shifted in esoteric areas that will affect some plugins. Reading this article is highly recommended.
Contents
Module Requirement System
As part of the new Automatic Module Loading, the old #pragma library has been deprecated. You must now use:
#pragma reqlib <library>
This means "require library". Plugins still compiled with #pragma library will still fail on load if the given module is not found. However, core will try to load each module given the rules below under "Automatic Module Loading".
Automatic Module Loading
Overview
As of AMX Mod X 1.75, there is a new, powerful automatic module loading system. That means that modules.ini is largely deprecated for general use. Instead, modules are loaded as plugins need them. This is done dynamically by core before plugins are even loaded, without the need to patch modules.ini and then change the map.
Modules can now define "Libraries" and "Library Classes". A library is a specific identifier that should match the filename of the module. For example, Engine's defined library is "engine". FakeMeta's library is "fakemeta", and so on.
A "library class" defines membership to a set of modules. For example, CSX has the library name "csx", but it is part of the library class "xstats". Library classes are also used for DBI and SQLX. This is very useful for being able to require one module type of any implementation.
New API
Compiler Pragmas
This is expanded with a number of new #pragma directives:
- #pragma reqlib <library> - Requires that a given library must be loaded.
- #pragma reqclass <libclass> - Requires that a given library class must be loaded.
- #pragma loadlib <library> - Automatically attempts to load a given library (see more info below).
- #pragma expectlib <library1> <library2> - If the first library is not loaded, the second one will be attempted to load (not very useful).
- #pragma expectclass <class> <library> - If the expected class is not found, the given library will be attempted to load. This is useful for defining a default module to be loaded with a given class of modules.
- #pragma defclasslib <class> <library> - Same as expectclass, however, defclasslib waits until all expectations are resolved. This lets plugins override defaults by adding their own expectations.
Module Filtering
The module_filter prototype now includes a second parameter, which tells you whether the requirement is a class or library.
Furthermore, module_exists has been deprecated for LibraryExists().
How it Works
The precise order of events is as follows:
- When the first entity is spawned, AMX Mod X loads all unloaded modules in modules.ini.
- After modules.ini is parsed, plugins.ini is read. Each file is mapped into a cache.
- The cache is previewed.
- First, the "library" table is read. This table is read for backwards compatibility with AMX Mod X 1.71 and prior. Each entry is read as a module file shortname, and the module is loaded if it exists.
- Next, the "pubtags" table is read. Each entry is decoded to one of the special #pragma commands.
- All loadlib commands are executed, and the modules loaded.
- All expect commands are executed.
- All defclasslib commands are executed.
- AMX Mod X then waits until ServerActivate is called.
- All plugins are loaded. If the plugin is in the cache, the cache is read instead. For each plugin...
- The library table is read. For each library that is both nonexistant and unhandled by a module filter, the plugin fails to load.
- The pubtags table is read. For each reqlib and reqclass entry that are both nonexistant and unhandled by a module filter, the plugin fails to load.
- The plugin cache is invalidated and the server is considered "loaded".
New Natives / Native Changes
Register Message
The register_message set of natives, including get/set_msg_block, has been moved to Core. This is to facilitate users who prefer to use FakeMeta, and like the simplicity and speed of using Engine's message interception functions.
This change is backwards compatible.
Argument Formatting
The format_args function is now replaced with a much faster, more compatible vformat function. Its usage is slightly different (read the include file, string.inc), but it accepts %L, whereas format_args does not. A quick example:
debugprint(const fmt[], ...) { static temp[2048] vformat(temp, sizeof(temp)-1, fmt, 2) log_message("[DEBUG] %s", temp) }
Other Core Natives
- register_plugin - Now returns a plugin id.
- get_amxx_verstring - Returns the AMX Mod X version string.
- get_weaponid - Gets a weapon id from a weapon name.
FakeMeta
New Natives
- get_orig_retval - Gets the original return value of an engine or game DLL function.
- copy_infokey_buffer - Copies the given infobuffer pointer into output buffer.
- get/set_cd - Gets or sets members of a clientdata data structure (used with UpdateClientData).
- get/set_es - Gets or sets members of an entity_state data structure (used with AddToFullPack).
- get/set_uc - Gets or sets members of a usecmd data structure (used with CmdStart).
New Engine/GameDLL Functions
The register_forward native now allows for hooking a number of new functions from the engine or game DLL including:
- UpdateClientData
- AddToFullPack
- CmdStart
- CmdEnd
- CreateInstBaseline
- CreateBaseline
- GetInfoKeyBuffer
These functions can also be called via engfunc or dllfunc.
Breaking Changes
Using engfunc in order to call EngFunc_InfoKeyValue, EngFunc_SetKeyValue, or EngFunc_SetClientKeyValue now requires passing an infobuffer pointer. An infobuffer pointer can be obtained by calling EngFunc_GetInfoKeyBuffer. For example:
some_function(id, name[]) { new infokey = engfunc(EngFunc_GetInfoKeyBuffer, id) engfunc(EngFunc_SetClientKeyValue, id, infokey, "model", name) }
If you hook ClientUserInfoChanged via Fakemeta, an infobuffer pointer is now also forwarded to your function in addition to the client id.
Cstrike
- cs_set_user_vip - Now takes two additional (but optional) parameters for determing whether or not the player model and scoreboard get updated.
New Stocks
Engine
- IsInWorld - Checks if an entity is within the bounds of the world (from HLSDK).
FakeMeta
- DF_UpdateClientData - Calls UpdateClientData game DLL function.
- DF_AddToFullPack - Calls AddToFullPack game DLL function.
- DF_CmdStart - Calls CmdStart game DLL function.
- DF_CmdEnd - Calls CmdEnd game DLL function.
- DF_CreateBaseline - Calls CreateBaseline game DLL function.
- DF_CreateInstBaselines - Calls CreateInstancedBaselines game dll function.
- EF_CreateInstBaseline - Calls CreateInstancedBaseline engine function.
- EF_GetInfoKeyBuffer - Calls GetInfoKeyBuffer engine function.
New Constants
Various sound constants (SND_SPAWNING, SND_STOP, SND_CHANGE_VOL, and SND_CHANGE_PITCH) from the HLSDK as well as a constant for pi were added to amxconst.inc.
Module API
The AMX Mod X module API received a small overhaul for 1.75.
Versioning/Interface Additions
The internal module interface version is 4. However, modules from M/SDK 3 will still load.
M/SDK Version 4 modules have two new members of public information: the library string, and the library class string. These contain comma delimited names of whatever libraries or library classes the module would like to be registered.
For backwards compatibility, M/SDK Version 4 modules have an automatically empty library class string, and a library string equal to the logtag string.
New Callbacks
Modules can now be informed of when plugins are about to be unloaded, and when plugins have been fully unloaded. This means that modules don't have to hook ServerActivate and ServerActivate_Post (implementation dependent), don't need to be loaded by Metamod, and don't need to detach simply to release resources.
New Functions
- MF_GetLocalInfo - Intended for modules using LOCALINFO, which required a Metamod attachment. This is equal to AMX Mod X's core function get_localinfo.
- MF_OverrideNatives - Given a native list, this specifies that any other module already providing these natives will no longer provide them. This was added to force backwards compatibility between SQLITE and MySQLX. Usage is not recommended.
- MF_FindLibrary - Essentially the same function as LibraryExists() for plugins.
- MF_AddLibraries - Adds a comma delimited list of libraries or library classes. You must specify a "parent" pointer that identifies the module. This is easily accomplished by taking the address of any static variable.
- MF_RemoveLibraries - Removes all library entries with the given parent pointer. This is useful if your module adds custom entries not in its defined list.
MSVC8 Compatibility
M/SDK Version 4 now contains preprocessor definitions for compatibility with Microsoft's Visual Studio 2005/8.0 (provided by Damaged Soul). These macros can be turned off in the moduleconfig.h file by uncommenting the definition of NO_MSVC8_AUTO_COMPAT.
Minor Changes
Compiler Defines
Since __DATE__ was fixed in 1.75, the macro __TIME__ was also added.