public static List <dialog> getDialogListRAW(string inFile, bool format = false) { pOps.MaxDegreeOfParallelism = threads; List <dialog> dlist = new List <dialog>(); Header head = getHeader(inFile); int script_offset = head.sOffset; int script_size = head.sSize; EndianBinaryReader reader = new EndianBinaryReader(EndianBitConverter.Little, File.Open(inFile, FileMode.Open, FileAccess.Read)); reader.BaseStream.Position = script_offset; MemoryStream scriptStream = new MemoryStream(reader.ReadBytes(script_size)); reader.Close(); while (scriptStream.Position != scriptStream.Length) { dialog d = new dialog(); d.offset = scriptStream.Position;// + script_offset; d.text = ReadStringZ(scriptStream); d.size = Encoding.UTF8.GetBytes(d.text).Length; dlist.Add(d); } if (format) { List <dialog> final = new List <dialog>(); Parallel.ForEach(dlist, pOps, dl => { dialog tmp = new dialog(); tmp.offset = dl.offset; tmp.size = dl.size; string tmps = dl.text; tmps = tmps.Replace(Encoding.UTF8.GetString(new byte[] { 0x0A }), "<LINEEND>"); tmps = tmps.Replace(Encoding.UTF8.GetString(new byte[] { 0x00 }), "<END>"); tmp.text = tmps; lock (fLock) { final.Add(tmp); } }); dlist.Clear(); return(final.OrderBy(o => o.offset).ToList()); } else { return(dlist); } }
// Summary: // Gets a List<dialog> from asb file. public static List <dialog> getDialogList(string inFile, bool format = false, bool eventOnly = false) { pOps.MaxDegreeOfParallelism = threads; List <dialog> dlist = new List <dialog>(); Header head = getHeader(inFile); int script_offset = head.sOffset; int script_size = head.sSize; EndianBinaryReader reader = new EndianBinaryReader(EndianBitConverter.Little, File.Open(inFile, FileMode.Open, FileAccess.Read)); reader.BaseStream.Position = script_offset; MemoryStream scriptStream = new MemoryStream(reader.ReadBytes(script_size)); reader.Close(); while (scriptStream.Position != scriptStream.Length) { dialog d = new dialog(); d.offset = scriptStream.Position + script_offset; d.text = ReadStringZ(scriptStream); d.size = Encoding.UTF8.GetBytes(d.text).Length; dlist.Add(d); } if (format && !eventOnly) { List <dialog> final = new List <dialog>(); Parallel.ForEach(dlist, pOps, dtpl => { if (dtpl.text.StartsWith(Encoding.UTF8.GetString(new byte[] { 0x40 })) || dtpl.text.StartsWith(Encoding.UTF8.GetString(new byte[] { 0x00 })) || dtpl.text.StartsWith("//") || dtpl.text.StartsWith("pow( x,") || dtpl.text.StartsWith("env") || dtpl.text.StartsWith("__main") || dtpl.text.StartsWith("main") || dtpl.text.StartsWith("se") || Regex.IsMatch(dtpl.text, "([0-9]{2}_[0-9]{2}_[0-9]{4})")) { } else { dialog tmp = new dialog(); tmp.offset = dtpl.offset; tmp.size = dtpl.size; string tmps = dtpl.text; tmps = tmps.Replace(Encoding.UTF8.GetString(new byte[] { 0x0A }), "<LINEEND>"); tmps = tmps.Replace(Encoding.UTF8.GetString(new byte[] { 0x00 }), "<END>"); tmp.text = tmps; lock (fLock) { final.Add(tmp); } } }); dlist.Clear(); return(final.OrderBy(o => o.offset).ToList()); } else if (eventOnly) { List <dialog> final = new List <dialog>(); bool write = false; string filename = "@" + Path.GetFileNameWithoutExtension(inFile); Parallel.ForEach(dlist, pOps, dl => { if (write) { if (dl.text.StartsWith(Encoding.UTF8.GetString(new byte[] { 0x40 })) || dl.text.StartsWith(Encoding.UTF8.GetString(new byte[] { 0x00 })) || dl.text.StartsWith("//") || dl.text.StartsWith("env") || dl.text.StartsWith("pow( x,") || dl.text.StartsWith("__main") || dl.text.StartsWith("main") || dl.text.StartsWith("se") || Regex.IsMatch(dl.text, "([0-9]{2}_[0-9]{2}_[0-9]{4})")) { } else { dialog tmp = new dialog(); tmp.offset = dl.offset; tmp.size = dl.size; string tmps = dl.text; tmps = tmps.Replace(Encoding.UTF8.GetString(new byte[] { 0x0A }), "<LINEEND>"); tmps = tmps.Replace(Encoding.UTF8.GetString(new byte[] { 0x00 }), "<END>"); tmp.text = tmps; lock (fLock) { final.Add(tmp); } } } else { if (dl.text.Contains(filename)) { write = true; } } }); dlist.Clear(); return(final.OrderBy(o => o.offset).ToList()); } else { return(dlist); } }