public static Savegame ReadNew(BinaryReader r) { Savegame sg = new Savegame(); sg.version = ZZVersion.ReadNew(r); sg.name = r.ReadZString(); sg.secondsPlayed = r.ReadInt32(); sg.progress = r.ReadInt32(); if (r.ReadUInt32() != LocationBlockSize) { throw new InvalidDataException("Invalid size of savegame location block"); } sg.sceneId = r.ReadInt32(); sg.entryId = r.ReadInt32(); var sceneCount = r.ReadUInt32(); sg.gameState.EnsureCapacity((int)sceneCount); for (uint i = 0; i < sceneCount; i++) { var sceneName = r.ReadZString(); var modCount = r.ReadInt32(); var mods = new List <IGameStateMod>(modCount); for (int j = 0; j < modCount; j++) { mods.Add(IGameStateMod.ReadNew(r)); } sg.gameState[sceneName] = mods; } var itemCount = r.ReadUInt32(); sg.inventory.EnsureCapacity((int)itemCount); for (uint i = 0; i < itemCount; i++) { sg.inventory.Add(InventoryCard.ReadNew(r)); } sg.pixiesHolding = r.ReadUInt32(); sg.pixiesCatched = r.ReadUInt32(); if (r.ReadInt32() != GlobalVar.Count) { throw new InvalidDataException("Invalid global variable count"); } for (int i = 0; i < sg.globalVars.Length; i++) { sg.globalVars[i] = GlobalVar.ReadNew(r); } sg.switchGameMinMoves = r.ReadUInt32(); return(sg); }
public static InventoryCard ReadNew(BinaryReader r) { var cardId = new CardId(r.ReadUInt32()); InventoryCard card = cardId.Type switch { CardType.Item => new InventoryItem(), CardType.Spell => new InventorySpell(), CardType.Fairy => new InventoryFairy(), _ => throw new InvalidDataException($"Invalid inventory card type: {cardId.Type}") }; card.cardId = cardId; card.atIndex = r.ReadUInt32(); card.dbUID = UID.ReadNew(r); card.amount = r.ReadUInt32(); card.isInUse = r.ReadBoolean(); card.ReadSub(r); return(card); }