public void addPotsItems() { int item_address_snes = (01 << 16) + (ROM.DATA[ConstantsReader.GetAddress("room_items_pointers") + (index * 2) + 1] << 8) + ROM.DATA[ConstantsReader.GetAddress("room_items_pointers") + (index * 2)]; int item_address = Addresses.snestopc(item_address_snes); while (true) { byte b1 = ROM.DATA[item_address]; byte b2 = ROM.DATA[item_address + 1]; byte b3 = ROM.DATA[item_address + 2]; //0x20 = bg2 if (b1 == 0xFF && b2 == 0xFF) { break; } int address = ((b2 & 0x1F) << 8 | b1) >> 1; int px = address % 64; int py = address >> 6; roomPotSave p = new roomPotSave(b3, (ushort)index, (byte)((px)), (byte)((py)), (b2 & 0x20) == 0x20 ? true : false); pot_items.Add(p); //bit 7 is set if the object is a special object holes, switches //after 0x16 it goes to 0x80 item_address += 3; } }
public RoomSave(short roomId) { staircase_rooms = new byte[4]; staircase_plane = new byte[4]; blocks = new List <Room_Blocks>(); torches = new List <Room_Torches>(); doors = new List <DoorSave>(); chest_list = new List <ChestData>(); tilesObjects = new List <Room_Object>(); sprites = new List <Room_Sprite>(); pot_items = new List <roomPotSave>(); sortSprites = false; index = roomId; this.name = ROMStructure.roomsNames[index]; messageid = (short)((ROM.DATA[ConstantsReader.GetAddress("messages_id_dungeon") + (index * 2) + 1] << 8) + ROM.DATA[ConstantsReader.GetAddress("messages_id_dungeon") + (index * 2)]); loadHeader(); loadTilesObjects(); //addSprites(); addBlocks(); addTorches(); addPotsItems(); isdamagePit(); }
public void AssembleMap16Tiles(bool fromJson = false, string path = "") { if (!fromJson) { int tpos = ConstantsReader.GetAddress("map16Tiles"); for (int i = 0; i < 4096; i += 1)//3760 { TileInfo t0 = Gettilesinfo(BitConverter.ToInt16(ROM.DATA, (tpos))); tpos += 2; TileInfo t1 = Gettilesinfo(BitConverter.ToInt16(ROM.DATA, (tpos))); tpos += 2; TileInfo t2 = Gettilesinfo(BitConverter.ToInt16(ROM.DATA, (tpos))); tpos += 2; TileInfo t3 = Gettilesinfo(BitConverter.ToInt16(ROM.DATA, (tpos))); tpos += 2; tiles16.Add(new Tile16(t0, t1, t2, t3)); } } else { tiles16 = JsonConvert.DeserializeObject <Tile16[]>(File.ReadAllText(path + @"//Overworld//Tiles16.json")).ToList(); } }
public void writeOverworldExits(string path) { if (!Directory.Exists(path + "Overworld")) { Directory.CreateDirectory(path + "Overworld"); } if (!Directory.Exists(path + "Overworld//Entrances")) { Directory.CreateDirectory(path + "Overworld//Entrances"); } ExitOW[] exits = new ExitOW[0x4F]; for (int i = 0; i < 0x4F; i++) { short[] e = new short[13]; e[0] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitRoomId") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitRoomId") + (i * 2)])); e[1] = (byte)((ROM.DATA[ConstantsReader.GetAddress("OWExitMapId") + i])); e[2] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitVram") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitVram") + (i * 2)])); e[3] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitYScroll") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitYScroll") + (i * 2)])); e[4] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitXScroll") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitXScroll") + (i * 2)])); e[5] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitYPlayer") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitYPlayer") + (i * 2)])); e[6] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitXPlayer") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitXPlayer") + (i * 2)])); e[7] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitYCamera") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitYCamera") + (i * 2)])); e[8] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitXCamera") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitXCamera") + (i * 2)])); e[9] = (byte)((ROM.DATA[ConstantsReader.GetAddress("OWExitUnk1") + i])); e[10] = (byte)((ROM.DATA[ConstantsReader.GetAddress("OWExitUnk2") + i])); e[11] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitDoorType1") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitDoorType1") + (i * 2)])); e[12] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitDoorType2") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitDoorType2") + (i * 2)])); ExitOW eo = (new ExitOW(e[0], (byte)e[1], e[2], e[3], e[4], e[5], e[6], e[7], e[8], (byte)e[9], (byte)e[10], e[11], e[12])); exits[i] = eo; } File.WriteAllText(path + "Overworld//Entrances//Exits.json", JsonConvert.SerializeObject(exits)); }
public void Import(string fname = "") { RegionId.GenerateRegion(); ConstantsReader.SetupRegion(RegionId.myRegion, "../../"); all_maps = new MapSave[160]; CheckGameTitle(); LoadOverworldTiles(); LoadOverworldEntrances(); LoadOverworldExits(); LoadOverworldSprites(); loadOverworldTilesTypes(); LoadOverworldItems(); loadOverworldOverlays(); //progressBar.Value = progressBar.Maximum; //WriteLog("All 'Overworld' data saved in ROM successfuly.", Color.Green, FontStyle.Bold); try { //GFX.gfxdata = Compression.DecompressTiles(); //SaveFileDialog sf = new SaveFileDialog(); // if (sf.ShowDialog() == DialogResult.OK) // { //} runAsar(path, fname); } catch (Exception e) { //WriteLog("Error : " + e.Message.ToString(), Color.Red); return; } }
public void writeOverworldConfig(string path) { if (!Directory.Exists(path + "Overworld")) { Directory.CreateDirectory(path + "Overworld"); } const int dim = 0xA6; byte[] owpalettesgroups = new byte[dim]; int addr = ConstantsReader.GetAddress("overworldMapPaletteGroup"); for (int i = 0; i < dim; i++) { owpalettesgroups[i] = ROM.DATA[i + addr]; } File.WriteAllText(path + "Overworld//PalettesGroups.json", JsonConvert.SerializeObject(owpalettesgroups)); OverworldConfig c = new OverworldConfig(); Color[] grasscolors = new Color[3]; grasscolors[0] = c.hardCodedLWGrass; grasscolors[1] = c.hardCodedDWGrass; grasscolors[2] = c.hardCodedDMGrass; File.WriteAllText(path + "Overworld//GrassColors.json", JsonConvert.SerializeObject(grasscolors)); }
public void LoadOverworldEntrances() { EntranceOW[] holes = JsonConvert.DeserializeObject <EntranceOW[]>(File.ReadAllText(path + @"//Overworld//Entrances//Holes.json")); all_entrancesOW = JsonConvert.DeserializeObject <EntranceOW[]>(File.ReadAllText(path + @"//Overworld//Entrances//Entrances.json")); for (int i = 0; i < all_entrancesOW.Length; i++) { ROM.DATA[ConstantsReader.GetAddress("OWEntranceMap") + (i * 2) + 1] = (byte)((all_entrancesOW[i].mapId >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWEntranceMap") + (i * 2)] = (byte)((all_entrancesOW[i].mapId) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWEntrancePos") + (i * 2) + 1] = (byte)((all_entrancesOW[i].mapPos >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWEntrancePos") + (i * 2)] = (byte)((all_entrancesOW[i].mapPos) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWEntranceEntranceId") + i] = (byte)((all_entrancesOW[i].entranceId) & 0xFF); } for (int i = 0; i < holes.Length; i++) { ROM.DATA[ConstantsReader.GetAddress("OWHoleArea") + (i * 2) + 1] = (byte)((holes[i].mapId >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWHoleArea") + (i * 2)] = (byte)((holes[i].mapId) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWHolePos") + (i * 2) + 1] = (byte)((holes[i].mapPos >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWHolePos") + (i * 2)] = (byte)((holes[i].mapPos) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWHoleEntrance") + i] = (byte)((holes[i].entranceId) & 0xFF); } //WriteLog("Overworld Entrances data loaded properly", Color.Green); }
public void addBlocks() { //288 int blocksCount = (short)((ROM.DATA[ConstantsReader.GetAddress("blocks_length") + 1] << 8) + ROM.DATA[ConstantsReader.GetAddress("blocks_length")]); byte[] blocksdata = new byte[blocksCount]; //int blocksCount = (short)((ROM.DATA[ConstantsReader.GetAddress("blocks_length + 1] << 8) + ROM.DATA[ConstantsReader.GetAddress("blocks_length]); addlistBlock(ref blocksdata, blocksCount); for (int i = 0; i < blocksCount; i += 4) { byte b1 = blocksdata[i], b2 = blocksdata[i + 1], b3 = blocksdata[i + 2], b4 = blocksdata[i + 3]; if (((b2 << 8) + b1) == index) { if (b3 == 0xFF && b4 == 0xFF) { break; } int address = ((b4 & 0x1F) << 8 | b3) >> 1; int px = address % 64; int py = address >> 6; blocks.Add(new Room_Blocks(0x0E00, (byte)(px), (byte)(py), 0, (byte)((b4 & 0x20) >> 5))); } } }
public void AssembleMap32Tiles() { map32address = new int[] { ConstantsReader.GetAddress("map32TilesTL"), ConstantsReader.GetAddress("map32TilesTR"), ConstantsReader.GetAddress("map32TilesBL"), ConstantsReader.GetAddress("map32TilesBR") }; const int dim = 4; for (int i = 0; i < 0x33F0; i += 6) { ushort[,] b = new ushort[dim, dim]; ushort tl, tr, bl, br; for (int k = 0; k < 4; k++) { tl = generate(i, k, (int)Dimension.map32TilesTL); tr = generate(i, k, (int)Dimension.map32TilesTR); bl = generate(i, k, (int)Dimension.map32TilesBL); br = generate(i, k, (int)Dimension.map32TilesBR); tiles32.Add(new Tile32(tl, tr, bl, br)); } } }
public void writeTransportstuff(string path) { if (!Directory.Exists(path + "Overworld")) { Directory.CreateDirectory(path + "Overworld"); } if (!Directory.Exists(path + "Overworld//Entrances")) { Directory.CreateDirectory(path + "Overworld//Entrances"); } ExitOWWhirlpool[] whirlpool = new ExitOWWhirlpool[0x08]; for (int i = 0; i < 0x08; i++) { short[] e = new short[13]; e[0] = (byte)((ROM.DATA[ConstantsReader.GetAddress("OWExitMapIdWhirlpool") + i])); e[1] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitVramWhirlpool") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitVramWhirlpool") + (i * 2)])); e[2] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitYScrollWhirlpool") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitYScrollWhirlpool") + (i * 2)])); e[3] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitXScrollWhirlpool") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitXScrollWhirlpool") + (i * 2)])); e[4] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitYPlayerWhirlpool") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitYPlayerWhirlpool") + (i * 2)])); e[5] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitXPlayerWhirlpool") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitXPlayerWhirlpool") + (i * 2)])); e[6] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitYCameraWhirlpool") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitYCameraWhirlpool") + (i * 2)])); e[7] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWExitXCameraWhirlpool") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWExitXCameraWhirlpool") + (i * 2)])); e[8] = (byte)((ROM.DATA[ConstantsReader.GetAddress("OWExitUnk1Whirlpool") + i])); e[9] = (byte)((ROM.DATA[ConstantsReader.GetAddress("OWExitUnk2Whirlpool") + i])); e[10] = (short)((ROM.DATA[ConstantsReader.GetAddress("OWWhirlpoolPosition") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWWhirlpoolPosition") + (i * 2)])); ExitOWWhirlpool eo = (new ExitOWWhirlpool((byte)e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7], (byte)e[8], (byte)e[9], e[10])); whirlpool[i] = eo; } File.WriteAllText(path + "Overworld//Entrances//Whirlpool.json", JsonConvert.SerializeObject(whirlpool)); }
public void LoadOverworldTiles() { overworld.AssembleMap16Tiles(true, path); int palettesOW_Addr = ConstantsReader.GetAddress("overworldMapPalette"); int spritepalettesOW_Addr = ConstantsReader.GetAddress("overworldSpritePalette"); int spritesetOW_Addr = ConstantsReader.GetAddress("overworldSpriteset"); int mapsizeOW_Addr = ConstantsReader.GetAddress("overworldMapSize"); int messageOW_Addr = ConstantsReader.GetAddress("overworldMessages"); int blocksetOW_Addr = ConstantsReader.GetAddress("mapGfx"); for (int i = 0; i < 160; i++) { all_maps[i] = JsonConvert.DeserializeObject <MapSave>(File.ReadAllText(path + @"//Overworld//Maps//Map" + i.ToString("D3") + ".json")); overworld.AllMapTilesFromMap(i, all_maps[i].tiles); if (i == 159) { string s = ""; int tpos = 0; for (int y = 0; y < 16; y++) { for (int x = 0; x < 16; x++) { Tile32 map16 = new Tile32(all_maps[i].tiles[(x * 2), (y * 2)], all_maps[i].tiles[(x * 2) + 1, (y * 2)], all_maps[i].tiles[(x * 2), (y * 2) + 1], all_maps[i].tiles[(x * 2) + 1, (y * 2) + 1]); s += "[" + map16.tile0.ToString("D4") + "," + map16.tile1.ToString("D4") + "," + map16.tile2.ToString("D4") + "," + map16.tile3.ToString("D4") + "] "; tpos++; } s += "\r\n"; } //File.WriteAllText("TileDebug2.txt", s); } } for (int i = 0; i < 136; i++) { //Need to finish importing stuff here ! ROM.DATA[(0x1EF800 + DataOffset) + i] = all_maps[i].tileTypeSet; ROM.DATA[palettesOW_Addr + i] = (byte)(all_maps[i].palette >> 2); // why the >> 2 ¯\_(ツ)_/¯ ROM.DATA[blocksetOW_Addr + i] = all_maps[i].blockset; ROM.DATA[spritesetOW_Addr + i] = all_maps[i].spriteset; ROM.DATA[spritepalettesOW_Addr + i] = all_maps[i].sprite_palette; ROM.DATA[messageOW_Addr + (i * 2) + 1] = (byte)((all_maps[i].msgid >> 8) & 0xFF); ROM.DATA[messageOW_Addr + (i * 2)] = (byte)(all_maps[i].msgid & 0xFF); } //ROM.DATA[mapsizeOW_Addr + i] = (byte)(all_maps[i].largeMap?0:1); byte[] largemaps = getLargeMaps(); //overworld.createMap32TilesFrom16(); //overworld.savemapstorom(); overworld.savemapstoromNEW(all_maps); //WriteLog("Overworld tiles data loaded properly", Color.Green); }
public void savemapstorom() { int pos = 0x1A0000; for (int i = 0; i < 160; i++) { int npos = 0; byte[] singlemap1 = new byte[256], singlemap2 = new byte[256]; for (int y = 0; y < 16; y++) { for (int x = 0; x < 16; x++) { singlemap1[npos] = (byte)(t32[npos + (i * 256)] & 0xFF); singlemap2[npos] = (byte)((t32[npos + (i * 256)] >> 8) & 0xFF); npos++; } } int snesPos = Addresses.pctosnes(pos); ROM.DATA[(ConstantsReader.GetAddress("compressedAllMap32PointersHigh")) + 0 + (int)(3 * i)] = (byte)(snesPos & 0xFF); ROM.DATA[(ConstantsReader.GetAddress("compressedAllMap32PointersHigh")) + 1 + (int)(3 * i)] = (byte)((snesPos >> 8) & 0xFF); ROM.DATA[(ConstantsReader.GetAddress("compressedAllMap32PointersHigh")) + 2 + (int)(3 * i)] = (byte)((snesPos >> 16) & 0xFF); ROM.DATA[pos] = 0xE0; ROM.DATA[pos + 1] = 0xFF; pos += 2; for (int j = 0; j < 256; j++) { ROM.DATA[pos] = singlemap2[j]; pos += 1; } ROM.DATA[pos] = 0xFF; pos += 1; snesPos = Addresses.pctosnes(pos); ROM.DATA[(ConstantsReader.GetAddress("compressedAllMap32PointersLow")) + 0 + (int)(3 * i)] = (byte)((snesPos >> 00) & 0xFF); ROM.DATA[(ConstantsReader.GetAddress("compressedAllMap32PointersLow")) + 1 + (int)(3 * i)] = (byte)((snesPos >> 08) & 0xFF); ROM.DATA[(ConstantsReader.GetAddress("compressedAllMap32PointersLow")) + 2 + (int)(3 * i)] = (byte)((snesPos >> 16) & 0xFF); ROM.DATA[pos] = 0xE0; ROM.DATA[pos + 1] = 0xFF; pos += 2; for (int j = 0; j < 256; j++) { ROM.DATA[pos] = singlemap1[j]; pos += 1; } ROM.DATA[pos] = 0xFF; pos += 1; } Console.WriteLine(); Save32Tiles(); }
public void Save32Tiles() { int index = 0; int c = tiles32count + 8; //Need to compare US and JP, JP Limit is 33C0, US is 33F0 for (int i = 0; i < c - 4; i += 6) { if (i >= 0x33F0) { Console.WriteLine("Too Many Unique Tiles !"); break; } //Top Left ROM.DATA[ConstantsReader.GetAddress("map32TilesTL") + (i + 0)] = (byte)(t32Unique[index + 0].tile0 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesTL") + (i + 1)] = (byte)(t32Unique[index + 1].tile0 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesTL") + (i + 2)] = (byte)(t32Unique[index + 2].tile0 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesTL") + (i + 3)] = (byte)(t32Unique[index + 3].tile0 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesTL") + (i + 4)] = (byte)(((t32Unique[index].tile0 >> 4) & 0xF0) + ((t32Unique[index + 1].tile0 >> 8) & 0x0F)); ROM.DATA[ConstantsReader.GetAddress("map32TilesTL") + (i + 5)] = (byte)(((t32Unique[index + 2].tile0 >> 4) & 0xF0) + ((t32Unique[index + 3].tile0 >> 8) & 0x0F)); //Top Right ROM.DATA[ConstantsReader.GetAddress("map32TilesTR") + (i)] = (byte)(t32Unique[index].tile1 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesTR") + (i + 1)] = (byte)(t32Unique[index + 1].tile1 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesTR") + (i + 2)] = (byte)(t32Unique[index + 2].tile1 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesTR") + (i + 3)] = (byte)(t32Unique[index + 3].tile1 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesTR") + (i + 4)] = (byte)(((t32Unique[index].tile1 >> 4) & 0xF0) | ((t32Unique[index + 1].tile1 >> 8) & 0x0F)); ROM.DATA[ConstantsReader.GetAddress("map32TilesTR") + (i + 5)] = (byte)(((t32Unique[index + 2].tile1 >> 4) & 0xF0) | ((t32Unique[index + 3].tile1 >> 8) & 0x0F)); //Bottom Left ROM.DATA[ConstantsReader.GetAddress("map32TilesBL") + (i)] = (byte)(t32Unique[index].tile2 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesBL") + (i + 1)] = (byte)(t32Unique[index + 1].tile2 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesBL") + (i + 2)] = (byte)(t32Unique[index + 2].tile2 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesBL") + (i + 3)] = (byte)(t32Unique[index + 3].tile2 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesBL") + (i + 4)] = (byte)(((t32Unique[index].tile2 >> 4) & 0xF0) | ((t32Unique[index + 1].tile2 >> 8) & 0x0F)); ROM.DATA[ConstantsReader.GetAddress("map32TilesBL") + (i + 5)] = (byte)(((t32Unique[index + 2].tile2 >> 4) & 0xF0) | ((t32Unique[index + 3].tile2 >> 8) & 0x0F)); //Bottom Right ROM.DATA[ConstantsReader.GetAddress("map32TilesBR") + (i)] = (byte)(t32Unique[index].tile3 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesBR") + (i + 1)] = (byte)(t32Unique[index + 1].tile3 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesBR") + (i + 2)] = (byte)(t32Unique[index + 2].tile3 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesBR") + (i + 3)] = (byte)(t32Unique[index + 3].tile3 & 0xFF); ROM.DATA[ConstantsReader.GetAddress("map32TilesBR") + (i + 4)] = (byte)(((t32Unique[index].tile3 >> 4) & 0xF0) | ((t32Unique[index + 1].tile3 >> 8) & 0x0F)); ROM.DATA[ConstantsReader.GetAddress("map32TilesBR") + (i + 5)] = (byte)(((t32Unique[index + 2].tile3 >> 4) & 0xF0) | ((t32Unique[index + 3].tile3 >> 8) & 0x0F)); index += 4; c += 2; } }
public void addTorches() { int bytes_count = (ROM.DATA[ConstantsReader.GetAddress("torches_length_pointer") + 1] << 8) + ROM.DATA[ConstantsReader.GetAddress("torches_length_pointer")]; int torchDataAddress = ConstantsReader.GetAddress("torch_data"); for (int i = 0; i < bytes_count; i += 2) { byte b1 = ROM.DATA[torchDataAddress + i]; byte b2 = ROM.DATA[torchDataAddress + i + 1]; if (b1 == 0xFF && b2 == 0xFF) { continue; } if (((b2 << 8) + b1) == index) // if roomindex = indexread { i += 2; while (true) { b1 = ROM.DATA[torchDataAddress + i]; b2 = ROM.DATA[torchDataAddress + i + 1]; if (b1 == 0xFF && b2 == 0xFF) { break; } int address = ((b2 & 0x1F) << 8 | b1) >> 1; int px = address % 64; int py = address >> 6; torches.Add(new Room_Torches(0x150, (byte)px, (byte)py, 0, (byte)((b2 & 0x20) >> 5))); //tilesObjects[tilesObjects.Count - 1].is_torch = true; i += 2; } } else { while (true) { b1 = ROM.DATA[torchDataAddress + i]; b2 = ROM.DATA[torchDataAddress + i + 1]; if (b1 == 0xFF && b2 == 0xFF) { break; } i += 2; } } } }
public void writeOverworldTilesType(string path) { byte[][] types = new byte[16][]; int addr = (ConstantsReader.GetAddress("overworldTilesType")); for (int j = 0; j < 16; j++) { types[j] = new byte[512]; for (int i = 0; i < 512; i++) { types[j][i] = ROM.DATA[addr + i]; } } File.WriteAllText(path + "Overworld//TilesTypes.json", JsonConvert.SerializeObject(types)); }
public void isdamagePit() { int pitCount = (ROM.DATA[ConstantsReader.GetAddress("pit_count")] / 2); int pitPointer = AddressLoROM.SnesToPc(ConstantsReader.GetAddress("pit_pointer")); pitPointer = Addresses.snestopc(pitPointer); for (int i = 0; i < pitCount; i++) { if (((ROM.DATA[pitPointer + 1 + (i * 2)] << 8) + (ROM.DATA[pitPointer + (i * 2)])) == index) { damagepit = true; return; } } }
public void writeOverworldGroups2(string path) { if (!Directory.Exists(path + "Overworld")) { Directory.CreateDirectory(path + "Overworld"); } const int dim = 80 * 8; byte[] owblocksetgroups = new byte[dim]; for (int i = 0; i < dim; i++) { owblocksetgroups[i] = ROM.DATA[ConstantsReader.GetAddress("overworldgfxGroups2") + i]; } File.WriteAllText(path + "Overworld//BlocksetGroups2.json", JsonConvert.SerializeObject(owblocksetgroups)); }
public void writeOverworldItems(string path) { if (!Directory.Exists(path + "Overworld//Items")) { Directory.CreateDirectory(path + "Overworld//Items"); } List <roomPotSave> items = new List <roomPotSave>(); for (int i = 0; i < 128; i++) { int addr = (ConstantsReader.GetAddress("overworldItemsBank") << 16) + (ROM.DATA[ConstantsReader.GetAddress("overworldItemsPointers") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("overworldItemsPointers") + (i * 2)]); addr = Addresses.snestopc(addr); if (all_maps[i].largeMap == true) { if (mapParent[i] != (byte)i) { continue; } } while (true) { byte b1 = ROM.DATA[addr]; byte b2 = ROM.DATA[addr + 1]; byte b3 = ROM.DATA[addr + 2]; if (b1 == 0xFF && b2 == 0xFF) { break; } int p = (((b2 & 0x1F) << 8) + b1) >> 1; int x = p % 64; int y = p >> 6; items.Add(new roomPotSave(b3, (ushort)i, (byte)x, (byte)y, false)); addr += 3; } } File.WriteAllText(path + "Overworld//Items/Items.json", JsonConvert.SerializeObject(items)); }
public void Export() { RegionId.GenerateRegion(); ConstantsReader.SetupRegion(RegionId.myRegion, "../../"); all_rooms = new RoomSave[296]; all_maps = new MapSave[160]; CheckGameTitle(); LoadDungeonsRooms(); LoadOverworldTiles(); LoadOverworldMaps(); TextData.readAllText(); LoadedProjectStatistics.texts = TextData.messages.Count; SaveJson s = new SaveJson(path, rompath, all_rooms, all_maps, null, TextData.messages.ToArray(), overworld); MessageBox.Show("Project creation successful."); }
public void loadHeader() { //address of the room header int headerPointer = AddressLoROM.SnesToPc(ConstantsReader.GetAddress("room_header_pointer")); headerPointer = Addresses.snestopc(headerPointer); int address = (ROM.DATA[ConstantsReader.GetAddress("room_header_pointers_bank")] << 16) + (ROM.DATA[(headerPointer + 1) + (index * 2)] << 8) + ROM.DATA[(headerPointer) + (index * 2)]; header_location = Addresses.snestopc(address); bg2 = (byte)((ROM.DATA[header_location] >> 5) & 0x07); collision = (byte)((ROM.DATA[header_location] >> 2) & 0x07); light = (((ROM.DATA[header_location]) & 0x01) == 1 ? true : false); if (light) { bg2 = 00; } palette = (byte)((ROM.DATA[header_location + 1] & 0x3F)); blockset = (byte)((ROM.DATA[header_location + 2])); spriteset = (byte)((ROM.DATA[header_location + 3])); effect = (byte)((ROM.DATA[header_location + 4])); tag1 = (byte)((ROM.DATA[header_location + 5])); tag2 = (byte)((ROM.DATA[header_location + 6])); holewarp_plane = (byte)((ROM.DATA[header_location + 7]) & 0x03); staircase_plane[0] = (byte)((ROM.DATA[header_location + 7] >> 2) & 0x03); staircase_plane[1] = (byte)((ROM.DATA[header_location + 7] >> 4) & 0x03); staircase_plane[2] = (byte)((ROM.DATA[header_location + 7] >> 6) & 0x03); staircase_plane[3] = (byte)((ROM.DATA[header_location + 8]) & 0x03); holewarp = (byte)((ROM.DATA[header_location + 9])); staircase_rooms[0] = (byte)((ROM.DATA[header_location + 10])); staircase_rooms[1] = (byte)((ROM.DATA[header_location + 11])); staircase_rooms[2] = (byte)((ROM.DATA[header_location + 12])); staircase_rooms[3] = (byte)((ROM.DATA[header_location + 13])); }
/* public void addSprites() * { * int spritePointer = (04 << 16) + (ROM.DATA[ConstantsReader.GetAddress("rooms_sprite_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("rooms_sprite_pointer")]); * //09 bank ? Need to check if HM change that * int sprite_address_snes = (09 << 16) + * (ROM.DATA[spritePointer + (index * 2) + 1] << 8) + * ROM.DATA[spritePointer + (index * 2)]; * int sprite_address = Addresses.snestopc(sprite_address_snes); * sortSprites = ROM.DATA[sprite_address] == 1 ? true : false; * sprite_address += 1; * while (true) * { * byte * b1 = ROM.DATA[sprite_address], * b2 = ROM.DATA[sprite_address + 1], * b3 = ROM.DATA[sprite_address + 2]; * * if (b1 == 0xFF) { break; } * Room_Sprite s = new Room_Sprite(b3, (byte)(b2 & 0x1F), (byte)(b1 & 0x1F), Sprites_Names.name[b3], (byte)((b2 & 0xE0) >> 5), (byte)((b1 & 0x60) >> 5), (byte)((b1 & 0x80) >> 7), 0); * sprites.Add(s); * * if (sprites.Count > 1) * { * Room_Sprite spr = sprites[sprites.Count - 1]; * Room_Sprite prevSprite = sprites[sprites.Count - 2]; * if (spr.id == 0xE4 && spr.x == 0x00 && spr.y == 0x1E && spr.layer == 1 && ((spr.subtype << 3) + spr.overlord) == 0x18) * { * if (prevSprite != null) * { * prevSprite.keyDrop = 1; * sprites.RemoveAt(sprites.Count - 1); * } * } * if (spr.id == 0xE4 && spr.x == 0x00 && spr.y == 0x1D && spr.layer == 1 && ((spr.subtype << 3) + spr.overlord) == 0x18) * { * if (prevSprite != null) * { * prevSprite.keyDrop = 2; * sprites.RemoveAt(sprites.Count - 1); * } * } * } * sprite_address += 3; * } * }*/ public void addlistBlock(ref byte[] blocksdata, int maxCount) { int pos1 = AddressLoROM.SnesToPc(ConstantsReader.GetAddress("blocks_pointer1")), pos2 = AddressLoROM.SnesToPc(ConstantsReader.GetAddress("blocks_pointer2")), pos3 = AddressLoROM.SnesToPc(ConstantsReader.GetAddress("blocks_pointer3")), pos4 = AddressLoROM.SnesToPc(ConstantsReader.GetAddress("blocks_pointer4")); for (int i = 0; i < 0x80; i += 1) { blocksdata[i] = (ROM.DATA[i + pos1]); blocksdata[i + 0x80] = (ROM.DATA[i + pos2]); if (i + 0x100 < maxCount) { blocksdata[i + 0x100] = (ROM.DATA[i + pos3]); } if (i + 0x180 < maxCount) { blocksdata[i + 0x180] = (ROM.DATA[i + pos4]); } } }
public void writeOverworldEntrances(string path) { if (!Directory.Exists(path + "Overworld")) { Directory.CreateDirectory(path + "Overworld"); } if (!Directory.Exists(path + "Overworld//Entrances")) { Directory.CreateDirectory(path + "Overworld//Entrances"); } EntranceOW[] entrances = new EntranceOW[129]; for (int i = 0; i < 129; i++) { short mapId = (short)((ROM.DATA[ConstantsReader.GetAddress("OWEntranceMap") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWEntranceMap") + (i * 2)])); short mapPos = (short)((ROM.DATA[ConstantsReader.GetAddress("OWEntrancePos") + (i * 2) + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("OWEntrancePos") + (i * 2)])); byte entranceId = (byte)((ROM.DATA[ConstantsReader.GetAddress("OWEntranceEntranceId") + i])); EntranceOW eo = new EntranceOW(mapId, mapPos, entranceId); entrances[i] = eo; } File.WriteAllText(path + "Overworld//Entrances//Entrances.json", JsonConvert.SerializeObject(entrances)); }
public void LoadOverworldExits() { all_exitsOW = JsonConvert.DeserializeObject <ExitOW[]>(File.ReadAllText(path + @"//Overworld//Entrances//Exits.json")); for (int i = 0; i < 78; i++) { ROM.DATA[ConstantsReader.GetAddress("OWExitMapId") + (i)] = (byte)((all_exitsOW[i].mapId) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitXScroll") + (i * 2) + 1] = (byte)((all_exitsOW[i].xScroll >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitXScroll") + (i * 2)] = (byte)((all_exitsOW[i].xScroll) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitYScroll") + (i * 2) + 1] = (byte)((all_exitsOW[i].yScroll >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitYScroll") + (i * 2)] = (byte)((all_exitsOW[i].yScroll) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitXCamera") + (i * 2) + 1] = (byte)((all_exitsOW[i].cameraX >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitXCamera") + (i * 2)] = (byte)((all_exitsOW[i].cameraX) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitYCamera") + (i * 2) + 1] = (byte)((all_exitsOW[i].cameraY >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitYCamera") + (i * 2)] = (byte)((all_exitsOW[i].cameraY) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitVram") + (i * 2) + 1] = (byte)((all_exitsOW[i].vramLocation >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitVram") + (i * 2)] = (byte)((all_exitsOW[i].vramLocation) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitRoomId") + (i * 2) + 1] = (byte)((all_exitsOW[i].roomId >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitRoomId") + (i * 2)] = (byte)((all_exitsOW[i].roomId) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitXPlayer") + (i * 2) + 1] = (byte)((all_exitsOW[i].playerX >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitXPlayer") + (i * 2)] = (byte)((all_exitsOW[i].playerX) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitYPlayer") + (i * 2) + 1] = (byte)((all_exitsOW[i].playerY >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitYPlayer") + (i * 2)] = (byte)((all_exitsOW[i].playerY) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitDoorType1") + (i * 2) + 1] = (byte)((all_exitsOW[i].doorType1 >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitDoorType1") + (i * 2)] = (byte)((all_exitsOW[i].doorType1) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitDoorType2") + (i * 2) + 1] = (byte)((all_exitsOW[i].doorType2 >> 8) & 0xFF); ROM.DATA[ConstantsReader.GetAddress("OWExitDoorType2") + (i * 2)] = (byte)((all_exitsOW[i].doorType2) & 0xFF); } //WriteLog("Overworld Exits data loaded properly", Color.Green); }
public void loadChests(ref List <ChestData> chests_in_room) { int cpos = AddressLoROM.SnesToPc(ConstantsReader.GetAddress("chests_data_pointer1")); cpos = Addresses.snestopc(cpos); int clength = (ROM.DATA[ConstantsReader.GetAddress("chests_length_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("chests_length_pointer")]); for (int i = 0; i < (clength); i++) { if ((((ROM.DATA[cpos + (i * 3) + 1] << 8) + (ROM.DATA[cpos + (i * 3)])) & 0x7FFF) == index) { //there's a chest in that room ! bool big = false; if ((((ROM.DATA[cpos + (i * 3) + 1] << 8) + (ROM.DATA[cpos + (i * 3)])) & 0x8000) == 0x8000) //????? { big = true; } chests_in_room.Add(new ChestData(ROM.DATA[cpos + (i * 3) + 2], big)); // } } }
public void DecompressAllMapTiles() { //locat functions int genPointer(int address, int i) => PointerRead.LongRead_LoHiBank(address + i * 3); byte[] Decomp(int pointer, ref int compressedSize) => Decompress.ALTTPDecompressOverworld(ROM.DATA, pointer, 1000, ref compressedSize); int npos = 0; for (int i = 0; i < 160; i++) { int p1 = genPointer(ConstantsReader.GetAddress("compressedAllMap32PointersHigh"), i), p2 = genPointer(ConstantsReader.GetAddress("compressedAllMap32PointersLow"), i); int ttpos = 0, compressedSize1 = 0, compressedSize2 = 0; byte[] bytes = Decomp(p2, ref compressedSize1), bytes2 = Decomp(p1, ref compressedSize2); for (int y = 0; y < 16; y++) { for (int x = 0, tpos; x < 16; x++, npos++, ttpos++) { tpos = (ushort)((bytes2[ttpos] << 8) + bytes[ttpos]); if (tpos < tiles32.Count) { map16tiles[npos] = new Tile32(tiles32[tpos].tile0, tiles32[tpos].tile1, tiles32[tpos].tile2, tiles32[tpos].tile3); } else { Console.WriteLine("Found 0,0,0,0"); map16tiles[npos] = new Tile32(0, 0, 0, 0); } } } } }
public void loadOverworldOverlays() { //first one == 0xFF 0xFF for the empty int dataPos = ConstantsReader.GetAddress("overlayNewCode"); //empty pointer = overlayNewCode int emptyPos = ConstantsReader.GetAddress("overlayNewCode");; ROM.DATA[dataPos++] = 0xFF; ROM.DATA[dataPos++] = 0xFF; List <OverlayData>[] overlaysData = JsonConvert.DeserializeObject <List <OverlayData>[]>(File.ReadAllText(path + @"//Overworld//Overlays.json")); int pointeraddr = ConstantsReader.GetAddress("overlayPointers"); for (int i = 0; i < 128; i++) { if (vanillaOverlays[i] == true) { int snesaddr = Addresses.pctosnes(dataPos); ROM.DATA[pointeraddr + (i * 2) + 1] = (byte)((snesaddr >> 8) & 0xFF); ROM.DATA[pointeraddr + (i * 2)] = (byte)((snesaddr) & 0xFF); // Format: iiiipppp pppppppp iiiiiiii - p = position, i = tile id foreach (OverlayData od in overlaysData[i]) { short pos = (short)((((od.y * 64) + od.x)) << 1); byte b1 = (byte)((pos & 0xFF00) >> 8); byte b2 = (byte)((pos & 0x00FF)); byte b3 = (byte)((od.tileId & 0xFF00) >> 8); byte b4 = (byte)(od.tileId & 0xFF); ROM.DATA[dataPos++] = b2; ROM.DATA[dataPos++] = b1; ROM.DATA[dataPos++] = b4; ROM.DATA[dataPos++] = b3; } ROM.DATA[dataPos++] = 0xFF; ROM.DATA[dataPos++] = 0xFF; } else { int snesaddr = Addresses.pctosnes(emptyPos); ROM.DATA[pointeraddr + (i * 2) + 1] = (byte)((snesaddr >> 8) & 0xFF); ROM.DATA[pointeraddr + (i * 2)] = (byte)((snesaddr) & 0xFF); } } /*ROM.DATA[pointeraddr + (i * 2) + 1] = (byte)((snesaddr >> 8) & 0xFF); * ROM.DATA[pointeraddr + (i * 2)] = (byte)((snesaddr) & 0xFF); * foreach (roomPotSave item in roomItems[i]) * { * * //Console.WriteLine(item.x); * * short mapPos = (short)(((item.y << 6) + item.x) << 1); * * byte b1 = (byte)((mapPos >> 8));//1111 1111 0000 0000 * byte b2 = (byte)(mapPos & 0xFF);//0000 0000 1111 1111 * byte b3 = (byte)(item.id); * * ROM.DATA[dataPos++] = b2; * ROM.DATA[dataPos++] = b1; * ROM.DATA[dataPos++] = b3; * } * ROM.DATA[dataPos++] = 0xFF; * ROM.DATA[dataPos] = 0xFF; * if (dataPos >= (0x1F2800 + DataOffset)) * { * Console.WriteLine("Too many Overworld items !"); * break; * } * dataPos++; * * } * else * { * int snesaddr = Addresses.pctosnes(emptyPointer); * ROM.DATA[pointeraddr + (i * 2) + 1] = (byte) ((snesaddr >> 8) & 0xFF); * ROM.DATA[pointeraddr + (i * 2)] = (byte) ((snesaddr) & 0xFF); * //Save Empty Pointer * }*/ }
public void LoadOverworldItems() { roomPotSave[] items = JsonConvert.DeserializeObject <roomPotSave[]>(File.ReadAllText(path + @"//Overworld//Items//Items.json")); List <roomPotSave>[] roomItems = new List <roomPotSave> [128]; for (int i = 0; i < 128; i++) { roomItems[i] = new List <roomPotSave>(); for (int j = 0; j < items.Length; j++) { if (i == items[j].roomMapId) { roomItems[i].Add(items[j]); } } } ROM.DATA[(0x1F1201 + DataOffset)] = 0xFF; ROM.DATA[(0x1F1202 + DataOffset)] = 0xFF; short emptyPointer = 0x1201; int dataPos = (0x1F1203 + DataOffset); int pointeraddr = ConstantsReader.GetAddress("overworldItemsPointers"); for (int i = 0; i < 128; i++) { if (roomItems[i].Count != 0) { int snesaddr = Addresses.pctosnes(dataPos); ROM.DATA[pointeraddr + (i * 2) + 1] = (byte)((snesaddr >> 8) & 0xFF); ROM.DATA[pointeraddr + (i * 2)] = (byte)((snesaddr) & 0xFF); foreach (roomPotSave item in roomItems[i]) { //Console.WriteLine(item.x); short mapPos = (short)(((item.y << 6) + item.x) << 1); byte b1 = (byte)((mapPos >> 8)); //1111 1111 0000 0000 byte b2 = (byte)(mapPos & 0xFF); //0000 0000 1111 1111 byte b3 = (byte)(item.id); ROM.DATA[dataPos++] = b2; ROM.DATA[dataPos++] = b1; ROM.DATA[dataPos++] = b3; } ROM.DATA[dataPos++] = 0xFF; ROM.DATA[dataPos] = 0xFF; if (dataPos >= (0x1F2800 + DataOffset)) { Console.WriteLine("Too many Overworld items !"); break; } dataPos++; } else { int snesaddr = Addresses.pctosnes(emptyPointer); ROM.DATA[pointeraddr + (i * 2) + 1] = (byte)((snesaddr >> 8) & 0xFF); ROM.DATA[pointeraddr + (i * 2)] = (byte)((snesaddr) & 0xFF); //Save Empty Pointer } } }
public void loadTilesObjects(bool floor = true) { //adddress of the room objects int objectPointer = (ROM.DATA[ConstantsReader.GetAddress("room_object_pointer") + 2] << 16) + (ROM.DATA[ConstantsReader.GetAddress("room_object_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("room_object_pointer")]); objectPointer = Addresses.snestopc(objectPointer); int room_address = objectPointer + (index * 3); int tile_address = (ROM.DATA[room_address + 2] << 16) + (ROM.DATA[room_address + 1] << 8) + ROM.DATA[room_address]; int objects_location = Addresses.snestopc(tile_address); if (floor) { floor1 = (byte)(ROM.DATA[objects_location] & 0x0F); floor2 = (byte)((ROM.DATA[objects_location] >> 4) & 0x0F); } layout = (byte)((ROM.DATA[objects_location + 1] >> 2) & 0x07); List <ChestData> chests_in_room = new List <ChestData>(); loadChests(ref chests_in_room); int pos = objects_location + 2; byte b1 = 0; byte b2 = 0; byte b3 = 0; byte posX = 0; byte posY = 0; byte sizeX = 0; byte sizeY = 0; byte sizeXY = 0; short oid = 0; int layer = 0; bool door = false; bool endRead = false; while (endRead == false) { b1 = ROM.DATA[pos]; b2 = ROM.DATA[pos + 1]; if (b1 == 0xFF && b2 == 0xFF) { pos += 2; //we jump to layer2 layer++; door = false; if (layer == 3) { endRead = true; break; } continue; } if (b1 == 0xF0 && b2 == 0xFF) { pos += 2; //we jump to layer2 door = true; continue; } b3 = ROM.DATA[pos + 2]; if (door) { pos += 2; } else { pos += 3; } if (door == false) { if (b3 >= 0xF8) { oid = (short)((b3 << 4) | 0x80 + (((b2 & 0x03) << 2) + ((b1 & 0x03)))); posX = (byte)((b1 & 0xFC) >> 2); posY = (byte)((b2 & 0xFC) >> 2); sizeXY = (byte)((((b1 & 0x03) << 2) + (b2 & 0x03))); } else //subtype1 { oid = b3; posX = (byte)((b1 & 0xFC) >> 2); posY = (byte)((b2 & 0xFC) >> 2); sizeX = (byte)((b1 & 0x03)); sizeY = (byte)((b2 & 0x03)); sizeXY = (byte)(((sizeX << 2) + sizeY)); } if (b1 >= 0xFC) //subtype2 (not scalable? ) { oid = (short)((b3 & 0x3F) + 0x100); posX = (byte)(((b2 & 0xF0) >> 4) + ((b1 & 0x3) << 4)); posY = (byte)(((b2 & 0x0F) << 2) + ((b3 & 0xC0) >> 6)); sizeXY = 0; } tilesObjects.Add(new Room_Object(oid, posX, posY, sizeXY, (byte)layer)); //IF Object is a chest loaded and there's object in the list chest if (oid == 0xF99) { if (chests_in_room.Count > 0) { chest_list.Add(new ChestData(chests_in_room[0].itemIn, false)); chests_in_room.RemoveAt(0); } } else if (oid == 0xFB1) { if (chests_in_room.Count > 0) { chest_list.Add(new ChestData(chests_in_room[0].itemIn, true)); chests_in_room.RemoveAt(0); } } } else { doors.Add(new DoorSave((short)((b2 << 8) + b1))); continue; } } }
public static byte[] DecompressTiles() //to gfx.bin { int gfxPointer1 = Addresses.snestopc((ROM.DATA[ConstantsReader.GetAddress("gfx_1_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("gfx_1_pointer")])), gfxPointer2 = Addresses.snestopc((ROM.DATA[ConstantsReader.GetAddress("gfx_2_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("gfx_2_pointer")])), gfxPointer3 = Addresses.snestopc((ROM.DATA[ConstantsReader.GetAddress("gfx_3_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("gfx_3_pointer")])); byte[] buffer = new byte[0x6F800], // (185) bufferBlock; int bufferPos = 0; for (int i = 0; i < 96; i++) { byte[] b = new byte[] { ROM.DATA[gfxPointer3 + i], ROM.DATA[gfxPointer2 + i], ROM.DATA[gfxPointer1 + i], 0 }; int addr = BitConverter.ToInt32(b, 0); addresses[i] = Addresses.snestopc(addr); //Console.WriteLine(Addresses.snestopc(addr).ToString("X6")); byte[] tbufferBlock = Decompress.ALTTPDecompressGraphics(ROM.DATA, Addresses.snestopc(addr), 0x800, ref blockSize[i]); bufferBlock = tbufferBlock; if (tbufferBlock.Length != 0x600) { bpp[i] = 2; bufferBlock = new byte[0x600]; for (int j = 0; j < 0x600; j++) { bufferBlock[j] = tbufferBlock[j]; } } else { bpp[i] = 3; } //bufferBlock = Decompress(Addresses.snestopc(addr), ROM.DATA); for (int j = 0; j < bufferBlock.Length; j++) { buffer[bufferPos] = bufferBlock[j]; bufferPos++; } } for (int i = 96; i < 223; i++) { bpp[i] = 3; if (i < 115 || i > 126) //not compressed { byte[] b = new byte[] { ROM.DATA[gfxPointer3 + i], ROM.DATA[gfxPointer2 + i], ROM.DATA[gfxPointer1 + i], 0 }; int addr = BitConverter.ToInt32(b, 0); addresses[i] = Addresses.snestopc(addr); byte[] tbufferBlock = Decompress.ALTTPDecompressGraphics(ROM.DATA, Addresses.snestopc(addr), 0x800, ref blockSize[i]); bufferBlock = tbufferBlock; if (tbufferBlock.Length != 0x600) { bpp[i] = 2; bufferBlock = new byte[0xC00]; //Console.WriteLine(tbufferBlock.Length); for (int j = 0; j < tbufferBlock.Length; j++) { bufferBlock[j] = tbufferBlock[j]; } //Console.WriteLine("Buffer Size :" + tbufferBlock.Length.ToString("X4")); } for (int j = 0; j < bufferBlock.Length; j++) { buffer[bufferPos] = bufferBlock[j]; bufferPos++; } } else { byte[] b = new byte[] { ROM.DATA[gfxPointer3 + i], ROM.DATA[gfxPointer2 + i], ROM.DATA[gfxPointer1 + i], 0 }; int addr = BitConverter.ToInt32(b, 0); addr = Addresses.snestopc(addr); bpp[i] = 3; for (int j = 0; j < 0x600; j++) { buffer[bufferPos] = ROM.DATA[addr + j]; bufferPos++; } } } /*FileStream fs = new FileStream("testgfx.gfx", FileMode.OpenOrCreate, FileAccess.Write); * fs.Write(buffer.ToArray(), 0, buffer.Length); * fs.Close();*/ return(buffer); }
public void LoadOverworldSprites() { Room_Sprite[][] all_spritesOW = new Room_Sprite[3][]; all_spritesOW[0] = JsonConvert.DeserializeObject <Room_Sprite[]>(File.ReadAllText(path + @"//Overworld//Sprites//Beginning Sprites.json")); all_spritesOW[1] = JsonConvert.DeserializeObject <Room_Sprite[]>(File.ReadAllText(path + @"//Overworld//Sprites//ZeldaRescued Sprites.json")); all_spritesOW[2] = JsonConvert.DeserializeObject <Room_Sprite[]>(File.ReadAllText(path + @"//Overworld//Sprites//AgahnimDefeated Sprites.json")); //Restore sprites by room //64, 143 for (int i = 0; i < 64; i++) { roomSpritesBeginning[i] = new List <Room_Sprite>(); for (int j = 0; j < all_spritesOW[0].Length; j++) { if (all_spritesOW[0][j].roomMapId == i) { roomSpritesBeginning[i].Add(all_spritesOW[0][j]); } } } for (int i = 0; i < 143; i++) { roomSpritesZelda[i] = new List <Room_Sprite>(); roomSpritesAgahnim[i] = new List <Room_Sprite>(); for (int j = 0; j < all_spritesOW[1].Length; j++) { if (all_spritesOW[1][j].roomMapId == i) { roomSpritesZelda[i].Add(all_spritesOW[1][j]); } } for (int j = 0; j < all_spritesOW[2].Length; j++) { if (all_spritesOW[2][j].roomMapId == i) { roomSpritesAgahnim[i].Add(all_spritesOW[2][j]); } } } //data location range spritedata = AED length : 2797 //0x4CB41 starting data location (1st is just a FF for empty pointers) //real starting location = 0x4CB42 //ROM.DATA[0x4CB41] = 0xFF;//Ensure the first data is a return so maps with no sprites can use that ROM.DATA[(0x1F0001 + DataOffset)] = 0xFF; ROM.DATA[(0x1F0000 + DataOffset)] = 0xFF; int emptyPointer = 0x0000; int dataPos = (0x1F0002 + DataOffset); //int dataPos = 0x4CB42; int beginningPointers = ConstantsReader.GetAddress("overworldSpritesBegining"); int zeldaPointers = ConstantsReader.GetAddress("overworldSpritesZelda"); int agahnimPointers = ConstantsReader.GetAddress("overworldSpritesAgahnim"); for (int i = 0; i < 64; i++) { if (roomSpritesBeginning[i].Count != 0) { int snesaddr = Addresses.pctosnes(dataPos); ROM.DATA[beginningPointers + (i * 2) + 1] = (byte)((snesaddr >> 8) & 0xFF); ROM.DATA[beginningPointers + (i * 2)] = (byte)((snesaddr) & 0xFF); foreach (Room_Sprite spr in roomSpritesBeginning[i]) { byte b1 = spr.y; byte b2 = spr.x; byte b3 = spr.id; ROM.DATA[dataPos++] = b1; ROM.DATA[dataPos++] = b2; ROM.DATA[dataPos++] = b3; } //add FF to end the room ROM.DATA[dataPos++] = 0xFF; if (dataPos >= ((0x1F1200 + DataOffset))) { Console.WriteLine("Too many Overworld sprites !"); break; } } else { int snesaddr = Addresses.pctosnes(emptyPointer); ROM.DATA[beginningPointers + (i * 2) + 1] = (byte)((snesaddr >> 8) & 0xFF); ROM.DATA[beginningPointers + (i * 2)] = (byte)((snesaddr) & 0xFF); } } for (int i = 0; i < 143; i++) { if (roomSpritesZelda[i].Count != 0) { int snesaddr = Addresses.pctosnes(dataPos); ROM.DATA[zeldaPointers + (i * 2) + 1] = (byte)((snesaddr >> 8) & 0xFF); ROM.DATA[zeldaPointers + (i * 2)] = (byte)((snesaddr) & 0xFF); foreach (Room_Sprite spr in roomSpritesZelda[i]) { byte b1 = spr.y; byte b2 = spr.x; byte b3 = spr.id; ROM.DATA[dataPos++] = b1; ROM.DATA[dataPos++] = b2; ROM.DATA[dataPos++] = b3; } //add FF to end the room ROM.DATA[dataPos++] = 0xFF; if (dataPos >= (0x1F1200 + DataOffset)) { Console.WriteLine("Too many Overworld sprites ! (Zelda)"); break; } } else { int snesaddr = Addresses.pctosnes(emptyPointer); ROM.DATA[zeldaPointers + (i * 2) + 1] = (byte)((snesaddr >> 8) & 0xFF); ROM.DATA[zeldaPointers + (i * 2)] = (byte)((snesaddr) & 0xFF); } } for (int i = 0; i < 143; i++) { if (roomSpritesAgahnim[i].Count != 0) { int snesaddr = Addresses.pctosnes(dataPos); ROM.DATA[agahnimPointers + (i * 2) + 1] = (byte)((snesaddr >> 8) & 0xFF); ROM.DATA[agahnimPointers + (i * 2)] = (byte)((snesaddr) & 0xFF); foreach (Room_Sprite spr in roomSpritesAgahnim[i]) { byte b1 = spr.y; byte b2 = spr.x; byte b3 = spr.id; ROM.DATA[dataPos++] = b1; ROM.DATA[dataPos++] = b2; ROM.DATA[dataPos++] = b3; } //add FF to end the room ROM.DATA[dataPos++] = 0xFF; if (dataPos >= (0x1F1200 + DataOffset)) { Console.WriteLine("Too many Overworld sprites ! (Agah) room : " + i); break; } } else { int snesaddr = Addresses.pctosnes(emptyPointer); ROM.DATA[agahnimPointers + (i * 2) + 1] = (byte)((snesaddr >> 8) & 0xFF); ROM.DATA[agahnimPointers + (i * 2)] = (byte)((snesaddr) & 0xFF); } } }