Exemplo n.º 1
0
        public static int ByteswapROM(string filename)
        {
            using (BinaryReader ROM = new BinaryReader(File.Open(filename, FileMode.Open)))
            {
                if (ROM.BaseStream.Length % 4 != 0)
                {
                    return(-1);
                }

                byte[] buffer = new byte[4];
                ROM.Read(buffer, 0, 4);
                // very hacky
                ROM.BaseStream.Seek(0, 0);
                if (buffer[0] == 0x80)
                {
                    return(1);
                }
                else if (buffer[1] == 0x80)
                {
                    using (BinaryWriter newROM = new BinaryWriter(File.Open(filename + ".z64", FileMode.Create)))
                    {
                        while (ROM.BaseStream.Position < ROM.BaseStream.Length)
                        {
                            newROM.Write(ReadWriteUtils.Byteswap16(ReadWriteUtils.ReadU16(ROM)));
                        }
                    }
                    return(0);
                }
                else if (buffer[3] == 0x80)
                {
                    using (BinaryWriter newROM = new BinaryWriter(File.Open(filename + ".z64", FileMode.Create)))
                    {
                        while (ROM.BaseStream.Position < ROM.BaseStream.Length)
                        {
                            newROM.Write(ReadWriteUtils.Byteswap32(ReadWriteUtils.ReadU32(ROM)));
                        }
                    }
                    return(0);
                }
            }
            return(-1);
        }
Exemplo n.º 2
0
        private static void UpdateShop(Item location, Item item, List <MessageEntry> newMessages)
        {
            var newItem = RomData.GetItemList[item.GetItemIndex().Value];

            var shopRooms = location.GetAttributes <ShopRoomAttribute>();

            foreach (var shopRoom in shopRooms)
            {
                ReadWriteUtils.WriteToROM(shopRoom.RoomObjectAddress, (ushort)newItem.Object);
            }

            var shopInventories = location.GetAttributes <ShopInventoryAttribute>();

            foreach (var shopInventory in shopInventories)
            {
                ReadWriteUtils.WriteToROM(shopInventory.ShopItemAddress, (ushort)newItem.Object);
                var index = newItem.Index > 0x7F ? (byte)(0xFF - newItem.Index) : (byte)(newItem.Index - 1);
                ReadWriteUtils.WriteToROM(shopInventory.ShopItemAddress + 0x03, index);

                var    shopTexts = item.ShopTexts();
                string description;
                switch (shopInventory.Keeper)
                {
                case ShopInventoryAttribute.ShopKeeper.WitchShop:
                    description = shopTexts.WitchShop;
                    break;

                case ShopInventoryAttribute.ShopKeeper.TradingPostMain:
                    description = shopTexts.TradingPostMain;
                    break;

                case ShopInventoryAttribute.ShopKeeper.TradingPostPartTimer:
                    description = shopTexts.TradingPostPartTimer;
                    break;

                case ShopInventoryAttribute.ShopKeeper.CuriosityShop:
                    description = shopTexts.CuriosityShop;
                    break;

                case ShopInventoryAttribute.ShopKeeper.BombShop:
                    description = shopTexts.BombShop;
                    break;

                case ShopInventoryAttribute.ShopKeeper.ZoraShop:
                    description = shopTexts.ZoraShop;
                    break;

                case ShopInventoryAttribute.ShopKeeper.GoronShop:
                    description = shopTexts.GoronShop;
                    break;

                case ShopInventoryAttribute.ShopKeeper.GoronShopSpring:
                    description = shopTexts.GoronShopSpring;
                    break;

                default:
                    description = null;
                    break;
                }
                if (description == null)
                {
                    description = shopTexts.Default;
                }

                var messageId = ReadWriteUtils.ReadU16(shopInventory.ShopItemAddress + 0x0A);
                newMessages.Add(new MessageEntry
                {
                    Id      = messageId,
                    Header  = null,
                    Message = MessageUtils.BuildShopDescriptionMessage(item.Name(), 20, description)
                });

                newMessages.Add(new MessageEntry
                {
                    Id      = (ushort)(messageId + 1),
                    Header  = null,
                    Message = MessageUtils.BuildShopPurchaseMessage(item.Name(), 20, item.ShopTexts()?.IsMultiple ?? false)
                });
            }
        }