Пример #1
0
        public static void Init(string directory, string settingsJSON)
        {
            Logger = HBS.Logging.Logger.GetLogger("CustomFilters", LogLevel.Debug);

            try
            {
                try
                {
                    Settings = new CustomFiltersSettings();
                    JSONSerializationUtility.FromJSON(Settings, settingsJSON);
                    HBS.Logging.Logger.SetLoggerLevel(Logger.Name, Settings.LogLevel);
                }
                catch (Exception)
                {
                    Settings = new CustomFiltersSettings();
                }

                Settings.Complete();
                SetupLogging(directory);

                var harmony = HarmonyInstance.Create("io.github.denadan.CustomFilters");
                harmony.PatchAll(Assembly.GetExecutingAssembly());

                Logger.Log("Loaded CustomFilters v0.1 for bt 1.6.2");

                CustomComponents.Registry.RegisterSimpleCustomComponents(Assembly.GetExecutingAssembly());

                Logger.LogDebug("done");
                Logger.LogDebug(JSONSerializationUtility.ToJSON(Settings));
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
Пример #2
0
 public static void Start(string modDirectory, string json)
 {
     try
     {
         var hasModTek = GetAssemblyByName("ModTek") != null;
         if (!hasModTek)
         {
             throw new InvalidOperationException("This mod is for ModTek only and does not run under ModLoader");
         }
         JSONSerializationUtility.FromJSON(settings, json);
         if (settings.MigrateSavesToVanillaLocation)
         {
             throw new InvalidOperationException("MigrateSavesToVanillaLocation not yet implemented");
             // TODO how to know what location to use?
             // cloud vs local
             // gog vs steam vs more?
         }
         else
         {
             Control.Logger.Log($"Saving to folder {NewSaveFolderFeature.SavesPath}");
             var harmony = HarmonyInstance.Create(Name);
             harmony.PatchAll(Assembly.GetExecutingAssembly());
         }
     }
     catch (Exception e)
     {
         Control.Logger.LogError(e);
     }
 }
Пример #3
0
 public void SaveSettings <T>(T settings) where T : ModSettings
 {
     using (var writer = new StreamWriter(SettingsPath))
     {
         var json = JSONSerializationUtility.ToJSON(settings);
         writer.Write(json);
     }
 }
Пример #4
0
        private void init(string directory, string settingsJSON)
        {
            try
            {
                Logger = HBS.Logging.Logger.GetLogger(ModName, LogLevel.Debug);
                try
                {
                    Settings = new Settings();
                    JSONSerializationUtility.FromJSON(Settings, settingsJSON);
                    HBS.Logging.Logger.SetLoggerLevel(Logger.Name, LogLevel.Debug);
                }
                catch (Exception)
                {
                    Settings = new Settings();
                }

                if (!Settings.AddLogPrefix)
                {
                    LogPrefix = "";
                }

                SetupLogging(directory);

                var harmony = HarmonyInstance.Create($"{ModName}");
                harmony.PatchAll(Assembly.GetExecutingAssembly());
                Logger.Log("=========================================================");
                Logger.Log($"Loaded {ModName} v0.5 for bt 1.9");
                Logger.Log("=========================================================");

                if (Settings.ShowSettingsOnLoad)
                {
                    Logger.LogDebug(JSONSerializationUtility.ToJSON(Settings));
                }
                CustomComponents.Registry.RegisterSimpleCustomComponents(Assembly.GetExecutingAssembly());

                if (Settings.FixMechPartCost)
                {
                    CustomComponents.AutoFixer.Shared.RegisterMechFixer(Extentions.FixVehicleCost, Settings.FakeVehicleTag);
                }
                if (Settings.FixUIName)
                {
                    CustomComponents.AutoFixer.Shared.RegisterMechFixer(Extentions.FixVehicleUIName, Settings.FakeVehicleTag);
                }
                if (Settings.AddWeaponToDescription)
                {
                    CustomComponents.AutoFixer.Shared.RegisterMechFixer(Extentions.FixDescription, Settings.FakeVehicleTag);
                }

                Logger.LogDebug("done");
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
Пример #5
0
        public void LoadSettings(object settings)
        {
            if (!File.Exists(SettingsPath))
            {
                return;
            }

            using (var reader = new StreamReader(SettingsPath))
            {
                var json = reader.ReadToEnd();
                JSONSerializationUtility.FromJSON(settings, json);
            }
        }
Пример #6
0
        public static IEnumerable <T> Enumerate <T>(
            string resourceType,
            Dictionary <string, Dictionary <string, VersionManifestEntry> > customResources)
        {
            if (customResources == null)
            {
                Control.LogDebug(DType.CustomResource, $"customResources not found");
                yield break;
            }

            if (!customResources.TryGetValue(resourceType, out var entries))
            {
                Control.LogDebug(DType.CustomResource, $"{resourceType} not found");
                yield break;
            }

            foreach (var entry in entries.Values)
            {
                var settings = new SettingsResource <T>();
                try
                {
                    Control.LogDebug(DType.CustomResource, $"Reading {entry.FilePath}");
                    using (var reader = new StreamReader(entry.FilePath))
                    {
                        var json = reader.ReadToEnd();
                        JSONSerializationUtility.FromJSON(settings, json);
                    }
                }
                catch (Exception e)
                {
                    Control.LogDebug(DType.CustomResource, $"Couldn't read {entry.FilePath}", e);
                }

                if (settings.Settings == null)
                {
                    Control.LogDebug(DType.CustomResource, $"Settings is null in {entry.FilePath}");
                    continue;
                }

                Control.LogDebug(DType.CustomResource, $" - total {settings.Settings.Count} entries loaded");

                foreach (var settingsEntry in settings.Settings)
                {
                    yield return(settingsEntry);
                }
            }
        }
Пример #7
0
        public static void Init(string directory, string settingsJSON)
        {
            var harmony = HarmonyInstance.Create("com.joelmeador.MechResizer");

            harmony.PatchAll(Assembly.GetExecutingAssembly());

            ModDirectory = directory;
            try
            {
                JSONSerializationUtility.FromJSON(ModSettings, settingsJSON);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                ModSettings = new Settings();
            }
        }
Пример #8
0
        internal void LoadSettings(object settings)
        {
            if (!File.Exists(SettingsPath))
            {
                return;
            }

            try
            {
                using var reader = new StreamReader(SettingsPath);
                var json = reader.ReadToEnd();
                JSONSerializationUtility.FromJSON(settings, json);
            }
            catch (Exception e)
            {
                WriteStartupError(e);
            }
        }
 internal static void EmbeddedSettingsJSON(string settingsJSON)
 {
     // test if embedded mod.json settings work
     try
     {
         var settings = new Settings();
         JSONSerializationUtility.FromJSON(settings, settingsJSON);
         if (settings.OldSchoolSettingsKey == "It works")
         {
             Control.Logger.Log($"{LogPrefix}Parsing embedded json works.");
         }
         else
         {
             Control.Logger.LogError($"{LogPrefix}Embedded settings could not be read, didn't find {nameof(Settings.OldSchoolSettingsKey)}='It works', json data is: {settingsJSON}.");
         }
     }
     catch (Exception e)
     {
         Control.Logger.LogError($"{LogPrefix}Couldn't load embedded json, json data is: {settingsJSON}", e);
     }
 }
Пример #10
0
        public static void FinishedLoading(Dictionary <string, Dictionary <string, VersionManifestEntry> > customResources)
        {
            if (customResources.ContainsKey(nameof(ForcedTimelineEvent)))
            {
                foreach (var entry in customResources[nameof(ForcedTimelineEvent)].Values)
                {
                    ForcedEvents.ForcedTimelineEvents.Add(SerializeUtil.FromPath <ForcedTimelineEvent>(entry.FilePath));
                }
            }

            if (customResources.ContainsKey(nameof(ItemCollectionRequirement)))
            {
                foreach (var entry in customResources[nameof(ItemCollectionRequirement)].Values)
                {
                    // have to use fastJSON because requirementDefs are very picky apparently
                    var itemReq = new ItemCollectionRequirement();
                    JSONSerializationUtility.FromJSON(itemReq, File.ReadAllText(entry.FilePath));
                    ItemCollectionRequirements.ShopItemRequirements.Add(itemReq.ItemID, itemReq.RequirementDef);
                }
            }
        }
Пример #11
0
 public static void Prefix(MechComponentDef __instance, ref string json)
 {
     try {
         JObject content = JObject.Parse(json);
         if (content["Auras"] != null)
         {
             Log.Debug?.Write("Auras WeaponDef:" + content["Description"]["Id"] + "\n");
             if (content["Auras"].Type == JTokenType.Array)
             {
                 List <AuraDef> auras  = new List <AuraDef>();
                 JToken         jauras = content["Auras"];
                 foreach (JObject jaura in jauras)
                 {
                     AuraDef aura = JsonConvert.DeserializeObject <AuraDef>(jaura.ToString());
                     if (jaura["statusEffects"] != null)
                     {
                         if (jaura["statusEffects"].Type == JTokenType.Array)
                         {
                             JToken statusEffects = jaura["statusEffects"];
                             aura.statusEffects = new List <EffectData>();
                             foreach (JObject statusEffect in statusEffects)
                             {
                                 EffectData effect = new EffectData();
                                 JSONSerializationUtility.FromJSON <EffectData>(effect, statusEffect.ToString());
                                 aura.statusEffects.Add(effect);
                             }
                         }
                     }
                     auras.Add(aura);
                 }
                 __instance.AddAuras(auras);
             }
             content.Remove("Auras");
         }
         json = content.ToString();
     } catch (Exception e) {
         Log.Debug?.Write("Error:" + e.ToString() + "\n");
         Log.Debug?.Write("IN:" + json + "\n");
     }
 }
Пример #12
0
        public void LoadSettings <T>(T settings) where T : Settings
        {
            try
            {
                string SettingsPath = "mods/AddYearToTimeline/Settings.json";

                if (!File.Exists(SettingsPath))
                {
                    return;
                }

                using (var reader = new StreamReader(SettingsPath))
                {
                    var json = reader.ReadToEnd();
                    JSONSerializationUtility.FromJSON(settings, json);
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
Пример #13
0
        public void LoadSettings <T>(T settings) where T : ModSettings
        {
            if (!File.Exists(SettingsPath))
            {
                return;
            }

            using (var reader = new StreamReader(SettingsPath))
            {
                var json = reader.ReadToEnd();
                JSONSerializationUtility.FromJSON(settings, json);
            }

            var logLevelString = settings.logLevel;

            DebugBridge.StringToLogLevel(logLevelString, out var level);
            if (level == null)
            {
                level = LogLevel.Debug;
            }
            HBS.Logging.Logger.SetLoggerLevel(Name, level);
        }
Пример #14
0
 internal static void AddedCustomEntry(Dictionary <string, Dictionary <string, VersionManifestEntry> > customResources)
 {
     try
     {
         var manifest = customResources["MTTResource"];
         var entry    = manifest["MTTType_ModTekTest"];
         var json     = File.ReadAllText(entry.FilePath);
         var customs  = new Customs();
         JSONSerializationUtility.FromJSON(customs, json);
         if (customs.Entries[0].id == "first entry")
         {
             Control.Logger.Log($"{LogPrefix}customResources works.");
         }
         else
         {
             Control.Logger.LogError($"{LogPrefix}Could not find 'first entry' in custom resource.");
         }
     }
     catch (Exception e)
     {
         Control.Logger.LogError($"{LogPrefix}Couldn't read custom resource", e);
     }
 }
 public override string ToJSON()
 {
     return(JSONSerializationUtility.ToJSON <SetChunkStateAtRandomActivator>(this));
 }
 public override void FromJSON(string json)
 {
     JSONSerializationUtility.FromJSON <SetChunkStateAtRandomActivator>(this, json);
 }
 public override string GenerateJSONTemplate()
 {
     return(JSONSerializationUtility.ToJSON <SetChunkStateAtRandomActivator>(new SetChunkStateAtRandomActivator()));
 }
 public override string GenerateJSONTemplate()
 {
     return(JSONSerializationUtility.ToJSON <CustomPlayerLanceSpawnerGameLogic>(new CustomPlayerLanceSpawnerGameLogic()));
 }
        public virtual IEnumerable <ICustom> Create(object target, Dictionary <string, object> values)
        {
            if (!(target is TDef def))
            {
                yield break;
            }

            if (!values.TryGetValue(Control.CustomSectionName, out var customSettingsObject))
            {
                yield break;
            }

            if (!(customSettingsObject is Dictionary <string, object> customSettings))
            {
                yield break;
            }

            if (!customSettings.TryGetValue(CustomName, out var componentSettingsObject))
            {
                yield break;
            }


#if CCDEBUG
            Control.Logger.LogDebug($"Factory {CustomName} for {customSettingsObject})");
#endif
            if (componentSettingsObject is Dictionary <string, object> compDictionary)
            {
#if CCDEBUG
                Control.Logger.LogDebug($"-- Dictionary - return one {compDictionary}");
                foreach (var pair in compDictionary)
                {
                    Control.Logger.LogDebug($"---- {pair.Key}: {pair.Value}");
                }
#endif
                var obj = new TCustom();
                JSONSerializationUtility.RehydrateObjectFromDictionary(obj, compDictionary);
                obj.Def = def;

                yield return(obj);
            }
            else if (componentSettingsObject is IEnumerable <object> compList)
            {
#if CCDEBUG
                Control.Logger.LogDebug($"-- List - return {compList.Count()} items {compList}");
#endif
                foreach (var item in compList)
                {
                    if (item is Dictionary <string, object> compDictItem)
                    {
                        var obj = new TCustom();
                        JSONSerializationUtility.RehydrateObjectFromDictionary(obj, compDictItem);
                        obj.Def = def;

#if CCDEBUG
                        Control.Logger.LogDebug($"---- Factory for {obj}");
#endif

                        yield return(obj);
                    }
                }
            }
        }
Пример #20
0
 public override string GenerateJSONTemplate()
 {
     return(JSONSerializationUtility.ToJSON <DisablePilotDeathGameLogic>(new DisablePilotDeathGameLogic()));
 }
Пример #21
0
 public override string ToJSON()
 {
     return(JSONSerializationUtility.ToJSON <DisablePilotDeathGameLogic>(this));
 }
Пример #22
0
 public void FromJSON(string json)
 {
     JSONSerializationUtility.FromJSON(this, json);
 }
Пример #23
0
 public string GenerateJSONTemplate()
 {
     return(JSONSerializationUtility.ToJSON(new ModEntry("")));
 }
Пример #24
0
 public override string ToJSON()
 {
     return(JSONSerializationUtility.ToJSON <LanceSpawnedMessage>(this));
 }
Пример #25
0
        public static bool Prefix(AmmunitionDef __instance, ref string json)
        {
            CustomAmmoCategoriesLog.Log.LogWrite("AmmunitionDef fromJSON ");
            JObject defTemp = JObject.Parse(json);

            CustomAmmoCategoriesLog.Log.LogWrite(defTemp["Description"]["Id"] + "\n");
            CustomAmmoCategory custCat = CustomAmmoCategories.find((string)defTemp["Category"]);

            //CustomAmmoCategories.RegisterAmmunition((string)defTemp["Description"]["Id"], custCat);
            defTemp["Category"] = custCat.BaseCategory.ToString();
            ExtAmmunitionDef extAmmoDef = new ExtAmmunitionDef();

            extAmmoDef.AmmoCategory = custCat;
            if (defTemp["AccuracyModifier"] != null)
            {
                extAmmoDef.AccuracyModifier = (float)defTemp["AccuracyModifier"];
                defTemp.Remove("AccuracyModifier");
            }
            if (defTemp["DamagePerShot"] != null)
            {
                extAmmoDef.DamagePerShot = (float)defTemp["DamagePerShot"];
                defTemp.Remove("DamagePerShot");
            }
            if (defTemp["HeatDamagePerShot"] != null)
            {
                extAmmoDef.HeatDamagePerShot = (float)defTemp["HeatDamagePerShot"];
                defTemp.Remove("HeatDamagePerShot");
            }
            if (defTemp["ProjectilesPerShot"] != null)
            {
                extAmmoDef.ProjectilesPerShot = (int)defTemp["ProjectilesPerShot"];
                defTemp.Remove("ProjectilesPerShot");
            }
            if (defTemp["ShotsWhenFired"] != null)
            {
                extAmmoDef.ShotsWhenFired = (int)defTemp["ShotsWhenFired"];
                defTemp.Remove("ShotsWhenFired");
            }
            if (defTemp["CriticalChanceMultiplier"] != null)
            {
                extAmmoDef.CriticalChanceMultiplier = (float)defTemp["CriticalChanceMultiplier"];
                defTemp.Remove("CriticalChanceMultiplier");
            }
            if (defTemp["AIBattleValue"] != null)
            {
                extAmmoDef.AIBattleValue = (int)defTemp["AIBattleValue"];
                defTemp.Remove("AIBattleValue");
            }
            if (defTemp["MinRange"] != null)
            {
                extAmmoDef.MinRange = (float)defTemp["MinRange"];
                defTemp.Remove("MinRange");
            }
            if (defTemp["MaxRange"] != null)
            {
                extAmmoDef.MaxRange = (float)defTemp["MaxRange"];
                defTemp.Remove("MaxRange");
            }
            if (defTemp["ShortRange"] != null)
            {
                extAmmoDef.ShortRange = (float)defTemp["ShortRange"];
                defTemp.Remove("ShortRange");
            }
            if (defTemp["MediumRange"] != null)
            {
                extAmmoDef.MediumRange = (float)defTemp["MediumRange"];
                defTemp.Remove("MediumRange");
            }
            if (defTemp["LongRange"] != null)
            {
                extAmmoDef.LongRange = (float)defTemp["LongRange"];
                defTemp.Remove("LongRange");
            }
            if (defTemp["ForbiddenRange"] != null)
            {
                extAmmoDef.ForbiddenRange = (float)defTemp["ForbiddenRange"];
                defTemp.Remove("ForbiddenRange");
            }
            if (defTemp["RefireModifier"] != null)
            {
                extAmmoDef.RefireModifier = (int)defTemp["RefireModifier"];
                defTemp.Remove("RefireModifier");
            }
            if (defTemp["Instability"] != null)
            {
                extAmmoDef.Instability = (float)defTemp["Instability"];
                defTemp.Remove("Instability");
            }
            if (defTemp["AttackRecoil"] != null)
            {
                extAmmoDef.AttackRecoil = (int)defTemp["AttackRecoil"];
                defTemp.Remove("AttackRecoil");
            }
            if (defTemp["WeaponEffectID"] != null)
            {
                extAmmoDef.WeaponEffectID = (string)defTemp["WeaponEffectID"];
                defTemp.Remove("WeaponEffectID");
            }
            if (defTemp["EvasivePipsIgnored"] != null)
            {
                extAmmoDef.EvasivePipsIgnored = (float)defTemp["EvasivePipsIgnored"];
                defTemp.Remove("EvasivePipsIgnored");
            }
            if (defTemp["FlatJammingChance"] != null)
            {
                extAmmoDef.FlatJammingChance = (float)defTemp["FlatJammingChance"];
                defTemp.Remove("FlatJammingChance");
            }
            if (defTemp["GunneryJammingBase"] != null)
            {
                extAmmoDef.GunneryJammingBase = (float)defTemp["GunneryJammingBase"];
                defTemp.Remove("GunneryJammingBase");
            }
            if (defTemp["GunneryJammingMult"] != null)
            {
                extAmmoDef.GunneryJammingMult = (float)defTemp["GunneryJammingMult"];
                defTemp.Remove("GunneryJammingMult");
            }
            if (defTemp["IndirectFireCapable"] != null)
            {
                extAmmoDef.IndirectFireCapable = ((bool)defTemp["IndirectFireCapable"] == true) ? TripleBoolean.True : TripleBoolean.False;
                defTemp.Remove("IndirectFireCapable");
            }
            if (defTemp["DirectFireModifier"] != null)
            {
                extAmmoDef.DirectFireModifier = (float)defTemp["DirectFireModifier"];
                defTemp.Remove("DirectFireModifier");
            }
            if (defTemp["AOECapable"] != null)
            {
                extAmmoDef.AOECapable = ((bool)defTemp["AOECapable"] == true) ? TripleBoolean.True : TripleBoolean.False;
                defTemp.Remove("AOECapable");
            }
            if (defTemp["DistantVariance"] != null)
            {
                extAmmoDef.DistantVariance = (float)defTemp["DistantVariance"];
                defTemp.Remove("DistantVariance");
            }
            if (defTemp["AlwaysIndirectVisuals"] != null)
            {
                extAmmoDef.AlwaysIndirectVisuals = ((bool)defTemp["AlwaysIndirectVisuals"] == true) ? TripleBoolean.True : TripleBoolean.False;
                defTemp.Remove("AlwaysIndirectVisuals");
            }
            if (defTemp["DamageMultiplier"] != null)
            {
                extAmmoDef.DamageMultiplier = (float)defTemp["DamageMultiplier"];
                defTemp.Remove("DamageMultiplier");
            }
            if (defTemp["DistantVarianceReversed"] != null)
            {
                extAmmoDef.DistantVarianceReversed = ((bool)defTemp["DistantVarianceReversed"] == true) ? TripleBoolean.True : TripleBoolean.False;
                defTemp.Remove("DistantVarianceReversed");
            }
            if (defTemp["DamageVariance"] != null)
            {
                extAmmoDef.DamageVariance = (float)defTemp["DamageVariance"];
                defTemp.Remove("DamageVariance");
            }
            if (defTemp["HitGenerator"] != null)
            {
                try {
                    extAmmoDef.HitGenerator = (HitGeneratorType)Enum.Parse(typeof(HitGeneratorType), (string)defTemp["HitGenerator"], true);
                } catch (Exception e) {
                    extAmmoDef.HitGenerator = HitGeneratorType.NotSet;
                }
                defTemp.Remove("HitGenerator");
            }
            if (defTemp["statusEffects"] != null)
            {
                if (defTemp["statusEffects"].Type == JTokenType.Array)
                {
                    List <EffectData> tmpList       = new List <EffectData>();
                    JToken            statusEffects = defTemp["statusEffects"];
                    foreach (JObject statusEffect in statusEffects)
                    {
                        EffectData effect = new EffectData();
                        JSONSerializationUtility.FromJSON <EffectData>(effect, statusEffect.ToString());
                        tmpList.Add(effect);
                    }
                    extAmmoDef.statusEffects = tmpList.ToArray();
                }
                //extAmmoDef.statusEffects = JsonConvert.DeserializeObject<EffectData[]>(defTemp["statusEffects"].ToString());
                //JSONSerializationUtility.FromJSON<EffectData[]>(extAmmoDef.statusEffects, defTemp["statusEffects"].ToString());
                //CustomAmmoCategoriesLog.Log.LogWrite(JsonConvert.SerializeObject(extAmmoDef.statusEffects)+"\n");
                defTemp.Remove("statusEffects");
            }
            CustomAmmoCategories.RegisterExtAmmoDef((string)defTemp["Description"]["Id"], extAmmoDef);
            json = defTemp.ToString();
            return(true);
        }
 public override string ToJSON()
 {
     return(JSONSerializationUtility.ToJSON(this));
 }
Пример #27
0
 public override void FromJSON(string json)
 {
     JSONSerializationUtility.FromJSON <LanceSpawnedMessage>(this, json);
 }
Пример #28
0
 public override void FromJSON(string json)
 {
     JSONSerializationUtility.FromJSON <DisablePilotDeathGameLogic>(this, json);
 }
 public override string GenerateJSONTemplate()
 {
     return(JSONSerializationUtility.ToJSON(new SystemModDef()));
 }
Пример #30
0
 public override string GenerateJSONTemplate()
 {
     return(JSONSerializationUtility.ToJSON <LanceSpawnedMessage>(new LanceSpawnedMessage(string.Empty, string.Empty)));
 }