public roomHeader() { primaryPointer = ConstantsReader.GetAddress("room_header_pointer"); pointer_bank = ConstantsReader.GetAddress("room_header_pointers_bank"); roomHeaders = new i_roomHeader[numberOfHeaders]; readPointer(); }
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 indoor_blocks() : base(4) { primaryPointer_location = new int[] { ConstantsReader.GetAddress("blocks_pointer1"), ConstantsReader.GetAddress("blocks_pointer2"), ConstantsReader.GetAddress("blocks_pointer3"), ConstantsReader.GetAddress("blocks_pointer4") }; //maxBytesPerBlockFor012 = ReadMixedNumbers.readTwoByte(addressOfStorageMaxFor012); maxBytesPerBlockFor012 = 0x80; dataSize = new int[] { maxBytesPerBlockFor012, maxBytesPerBlockFor012, maxBytesPerBlockFor012, maxBytesPerBlockFor3 }; for (int i = 0; i < numberOfPointers; i++) { sizeOfBlockData += dataSize[i]; } maxBlockEntries = sizeOfBlockData / bytesPerBlock; refreshPointer3Bytes(); }
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, (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 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 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 Import() { RegionId.GenerateRegion(); ConstantsReader.SetupRegion(RegionId.myRegion, "../../"); all_maps = new MapSave[160]; CheckGameTitle(); LoadOverworldTiles(); LoadOverworldEntrances(); 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) { FileStream fs = new FileStream(sf.FileName, FileMode.OpenOrCreate, FileAccess.Write); fs.Write(ROM.DATA, 0, ROM.DATA.Length); fs.Close(); } } catch (Exception e) { WriteLog("Error : " + e.Message.ToString(), Color.Red); return; } }
byte[] DecryptResource_v18_r75367_dynamic(byte[] encrypted) { var local = GetDynamicLocal(out int ldlocIndex); if (local == null) { throw new ApplicationException("Could not find local"); } var instrs = installMethod.Body.Instructions; int startIndex = GetDynamicStartIndex(instrs, ldlocIndex); int endIndex = GetDynamicEndIndex(startIndex, local); if (endIndex < 0) { throw new ApplicationException("Could not find endIndex"); } var constReader = new ConstantsReader(installMethod); return(DecryptResource(encrypted, magic => { constReader.SetConstantInt32(local, magic); int index = startIndex; if (!constReader.GetNextInt32(ref index, out int result)) { throw new ApplicationException("Could not get constant"); } if (index != endIndex) { throw new ApplicationException("Wrong constant"); } return (byte)result; }));
protected byte[] DecryptConstant_v17_r73740_dynamic(DecrypterInfo info, byte[] encrypted, uint offs, uint key1, byte[] key2) { var local = GetDynamicLocal_v17_r73740(info.decryptMethod); if (local == null) { throw new ApplicationException("Could not find local"); } int endIndex = GetDynamicEndIndex_v17_r73740(info.decryptMethod, local); if (endIndex < 0) { endIndex = GetDynamicEndIndex_v17_r74788(info.decryptMethod, local); } int startIndex = GetDynamicStartIndex_v17_r73740(info.decryptMethod, endIndex); if (startIndex < 0) { throw new ApplicationException("Could not find start/end index"); } var constReader = new ConstantsReader(info.decryptMethod); return(Decrypt(encrypted, key1, (magic, i) => { constReader.SetConstantInt32(local, magic); int index = startIndex, result; if (!constReader.GetNextInt32(ref index, out result) || index != endIndex) { throw new ApplicationException("Could not decrypt integer"); } return (byte)(result ^ key2[i % key2.Length]); })); }
public void Export() { RegionId.GenerateRegion(); ConstantsReader.SetupRegion(RegionId.myRegion, "../../"); Stopwatch sw = new Stopwatch(); sw.Start(); ; all_rooms = new RoomSave[296]; all_maps = new MapSave[160]; CheckGameTitle(); progressBar.Value++; LoadDungeonsRooms(); progressBar.Value++; LoadOverworldTiles(); progressBar.Value++; LoadOverworldMaps(); progressBar.Value++; TextData.readAllText(); LoadedProjectStatistics.texts = TextData.messages.Count; progressBar.Value++; WriteLog("All data loaded successfuly.", Color.Green, FontStyle.Bold); sw.Stop(); WriteLog("Elapsed Milliseconds : " + sw.ElapsedMilliseconds.ToString(), Color.DarkRed, FontStyle.Bold); SaveJson s = new SaveJson(all_rooms, all_maps, null, TextData.messages.ToArray(), overworld); progressBar.Value = progressBar.Maximum; WriteLog("All data exported successfuly.", Color.Green, FontStyle.Bold); }
public void writeOverworldExits(string path) { if (!Directory.Exists(path + "Overworld")) { Directory.CreateDirectory(path + "Overworld"); } if (!Directory.Exists(path + "Overworld//Exits")) { Directory.CreateDirectory(path + "Overworld//Exits"); } 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] = (byte)((ROM.DATA[ConstantsReader.GetAddress("OWExitDoorType1") + i])); e[12] = (byte)((ROM.DATA[ConstantsReader.GetAddress("OWExitDoorType2") + i])); 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], (byte)e[11], (byte)e[12])); File.WriteAllText(path + "Overworld//Exits//Exit" + i.ToString("D3") + ".json", JsonConvert.SerializeObject(eo)); } }
public void addlistBlock(ref byte[] blocksdata, int maxCount) { int pos1 = (ROM.DATA[ConstantsReader.GetAddress("blocks_pointer1") + 2] << 16) + (ROM.DATA[ConstantsReader.GetAddress("blocks_pointer1") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("blocks_pointer1")]); pos1 = Addresses.snestopc(pos1); int pos2 = (ROM.DATA[ConstantsReader.GetAddress("blocks_pointer2") + 2] << 16) + (ROM.DATA[ConstantsReader.GetAddress("blocks_pointer2") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("blocks_pointer2")]); pos2 = Addresses.snestopc(pos2); int pos3 = (ROM.DATA[ConstantsReader.GetAddress("blocks_pointer3") + 2] << 16) + (ROM.DATA[ConstantsReader.GetAddress("blocks_pointer3") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("blocks_pointer3")]); pos3 = Addresses.snestopc(pos3); int pos4 = (ROM.DATA[ConstantsReader.GetAddress("blocks_pointer4") + 2] << 16) + (ROM.DATA[ConstantsReader.GetAddress("blocks_pointer4") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("blocks_pointer4")]); pos4 = Addresses.snestopc(pos4); 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]); } } }
internal indoor_damagepits() { POINTER_LOCATION = ConstantsReader.GetAddress("pit_pointer"); DATALENGTH_VALUE_LOCATION = ConstantsReader.GetAddress("pit_count"); dataAddress = PointerRead.LongRead_LoHiBank(POINTER_LOCATION); maxLength = Conversion.toUShort(ROM.DATA[DATALENGTH_VALUE_LOCATION + 1], ROM.DATA[DATALENGTH_VALUE_LOCATION + 0]) + embedded2; readData(); }
public byte music; //1byte //Will need to be renamed and changed to add support to MSU1 public Entrance(byte entranceId, bool startingEntrance = false) { room = (short)((ROM.DATA[(ConstantsReader.GetAddress("entrance_room") + (entranceId * 2)) + 1] << 8) + ROM.DATA[ConstantsReader.GetAddress("entrance_room") + (entranceId * 2)]); yposition = (short)(((ROM.DATA[(ConstantsReader.GetAddress("entrance_yposition") + (entranceId * 2)) + 1]) << 8) + ROM.DATA[ConstantsReader.GetAddress("entrance_yposition") + (entranceId * 2)]); xposition = (short)(((ROM.DATA[(ConstantsReader.GetAddress("entrance_xposition") + (entranceId * 2)) + 1]) << 8) + ROM.DATA[ConstantsReader.GetAddress("entrance_xposition") + (entranceId * 2)]); xscroll = (short)(((ROM.DATA[(ConstantsReader.GetAddress("entrance_xscroll") + (entranceId * 2)) + 1]) << 8) + ROM.DATA[ConstantsReader.GetAddress("entrance_xscroll") + (entranceId * 2)]); yscroll = (short)(((ROM.DATA[(ConstantsReader.GetAddress("entrance_yscroll") + (entranceId * 2)) + 1]) << 8) + ROM.DATA[ConstantsReader.GetAddress("entrance_yscroll") + (entranceId * 2)]); ycamera = (short)(((ROM.DATA[(ConstantsReader.GetAddress("entrance_camerayposition") + (entranceId * 2)) + 1]) << 8) + ROM.DATA[ConstantsReader.GetAddress("entrance_camerayposition") + (entranceId * 2)]); xcamera = (short)(((ROM.DATA[(ConstantsReader.GetAddress("entrance_cameraxposition") + (entranceId * 2)) + 1]) << 8) + ROM.DATA[ConstantsReader.GetAddress("entrance_cameraxposition") + (entranceId * 2)]); blockset = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_blockset") + entranceId)]); music = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_music") + entranceId)]); dungeon = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_dungeon") + entranceId)]); floor = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_floor") + entranceId)]); door = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_door") + entranceId)]); ladderbg = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_ladderbg") + entranceId)]); scrolling = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_scrolling") + entranceId)]); scrollquadrant = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_scrollquadrant") + entranceId)]); exit = (short)(((ROM.DATA[(ConstantsReader.GetAddress("entrance_exit") + (entranceId * 2)) + 1]) << 8) + ROM.DATA[ConstantsReader.GetAddress("entrance_exit") + (entranceId * 2)]); scrolledge_HU = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_scrolledge") + entranceId)]); scrolledge_FU = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_scrolledge") + entranceId) + 1]); scrolledge_HD = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_scrolledge") + entranceId) + 2]); scrolledge_FD = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_scrolledge") + entranceId) + 3]); scrolledge_HL = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_scrolledge") + entranceId) + 4]); scrolledge_FL = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_scrolledge") + entranceId) + 5]); scrolledge_HR = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_scrolledge") + entranceId) + 6]); scrolledge_FR = (byte)(ROM.DATA[(ConstantsReader.GetAddress("entrance_scrolledge") + entranceId) + 7]); if (startingEntrance == true) { room = (short)((ROM.DATA[(ConstantsReader.GetAddress("startingentrance_room") + ((entranceId) * 2)) + 1] << 8) + ROM.DATA[ConstantsReader.GetAddress("startingentrance_room") + ((entranceId) * 2)]); yposition = (short)(((ROM.DATA[(ConstantsReader.GetAddress("startingentrance_yposition") + ((entranceId) * 2)) + 1] & 0x01) << 8) + ROM.DATA[ConstantsReader.GetAddress("startingentrance_yposition") + ((entranceId) * 2)]); xposition = (short)(((ROM.DATA[(ConstantsReader.GetAddress("startingentrance_xposition") + ((entranceId) * 2)) + 1] & 0x01) << 8) + ROM.DATA[ConstantsReader.GetAddress("startingentrance_xposition") + ((entranceId) * 2)]); xscroll = (short)(((ROM.DATA[(ConstantsReader.GetAddress("startingentrance_xscroll") + ((entranceId) * 2)) + 1] & 0x01) << 8) + ROM.DATA[ConstantsReader.GetAddress("startingentrance_xscroll") + ((entranceId) * 2)]); yscroll = (short)(((ROM.DATA[(ConstantsReader.GetAddress("startingentrance_yscroll") + ((entranceId) * 2)) + 1] & 0x01) << 8) + ROM.DATA[ConstantsReader.GetAddress("startingentrance_yscroll") + ((entranceId) * 2)]); ycamera = (short)(((ROM.DATA[(ConstantsReader.GetAddress("startingentrance_camerayposition") + ((entranceId) * 2)) + 1] & 0x01) << 8) + ROM.DATA[ConstantsReader.GetAddress("startingentrance_camerayposition") + ((entranceId) * 2)]); xcamera = (short)(((ROM.DATA[(ConstantsReader.GetAddress("startingentrance_cameraxposition") + ((entranceId) * 2)) + 1] & 0x01) << 8) + ROM.DATA[ConstantsReader.GetAddress("startingentrance_cameraxposition") + ((entranceId) * 2)]); blockset = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_blockset") + entranceId)]); music = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_music") + entranceId)]); dungeon = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_dungeon") + entranceId)]); floor = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_floor") + entranceId)]); door = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_door") + entranceId)]); ladderbg = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_ladderbg") + entranceId)]); scrolling = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_scrolling") + entranceId)]); scrollquadrant = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_scrollquadrant") + entranceId)]); exit = (short)(((ROM.DATA[(ConstantsReader.GetAddress("startingentrance_exit") + (entranceId * 2)) + 1] & 0x01) << 8) + ROM.DATA[ConstantsReader.GetAddress("startingentrance_exit") + (entranceId * 2)]); scrolledge_HU = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_scrolledge") + entranceId)]); scrolledge_FU = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_scrolledge") + entranceId) + 1]); scrolledge_HD = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_scrolledge") + entranceId) + 2]); scrolledge_FD = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_scrolledge") + entranceId) + 3]); scrolledge_HL = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_scrolledge") + entranceId) + 4]); scrolledge_FL = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_scrolledge") + entranceId) + 5]); scrolledge_HR = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_scrolledge") + entranceId) + 6]); scrolledge_FR = (byte)(ROM.DATA[(ConstantsReader.GetAddress("startingentrance_scrolledge") + entranceId) + 7]); } }
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; } 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 LoadDungeonsRooms() { int objCount = 0, chestCount = 0, itemCount = 0, blockCount = 0, torchCount = 0, pitsCount = 0, spritesCount = 0, roomCount = 0; for (int i = 0; i < 296; i++) { try { all_rooms[i] = new RoomSave((short)i); objCount += all_rooms[i].tilesObjects.Count; chestCount += all_rooms[i].chest_list.Count; itemCount += all_rooms[i].pot_items.Count; blockCount += all_rooms[i].blocks.Count; torchCount += all_rooms[i].torches.Count; pitsCount += all_rooms[i].damagepit ? 1 : 0; spritesCount += all_rooms[i].sprites.Count; if (all_rooms[i].tilesObjects.Count != 0) { roomCount++; } if (i == 5) { Console.WriteLine(all_rooms[i].tilesObjects.Count); } } catch (Exception e) { WriteLog("Error : " + e.Message.ToString(), Color.Red); return; } } LoadedProjectStatistics.blocksRooms = blockCount; LoadedProjectStatistics.chestsRooms = chestCount; LoadedProjectStatistics.chestsRoomsLength = ((ROM.DATA[ConstantsReader.GetAddress("chests_length_pointer") + 1] << 8) + (ROM.DATA[ConstantsReader.GetAddress("chests_length_pointer")])) / 3; LoadedProjectStatistics.blocksRoomsLength = ((short)((ROM.DATA[ConstantsReader.GetAddress("blocks_length") + 1] << 8) + ROM.DATA[ConstantsReader.GetAddress("blocks_length")])) / 4; LoadedProjectStatistics.torchesRoomsLength = 86;//(ROM.DATA[ConstantsReader.GetAddress("torches_length_pointer + 1] << 8) + ROM.DATA[ConstantsReader.GetAddress("torches_length_pointer]; LoadedProjectStatistics.entrancesRooms = 132; LoadedProjectStatistics.itemsRooms = itemCount; LoadedProjectStatistics.pitsRooms = pitsCount; LoadedProjectStatistics.pitsRoomsLength = (ROM.DATA[ConstantsReader.GetAddress("pit_count")] / 2); LoadedProjectStatistics.torchesRooms = torchCount; LoadedProjectStatistics.usedRooms = roomCount; LoadedProjectStatistics.spritesRooms = spritesCount; LoadedProjectStatistics.objectsRooms = objCount; WriteLog("All dungeon rooms data loaded properly : ", Color.Green); }
public void addTorches() { int bytes_count = (ROM.DATA[ConstantsReader.GetAddress("torches_length_pointer") + 1] << 8) + ROM.DATA[ConstantsReader.GetAddress("torches_length_pointer")]; for (int i = 0; i < bytes_count; i += 2) { byte b1 = ROM.DATA[ConstantsReader.GetAddress("torch_data") + i]; byte b2 = ROM.DATA[ConstantsReader.GetAddress("torch_data") + i + 1]; if (b1 == 0xFF && b2 == 0xFF) { continue; } if (((b2 << 8) + b1) == index) // if roomindex = indexread { i += 2; while (true) { b1 = ROM.DATA[ConstantsReader.GetAddress("torch_data") + i]; b2 = ROM.DATA[ConstantsReader.GetAddress("torch_data") + 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[ConstantsReader.GetAddress("torch_data") + i]; b2 = ROM.DATA[ConstantsReader.GetAddress("torch_data") + i + 1]; if (b1 == 0xFF && b2 == 0xFF) { break; } i += 2; } } } }
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 isdamagePit() { int pitCount = (ROM.DATA[ConstantsReader.GetAddress("pit_count")] / 2); int pitPointer = (ROM.DATA[ConstantsReader.GetAddress("pit_pointer") + 2] << 16) + (ROM.DATA[ConstantsReader.GetAddress("pit_pointer") + 1] << 8) + (ROM.DATA[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 writeOverworldSpriteset(string path) { if (!Directory.Exists(path + "Overworld")) { Directory.CreateDirectory(path + "Overworld"); } const int dim = 143 * 4; byte[] owblocksetgroups = new byte[dim]; for (int i = 0; i < dim; i++) { owblocksetgroups[i] = ROM.DATA[ConstantsReader.GetAddress("sprite_blockset_pointer") + i]; } File.WriteAllText(path + "Overworld//SpritesetGroups.json", JsonConvert.SerializeObject(owblocksetgroups)); }
public void LoadOverworldEntrances() { for (int i = 0; i < 129; i++) { all_entrancesOW[i] = JsonConvert.DeserializeObject <EntranceOW>(File.ReadAllText("ProjectDirectory//Overworld//Entrances//Entrance" + i.ToString("D3") + ".json")); 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); } WriteLog("Overworld Entrances data loaded properly", Color.Green); }
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"); } 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); File.WriteAllText(path + "Overworld//Entrances//Entrance" + i.ToString("D3") + ".json", JsonConvert.SerializeObject(eo)); } }
/// <summary> /// Initilializes a new instance of indoor_sprites /// </summary> internal indoor_sprites() { primaryPointer = ConstantsReader.GetAddress("rooms_sprite_pointer"); switch (RegionId.myRegion) { case (int)RegionId.Region.Japan: case (int)RegionId.Region.USA: codePointer = 0x4C296; break; case (int)RegionId.Region.German: codePointer = 0x4C2BE; break; default: throw new NotImplementedException(); } updatePointers(); }
public void loadHeader() { //address of the room header int headerPointer = (ROM.DATA[ConstantsReader.GetAddress("room_header_pointer") + 2] << 16) + (ROM.DATA[ConstantsReader.GetAddress("room_header_pointer") + 1] << 8) + (ROM.DATA[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 indoor_chests() : base(3) { primaryPointer_location = new int[] { ConstantsReader.GetAddress("chests_data_pointer1"), ConstantsReader.GetAddress("chests_data_pointer2"), ConstantsReader.GetAddress("chests_data_pointer3"), }; addressOfTotalMax = ConstantsReader.GetAddress("chests_length_pointer"); byte[] b = ROM.Read(addressOfTotalMax, 2); totalMax = Conversion.toUShort(b[1], b[0]); if (totalMax % numberOfPointers != 0) { throw new Exception(); } refreshPointer3Bytes(); readAllChests(); }
public void loadChests(ref List <ChestData> chests_in_room) { int cpos = (ROM.DATA[ConstantsReader.GetAddress("chests_data_pointer1") + 2] << 16) + (ROM.DATA[ConstantsReader.GetAddress("chests_data_pointer1") + 1] << 8) + (ROM.DATA[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 AssembleMap16Tiles(bool fromJson = false) { if (!fromJson) { int tpos = ConstantsReader.GetAddress("map16Tiles"); for (int i = 0; i < 3760; i += 1) { Tile8 t0 = new Tile8(BitConverter.ToInt16(ROM.DATA, (tpos))); tpos += 2; Tile8 t1 = new Tile8(BitConverter.ToInt16(ROM.DATA, (tpos))); tpos += 2; Tile8 t2 = new Tile8(BitConverter.ToInt16(ROM.DATA, (tpos))); tpos += 2; Tile8 t3 = new Tile8(BitConverter.ToInt16(ROM.DATA, (tpos))); tpos += 2; tiles16.Add(new Tile16(t0, t1, t2, t3)); } } else { tiles16 = JsonConvert.DeserializeObject <Tile16[]>(File.ReadAllText("ProjectDirectory//Overworld//Tiles16.json")).ToList(); } }
static List<int> getConstants(MethodDefinition method) { var list = new List<int>(); if (method == null) return list; int index = 0; var instrs = method.Body.Instructions; var constantsReader = new ConstantsReader(method); while (true) { int val; if (!constantsReader.getNextInt32(ref index, out val)) break; if (index < instrs.Count && instrs[index].OpCode.Code != Code.Ret) list.Add(val); } return list; }
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; } } }
byte[] DecryptResource_v18_r75367_dynamic(byte[] encrypted) { int ldlocIndex; var local = GetDynamicLocal(out ldlocIndex); if (local == null) throw new ApplicationException("Could not find local"); var instrs = installMethod.Body.Instructions; int startIndex = GetDynamicStartIndex(instrs, ldlocIndex); int endIndex = GetDynamicEndIndex(startIndex, local); if (endIndex < 0) throw new ApplicationException("Could not find endIndex"); var constReader = new ConstantsReader(installMethod); return DecryptResource(encrypted, magic => { constReader.SetConstantInt32(local, magic); int index = startIndex, result; if (!constReader.GetNextInt32(ref index, out result)) throw new ApplicationException("Could not get constant"); if (index != endIndex) throw new ApplicationException("Wrong constant"); return (byte)result; }); }
protected byte[] DecryptConstant_v17_r73740_dynamic(DecrypterInfo info, byte[] encrypted, uint offs, uint key1, byte[] key2) { var local = GetDynamicLocal_v17_r73740(info.decryptMethod); if (local == null) throw new ApplicationException("Could not find local"); int endIndex = GetDynamicEndIndex_v17_r73740(info.decryptMethod, local); if (endIndex < 0) endIndex = GetDynamicEndIndex_v17_r74788(info.decryptMethod, local); int startIndex = GetDynamicStartIndex_v17_r73740(info.decryptMethod, endIndex); if (startIndex < 0) throw new ApplicationException("Could not find start/end index"); var constReader = new ConstantsReader(info.decryptMethod); return Decrypt(encrypted, key1, (magic, i) => { constReader.SetConstantInt32(local, magic); int index = startIndex, result; if (!constReader.GetNextInt32(ref index, out result) || index != endIndex) throw new ApplicationException("Could not decrypt integer"); return (byte)(result ^ key2[i % key2.Length]); }); }