public void Load(bool forceReadIncompatibleVersion)
        {
            using (var reader = new BinaryReader(new FileStream(UserFilePath, FileMode.Open, FileAccess.Read)))
            {
                var version = reader.ReadUInt32();
                if (version != 0x0C && !forceReadIncompatibleVersion)
                {
                    throw new IncompatibleVersionException();
                }
                Level.Read(reader);
                moneyOver10 = reader.ReadInt32();
                NumTimesAdventureModeCompleted = reader.ReadInt32();

                IOUtils.ReadInt32Array(reader, SurvivalModeFlags);
                IOUtils.ReadUInt32Array(reader, unknown1);
                StreakLengthEndlessSurvival = reader.ReadInt32();

                IOUtils.ReadUInt32Array(reader, unknown2);

                IOUtils.ReadBoolPreserveNonzeroArray(reader, HasMinigameTrophy, 4);
                IOUtils.ReadUInt32Array(reader, unknown3);
                TreeOfWisdomHeight = reader.ReadInt32();
                IOUtils.ReadBoolPreserveNonzeroArray(reader, HasVaseBreakerTrophy, 4);
                StreakLengthVaseBreakerEndless = reader.ReadInt32();
                IOUtils.ReadBoolPreserveNonzeroArray(reader, HasIZombieTrophy, 4);
                StreakLengthIZombieEndless = reader.ReadInt32();

                IOUtils.ReadUInt32Array(reader, unknown4);

                IOUtils.ReadBoolPreserveNonzeroArray(reader, HasShopPlant, 4);
                unknown5 = reader.ReadUInt32();
                for (int i=0; i < MarigoldLastPurchased.Length; i++)
                {
                    MarigoldLastPurchased[i] = IOUtils.ReadDaysSince2000(reader);
                }
                HasGoldenWateringCan = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                FertilizerAmount = IOUtils.ReadInt32Offset(reader, 1000);
                BugSprayAmount = IOUtils.ReadInt32Offset(reader, 1000);
                HasPhonograph = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                HasGardeningGlove = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                HasMushroomGarden = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                HasWheelbarrow = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                StinkyLastAwokenTime = IOUtils.ReadUnixTimestamp(reader);
                NumberSlots = reader.ReadInt32() + 6;
                HasPoolCleaners = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                HasRoofCleaners = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                RakeUses = reader.ReadUInt32();
                HasAquariumGarden = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                ChocolateAmount = IOUtils.ReadInt32Offset(reader, 1000);
                TreeOfWisdomAvailable = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                TreeFoodAmount = IOUtils.ReadInt32Offset(reader, 1000);
                HasWallNutFirstAid = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                IOUtils.ReadUInt32Array(reader, unknown6);
                unknown7 = reader.ReadUInt32();
                StinkyLastChocolateTime = IOUtils.ReadUnixTimestamp(reader);
                StinkyXPosition = reader.ReadInt32();
                StinkyYPosition = reader.ReadInt32();
                MiniGamesUnlocked = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                PuzzleModeUnlocked = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                AnimateUnlockMiniGame = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                AnimateUnlockVasebreaker = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                AnimateUnlockIZombie = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                AnimateUnlockSurvival = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                unknown8 = reader.ReadUInt32();
                ShowAdventureCompleteDialog = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                HasTaco = IOUtils.ReadBoolPreserveNonzero(reader, 4);

                IOUtils.ReadUInt32Array(reader, unknown9);

                var numZenGardenPlants = reader.ReadUInt32();
                ZenGardenPlants = new ZenGardenPlant[numZenGardenPlants];
                for (int i = 0; i < ZenGardenPlants.Length; i++)
                {
                    ZenGardenPlants[i] = new ZenGardenPlant();
                    ZenGardenPlants[i].Load(reader);
                }

                IOUtils.ReadBoolPreserveNonzeroArray(reader, HasAchievement, 2);

                AcceptedZombatarLicenseAgreement = IOUtils.ReadBoolPreserveNonzero(reader, 1);
                var numZombatars = reader.ReadUInt32();
                Zombatars = new Zombatar[numZombatars];
                for (int i = 0; i < Zombatars.Length; i++)
                {
                    Zombatars[i] = new Zombatar();
                    Zombatars[i].Load(reader);
                }

                IOUtils.ReadUInt32Array(reader, unknown10);

                HaveCreatedZombatar = IOUtils.ReadBoolPreserveNonzero(reader, 1);

                // Read all trailing data into a buffer - if we're dealing with an incompatible version this might let us succeed
                // Warning: this might allocate a lot of memory if the file is huge for some reason
                trailingData = reader.ReadBytes((int)new FileInfo(UserFilePath).Length);
            }
        }
