/// <summary>Registers the item into it's registry</summary>
        public override OtherItem Register()
        {
            Build();

            MailRegistry.RegisterMailEntry(MailEntry);

            return(this);
        }
Example #2
0
        public static HashSet <SRMod> FindAllModsWithData(PlayerV14 player)
        {
            var mods = new HashSet <SRMod>();

            player.upgrades.ForEach((x) => mods.Add(ModdedIDRegistry.ModForID(x)));
            player.availUpgrades.ForEach((x) => mods.Add(ModdedIDRegistry.ModForID(x)));
            foreach (var x in player.upgradeLocks)
            {
                mods.Add(ModdedIDRegistry.ModForID(x.Key));
            }

            foreach (var x in player.progress)
            {
                mods.Add(ModdedIDRegistry.ModForID(x.Key));
            }
            foreach (var x in player.delayedProgress)
            {
                mods.Add(ModdedIDRegistry.ModForID(x.Key));
            }

            player.blueprints.ForEach((x) => mods.Add(ModdedIDRegistry.ModForID(x)));
            player.availBlueprints.ForEach((x) => mods.Add(ModdedIDRegistry.ModForID(x)));
            foreach (var x in player.blueprintLocks)
            {
                mods.Add(ModdedIDRegistry.ModForID(x.Key));
            }

            foreach (var x in player.gadgets)
            {
                mods.Add(ModdedIDRegistry.ModForID(x.Key));
            }

            foreach (var x in player.craftMatCounts)
            {
                mods.Add(ModdedIDRegistry.ModForID(x.Key));
            }

            player.mail.ForEach((x) => mods.Add(MailRegistry.GetModForMail(x.messageKey)));

            player.unlockedZoneMaps.ForEach((x) => mods.Add(ModdedIDRegistry.ModForID(x)));

            mods.Remove(null);
            return(mods);
        }
Example #3
0
        public void Push(PlayerV14 player)
        {
            player.upgrades.AddRange(upgrades.Where((x) => ModdedIDRegistry.IsValidID(x)));
            player.availUpgrades.AddRange(availUpgrades.Where((x) => ModdedIDRegistry.IsValidID(x)));
            AddRange(player.upgradeLocks, upgradeLocks.Where((x) => ModdedIDRegistry.IsValidID(x.Key)));

            AddRange(player.progress, progress.Where((x) => ModdedIDRegistry.IsValidID(x.Key)));
            AddRange(player.delayedProgress, delayedProgress.Where((x) => ModdedIDRegistry.IsValidID(x.Key)));

            player.blueprints.AddRange(blueprints.Where((x) => ModdedIDRegistry.IsValidID(x)));
            player.availBlueprints.AddRange(availBlueprints.Where((x) => ModdedIDRegistry.IsValidID(x)));
            AddRange(player.blueprintLocks, blueprintLocks.Where((x) => ModdedIDRegistry.IsValidID(x.Key)));

            AddRange(player.gadgets, gadgets.Where((x) => ModdedIDRegistry.IsValidID(x.Key)));

            AddRange(player.craftMatCounts, craftMatCounts.Where((x) => ModdedIDRegistry.IsValidID(x.Key)));
            player.unlockedZoneMaps.AddRange(unlockedZoneMaps.Where((x) => ModdedIDRegistry.IsValidID(unlockedZoneMaps)));
            player.mail.AddRange(mail.Where((x) => MailRegistry.GetModForMail(x.messageKey) != null));
        }
Example #4
0
        public void Pull(PlayerV14 player, SRMod ourMod)
        {
            upgrades.AddRange(player.upgrades.Where((x) => ModdedIDRegistry.ModForID(x) == ourMod));
            availUpgrades.AddRange(player.availUpgrades.Where((x) => ModdedIDRegistry.ModForID(x) == ourMod));
            AddRange(upgradeLocks, player.upgradeLocks.Where((x) => ModdedIDRegistry.ModForID(x.Key) == ourMod));

            AddRange(progress, player.progress.Where((x) => ModdedIDRegistry.ModForID(x.Key) == ourMod));
            AddRange(delayedProgress, player.delayedProgress.Where((x) => ModdedIDRegistry.ModForID(x.Key) == ourMod));

            blueprints.AddRange(player.blueprints.Where((x) => ModdedIDRegistry.ModForID(x) == ourMod));
            availBlueprints.AddRange(player.availBlueprints.Where((x) => ModdedIDRegistry.ModForID(x) == ourMod));
            AddRange(blueprintLocks, player.blueprintLocks.Where((x) => ModdedIDRegistry.ModForID(x.Key) == ourMod));

            AddRange(gadgets, player.gadgets.Where((x) => ModdedIDRegistry.ModForID(x.Key) == ourMod));

            AddRange(craftMatCounts, player.craftMatCounts.Where((x) => ModdedIDRegistry.ModForID(x.Key) == ourMod));

            unlockedZoneMaps.AddRange(player.unlockedZoneMaps.Where((x) => ModdedIDRegistry.ModForID(x) == ourMod));

            mail.AddRange(player.mail.Where((x) => MailRegistry.GetModForMail(x.messageKey) == ourMod));
        }
