public Trigger CreateNewTrigger(eSlotAonTypeObj typeObj) { Trigger trigger = null; int idGen = -1; if (typeObj == eSlotAonTypeObj.Warps) { idGen = WarpsData.Count; WarpsData.Add(new Warps()); trigger = WarpsData[idGen]; } else if (typeObj == eSlotAonTypeObj.Signposts) { idGen = SignpostsData.Count; SignpostsData.Add(new Signposts()); trigger = SignpostsData[idGen]; } else if (typeObj == eSlotAonTypeObj.Person) { idGen = NPCData.Count; NPCData.Add(new NPC()); trigger = NPCData[idGen]; // ComboBoxHelper.Instance.ResetDataNPCList(); } else if (typeObj == eSlotAonTypeObj.Script) { idGen = ScriptData.Count; ScriptData.Add(new Script()); trigger = ScriptData[idGen]; // ComboBoxHelper.Instance.ResetDataScriptList(); } return(trigger); }
void Awake() { GameState = FindObjectOfType <GlobalGameStateManager>(); textList = new string[] { }; InitTypewriter(false); Script = FindObjectOfType <ScriptData>(); }
private void WriteStrings(ScriptData data, IStream stream, StructureValueCollection scnr) { int oldStringsSize = (int)scnr.GetInteger("script string table size"); uint oldStringAddress = (uint)scnr.GetInteger("script string table address"); long expOldStringAddress = _expander.Expand(oldStringAddress); long newStringsAddress = 0; // Check if the returned data contained strings if (data.Strings.Size > 0) { // allocate space for the string table if (oldStringsSize > 0) { newStringsAddress = _allocator.Reallocate(expOldStringAddress, oldStringsSize, data.Strings.Size, stream); } else { newStringsAddress = _allocator.Allocate(data.Strings.Size, stream); } // write strings stream.SeekTo(_metaArea.PointerToOffset(newStringsAddress)); data.Strings.Write(stream); } // free the old string table if the new scripts didn't contain strings (impossible) else if (oldStringsSize > 0) { _allocator.Free(expOldStringAddress, oldStringsSize); } scnr.SetInteger("script string table size", (uint)data.Strings.Size); scnr.SetInteger("script string table address", _expander.Contract(newStringsAddress)); }
/// <summary> /// given input contents, parse it, and return a ScriptData object /// this can throw /// </summary> /// <param name="inputContents">The Bash File or JSON file contents</param> /// <returns></returns> private static ScriptData FromFileContents(string inputContents) { if (inputContents == "") { throw new ArgumentException("The file is empty"); } ScriptData scriptData = null; // is it bash, json, or trash? // bw scripts start with # and JSON with { switch (inputContents[0]) { case '#': { // treat like a Bash Wizard shell script - parse it and echo out a new bash script scriptData = ScriptData.FromBash(inputContents); } break; case '{': { // treat like a JSON file - echo out a new bash script based on the JSON scriptData = ScriptData.FromJson(inputContents, ""); } break; default: throw new Exception($"The input is not a JSON file or a Bash Wizard File because the first character is {inputContents[0]} instead of a # or a {{"); } return(scriptData); }
public void SaveScripts(ScriptData data, IStream stream, IProgress <int> progress) { progress.Report(0); StructureValueCollection values = LoadScriptTag(stream, _scnrTag); StructureLayout scnrLayout = _buildInfo.Layouts.GetLayout("scnr"); progress.Report(10); WriteExpressions(data, stream, values); progress.Report(40); WriteStrings(data, stream, values); progress.Report(50); WriteGlobals(data, stream, values); progress.Report(60); WriteTagReferences(data, stream, values); progress.Report(70); WriteScripts(data, stream, values); progress.Report(90); stream.SeekTo(_scnrTag.MetaLocation.AsOffset()); StructureWriter.WriteStructure(values, scnrLayout, stream); progress.Report(100); }
public ResourceEntry WriteScriptEntry(ResourceEntry entry, XPathNodeIterator nodes, string sdsFolder, XmlNode descNode) { //get xml data. nodes.Current.MoveToNext(); string path = nodes.Current.Value; nodes.Current.MoveToNext(); int numScripts = Convert.ToInt32(nodes.Current.Value); //main stuff ScriptResource resource = new ScriptResource(); resource.Path = path; for (int i = 0; i != numScripts; i++) { ScriptData data = new ScriptData(); nodes.Current.MoveToNext(); data.Name = nodes.Current.Value; data.Data = File.ReadAllBytes(sdsFolder + data.Name); resource.Scripts.Add(data); } //finish nodes.Current.MoveToNext(); ushort version = Convert.ToUInt16(nodes.Current.Value); MemoryStream stream = new MemoryStream(); resource.Serialize(version, stream, Endian.Little); entry.Version = version; entry.Data = stream.GetBuffer(); descNode.InnerText = path; return(entry); }
/// <summary> /// Compares two script data. /// </summary> private static int CompareScriptData(ScriptData x, ScriptData y) { CategoryData categoryX = x as CategoryData; CategoryData categoryY = y as CategoryData; NodeData nodeX = x as NodeData; NodeData nodeY = y as NodeData; if (categoryX != null && categoryY != null) { return(categoryX.Name.CompareTo(categoryY.Name)); } else if (categoryX != null && categoryY == null) { return(-1); } else if (categoryX == null && categoryY != null) { return(1); } else if (nodeX != null && nodeY != null) { return(nodeX.Name.CompareTo(nodeY.Name)); } else { Debug.Assert(true, "Not supported types."); return(0); } }
static ScriptData GetScriptData(string fn) { ScriptData res; if (!scripts.TryGetValue(fn, out res)) { res = new ScriptData { Script = new Script() }; res.Script.Options.DebugPrint = (s) => Debug.Log(s); // グローバル変数に設定 res.Script.Globals["Param"] = UserData.CreateStatic <Param>(); res.Script.Globals["Attribute"] = UserData.CreateStatic <Attribute>(); res.Script.Globals["Race"] = UserData.CreateStatic <Race>(); res.Script.Globals["Side"] = UserData.CreateStatic <Unit.Side>(); var text = Resources.Load <TextAsset>($"Skill/{fn}").text; res.Script.DoString(text); res.Func = res.Script.Globals["Exec"]; // キャッシュ scripts[fn] = res; } return(res); }
private void LoadScript(ScriptData scriptData) { Debug.Log($"Loading script {scriptData.name}..."); _scriptData = scriptData; ScriptView.LoadScript(_scriptData); }
public static void OpenAsset(ScriptData scriptData) { ScriptEditorWindow window = GetWindow <ScriptEditorWindow>(); window.LoadScript(scriptData); window.Show(); }
private static void LoadAndSave(string input, string output) { Console.WriteLine($"updating {input}"); string oldBash = System.IO.File.ReadAllText(input); ScriptData data = ScriptData.FromBash(oldBash); File.WriteAllText(output, data.BashScript); }
private void CreateNewScript() { Debug.Log("Creating new script..."); _scriptData = CreateInstance <ScriptData>(); _scriptData.name = "ScriptData"; ScriptView.LoadScript(_scriptData); }
public EmbeddedScript(ScriptData Data, SimpleSubrecord <Byte[]> CompiledScript, SimpleSubrecord <Char[]> ScriptSource, List <LocalVariable> LocalVariables, List <Subrecord> References) { this.Data = Data; this.CompiledScript = CompiledScript; this.ScriptSource = ScriptSource; this.LocalVariables = LocalVariables; this.References = References; }
public void InitializeMRM(IScriptModulePlugin plugin, ScriptData data, MRMBase mmb, uint localID, UUID itemID) { IWorld world; IHost host; GetGlobalEnvironment(plugin, data, localID, out world, out host); mmb.InitMiniModule(world, host, itemID); }
public int CreateNewScript() { int idGen = ScriptData.Count; ScriptData.Add(new Script()); ComboBoxHelper.Instance.ResetTypeObj(eSlotAonTypeObj.Script); // ComboBoxHelper.Instance.ResetDataScriptList(); return(idGen); }
public ScriptData[] GetScriptData() { List<ScriptData> myList=new List<ScriptData>(); string [] StringArray=File.ReadAllLines(FileName); for(int ctr=0;ctr<StringArray.Length;ctr++) { string temp=StringArray[ctr].Trim(); if(temp.StartsWith("//")||(temp==String.Empty)) continue; // this is a comment string [] splitstr=temp.Split(new char[]{','}); ScriptData myScriptData= new ScriptData(); try { if(splitstr[0].Trim().ToUpper()=="SIX") myScriptData.Command=Commands.SIX; else if(splitstr[0].Trim().ToUpper()=="ENTERICSPNORMALMODE") myScriptData.Command=Commands.ENTERICSPNORMAL; else if(splitstr[0].Trim().ToUpper()=="FORCEDSIX") myScriptData.Command=Commands.FORCEDSIX; else if(splitstr[0].Trim().ToUpper()=="EXIT_ICSP") myScriptData.Command=Commands.EXITICSP; else if(splitstr[0].Trim().ToUpper()=="REGOUT") myScriptData.Command=Commands.REGOUT; else if(splitstr[0].Trim().ToUpper()=="SIX_AFTER_REGOUT") myScriptData.Command=Commands.SIX_AFTER_REGOUT; //PIC18 else if(splitstr[0].Trim().ToUpper()=="PIC18ENTERICSP") myScriptData.Command=Commands.PIC18ENTERICSP; else if(splitstr[0].Trim().ToUpper()=="SEND4BITCOMMANDMSBFIRST") // this must be changed TODO myScriptData.Command=Commands.SEND4BITCOMMANDLSBFIRST; else if(splitstr[0].Trim().ToUpper()=="SEND16BITDATALSBFIRST") myScriptData.Command=Commands.SEND16BITDATALSBFIRST; else if(splitstr[0].Trim().ToUpper()=="READ8BITLSBFIRST") myScriptData.Command=Commands.READ8BITLSBFIRST; else if(splitstr[0].Trim().ToUpper()=="SEND8BITDATALSBFIRST") myScriptData.Command=Commands.SEND8BITDATALSBFIRST; else if(splitstr[0].Trim().ToUpper()=="DELAYCLKON4THBIT") myScriptData.Command=Commands.DELAYCLKON4THBIT; else throw new ApplicationException(); myScriptData.HexData=Convert.ToUInt32(splitstr[1].Trim(),16); myScriptData.Delay=Convert.ToInt32(splitstr[2].Trim()); myList.Add(myScriptData); } catch { throw new ApplicationException("Error in Line #" + (ctr+1).ToString() + "!"); } } return myList.ToArray(); }
public void LoadScript(ScriptData scriptData) { ScriptData = scriptData; DeleteElements(graphElements.ToList()); //Debug.Log($"Loading script '{scriptData.name}' with {scriptData.Nodes.Count} nodes..."); // add nodes foreach (ScriptNodeData nodeData in scriptData.Nodes) { AddNode(nodeData); } // add edges foreach (ScriptNodeData nodeData in Nodes.Values) { Type nodeType = nodeData.GetType(); var connections = nodeType.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) .Where(x => Attribute.IsDefined(x, typeof(ConnectionAttribute))); foreach (FieldInfo connection in connections) { ConnectionAttribute attr = connection.GetCustomAttribute <ConnectionAttribute>(); if (attr.ConnectionDirection != ConnectionAttribute.Direction.Output) { continue; } ScriptNodePortData outputPort = (ScriptNodePortData)connection.GetValue(nodeData); if (!outputPort.IsConnected) { //Debug.Log($"Node {nodeData.Id} connection {outputPort.Id} not connected"); continue; } AddEdge(nodeData.Id, outputPort.Id, outputPort.NodeId, outputPort.PortId); } var outputs = nodeType.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) .Where(x => Attribute.IsDefined(x, typeof(OutputAttribute))); foreach (FieldInfo output in outputs) { OutputAttribute attr = output.GetCustomAttribute <OutputAttribute>(); ScriptNodePortData outputPort = (ScriptNodePortData)output.GetValue(nodeData); if (!outputPort.IsConnected) { //Debug.Log($"Node {nodeData.Id} output {outputPort.Id} not connected"); continue; } AddEdge(nodeData.Id, outputPort.Id, outputPort.NodeId, outputPort.PortId); } } }
public void GetGlobalEnvironment(IScriptModulePlugin plugin, ScriptData data, uint localID, out IWorld world, out IHost host) { // UUID should be changed to object owner. UUID owner = data.World.RegionInfo.EstateSettings.EstateOwner; SEUser securityUser = new SEUser(owner, "Name Unassigned"); SecurityCredential creds = new SecurityCredential(securityUser, data.World); world = new World(data.World, creds); host = new Host(new SOPObject(data.World, localID, creds), data.World, new ExtensionHandler(plugin.Extensions)); }
public static IEnumerable <dynamic> GetData(ScriptResult result, string key) { if (string.IsNullOrEmpty(key)) { key = "default"; } ScriptData data = result.DataSet[key]; return(data.Items); }
public void LoadScriptWithIsolatedScope(string p_fileToLLoad) { // Wipe the stack for the script to reconfigure this.m_dataForScriptsToSetup = new ScriptData(); // Do the Script this.m_luaEngine.DoFile(p_fileToLLoad); // Setup long term storage for information from scripts this.m_ScriptInfo.Add(p_fileToLLoad, m_dataForScriptsToSetup); }
public override void ReadXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; if (ele.TryPathTo("Data", false, out subEle)) { if (Data == null) { Data = new ScriptData(); } Data.ReadXML(subEle, master); } if (ele.TryPathTo("CompiledScript", false, out subEle)) { if (CompiledScript == null) { CompiledScript = new SimpleSubrecord <Byte[]>(); } CompiledScript.ReadXML(subEle, master); } if (ele.TryPathTo("ScriptSource", false, out subEle)) { if (ScriptSource == null) { ScriptSource = new SimpleSubrecord <Char[]>(); } ScriptSource.ReadXML(subEle, master); } if (ele.TryPathTo("LocalVariables", false, out subEle)) { if (LocalVariables == null) { LocalVariables = new List <LocalVariable>(); } foreach (XElement e in subEle.Elements()) { LocalVariable temp = new LocalVariable(); temp.ReadXML(e, master); LocalVariables.Add(temp); } } ReadReferencesXML(ele, master); ReadLocalReferenceXML(ele, master); ReadGlobalReferenceXML(ele, master); }
public void FinishCompile(IScriptModulePlugin plugin, ScriptData data, IScript Script) { MRMBase mmb = (MRMBase)Script; if (mmb == null) { return; } InitializeMRM(plugin, data, mmb, data.Part.LocalId, data.ItemID); mmb.Start(); }
private static bool OpenScriptData(string assetPath) { ScriptData scriptData = AssetDatabase.LoadAssetAtPath <ScriptData>(assetPath); if (null == scriptData) { return(false); } ScriptEditorWindow.OpenAsset(scriptData); return(true); }
private static ByteProcessor ProcessScriptData(ScriptDataProcessor processor) { return(delegate(FileEntry fe, PackageFileEntry pfe, byte[] data) { using var mr = new MemoryStream(data); using var br = new BinaryReader(mr); var sd = new ScriptData(br, Utils.IsRaid()); var root = sd.Root as Dictionary <string, object>; return processor(fe, pfe, root); }); }
public double script(ScriptFunctions sf, ScriptData sd) { double fixingValue = 0.0; double payoff = 0.0; double yield = 0.0; bool iscalled = false; double discount = 1.0; int i = 0; double strike = sd.INDEX("strike")[0]; // Go through all dates // for (int t = 0; t < sf.PATHNB(); t++) { double k = sf.PATHVALUE(t); if (sf.PATHTIME(t) == sd.TIME("fixing")[i] && (iscalled == false)) { fixingValue = sf.PATHVALUE(t); yield = fixingValue / strike; if (yield > 1.0) { iscalled = true; discount = sf.DISCOUNT(sf.PATHTIME(t)); payoff = (1 + sd.INDEX("coupons")[i]) * 100 * discount; sf.INSPOUT("ProbaCall " + i, 1.0); return(payoff); } i++; } } // if no previous payoff compute last redemption // fixingValue = sf.PATHVALUE(); yield = fixingValue / strike; discount = sf.DISCOUNT(); if ((iscalled == false) && (yield < sd.INDEX("barrier")[0])) { payoff = yield * 100 * discount; sf.INSPOUT("ProbaDown", 1.0); sf.INSPOUT("AvgDown", yield); } else { payoff = 100.0 * discount; sf.INSPOUT("ProbaMid", 1.0); } // return payoff // return(payoff); }
ScriptData Init_Script(UnityEditor.MonoScript script) { if (script == null) { throw new System.ArgumentNullException("Init_Script: script cannot be null"); } var scriptClass = script.GetClass(); if (scriptClass == null) { throw new System.ArgumentNullException("Init_Script: must be a monoscript with a valid class"); } ScriptData scriptData = null; if (scriptDataTable.TryGetValue(script, out scriptData)) { return(scriptData); } else { scriptData = scriptDataTable[script] = new ScriptData(); scriptData.script = script; } var fixedOrderAttribute = scriptClass.GetCustomAttributes(typeof(ScriptExecutionOrderAttribute), true).Cast <ScriptExecutionOrderAttribute>().FirstOrDefault(); if (fixedOrderAttribute != null) { scriptData.fixedOrderValue = fixedOrderAttribute.order; } var dependsOnAttributes = scriptClass.GetCustomAttributes(typeof(ScriptDependencyAttribute), true).Cast <ScriptDependencyAttribute>().ToArray(); foreach (var i in dependsOnAttributes) { var dependsOnTypes = i.GetScriptDependencies() .Where(x => typeLookup.ContainsKey(x)) .Select(x => typeLookup[x]) .ToArray(); foreach (var j in dependsOnTypes) { var dependsOnSD = Init_Script(j); dependsOnSD.dependedOnBy.Add(scriptData); scriptData.dependsOn.Add(dependsOnSD); } } return(scriptData); }
public string GetName(ScriptData script_data) { var script = script_data as AmiScriptData; if (null != script) { return(script.Id.ToString("x8")); } else { return(null); } }
private static void CheckForParseErrors(ScriptData scriptData) { if (scriptData.ParseErrors.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (var error in scriptData.ParseErrors) { sb.Append($"{error}"); } sb.Append("Please fix the errors and try again"); throw new Exception(sb.ToString()); } }
public ScriptTag(byte[] headerBytes, byte[] bodyBytes) : base(headerBytes) { if (Header.Filtered == 0) { MemoryStream memoryStream = new MemoryStream(bodyBytes); Name = ScriptData.ReadData(memoryStream); Value = ScriptData.ReadData(memoryStream); } else { throw new UnsupportedFormat("Script tag with filter is not supported"); } }
public void CancelHelperInvoke(MonoBehaviour script, string methodKey) { if (scriptDataList == null) { return; } ScriptData data = scriptDataList.Find(o => o.script.Equals(script)); if (data != null) { data.invokeList.RemoveAll(o => o.key == methodKey); } }
/// <summary> /// Compose into standard form any compositions in the decompositions table. /// </summary> private int Compose(int ch0, Regex block0, ScriptData sd, char[] text, int pos, int len) { if (pos + 1 >= len) // need at least 2 chars! { return(len); } int ch1 = text[pos + 1] - sd.@base; var block1 = GetBlockForChar(text[pos + 1]); if (block1 != block0) // needs to be the same writing system { return(len); } int ch2 = -1; if (pos + 2 < len) { ch2 = text[pos + 2] - sd.@base; var block2 = GetBlockForChar(text[pos + 2]); if (text[pos + 2] == '\u200D') // ZWJ { ch2 = 0xFF; } else if (block2 != block1) // still allow a 2-char match { ch2 = -1; } } for (int i = 0; i < decompositions.Length; i++) { if (decompositions[i][0] == ch0 && (decompositions[i][4] & (int)sd.flag) != 0) { if (decompositions[i][1] == ch1 && (decompositions[i][2] < 0 || decompositions[i][2] == ch2)) { text[pos] = (char)(sd.@base + decompositions[i][3]); len = StemmerUtil.Delete(text, pos + 1, len); if (decompositions[i][2] >= 0) { len = StemmerUtil.Delete(text, pos + 1, len); } return(len); } } } return(len); }
/// <summary> /// given file contents, output the JSON for the parameters /// </summary> /// <param name="inputContents"></param> /// <param name="outputFileName"></param> private static void OutputJson(string inputContents, string outputFileName) { var scriptData = ScriptData.FromBash(inputContents); CheckForParseErrors(scriptData); if (outputFileName == "") { Console.WriteLine(scriptData.ToJson()); Console.WriteLine(""); } else { File.WriteAllText(outputFileName, scriptData.ToJson()); } }
private void LoadScripts() { String[] scripts = Directory.GetFiles("Scripts/"); foreach (String script in scripts) { if ( script.Equals("Scripts/setup.lua") ) { // Load script as usual this.LoadScriptWithIsolatedScope(script); // Stash the info from the setup script m_dataFromSetupLua = m_dataForScriptsToSetup; // Remove the script from the dictionary so we don't try and process it m_ScriptInfo.Remove(script); // Keep on looping continue; } else { if (script.EndsWith(".lua")) { this.LoadScriptWithIsolatedScope(script); } } } }
internal void FinishCompile(ScriptData scriptData, IScript Script) { FindConverterForScript(scriptData.Source).FinishCompile(m_scriptEngine, scriptData, Script); }
public string GetName(ScriptData script_data) { var script = script_data as AmiScriptData; if (null != script) return script.Id.ToString ("x8"); else return null; }
private GrammarBuilder LoadSpeechInformation(ScriptData p_scriptData) { /*** Fake the old api from lorei * Run through the keywords and build the grammers for each of the functions * I also keep track of amout of entries added to each list. There doesn't * seem to be a way to keep to see if entires exist in the speech data structures * without building a parser(way to much work) ***/ // Data Choices keywords; int countKeywords = 0; Choices functions; int countFunctions = 0; Choices programs; int countPrograms = 0; Choices programActions; int countProgramActions = 0; Choices finalChoices = new Choices(); int countFinalChoices = 0; // Grammar Stuff GrammarBuilder m_FunctionExecution = new GrammarBuilder(); GrammarBuilder m_ProgramControl = new GrammarBuilder(); GrammarBuilder m_GrammarToReturn = new GrammarBuilder(); // Collect and setup all key words // Setup Keywords keywords = new Choices(p_scriptData.m_Keywords.ToArray()); countKeywords += p_scriptData.m_Keywords.Count; keywords.Add(m_LoreiApi.GetLoreiNames().ToArray()); countKeywords += m_LoreiApi.GetLoreiNames().Count; // Setup Function List functions = new Choices(p_scriptData.m_Functions.ToArray()); countFunctions += p_scriptData.m_Functions.Count; functions.Add(m_dataFromSetupLua.m_Functions.ToArray()); countFunctions += m_dataFromSetupLua.m_Functions.Count; foreach (var x in m_ScriptInfo.Values) { functions.Add(x.m_Functions.ToArray()); countFunctions++; } // Setup List of Programs; programs = new Choices(p_scriptData.m_Programs.ToArray()); countPrograms += p_scriptData.m_Programs.Count; // Program Functions programActions = new Choices(p_scriptData.m_ProgramActions.ToArray()); countProgramActions += p_scriptData.m_ProgramActions.Count; // Setup Grammar for lorei functions if ( countKeywords > 0 && countFunctions > 0 && countPrograms > 0 ) { m_FunctionExecution.Append(keywords); m_FunctionExecution.Append(functions); m_FunctionExecution.Append(programs); // Setup function grammars finalChoices.Add(m_FunctionExecution); // Keep track of number of final choices countFinalChoices++; } // Setup Grammar for program controls if (countKeywords > 0 && countPrograms > 0 && countProgramActions > 0) { m_ProgramControl.Append(keywords); m_ProgramControl.Append(programs); m_ProgramControl.Append(programActions); // Setup function grammars finalChoices.Add(m_ProgramControl); // Keep track of number of final choices countFinalChoices++; } if ( countFinalChoices > 0) { return finalChoices.ToGrammarBuilder(); } else { return null; } // Setup Engine //m_FunctionGrammar = new Grammar(m_FunctionExecution); //m_ProgramGrammar = new Grammar(m_ProgramControl); //m_FunctionGrammar.Name = "m_FunctionGrammar"; //m_ProgramGrammar.Name = "m_ProgramGrammar"; //m_LoreiApi.RegisterLoreiGrammar(m_FunctionGrammar); //m_LoreiApi.RegisterLoreiGrammar(m_ProgramGrammar); }
static void ProcessFile(string filePath) { Console.WriteLine(filePath); string txt = File.ReadAllText(filePath); string[] lines = File.ReadAllLines(filePath); Array.Reverse(lines); ArrayList scripts = new ArrayList(); ScriptData data = null; bool scriptStart = false; foreach (string line in lines) { if (line.IndexOf("Script *") != -1) { break; } if (line.IndexOf("->RegisterSelf();") != -1) { scriptStart = true; data = new ScriptData(); continue; } if (scriptStart) { if (line.IndexOf("= new Script") != -1) { scriptStart = false; scripts.Add(data); data = null; continue; } Regex r = new Regex("newscript->([a-zA-Z]+) *= *&?([\"_a-zA-Z0-9]+);"); Match m = r.Match(line); if (m.Success) { if (m.Groups[1].Value.Equals("Name")) { data.name = m.Groups[2].Value.Trim(new char[] { '"' }); } else { data.AddMethod(m.Groups[2].Value); } } continue; } } if (scripts.Count != 0) { string register = ""; foreach (ScriptData sd in scripts) { string ss = ""; Console.WriteLine(sd); int minPos = txt.Length; foreach (string method in sd.methods) { string s = GetMethod(method, ref txt, ref minPos); ss += s + "\n"; } if (sd.instanceName != null) { string s = GetMethod("struct " + sd.instanceName, ref txt, ref minPos); ss += s + "\n"; } if (sd.aiName != null) { string ai = GetMethod("struct " + sd.aiName, ref txt, ref minPos); if (ai != null) { string sm = null; Regex r = new Regex("\\S+ " + sd.aiName + "::([^( ]+)"); while (r.IsMatch(txt)) { Match m = r.Match(txt); int startPos = m.Index; int endPos = txt.IndexOf("\n}", startPos); if (endPos != -1) endPos += 2; while (endPos++ >= 0 && endPos < txt.Length) { if (txt[endPos] == '\n') break; } sm = txt.Substring(startPos, endPos - startPos); txt = txt.Remove(startPos, endPos - startPos); if (sm != null) { sm = sm.Replace("\n", "\n "); Regex r1 = new Regex("\\S+ " + m.Groups[1] + " *\\([^)]*\\) *;"); Match m1 = r1.Match(ai); if (m1.Success) { ai = r1.Replace(ai, sm); } } } ai = ai.Replace(sd.aiName + "::", ""); ss += ai + "\n"; } } if (ss.Length != 0) { string typeName = "UnknownScript"; switch (sd.type) { case 1: typeName = "CreatureScript"; break; case 2: typeName = "InstanceMapScript"; break; default: if (sd.name.IndexOf("npc") == 0) typeName = "CreatureScript"; else if (sd.name.IndexOf("mob") == 0) typeName = "CreatureScript"; else if (sd.name.IndexOf("boss_") == 0) typeName = "CreatureScript"; else if (sd.name.IndexOf("item_") == 0) typeName = "ItemScript"; else if (sd.name.IndexOf("go_") == 0) typeName = "GameObjectScript"; else if (sd.name.IndexOf("at_") == 0) typeName = "AreaTriggerScript"; else if (sd.name.IndexOf("instance_") == 0) typeName = "InstanceMapScript"; break; } if (sd.instanceName != null) ss = ss.Replace(sd.instanceName, sd.instanceName + "_InstanceMapScript"); ss = ss.Replace("\n", "\n "); ss = "class " + sd.name + " : public " + typeName + "\n{\npublic:\n " + sd.name + "() : " + typeName + "(\"" + sd.name + "\") { }\n" + ss + "\n};"; ss = ss.Replace("_" + sd.name, ""); ss = ss.Replace("AIAI", "AI"); ss = ss.Replace(" \r\n", "\r\n"); ss = ss.Replace(" \n", "\n"); txt = txt.Insert(minPos, ss); register = " new " + sd.name + "();\n" + register; } } Regex r2 = new Regex("void +AddSC_([_a-zA-Z0-9]+)"); Match m2 = r2.Match(txt); if (m2.Success) { txt = txt.Remove(m2.Index); txt += "void AddSC_" + m2.Groups[1].Value + "()\n{\n" + register + "}\n"; } // File.Copy(filePath, filePath + ".bkp"); txt = txt.Replace("\r\n", "\n"); File.WriteAllText(filePath, txt); } }
public override void Write(Stream stream, ScriptData script_data) { var script = script_data as AmiScriptData; if (null == script) throw new ArgumentException ("Illegal ScriptData", "script_data"); using (var file = new BinaryWriter (stream, Encodings.cp932, true)) { file.Write (Signature); file.Write (script.Type); uint count = (uint)script.TextLines.Count; file.Write (count); var index_pos = file.BaseStream.Position; file.Seek ((int)count*12, SeekOrigin.Current); var index = new IndexEntry[count]; int i = 0; foreach (var line in script.TextLines) { var text = Encodings.cp932.GetBytes (line.Text); index[i].offset = (uint)file.BaseStream.Position; index[i].size = (uint)text.Length; index[i].id = line.Id; file.Write (text); file.Write ((byte)0); ++i; } var end_pos = file.BaseStream.Position; file.BaseStream.Position = index_pos; foreach (var entry in index) { file.Write (entry.offset); file.Write (entry.size); file.Write (entry.id); } file.BaseStream.Position = end_pos; } }
public override void Write(Stream stream, ScriptData script_data) { var script = script_data as GscScriptData; if (null == script) throw new InvalidFormatException(); using (var file = new BinaryWriter (stream, Encodings.cp932, true)) { long file_size_pos = file.BaseStream.Position; file.Write ((int)0); file.Write ((int)(script.Header.Length + 0x14)); file.Write ((int)script.Code.Length); int line_count = script.TextLines.Count; int text_index_size = line_count * 4; file.Write (text_index_size); long text_size_pos = file.BaseStream.Position; file.Write ((int)0); if (0 < script.Header.Length) file.Write (script.Header); if (0 < script.Code.Length) file.Write (script.Code); long text_index_pos = file.BaseStream.Position; var index = new uint[line_count]; file.BaseStream.Seek (text_index_size, SeekOrigin.Current); int i = 0; long text_pos = file.BaseStream.Position; uint current_pos = 0; foreach (var line in script.TextLines) { index[i] = current_pos; var text = Encodings.cp932.GetBytes (line.Text); file.Write (text); file.Write ((byte)0); ++i; current_pos += (uint)text.Length + 1; } uint text_size = (uint)(file.BaseStream.Position - text_pos); if (0 < script.Footer.Length) file.Write (script.Footer); uint file_size = (uint)(file.BaseStream.Position - file_size_pos); file.BaseStream.Position = file_size_pos; file.Write (file_size); file.BaseStream.Position = text_size_pos; file.Write (text_size); file.BaseStream.Position = text_index_pos; foreach (var offset in index) file.Write (offset); file.BaseStream.Position = file_size_pos + file_size; } }
public void FinishCompile(IScriptModulePlugin plugin, ScriptData data, IScript Script) { MRMBase mmb = (MRMBase) Script; if (mmb == null) return; InitializeMRM(plugin, data, mmb, data.Part.LocalId, data.ItemID); mmb.Start(); }
public void FinishCompile (IScriptModulePlugin plugin, ScriptData data, IScript Script) { }
public void FinishCompile(IScriptModulePlugin plugin, ScriptData data, IScript Script) { Script.SetSceneRefs(data.World, data.Part, false); }
/// <summary> /// Compose into standard form any compositions in the decompositions table. /// </summary> private int Compose(int ch0, Regex block0, ScriptData sd, char[] text, int pos, int len) { if (pos + 1 >= len) // need at least 2 chars! { return len; } int ch1 = text[pos + 1] - sd.@base; var block1 = GetBlockForChar(text[pos + 1]); if (block1 != block0) // needs to be the same writing system { return len; } int ch2 = -1; if (pos + 2 < len) { ch2 = text[pos + 2] - sd.@base; var block2 = GetBlockForChar(text[pos + 2]); if (text[pos + 2] == '\u200D') // ZWJ { ch2 = 0xFF; } else if (block2 != block1) // still allow a 2-char match { ch2 = -1; } } for (int i = 0; i < decompositions.Length; i++) { if (decompositions[i][0] == ch0 && (decompositions[i][4] & (int)sd.flag) != 0) { if (decompositions[i][1] == ch1 && (decompositions[i][2] < 0 || decompositions[i][2] == ch2)) { text[pos] = (char)(sd.@base + decompositions[i][3]); len = StemmerUtil.Delete(text, pos + 1, len); if (decompositions[i][2] >= 0) { len = StemmerUtil.Delete(text, pos + 1, len); } return len; } } } return len; }