Exemplo n.º 1
0
        //-----------------------------------------------------------------------------
        // 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;
        }
Exemplo n.º 2
0
        //-----------------------------------------------------------------------------
        // Constructor
        //-----------------------------------------------------------------------------

        public ScriptRunner(GameControl gameControl)
        {
            this.gameControl      = gameControl;
            this.scriptObject     = null;
            this.compiledAssembly = null;
            this.scriptMethods    = new Dictionary <string, MethodInfo>();
        }
Exemplo n.º 3
0
 //-----------------------------------------------------------------------------
 // Constructor
 //-----------------------------------------------------------------------------
 public ScriptRunner(GameControl gameControl)
 {
     this.gameControl		= gameControl;
     this.scriptObject		= null;
     this.compiledAssembly	= null;
     this.scriptMethods		= new Dictionary<string, MethodInfo>();
 }
Exemplo n.º 4
0
        //-----------------------------------------------------------------------------
        // 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);
        }