Example #5
0
        //! Patch: SavedGame.Load
        internal static void Load(GameV12 original)
        {
            //& Merge Summary
            if (gameState.summary.iconId != Identifiable.Id.NONE && IsGuuIdentifiable(gameState.summary.iconId))
            {
                original.summary.iconId = gameState.summary.iconId;
            }

            if (gameState.summary.gameMode != PlayerState.GameMode.CLASSIC)
            {
                original.summary.gameMode = gameState.summary.gameMode;
            }

            //& Merge World
            original.world.lastOfferRancherIds.AddAll(gameState.world.lastOfferRancherIds, IsGuuID);
            original.world.pendingOfferRancherIds.AddAll(gameState.world.pendingOfferRancherIds, IsGuuID);

            if (gameState.world.weather != AmbianceDirector.Weather.NONE)
            {
                original.world.weather = gameState.world.weather;
            }

            foreach (ExchangeDirector.OfferType type in original.world.offers.Keys)
            {
                if (!gameState.world.offers.ContainsKey(type))
                {
                    continue;
                }
                ExchangeOfferV04 ori = original.world.offers[type];
                ExchangeOfferV04 mod = gameState.world.offers[type];

                ori.requests.AddAll(mod.requests, request => IsGuuIdentifiable(request.id) || ExchangeRegistry.IsNonIdenRegistered(request.nonIdentReward));
                ori.rewards.AddAll(mod.rewards, reward => IsGuuIdentifiable(reward.id) || ExchangeRegistry.IsNonIdenRegistered(reward.nonIdentReward));

                gameState.world.offers.Remove(type);
            }
            original.world.offers.AddAll(gameState.world.offers, pair => IsGuuID(pair.Value.rancherId) || IsGuuID(pair.Value.offerId) || ExchangeRegistry.IsOfferTypeRegistered(pair.Key));

            original.world.econSaturations.AddAll(gameState.world.econSaturations, IsGuuIdentifiable);
            original.world.teleportNodeActivations.AddAll(gameState.world.teleportNodeActivations, IsGuuID);
            original.world.liquidSourceUnits.AddAll(gameState.world.liquidSourceUnits, IsGuuID);

            foreach (string id in original.world.gordos.Keys)
            {
                if (!gameState.world.gordos.ContainsKey(id))
                {
                    continue;
                }
                original.world.gordos[id].fashions.AddAll(gameState.world.gordos[id].fashions, IsGuuIdentifiable);
                gameState.world.gordos.Remove(id);
            }
            original.world.gordos.AddRange(gameState.world.gordos);

            foreach (string id in original.world.placedGadgets.Keys)
            {
                if (!gameState.world.placedGadgets.ContainsKey(id))
                {
                    continue;
                }
                PlacedGadgetV08 ori = original.world.placedGadgets[id];
                PlacedGadgetV08 mod = gameState.world.placedGadgets[id];

                if (mod.gadgetId != Gadget.Id.NONE)
                {
                    ori.gadgetId = mod.gadgetId;
                }

                int i = 0;
                foreach (AmmoDataV02 ammo in mod.ammo)
                {
                    if (ammo.id != Identifiable.Id.NONE && IsGuuIdentifiable(ammo.id))
                    {
                        ori.ammo[i].id = ammo.id;
                    }
                    ori.ammo[i].emotionData.emotionData.AddRange(ammo.emotionData.emotionData);
                    i++;
                }

                if (mod.baitTypeId != Identifiable.Id.NONE && IsGuuIdentifiable(mod.baitTypeId))
                {
                    ori.baitTypeId = mod.baitTypeId;
                }
                if (mod.gordoTypeId != Identifiable.Id.NONE && IsGuuIdentifiable(mod.gordoTypeId))
                {
                    ori.gordoTypeId = mod.gordoTypeId;
                }
                ori.fashions.AddAll(mod.fashions, IsGuuIdentifiable);

                if (ori.drone != null)
                {
                    if (mod.drone.drone.ammo.id != Identifiable.Id.NONE && IsGuuIdentifiable(mod.drone.drone.ammo.id))
                    {
                        ori.drone.drone.ammo.id = mod.drone.drone.ammo.id;
                    }
                    ori.drone.drone.ammo.emotionData.emotionData.AddRange(mod.drone.drone.ammo.emotionData.emotionData);
                    ori.drone.drone.fashions.AddAll(mod.drone.drone.fashions, IsGuuIdentifiable);
                }

                gameState.world.placedGadgets.Remove(id);
            }
            original.world.placedGadgets.AddAll(gameState.world.placedGadgets, IsGuuID);

            foreach (string id in original.world.treasurePods.Keys)
            {
                if (!gameState.world.treasurePods.ContainsKey(id))
                {
                    continue;
                }
                original.world.treasurePods[id].spawnQueue.AddAll(gameState.world.treasurePods[id].spawnQueue, IsGuuIdentifiable);
                gameState.world.treasurePods.Remove(id);
            }
            original.world.treasurePods.AddRange(gameState.world.treasurePods);

            original.world.switches.AddAll(gameState.world.switches, IsGuuID);
            original.world.puzzleSlotsFilled.AddAll(gameState.world.puzzleSlotsFilled, IsGuuID);
            original.world.occupiedPhaseSites.AddAll(gameState.world.occupiedPhaseSites, IsGuuID);
            original.world.quicksilverEnergyGenerators.AddAll(gameState.world.quicksilverEnergyGenerators, IsGuuID);
            original.world.oasisStates.AddAll(gameState.world.oasisStates, IsGuuID);
            original.world.activeGingerPatches.AddAll(gameState.world.activeGingerPatches, IsGuuID);
            original.world.echoNoteGordos.AddAll(gameState.world.echoNoteGordos, IsGuuID);

            //? Slimeulation
            original.world.glitch.teleporters.AddAll(gameState.world.glitch.teleporters, IsGuuID);
            original.world.glitch.nodes.AddAll(gameState.world.glitch.nodes, IsGuuID);
            original.world.glitch.impostoDirectors.AddAll(gameState.world.glitch.impostoDirectors, IsGuuID);
            original.world.glitch.impostos.AddAll(gameState.world.glitch.impostos, IsGuuID);
            original.world.glitch.slimes.AddAll(gameState.world.glitch.slimes, IsGuuID);
            original.world.glitch.storage.AddAll(gameState.world.glitch.storage, pair => IsGuuID(pair.Key) || IsGuuIdentifiable(pair.Value.id));

            //& Merge Player
            if (gameState.player.gameMode != PlayerState.GameMode.CLASSIC)
            {
                original.player.gameMode = gameState.player.gameMode;
            }
            if (gameState.player.gameIconId != Identifiable.Id.NONE && IsGuuIdentifiable(gameState.player.gameIconId))
            {
                original.player.gameIconId = gameState.player.gameIconId;
            }

            original.player.upgrades.AddAll(gameState.player.upgrades, IsGuuUpgrade);

            foreach (PlayerState.AmmoMode mode in original.player.ammo.Keys)
            {
                if (!gameState.player.ammo.ContainsKey(mode))
                {
                    continue;
                }

                int i = 0;
                foreach (AmmoDataV02 ammo in gameState.player.ammo[mode])
                {
                    if (ammo.id != Identifiable.Id.NONE && IsGuuIdentifiable(ammo.id))
                    {
                        original.player.ammo[mode][i].id = ammo.id;
                    }
                    original.player.ammo[mode][i].emotionData.emotionData.AddRange(ammo.emotionData.emotionData);
                    i++;
                }

                gameState.player.ammo.Remove(mode);
            }
            original.player.ammo.AddAll(gameState.player.ammo, pair => AmmoRegistry.IsAmmoModeRegistered(pair.Key));

            foreach (MailV02 mail in original.player.mail)
            {
                MailV02 mod = gameState.player.mail.Find(m => m.messageKey.Equals(mail.messageKey));
                if (mod != null)
                {
                    continue;
                }

                if (!mod.messageKey.Equals(string.Empty) && MailRegistry.IsMailRegistered(mod.messageKey))
                {
                    mail.messageKey = mod.messageKey;
                    mail.mailType   = mod.mailType;
                    mod.mailType    = MailDirector.Type.UPGRADE;
                }

                if (mod.mailType != MailDirector.Type.UPGRADE && MailRegistry.IsTypeRegistered(mod.mailType))
                {
                    mail.mailType = mod.mailType;
                }

                gameState.player.mail.RemoveAll(m => m.messageKey.Equals(mail.messageKey));
            }

            original.player.availUpgrades.AddAll(gameState.player.availUpgrades, IsGuuUpgrade);
            original.player.upgradeLocks.AddAll(gameState.player.upgradeLocks, IsGuuUpgrade);
            original.player.progress.AddAll(gameState.player.progress, pair => ProgressRegistry.IsTypeRegistered(pair.Key));
            original.player.delayedProgress.AddAll(gameState.player.delayedProgress, pair => ProgressRegistry.IsTrackerRegistered(pair.Key));
            original.player.blueprints.AddAll(gameState.player.blueprints, IsGuuGadget);
            original.player.availBlueprints.AddAll(gameState.player.availBlueprints, IsGuuGadget);
            original.player.blueprintLocks.AddAll(gameState.player.blueprintLocks, IsGuuGadget);
            original.player.gadgets.AddAll(gameState.player.gadgets, IsGuuGadget);
            original.player.craftMatCounts.AddAll(gameState.player.craftMatCounts, IsGuuIdentifiable);

            original.player.unlockedZoneMaps.AddRange(gameState.player.unlockedZoneMaps);

            if (gameState.player.regionSetId != RegionRegistry.RegionSetId.UNSET)
            {
                original.player.playerPos   = gameState.player.playerPos;
                original.player.regionSetId = gameState.player.regionSetId;
            }

            //? Decorizer
            original.player.decorizer.contents.AddAll(gameState.player.decorizer.contents, IsGuuIdentifiable);
            original.player.decorizer.settings.AddAll(gameState.player.decorizer.settings, pair => IsGuuIdentifiable(pair.Value.selected));

            //& Merge Ranch
            foreach (LandPlotV08 plot in original.ranch.plots)
            {
                LandPlotV08 mPlot = gameState.ranch.plots.Find(p => p.id.Equals(plot.id));
                if (mPlot == null)
                {
                    continue;
                }

                if (mPlot.typeId != LandPlot.Id.NONE)
                {
                    plot.typeId = mPlot.typeId;
                }
                if (mPlot.attachedId != SpawnResource.Id.NONE)
                {
                    plot.attachedId = mPlot.attachedId;
                }
                plot.upgrades.AddRange(plot.upgrades);

                foreach (SiloStorage.StorageType type in plot.siloAmmo.Keys)
                {
                    if (!mPlot.siloAmmo.ContainsKey(type))
                    {
                        continue;
                    }

                    int i = 0;
                    foreach (AmmoDataV02 ammo in mPlot.siloAmmo[type])
                    {
                        if (ammo.id != Identifiable.Id.NONE && IsGuuIdentifiable(ammo.id))
                        {
                            plot.siloAmmo[type][i].id = ammo.id;
                        }
                        plot.siloAmmo[type][i].emotionData.emotionData.AddRange(ammo.emotionData.emotionData);
                        i++;
                    }

                    mPlot.siloAmmo.Remove(type);
                }
                plot.siloAmmo.AddAll(mPlot.siloAmmo, pair => AmmoRegistry.IsStorageTypeRegistered(pair.Key));

                gameState.ranch.plots.RemoveAll(p => p.id.Equals(plot.id));
            }
            original.ranch.plots.AddRange(gameState.ranch.plots);

            original.ranch.accessDoorStates.AddAll(gameState.ranch.accessDoorStates, IsGuuID);
            original.ranch.palettes.AddAll(gameState.ranch.palettes, pair => ChromaPackRegistry.IsTypeRegistered(pair.Key) || ChromaPackRegistry.IsPaletteRegistered(pair.Value));
            original.ranch.ranchFastForward.AddAll(gameState.ranch.ranchFastForward, IsGuuID);

            //& Merge Actors
            foreach (ActorDataV09 actor in original.actors)
            {
                ActorDataV09 mActor = gameState.actors.Find(a => a.actorId == actor.actorId);
                if (mActor == null)
                {
                    continue;
                }

                actor.fashions.AddAll(mActor.fashions, IsGuuIdentifiable);
                actor.emotions.emotionData.AddRange(mActor.emotions.emotionData);
                if (mActor.regionSetId != RegionRegistry.RegionSetId.UNSET)
                {
                    actor.pos         = mActor.pos;
                    actor.regionSetId = mActor.regionSetId;
                }

                gameState.actors.RemoveAll(a => a.actorId == actor.actorId);
            }
            original.actors.AddRange(gameState.actors);

            //& Merge Pedia
            original.pedia.unlockedIds.AddRange(gameState.pedia.unlockedIds);
            original.pedia.completedTuts.AddRange(gameState.pedia.completedTuts);
            original.pedia.popupQueue.AddRange(gameState.pedia.popupQueue);

            //& Merge Achievements
            original.achieve.gameFloatStatDict.AddRange(gameState.achieve.gameFloatStatDict);
            original.achieve.gameDoubleStatDict.AddRange(gameState.achieve.gameDoubleStatDict);
            original.achieve.gameIntStatDict.AddRange(gameState.achieve.gameIntStatDict);

            foreach (AchievementsDirector.GameIdDictStat stat in original.achieve.gameIdDictStatDict.Keys)
            {
                if (!gameState.achieve.gameIdDictStatDict.ContainsKey(stat))
                {
                    continue;
                }
                original.achieve.gameIdDictStatDict[stat].AddAll(gameState.achieve.gameIdDictStatDict[stat], IsGuuIdentifiable);
                gameState.achieve.gameIdDictStatDict.Remove(stat);
            }
            original.achieve.gameIdDictStatDict.AddRange(gameState.achieve.gameIdDictStatDict);

            //& Merge Holiday
            original.holiday.eventGordos.AddAll(gameState.holiday.eventGordos, IsGuuID);
            original.holiday.eventEchoNoteGordos.AddAll(gameState.holiday.eventEchoNoteGordos, IsGuuID);

            //& Merge Appearances
            foreach (Identifiable.Id unlKey in original.appearances.unlocks.Keys)
            {
                if (!gameState.appearances.unlocks.ContainsKey(unlKey))
                {
                    continue;
                }
                original.appearances.unlocks[unlKey].AddRange(gameState.appearances.unlocks[unlKey]);
                gameState.appearances.unlocks.Remove(unlKey);
            }
            original.appearances.unlocks.AddAll(gameState.appearances.unlocks, IsGuuIdentifiable);

            foreach (Identifiable.Id selKey in original.appearances.selections.Keys)
            {
                if (!gameState.appearances.selections.ContainsKey(selKey))
                {
                    continue;
                }
                original.appearances.selections[selKey] = gameState.appearances.selections[selKey];
                gameState.appearances.selections.Remove(selKey);
            }
            original.appearances.selections.AddAll(gameState.appearances.selections, IsGuuIdentifiable);

            //& Merge Instrument
            original.instrument.unlocks.AddRange(gameState.instrument.unlocks);
            if (gameState.instrument.selection != InstrumentModel.Instrument.NONE)
            {
                original.instrument.selection = gameState.instrument.selection;
            }

            //& Runs the loading actions registered to SaveHandler
            OnLoad?.Invoke(gameState, saveName);

            //& Finalize the process
            saveName  = null;
            gameState = null;

            GuuCore.LOGGER.Log($"Loaded and injected modded save file {saveName}");
        }
