Exemple #1
0
        public static Identifiable.Id CreateIdentifiableId(object value, string name, bool shouldCategorize = true)
        {
            if (SRModLoader.CurrentLoadingStep > SRModLoader.LoadingStep.PRELOAD)
            {
                throw new Exception("Can't register identifiables outside of the PreLoad step");
            }
            var id = (Identifiable.Id)value;

            if (moddedIdentifiables.ContainsKey(id))
            {
                throw new Exception(
                          $"Identifiable {value} is already registered to {moddedIdentifiables[id].ModInfo.Id}");
            }
            var sr = SRMod.GetCurrentMod();

            if (sr != null)
            {
                moddedIdentifiables[id] = sr;
            }
            EnumPatcher.AddEnumValue(typeof(Identifiable.Id), id, name);

            if (shouldCategorize)
            {
                CategorizeId(id);
            }
            return(id);
        }
        /// <summary>
        /// Register all <see cref="PlayerAction"/>'s in a Type
        /// </summary>
        /// <param name="type">Type holding the <see cref="PlayerAction"/>'s</param>
        public static void RegisterActions(Type type)
        {
            var mod = SRMod.GetCurrentMod();

            foreach (var field in type.GetFields().Where(x => x.IsStatic && typeof(PlayerAction).IsAssignableFrom(x.FieldType)))
            {
                PlayerActionCreateDelegate del = (set) =>
                {
                    var action = new PlayerAction(field.Name, set);
                    RegisterAction(action, mod);
                    field.SetValue(null, action);
                };

                switch (SRModLoader.CurrentLoadingStep)
                {
                case SRModLoader.LoadingStep.PRELOAD:
                    precreators.Add(del);
                    break;

                default:
                    del(SRInput.Actions);
                    break;
                }
            }
        }
Exemple #3
0
 public static void FreeAllIDs()
 {
     foreach (var v in Registries)
     {
         v.UnRegisterAll(SRMod.GetCurrentMod());
     }
 }
        public static void RegisterAllEnums(Module module)
        {
            SRMod.ForceModContext(SRModLoader.GetModForAssembly(module.Assembly));
            foreach (var type in module.GetTypes())
            {
                if (type.GetCustomAttributes(true).Any((x) => x is EnumHolderAttribute))
                {
                    foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public |
                                                         BindingFlags.NonPublic))
                    {
                        if (!field.FieldType.IsEnum)
                        {
                            continue;
                        }

                        if ((int)field.GetValue(null) == 0)
                        {
                            var newVal = EnumPatcher.GetFirstFreeValue(field.FieldType);
                            EnumPatcher.AddEnumValueWithAlternatives(field.FieldType, newVal, field.Name);
                            field.SetValue(null, newVal);
                        }
                        else
                        {
                            EnumPatcher.AddEnumValueWithAlternatives(field.FieldType, field.GetValue(null), field.Name);
                        }
                    }
                }
            }
            SRMod.ClearModContext();
        }
Exemple #5
0
 public static void RegisterBasicTarget(Identifiable.Id id)
 {
     customBasicTarget.Add(id, SRMod.GetCurrentMod());
     foreach (var v in GetMetadatas())
     {
         v.targets = v.targets.AddToArray(new DroneMetadata.Program.Target.Basic(id));
     }
 }
Exemple #6
0
 internal static ModSaveInfo GetSaveInfo(SRMod mod)
 {
     if (!modToSaveInfo.ContainsKey(mod))
     {
         modToSaveInfo.Add(mod, new ModSaveInfo());
     }
     return(modToSaveInfo[mod]);
 }
Exemple #7
0
        internal static EnumTranslator GenerateEnumTranslator(SRMod mod)
        {
            var newTranslator = new EnumTranslator();

            foreach (var v in moddedIdRegistries)
            {
                newTranslator.GenerateTranslationTable(v.Value.GetIDsForMod(mod));
            }
            return(newTranslator);
        }
