public void Write(string fileOut, SQ translated) { Update_Blocks(ref translated); BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut)); bw.Write(translated.id); // First 4 blocks for (int i = 0; i < translated.sblocks.Length; i++) { bw.Write(translated.sblocks[i].size); bw.Write(enc.GetBytes(Helper.LatinToSJIS(translated.sblocks[i].text))); } bw.Write(translated.unknown); bw.Write(translated.num_fblocks); // Write final blocks for (int i = 0; i < translated.fblocks.Length; i++) { bw.Write(translated.fblocks[i].size); bw.Write(enc.GetBytes(Helper.LatinToSJIS(translated.fblocks[i].text))); } bw.Write(translated.num_final); for (int i = 0; i < translated.final.Length; i++) { bw.Write((byte)(translated.final[i].Length - 4)); bw.Write(translated.final[i]); } bw.Flush(); bw.Close(); }
private void TEST() { // Test method to know if it's working with all the files // it could be useful later to import all of them in one time (batch mode) string folder = @"G:\nds\projects\ninokuni\Quest\"; string[] files = Directory.GetFiles(folder, "*.sq"); for (int i = 0; i < files.Length; i++) { SQ temp = Read(files[i]); string temp_xml = files[i] + ".xml"; Export_XML(temp_xml, temp); Import_XML(temp_xml, ref temp); string temp_sq = files[i] + ".nSQ"; Write(temp_sq, temp); if (!Compare(files[i], temp_sq)) { MessageBox.Show("Test " + files[i]); } File.Delete(temp_sq); } MessageBox.Show("Final"); }
private void Export_XML(string fileOut, SQ translated) { if (File.Exists(fileOut)) { File.Delete(fileOut); } XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); XmlElement root = doc.CreateElement("SubQuest"); XmlElement sBlocks = doc.CreateElement("StartBlocks"); for (int i = 0; i < translated.sblocks.Length; i++) { XmlElement s = doc.CreateElement("String"); string text = translated.sblocks[i].text; text = text.Replace('<', '【'); text = text.Replace('>', '】'); text = text.Replace("\n", "\n "); if (text.Contains("\n")) { text = "\n " + text + "\n "; } s.InnerText = text; sBlocks.AppendChild(s); } root.AppendChild(sBlocks); XmlElement fBlocks = doc.CreateElement("FinalBlocks"); for (int i = 0; i < translated.fblocks.Length; i++) { XmlElement s = doc.CreateElement("String"); string text = translated.fblocks[i].text; text = text.Replace('<', '【'); text = text.Replace('>', '】'); text = text.Replace("\n", "\n "); if (text.Contains("\n")) { text = "\n " + text + "\n "; } s.InnerText = text; fBlocks.AppendChild(s); } root.AppendChild(fBlocks); doc.AppendChild(root); doc.Save(fileOut); }
private void Update_Blocks(ref SQ translated) { for (int i = 0; i < translated.sblocks.Length; i++) { translated.sblocks[i].size = (ushort)enc.GetByteCount(Helper.LatinToSJIS(translated.sblocks[i].text)); } for (int i = 0; i < translated.fblocks.Length; i++) { translated.fblocks[i].size = (ushort)enc.GetByteCount(Helper.LatinToSJIS(translated.fblocks[i].text)); } }
public SQcontrol(IPluginHost pluginHost, string file, int id) { InitializeComponent(); this.fileName = Path.GetFileName(file).Substring(12); this.pluginHost = pluginHost; this.id = id; enc = Encoding.GetEncoding(932); original = Read(file); translated = Read(file); ReadLanguage(); radio_CheckedChanged(null, null); //TEST(); }
public void Import_XML(string fileIn, ref SQ translated) { XDocument doc = XDocument.Load(fileIn); XElement root = doc.Element("SubQuest"); XElement sBlocks = root.Element("StartBlocks"); int i = 0; foreach (XElement e in sBlocks.Elements("String")) { string text = e.Value; if (text.Contains("\n")) { text = text.Remove(0, 7); text = text.Remove(text.Length - 5); text = text.Replace("\n ", "\n"); } text = text.Replace('【', '<'); text = text.Replace('】', '>'); translated.sblocks[i++].text = text; } XElement fBlocks = root.Element("FinalBlocks"); i = 0; foreach (XElement e in fBlocks.Elements("String")) { string text = e.Value; if (text.Contains("\n")) { text = text.Remove(0, 7); text = text.Remove(text.Length - 5); text = text.Replace("\n ", "\n"); } text = text.Replace('【', '<'); text = text.Replace('】', '>'); translated.fblocks[i++].text = text; } sBlocks = null; fBlocks = null; root = null; doc = null; }
public SQ Read(string file) { BinaryReader br = new BinaryReader(File.OpenRead(file)); SQ original = new SQ(); original.sblocks = new SQ.Block[4]; original.id = br.ReadUInt32(); // File ID // Read the first 4 blocks for (int i = 0; i < 4; i++) { original.sblocks[i].size = br.ReadUInt16(); original.sblocks[i].text = new String(enc.GetChars(br.ReadBytes((int)original.sblocks[i].size))); original.sblocks[i].text = Helper.SJISToLatin(original.sblocks[i].text); } original.unknown = br.ReadBytes(0xD); // Unknown data original.num_fblocks = br.ReadByte(); original.fblocks = new SQ.Block[original.num_fblocks]; for (int i = 0; i < original.num_fblocks; i++) { original.fblocks[i].size = br.ReadUInt16(); original.fblocks[i].text = new String(enc.GetChars(br.ReadBytes((int)original.fblocks[i].size))); original.fblocks[i].text = Helper.SJISToLatin(original.fblocks[i].text); } original.num_final = br.ReadByte(); original.final = new byte[original.num_final][]; for (int i = 0; i < original.num_final; i++) { byte size = br.ReadByte(); original.final[i] = br.ReadBytes(size + 4); } br.Close(); return(original); }
void Compile_Events(string path) { string fout; string fin; string mainQuest = path + "MainQuest.xml"; if (File.Exists(mainQuest)) { fout = pluginHost.Get_TempFile(); fin = pluginHost.Search_File(0xF76); MQuestText mqc = new MQuestText(pluginHost, fin, 0xF76); mqc.Import(mainQuest); mqc.Write(fout); pluginHost.ChangeFile(0xF76, fout); } if (Directory.Exists(path + "SubQuest")) { string[] sub = Directory.GetFiles(path + "SubQuest", "*.xml", SearchOption.TopDirectoryOnly); sFolder subf = pluginHost.Search_Folder(0xF07E); for (int i = 0; i < subf.files.Count; i++) { string cfile = Array.Find(sub, a => Path.GetFileNameWithoutExtension(a) == subf.files[i].name); if (cfile == null) { continue; } string tempsub = Save_File(subf.files[i]); fout = pluginHost.Get_TempFile(); SQcontrol sqc = new SQcontrol(pluginHost, tempsub, subf.files[i].id); SQ sq = sqc.Read(tempsub); sqc.Import_XML(cfile, ref sq); sqc.Write(fout, sq); pluginHost.ChangeFile(subf.files[i].id, fout); } } string scenario = path + "Scenario.xml"; if (File.Exists(scenario)) { fout = pluginHost.Get_TempFile(); fin = pluginHost.Search_File(0xFF2); ScenarioText st = new ScenarioText(pluginHost, fin, 0xFF2); st.Import(scenario); st.Write(fout); pluginHost.ChangeFile(0xFF2, fout); } string system = path + "System.xml"; if (File.Exists(system)) { fout = pluginHost.Get_TempFile(); fin = pluginHost.Search_File(0xFF4); SystemText st = new SystemText(fin, 0xFF4, pluginHost); st.Import(system); st.Write(fout); pluginHost.ChangeFile(0xFF4, fout); } }
private void Update_Blocks(ref SQ translated) { for (int i = 0; i < translated.sblocks.Length; i++) translated.sblocks[i].size = (ushort)enc.GetByteCount(Helper.LatinToSJIS(translated.sblocks[i].text)); for (int i = 0; i < translated.fblocks.Length; i++) translated.fblocks[i].size = (ushort)enc.GetByteCount(Helper.LatinToSJIS(translated.fblocks[i].text)); }
private void Export_XML(string fileOut, SQ translated) { if (File.Exists(fileOut)) File.Delete(fileOut); XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); XmlElement root = doc.CreateElement("SubQuest"); XmlElement sBlocks = doc.CreateElement("StartBlocks"); for (int i = 0; i < translated.sblocks.Length; i++) { XmlElement s = doc.CreateElement("String"); string text = translated.sblocks[i].text; text = text.Replace('<', '【'); text = text.Replace('>', '】'); text = text.Replace("\n", "\n "); if (text.Contains("\n")) text = "\n " + text + "\n "; s.InnerText = text; sBlocks.AppendChild(s); } root.AppendChild(sBlocks); XmlElement fBlocks = doc.CreateElement("FinalBlocks"); for (int i = 0; i < translated.fblocks.Length; i++) { XmlElement s = doc.CreateElement("String"); string text = translated.fblocks[i].text; text = text.Replace('<', '【'); text = text.Replace('>', '】'); text = text.Replace("\n", "\n "); if (text.Contains("\n")) text = "\n " + text + "\n "; s.InnerText = text; fBlocks.AppendChild(s); } root.AppendChild(fBlocks); doc.AppendChild(root); doc.Save(fileOut); }
public SQ Read(string file) { BinaryReader br = new BinaryReader(File.OpenRead(file)); SQ original = new SQ(); original.sblocks = new SQ.Block[4]; original.id = br.ReadUInt32(); // File ID // Read the first 4 blocks for (int i = 0; i < 4; i++) { original.sblocks[i].size = br.ReadUInt16(); original.sblocks[i].text = new String(enc.GetChars(br.ReadBytes((int)original.sblocks[i].size))); original.sblocks[i].text = Helper.SJISToLatin(original.sblocks[i].text); } original.unknown = br.ReadBytes(0xD); // Unknown data original.num_fblocks = br.ReadByte(); original.fblocks = new SQ.Block[original.num_fblocks]; for (int i = 0; i < original.num_fblocks; i++) { original.fblocks[i].size = br.ReadUInt16(); original.fblocks[i].text = new String(enc.GetChars(br.ReadBytes((int)original.fblocks[i].size))); original.fblocks[i].text = Helper.SJISToLatin(original.fblocks[i].text); } original.num_final = br.ReadByte(); original.final = new byte[original.num_final][]; for (int i = 0; i < original.num_final; i++) { byte size = br.ReadByte(); original.final[i] = br.ReadBytes(size + 4); } br.Close(); return original; }