Ejemplo n.º 1
0
 private static void PullAmmoData(ModdedSaveData data, Game game)
 {
     foreach (var ammo in AmmoDataUtils.GetAllAmmoData(game))
     {
         var modsInThis   = new HashSet <SRMod>(ammo.Select((x) => ModdedIDRegistry.IsModdedID(x.id) ? ModdedIDRegistry.ModForID(x.id) : null));
         var belongingMod = AmmoIdentifier.TryGetIdentifier(ammo, game, out var id) ? AmmoIdentifier.GetModForIdentifier(id) : null;
         modsInThis.Add(belongingMod);
         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) => mod == belongingMod?ModdedIDRegistry.ModForID(x.id) == null:ModdedIDRegistry.ModForID(x.id) == mod, false);
             }
             else
             {
                 Debug.LogError("Unknown ammo identifier, skipping...");
             }
         }
     }
 }
Ejemplo n.º 2
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);
        }