mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-19 16:47:14 +02:00
Untested update to the new plugin API.
Various other changes to the plugin as well.
This commit is contained in:
bin
cbp
external/TCC
COPYINGChangelogREADMERELICENSINGTODOVERSIONc67-gen.ccoff.hconfig.helf.hi386-asm.ci386-asm.hi386-gen.ci386-tok.hil-gen.cil-opcodes.h
lib
alloca-arm.Salloca86-bt.Salloca86.Salloca86_64-bt.Salloca86_64.Sarmeabi.cbcheck.clib-arm64.clibtcc1.ctestfp.c
libtcc.clibtcc.hstab.defstab.htcc.ctcc.htccasm.ctcccoff.ctccelf.ctccgen.ctcclib.htccpe.ctccpp.ctccrun.ctcctok.hwin32
x86_64-asm.hx86_64-gen.cinclude
modules
ini
irc
mmdb
sample
sqlite
tcc
xml
shared
source
Base
AABB.cppAABB.hppBuffer.cppBuffer.hppCircle.cppCircle.hppColor3.cppColor3.hppColor4.cppColor4.hppQuaternion.cppQuaternion.hppShared.cppShared.hppSphere.cppSphere.hppVector2.cppVector2.hppVector2i.cppVector2i.hppVector3.cppVector3.hppVector4.cppVector4.hpp
Command.cppCommand.hppConstants.cppCore.cppCore.hppCoreEntity.cppCoreEvents.cppCoreUtils.cppEntity
Blip.cppBlip.hppCheckpoint.cppCheckpoint.hppForcefield.cppForcefield.hppKeybind.cppObject.cppObject.hppPickup.cppPickup.hppPlayer.cppPlayer.hppSprite.cppSprite.hppTextdraw.cppTextdraw.hppVehicle.cppVehicle.hpp
Exports.cppLibrary
Logger.cppLogger.hppMain.cppMisc.cppMisc
Functions.cppFunctions.hppModel.cppModel.hppPlayer.cppPlayer.hppRegister.cppVehicle.cppVehicle.hppWeapon.cppWeapon.hppWorld.cppWorld.hpp
Register.cppRoutine.cppRoutine.hppSqBase.hpp@ -102,15 +102,6 @@ void OnSquirrelTerminate()
|
||||
DefaultVM::Set(nullptr);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Update the plugin on each frame.
|
||||
*/
|
||||
static void OnFrame(float /*delta*/)
|
||||
{
|
||||
// Update the sessions and pool for events
|
||||
Session::Process();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the module API to make sure we don't run into issues.
|
||||
*/
|
||||
@ -133,12 +124,12 @@ bool CheckAPIVer(CCStr ver)
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* React to command sent by other plugins.
|
||||
*/
|
||||
static int OnInternalCommand(unsigned int type, const char * text)
|
||||
static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
|
||||
{
|
||||
switch(type)
|
||||
switch(command_identifier)
|
||||
{
|
||||
case SQMOD_INITIALIZE_CMD:
|
||||
if (CheckAPIVer(text))
|
||||
if (CheckAPIVer(message))
|
||||
{
|
||||
OnSquirrelInitialize();
|
||||
}
|
||||
@ -157,33 +148,42 @@ static int OnInternalCommand(unsigned int type, const char * text)
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The server was initialized and this plugin was loaded successfully.
|
||||
*/
|
||||
static int OnInitServer()
|
||||
static uint8_t OnServerInitialise()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void OnShutdownServer(void)
|
||||
static void OnServerShutdown(void)
|
||||
{
|
||||
// The server may still send callbacks
|
||||
UnbindCallbacks();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Update the plugin on each frame.
|
||||
*/
|
||||
static void OnServerFrame(float /*delta*/)
|
||||
{
|
||||
// Update the sessions and pool for events
|
||||
Session::Process();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void BindCallbacks()
|
||||
{
|
||||
_Clbk->OnInitServer = OnInitServer;
|
||||
_Clbk->OnFrame = OnFrame;
|
||||
_Clbk->OnInternalCommand = OnInternalCommand;
|
||||
_Clbk->OnShutdownServer = OnShutdownServer;
|
||||
_Clbk->OnServerInitialise = OnServerInitialise;
|
||||
_Clbk->OnServerShutdown = OnServerShutdown;
|
||||
_Clbk->OnServerFrame = OnServerFrame;
|
||||
_Clbk->OnPluginCommand = OnPluginCommand;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void UnbindCallbacks()
|
||||
{
|
||||
_Clbk->OnInitServer = nullptr;
|
||||
_Clbk->OnFrame = nullptr;
|
||||
_Clbk->OnInternalCommand = nullptr;
|
||||
_Clbk->OnShutdownServer = nullptr;
|
||||
_Clbk->OnServerInitialise = nullptr;
|
||||
_Clbk->OnServerShutdown = nullptr;
|
||||
_Clbk->OnServerFrame = nullptr;
|
||||
_Clbk->OnPluginCommand = nullptr;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
@ -496,17 +496,17 @@ void OutputMessageImpl(const char * msg, va_list args)
|
||||
CONSOLE_SCREEN_BUFFER_INFO csb_before;
|
||||
GetConsoleScreenBufferInfo( hstdout, &csb_before);
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
|
||||
printf("[SQMOD] ");
|
||||
std::printf("[SQMOD] ");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
vprintf(msg, args);
|
||||
puts("");
|
||||
std::vprintf(msg, args);
|
||||
std::puts("");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
|
||||
#else
|
||||
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
|
||||
vprintf(msg, args);
|
||||
puts("");
|
||||
std::printf("%c[0;32m[SQMOD]%c[0m", 27, 27);
|
||||
std::vprintf(msg, args);
|
||||
std::puts("");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -519,17 +519,17 @@ void OutputErrorImpl(const char * msg, va_list args)
|
||||
CONSOLE_SCREEN_BUFFER_INFO csb_before;
|
||||
GetConsoleScreenBufferInfo( hstdout, &csb_before);
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
printf("[SQMOD] ");
|
||||
std::printf("[SQMOD] ");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
vprintf(msg, args);
|
||||
puts("");
|
||||
std::vprintf(msg, args);
|
||||
std::puts("");
|
||||
|
||||
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
|
||||
#else
|
||||
printf("%c[0;32m[SQMOD]%c[0;37m", 27, 27);
|
||||
vprintf(msg, args);
|
||||
puts("");
|
||||
std::printf("%c[0;91m[SQMOD]%c[0m", 27, 27);
|
||||
std::vprintf(msg, args);
|
||||
std::puts("");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -597,7 +597,7 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
|
||||
return SQMOD_FAILURE;
|
||||
}
|
||||
// Should never reach this point but just in case
|
||||
else if (host_plugin_id > (info->nPluginId))
|
||||
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
|
||||
{
|
||||
OutputError("%s loaded after the host plugin", SQIRC_NAME);
|
||||
// Don't load!
|
||||
@ -616,9 +616,12 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
|
||||
_Func = functions;
|
||||
_Clbk = callbacks;
|
||||
_Info = info;
|
||||
// Assign plugin information
|
||||
_Info->uPluginVer = SQIRC_VERSION;
|
||||
std::strcpy(_Info->szName, SQIRC_HOST_NAME);
|
||||
// Assign plugin version
|
||||
_Info->pluginVersion = SQIRC_VERSION;
|
||||
_Info->apiMajorVersion = PLUGIN_API_MAJOR;
|
||||
_Info->apiMinorVersion = PLUGIN_API_MINOR;
|
||||
// Assign the plugin name
|
||||
std::snprintf(_Info->name, sizeof(_Info->name), "%s", SQIRC_HOST_NAME);
|
||||
// Bind callbacks
|
||||
BindCallbacks();
|
||||
// Notify that the plugin was successfully loaded
|
||||
|
Reference in New Issue
Block a user