22
33#include "include/vscript.inc"
44
5- #define PLUGIN_VERSION " 1.8.7 "
5+ #define PLUGIN_VERSION " 1.9.0 "
66#define PLUGIN_VERSION_REVISION " manual"
77
88char g_sOperatingSystem [16 ];
@@ -18,6 +18,7 @@ int g_iScriptVariant_union;
1818int g_iScriptVariant_type ;
1919
2020static Handle g_hSDKCallCompileScript ;
21+ static Handle g_hSDKCallRegisterInstance ;
2122static Handle g_hSDKCallGetInstanceEntity ;
2223
2324const HSCRIPT INVALID_HSCRIPT = view_as <HSCRIPT >(- 1 );
@@ -94,9 +95,15 @@ public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int iLen
9495 CreateNative (" VScriptFunction.Class.get" , Native_Function_ClassGet );
9596
9697 CreateNative (" VScriptClass.GetScriptName" , Native_Class_GetScriptName );
98+ CreateNative (" VScriptClass.SetScriptName" , Native_Class_SetScriptName );
99+ CreateNative (" VScriptClass.GetClassName" , Native_Class_GetClassName );
100+ CreateNative (" VScriptClass.SetClassName" , Native_Class_SetClassName );
101+ CreateNative (" VScriptClass.GetDescription" , Native_Class_GetDescription );
102+ CreateNative (" VScriptClass.SetDescription" , Native_Class_SetDescription );
97103 CreateNative (" VScriptClass.GetAllFunctions" , Native_Class_GetAllFunctions );
98104 CreateNative (" VScriptClass.GetFunction" , Native_Class_GetFunction );
99105 CreateNative (" VScriptClass.CreateFunction" , Native_Class_CreateFunction );
106+ CreateNative (" VScriptClass.RegisterInstance" , Native_Class_RegisterInstance );
100107 CreateNative (" VScriptClass.Base.get" , Native_Class_BaseGet );
101108 CreateNative (" VScriptClass.IsDerivedFrom" , Native_Class_IsDerivedFrom ); // legacy native, to be removed later
102109
@@ -120,6 +127,7 @@ public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int iLen
120127 CreateNative (" VScript_CreateTable" , Native_CreateTable );
121128 CreateNative (" VScript_GetAllClasses" , Native_GetAllClasses );
122129 CreateNative (" VScript_GetClass" , Native_GetClass );
130+ CreateNative (" VScript_CreateClass" , Native_CreateClass );
123131 CreateNative (" VScript_GetClassFunction" , Native_GetClassFunction );
124132 CreateNative (" VScript_GetAllGlobalFunctions" , Native_GetAllGlobalFunctions );
125133 CreateNative (" VScript_GetGlobalFunction" , Native_GetGlobalFunction );
@@ -163,6 +171,7 @@ public void OnPluginStart()
163171 List_LoadGamedata (hGameData );
164172
165173 g_hSDKCallCompileScript = CreateSDKCall (hGameData , " IScriptVM" , " CompileScript" , SDKType_PlainOldData , SDKType_String , SDKType_String );
174+ g_hSDKCallRegisterInstance = CreateSDKCall (hGameData , " IScriptVM" , " RegisterInstance" , SDKType_PlainOldData , SDKType_PlainOldData , SDKType_String );
166175 g_hSDKCallGetInstanceEntity = CreateSDKCall (hGameData , " IScriptVM" , " GetInstanceValue" , SDKType_CBaseEntity , SDKType_PlainOldData , SDKType_PlainOldData );
167176
168177 delete hGameData ;
@@ -339,7 +348,7 @@ public any Native_Function_SetScriptName(Handle hPlugin, int iNumParams)
339348 char [] sBuffer = new char [iLength + 1 ];
340349 GetNativeString (2 , sBuffer , iLength + 1 );
341350
342- // Check if script name dont already exist
351+ // Check if script name not already exist
343352 if (Function_GetFlags (pFunction ) & SF_MEMBER_FUNC )
344353 {
345354 VScriptClass pClass = List_GetClassFromFunction (pFunction );
@@ -525,6 +534,57 @@ public any Native_Class_GetScriptName(Handle hPlugin, int iNumParams)
525534 return 0 ;
526535}
527536
537+ public any Native_Class_SetScriptName (Handle hPlugin , int iNumParams )
538+ {
539+ VScriptClass pClass = GetNativeCell (1 );
540+
541+ int iLength ;
542+ GetNativeStringLength (2 , iLength );
543+
544+ char [] sBuffer = new char [iLength + 1 ];
545+ GetNativeString (2 , sBuffer , iLength + 1 );
546+
547+ // Check if script name not already exist
548+ if (List_GetClass (sBuffer ))
549+ ThrowNativeError (SP_ERROR_NATIVE , " Global function named '%s ' already exists" , sBuffer );
550+
551+ Class_SetScriptName (pClass , 2 );
552+ return 0 ;
553+ }
554+
555+ public any Native_Class_GetClassName (Handle hPlugin , int iNumParams )
556+ {
557+ int iLength = GetNativeCell (3 );
558+ char [] sBuffer = new char [iLength ];
559+
560+ Class_GetClassName (GetNativeCell (1 ), sBuffer , iLength );
561+ SetNativeString (2 , sBuffer , iLength );
562+ return 0 ;
563+ }
564+
565+ public any Native_Class_SetClassName (Handle hPlugin , int iNumParams )
566+ {
567+ // Could add an already exist check like SetScriptName, meh
568+ Class_SetClassName (GetNativeCell (1 ), 2 );
569+ return 0 ;
570+ }
571+
572+ public any Native_Class_GetDescription (Handle hPlugin , int iNumParams )
573+ {
574+ int iLength = GetNativeCell (3 );
575+ char [] sBuffer = new char [iLength ];
576+
577+ Class_GetDescription (GetNativeCell (1 ), sBuffer , iLength );
578+ SetNativeString (2 , sBuffer , iLength );
579+ return 0 ;
580+ }
581+
582+ public any Native_Class_SetDescription (Handle hPlugin , int iNumParams )
583+ {
584+ Class_SetDescription (GetNativeCell (1 ), 2 );
585+ return 0 ;
586+ }
587+
528588public any Native_Class_GetAllFunctions (Handle hPlugin , int iNumParams )
529589{
530590 ArrayList aList = Class_GetAllFunctions (GetNativeCell (1 ));
@@ -550,6 +610,26 @@ public any Native_Class_CreateFunction(Handle hPlugin, int iNumParams)
550610 return Class_CreateFunction (GetNativeCell (1 ));
551611}
552612
613+ public any Native_Class_RegisterInstance (Handle hPlugin , int iNumParams )
614+ {
615+ int iLength ;
616+ GetNativeStringLength (2 , iLength );
617+
618+ char [] sBuffer = new char [iLength + 1 ];
619+ GetNativeString (2 , sBuffer , iLength + 1 );
620+
621+ // Second param is void *, but we can just pass string to it
622+ HSCRIPT pInstance = SDKCall (g_hSDKCallRegisterInstance , GetScriptVM (), GetNativeCell (1 ), sBuffer );
623+
624+ // Not sure if this is the correct way to do it, but it works
625+ ScriptVariant_t pValue = new ScriptVariant_t ();
626+ pValue .nType = FIELD_HSCRIPT ;
627+ pValue .nValue = pInstance ;
628+ HScript_SetValue (HSCRIPT_RootTable , sBuffer , pValue );
629+
630+ return pInstance ;
631+ }
632+
553633public any Native_Class_BaseGet (Handle hPlugin , int iNumParams )
554634{
555635 return Class_GetBaseDesc (GetNativeCell (1 ));
@@ -796,6 +876,25 @@ public any Native_GetClass(Handle hPlugin, int iNumParams)
796876 return pClass ;
797877}
798878
879+ public any Native_CreateClass (Handle hPlugin , int iNumParams )
880+ {
881+ int iLength ;
882+ GetNativeStringLength (1 , iLength );
883+
884+ char [] sBuffer = new char [iLength + 1 ];
885+ GetNativeString (1 , sBuffer , iLength + 1 );
886+
887+ VScriptClass pClass = List_GetClass (sBuffer );
888+ if (pClass )
889+ return pClass ;
890+
891+ pClass = Class_Create ();
892+ Class_Init (pClass );
893+ Class_SetScriptName (pClass , 1 );
894+ Class_SetClassName (pClass , 1 );
895+ return pClass ;
896+ }
897+
799898public any Native_GetClassFunction (Handle hPlugin , int iNumParams )
800899{
801900 int iClassNameLength , iFunctionNameLength ;
0 commit comments