private void UpdateInformationLabels() { if (selection + 2 >= rom.Length) { return; } info_offset.Text = "Offset: " + selection.ToString("X6"); if (ROMData.SelectionLength / 3 == 3) { info_value.Text = "Value: " + Bits.GetInt24(rom, selection).ToString(); } else if (ROMData.SelectionLength / 3 == 2) { info_value.Text = "Value: " + Bits.GetShort(rom, selection).ToString(); } else if (ROMData.SelectionLength / 3 <= 1) { info_value.Text = "Value: " + rom[selection].ToString(); } else { info_value.Text = "Value: "; } int sel = ROMData.SelectionLength / 3; info_sel.Text = "Sel: 0x" + sel.ToString("X") + " (" + sel.ToString() + ") bytes"; }
// assemblers private void Disassemble() { animationOffset = Bits.GetInt24(rom, 0x252000 + (index * 3)) - 0xC00000; int animationLength = Bits.GetShort(rom, animationOffset); buffer = Bits.GetBytes(rom, animationOffset, animationLength); // int offset = 2; ushort sequencePacketPointer = Bits.GetShort(buffer, offset); offset += 2; ushort moldPacketPointer = Bits.GetShort(buffer, offset); offset += 2; byte sequenceCount = buffer[offset++]; byte moldCount = buffer[offset++]; vramAllocation = (ushort)(buffer[offset] << 8); offset += 2; unknown = Bits.GetShort(buffer, offset); // offset = sequencePacketPointer; for (int i = 0; i < sequenceCount; i++) { Sequence tSequence = new Sequence(); tSequence.Disassemble(buffer, offset); sequences.Add(tSequence); offset += 2; } offset = moldPacketPointer; for (int i = 0; i < moldCount; i++) { Mold tMold = new Mold(); tMold.Disassemble(buffer, offset, uniqueTiles, index, animationOffset); molds.Add(tMold); offset += 2; } }
// assemblers private void Disassemble() { animationOffset = Bits.GetInt24(rom, 0x252C00 + (index * 3)) - 0xC00000; ushort animationLength = Bits.GetShort(rom, animationOffset); buffer = Bits.GetBytes(rom, animationOffset, Bits.GetShort(rom, animationOffset)); // int offset = 2; ushort graphicSetPointer = Bits.GetShort(buffer, offset); offset += 2; ushort paletteSetPointer = Bits.GetShort(buffer, offset); offset += 2; ushort sequencePacketPointer = Bits.GetShort(buffer, offset); offset += 2; ushort moldPacketPointer = Bits.GetShort(buffer, offset); offset += 2; // skip 2 unknown bytes offset += 2; // width = buffer[offset++]; height = buffer[offset++]; codec = Bits.GetShort(buffer, offset); offset += 2; // int tileSetPointer = Bits.GetShort(buffer, offset); graphicSetLength = paletteSetPointer - graphicSetPointer; graphicSet = new byte[0x2000]; Buffer.BlockCopy(buffer, graphicSetPointer, graphicSet, 0, graphicSetLength); paletteSetLength = (ushort)(tileSetPointer - paletteSetPointer); paletteSet = new PaletteSet(buffer, 0, paletteSetPointer, 8, 16, 32); tilesetLength = sequencePacketPointer - tileSetPointer - 2; tileset_bytes = new byte[64 * 4 * 2 * 4]; Buffer.BlockCopy(buffer, tileSetPointer, tileset_bytes, 0, tilesetLength); // offset = sequencePacketPointer; for (int i = 0; Bits.GetShort(buffer, offset) != 0x0000; i++) { E_Sequence tSequence = new E_Sequence(); tSequence.Disassemble(buffer, offset); sequences.Add(tSequence); offset += 2; } offset = moldPacketPointer; ushort end = 0; for (int i = 0; Bits.GetShort(buffer, offset) != 0x0000; i++) { if (Bits.GetShort(buffer, offset + 2) == 0x0000) { end = animationLength; } else { end = Bits.GetShort(buffer, offset + 2); } E_Mold tMold = new E_Mold(); tMold.Disassemble(buffer, offset, end); molds.Add(tMold); offset += 2; } }
// assemblers private void Disassemble() { int offset = Bits.GetInt24(rom, index * 3 + 0x042333); if (offset == 0) { return; } offset -= 0xC00000; int size = Bits.GetShort(rom, offset); offset += 2; sample = Bits.GetBytes(rom, offset, size); loopStart = Bits.GetShort(rom, index * 2 + 0x04248F); relGain = (short)Bits.GetShort(rom, index * 2 + 0x042577); relFreq = (short)Bits.GetShort(rom, index * 2 + 0x04265F); }
// assemblers private void Disassemble() { int offset = Bits.GetInt24(rom, index * 3 + 0x042748) - 0xC00000; delayTime = rom[offset++]; decayFactor = rom[offset++]; echo = rom[offset++]; samples = new SampleIndex[20]; int i = 0; while (rom[offset] != 0xFF && i < 20) { samples[i++] = new SampleIndex(rom[offset++], rom[offset++]); } offset++; Length = Bits.GetShort(rom, offset); offset += 2; spcData = Bits.GetBytes(rom, offset, Length); // CreateCommands(); }
// accessor functions /// <summary> /// Creates a pixel array of the sprite. /// </summary> /// <param name="byMold">Create the pixels by mold index.</param> /// <param name="byFCoord">Create the pixels by facing index.</param> /// <param name="moldIndex">The index of the mold (ignored if byMold == false).</param> /// <param name="fCoord">The index of the facing (ignored if byFacing == false)</param> /// <param name="palette">If want to use a particular palette.</param> /// <param name="mirror">Mirror the sprite pixels.</param> /// <param name="crop">Crop the sprite pixels to their edges.</param> /// <returns></returns> public int[] GetPixels(bool byMold, bool byFCoord, int moldIndex, int fCoord, int[] palette, bool mirror, bool crop, ref Size size) { // set palette to use if (palette == null) { palette = Palette; } // get offsets int animationNum = Bits.GetShort(rom, this.index * 4 + 0x250002); int animationOffset = Bits.GetInt24(rom, 0x252000 + (animationNum * 3)) - 0xC00000; int animationLength = Bits.GetShort(rom, animationOffset); // get mold data byte[] sm = Bits.GetBytes(rom, animationOffset, animationLength); int offset = Bits.GetShort(sm, 2); if (byFCoord) { switch (fCoord) { case 0: mirror = !mirror; if (sm[6] < 13) { break; } offset += 24; break; case 1: mirror = !mirror; break; case 2: if (sm[6] < 11) { break; } offset += 20; break; case 4: if (sm[6] < 13) { break; } offset += 24; break; case 5: if (sm[6] < 2) { break; } offset += 2; break; case 6: if (sm[6] < 12) { break; } offset += 22; break; case 7: mirror = !mirror; if (sm[6] < 2) { break; } offset += 2; break; default: break; } } offset = Bits.GetShort(sm, offset); if (!byMold) { moldIndex = offset != 0xFFFF && sm[offset + 1] != 0 && sm[offset + 1] < sm[7] ? (int)sm[offset + 1] : 0; } offset = Bits.GetShort(sm, 4); offset += moldIndex * 2; // create mold from data Mold mold = new Mold(); mold.Disassemble(sm, offset, new List <Mold.Tile>(), animationNum, animationOffset); // generate subtiles in mold, then grab pixel array foreach (Mold.Tile t in mold.Tiles) { t.DrawSubtiles(Graphics, palette, mold.Gridplane); } int[] pixels = mold.MoldPixels(); // crop image int lowY = 0, highY = 0, lowX = 0, highX = 0; if (crop) { bool stop = false; for (int y = 0; y < 256 && !stop; y++) { for (int x = 0; x < 256; x++) { if (pixels[y * 256 + x] != 0) { lowY = y; lowX = x; stop = true; break; } } } stop = false; for (int y = 255; y >= 0 && !stop; y--) { for (int x = 255; x >= 0; x--) { if (pixels[y * 256 + x] != 0) { highY = y; highX = x; stop = true; break; } } } stop = false; for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { if (pixels[y * 256 + x] != 0 && x < lowX) { lowX = x; break; } } } stop = false; for (int y = 255; y >= 0; y--) { for (int x = 255; x >= 0; x--) { if (pixels[y * 256 + x] != 0 && x > highX) { highX = x; break; } } } stop = false; highY++; highX++; } else { highY = 256; highX = 256; } int imageHeight = highY - lowY; int imageWidth = highX - lowX; if (crop) { int[] tempPixels = new int[imageWidth * imageHeight]; for (int y = 0; y < imageHeight; y++) { for (int x = 0; x < imageWidth; x++) { tempPixels[y * imageWidth + x] = pixels[(y + lowY) * 256 + x + lowX]; } } pixels = tempPixels; } int temp; if (mirror) { for (int y = 0; y < imageHeight; y++) { for (int a = 0, c = imageWidth - 1; a < imageWidth / 2; a++, c--) { temp = pixels[(y * imageWidth) + a]; pixels[(y * imageWidth) + a] = pixels[(y * imageWidth) + c]; pixels[(y * imageWidth) + c] = temp; } } } size = new Size(imageWidth, imageHeight); return(pixels); }