Ejemplo n.º 1
0
        public override void Run(NCSContext context)
        {
            int val2   = (int)context.Pop();
            int val1   = (int)context.Pop();
            int result = val1 % val2;

            context.Push(result);
        }
Ejemplo n.º 2
0
        public override void Run(NCSContext context)
        {
            // Computes the logical not of the value
            int val1   = (int)context.Pop();
            int result = val1 == 0 ? 1 : 0;

            context.Push(result);
        }
Ejemplo n.º 3
0
        public override void Run(NCSContext context)
        {
            // Adds a float and an integer together
            int   val2   = (int)context.Pop();
            float val1   = (float)context.Pop();
            float result = val1 + val2;

            context.Push(result);
        }
Ejemplo n.º 4
0
        public override void Run(NCSContext context)
        {
            // Pushes an immediate value onto the stack
            int value = int.Parse(args[1]);

            if (value == 0)
            {
                context.Push(context.objectSelf);
            }
            else if (value == 0x00000001 || value == -1 || value == 0x7F000000)
            {
                context.Push(null);
            }
            else
            {
                throw new Exception("Tried to instantiate constant object with value " + args[1]);
            }
        }
Ejemplo n.º 5
0
        public override void Run(NCSContext context)
        {
            // Adds two floats together
            float val2   = (float)context.Pop();
            float val1   = (float)context.Pop();
            float result = val1 + val2;

            context.Push(result);
        }
Ejemplo n.º 6
0
        public override void Run(NCSContext context)
        {
            // Pushes an immediate value onto the stack
            Vector3 val2   = (Vector3)context.Pop();
            Vector3 val1   = (Vector3)context.Pop();
            Vector3 result = val1 + val2;

            context.Push(result);
        }
Ejemplo n.º 7
0
        public override void Run(NCSContext context)
        {
            // Computes the boolean/bitwise AND of two integers
            int val2   = (int)context.Pop();
            int val1   = (int)context.Pop();
            int result = val1 & val2;

            context.Push(result);
        }
Ejemplo n.º 8
0
        public override void Run(NCSContext context)
        {
            // Bitwise exclusive or
            int val2   = (int)context.Pop();
            int val1   = (int)context.Pop();
            int result = val1 ^ val2;

            context.Push(result);
        }
Ejemplo n.º 9
0
        public override void Run(NCSContext context)
        {
            // Reference: https://stackoverflow.com/questions/8125127/what-is-the-c-sharp-equivalent-of-java-unsigned-right-shift-operator
            int  val2   = (int)context.Pop();
            uint val1   = (uint)(int)context.Pop();
            uint result = val1 << val2;

            context.Push((int)result);
        }
Ejemplo n.º 10
0
        public override void Run(NCSContext context)
        {
            // Adds two floats together
            string val2   = (string)context.Pop();
            string val1   = (string)context.Pop();
            string result = val1 + val2;

            context.Push(result);
        }
Ejemplo n.º 11
0
        public override void Run(NCSContext context)
        {
            // Adds two integers together
            int val2   = (int)context.Pop();
            int val1   = (int)context.Pop();
            int result = val1 + val2;

            context.Push(result);
        }
Ejemplo n.º 12
0
        public override void Run(NCSContext context)
        {
            // Pushes an immediate value onto the stack
            object val2   = context.Pop();
            object val1   = context.Pop();
            bool   truth  = val1 != val2;
            int    result = truth ? 1 : 0;

            context.Push(result);
        }
Ejemplo n.º 13
0
        public override void Run(NCSContext context)
        {
            // Determines if two integers are equal
            int  val2   = (int)context.Pop();
            int  val1   = (int)context.Pop();
            bool truth  = val1 == val2;
            int  result = truth ? 1 : 0;

            context.Push(result);
        }
Ejemplo n.º 14
0
        public override void Run(NCSContext context)
        {
            // Determines if two floats are equal
            float val2   = (float)context.Pop();
            float val1   = (float)context.Pop();
            bool  truth  = val1 <= val2;
            int   result = truth ? 1 : 0;

            context.Push(result);
        }
Ejemplo n.º 15
0
        public override void Run(NCSContext context)
        {
            // Compute the logical OR of two integer values.
            int  val2   = (int)context.Pop();
            int  val1   = (int)context.Pop();
            bool truth  = (val1 != 0) || (val2 != 0);
            int  result = truth ? 1 : 0;

            context.Push(result);
        }
Ejemplo n.º 16
0
        public override void Run(NCSContext context)
        {
            // Determines if two strings are equal
            string val2   = (string)context.Pop();
            string val1   = (string)context.Pop();
            bool   truth  = val1 != val2;
            int    result = truth ? 1 : 0;

            context.Push(result);
        }
