private void DumpEntries() { gvEntries.Rows.Clear(); foreach (TAHEntry entry in decrypter.Entries) { string file_name = entry.file_name.ToLower(); if (entry.flag % 2 == 1) { file_name += TAHFileUtils.GetExtensionFromMagic(decrypter.ExtractResource(entry)); } string ext = Path.GetExtension(file_name); if (ext == ".tbn") { if (file_name.StartsWith("script/backgrounds/")) { string[] row = { entry.file_name, entry.offset.ToString(), entry.length.ToString() }; gvEntries.Rows.Add(row); } } else if (ext == ".psd") { if (file_name.StartsWith("data/icon/backgrounds/")) { string[] row = { entry.file_name, entry.offset.ToString(), entry.length.ToString() }; gvEntries.Rows.Add(row); } } else if (ext == ".tso") { if (file_name.StartsWith("data/bgmodel/")) { string[] row = { entry.file_name, entry.offset.ToString(), entry.length.ToString() }; gvEntries.Rows.Add(row); } } } }
private void bwCompress_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; Encrypter encrypter = new Encrypter(); encrypter.SourcePath = @"."; Dictionary <string, TAHEntry> entries = new Dictionary <string, TAHEntry>(); foreach (TAHEntry entry in decrypter.Entries) { string file_name = entry.file_name; if (entry.flag % 2 == 1) { file_name += TAHFileUtils.GetExtensionFromMagic(decrypter.ExtractResource(entry)); } string ext = Path.GetExtension(file_name).ToLower(); if (ext == ".tmo") { string true_file_name = Path.Combine(encrypter.SourcePath, file_name.Replace("/", @"\")); entries[true_file_name] = entry; encrypter.Add(true_file_name); } else if (ext == ".png") { string true_file_name = Path.Combine(encrypter.SourcePath, file_name.Replace("/", @"\")); entries[true_file_name] = entry; encrypter.Add(true_file_name); } } int entries_count = encrypter.Count; int current_index = 0; encrypter.GetFileEntryStream = delegate(string true_file_name) { Console.WriteLine("compressing {0}", true_file_name); TAHEntry entry = entries[true_file_name]; string ext = Path.GetExtension(true_file_name).ToLower(); Stream ret_stream = null; if (ext == ".tmo") { TMOFile tmo = new TMOFile(); MemoryStream tmo_stream = new MemoryStream(decrypter.ExtractResource(entry)); tmo.Load(tmo_stream); if (tmo.nodes[0].Path == "|W_Hips") { tmo_Transform(tmo); tmo_stream.Seek(0, SeekOrigin.Begin); tmo.Save(tmo_stream); } tmo_stream.Seek(0, SeekOrigin.Begin); ret_stream = tmo_stream; } else if (ext == ".png") { MemoryStream png_stream = new MemoryStream(decrypter.ExtractResource(entry)); ret_stream = new MemoryStream(); Process(png_stream, ret_stream); ret_stream.Seek(0, SeekOrigin.Begin); } current_index++; int percent = current_index * 100 / entries_count; worker.ReportProgress(percent); return(ret_stream); }; encrypter.Save(@"tmo-" + Path.GetFileName(source_file)); }
public void Process() { string[] cols = File.ReadAllLines(GetColsPath()); Encrypter encrypter = new Encrypter(); encrypter.SourcePath = @"."; encrypter.Version = tah_version; Dictionary <string, TAHEntry> tso_entries = new Dictionary <string, TAHEntry>(); Dictionary <string, TAHEntry> psd_entries = new Dictionary <string, TAHEntry>(); foreach (TAHEntry entry in GetTSOHairEntries()) { string path = entry.file_name; string basename = Path.GetFileNameWithoutExtension(path); string code = basename.Substring(0, 8); string row = basename.Substring(9, 1); tso_entries[code] = entry; foreach (string col in cols) { string new_basename = code + "_" + row + col; string tbn_path = encrypter.SourcePath + "/script/items/" + new_basename + ".tbn"; encrypter.Add(tbn_path); string tso_path = encrypter.SourcePath + "/data/model/" + new_basename + ".tso"; encrypter.Add(tso_path); string psd_path = encrypter.SourcePath + "/data/icon/items/" + new_basename + ".psd"; encrypter.Add(psd_path); } } foreach (TAHEntry entry in GetPSDIconEntries()) { string path = entry.file_name; string basename = Path.GetFileNameWithoutExtension(path); string code = basename.Substring(0, 8); string row = basename.Substring(9, 1); psd_entries[code] = entry; } int entries_count = encrypter.Count; int current_index = 0; encrypter.GetFileEntryStream = delegate(string path) { Console.WriteLine("compressing {0}", path); Stream ret_stream = null; string basename = Path.GetFileNameWithoutExtension(path); string code = basename.Substring(0, 8); string row = basename.Substring(9, 1); string col = basename.Substring(10, 2); string ext = Path.GetExtension(path).ToLower(); if (ext == ".tbn") { string src_path = null; foreach (TBNHairPart part in parts) { if (row == part.Row) { src_path = part.TbnPath; break; } } using (FileStream source_stream = File.OpenRead(Path.Combine(KitRoot, src_path))) { ret_stream = new MemoryStream(); ProcessTBNFile(source_stream, ret_stream, basename); } ret_stream.Seek(0, SeekOrigin.Begin); } else if (ext == ".tso") { TAHEntry entry = tso_entries[code]; using (MemoryStream tso_stream = new MemoryStream(decrypter.ExtractResource(entry))) { ret_stream = new MemoryStream(); ProcessTSOFile(tso_stream, ret_stream, col); } ret_stream.Seek(0, SeekOrigin.Begin); } else if (ext == ".psd") { if (col == "00") { TAHEntry entry = psd_entries[code]; ret_stream = new MemoryStream(decrypter.ExtractResource(entry)); } else { string src_path = Path.Combine(KitRoot, string.Format(PsdPath, col)); using (FileStream source_stream = File.OpenRead(src_path)) { ret_stream = new MemoryStream(); Copy(source_stream, ret_stream); } ret_stream.Seek(0, SeekOrigin.Begin); } } current_index++; int percent = current_index * 100 / entries_count; ProgressChanged(percent); return(ret_stream); }; encrypter.Save(@"col-" + colsname + "-" + Path.GetFileName(source_file)); }