public override List <string> GetAutoComplete(int argIndex, string argText) { if (argIndex == 0) { return(SRModLoader.GetMods().Where(x => x.Configs.Count > 0).Select(x => x.ModInfo.Id).ToList()); } var strs = ConsoleWindow.cmdText.Split(' '); var mod = SRModLoader.GetMod(strs[1]); if (argIndex == 1) { return(mod?.Configs.Select(x => x.FileName).ToList()); } var config = mod?.Configs.FirstOrDefault(x => x.FileName.ToLower() == strs[2].ToLower()); if (argIndex == 2) { return(config?.Sections.Select(x => x.Name).ToList()); } var section = config?.Sections.FirstOrDefault(x => x.Name.ToLower() == strs[3].ToLower()); if (argIndex == 3) { return(section?.Elements.Select(x => x.Options.Name).ToList()); } return(base.GetAutoComplete(argIndex, argText)); }
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; } } }
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 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); }
internal static SRMod GetModForIdentifier(AmmoIdentifier id) { switch (id.AmmoType) { case AmmoType.PLAYER: return(ModdedIDRegistry.ModForID((PlayerState.AmmoMode)(int) id.longIdentifier)); case AmmoType.LANDPLOT: return(ModdedIDRegistry.ModForID((SiloStorage.StorageType)(int) id.longIdentifier)); } return(id.AmmoType.IsCustom() ? SRModLoader.GetMod(id.custommodid) : null); }
internal static SRMod GetModForModdedString(string str) { if (!StringRegistry.IsLongForm(str)) { return(null); } StringRegistry.ParseLongForm(str, out var prefix, out var modid, out var id); var mod = SRModLoader.GetMod(modid); if (!GetRegistry(prefix).Contains(mod, id)) { return(null); } return(mod); }
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); } } }
internal static void CullMissingModsFromData(CompoundDataPiece piece) { List <DataPiece> toRemove = new List <DataPiece>(); foreach (var v in piece.DataList) { if (SRModLoader.GetMod(v.key) == null) { toRemove.Add(v); } } foreach (var v in toRemove) { piece.DataList.Remove(v); } }
public override bool Execute(string[] args) { var mod = SRModLoader.GetMod(args[0]); var config = mod.Configs.First(x => x.FileName.ToLower() == args[1].ToLower()); var section = config.Sections.First(x => x.Name.ToLower() == args[2].ToLower()); var element = section.Elements.First(x => x.Options.Name.ToLower() == args[3].ToLower()); if (args.Length >= 5) { element.SetValue(element.Options.Parser.ParseObject(args[4])); //Debug.Log(element.GetValue<object>()+" "+element.GetType()+"!"); } else { Console.Log("Current Value: " + element.Options.Parser.EncodeObject(element.GetValue <object>())); } SRMod.ForceModContext(mod); config.SaveToFile(); SRMod.ClearModContext(); return(true); }
internal static void Push(ModdedSaveData data) { foreach (var actorData in extendedActorData) { 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, identifier = actorData.Key, idType = ExtendedDataTree.IdentifierType.ACTOR }); } } }