Example #6
0
        public static void Prefix(GameV12 __instance, ref RemovalData __state)
        {
            __state = new RemovalData();

            __state.AddAndRemoveWhereCustom(__instance.actors);
            __state.AddAndRemoveWhere(__instance.world.placedGadgets, (x) => SaveRegistry.IsCustom(x.Value) || ModdedStringRegistry.IsModdedString(x.Key));
            __state.AddAndRemoveWhere(__instance.ranch.plots, (x) => SaveRegistry.IsCustom(x) || ModdedStringRegistry.IsModdedString(x.id));
            __state.AddAndRemoveWhere(__instance.world.gordos, x => SaveRegistry.IsCustom(x.Value) || ModdedStringRegistry.IsModdedString(x.Key));
            __state.AddAndRemoveWhere(__instance.world.treasurePods, x => SaveRegistry.IsCustom(x.Value) || ModdedStringRegistry.IsModdedString(x.Key));
            __state.AddAndRemoveWhere(__instance.world.offers, x => SaveRegistry.IsCustom(x.Value) || ModdedIDRegistry.IsModdedID(x.Key) || ExchangeOfferRegistry.IsCustom(x.Value));
            __state.AddAndRemoveWhere(__instance.world.econSaturations, (x) => ModdedIDRegistry.IsModdedID(x.Key));
            __state.AddAndRemoveWhere(__instance.world.lastOfferRancherIds, ExchangeOfferRegistry.IsCustom);
            __state.AddAndRemoveWhere(__instance.world.pendingOfferRancherIds, ExchangeOfferRegistry.IsCustom);

            __state.AddAndRemoveWhereCustom(__instance.player.upgrades);
            __state.AddAndRemoveWhereCustom(__instance.player.availUpgrades);
            __state.AddAndRemoveWhere(__instance.player.upgradeLocks,
                                      (x) => ModdedIDRegistry.IsModdedID(x.Key));

            __state.AddAndRemoveWhereCustom(__instance.player.blueprints);
            __state.AddAndRemoveWhereCustom(__instance.player.availBlueprints);
            __state.AddAndRemoveWhere(__instance.player.blueprintLocks, (x) => ModdedIDRegistry.IsModdedID(x.Key));

            __state.AddAndRemoveWhere(__instance.player.progress, (x) => ModdedIDRegistry.IsModdedID(x.Key));
            __state.AddAndRemoveWhere(__instance.player.delayedProgress, (x) => ModdedIDRegistry.IsModdedID(x.Key));

            __state.AddAndRemoveWhere(__instance.player.gadgets, (x) => ModdedIDRegistry.IsModdedID(x.Key));

            __state.AddAndRemoveWhere(__instance.player.craftMatCounts, (x) => ModdedIDRegistry.IsModdedID(x.Key));

            __state.AddAndRemoveWhereCustom(__instance.player.unlockedZoneMaps);

            __state.AddAndRemoveWhere(__instance.player.mail, (x) => MailRegistry.GetModForMail(x.messageKey) != null);

            __state.AddAndRemoveWhere(__instance.pedia.unlockedIds, (x) => ModdedIDRegistry.IsModdedID(Enum.Parse(typeof(PediaDirector.Id), x)));
            __state.AddAndRemoveWhere(__instance.pedia.completedTuts, (x) => ModdedIDRegistry.IsModdedID(Enum.Parse(typeof(TutorialDirector.Id), x)));
            __state.AddAndRemoveWhere(__instance.pedia.popupQueue, (x) => ModdedIDRegistry.IsModdedID(Enum.Parse(typeof(TutorialDirector.Id), x)));



            foreach (var data in AmmoDataUtils.GetAllAmmoData(__instance))
            {
                if (AmmoIdentifier.TryGetIdentifier(data, __instance, out var id) && AmmoIdentifier.IsModdedIdentifier(id))
                {
                    __state.addBacks.Add(AmmoDataUtils.RemoveAmmoDataWithAddBack(data, __instance));
                }
                else
                {
                    var moddedData = AmmoDataUtils.RipOutModdedData(data);

                    __state.addBacks.Add(() =>
                    {
                        AmmoDataUtils.SpliceAmmoData(data, moddedData);
                    });
                }
            }

            void RemovePartial(object actor, RemovalData data)
            {
                if (CustomChecker.GetCustomLevel(actor) == CustomChecker.CustomLevel.PARTIAL)
                {
                    var partial = PartialData.GetPartialData(actor.GetType(), true);
                    partial.Pull(actor);
                    data.addBacks.Add(() =>
                    {
                        partial.Push(actor);
                    });
                }
            }

            foreach (var actor in __instance.actors)
            {
                RemovePartial(actor, __state);
            }

            foreach (var actor in __instance.ranch.plots)
            {
                RemovePartial(actor, __state);
            }

            foreach (var actor in __instance.world.placedGadgets)
            {
                RemovePartial(actor.Value, __state);
            }

            foreach (var actor in __instance.world.gordos)
            {
                RemovePartial(actor.Value, __state);
            }

            foreach (var actor in __instance.world.treasurePods)
            {
                RemovePartial(actor.Value, __state);
            }

            foreach (var offer in __instance.world.offers)
            {
                RemovePartial(offer.Value, __state);
            }

            var partialAppearance = new PartialAppearancesData();

            partialAppearance.Pull(__instance.appearances);
            __state.addBacks.Add(() => partialAppearance.Push(__instance.appearances));
        }
