public override void Run(NCSContext context) { // Pushes an immediate value onto the stack string value = args[2]; context.Push(value); }
public override void Run(NCSContext context) { // Pushes an immediate value onto the stack float value = float.Parse(args[1]); context.Push(value); }
public override void Run(NCSContext context) { int basePtr = context.basePointer; context.Push(basePtr); context.basePointer = context.stackPointer; }
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); } }
void LoadDump() { string loc = "D:\\KOTOR\\KotOR-Unity\\Dump\\dump.json"; context = JsonConvert.DeserializeObject <NCSContext>(File.ReadAllText(loc)); script = context.script; }
public void RunScript(string resref, AuroraObject caller, int scriptVar = -1) { //Debug.Log("Running script " + resref + " with OBJECT_SELF=" + caller); // TODO: Figure out what to do with "scriptVar" if (resref == null) { return; } if (resref == "") { // This is not referring to a script, so just return return; } if (scriptOverrides.ContainsKey(resref)) { scriptOverrides[resref](caller, scriptVar); return; } NCSScript script = AuroraEngine.Resources.LoadScript(resref.Replace("\"", "")); if (script == null) { Debug.LogWarning("Could not find script " + resref); return; } NCSContext context = new NCSContext(script, script.file); Execute(caller, script, context, scriptVar); }
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); }
string ContextStatus(NCSContext context) { string str = "Script " + context.script.scriptName + " owned by " + context.objectSelf; str += "stopped @ PC = " + context.GetPC() + "; Last instruction: " + string.Join(" ", context.script.instructions[context.GetPC()].args); return(str); }
public override void Run(NCSContext context) { int val2 = (int)context.Pop(); int val1 = (int)context.Pop(); int result = val1 % val2; context.Push(result); }
public NCSContext GetState() { NCSContext ctx = stateStack.Last(); stateStack.RemoveAt(stateStack.Count - 1); return(ctx); }
public override void Run(NCSContext context) { // int newPC = script.labels[args[1]]; int offset = int.Parse(args[1]); context.JumpOffset(offset, true); // context.Jump(newPC); }
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) { int offset = int.Parse(args[1]); int value = ((int)context.GetOffsetBP(offset)) + 1; context.SetOffsetBP(offset, value); }
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) { if (context.stack.Count == 1) { context.last_return = context.stack[0]; } context.Return(); }
private void OnGUI() { using (new GUILayout.VerticalScope("box")) { using (new GUILayout.HorizontalScope("box")) { // Stack visualization using (var stackScope = new GUILayout.ScrollViewScope(stackScroll, "box", GUILayout.Width(Screen.width / 3), GUILayout.Height(2 * Screen.height / 3))) { stackScroll = stackScope.scrollPosition; for (int i = 0; i < context.stack.Count; i++) { if (context.stack[i] == null) { GUILayout.Label("NULL"); } else { GUILayout.Label(context.stack[i].ToString()); } } } // Instruction visualization using (var instScope = new GUILayout.ScrollViewScope(instScroll, "box", GUILayout.Width(Screen.width / 3), GUILayout.Height(2 * Screen.height / 3))) { instScroll = instScope.scrollPosition; for (int i = 0; i < script.instructions.Count; i++) { GUILayout.Label(i + ": " + script.instructions[i].ToString()); } } } using (new GUILayout.HorizontalScope("box")) { if (GUILayout.Button(">", GUILayout.Width(50), GUILayout.Height(50))) { script.Step(context); } if (GUILayout.Button(">>", GUILayout.Width(50), GUILayout.Height(50))) { running = !running; } if (GUILayout.Button("<<", GUILayout.Width(50), GUILayout.Height(50))) { context = new NCSContext(script, script.file); script.lastInstruction = null; } if (script.lastInstruction != null) { GUILayout.Label("Last instruction (" + context.programCounter + "): " + script.lastInstruction.ToString()); } } } }
public override void Run(NCSContext context) { // Moves forward a number of steps in the program // int newPC = script.labels[args[1]]; // context.programCounter = newPC; int offset = int.Parse(args[1]); context.JumpOffset(offset); }
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 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) { // 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) { // 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) { // 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) { // 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) { // 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 floats together float val2 = (float)context.Pop(); float val1 = (float)context.Pop(); float result = val1 + val2; context.Push(result); }
public void AssignCommand(AuroraObject obj, NCSContext ctx) { //Debug.Log("Assigning command to " + obj); assignedCommands.Last().Add(new AuroraCommand() { obj = obj, context = ctx }); }
void ShowEditor() { using (new EditorGUILayout.VerticalScope()) { // Main viewer using (new EditorGUILayout.HorizontalScope()) { // Show the stack using (var codeScope = new GUILayout.ScrollViewScope(codeScroll, "box", GUILayout.Width(Screen.width / 3), GUILayout.Height(2 * Screen.height / 3))) { codeScroll = codeScope.scrollPosition; DrawStack(); } // Show the ncs bytecode using (var stackScope = new GUILayout.ScrollViewScope(stackScroll, "box", GUILayout.Width(Screen.width / 3), GUILayout.Height(2 * Screen.height / 3))) { stackScroll = stackScope.scrollPosition; DrawCode(); } } // Controls using (new GUILayout.HorizontalScope("box")) { if (GUILayout.Button(">", GUILayout.Width(50), GUILayout.Height(50))) { script.Step(context); } if (GUILayout.Button(">10", GUILayout.Width(50), GUILayout.Height(50))) { for (int i = 0; i < 10; i++) { script.Step(context); } } if (GUILayout.Button(">50", GUILayout.Width(50), GUILayout.Height(50))) { for (int i = 0; i < 50; i++) { script.Step(context); } } if (GUILayout.Button("<<", GUILayout.Width(50), GUILayout.Height(50))) { context = new NCSContext(script, script.file); script.lastInstruction = null; } if (script.lastInstruction != null) { GUILayout.Label("Last instruction (" + context.programCounter + "): " + script.lastInstruction.ToString()); } } } }
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); }