public void fromFile(TibiaFolder folder) { BinaryReader signa = new BinaryReader(File.OpenRead(folder.getPath() + "\\signature.dat")); this.signature[0] = signa.ReadByte(); this.signature[1] = signa.ReadByte(); this.signature[2] = signa.ReadByte(); this.signature[3] = signa.ReadByte(); }
public void save(TibiaFolder folder, string newFolderName) { FileStream dat = new FileStream(folder.getPath() + "\\" + newFolderName + "\\signature.dat", FileMode.Create); BinaryWriter writer = new BinaryWriter(dat); writer.Write(signature[0]); writer.Write(signature[1]); writer.Write(signature[2]); writer.Write(signature[3]); writer.Flush(); writer.Close(); }
//Thread responsável pela compilação de sprites para as versões entre 7.0 e 9.54 private void compileTo70() { //Declarando variaveis bool wrongVersion = false, cantReadSignature = false; UInt16 quantidade_de_sprites = 0; Image spr; //lendo assinatura try { setLog("Reading signature..."); assinatura.fromFile(compilar_onde); readSignature = assinatura.get(); } catch { cantReadSignature = true; } try { setLog("Reading sprite number..."); quantidade_de_sprites = Conversor.UInt32_to_UInt16(compilar_onde.getSprites()); } catch { wrongVersion = true; } if (wrongVersion == true) { setLog("Unable to read all the sprites"); setLog("The maximum supported sprites for a compilation between versions 7.0 and 9.54 is 65535 images."); setLog("Operation aborted..."); } else if (cantReadSignature == true) { setLog("Error while trying to read signature."); setLog("Operation aborted..."); } else { //organizando as variaveis para começar a leitura setLog("[0%] 0 sprites from " + quantidade_de_sprites.ToString()); compiling = new BinaryWriter(new FileStream(compilar_para_onde.getPath() + "\\virtual_memory.bin", FileMode.Create)); offset = new UInt32[quantidade_de_sprites]; offset[0] = Conversor.Int32_to_UInt32((quantidade_de_sprites * 4) + 6); compiledSprite = new byte[quantidade_de_sprites + 1]; //lendo as sprites aqui e criando as offsets for (int i = 1; i <= quantidade_de_sprites; i++) { lastLog("[" + percent(i, quantidade_de_sprites).ToString() + "%] " + i.ToString() + " sprites from " + quantidade_de_sprites.ToString()); spr = Image.FromFile(compilar_onde.getPath() + "\\s" + i.ToString() + ".bmp"); compiledSprite = sc70.CompileImg(spr); if (i != quantidade_de_sprites) { offset[i] = Conversor.UInt32_add(offset[i - 1], compiledSprite.Length); } compiling.Write(compiledSprite); } compiling.Flush(); compiling.Close(); compiling = null; //criando o arquivo .spr setLog("Concluding compilation..."); string file_name = compilar_para_onde.generateFileName(); compiled = new BinaryWriter(new FileStream(file_name, FileMode.Create)); compiled.Write(readSignature); compiled.Write(Conversor.UInt16_to_Byte(quantidade_de_sprites)); for (int i = 0; i < quantidade_de_sprites; i++) { compiled.Write(Conversor.UInt32_to_Byte(offset[i])); } get_bin_file_from_virtual_memory = new BinaryReader(File.OpenRead(compilar_para_onde.getPath() + "\\virtual_memory.bin")); get_bin_file_from_virtual_memory.BaseStream.Position = 0; compiled.Write(get_bin_file_from_virtual_memory.ReadBytes(Conversor.Int64_to_Int32(get_bin_file_from_virtual_memory.BaseStream.Length))); //Encerrando get_bin_file_from_virtual_memory.Close(); get_bin_file_from_virtual_memory = null; compiled.Flush(); compiled.Close(); compiled = null; File.Delete(compilar_para_onde.getPath() + "\\virtual_memory.bin"); setLog("File compiled to: " + file_name); setLog("Compilation complete!"); } }
private void Extract_Click(object sender, EventArgs e) { if (getVersion() == 3.0) { #region lendo para a versão 3.0 até 6.5 setLog("Can't work with this version."); #endregion } else { extrair_quem = new TibiaFile("Which file you want to decompile?"); if (extrair_quem.success == true) { extrair_para_onde = new TibiaFolder("Where do you want the folder be created?"); if (extrair_para_onde.success == true) { #region lendo para a versão 7.0 até 9.54 if (getVersion() == 7.0) { setLog("Reading sprite file."); try { sd70 = new SprDecompiler70(extrair_quem); setLog("Exporting..."); setLog("The logs blinking while extracting means that my program is the best..."); sprites_to_export = sd70.getSprites(); assinatura.set(sd70.getSignature()); } catch { try { setLog("Can't read the file..."); selectversion.SelectedIndex = 1; setLog("Trying to decompile under the pattern from version 9.6"); setLog("Reading sprite file."); sd96 = new SprDecompiler96(extrair_quem); setLog("Exporting..."); sprites_to_export = sd96.getSprites(); assinatura.set(sd96.getSignature()); } catch { setLog("Can't read the file... Operation aborted"); } } } #endregion #region lendo para versão 9.6 else if (getVersion() == 9.6) { setLog("Reading sprite file."); //try // { sd96 = new SprDecompiler96(extrair_quem); setLog("Exporting..."); sprites_to_export = sd96.getSprites(); assinatura.set(sd96.getSignature()); /*} * * catch * { * try * { * setLog("Can't read the file..."); * selectversion.SelectedIndex = 0; * setLog("Trying to decompile under the pattern from version 7.2 to 9.54"); * setLog("Reading sprite file."); * sd70 = new SprDecompiler70(extrair_quem); * assinatura.set(sd70.getSignature()); * setLog("Exporting..."); * sprites_to_export = sd70.getSprites(); * } * * catch * { * setLog("Can't read the file... Operation aborted"); * } */ } #endregion #region criando a pasta onde as sprites serão armazenadas e depois iniciando o thread if (sprites_to_export != null) { string nova_pasta = "Sprites"; int k = 2; while (Directory.Exists(extrair_para_onde.getPath() + "\\" + nova_pasta)) { nova_pasta = "Sprites " + k.ToString(); k++; } export_folder_name = extrair_para_onde.getPath() + "\\" + nova_pasta; Directory.CreateDirectory(export_folder_name); assinatura.save(extrair_para_onde, nova_pasta); } this.sprites_exporter = new Thread(new ThreadStart(this.saveSprites)); this.sprites_exporter.Start(); #endregion } //seleção da pasta onde as imagens vão ficar } //seleção do arquivo a ser extraido } }