// This handler deals with background graphics and palettes as well, // even though those are technically separate "objects" public override void ReadClass(Rom rom) { // The only way to determine the bit depth of each BG palette is // to check the bit depth of the backgrounds that use it - so, // first we create an array to track palette bit depths: int[] palbits = new int[114]; int[] gfxbits = new int[103]; for (int i = 0; i < 327; i++) { BattleBG bg = new BattleBG(); rom.Add(bg); bg.Read(i); // Now that the BG has been read, update the BPP entry for its palette // We can also check to make sure palettes are used consistently: int pal = bg.PaletteIndex; if (palbits[pal] != 0 && palbits[pal] != bg.BitsPerPixel) { throw new Exception("Battle BG Palette Error - inconsistent bit depth"); } palbits[pal] = bg.BitsPerPixel; gfxbits[bg.GraphicsIndex] = bg.BitsPerPixel; } // Now load palettes for (int i = 0; i < 114; i++) { BackgroundPalette p = new BackgroundPalette(); rom.Add(p); p.BitsPerPixel = palbits[i]; p.Read(i); } // Load graphics for (int i = 0; i < 103; i++) { BackgroundGraphics g = new BackgroundGraphics(); rom.Add(g); g.BitsPerPixel = gfxbits[i]; g.Read(i); } }
public override void Read(int index) { // Graphics pointer table entry Block gfxPtrBlock = Parent.ReadBlock(0xAD9A1 + index * 4); //int gfxPtr = Rom.SnesToHex(gfxPtrBlock.ReadInt()); // Read graphics LoadGraphics(Parent.ReadBlock(Rom.SnesToHex(gfxPtrBlock.ReadInt()))); // Arrangement pointer table entry Block arrPtrBlock = Parent.ReadBlock(0xADB3D + index * 4); int arrPtr = Rom.SnesToHex(arrPtrBlock.ReadInt()); // Read and decompress arrangement Block arrBlock = Parent.ReadBlock(arrPtr); arr = arrBlock.Decomp(); }
/// <summary> /// Decompresses data from the block's current position. Note that /// this method first measures the compressed data's size before allocating /// the destination array, which incurs a slight additional overhead. /// </summary> /// <returns>An array containing the decompressed data.</returns> public byte[] Decomp() { int size = Rom.GetCompressedSize(pointer, data); if (size < 1) { throw new Exception("Invalid compressed data."); } byte[] output = new byte[size]; int read; int actualSize = Rom.Decomp(pointer, data, output, out read); if (size != actualSize) { throw new Exception("ERROR! Computed and actual decompressed sizes do not math. Please reinstall universe and reboot."); } return(output); }
public override void WriteClass(Rom rom) { }
public abstract void WriteClass(Rom rom);
public static void WriteClass(Rom rom) { throw new Exception("RomObject classes must implement a new static WriteClass method!"); }
public abstract void ReadClass(Rom rom);
/* * Methods */ public static void ReadClassFromRom(Rom rom) { throw new Exception("RomObject classes must implement a new static ReadClass method!"); }