Exemple #8
0
        /// <summary>
        /// Register a secret style in a <see cref="SlimeDefinition"/>
        /// </summary>
        /// <param name="definition">Slime definition to register the secret style for</param>
        /// <param name="exoticAppearance">Secret style to register</param>
        public static void RegisterSecretStyle(SlimeDefinition definition, SlimeAppearance exoticAppearance)
        {
            SecretStyle ss  = new SecretStyle(definition, exoticAppearance);
            SRMod       mod = SRMod.GetCurrentMod();

            if (secretStyles.ContainsKey(ss))
            {
                throw new Exception($"{definition.IdentifiableId} already has a secret style registered by {secretStyles[ss].ModInfo.Id}");
            }
            secretStyles[ss] = mod;
        }
Exemple #9
0
        public static void PopulateConfigs(SRMod mod)
        {
            SRMod.ForceModContext(mod);

            foreach (var file in GetConfigs(mod.EntryType.Module))
            {
                mod.Configs.Add(file);
                file.TryLoadFromFile();
            }

            SRMod.ClearModContext();
        }
Exemple #10
0
 public void Pull(VanillaWorldData data, SRMod mod)
 {
     foreach (var v in data.econSaturations)
     {
         if (ModdedIDRegistry.ModForID(v.Key) == mod)
         {
             econSaturations.Add(v.Key, v.Value);
         }
     }
     pendingOfferRancherIds.AddRange(data.pendingOfferRancherIds.Where((x) => ExchangeOfferRegistry.GetModForID(x) == mod));
     lastOfferRancherIds.AddRange(data.lastOfferRancherIds.Where((x) => ExchangeOfferRegistry.GetModForID(x) == mod));
 }
Exemple #11
0
        public ModDataSegment GetSegmentForMod(SRMod mod)
        {
            if (!(segments.FirstOrDefault((x) => x.modid == mod.ModInfo.Id) is ModDataSegment seg))
            {
                var segment = new ModDataSegment();
                segment.modid = mod.ModInfo.Id;
                segments.Add(segment);
                return(segment);
            }

            return(seg);
        }
Exemple #12
0
 public HashSet <string> GetIDsForMod(SRMod mod)
 {
     if (mod == null)
     {
         return(null);
     }
     if (!TryGetValue(mod, out var set))
     {
         set       = new HashSet <string>(StringComparer.Ordinal);
         this[mod] = set;
     }
     return(set);
 }
Exemple #13
0
        /// <summary>
        /// Registers a new command into the console
        /// </summary>
        /// <param name="cmd">Command to register</param>
        /// <returns>True if registered succesfully, false otherwise</returns>
        public static bool RegisterCommand(ConsoleCommand cmd)
        {
            if (commands.ContainsKey(cmd.ID.ToLowerInvariant()))
            {
                LogWarning($"Trying to register command with id '<color=white>{cmd.ID.ToLowerInvariant()}</color>' but the ID is already registered!");
                return(false);
            }

            cmd.belongingMod = SRMod.GetCurrentMod();
            commands.Add(cmd.ID.ToLowerInvariant(), cmd);
            ConsoleWindow.cmdsText += $"{(ConsoleWindow.cmdsText.Equals(string.Empty) ? "" : "\n")}<color=#77DDFF>{ColorUsage(cmd.Usage)}</color> - {cmd.Description}";
            return(true);
        }
Exemple #14
0
        public T RegisterValue(T id)
        {
            if (ContainsKey(id))
            {
                throw new Exception(
                          $"{id} is already registered to {this[id].ModInfo.Id}");
            }
            var sr = SRMod.GetCurrentMod();

            if (sr != null)
            {
                this[id] = sr;
            }
            return(id);
        }
Exemple #15
0
        internal static Dictionary <string, List <string> > GetKeysForMod(SRMod mod)
        {
            Dictionary <string, List <string> > output = new Dictionary <string, List <string> >();

            List <string> GetListForKey(string key)
            {
                return(output.TryGetValue(key, out var list) ? list : output[key] = new List <string>());
            }

            foreach (var pair in keyToMod.Where((x) => x.Value == mod).Select((x) => x.Key))
            {
                GetListForKey(pair.Key).Add(pair.Value);
            }

            return(output);
        }
Exemple #16
0
        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));
        }
