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..."); } } } }
public static bool IsCustom(object data) { if (data == null) { return(false); } if (data.GetType().IsEnum) { throw new Exception("IsCustom for enums has been deprecated, use ModdedIDRegistry"); } if (data.GetType().IsValueType) { throw new Exception("Custom Value Type " + data.GetType()); } return(IsFullyModdedData(data) || ModdedIDRegistry.HasModdedID(data)); }
internal static SRMod ModForData(object data) { if (!IsCustom(data)) { return(null); } if (data is IDataRegistryMember model) { return(ModForModelType(model.GetModelType())); } if (data is VanillaActorData actor) { return(ModdedIDRegistry.ModForID((Identifiable.Id)actor.typeId)); } if (data is VanillaGadgetData gadget) { return(ModdedIDRegistry.ModForID(gadget.gadgetId)); } if (data is VanillaLandPlotData plot) { return(ModdedIDRegistry.ModForID(plot.typeId)); } return(null); }
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 } }); } }
internal static void RegisterIDRegistry(ModdedIDRegistry registry) { moddedIdRegistries[registry.RegistryType] = registry; }