2 Commits e3d6a9572b ... 8f70ad7104

Author SHA1 Message Date
  nosoop 8f70ad7104 Add build steps for plugin 1 year ago
  nosoop c100718be8 Rename handle to TF2EconDynAttribute 1 year ago
9 changed files with 94 additions and 36 deletions
  1. 13 0
      AMBuildScript
  2. 38 0
      AMBuilder
  3. 5 0
      PackageScript
  4. 2 0
      configure.py
  5. 1 1
      mmsplugin.cpp
  6. 16 16
      natives.cpp
  7. 9 9
      natives.h
  8. 8 8
      scripting/include/tf_econ_dynamic.inc
  9. 2 2
      scripting/tf_econ_dynamic_compat.sp

+ 13 - 0
AMBuildScript

@@ -1,5 +1,6 @@
 # vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
 import os, sys
+import shutil
 
 # Simple extensions do not need to modify this file.
 
@@ -68,9 +69,12 @@ class ExtensionConfig(object):
     self.sdks = {}
     self.binaries = []
     self.extensions = []
+    self.plugins = {}
     self.generated_headers = None
     self.mms_root = None
     self.sm_root = None
+    self.spcomp_path = None
+    self.spcomp_bin = None
 
   @property
   def tag(self):
@@ -123,6 +127,15 @@ class ExtensionConfig(object):
       if not self.mms_root:
         self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'mmsource-central')
 
+    self.spcomp_path = builder.options.spcomp_path
+    if not self.spcomp_path or not os.path.isdir(self.spcomp_path):
+      spcomp_found = shutil.which("spcomp")
+      if not spcomp_found:
+        raise Exception('Could not find a path for spcomp')
+      self.spcomp_path = os.path.dirname(spcomp_found)
+    self.spcomp_path = Normalize(self.spcomp_path)
+    self.spcomp_bin = shutil.which('spcomp', path = self.spcomp_path)
+
     if not self.mms_root or not os.path.isdir(self.mms_root):
       raise Exception('Could not find a source copy of Metamod:Source')
     self.mms_root = Normalize(self.mms_root)

+ 38 - 0
AMBuilder

@@ -9,6 +9,18 @@ sourceFiles = [
   'natives.cpp',
 ]
 
+pluginFiles = [
+  'tf_econ_dynamic_compat.sp'
+]
+
+spcomp_argv = [
+  Extension.spcomp_bin,
+  '-i' + os.path.relpath(os.path.join(builder.sourcePath, 'scripting', 'include'),
+                         os.path.join(builder.buildPath, builder.buildFolder)),
+  '-h',
+  '-E',
+]
+
 ###############
 # Make sure to edit PackageScript, which copies your files to their appropriate locations
 # Simple extensions do not need to modify past this point.
@@ -29,4 +41,30 @@ for sdk_name in Extension.sdks:
   
   binary = Extension.HL2Config(project, projectName + '.ext.' + sdk.ext, sdk)
 
+def build_plugin(script_path, smx_file):
+  inputs = [
+    Extension.spcomp_bin,
+    script_path,
+  ]
+  outputs = [
+    smx_file
+  ]
+  argv = spcomp_argv + [script_path]
+  result = builder.AddCommand(
+    inputs = inputs,
+    argv = argv,
+    outputs = outputs,
+    dep_type = 'msvc',
+  )
+
+  # ???
+  (smx_command, smx_outputs) = result
+  out, *_ = smx_outputs
+  Extension.plugins[smx_file] = out
+
+for script_file in pluginFiles:
+  script_path = os.path.join(builder.currentSourcePath, 'scripting', script_file)
+  smx_file = os.path.splitext(script_file)[0] + '.smx'
+  build_plugin(script_path, smx_file)
+
 Extension.extensions = builder.Add(project)

+ 5 - 0
PackageScript

@@ -9,6 +9,7 @@ builder.SetBuildFolder('package')
 folder_list = [
   'addons/sourcemod/extensions',
   'addons/sourcemod/gamedata',
+  'addons/sourcemod/plugins',
 ]
 
 # Create the distribution folder hierarchy.
