Esempio n. 1
0
 internal static void Push(ModdedSaveData data)
 {
     foreach (var actorData in GetAllData(SceneContext.Instance.GameModel))
     {
         foreach (CompoundDataPiece modPiece in actorData.Value.DataList)
         {
             var mod         = SRModLoader.GetMod(modPiece.key);
             var seg         = data.GetSegmentForMod(mod);
             var newCompound = new CompoundDataPiece("root");
             foreach (var dat in modPiece.DataList)
             {
                 newCompound.DataList.Add(dat);
             }
             seg.extendedData.Add(new ExtendedDataTree()
             {
                 dataPiece        = newCompound,
                 longIdentifier   = actorData.Key.longID,
                 stringIdentifier = actorData.Key.stringID ?? "",
                 idType           = ExtendedDataTree.IdentifierType.ACTOR
             });
         }
     }
     foreach (var pair in worldSaveData)
     {
         SaveRegistry.GetSaveInfo(pair.Key).WorldDataSave(pair.Value);
         if (pair.Value.DataList.Count > 0)
         {
             data.GetSegmentForMod(pair.Key).extendedWorldData = pair.Value;
         }
     }
 }
Esempio n. 2
0
 static ExtendedData()
 {
     SRCallbacks.OnSaveGameLoaded += (s) =>
     {
         foreach (var v in worldSaveData)
         {
             SaveRegistry.GetSaveInfo(v.Key)?.WorldDataLoad(v.Value);
         }
     };
 }
Esempio n. 3
0
        internal static void Pull(ModdedSaveData data)
        {
            Clear();
            foreach (var mod in data.segments)
            {
                Debug.Log($"mod {mod.modid} has {mod.extendedData.Count} extended actor datas");
                foreach (var extendedDataTree in mod.extendedData)
                {
                    switch (extendedDataTree.idType)
                    {
                    case ExtendedDataTree.IdentifierType.ACTOR:
                        var          identifier = DataIdentifier.GetActorIdentifier(extendedDataTree.longIdentifier);
                        PreparedData pdata;
                        if (!preparedData.TryGetValue(identifier, out pdata))
                        {
                            pdata = new PreparedData()
                            {
                                Data = new CompoundDataPiece("root"), SourceType = PreparedData.PreparationSource.SPAWN
                            };
                            preparedData[identifier] = pdata;
                        }
                        extendedDataTree.dataPiece.DataList.Do((x) => pdata.Data.GetCompoundPiece(mod.modid).DataList.Add(x));
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
                var actualMod = SRModLoader.GetMod(mod.modid);
                if (actualMod == null)
                {
                    continue;
                }
                worldSaveData.Add(actualMod, mod.extendedWorldData);
                SaveRegistry.GetSaveInfo(actualMod).WorldDataPreLoad(mod.extendedWorldData);
            }
            foreach (var v in SRModLoader.GetMods())
            {
                if (!worldSaveData.ContainsKey(v))
                {
                    var newData = new CompoundDataPiece("root");
                    worldSaveData.Add(v, newData);
                    SaveRegistry.GetSaveInfo(v).WorldDataPreLoad(newData);
                }
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        private static void PullFullData(ModdedSaveData data, Game game)
        {
            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 plot in game.ranch.plots.Where(x => ModdedStringRegistry.IsValidString(x.id) && (SaveRegistry.IsCustom(x) || ModdedStringRegistry.IsModdedString(x.id))))
            {
                var segment = data.GetSegmentForMod(SaveRegistry.ModForData(plot) is SRMod mod ? mod : ModdedStringRegistry.GetModForModdedString(plot.id));
                segment.identifiableData.Add(new IdentifiedData()
                {
                    data   = plot,
                    dataID = new DataIdentifier()
                    {
                        longID = 0, stringID = plot.id, Type = IdentifierType.LANDPLOT
                    }
                });
            }

            void GetStringIndexedModdedData <T>(Dictionary <string, T> source, Func <KeyValuePair <string, T>, DataIdentifier> dataIdentifier) where T : PersistedDataSet
            {
                foreach (var pair in source.Where(x => ModdedStringRegistry.IsValidString(x.Key) && (SaveRegistry.IsCustom(x.Value) || ModdedStringRegistry.IsModdedString(x.Key))))
                {
                    var segment = data.GetSegmentForMod(SaveRegistry.ModForData(pair.Value) ?? ModdedStringRegistry.GetModForModdedString(pair.Key));
                    segment.identifiableData.Add(new IdentifiedData()
                    {
                        data   = pair.Value,
                        dataID = dataIdentifier(pair)
                    });
                }
            }

            GetStringIndexedModdedData(game.world.placedGadgets, (gadget) => new DataIdentifier()
            {
                longID = 0, stringID = gadget.Key, Type = IdentifierType.GADGET
            });
            GetStringIndexedModdedData(game.world.gordos, (gordo) => new DataIdentifier()
            {
                longID = 0, stringID = gordo.Key, Type = IdentifierType.GORDO
            });
            GetStringIndexedModdedData(game.world.treasurePods, (pod) => new DataIdentifier()
            {
                longID = 0, stringID = pod.Key, Type = IdentifierType.TREASUREPOD
            });

            foreach (var v in game.world.offers.Where(x => ModdedIDRegistry.IsModdedID(x.Key) || ExchangeOfferRegistry.IsCustom(x.Value)))
            {
                var segment = data.GetSegmentForMod(SaveRegistry.ModForData(v.Value) ?? ExchangeOfferRegistry.GetModForData(v.Value));
                segment.identifiableData.Add(new IdentifiedData()
                {
                    data   = v.Value,
                    dataID = new DataIdentifier()
                    {
                        Type = IdentifierType.EXCHANGEOFFER, longID = (int)v.Key
                    }
                });
            }
        }