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 void Postfix(Ammo __instance, bool __result, Identifiable.Id id, Identifiable identifiable, int slotIdx, int count, bool overflow) { if (!__result) { return; } if (AmmoIdentifier.TryGetIdentifier(__instance, out var identifier)) { if (identifiable && ExtendedData.IsRegistered(identifiable.gameObject)) { var ammo = PersistentAmmoManager.GetPersistentAmmoForAmmo(__instance.ammoModel); for (int i = 0; i < count; i++) { ammo.DataModel.slots[slotIdx] .PushTop(ExtendedData.extendedActorData[identifiable.GetActorId()]); } } else { if (!PersistentAmmoManager.HasPersistentAmmo(identifier)) { return; } var ammo = PersistentAmmoManager.PersistentAmmoData[identifier]; for (int i = 0; i < count; i++) { ammo.DataModel.slots[slotIdx].PushTop(null); } } } }
public static void PushModdedData(GameV09 game) { foreach (var mod in data.segments) { Debug.Log($"Splicing data from mod {mod.modid} which {mod.identifiableData.Count} pieces of identifiable data"); foreach (var customData in mod.identifiableData) { switch (customData.dataID.Type) { case IdentifierType.ACTOR: game.actors.Add((VanillaActorData)customData.data); break; case IdentifierType.GADGET: game.world.placedGadgets[customData.dataID.stringID] = (VanillaGadgetData)customData.data; break; default: throw new NotImplementedException(); } } mod.playerData.Push(game.player); mod.pediaData.Push(game.pedia); foreach (var ammo in mod.customAmmo) { AmmoDataUtils.SpliceAmmoData(AmmoIdentifier.ResolveToData(ammo.Key, game), ammo.Value); } } ExtendedData.Pull(data); PersistentAmmoManager.Pull(data); }
internal static void OnAmmoDecrement(AmmoIdentifier id, int slot, int count) { PersistentAmmoData[id].OnDecrement(slot, count); if (PersistentAmmoData[id].DataModel.HasNoData()) { PersistentAmmoData.Remove(id); } }
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 static void Postfix(Ammo __instance, int amount) { if (AmmoIdentifier.TryGetIdentifier(__instance, out var identifier)) { if (PersistentAmmoManager.HasPersistentAmmo(identifier)) { PersistentAmmoManager.OnAmmoDecrement(identifier, __instance.selectedAmmoIdx, amount); } } }
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); }
private static void PushSegmentAmmoData(Game game, ModDataSegment mod) { foreach (var ammo in mod.customAmmo) { if (!ammo.Key.IsValid()) { continue; } AmmoDataUtils.SpliceAmmoData(AmmoIdentifier.ResolveToData(ammo.Key, game), ammo.Value); } }
internal static void Pull(ModdedSaveData data) { PersistentAmmoData.Clear(); AmmoIdentifier.ClearCache(); foreach (var v in data.ammoDataEntries) { if (v.model.HasNoData()) { continue; } PersistentAmmoData[v.identifier] = new PersistentAmmo(v.identifier, v.model); } }
public static void Postfix(Ammo __instance, int idx, bool __result) { if (idx < __instance.ammoModel.usableSlots) { if (AmmoIdentifier.TryGetIdentifier(__instance, out var identifier)) { if (PersistentAmmoManager.HasPersistentAmmo(identifier)) { PersistentAmmoManager.PersistentAmmoData[identifier].OnSelected(__instance.GetSelectedId(), __instance.selectedAmmoIdx); } } } }
internal static PersistentAmmo GetPersistentAmmoForAmmo(AmmoModel model) { var identifier = AmmoIdentifier.GetIdentifier(model); if (identifier.AmmoType == AmmoType.NONE) { return(null); } if (!PersistentAmmoData.ContainsKey(identifier)) { var newData = new PersistentAmmo(identifier, new PersistentAmmoModel(model)); PersistentAmmoData.Add(identifier, newData); newData.Sync(); } return(PersistentAmmoData[identifier]); }
public static void Postfix(Ammo __instance, GameObject __result) { if (!__result) { return; } if ((new StackFrame(2)).GetMethod().DeclaringType == typeof(VacColorAnimator)) { return; } if (AmmoIdentifier.TryGetIdentifier(__instance, out var identifier)) { if (PersistentAmmoManager.HasPersistentAmmo(identifier)) { PersistentAmmoManager.PersistentAmmoData[identifier].OnSelected(Identifiable.GetId(__result), __instance.selectedAmmoIdx); } } }
public static void Postfix(Ammo __instance, bool __result, Identifiable.Id id, Identifiable identifiable) { if (!__result) { return; } if (AmmoIdentifier.TryGetIdentifier(__instance, out var identifier)) { var count = -1; for (int i = 0; i < __instance.Slots.Length; i++) { if (__instance.Slots[i]?.id == id) { count = i; break; } } if (count == -1) { throw new Exception(); } if (identifiable && ExtendedData.HasExtendedData(identifiable.gameObject)) { var ammo = PersistentAmmoManager.GetPersistentAmmoForAmmo(__instance.ammoModel); ammo.DataModel.slots[count].PushTop(ExtendedData.ReadDataFromGameObject(identifiable.gameObject)); ammo.Sync(); } else { if (!PersistentAmmoManager.HasPersistentAmmo(identifier)) { return; } var ammo = PersistentAmmoManager.GetPersistentAmmoForAmmo(__instance.ammoModel); ammo.DataModel.slots[count].PushTop(null); ammo.Sync(); } } }
public static void Postfix(Ammo __instance, bool __result, Identifiable.Id id, Identifiable identifiable, int slotIdx, int count, bool overflow) { if (!__result) { return; } if (AmmoIdentifier.TryGetIdentifier(__instance, out var identifier)) { if (identifiable && ExtendedData.HasExtendedData(identifiable.gameObject)) { var ammo = PersistentAmmoManager.GetPersistentAmmoForAmmo(__instance.ammoModel); if (ammo == null) { return; } for (int i = 0; i < count; i++) { ammo.DataModel.slots[slotIdx] .PushTop(ExtendedData.ReadDataFromGameObject(identifiable.gameObject)); } ammo.Sync(); } else { if (!PersistentAmmoManager.HasPersistentAmmo(identifier)) { return; } var ammo = PersistentAmmoManager.PersistentAmmoData[identifier]; for (int i = 0; i < count; i++) { ammo.DataModel.slots[slotIdx].PushTop(null); } ammo.Sync(); } } }
public void Write(BinaryWriter writer) { AmmoIdentifier.Write(identifier, writer); model.Write(writer); }
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); }
internal static bool HasPersistentAmmo(AmmoIdentifier id) { return(PersistentAmmoData.ContainsKey(id)); }
internal static void Clear() { PersistentAmmoData.Clear(); AmmoIdentifier.ClearCache(); }
public PersistentAmmo(AmmoIdentifier identifier, PersistentAmmoModel model) { this.Identifier = identifier; this.DataModel = model; }
public void Read(BinaryReader reader) { identifier = AmmoIdentifier.Read(reader); model.Read(reader); }
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)); }