Пример #2
0
        public void Load(bool forceReadIncompatibleVersion)
        {
            using (var reader = new BinaryReader(new FileStream(UserFilePath, FileMode.Open, FileAccess.Read)))
            {
                var version = reader.ReadUInt32();
                if (version != 0x0C && !forceReadIncompatibleVersion)
                {
                    throw new IncompatibleVersionException();
                }
                Level.Read(reader);
                moneyOver10 = reader.ReadInt32();
                NumTimesAdventureModeCompleted = reader.ReadInt32();

                IOUtils.ReadInt32Array(reader, SurvivalModeFlags);
                IOUtils.ReadUInt32Array(reader, unknown1);
                StreakLengthEndlessSurvival = reader.ReadInt32();

                IOUtils.ReadUInt32Array(reader, unknown2);

                IOUtils.ReadBoolPreserveNonzeroArray(reader, HasMinigameTrophy, 4);
                IOUtils.ReadUInt32Array(reader, unknown3);
                TreeOfWisdomHeight = reader.ReadInt32();
                IOUtils.ReadBoolPreserveNonzeroArray(reader, HasVaseBreakerTrophy, 4);
                StreakLengthVaseBreakerEndless = reader.ReadInt32();
                IOUtils.ReadBoolPreserveNonzeroArray(reader, HasIZombieTrophy, 4);
                StreakLengthIZombieEndless = reader.ReadInt32();

                IOUtils.ReadUInt32Array(reader, unknown4);

                IOUtils.ReadBoolPreserveNonzeroArray(reader, HasShopPlant, 4);
                unknown5 = reader.ReadUInt32();
                for (int i = 0; i < MarigoldLastPurchased.Length; i++)
                {
                    MarigoldLastPurchased[i] = IOUtils.ReadDaysSince2000(reader);
                }
                HasGoldenWateringCan  = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                FertilizerAmount      = IOUtils.ReadInt32Offset(reader, 1000);
                BugSprayAmount        = IOUtils.ReadInt32Offset(reader, 1000);
                HasPhonograph         = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                HasGardeningGlove     = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                HasMushroomGarden     = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                HasWheelbarrow        = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                StinkyLastAwokenTime  = IOUtils.ReadUnixTimestamp(reader);
                NumberSlots           = reader.ReadInt32() + 6;
                HasPoolCleaners       = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                HasRoofCleaners       = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                RakeUses              = reader.ReadUInt32();
                HasAquariumGarden     = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                ChocolateAmount       = IOUtils.ReadInt32Offset(reader, 1000);
                TreeOfWisdomAvailable = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                TreeFoodAmount        = IOUtils.ReadInt32Offset(reader, 1000);
                HasWallNutFirstAid    = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                IOUtils.ReadUInt32Array(reader, unknown6);
                unknown7 = reader.ReadUInt32();
                StinkyLastChocolateTime  = IOUtils.ReadUnixTimestamp(reader);
                StinkyXPosition          = reader.ReadInt32();
                StinkyYPosition          = reader.ReadInt32();
                MiniGamesUnlocked        = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                PuzzleModeUnlocked       = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                AnimateUnlockMiniGame    = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                AnimateUnlockVasebreaker = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                AnimateUnlockIZombie     = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                AnimateUnlockSurvival    = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                unknown8 = reader.ReadUInt32();
                ShowAdventureCompleteDialog = IOUtils.ReadBoolPreserveNonzero(reader, 4);
                HasTaco = IOUtils.ReadBoolPreserveNonzero(reader, 4);

                IOUtils.ReadUInt32Array(reader, unknown9);

                var numZenGardenPlants = reader.ReadUInt32();
                ZenGardenPlants = new ZenGardenPlant[numZenGardenPlants];
                for (int i = 0; i < ZenGardenPlants.Length; i++)
                {
                    ZenGardenPlants[i] = new ZenGardenPlant();
                    ZenGardenPlants[i].Load(reader);
                }

                IOUtils.ReadBoolPreserveNonzeroArray(reader, HasAchievement, 2);

                AcceptedZombatarLicenseAgreement = IOUtils.ReadBoolPreserveNonzero(reader, 1);
                var numZombatars = reader.ReadUInt32();
                Zombatars = new Zombatar[numZombatars];
                for (int i = 0; i < Zombatars.Length; i++)
                {
                    Zombatars[i] = new Zombatar();
                    Zombatars[i].Load(reader);
                }

                IOUtils.ReadUInt32Array(reader, unknown10);

                HaveCreatedZombatar = IOUtils.ReadBoolPreserveNonzero(reader, 1);

                // Read all trailing data into a buffer - if we're dealing with an incompatible version this might let us succeed
                // Warning: this might allocate a lot of memory if the file is huge for some reason
                trailingData = reader.ReadBytes((int)new FileInfo(UserFilePath).Length);
            }
        }