Exemple #1
0
        /// <summary>
        /// Testing changes to CARD_Named.bin
        /// </summary>
        private static void TestModifyCardNamedBin(GameVersion version)
        {
            LotdArchive archive = new LotdArchive(version);

            archive.WriteAccess = true;
            archive.Load();

            Dictionary <CardNameType, List <short> > cardNameTypes = new Dictionary <CardNameType, List <short> >();

            BinaryWriter writer = new BinaryWriter(archive.Reader.BaseStream, Encoding.Default, true);
            LotdFile     file   = archive.Root.FindFile("bin/CARD_Named.bin");

            /*foreach (byte b in file.LoadBuffer())
             * {
             *  Console.Write(b.ToString("X2") + " ");
             * }*/
            using (BinaryReader reader = new BinaryReader(new MemoryStream(file.LoadBuffer())))
            {
                ushort numArchetypes = reader.ReadUInt16();
                ushort numCards      = reader.ReadUInt16();

                long cardsStartOffset = 4 + (numArchetypes * 4);
                long cardsEndOffset   = cardsStartOffset + (numCards * 2);
                System.Diagnostics.Debug.Assert(reader.BaseStream.Length == cardsEndOffset);

                for (int i = 0; i < numArchetypes; i++)
                {
                    int          offset = reader.ReadInt16(); // The offset of the cards for this named group (starts at 0)
                    int          count  = reader.ReadInt16(); // The number of cards for this named group
                    List <short> cardIds;
                    if (!cardNameTypes.TryGetValue((CardNameType)i, out cardIds))
                    {
                        cardNameTypes.Add((CardNameType)i, cardIds = new List <short>());
                    }

                    long tempOffset = reader.BaseStream.Position;
                    reader.BaseStream.Position = cardsStartOffset + (offset * 2);
                    for (int j = 0; j < count; j++)
                    {
                        short cardId = reader.ReadInt16();
                        cardIds.Add(cardId);
                    }
                    reader.BaseStream.Position = tempOffset;
                }
            }

            int totalCards  = 0;
            int cardsOffset = 0;

            foreach (KeyValuePair <CardNameType, List <short> > cards in cardNameTypes)
            {
                totalCards += cards.Value.Count;
            }

            writer.BaseStream.Position = file.ArchiveOffset;
            writer.Write((ushort)cardNameTypes.Count);
            writer.Write((ushort)totalCards);// total num cards
            foreach (KeyValuePair <CardNameType, List <short> > cards in cardNameTypes)
            {
                writer.Write((ushort)cardsOffset);       // The offset of the cards for this named group (starts at 0)
                writer.Write((ushort)cards.Value.Count); // The number of cards for this named group
                cardsOffset += cards.Value.Count;
            }
            foreach (KeyValuePair <CardNameType, List <short> > cards in cardNameTypes)
            {
                if (cards.Key == CardNameType.UA)
                {
                    //cards.Value.Remove(11637);
                    cards.Value.Add(11641);
                    cards.Value.Sort();
                }

                //bool first = true;
                foreach (short cardId in cards.Value)                 //.OrderBy(x => x))
                {
                    if ((cards.Key == CardNameType.UA /* && first*/)) // || cards.Key > CardNameType.PendDragon)
                    {
                        /*if (cardId == 11637)//(cards.Key == CardNameType.UA && first))
                         * {
                         *  Console.WriteLine(cardId);
                         *  writer.Write((short)5380);
                         * }
                         * else*/
                        {
                            writer.Write(cardId);
                        }
                    }
                    else
                    {
                        writer.Write(cardId);
                    }
                    //first = false;
                }
            }
            writer.Close();

            System.Diagnostics.Debugger.Break();
        }