//----------------------------------------------------------------------------- // World Initialization //----------------------------------------------------------------------------- public bool OnLoadWorld(World world) { scriptMethods.Clear(); // Load the assembly. byte[] rawAssembly = world.ScriptManager.RawAssembly; if (rawAssembly == null || rawAssembly.Length == 0) return false; compiledAssembly = Assembly.Load(rawAssembly); if (compiledAssembly == null) return false; // Find the type (class) of the custom script method. Type type = compiledAssembly.GetType("ZeldaAPI.CustomScripts.CustomScript"); if (type == null) return false; // Find the default constructor for the type. ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes); if (constructor == null) return false; // Construct the script object. scriptObject = (ZeldaAPI.CustomScriptBase) constructor.Invoke(null); if (scriptObject == null) return false; // Find the script method infos. foreach (string scriptName in world.Scripts.Keys) { scriptMethods[scriptName] = type.GetMethod("RunScript_" + scriptName); } return true; }
//----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- public ScriptRunner(GameControl gameControl) { this.gameControl = gameControl; this.scriptObject = null; this.compiledAssembly = null; this.scriptMethods = new Dictionary <string, MethodInfo>(); }
//----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- public ScriptRunner(GameControl gameControl) { this.gameControl = gameControl; this.scriptObject = null; this.compiledAssembly = null; this.scriptMethods = new Dictionary<string, MethodInfo>(); }
//----------------------------------------------------------------------------- // World Initialization //----------------------------------------------------------------------------- public bool OnLoadWorld(World world) { scriptMethods.Clear(); // Load the assembly. byte[] rawAssembly = world.ScriptManager.RawAssembly; if (rawAssembly == null || rawAssembly.Length == 0) { return(false); } compiledAssembly = Assembly.Load(rawAssembly); if (compiledAssembly == null) { return(false); } // Find the type (class) of the custom script method. Type type = compiledAssembly.GetType("ZeldaAPI.CustomScripts.CustomScript"); if (type == null) { return(false); } // Find the default constructor for the type. ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes); if (constructor == null) { return(false); } // Construct the script object. scriptObject = (ZeldaAPI.CustomScriptBase)constructor.Invoke(null); if (scriptObject == null) { return(false); } // Find the script method infos. foreach (string scriptName in world.Scripts.Keys) { scriptMethods[scriptName] = type.GetMethod("RunScript_" + scriptName); } return(true); }