Beispiel #1
0
        private List <Shop> GetShops(ShopType shopType)
        {
            var shops = new List <Shop>();

            for (int i = 0; i < ShopSectionSize; i++)
            {
                if (Index.Data[(int)shopType + i] != ShopNullPointer)
                {
                    var prototype = ShopPrototypes[(int)shopType + i];

                    if (shopType == ShopType.Clinic || shopType == ShopType.Inn)
                    {
                        ushort price = rom.Get(ShopPointerBase + Index.Data[(int)shopType + i], 2).ToUShorts()[0];
                        shops.Add(new Shop(prototype.Index, prototype.Type, prototype.Location, prototype.MapId, prototype.TileId, prototype.Name, price));
                    }
                    else
                    {
                        var entries     = new List <byte>();
                        var shopEntries = rom.Get(ShopPointerBase + Index.Data[(int)shopType + i], 5);

                        for (int j = 0; j < 5 && shopEntries[j] != 0; j++)
                        {
                            entries.Add(shopEntries[j]);
                        }

                        shops.Add(new Shop(prototype.Index, prototype.Type, prototype.Location, prototype.MapId, prototype.TileId, prototype.Name, entries.Where(e => e != 0).Cast <Item>().ToList()));
                    }
                }
            }

            return(shops);
        }
Beispiel #2
0
        private SCCoords LoadCoords(int address)
        {
            byte[] data = rom.Get(address, 2);
            var    X    = (((int)data[0] + 7) & 0xFF);
            var    Y    = (((int)data[1] + 7) & 0xFF);

            return(new SCCoords(X, Y));
        }
        public string TranslateItem(Item item)
        {
            switch (item)
            {
            case Item.Ship: return(FF1Text.BytesToText(rom.Get(0x2B5D0, 4)));

            case Item.Bridge: return(FF1Text.BytesToText(rom.Get(0x2B5D0 + 16, 6)));

            case Item.Canal: return(FF1Text.BytesToText(rom.Get(0x2B5D0 + 24, 5)));

            case Item.Canoe: return(FF1Text.BytesToText(rom.Get(0x2B5D0 + 36, 5)));

            default: return(itemnames[(int)item].Replace(" ", ""));
            }
        }
        private void WriteV2SpoilerArea(Sanity.SCArea a, string tab, int depth)
        {
            Utilities.WriteSpoilerLine(tab + a.Map.MapId.ToString());

            //if (a.Map.MapId == MapId.TempleOfFiends && depth < 15) throw new RerollException();

            foreach (var p in a.PointsOfInterest)
            {
                switch (p.Type)
                {
                case Sanity.SCPointOfInterestType.Orb:
                    Utilities.WriteSpoilerLine(tab + " - " + a.Map.MapId.ToString() + " - " + p.Type.ToString() + " - " + p.BitFlagSet);
                    break;

                case Sanity.SCPointOfInterestType.Shop:
                    var shop = shopData.Shops.First(x => x.Index == p.ShopId - 1);
                    Utilities.WriteSpoilerLine(tab + " - " + a.Map.MapId.ToString() + " - " + p.Type.ToString() + " - " + shop.Type + "." + shop.Location + "." + p.ShopId.ToString() + " - " + p.BitFlagSet);
                    break;

                case Sanity.SCPointOfInterestType.Treasure:
                    var item = (Item)rom.Get(0x3100 + p.TreasureId, 1)[0];
                    Utilities.WriteSpoilerLine(tab + " - " + a.Map.MapId.ToString() + " - " + p.Type.ToString() + " - " + GetItemName(item) + " - " + p.BitFlagSet);
                    break;
                }
            }

            foreach (var a2 in a.ChildAreas)
            {
                WriteV2SpoilerArea(a2, tab + "\t", depth + 1);
            }
        }
        public void LoadTable()
        {
            Data = new T[count];

            byte[] buffer = rom.Get(address, count * Marshal.SizeOf <T>());

            Buffer.BlockCopy(buffer, 0, Data, 0, buffer.Length);
        }
Beispiel #6
0
        public List <List <byte> > GetCompressedMapRows()
        {
            var pointers = _rom.Get(bankStart, 512).ToUShorts().Select(x => x - bankStart);
            var mapRows  = pointers.Select(x =>
            {
                var mapRow = _rom.Get(x, 256).ToBytes();
                var result = new List <byte>();
                var index  = 0;
                while (index < 256 && mapRow[index] != 255)
                {
                    result.Add(mapRow[index]);
                    index++;
                }
                result.Add(mapRow[index]);
                return(result);
            }).ToList();

            return(mapRows);
        }
