public void ParseTim() { Palettes.Clear(); Bitmaps.Clear(); textureAddresses.Clear(); paletteAddresses.Clear(); int max = timBinary.ReadInt(12, false); int startPalette = +timBinary.ReadInt(timBinary.ReadUInt(0x14, false) + 0x74, false); int[] offs = new int[] { 0x0000, 0x0040, 0x1000, 0x1040, 0x0080, 0x00C0, 0x1080, 0x10C0 }; for (int i = 0; i < max; i++) { byte iI = timBinary.Buffer[timBinary.ReadUInt(0x10, false) + i]; ulong num = timBinary.ReadUInt64(timBinary.ReadUInt(0x18, false) + 0xA0 * i + 0x70, false); int paletteOffset = startPalette + offs[i % 8] + ((i / 8) * 0x2000); System.Drawing.Color[] paletteSwap = GetPalette((paletteOffset)); paletteAddresses.Insert(paletteAddresses.Count, paletteOffset); Palettes.Insert(Palettes.Count, paletteSwap); textureAddresses.Insert(textureAddresses.Count, +timBinary.ReadInt(+timBinary.ReadInt(0x14, false) + 0x104 + 0x90 * iI, false)); int wByte = 2 * timBinary.ReadInt(timBinary.ReadInt(0x14, false) + 0xD0 + 0x90 * iI, false); int hByte = 2 * timBinary.ReadInt(timBinary.ReadInt(0x14, false) + 0xD4 + 0x90 * iI, false); ushort textureWidth = (ushort)(1u << ((int)(num >> 0x1A) & 0x0F)); ushort textureHeight = (ushort)(1u << ((int)(num >> 0x1E) & 0x0F)); //ushort textureWidth = (ushort)(2 * timBinary.ReadUShort(timBinary.ReadUInt(0x14) + 0x40 + 0x90 * (iI + 0))); //ushort textureHeight = (ushort)(2 * timBinary.ReadUShort(timBinary.ReadUInt(0x14) + 0x44 + 0x90 * (iI + 0))); byte palCs = (byte)((uint)(num << 0x41) & 0x1Fu); uint type = (uint)(num >> 20) & 0x3fu; long pixelsPerByte = (textureWidth * textureHeight / (wByte * hByte)); if (pixelsPerByte != 1) { return; } Bitmaps.Add(GetTextureBitmap(textureAddresses[textureAddresses.Count - 1], Palettes[textureAddresses.Count - 1], textureWidth, textureHeight)); } this.Patches = new List <Bitmap>(0); this.PatchIndexes = new List <int>(0); this.PatchTextureIndexes = new List <int>(0); this.PatchCounts = new List <int>(0); this.PatchSizes = new List <Size>(0); this.PatchLocs = new List <Point>(0); dmyCount = 0; int DMYReach = startPalette; DMYReach = 16 * (DMYReach / 16); while (BitConverter.ToInt32(timBinary.Buffer, DMYReach) != 0x594D445F) { DMYReach += 16; if (DMYReach + 16 >= timBinary.Buffer.Length) { GetDisplayTextures(); return; } } DMY = DMYReach; while (DMYReach + 16 < +timBinary.Buffer.Length && BitConverter.ToInt32(timBinary.Buffer, DMYReach) == 0x594D445F) { int next = DMYReach + 16 + timBinary.ReadInt(DMYReach + 12, false); int startPatch = DMYReach + 16 + timBinary.ReadInt(DMYReach + 48, false); ushort maxPatch = timBinary.ReadUShort(DMYReach + 0x1E, false); ushort patchX = timBinary.ReadUShort(DMYReach + 0x20, false); ushort patchY = timBinary.ReadUShort(DMYReach + 0x22, false); ushort patchWidth = timBinary.ReadUShort(DMYReach + 0x24, false); ushort patchHeight = (ushort)(timBinary.ReadUShort(DMYReach + 0x26, false) * maxPatch); if (patchWidth < 1 || patchHeight < 1 || patchWidth > 512 || patchHeight > 512 || startPatch + patchWidth * patchHeight > +timBinary.Buffer.Length) { break; } short paletteIndex = timBinary.ReadShort(DMYReach + 0x12, false); dmyCount++; this.textureAddresses.Insert(textureAddresses.Count, (startPatch)); System.Drawing.Color[][] currPal = Palettes.ToArray(); this.Palettes.Insert(Palettes.Count, currPal[paletteIndex]); this.Bitmaps.Insert(Bitmaps.Count, GetPatchBitmap(textureAddresses[textureAddresses.Count - 1], Palettes[Palettes.Count - 1], patchWidth, patchHeight)); this.Patches.Insert(this.Patches.Count, this.Bitmaps[this.Bitmaps.Count - 1]); this.PatchIndexes.Insert(this.PatchIndexes.Count, -1); this.PatchTextureIndexes.Insert(this.PatchTextureIndexes.Count, paletteIndex); this.PatchSizes.Insert(this.PatchSizes.Count, new Size(patchWidth, timBinary.ReadUShort(DMYReach + 0x26, false))); this.PatchCounts.Insert(this.PatchCounts.Count, maxPatch); this.PatchLocs.Insert(this.PatchLocs.Count, new Point(patchX, patchY)); this.paletteAddresses.Insert(paletteAddresses.Count, paletteAddresses[paletteIndex]); DMYReach = next; } GetDisplayTextures(); }