Exemple #17
0
        /// <summary>
        /// Register a slime definition in the <see cref="SlimeDefinitions"/> database
        /// </summary>
        /// <param name="definition">Slime definition to register</param>
        public static void RegisterSlimeDefinition(SlimeDefinition definition, bool refreshEatMaps = true)
        {
            slimeDefinitions[definition] = SRMod.GetCurrentMod();
            SlimeDefinitions definitions;

            switch (SRModLoader.CurrentLoadingStep)
            {
            case SRModLoader.LoadingStep.PRELOAD:
                definitions = UnityEngine.Object.FindObjectOfType <GameContext>().SlimeDefinitions;
                break;

            default:
                definitions = GameContext.Instance.SlimeDefinitions;
                break;
            }
            if (definition.IsLargo && definition.BaseSlimes != null && definition.BaseSlimes.Length == 2 && definition.BaseSlimes[0].Diet.ProducePlorts() && definition.BaseSlimes[1].Diet.ProducePlorts())
            {
                SlimeDefinitions.PlortPair pair = new SlimeDefinitions.PlortPair(definition.BaseSlimes[0].Diet.Produces[0], definition.BaseSlimes[1].Diet.Produces[0]);
                definitions.largoDefinitionByBasePlorts = definitions.largoDefinitionByBasePlorts.Where(x => !x.Key.Equals(pair)).ToDictionary(x => x.Key, y => y.Value);
                definitions.largoDefinitionByBasePlorts.Add(pair, definition);
            }
            if (definition.IsLargo && definition.BaseSlimes != null && definition.BaseSlimes.Length == 2)
            {
                SlimeDefinitions.SlimeDefinitionPair pair = new SlimeDefinitions.SlimeDefinitionPair(definition.BaseSlimes[0], definition.BaseSlimes[1]);
                definitions.largoDefinitionByBaseDefinitions = definitions.largoDefinitionByBaseDefinitions.Where(x => !x.Key.Equals(pair)).ToDictionary(x => x.Key, y => y.Value);
                definitions.largoDefinitionByBaseDefinitions.Add(pair, definition);
            }
            definitions.slimeDefinitionsByIdentifiable.Add(definition.IdentifiableId, definition);
            definitions.Slimes = definitions.Slimes.Where(x => x.IdentifiableId != definition.IdentifiableId).ToArray();
            definitions.Slimes = definitions.Slimes.AddToArray(definition);
            if (refreshEatMaps)
            {
                definition.Diet.RefreshEatMap(definitions, definition);
                if (definition.BaseSlimes != null)
                {
                    foreach (SlimeDefinition child in definition.BaseSlimes)
                    {
                        child.Diet.RefreshEatMap(definitions, child);
                    }
                }
            }
        }
Exemple #18
0
        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);
        }
Exemple #19
0
        public void Pull(PlayerV14 player, SRMod ourMod)
        {
            upgrades.AddRange(player.upgrades.Where((x) => ModdedIDRegistry.ModForID(x) == ourMod));
            availUpgrades.AddRange(player.availUpgrades.Where((x) => ModdedIDRegistry.ModForID(x) == ourMod));
            AddRange(upgradeLocks, player.upgradeLocks.Where((x) => ModdedIDRegistry.ModForID(x.Key) == ourMod));

            AddRange(progress, player.progress.Where((x) => ModdedIDRegistry.ModForID(x.Key) == ourMod));
            AddRange(delayedProgress, player.delayedProgress.Where((x) => ModdedIDRegistry.ModForID(x.Key) == ourMod));

            blueprints.AddRange(player.blueprints.Where((x) => ModdedIDRegistry.ModForID(x) == ourMod));
            availBlueprints.AddRange(player.availBlueprints.Where((x) => ModdedIDRegistry.ModForID(x) == ourMod));
            AddRange(blueprintLocks, player.blueprintLocks.Where((x) => ModdedIDRegistry.ModForID(x.Key) == ourMod));

            AddRange(gadgets, player.gadgets.Where((x) => ModdedIDRegistry.ModForID(x.Key) == ourMod));

            AddRange(craftMatCounts, player.craftMatCounts.Where((x) => ModdedIDRegistry.ModForID(x.Key) == ourMod));

            unlockedZoneMaps.AddRange(player.unlockedZoneMaps.Where((x) => ModdedIDRegistry.ModForID(x) == ourMod));

            mail.AddRange(player.mail.Where((x) => MailRegistry.GetModForMail(x.messageKey) == ourMod));
        }
