static PartialExchangeData() { RegisterPartialData(() => new PartialExchangeData()); EnumTranslator.RegisterEnumFixer <PartialExchangeData>((translator, mode, data) => { translator.FixEnumValues(mode, data.requests); translator.FixEnumValues(mode, data.rewards); }); EnumTranslator.RegisterEnumFixer <ItemEntryV03>((translator, mode, data) => { data.id = translator.TranslateEnum(mode, data.id); data.nonIdentReward = translator.TranslateEnum(mode, data.nonIdentReward); }); EnumTranslator.RegisterEnumFixer <RequestedItemEntryV03>((translator, mode, data) => { data.id = translator.TranslateEnum(mode, data.id); data.nonIdentReward = translator.TranslateEnum(mode, data.nonIdentReward); }); EnumTranslator.RegisterEnumFixer <ExchangeOfferV04>((translator, mode, data) => { translator.FixEnumValues(mode, data.requests); translator.FixEnumValues(mode, data.rewards); }); CustomChecker.RegisterCustomChecker <ExchangeOfferV04>((data) => { if (ExchangeOfferRegistry.IsCustom(data)) { return(CustomChecker.CustomLevel.FULL); } if (data.requests.Any(x => ModdedIDRegistry.IsModdedID(x.id) || ModdedIDRegistry.IsModdedID(x.nonIdentReward))) { return(CustomChecker.CustomLevel.PARTIAL); } if (data.rewards.Any(x => ModdedIDRegistry.IsModdedID(x.id) || ModdedIDRegistry.IsModdedID(x.nonIdentReward))) { return(CustomChecker.CustomLevel.PARTIAL); } return(CustomChecker.CustomLevel.VANILLA); }); }
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 } }); } }
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)); }