public Form1() { isOpened = false; openedFile = ""; pkgLocation = ""; selectedDialogue = 0; selectedUi = 0; selectedImage = null; lvwColumnSorter = new ListViewColumnSorter(); InitializeComponent(); this.listView1.ListViewItemSorter = lvwColumnSorter; this.listView3.ListViewItemSorter = lvwColumnSorter; }
public CResourceManager(string filename) { FileStream fs = new FileStream(filename, FileMode.Open); BinaryReader reader = new BinaryReader(fs); UInt32 magic = reader.ReadUInt32(); UInt32 textOffset = reader.ReadUInt32(); UInt32 textCount = reader.ReadUInt32(); UInt32 charactersOffset = reader.ReadUInt32(); UInt32 charactersCount = reader.ReadUInt32(); UInt32 uiOffset = reader.ReadUInt32(); UInt32 uiCount = reader.ReadUInt32(); UInt32 imageOffset = reader.ReadUInt32(); UInt32 imageCount = reader.ReadUInt32(); if (magic != 0x8D120AB6) { return; } fs.Seek(textOffset, SeekOrigin.Begin); for (uint i = 0; i < textCount; i++) { UInt32 id; UInt32 sourceLen; UInt32 translatedLen; id = reader.ReadUInt32(); sourceLen = reader.ReadUInt32(); translatedLen = reader.ReadUInt32(); if (sourceLen <= 1) { continue; } PackageText pkg = new PackageText(); pkg.source = reader.ReadBytes((int)sourceLen); pkg.sourceLen = sourceLen; pkg.sourceString = Encoding.GetEncoding("SHIFT-JIS").GetString(pkg.source); pkg.sourceString = Humanize(pkg.sourceString); if (translatedLen > 1) { pkg.translation = Encoding.GetEncoding("SHIFT-JIS").GetString(reader.ReadBytes((int)translatedLen - 1)); pkg.translation = Humanize(pkg.translation); reader.ReadByte(); } else { pkg.translation = ""; } dialogue.Add(id, pkg); } fs.Seek(uiOffset, SeekOrigin.Begin); for (uint i = 0; i < uiCount; i++) { UInt32 id; UInt32 sourceLen; UInt32 translatedLen; id = reader.ReadUInt32(); sourceLen = reader.ReadUInt32(); translatedLen = reader.ReadUInt32(); if (sourceLen <= 1) { continue; } PackageText pkg = new PackageText(); pkg.source = reader.ReadBytes((int)sourceLen); pkg.sourceLen = sourceLen; pkg.sourceString = Encoding.GetEncoding("SHIFT-JIS").GetString(pkg.source); if (translatedLen > 1) { pkg.translation = Encoding.GetEncoding("SHIFT-JIS").GetString(reader.ReadBytes((int)translatedLen - 1)); reader.ReadByte(); } else { pkg.translation = ""; } ui.Add(id, pkg); } fs.Seek(imageOffset, SeekOrigin.Begin); for (uint i = 0; i < imageCount; i++) { PackageImage img = new PackageImage(); UInt32 titleLen; img.hash = Encoding.GetEncoding("ASCII").GetString(reader.ReadBytes(40)); titleLen = reader.ReadUInt32(); img.title = Encoding.GetEncoding("ASCII").GetString(reader.ReadBytes((int)titleLen - 1)); reader.ReadByte(); img.width = reader.ReadInt16(); img.height = reader.ReadInt16(); img.flags = reader.ReadInt32(); img.depth = reader.ReadInt32(); img.replacementLen = reader.ReadUInt32(); if (img.replacementLen > 0) { img.replacement = reader.ReadBytes((int)img.replacementLen); } images.Add(img.hash, img); } fs.Close(); }
private void openClick(object sender, EventArgs e) { DialogResult res = openFileDialog1.ShowDialog(); if (res == DialogResult.OK) { if (isOpened) { selectedDialogue = 0; selectedUi = 0; selectedImage = null; resman.dialogue.Clear(); resman.ui.Clear(); resman.images.Clear(); listView1.Items.Clear(); listView3.Items.Clear(); textBox1.Clear(); textBox2.Clear(); textBox5.Clear(); textBox6.Clear(); textBoxTitle.Clear(); comboBox1.Items.Clear(); textBox1.ReadOnly = true; textBox2.ReadOnly = true; textBox5.ReadOnly = true; textBox6.ReadOnly = true; textBoxTitle.ReadOnly = true; comboBox1.Enabled = false; button1.Enabled = false; button2.Enabled = false; if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); } if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } pictureBox1.Image = null; pictureBox2.Image = null; } statusLabel.Text = "Loading package ..."; resman = new CResourceManager(openFileDialog1.FileName); listView1.BeginUpdate(); listView1.ListViewItemSorter = null; // THIS THING MADE EVERYTHING SO F*****G SLOW foreach (KeyValuePair <UInt32, PackageText> kv in resman.dialogue) { ListViewItem item = new ListViewItem(kv.Key.ToString()); item.SubItems.Add(kv.Value.sourceString); item.SubItems.Add(kv.Value.translation); item.SubItems.Add(kv.Value.translation.Length >= 1 ? "Yes" : "No"); item.Tag = kv.Key; listView1.Items.Add(item); } listView1.EndUpdate(); listView1.ListViewItemSorter = lvwColumnSorter; listView3.BeginUpdate(); listView3.ListViewItemSorter = null; // THIS THING MADE EVERYTHING SO F*****G SLOW foreach (KeyValuePair <UInt32, PackageText> kv in resman.ui) { ListViewItem item = new ListViewItem(kv.Key.ToString()); item.SubItems.Add(kv.Value.sourceString); item.SubItems.Add(kv.Value.translation); item.SubItems.Add(kv.Value.translation.Length >= 1 ? "Yes" : "No"); item.Tag = kv.Key; listView3.Items.Add(item); } listView3.EndUpdate(); listView3.ListViewItemSorter = lvwColumnSorter; comboBox1.BeginUpdate(); foreach (KeyValuePair <string, PackageImage> kv in resman.images) { comboBox1.Items.Add(kv.Value); } comboBox1.EndUpdate(); statusLabel.Text = "Loading done"; isOpened = true; comboBox1.Enabled = true; openedFile = openFileDialog1.FileName; pkgLocation = Path.GetDirectoryName(openedFile); } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex == -1) { textBoxTitle.Clear(); textBoxTitle.ReadOnly = true; comboBox1.Enabled = false; button1.Enabled = false; button2.Enabled = false; checkBoxReplaced.Checked = false; selectedImage = null; return; } selectedImage = (PackageImage)comboBox1.SelectedItem; button1.Enabled = true; textBoxTitle.Text = selectedImage.title; textBoxTitle.ReadOnly = false; labelHash.Text = selectedImage.hash; labelSize.Text = selectedImage.width + " x " + selectedImage.height; if (File.Exists(Path.Combine(pkgLocation, Path.Combine("Dump", selectedImage.hash + ".png")))) { pictureBox1.Image = Image.FromFile(Path.Combine(pkgLocation, Path.Combine("Dump", selectedImage.hash + ".png"))); } else { if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } pictureBox1.Image = null; } if (selectedImage.replacementLen > 0) { checkBoxReplaced.Checked = true; button2.Enabled = true; if ((selectedImage.flags & 0xFF) == 2 || (selectedImage.flags & 0xFF) == 3) { Bitmap bm = new Bitmap(selectedImage.width, selectedImage.height); CBitReader cr = new CBitReader(selectedImage.replacement); switch (selectedImage.flags & 0xFF) { case 2: CR6Ti.DecodeOpaque1(cr, bm, selectedImage.width, selectedImage.height, selectedImage.depth); break; case 3: CR6Ti.DecodeTransparent(cr, bm, selectedImage.width, selectedImage.height, selectedImage.depth); break; } pictureBox2.Image = bm; } else { if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); } pictureBox2.Image = null; } } else { checkBoxReplaced.Checked = false; if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); } pictureBox2.Image = null; } switch (selectedImage.flags & 0xFF) { case 2: if ((selectedImage.depth & 0x4) != 0) { labelType.Text = "Opaque1"; } else { labelType.Text = "Opaque2"; } break; case 3: labelType.Text = "Transparent"; break; default: labelType.Text = "Unknown"; break; } }