Exemple #20
0
        /// <summary>
        /// Register a slime definition in the <see cref="SlimeDefinitions"/> database
        /// </summary>
        /// <param name="definition">Slime definition to register</param>
        public static void RegisterSlimeDefinition(SlimeDefinition definition)
        {
            slimeDefinitions[definition] = SRMod.GetCurrentMod();
            SlimeDefinitions definitions;

            switch (SRModLoader.CurrentLoadingStep)
            {
            case SRModLoader.LoadingStep.PRELOAD:
                definitions = UnityEngine.Object.FindObjectOfType <GameContext>().SlimeDefinitions;
                break;

            default:
                definitions = GameContext.Instance.SlimeDefinitions;
                break;
            }
            definitions.largoDefinitionByBasePlorts.Clear();
            definitions.largoDefinitionByBaseDefinitions.Clear();
            definitions.slimeDefinitionsByIdentifiable.Clear();
            definitions.Slimes = definitions.Slimes.Where(x => x.IdentifiableId != definition.IdentifiableId).ToArray();
            definitions.Slimes = definitions.Slimes.AddToArray(definition);
            definitions.OnEnable();
        }
        public static PlayerState.Upgrade CreatePersonalUpgrade(object value, string name)
        {
            if (SRModLoader.CurrentLoadingStep > SRModLoader.LoadingStep.PRELOAD)
            {
                throw new Exception("Can't register gadgets outside of the PreLoad step");
            }
            var id = (PlayerState.Upgrade)value;

            if (moddedUpgrades.ContainsKey(id))
            {
                throw new Exception(
                          $"Upgrade {value} is already registered to {moddedUpgrades[id].ModInfo.Id}");
            }
            var sr = SRMod.GetCurrentMod();

            if (sr != null)
            {
                moddedUpgrades[id] = sr;
            }
            EnumPatcher.AddEnumValue(typeof(PlayerState.Upgrade), id, name);
            return(id);
        }
Exemple #22
0
 public static CompoundDataPiece GetWorldSaveData()
 {
     return(worldSaveData.Get(SRMod.GetCurrentMod()));
 }
Exemple #23
0
 /// <summary>
 /// Add a plaintext translation for a localization key
 /// </summary>
 /// <param name="bundlename">Key bundle the localization key is located in</param>
 /// <param name="key">The localization key</param>
 /// <param name="value">The plain text translation</param>
 public static void AddTranslationKey(string bundlename, string key, string value) => AddTranslationKey(bundlename, key, value, SRMod.GetCurrentMod());
Exemple #24
0
 internal static void AddTranslationKey(string bundlename, string key, string value, SRMod mod)
 {
     if (GetPatchesFor(bundlename).ContainsKey(key))
     {
         Debug.LogWarning($"Translation key '{key}' for bundle '{bundlename}' is already taken by {keyToMod[new KeyValuePair<string, string>(bundlename, key)]}! Overwriting...");
     }
     GetPatchesFor(bundlename)[key] = value;
     SetModForTranslationKey(bundlename, key, mod);
 }
Exemple #25
0
 internal static void SetModForTranslationKey(string bundlename, string key, SRMod mod) => keyToMod[new KeyValuePair <string, string>(bundlename, key)] = mod;
Exemple #26
0
 internal static ModSaveInfo GetSaveInfo()
 {
     return(GetSaveInfo(SRMod.GetCurrentMod()));
 }
Exemple #27
0
 public static void RegisterWorldDataLoadDelegate(WorldDataLoadDelegate del)
 {
     GetSaveInfo(SRMod.GetCurrentMod()).OnDataLoad += del;
 }
Exemple #28
0
 public static void RegisterOfferID(string id)
 {
     customOfferIDs.Add(id, SRMod.GetCurrentMod());
 }
Exemple #29
0
 public static void RegisterRancher(string id)
 {
     customRanchers.Add(id, SRMod.GetCurrentMod());
 }
Exemple #30
0
        internal static CompoundDataPiece GetDataForCurrentMod(CompoundDataPiece piece)
        {
            var strin = SRMod.GetCurrentMod().ModInfo.Id;

            return(ExtendedDataUtils.GetPieceForMod(strin, piece));
        }