Ejemplo n.º 17
0
        public override void Run(NCSContext context)
        {
            context.Log(context.stack[context.stack.Count - 1]);
            context.Log(context.stack[context.stack.Count - 2]);

            // Determines if two integers are equal
            int  val2   = (int)context.Pop();
            int  val1   = (int)context.Pop();
            bool truth  = val1 >= val2;
            int  result = truth ? 1 : 0;

            context.Push(result);
        }
Ejemplo n.º 18
0
        // Copy the given number of bytes from the location specified in the stack to the top of the stack.
        public override void Run(NCSContext context)
        {
            int start = int.Parse(args[1]); // This should always be a multiple of 4
            int size  = int.Parse(args[2]); // This should always be a multiple of 4

            while (size > 0)
            {
                // We don't add (+ 4 * i) because every time we push to the stack the top gets pushed up;
                // i..e the + 4 to the offset happens for us when we push to the stack, since the position is relative
                int    offset = start;
                object value  = context.GetOffsetSP(offset);
                context.Push(value);
                size -= 4;
            }
        }
Ejemplo n.º 19
0
        public override void Run(NCSContext context)
        {
            // Add the given number of bytes from the location specified
            // relative to the base pointer to the top of the stack.
            int offset = int.Parse(args[1]) - 4;
            int size   = int.Parse(args[2]);

            while (size > 0)
            {
                object value = context.GetOffsetBP(offset);
                context.Push(value);

                size   -= 4;
                offset += 4;
            }
        }
Ejemplo n.º 20
0
 // Reserves space on the stack for an object
 public override void Run(NCSContext context)
 {
     // Not required
     context.Push(new object());
 }
Ejemplo n.º 21
0
        // Runs an engine function (defined in nwscript.nss)
        public override void Run(NCSContext context)
        {
            context.Log("Calling " + args[1]);

            // Get the function definition for the action
            int method_idx = int.Parse(args[1]);

            string method_name = NWScript_Actions.ACTIONS[method_idx];

            UnityEngine.Debug.Log("Calling action " + method_name);

            MethodInfo m = nwscript.GetMethod(method_name);

            UnityEngine.Debug.Log("Action " + method_name + " has MethodInfo " + m);
            // MethodInfo[] methods = typeof(AuroraEngine.NWScript).GetMethods(BindingFlags.Public | BindingFlags.Static);
            // UnityEngine.Debug.Log("Calling method " + method_idx + " of " + methods.Length);
            // MethodInfo m = methods[method_idx];
            // UnityEngine.Debug.Log("Calling method no " + method_idx + ": " + m.Name);

            if (m == null)
            {
                Debug.LogError("Warning: could not find method " + args[1]);
            }

            int paramCount = int.Parse(args[2]);

            object[] parameters = new object[m.GetParameters().Length];

            context.Log("Method " + m.Name + " has " +
                        m.GetParameters().Length + " parameter(s)" +
                        " and providing " + paramCount
                        );

            ParameterInfo[] paramInfo = m.GetParameters();
            for (int i = 0; i < paramCount; i++)
            {
                ParameterInfo p = paramInfo[i];

                if (p.ParameterType == typeof(NCSContext))
                {
                    context.Log("Getting parameter from store state stack");
                    parameters[i] = context.GetState();
                }
                else if (p.ParameterType == typeof(AuroraVector))
                {
                    context.Log("Getting vector from stack");

                    context.Log(context.stack.Last());
                    float x = (float)context.Pop();
                    context.Log(context.stack.Last());
                    float y = (float)context.Pop();
                    context.Log(context.stack.Last());
                    float z = (float)context.Pop();

                    parameters[i] = new AuroraVector(x, y, z);
                }
                else
                {
                    context.Log("Getting parameter from stack");
                    parameters[i] = context.Pop();
                }
                context.Log("Parameter " + i + ": " + parameters[i]);
            }

            // Add any optional parameters if we need to
            for (int i = paramCount; i < m.GetParameters().Length; i++)
            {
                parameters[i] = Type.Missing;
            }

            // Generate the function call signature
            string signature = args[1] + "(";

            for (int i = 0; i < parameters.Length; i++)
            {
                signature += parameters[i];
                if (i != parameters.Length - 1)
                {
                    signature += ",";
                }
            }

            signature += ")";

            object return_value;

            try
            {
                return_value = m.Invoke(null, parameters);
            }
            catch (Exception e)
            {
                LoggedEvents.Log("  Action", "FAILED: " + signature);
                throw e;
            }

            LoggedEvents.Log("  Action", signature + " = " + return_value);

            context.Log(m.Name + " returned with value " + return_value);

            if (m.ReturnType == typeof(void))
            {
            }
            else if (m.ReturnType == typeof(AuroraVector))
            {
                AuroraVector vec = (AuroraVector)return_value;
                context.Push(vec.z);
                context.Push(vec.y);
                context.Push(vec.x);
            }
            else
            {
                context.Push(return_value);
            }
        }
Ejemplo n.º 22
0
 // Reserves space on the stack for a string
 public override void Run(NCSContext context)
 {
     context.Push("");
 }