public System.Windows.Forms.Control Show_Info(sFile file) { if ((file.id >= 0x12C && file.id <= 0x165) || (file.id >= 0x65D && file.id <= 0x68A) || file.id == 0x16B || file.id == 0x16C) { return(new TextControl(pluginHost, file.path)); } if ((file.id >= 0x1E4 && file.id <= 0x1F4) || (file.id >= 0x1F7 && file.id <= 0x2FC)) { string[] p = new String[] { file.path, "Sounds.Main", file.name + ".adx", "" }; return((System.Windows.Forms.Control)pluginHost.Call_Plugin(p, file.id, 1)); } if (file.id >= 0x01 && file.id <= 0x1E3) { if (file.size == 512 || file.size == 128 || file.size == 32) { RawPalette palette = new RawPalette(file.path, file.id, false, 0, -1, file.name); pluginHost.Set_Palette(palette); return(new PaletteControl(pluginHost)); } else { return(new Images(pluginHost, file.path, file.id).Get_Control()); } } return(new System.Windows.Forms.Control()); }
void Read(string fileIn) { BinaryReader br = new BinaryReader(File.OpenRead(fileIn)); char[] type = br.ReadChars(4); if (new String(type) != "TMAP") { br.Close(); br = null; throw new FormatException("Invalid header!"); } uint imgs_layer = br.ReadUInt32(); // Number of images per layer tile_width = br.ReadUInt32(); // Number of horizontal images tile_height = br.ReadUInt32(); // Number of vertical images // Layer 1: background // Layer 2: layer 1 (it's printed after print the NPC and player, it's over the player) // Layer 3: layer 2 // Layer 4: Collision tiles = new Bitmap[4][]; for (int l = 0; l < 4; l++) { // For each layer get al the files tiles[l] = new Bitmap[imgs_layer]; for (int i = 0; i < imgs_layer; i++) { // Read FAT br.BaseStream.Position = 0x10 + l * imgs_layer * 8 + i * 8; uint offset = br.ReadUInt32(); uint size = br.ReadUInt32(); if (offset == 0x00 || size == 0x00) { continue; } // Read file br.BaseStream.Position = offset; byte[] data = br.ReadBytes((int)size); string tempFile = null; if (data[0] == 0x11 || data[0] == 0x30) // Decompress it, LZ11 for BTX0 and RLE for BMP { pluginHost.Decompress(data); sFolder f = pluginHost.Get_Files(); if (!(f.files is List <sFile>) || f.files.Count != 1) // Check if the decompression fails { Console.WriteLine("Problem decompressing file -> l: {0}, i: {1}", l.ToString(), i.ToString()); continue; } tempFile = f.files[0].path; // Check if the decomprsesion fails data = File.ReadAllBytes(tempFile); if (data[0] == 0x11 || data[0] == 0x30) { continue; } } else { tempFile = pluginHost.Get_TempFile(); File.WriteAllBytes(tempFile, data); } // Get image string header = new string(Encoding.ASCII.GetChars(data, 0, 4)); if (header == "BTX0") { // Call to the 3D plugin to get a bitmap from the texture string[] param = { tempFile, "_3DModels.Main", "", "BTX0" }; pluginHost.Call_Plugin(param, -1, 0); if (pluginHost.Get_Object() is Bitmap[]) { tiles[l][i] = ((Bitmap[])pluginHost.Get_Object())[0]; pluginHost.Set_Object(null); } else { Console.WriteLine("Problem getting bitmap image -> l: {0}, i: {1}", l.ToString(), i.ToString()); } } else if (header.StartsWith("BM")) // BMP file { try { tiles[l][i] = (Bitmap)Image.FromFile(tempFile); } catch { } } else { Console.WriteLine("Unknown file -> l: {0}, i: {1}", l.ToString(), i.ToString()); } } } br.Close(); br = null; }