Exemplo n.º 1
0
        public static void PushModdedData(GameV09 game)
        {
            foreach (var mod in data.segments)
            {
                Debug.Log($"Splicing data from mod {mod.modid} which {mod.identifiableData.Count} pieces of identifiable data");
                foreach (var customData in mod.identifiableData)
                {
                    switch (customData.dataID.Type)
                    {
                    case IdentifierType.ACTOR:
                        game.actors.Add((VanillaActorData)customData.data);
                        break;

                    case IdentifierType.GADGET:
                        game.world.placedGadgets[customData.dataID.stringID] = (VanillaGadgetData)customData.data;
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }

                mod.playerData.Push(game.player);
                mod.pediaData.Push(game.pedia);

                foreach (var ammo in mod.customAmmo)
                {
                    AmmoDataUtils.SpliceAmmoData(AmmoIdentifier.ResolveToData(ammo.Key, game), ammo.Value);
                }
            }

            ExtendedData.Pull(data);
            PersistentAmmoManager.Pull(data);
        }
Exemplo n.º 2
0
        public static AmmoIdentifier GetIdentifier(List <AmmoDataV02> ammo, GameV09 game)
        {
            foreach (var v in game.player.ammo)
            {
                if (ammo == v.Value)
                {
                    return(new AmmoIdentifier(AmmoType.PLAYER, (ulong)v.Key));
                }
            }

            foreach (var v in game.ranch.plots)
            {
                foreach (var ammoData in v.siloAmmo)
                {
                    if (ammoData.Value == ammo)
                    {
                        return(new AmmoIdentifier(AmmoType.LANDPLOT, (ulong)ammoData.Key, v.id));
                    }
                }
            }

            foreach (var v in game.world.placedGadgets)
            {
                if (v.Value.ammo == ammo)
                {
                    return(new AmmoIdentifier(AmmoType.GADGET, v.Key));
                }
            }
            return(new AmmoIdentifier(AmmoType.NONE, 0));
        }
Exemplo n.º 3
0
        public static List <List <VanillaAmmoData> > GetAllAmmoData(GameV09 game)
        {
            List <List <VanillaAmmoData> > ammoDataData = new List <List <VanillaAmmoData> >();

            ammoDataData.AddRange(game.player.ammo.Values);

            ammoDataData.AddRange(game.ranch.plots.SelectMany((x) => x.siloAmmo).Select((x) => x.Value));

            ammoDataData.AddRange(game.world.placedGadgets.Values.Select((x) => x.ammo));

            ammoDataData.RemoveAll((x) => x == null);

            return(ammoDataData);
        }
Exemplo n.º 4
0
        public static List <AmmoDataV02> ResolveToData(AmmoIdentifier identifier, GameV09 game)
        {
            switch (identifier.AmmoType)
            {
            case AmmoType.PLAYER:
                return(game.player.ammo[(PlayerState.AmmoMode)identifier.longIdentifier]);

            case AmmoType.GADGET:
                return(game.world.placedGadgets[identifier.stringIdentifier].ammo);

            case AmmoType.LANDPLOT:
                return(game.ranch.plots.First((x) => x.id == identifier.stringIdentifier)
                       .siloAmmo[(SiloStorage.StorageType)identifier.longIdentifier]);
            }

            return(null);
        }
Exemplo n.º 5
0
        public static void Prefix(GameV09 __instance, ref RemovalData __state)
        {
            __state = new RemovalData();

            __state.AddAndRemoveWhereCustom(__instance.actors, __state.actors);
            __state.AddAndRemoveWhere(__instance.world.placedGadgets, __state.placedGadgets, (x) => SaveRegistry.IsCustom(x.Value));
            __state.AddAndRemoveWhereCustom(__instance.ranch.plots, __state.landplots);

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

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

            __state.AddAndRemoveWhere(__instance.player.progress, __state.progress, (x) => SaveRegistry.IsCustom(x.Key));
            __state.AddAndRemoveWhere(__instance.player.delayedProgress, __state.delayedProgress, (x) => SaveRegistry.IsCustom(x.Key));

            __state.AddAndRemoveWhere(__instance.player.gadgets, __state.gadgets, (x) => SaveRegistry.IsCustom(x.Key));

            __state.AddAndRemoveWhere(__instance.player.craftMatCounts, __state.craftMatCounts, (x) => SaveRegistry.IsCustom(x.Key));

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

            foreach (var data in AmmoDataUtils.GetAllAmmoData(__instance))
            {
                var moddedData = AmmoDataUtils.RipOutModdedData(data);
                __state.addBacks.Add(() =>
                {
                    AmmoDataUtils.SpliceAmmoData(data, moddedData);
                });
            }
        }
Exemplo n.º 6
0
        public static void PullModdedData(GameV09 game)
        {
            data.segments.Clear();
            data.ammoDataEntries.Clear();
            foreach (var actor in game.actors.Where((x) => SaveRegistry.IsCustom(x)))
            {
                var segment = data.GetSegmentForMod(SaveRegistry.ModForData(actor));
                segment.identifiableData.Add(new IdentifiedData()
                {
                    data   = actor,
                    dataID = new DataIdentifier()
                    {
                        longID = actor.actorId, stringID = "", Type = IdentifierType.ACTOR
                    }
                });
            }

            foreach (var gadget in game.world.placedGadgets.Where((x) => SaveRegistry.IsCustom(x.Value)))
            {
                var segment = data.GetSegmentForMod(SaveRegistry.ModForData(gadget.Value));
                segment.identifiableData.Add(new IdentifiedData()
                {
                    data   = gadget.Value,
                    dataID = new DataIdentifier()
                    {
                        longID = 0, stringID = gadget.Key, Type = IdentifierType.GADGET
                    }
                });
            }

            foreach (var mod in ModPlayerData.FindAllModsWithData(game.player))
            {
                var segment = data.GetSegmentForMod(mod);

                segment.playerData.Pull(game.player, mod);
            }

            PediaDataBuffer buf = new PediaDataBuffer(game.pedia);

            foreach (var mod in ModPediaData.FindAllModsWithData(buf))
            {
                var segment = data.GetSegmentForMod(mod);
                segment.pediaData.Pull(buf, mod);
            }

            foreach (var ammo in AmmoDataUtils.GetAllAmmoData(game).Where((x) => AmmoDataUtils.HasCustomData(x)))
            {
                var modsInThis = new HashSet <SRMod>(ammo.Select((x) => SaveRegistry.IsCustom(x.id) ? SaveRegistry.ModForID(x.id) : null));
                modsInThis.Remove(null);
                foreach (var mod in modsInThis)
                {
                    if (mod == null)
                    {
                        continue;
                    }
                    if (AmmoIdentifier.TryGetIdentifier(ammo, game, out var identifier))
                    {
                        var segment = data.GetSegmentForMod(mod);
                        segment.customAmmo[identifier] =
                            AmmoDataUtils.RipOutWhere(ammo, (x) => SaveRegistry.ModForID(x.id) == mod, false);
                    }
                    else
                    {
                        throw new Exception("OH GOD ITS HAPPENING");
                    }
                }
            }

            ExtendedData.Push(data);
            PersistentAmmoManager.SyncAll();
            PersistentAmmoManager.Push(data);
        }
Exemplo n.º 7
0
 public static void Postfix(GameV09 __instance, ref RemovalData __state)
 {
     __state.AddAllBack();
 }
Exemplo n.º 8
0
 public static bool TryGetIdentifier(List <AmmoDataV02> ammo, GameV09 game, out AmmoIdentifier identifier)
 {
     identifier = GetIdentifier(ammo, game);
     return(identifier.AmmoType != AmmoType.NONE);
 }