Beispiel #7
0
        public unsafe void LoadTable()
        {
            Data = new T[count];

            byte[] buffer = rom.Get(address, count * sizeof(T));

            fixed(byte *p = buffer)
            {
                T *pBuffer = (T *)p;

                for (int i = 0; i < count; i++)
                {
                    Data[i] = pBuffer[i];
                }
            }
        }
        public void BuildProgressiveExpChests(ChestXPType progressiveChestXPType)
        {
            //In progress
            rom.PutInBank(0x1F, 0xDDD0, Blob.FromHex("A9B648A9FF48A9114C03FE8A20DA8760"));
            rom.PutInBank(0x11, 0xB514, Blob.FromHex("A200A000BD00622904F01BA9B548A93248A91148A9BF48A98F48A9004C03FEA510C97B9001C8E8D0DB98C93F9002A93FAABD00B9856120B9EC60"));
            //JSR to this new function instead of directly to load price
            rom.PutInBank(0x11, 0xB44A, Blob.FromHex("2014B5"));
            //add the item lookup function to Bank 00
            rom.PutInBank(0x00, 0xBF90, Blob.FromHex("BD00B18510684C03FE60"));

            int expChestCountPercent = rng.Between(flags.ExpChestConversionMin, flags.ExpChestConversionMax);
            int expChestCount        = treasureData.Data.Where(g => g >= Item.Gold10).Count() * expChestCountPercent / 100;

            if (expChestCount == 0)
            {
                return;
            }

            LoadData();

            var unusedGoldDic = new HashSet <int>(rom.UnusedGoldItems.Cast <int>());

            // construct a dictionary and get a shuffled index into it.
            var goldItems = ItemLists.AllGoldTreasure.Select(g => (item: g, price: itemPrices[g], name: itemNames[(int)g])).ToList();

            goldItems.Shuffle(rng);
            var goldItemsDic = goldItems.Select((g, i) => (shuffleindex: i, item: g.item, price: g.price, name: g.name)).ToDictionary(g => g.item);

            var expItems = new HashSet <Item>(treasureData.Data
                                              .Where(g => goldItemsDic.ContainsKey(g) && !unusedGoldDic.Contains((int)g))
                                              .Select(g => (item: g, shuffleindex: goldItemsDic[g].shuffleindex))
                                              .OrderBy(g => g.shuffleindex)
                                              .Take(expChestCount)
                                              .Select(g => g.item)
                                              .Distinct());

            var firstExpItem = RepackGoldExpItems(goldItemsDic, expItems, unusedGoldDic);

            List <(ushort, int)> expChests = new List <(ushort, int)>();
            int currentChestIndex          = 0;

            for (int i = (int)firstExpItem; i < 176; i++)
            {
                if (unusedGoldDic.Contains(i))
                {
                    continue;
                }
                var e = (Item)i;

                if (progressiveChestXPType == ChestXPType.RandomProgressive)
                {
                    var exp = (ushort)rng.Between(flags.ExpChestMinReward, flags.ExpChestMaxReward);
                    itemPrices[e]     = exp;
                    itemNames[(int)e] = exp.ToString() + " EXP";
                    expChests.Add((exp, i));
                }
                else if (progressiveChestXPType == ChestXPType.LinearProgressive)
                {
                    int    expChestsTotal  = expItems.Count();
                    double maxXpIndex      = Math.Max((expChestsTotal * 0.80), 1.0);
                    double chestMultiplier = (flags.ExpChestMaxReward - flags.ExpChestMinReward) / maxXpIndex;
                    ushort exp             = Math.Min((ushort)(currentChestIndex * chestMultiplier + flags.ExpChestMinReward), (ushort)flags.ExpChestMaxReward);
                    itemPrices[e]     = exp;
                    itemNames[(int)e] = exp.ToString() + " EXP";
                    expChests.Add((exp, i));
                }
                else if (progressiveChestXPType == ChestXPType.ExponentialProgressive)
                {
                    int    expChestsTotal  = expItems.Count();
                    double maxXpIndex      = Math.Max((expChestsTotal * 0.80), 1.0);
                    double chestMultiplier = (flags.ExpChestMaxReward - flags.ExpChestMinReward) / (maxXpIndex * maxXpIndex);
                    ushort exp             = Math.Min((ushort)(currentChestIndex * currentChestIndex * chestMultiplier + flags.ExpChestMinReward), (ushort)flags.ExpChestMaxReward);
                    itemPrices[e]     = exp;
                    itemNames[(int)e] = exp.ToString() + " EXP";
                    expChests.Add((exp, i));
                }

                currentChestIndex++;
            }

            //sort ascending
            expChests.Sort((x, y) => x.Item1.CompareTo(y.Item1));
            currentChestIndex = 0;
            byte[] treasurePlacementData = rom.Get(FF1Rom.TreasureOffset, FF1Rom.TreasureCount);
            for (int i = 0; i < expChests.Count; i++)
            {
                //find out how many of these chests exist, there could be more than one of each, put them in order
                //for(int j = 0; j < treasurePlacementData.Where(x => x == expChests[i].Item2).Count(); j++)
                //{
                //	rom.PutInBank(0x11, 0xB900 + currentChestIndex, new byte[] { (byte)expChests[i].Item2 });
                //	currentChestIndex++;
                //	currentChestIndex = Math.Min(currentChestIndex, 63);
                //}

                rom.PutInBank(0x11, 0xB900 + currentChestIndex, new byte[] { (byte)expChests[i].Item2 });
                currentChestIndex++;
                rom.PutInBank(0x11, 0xB900 + currentChestIndex, new byte[] { (byte)expChests[i].Item2 });
                currentChestIndex++;
            }

            //fill out the rest of the table
            for (; currentChestIndex < 64; currentChestIndex++)
            {
                rom.PutInBank(0x11, 0xB900 + currentChestIndex, new byte[] { (byte)expChests.Last().Item2 });
            }

            FirstExpItem = firstExpItem;
            if (flags.Archipelago)
            {
                rom.PutInBank(0x11, 0xB446, new byte[] { (byte)firstExpItem });
            }
            else
            {
                rom.PutInBank(0x11, 0xB447, new byte[] { (byte)firstExpItem });
            }

            //put the comparision in the chest counter
            rom.PutInBank(0x11, 0xB536, new byte[] { (byte)firstExpItem });

            var result = treasureData.Data.Where(x => x > Item.Gold10).OrderBy(x => x).Select(x => itemNames[(int)x]).ToList();

            StoreData();
        }
Beispiel #9
0
 public void LoadTable()
 {
     Table = rom.Get(address, count).Chunk(size);
 }