public virtual Unity_MapTileMap GetTileSet(Context context, SNES_Proto_ROM rom) { // Read the tiles const int block_size = 0x20; uint length = (uint)rom.TileDescriptors.Length * 8 * 8; // Get the tile-set texture var tex = TextureHelpers.CreateTexture2D(256, Mathf.CeilToInt(length / 256f / Settings.CellSize) * Settings.CellSize); for (int i = 0; i < rom.TileDescriptors.Length; i++) { var descriptor = rom.TileDescriptors[i]; var x = ((i / 4) * 2) % (256 / 8) + ((i % 2) == 0 ? 0 : 1); var y = (((i / 4) * 2) / (256 / 8)) * 2 + ((i % 4) < 2 ? 0 : 1); var curOff = block_size * descriptor.TileIndex; FillTextureBlock(tex, 0, 0, x, y, rom.TileMap, curOff, rom.Palettes, descriptor.Palette, descriptor.FlipX, descriptor.FlipY); } tex.Apply(); return new Unity_MapTileMap(tex, Settings.CellSize); }
public Unity_ObjectManager_SNES.GraphicsGroup[] GetGraphicsGroups(SNES_Proto_ROM rom) { return(new Unity_ObjectManager_SNES.GraphicsGroup[] { // Rayman GetGraphicsGroup(rom, rom.Rayman.States, rom.Rayman.ImageDescriptors, false, "Rayman"), // Custom GetGraphicsGroup(rom, SNES_Proto_CustomGraphicsGroups.Enemy_Animations.Select(x => new SNES_Proto_State() { Animation = x, Flags = SNES_Proto_State.StateFlags.UseCurrentFlip, AnimSpeed = 8 }).ToArray(), SNES_Proto_CustomGraphicsGroups.Enemy_ImageDescriptors, true, "Unused Enemy (recreated)"), GetGraphicsGroup(rom, SNES_Proto_CustomGraphicsGroups.Orb_Animations.Select(x => new SNES_Proto_State() { Animation = x, Flags = SNES_Proto_State.StateFlags.UseCurrentFlip, AnimSpeed = 5 }).ToArray(), SNES_Proto_CustomGraphicsGroups.Orb_ImageDescriptors, true, "Unused Orb (recreated)"), GetGraphicsGroup(rom, SNES_Proto_CustomGraphicsGroups.Fist_Animations.Select(x => new SNES_Proto_State() { Animation = x, Flags = SNES_Proto_State.StateFlags.UseCurrentFlip, AnimSpeed = 8 }).ToArray(), SNES_Proto_CustomGraphicsGroups.Fist_ImageDescriptors, true, "Unused Fist (recreated)"), GetGraphicsGroup(rom, SNES_Proto_CustomGraphicsGroups.Effect_Animations.Select(x => new SNES_Proto_State() { Animation = x, Flags = SNES_Proto_State.StateFlags.UseCurrentFlip, AnimSpeed = 8 }).ToArray(), SNES_Proto_CustomGraphicsGroups.Effect_ImageDescriptors, true, "Unused Effects (recreated)"), }); }
public Sprite[] GetSprites(SNES_Proto_ROM rom, SNES_Proto_ImageDescriptor[] imageDescriptors) { var sprites = new Sprite[imageDescriptors.Length * 3]; var pal = Util.ConvertAndSplitGBAPalette(rom.SpritePalette); var buffer = new byte[rom.SpriteTileSet.Length]; for (int addBlock = 0; addBlock < 3; addBlock++) { Array.Copy(rom.SpriteTileSet, buffer, buffer.Length); switch (addBlock) { case 0: Array.Copy(rom.SpriteTileSetAdd0, 0, buffer, 0xC00, 0x400); Array.Copy(rom.SpriteTileSetAdd0, 0x400, buffer, 0x1000, 0x100); Array.Copy(rom.SpriteTileSetAdd0, 0x500, buffer, 0x1200, 0x100); break; case 1: Array.Copy(rom.SpriteTileSetAdd1, 0, buffer, 0xC00, 0x400); Array.Copy(rom.SpriteTileSetAdd1, 0x400, buffer, 0x1000, 0x100); Array.Copy(rom.SpriteTileSetAdd1, 0x500, buffer, 0x1200, 0x100); break; case 2: Array.Copy(rom.SpriteTileSetAdd2, 0, buffer, 0xC00, 0x400); break; } var tileSets = pal.Select(x => Util.ToTileSetTexture(buffer, x, Util.TileEncoding.Planar_4bpp, 8, true, wrap: 16, flipTileX: true)).ToArray(); for (int i = 0; i < imageDescriptors.Length; i++) { if (i == 0) { sprites[i] = null; continue; } var imgDescriptor = imageDescriptors[i]; var xPos = imgDescriptor.TileIndex % 16; var yPos = (imgDescriptor.TileIndex - xPos) / 16; var size = imgDescriptor.IsLarge ? 16 : 8; var spriteTex = TextureHelpers.CreateTexture2D(size, size); var flipX = imgDescriptor.FlipX; var flipY = !imgDescriptor.FlipY; var texX = xPos * 8; var texY = tileSets[imgDescriptor.Palette].height - yPos * 8 - size; var width = size; var height = size; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { spriteTex.SetPixel(flipX ? width - x - 1 : x, (!flipY) ? height - y - 1 : y, tileSets[imgDescriptor.Palette].GetPixel(texX + x, texY + y)); } } spriteTex.Apply(); sprites[addBlock * imageDescriptors.Length + i] = spriteTex.CreateSprite(); } } return(sprites); }
public Unity_ObjectManager_SNES.GraphicsGroup GetGraphicsGroup(SNES_Proto_ROM rom, SNES_Proto_State[] states, SNES_Proto_ImageDescriptor[] imgDescriptors, bool isRecreated, string name) { var objStates = states.Select(x => new Unity_ObjectManager_SNES.GraphicsGroup.State(x, x.Animation.ToCommonAnimation(x.VRAMConfigIndex * imgDescriptors.Length))).ToArray(); return(new Unity_ObjectManager_SNES.GraphicsGroup(objStates, imgDescriptors, GetSprites(rom, imgDescriptors), isRecreated, name)); }