Example #7
0
        //! Patch: SavedGame.Save
        internal static void Save(GameV12 original)
        {
            GuuCore.LOGGER.Log("Attempting to save modded save file");
            gameState = new GameV12();

            //& Strip Summary
            if (IdentifiableRegistry.IsIdentifiableRegistered(original.summary.iconId))
            {
                gameState.summary.iconId = original.summary.iconId;
                original.summary.iconId  = FALLBACK_ICON;
            }

            //# Strip Game Mode

            //& Strip World
            StripByMatch(original.world.lastOfferRancherIds, gameState.world.lastOfferRancherIds, IsGuuID);
            StripByMatch(original.world.pendingOfferRancherIds, gameState.world.pendingOfferRancherIds, IsGuuID);
            //# Strip Weather

            StripByMatch(original.world.offers, gameState.world.offers, pair => IsGuuID(pair.Value.rancherId) || IsGuuID(pair.Value.offerId) || ExchangeRegistry.IsOfferTypeRegistered(pair.Key));
            foreach (ExchangeDirector.OfferType type in original.world.offers.Keys)
            {
                ExchangeOfferV04 ori = original.world.offers[type];
                ExchangeOfferV04 mod = new ExchangeOfferV04();

                StripByMatch(ori.requests, mod.requests, request => IsGuuIdentifiable(request.id) || ExchangeRegistry.IsNonIdenRegistered(request.nonIdentReward));
                StripByMatch(ori.rewards, mod.rewards, reward => IsGuuIdentifiable(reward.id) || ExchangeRegistry.IsNonIdenRegistered(reward.nonIdentReward));

                gameState.world.offers.Add(type, mod);
            }

            StripByMatch(original.world.econSaturations, gameState.world.econSaturations, IsGuuIdentifiable);
            StripByMatch(original.world.teleportNodeActivations, gameState.world.teleportNodeActivations, IsGuuID);
            StripByMatch(original.world.liquidSourceUnits, gameState.world.liquidSourceUnits, IsGuuID);

            StripByMatch(original.world.gordos, gameState.world.gordos, IsGuuID);
            foreach (KeyValuePair <string, GordoV01> gordo in original.world.gordos.Where(pair => pair.Value.fashions.Exists(IsGuuIdentifiable)))
            {
                gameState.world.gordos.Add(gordo.Key, new GordoV01());
                StripByMatch(gordo.Value.fashions, gameState.world.gordos[gordo.Key].fashions, IsGuuIdentifiable);
            }

            StripByMatch(original.world.placedGadgets, gameState.world.placedGadgets, IsGuuID);
            foreach (string id in original.world.placedGadgets.Keys)
            {
                PlacedGadgetV08 ori = original.world.placedGadgets[id];
                PlacedGadgetV08 mod = new PlacedGadgetV08();

                if (IsGuuGadget(ori.gadgetId))
                {
                    mod.gadgetId = ori.gadgetId;
                    ori.gadgetId = Gadget.Id.NONE;
                }

                foreach (AmmoDataV02 ammo in ori.ammo)
                {
                    AmmoDataV02 mAmmo = new AmmoDataV02();

                    if (IsGuuIdentifiable(ammo.id))
                    {
                        mAmmo.id = ammo.id;
                        ammo.id  = Identifiable.Id.NONE;
                    }

                    //# Strip Emotion Data
                }

                if (IsGuuIdentifiable(ori.baitTypeId))
                {
                    mod.baitTypeId = ori.baitTypeId;
                    ori.baitTypeId = Identifiable.Id.NONE;
                }

                if (IsGuuIdentifiable(ori.gordoTypeId))
                {
                    mod.gordoTypeId = ori.gordoTypeId;
                    ori.gordoTypeId = Identifiable.Id.NONE;
                }

                StripByMatch(ori.fashions, mod.fashions, IsGuuIdentifiable);

                if (ori.drone != null)
                {
                    mod.drone = new DroneGadgetV01
                    {
                        drone = new DroneV05()
                    };

                    AmmoDataV02 ammo  = ori.drone.drone.ammo;
                    AmmoDataV02 mAmmo = mod.drone.drone.ammo;

                    if (IsGuuIdentifiable(ammo.id))
                    {
                        mAmmo.id = ammo.id;
                        ammo.id  = Identifiable.Id.NONE;
                    }

                    //# Strip Emotion Data

                    StripByMatch(ori.drone.drone.fashions, mod.drone.drone.fashions, IsGuuIdentifiable);
                }

                gameState.world.placedGadgets.Add(id, mod);
            }

            StripByMatch(original.world.treasurePods, gameState.world.treasurePods, IsGuuID);
            foreach (KeyValuePair <string, TreasurePodV01> pod in original.world.treasurePods.Where(pair => pair.Value.spawnQueue.Exists(IsGuuIdentifiable)))
            {
                gameState.world.treasurePods.Add(pod.Key, new TreasurePodV01());
                StripByMatch(pod.Value.spawnQueue, gameState.world.treasurePods[pod.Key].spawnQueue, IsGuuIdentifiable);
            }

            StripByMatch(original.world.switches, gameState.world.switches, IsGuuID);
            StripByMatch(original.world.puzzleSlotsFilled, gameState.world.puzzleSlotsFilled, IsGuuID);
            StripByMatch(original.world.occupiedPhaseSites, gameState.world.occupiedPhaseSites, IsGuuID);
            StripByMatch(original.world.quicksilverEnergyGenerators, gameState.world.quicksilverEnergyGenerators, IsGuuID);
            StripByMatch(original.world.oasisStates, gameState.world.oasisStates, IsGuuID);
            StripByMatch(original.world.activeGingerPatches, gameState.world.activeGingerPatches, IsGuuID);
            StripByMatch(original.world.echoNoteGordos, gameState.world.echoNoteGordos, IsGuuID);

            //? Slimeulation
            StripByMatch(original.world.glitch.teleporters, gameState.world.glitch.teleporters, IsGuuID);
            StripByMatch(original.world.glitch.nodes, gameState.world.glitch.nodes, IsGuuID);
            StripByMatch(original.world.glitch.impostoDirectors, gameState.world.glitch.impostoDirectors, IsGuuID);
            StripByMatch(original.world.glitch.impostos, gameState.world.glitch.impostos, IsGuuID);
            StripByMatch(original.world.glitch.slimes, gameState.world.glitch.slimes, IsGuuID);
            StripByMatch(original.world.glitch.storage, gameState.world.glitch.storage, IsGuuID);
            StripByMatch(original.world.glitch.storage, gameState.world.glitch.storage, pair => IsGuuIdentifiable(pair.Value.id));

            //& Strip Player
            //# Strip Game Mode

            if (IsGuuIdentifiable(original.player.gameIconId))
            {
                gameState.player.gameIconId = original.player.gameIconId;
                original.player.gameIconId  = FALLBACK_ICON;
            }

            StripByMatch(original.player.upgrades, gameState.player.upgrades, IsGuuUpgrade);

            StripByMatch(original.player.ammo, gameState.player.ammo, pair => AmmoRegistry.IsAmmoModeRegistered(pair.Key));
            foreach (KeyValuePair <PlayerState.AmmoMode, List <AmmoDataV02> > ammoList in original.player.ammo)
            {
                List <AmmoDataV02> moddedList = new List <AmmoDataV02>();
                foreach (AmmoDataV02 ammo in ammoList.Value)
                {
                    AmmoDataV02 data = new AmmoDataV02();

                    if (IsGuuIdentifiable(ammo.id))
                    {
                        data.id = ammo.id;
                        ammo.id = Identifiable.Id.NONE;
                    }

                    //# Strip Emotions

                    moddedList.Add(data);
                }

                if (moddedList.Count > 0)
                {
                    gameState.player.ammo[ammoList.Key] = moddedList;
                }
            }

            foreach (MailV02 mail in original.player.mail)
            {
                MailV02 mod = new MailV02
                {
                    messageKey = string.Empty,
                    mailType   = MailDirector.Type.UPGRADE
                };

                if (MailRegistry.IsTypeRegistered(mail.mailType))
                {
                    mod.mailType  = mail.mailType;
                    mail.mailType = MailDirector.Type.PERSONAL;
                }

                if (MailRegistry.IsMailRegistered(mail.messageKey))
                {
                    mod.messageKey = mail.messageKey;
                    if (mod.mailType == MailDirector.Type.UPGRADE)
                    {
                        mod.mailType = mail.mailType;
                    }
                    mail.mailType = MailDirector.Type.UPGRADE;
                }

                gameState.player.mail.Add(mod);
            }

            StripByMatch(original.player.availUpgrades, gameState.player.availUpgrades, IsGuuUpgrade);
            StripByMatch(original.player.upgradeLocks, gameState.player.upgradeLocks, IsGuuUpgrade);
            StripByMatch(original.player.progress, gameState.player.progress, pair => ProgressRegistry.IsTypeRegistered(pair.Key));
            StripByMatch(original.player.delayedProgress, gameState.player.delayedProgress, pair => ProgressRegistry.IsTrackerRegistered(pair.Key));
            StripByMatch(original.player.blueprints, gameState.player.blueprints, IsGuuGadget);
            StripByMatch(original.player.availBlueprints, gameState.player.availBlueprints, IsGuuGadget);
            StripByMatch(original.player.blueprintLocks, gameState.player.blueprintLocks, IsGuuGadget);
            StripByMatch(original.player.gadgets, gameState.player.gadgets, IsGuuGadget);
            StripByMatch(original.player.craftMatCounts, gameState.player.craftMatCounts, IsGuuIdentifiable);

            //# Strip Region Set ID && Player Pos
            //# Strip Unlocked Zone

            //? Decorizer
            StripByMatch(original.player.decorizer.contents, gameState.player.decorizer.contents, IsGuuIdentifiable);
            StripByMatch(original.player.decorizer.settings, gameState.player.decorizer.settings, IsGuuID);
            StripByMatch(original.player.decorizer.settings, gameState.player.decorizer.settings, pair => IsGuuIdentifiable(pair.Value.selected));

            //& Strip Ranch
            //# Strip Plots

            StripByMatch(original.ranch.accessDoorStates, gameState.ranch.accessDoorStates, IsGuuID);
            StripByMatch(original.ranch.palettes, gameState.ranch.palettes, pair => ChromaPackRegistry.IsTypeRegistered(pair.Key) || ChromaPackRegistry.IsPaletteRegistered(pair.Value));
            StripByMatch(original.ranch.ranchFastForward, gameState.ranch.ranchFastForward, IsGuuID);

            //& Strip Actors
            StripByMatch(original.actors, gameState.actors, actor => IsGuuID(actor.actorId));
            foreach (ActorDataV09 actor in original.actors)
            {
                ActorDataV09 newActor = new ActorDataV09();
                // ReSharper disable once ReplaceWithSingleAssignment.False
                bool hasData = false;

                //# Strip Emotions

                if (actor.fashions.Exists(IsGuuIdentifiable))
                {
                    hasData = true;
                    StripByMatch(actor.fashions, newActor.fashions, IsGuuIdentifiable);
                }

                //# Strip Region Set && Position

                if (hasData)
                {
                    gameState.actors.Add(newActor);
                }
            }

            //& Strip Pedia
            //# Strip Unlocked IDs
            //# Strip Completed Tuts
            //# Strip Popup Queue

            //& Strip Achievements
            //# Strip Float Stats
            //# Strip Double Stats
            //# Strip Int Stats

            //# Strip ID Stats by Key
            foreach (KeyValuePair <AchievementsDirector.GameIdDictStat, Dictionary <Identifiable.Id, int> > idDictStat in original.achieve.gameIdDictStatDict.Where(pair => pair.Value.Count(pair2 => IsGuuIdentifiable(pair2.Key)) > 0))
            {
                gameState.achieve.gameIdDictStatDict[idDictStat.Key] = new Dictionary <Identifiable.Id, int>();
                StripByMatch(idDictStat.Value, gameState.achieve.gameIdDictStatDict[idDictStat.Key], IsGuuIdentifiable);
            }

            //& Strip Holidays
            StripByMatch(original.holiday.eventGordos, gameState.holiday.eventGordos, IsGuuID);
            StripByMatch(original.holiday.eventEchoNoteGordos, gameState.holiday.eventEchoNoteGordos, IsGuuID);

            //& Strip Appearances
            StripByMatch(original.appearances.unlocks, gameState.appearances.unlocks, IsGuuIdentifiable);
            //# Strip Unlocks based on Appearance Sets

            StripByMatch(original.appearances.selections, gameState.appearances.selections, IsGuuIdentifiable);
            //# Strip Selections based on Appearance Sets

            //& Strip Instruments
            //# Strip Unlocks
            //# Strip Selection

            // TODO: Strip content from the original
        }