@@ -33,3 +34,7 @@ CopyFiles('gamedata', 'addons/sourcemod/gamedata', [
 # Copy binaries.
 for cxx_task in Extension.extensions:
   builder.AddCopy(cxx_task.binary, folder_map['addons/sourcemod/extensions'])
+
+# Copy plugins
+for smx_file, smx_entry in Extension.plugins.items():
+  builder.AddCopy(smx_entry, folder_map['addons/sourcemod/plugins'])

+ 2 - 0
configure.py

@@ -19,5 +19,7 @@ builder.options.add_option('--enable-optimize', action='store_const', const='1',
 builder.options.add_option('-s', '--sdks', default='all', dest='sdks',
                        help='Build against specified SDKs; valid args are "all", "present", or '
                             'comma-delimited list of engine names (default: %default)')
+builder.options.add_option('--spcomp-path', type=str, dest='spcomp_path', default=None,
+                           help='Path to directory containing spcomp')
 
 builder.Configure()

+ 1 - 1
mmsplugin.cpp

@@ -24,7 +24,7 @@ bool DynSchema::SDK_OnLoad(char *error, size_t maxlen, bool late)
 	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &DynSchema::Hook_LevelInitPost, true);
 
 	sharesys->AddNatives(myself, g_EconAttributeNatives);
-	g_EconInjectedAttributeType = g_pHandleSys->CreateType("EconInjectedAttribute", &g_EconInjectedAttributeHandler, 0, NULL, NULL, myself->GetIdentity(), NULL);
+	g_EconInjectedAttributeType = g_pHandleSys->CreateType("EconDynAttr", &g_EconInjectedAttributeHandler, 0, NULL, NULL, myself->GetIdentity(), NULL);
 
 	/* Prepare our manager */
 	if (!g_EconManager.Init(error, maxlen)) {

+ 16 - 16
natives.cpp

@@ -27,7 +27,7 @@ cell_t sm_EconAttributeCreate(IPluginContext *pContext, const cell_t *params) {
 			pContext->GetIdentity(), myself->GetIdentity(), NULL);
 }
 
-// void EconInjectedAttribute.SetClass(const char[] attrClass)
+// void TF2EconDynAttribute.SetClass(const char[] attrClass)
 cell_t sm_EconAttributeSetClass(IPluginContext *pContext, const cell_t *params) {
 	HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
 	HandleError err;
@@ -36,7 +36,7 @@ cell_t sm_EconAttributeSetClass(IPluginContext *pContext, const cell_t *params)
 	
 	AutoKeyValues *pContainer = nullptr;
 	if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
-		return pContext->ThrowNativeError("Invalid EconInjectedAttribute handle %x (error: %d)", hndl, err);
+		return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
 	}
 	
 	char *value;
@@ -46,7 +46,7 @@ cell_t sm_EconAttributeSetClass(IPluginContext *pContext, const cell_t *params)
 	return 0;
 }
 
-// void EconInjectedAttribute.SetName(const char[] attrName)
+// void TF2EconDynAttribute.SetName(const char[] attrName)
 cell_t sm_EconAttributeSetName(IPluginContext *pContext, const cell_t *params) {
 	HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
 	HandleError err;
@@ -55,7 +55,7 @@ cell_t sm_EconAttributeSetName(IPluginContext *pContext, const cell_t *params) {
 	
 	AutoKeyValues *pContainer = nullptr;
 	if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
-		return pContext->ThrowNativeError("Invalid EconInjectedAttribute handle %x (error: %d)", hndl, err);
+		return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
 	}
 	
 	char *value;
@@ -65,7 +65,7 @@ cell_t sm_EconAttributeSetName(IPluginContext *pContext, const cell_t *params) {
 	return 0;
 }
 
-// void EconInjectedAttribute.SetDescriptionFormat(const char[] attrDescFmt)
+// void TF2EconDynAttribute.SetDescriptionFormat(const char[] attrDescFmt)
 cell_t sm_EconAttributeSetDescriptionFormat(IPluginContext *pContext, const cell_t *params) {
 	HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
 	HandleError err;
@@ -74,7 +74,7 @@ cell_t sm_EconAttributeSetDescriptionFormat(IPluginContext *pContext, const cell
 	
 	AutoKeyValues *pContainer = nullptr;
 	if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
-		return pContext->ThrowNativeError("Invalid EconInjectedAttribute handle %x (error: %d)", hndl, err);
+		return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
 	}
 	
 	char *value;
@@ -84,7 +84,7 @@ cell_t sm_EconAttributeSetDescriptionFormat(IPluginContext *pContext, const cell
 	return 0;
 }
 
-// void EconInjectedAttribute.SetCustom(const char[] key, const char[] value)
+// void TF2EconDynAttribute.SetCustom(const char[] key, const char[] value)
 cell_t sm_EconAttributeSetCustomKeyValue(IPluginContext *pContext, const cell_t *params) {
 	HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
 	HandleError err;
@@ -93,7 +93,7 @@ cell_t sm_EconAttributeSetCustomKeyValue(IPluginContext *pContext, const cell_t
 	
 	AutoKeyValues *pContainer = nullptr;
 	if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
-		return pContext->ThrowNativeError("Invalid EconInjectedAttribute handle %x (error: %d)", hndl, err);
+		return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
 	}
 	
 	char *key, *value;
@@ -104,7 +104,7 @@ cell_t sm_EconAttributeSetCustomKeyValue(IPluginContext *pContext, const cell_t
 	return 0;
 }
 
-// void EconInjectedAttribute.SetDefIndex(int attrdef)
+// void TF2EconDynAttribute.SetDefIndex(int attrdef)
 cell_t sm_EconAttributeSetDefIndex(IPluginContext *pContext, const cell_t *params) {
 	HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
 	HandleError err;
@@ -113,7 +113,7 @@ cell_t sm_EconAttributeSetDefIndex(IPluginContext *pContext, const cell_t *param
 	
 	AutoKeyValues *pContainer = nullptr;
 	if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
-		return pContext->ThrowNativeError("Invalid EconInjectedAttribute handle %x (error: %d)", hndl, err);
+		return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
 	}
 	
 	(*pContainer)->SetName(std::to_string(params[2]).c_str());
@@ -121,7 +121,7 @@ cell_t sm_EconAttributeSetDefIndex(IPluginContext *pContext, const cell_t *param
 	return 0;
 }
 
-// void EconInjectedAttribute.ClearDefIndex()
+// void TF2EconDynAttribute.ClearDefIndex()
 cell_t sm_EconAttributeClearDefIndex(IPluginContext *pContext, const cell_t *params) {
 	HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
 	HandleError err;
@@ -130,7 +130,7 @@ cell_t sm_EconAttributeClearDefIndex(IPluginContext *pContext, const cell_t *par
 	
 	AutoKeyValues *pContainer = nullptr;
 	if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
-		return pContext->ThrowNativeError("Invalid EconInjectedAttribute handle %x (error: %d)", hndl, err);
+		return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
 	}
 	
 	(*pContainer)->SetName("auto");
@@ -138,7 +138,7 @@ cell_t sm_EconAttributeClearDefIndex(IPluginContext *pContext, const cell_t *par
 	return 0;
 }
 
-// bool EconInjectedAttribute.Register()
+// bool TF2EconDynAttribute.Register()
 cell_t sm_EconAttributeRegister(IPluginContext *pContext, const cell_t *params) {
 	HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
 	HandleError err;
@@ -147,7 +147,7 @@ cell_t sm_EconAttributeRegister(IPluginContext *pContext, const cell_t *params)
 	
 	AutoKeyValues *pContainer = nullptr;
 	if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
-		return pContext->ThrowNativeError("Invalid EconInjectedAttribute handle %x (error: %d)", hndl, err);
+		return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
 	}
 	
 	
@@ -157,7 +157,7 @@ cell_t sm_EconAttributeRegister(IPluginContext *pContext, const cell_t *params)
 	return true;
 }
 
-// void EconInjectedAttribute.Clear();
+// void TF2EconDynAttribute.Clear();
 cell_t sm_EconAttributeClear(IPluginContext *pContext, const cell_t *params) {
 	HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
 	HandleError err;
@@ -166,7 +166,7 @@ cell_t sm_EconAttributeClear(IPluginContext *pContext, const cell_t *params) {
 	
 	AutoKeyValues *pContainer = nullptr;
 	if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
-		return pContext->ThrowNativeError("Invalid EconInjectedAttribute handle %x (error: %d)", hndl, err);
+		return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
 	}
 	
 	KeyValues::AutoDelete empty("auto");

+ 9 - 9
natives.h

@@ -55,15 +55,15 @@ cell_t sm_EconAttributeRegister(IPluginContext *pContext, const cell_t *params);
 cell_t sm_EconAttributeClear(IPluginContext *pContext, const cell_t *params);
 
 const sp_nativeinfo_t g_EconAttributeNatives[] = {
-	{ "EconInjectedAttribute.EconInjectedAttribute", sm_EconAttributeCreate },
-	{ "EconInjectedAttribute.SetClass", sm_EconAttributeSetClass },
-	{ "EconInjectedAttribute.SetName", sm_EconAttributeSetName },
-	{ "EconInjectedAttribute.SetDescriptionFormat", sm_EconAttributeSetDescriptionFormat },
-	{ "EconInjectedAttribute.SetCustom", sm_EconAttributeSetCustomKeyValue },
-	{ "EconInjectedAttribute.SetDefIndex", sm_EconAttributeSetDefIndex },
-	{ "EconInjectedAttribute.ClearDefIndex", sm_EconAttributeClearDefIndex },
-	{ "EconInjectedAttribute.Register", sm_EconAttributeRegister },
-	{ "EconInjectedAttribute.Clear", sm_EconAttributeClear },
+	{ "TF2EconDynAttribute.TF2EconDynAttribute", sm_EconAttributeCreate },
+	{ "TF2EconDynAttribute.SetClass", sm_EconAttributeSetClass },
+	{ "TF2EconDynAttribute.SetName", sm_EconAttributeSetName },
+	{ "TF2EconDynAttribute.SetDescriptionFormat", sm_EconAttributeSetDescriptionFormat },
+	{ "TF2EconDynAttribute.SetCustom", sm_EconAttributeSetCustomKeyValue },
+	{ "TF2EconDynAttribute.SetDefIndex", sm_EconAttributeSetDefIndex },
+	{ "TF2EconDynAttribute.ClearDefIndex", sm_EconAttributeClearDefIndex },
+	{ "TF2EconDynAttribute.Register", sm_EconAttributeRegister },
+	{ "TF2EconDynAttribute.Clear", sm_EconAttributeClear },
 	
 	{NULL, NULL},
 };

+ 8 - 8
scripting/include/tf_econ_dynamic.inc

@@ -2,16 +2,16 @@
  * An InjectedAttribute is an abstraction over the KeyValues representation of an attribute
  * definition.
  */
-methodmap EconInjectedAttribute < Handle {
+methodmap TF2EconDynAttribute < Handle {
 	/**
-	 * Creates a new, empty EconInjectedAttribute handle.
+	 * Creates a new, empty TF2EconDynAttribute handle.
 	 * 
-	 * The attribute is not injected into the schema until EconInjectedAttribute.Register() is
+	 * The attribute is not injected into the schema until TF2EconDynAttribute.Register() is
 	 * called.
 	 * 
 	 * This handle should be freed by the calling plugin.
 	 */
-	public native EconInjectedAttribute();
+	public native TF2EconDynAttribute();
 	
 	/**
 	 * Sets the attribute class.  All values under the same attribute class are combined.
@@ -70,9 +70,9 @@ methodmap EconInjectedAttribute < Handle {
 	/**
 	 * Stores a copy of the attribute properties in the core plugin to be injected.
 	 * 
-	 * This operation does not clear existing values on the EconInjectedAttribute, so you can
-	 * create multiple attributes by repeatedly calling EconInjectedAttribute.SetName() and
-	 * EconInjectedAttribute.Register().
+	 * This operation does not clear existing values on the TF2EconDynAttribute, so you can
+	 * create multiple attributes by repeatedly calling TF2EconDynAttribute.SetName() and
+	 * TF2EconDynAttribute.Register().
 	 * 
 	 * If an attribute with the same name already exists and is not an injected attribute
 	 * managed by the core plugin, this will fail.
@@ -83,7 +83,7 @@ methodmap EconInjectedAttribute < Handle {
 	public native bool Register();
 	
 	/**
-	 * Imports the properties of an attribute by name to the EconInjectedAttribute handle,
+	 * Imports the properties of an attribute by name to the TF2EconDynAttribute handle,
 	 * replacing all values currently set.
 	 * 
 	 * @return    True if the attribute exists, otherwise false.

+ 2 - 2
scripting/tf_econ_dynamic_compat.sp

@@ -19,10 +19,10 @@ public Plugin myinfo = {
 	url = "https://github.com/nosoop/SMExt-TFEconDynamic"
 }
 
-static EconInjectedAttribute s_AttributeContext;
+static TF2EconDynAttribute s_AttributeContext;
 
 public void OnPluginStart() {
-	s_AttributeContext = new EconInjectedAttribute();
+	s_AttributeContext = new TF2EconDynAttribute();
 	
 	CreateAttributeConfigParsers();
 }