public void PreLoad() { HarmonyPatcher.GetInstance().PatchAll(Assembly.GetExecutingAssembly()); SRML.Console.Console.RegisterCommand(new SetColorsCommand()); TranslationPatcher.AddTranslationKey("pedia", RAVEBALL_KEY, "Rave Ball"); TranslationPatcher.AddTranslationKey("pedia", RAVEBALL_UI_KEY, "Rave Ball"); TranslationPatcher.AddTranslationKey("pedia", RAVEBALL_DESC_KEY, "This ball may look plain, but it makes slimes want to party!"); //IdentifiableRegistry.CreateIdentifiableId(RAVE_BALL_ID, "RAVE_BALL_TOY"); var bundle = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly() .GetManifestResourceStream(typeof(Main), "colorfulslimes")); var g = bundle.LoadAsset <GameObject>("raveball"); g.AddComponent <RegionMember>(); g.AddComponent <Identifiable>().id = CustomIds.RAVE_BALL_TOY; g.layer = LayerMask.NameToLayer("Actor"); g.AddComponent <Vacuumable>().size = Vacuumable.Size.LARGE; g.AddComponent <Raveball>(); g.transform.GetChild(0).gameObject.AddComponent <VacDelaunchTrigger>(); LookupRegistry.RegisterIdentifiablePrefab(g); SaveRegistry.RegisterDataParticipant <SlimePainter>(); }
public void Read(BinaryReader reader) { version = reader.ReadInt32(); modid = reader.ReadString(); byteLength = reader.ReadInt64(); if (!(SRModLoader.GetMod(modid) is SRMod mod)) { throw new Exception($"Unrecognized mod id: {modid}"); } var saveInfo = SaveRegistry.GetSaveInfo(mod); identifiableData.Clear(); int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { var e = new IdentifiedData(); e.Read(reader, saveInfo); identifiableData.Add(e); } extendedData.Clear(); count = reader.ReadInt32(); for (int i = 0; i < count; i++) { var e = new ExtendedDataTree(); e.Read(reader); extendedData.Add(e); } if (version >= 1) { playerData.Read(reader); pediaData.Read(reader); enumTranslator = new EnumTranslator(); enumTranslator.Read(reader); BinaryUtils.ReadDictionary(reader, customAmmo, (x) => AmmoIdentifier.Read(x), (x) => { var list = new List <VanillaAmmoData>(); int ammoCount = x.ReadInt32(); for (int i = 0; i < ammoCount; i++) { if (x.ReadBoolean()) { var newData = new VanillaAmmoData(); newData.Load(x.BaseStream); list.Add(newData); } else { list.Add(null); } } return(list); }); } }
public void AddAndRemoveWhereCustom <T>(List <T> original, List <T> buffer) { buffer.AddRange(original.Where((x) => SaveRegistry.IsCustom(x))); foreach (var v in buffer) { original.Remove(v); } addBacks.Add(() => original.AddRange(buffer)); }
public void InitializeAllEnumTranslators() { foreach (var v in segments) { if (v.enumTranslator == null) { v.enumTranslator = SaveRegistry.GenerateEnumTranslator(SRModLoader.GetMod(v.modid)); } } }
public void Write(BinaryWriter writer) { version = DATA_VERSION; var start = writer.BaseStream.Position; writer.Write(version); writer.Write(modid); var overwritePosition = writer.BaseStream.Position; writer.Write((long)0); if (!(SRModLoader.GetMod(modid) is SRMod mod)) { throw new Exception($"Unrecognized mod id: {modid}"); } var saveInfo = SaveRegistry.GetSaveInfo(mod); writer.Write(identifiableData.Count); foreach (var data in identifiableData) { data.Write(writer, saveInfo); } writer.Write(extendedData.Count); foreach (var data in extendedData) { data.Write(writer); } playerData.Write(writer); pediaData.Write(writer); BinaryUtils.WriteDictionary(writer, customAmmo, (x, y) => AmmoIdentifier.Write(y, x), (x, y) => { x.Write(y.Count); foreach (var v in y) { x.Write(v != null); if (v != null) { v.Write(x.BaseStream); } } }); DataPiece.Serialize(writer, extendedWorldData); worldData.Write(writer); var cur = writer.BaseStream.Position; writer.BaseStream.Seek(overwritePosition, SeekOrigin.Begin); byteLength = cur - (start); writer.Write(byteLength); writer.BaseStream.Seek(cur, SeekOrigin.Begin); }
public static HashSet <SRMod> FindAllModsWithData(PediaDataBuffer data) { var mods = new HashSet <SRMod>(); data.unlockedIds.ForEach((x) => mods.Add(SaveRegistry.ModForID(x))); data.completedTuts.ForEach((x) => mods.Add(SaveRegistry.ModForID(x))); data.popupQueue.ForEach((x) => mods.Add(SaveRegistry.ModForID(x))); mods.Remove(null); return(mods); }
public static VanillaActorData ActorCreator(GameModel gameModel, int typeId, long actorId, ActorModel actorModel) { var mod = SaveRegistry.ModForModelType(actorModel.GetType()); if (mod != null) { var info = SaveRegistry.GetSaveInfo(mod).GetRegistryFor <CustomActorData>(); var newmodel = info.GetDataForID(info.GetIDForModel(actorModel.GetType())); newmodel.PullCustomModel(actorModel); return((VanillaActorData)newmodel); } return(new VanillaActorData()); }
public override void PreLoad() { HarmonyInstance.PatchAll(); SRML.Console.Console.RegisterCommand(new ChangeVacVisualCommand()); SaveRegistry.RegisterDataParticipant <PlortUndisappearifier>(); LookupRegistry.RegisterUpgradeEntry(Ids.MOCHI_HACK, Main.assetBundle.LoadAsset <Sprite>("upgrade_initial"), 10000); Ids.MOCHI_HACK.GetTranslation().SetDescriptionTranslation("Hack the gate at Mochi's Manor to make it ineffective and go in/out with your normal inventory. But you have to be careful, Mochi may or may not see when her precious quicksilver slimes disappear, and if that happens, she will attack your base, trying to take them back!").SetNameTranslation("Gate Hack"); PersonalUpgradeRegistry.RegisterUpgradeLock(Ids.MOCHI_HACK, (PlayerState x) => x.CreateBasicLock(null, delegate { ProgressModel model = SRSingleton <SceneContext> .Instance.ProgressDirector.model; return(model != null && model.HasProgress(ProgressDirector.ProgressType.ENTER_ZONE_MOCHI_RANCH)); }, 0f)); }
public override void PreLoad() { SlimeTraitRegistry.Register(new DietTraitProcessor(SRModInfo.GetCurrentInfo().Id, "diet")); SlimeTraitRegistry.Register(new TemperamentTraitProcessor(SRModInfo.GetCurrentInfo().Id, "temperament")); SRCallbacks.OnActorSpawn += SRCallbacks_OnActorSpawn; SRCallbacks.OnSaveGameLoaded += (s) => s.Player.AddComponent <GenomeViewer>(); SaveRegistry.RegisterDataParticipant <GenomeHolder>(); SaveRegistry.RegisterDataParticipant <SlimeGeneticsHandler>(); BindingRegistry.RegisterActions(typeof(ModActions)); TranslationPatcher.AddUITranslation("key.probegenetics", "Probe Genetic Data"); GeneticUI.SetupGeneticUI(); }
public void Pull(PlayerV13 player, SRMod ourMod) { upgrades.AddRange(player.upgrades.Where((x) => SaveRegistry.ModForID(x) == ourMod)); availUpgrades.AddRange(player.availUpgrades.Where((x) => SaveRegistry.ModForID(x) == ourMod)); AddRange(upgradeLocks, player.upgradeLocks.Where((x) => SaveRegistry.ModForID(x.Key) == ourMod)); AddRange(progress, player.progress.Where((x) => SaveRegistry.ModForID(x.Key) == ourMod)); AddRange(delayedProgress, player.delayedProgress.Where((x) => SaveRegistry.ModForID(x.Key) == ourMod)); blueprints.AddRange(player.blueprints.Where((x) => SaveRegistry.ModForID(x) == ourMod)); availBlueprints.AddRange(player.availBlueprints.Where((x) => SaveRegistry.ModForID(x) == ourMod)); AddRange(blueprintLocks, player.blueprintLocks.Where((x) => SaveRegistry.ModForID(x.Key) == ourMod)); AddRange(gadgets, player.gadgets.Where((x) => SaveRegistry.ModForID(x.Key) == ourMod)); AddRange(craftMatCounts, player.craftMatCounts.Where((x) => SaveRegistry.ModForID(x.Key) == ourMod)); }
public override void OnInspectorGUI() { EditorExtension.DrawScriptField(this); serializedObject.Update(); SaveRegistry obj = (SaveRegistry)target; EditorGUILayout.HelpBox( $"This is {typeof(SaveRegistry).Name} file, items in it will be added to Saves Database, " + "but will not be SAVED/LOADED. For all items will be used Guid as SaveID", MessageType.Info); SerializedProperty enteries = serializedObject.FindProperty("m_entries"); EditorGUILayout.PropertyField(enteries); if (obj.Entries != null && obj.Entries.Count > 0) { foreach (var save in obj.Entries) { if (save != null) { save.SaveID.useGUID = true; } } } bool containsNested = SaveableBase.ContainsNestedSavables(obj.Entries, obj, out var containsItself); if (containsItself) { EditorGUILayout.HelpBox( "Your list contains itself, this will cause stack overflow upon LOAD/SAVE", MessageType.Error); } else if (containsNested) { EditorGUILayout.HelpBox( "Your list contains a nested list saves, it can cause unexpected behaviours", MessageType.Warning); } serializedObject.ApplyModifiedProperties(); }
public static HashSet <SRMod> FindAllModsWithData(PlayerV13 player) { var mods = new HashSet <SRMod>(); player.upgrades.ForEach((x) => mods.Add(SaveRegistry.ModForID(x))); player.availUpgrades.ForEach((x) => mods.Add(SaveRegistry.ModForID(x))); foreach (var x in player.upgradeLocks) { mods.Add(SaveRegistry.ModForID(x)); } foreach (var x in player.progress) { mods.Add(SaveRegistry.ModForID(x.Key)); } foreach (var x in player.delayedProgress) { mods.Add(SaveRegistry.ModForID(x.Key)); } player.blueprints.ForEach((x) => mods.Add(SaveRegistry.ModForID(x))); player.availBlueprints.ForEach((x) => mods.Add(SaveRegistry.ModForID(x))); foreach (var x in player.blueprintLocks) { mods.Add(SaveRegistry.ModForID(x.Key)); } foreach (var x in player.gadgets) { mods.Add(SaveRegistry.ModForID(x.Key)); } foreach (var x in player.craftMatCounts) { mods.Add(SaveRegistry.ModForID(x.Key)); } mods.Remove(null); return(mods); }
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); }); } }
public static List <VanillaAmmoData> RipOutModdedData(List <VanillaAmmoData> original) { return(RipOutWhere(original, (x) => SaveRegistry.IsCustom(x.id))); }
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)); }
static PersonalUpgradeRegistry() { SaveRegistry.RegisterIDRegistry(new ModdedIDRegistry((id => moddedUpgrades[(PlayerState.Upgrade)id]), () => typeof(PlayerState.Upgrade), (x) => IsModdedUpgrade((PlayerState.Upgrade)x), (mod) => moddedUpgrades.Where((x) => x.Value == mod).Select((x) => x.Key).ToList())); }
public void InitializeEnumTranslator() { enumTranslator = SaveRegistry.GenerateEnumTranslator(); }
public void Pull(PediaDataBuffer data, SRMod ourMod) { unlockedIds.AddRange(data.unlockedIds.Where((x) => SaveRegistry.ModForID(x) == ourMod).Select((x) => Enum.GetName(typeof(PediaDirector.Id), x))); completedTuts.AddRange(data.completedTuts.Where((x) => SaveRegistry.ModForID(x) == ourMod).Select((x) => Enum.GetName(typeof(TutorialDirector.Id), x))); popupQueue.AddRange(data.popupQueue.Where((x) => SaveRegistry.ModForID(x) == ourMod).Select((x) => Enum.GetName(typeof(TutorialDirector.Id), x))); }
public static bool HasCustomData(List <VanillaAmmoData> ammo) { return(ammo.Any((x) => SaveRegistry.IsCustom(x.id))); }
public void AddAndRemoveWhereCustom <T>(List <T> original) { var buffer = new List <T>(); buffer.AddRange(original.Where((x) => x.GetType().IsEnum? ModdedIDRegistry.IsModdedID(x):SaveRegistry.IsCustom(x))); foreach (var v in buffer) { original.Remove(v); } addBacks.Add(() => original.AddRange(buffer)); }
static IdentifiableRegistry() { SaveRegistry.RegisterIDRegistry(new ModdedIDRegistry((id => moddedIdentifiables[(Identifiable.Id)id]), () => typeof(Identifiable.Id), (x) => IsModdedIdentifiable((Identifiable.Id)x), (mod) => moddedIdentifiables.Where((x) => x.Value == mod).Select((x) => x.Key).ToList())); }
static GadgetRegistry() { SaveRegistry.RegisterIDRegistry(new ModdedIDRegistry((id => moddedGadgets[(Gadget.Id)id]), () => typeof(Gadget.Id), (x) => IsModdedGadget((Gadget.Id)x), (mod) => moddedGadgets.Where((x) => x.Value == mod).Select((x) => x.Key).ToList())); }