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 NCSContext(NCSScript script, NCSFile file) { this.script = script; this.file = file; // programCounter = 0; // returnStack.Clear(); // returnStack.Add(-1); }
void LoadScript() { loc = EditorUtility.OpenFilePanel("Open Script", "", "*.ncs"); using (Stream stream = new FileStream(loc, FileMode.Open)) { script = new NCSScript(stream, Path.GetFileNameWithoutExtension(loc)); } DecompileScript(script); }
int Execute(AuroraObject caller, NCSScript script, NCSContext context, int scriptVar, bool isConditional = false) { Debug.Log("Executing script: '" + script.scriptName + "'"); LoggedEvents.Log("Run Script", script.scriptName); if (pauseOnScript) { Debug.Log("Pausing before script " + script.scriptName); Debug.Break(); } // Add a new level of nesting to ObjectSelfStack and events events.Add(new List <AuroraEvent>()); assignedCommands.Add(new List <AuroraCommand>()); contexts.Push(context); scriptVars.Add(scriptVar); context.objectSelf = caller; int value = -1; //try //{ if (isConditional) { value = script.RunConditional(context); } else { script.Run(context); } //} //catch (Exception e) //{ // CreateStackTrace(); // Debug.LogError(e.Message + "\n" + e.Source + "\n" + e.StackTrace + "\n " + e.InnerException); //} RunEvents(); RunAssignedCommands(); scriptVars.RemoveAt(scriptVars.Count - 1); contexts.Pop(); assignedCommands.RemoveAt(assignedCommands.Count - 1); events.RemoveAt(events.Count - 1); LoggedEvents.Log("Finished Script", script.scriptName); return(value); }
void LoadScript() { location = EditorUtility.OpenFilePanel( "Open compiled NCS file", "D:\\KOTOR\\KOTOR1\\KOTOR\\tools\\dencs\\dencs_py", "ncs" ); using (FileStream fs = File.OpenRead(location)) { script = new NCSScript(fs, "script"); context = new NCSContext(script, script.file); } }
void MoveFromEntry() { // TODO: Not convinced by this... if (curEntry == null) { EndDialog(); return; } if (curEntry.RepliesList.Count == 0) { // Dialog is finished EndDialog(); return; } curMode = DialogMode.PC; // Get the options for the PC to choose replies.Clear(); foreach (AuroraDLG.AEntry.AReplies rply in curEntry.RepliesList) { if (rply.Active == "") { replies.Add(rply); continue; } NCSScript rplyScript = AuroraEngine.Resources.LoadScript(rply.Active); if (rplyScript.RunConditional(new NCSContext(rplyScript, rplyScript.file)) > 0) { replies.Add(rply); } } if (replies.Count != 1) { return; } string txt = AuroraEngine.Resources.GetString(dialogue.ReplyList[(int)replies[0].Index].Text); if (txt != "") { return; } MoveFromReply(0); }
public static NCSScript LoadScript(string resourceRef) { if (!scriptCache.ContainsKey(resourceRef)) { Stream stream = data.GetStream(resourceRef, ResourceType.NCS); if (stream == null) { UnityEngine.Debug.Log("Missing ncs: " + resourceRef); return(null); } scriptCache[resourceRef] = new NCSScript(stream, resourceRef); } return(scriptCache[resourceRef]); }
string DecompileScript(NCSScript script) { // Preprocessing script = Preprocess(script); //// Parse subroutines SubroutineGraph subGraph = new SubroutineGraph(script); // Perform heuristic signature analysis // Parse globals // Perform data-flow analysis // Perform control-flow analysis // Convert to NSS code return(null); }
public int RunConditionalScript(string resref, AuroraObject caller) { if (scriptOverrides.ContainsKey(resref)) { return(scriptOverrides[resref](caller, -1)); } NCSScript script = AuroraEngine.Resources.LoadScript(resref.Replace("\"", "")); if (script == null) { Debug.LogWarning("Conditional script " + resref + " not found"); return(0); } NCSContext context = new NCSContext(script, script.file); Debug.Log("Running conditional script " + resref); return(Execute(caller, script, context, -1, true)); }
NCSScript Preprocess(NCSScript script) { return(script); }
// Start is called before the first frame update void Start() { script = AuroraEngine.Resources.LoadScript(ScriptName); context = new NCSContext(script, script.file); }
void MoveFromReply(int idx) { curReply = dialogue.ReplyList[(int)replies[idx].Index]; Debug.Log((int)replies[idx].Index); //Debug.Log(curReply.id); if (curReply.Script != null && curReply.Script != "") { stateManager.RunScript(curReply.Script, stateManager.PC); } if (curReply.EntriesList.Count == 0) { // Dialog is finished EndDialog(); return; } curMode = DialogMode.NPC; // Get the next line of NPC dialog // TODO: Use conditional logic here by calling NCS scripts foreach (AuroraDLG.AReply.AEntries rply in curReply.EntriesList) { if (rply.Active == "") { curEntry = dialogue.EntryList[(int)rply.Index]; break; } NCSScript script = AuroraEngine.Resources.LoadScript(rply.Active); int value = script.RunConditional(new NCSContext(script, script.file)); if (value > 0) { curEntry = dialogue.EntryList[(int)rply.Index]; break; } else { Debug.Log("Conditional " + curEntry.Script + " failed"); } } // Load the audio AudioClip audio = GetAudioClip(); //LIP lipsync = AuroraEngine.Resources.LoadLipSync(curEntry.VO_ResRef); //if (lipsync != null) //{ // Debug.Log("Lip sync has length " + lipsync.length + " and " + lipsync.frames.Length + " frames"); //} if (audio != null) { Debug.Log("Found audio"); audioSource.clip = audio; audioSource.Play(); timer = audio.length; } else { Debug.Log("Did not find audio"); timer = 0; } if (timer == 0 && curEntry.CameraAnimation > 0) { timer = GetAnimationState().length; } if (curEntry.Delay > 0 && curEntry.Delay < 100000) { timer = curEntry.Delay; } // Run the on-play script for the current line being played if (curEntry.Script != "") { // TODO: Check who is the owner of the script when it's run through RuNScript stateManager.RunScript(curEntry.Script, stateManager.PC); } }
public void Initialize(string[] args, NCSScript script) { this.args = args; this.script = script; }
void ResetTool() { script = null; context = null; }