public override void Run(NCSContext context) { int val2 = (int)context.Pop(); int val1 = (int)context.Pop(); int result = val1 % val2; context.Push(result); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public override void Run(NCSContext context) { int stackSize = int.Parse(args[1]); int dontRemoveOffset = int.Parse(args[2]); int dontRemoveSize = int.Parse(args[3]); List <object> tmp = new List <object>(); while (stackSize > 0) { object obj = context.Pop(); if ((stackSize <= (dontRemoveOffset + dontRemoveSize)) && (stackSize > dontRemoveOffset)) { tmp.Add(obj); } stackSize -= 4; } if (tmp.Count != dontRemoveSize / 4) { throw new Exception("Expected tmp.Count = " + dontRemoveSize / 4 + " but found " + tmp.Count); } foreach (object obj in tmp) { context.Push(obj); } }
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); }
public override void Run(NCSContext context) { // Computes the negation of an int int val1 = (int)context.Pop(); int result = -val1; context.Push(result); }
public override void Run(NCSContext context) { // https://stackoverflow.com/questions/50870534/ones-complement-in-c-sharp int val1 = (int)context.Pop(); int result = ~val1; context.Push(result); }
public override void Run(NCSContext context) { // Computes the negation of a float float val1 = (float)context.Pop(); float result = -val1; context.Push(result); }
public override void Run(NCSContext context) { string label = args[1]; // int offset = context.script.labels[label]; int stackTop = (int)context.Pop(); if (stackTop != 0) { // Jump to the label int offset = int.Parse(args[1]); context.JumpOffset(offset); } }
public override void Run(NCSContext context) { // string label = args[1]; // int offset = context.script.labels[label]; object top = context.Pop(); UnityEngine.Debug.Log("Top of stack: " + top); int stackTop = (int)top; if (stackTop == 0) { // Jump to the label int offset = int.Parse(args[1]); context.JumpOffset(offset); } }
public override void Run(NCSContext context) { // TODO: Check whether this is correct: // In Xoreos they subtract the offset from the stack pointer? int offset = -int.Parse(args[1]); while (offset > 0) { // TODO: Make this work for vectors and structs try { context.Pop(); } catch { Debug.LogError("Could not pop from stack with MOVSP, offset = " + offset); return; } offset -= 4; } }
// 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); } }
public override void Run(NCSContext context) { int basePtr = (int)context.Pop(); context.basePointer = basePtr; }