Beispiel #1
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);
     }
 }
Beispiel #2
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);
            }
        }
        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);
            }
        }
Beispiel #4
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);
            }
        }
Beispiel #5
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);
                }
            }
        }
Beispiel #6
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();
            }
        }
Beispiel #7
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);
            }
        }
Beispiel #8
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);
                }
            }
        }
 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);
     }
 }
Beispiel #10
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");
     }
 }
Beispiel #11
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);
            }
        }
Beispiel #12
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);
        }
Beispiel #13
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 void FromJSON(string json)
 {
     JSONSerializationUtility.FromJSON <SwapPlacementGameLogic>(this, json);
 }
Beispiel #15
0
        public void fromJSON(string json)
        {
            JObject jWeaponMode = JObject.Parse(json);

            if (jWeaponMode["Id"] != null)
            {
                this.Id = (string)jWeaponMode["Id"];
            }
            if (jWeaponMode["UIName"] != null)
            {
                this.UIName = (string)jWeaponMode["UIName"];
            }
            if (jWeaponMode["AccuracyModifier"] != null)
            {
                this.AccuracyModifier = (float)jWeaponMode["AccuracyModifier"];
            }
            if (jWeaponMode["DamagePerShot"] != null)
            {
                this.DamagePerShot = (float)jWeaponMode["DamagePerShot"];
            }
            if (jWeaponMode["HeatDamagePerShot"] != null)
            {
                this.HeatDamagePerShot = (float)jWeaponMode["HeatDamagePerShot"];
            }
            if (jWeaponMode["HeatGenerated"] != null)
            {
                this.HeatGenerated = (int)jWeaponMode["HeatGenerated"];
            }
            if (jWeaponMode["ProjectilesPerShot"] != null)
            {
                this.ProjectilesPerShot = (int)jWeaponMode["ProjectilesPerShot"];
            }
            if (jWeaponMode["ShotsWhenFired"] != null)
            {
                this.ShotsWhenFired = (int)jWeaponMode["ShotsWhenFired"];
            }
            if (jWeaponMode["CriticalChanceMultiplier"] != null)
            {
                this.CriticalChanceMultiplier = (float)jWeaponMode["CriticalChanceMultiplier"];
            }
            if (jWeaponMode["AIBattleValue"] != null)
            {
                this.AIBattleValue = (int)jWeaponMode["AIBattleValue"];
            }
            if (jWeaponMode["MinRange"] != null)
            {
                this.MinRange = (float)jWeaponMode["MinRange"];
            }
            if (jWeaponMode["MaxRange"] != null)
            {
                this.MaxRange = (float)jWeaponMode["MaxRange"];
            }
            if (jWeaponMode["ShortRange"] != null)
            {
                this.ShortRange = (float)jWeaponMode["ShortRange"];
            }
            if (jWeaponMode["ForbiddenRange"] != null)
            {
                this.ForbiddenRange = (float)jWeaponMode["ForbiddenRange"];
            }
            if (jWeaponMode["MediumRange"] != null)
            {
                this.MediumRange = (float)jWeaponMode["MediumRange"];
            }
            if (jWeaponMode["LongRange"] != null)
            {
                this.LongRange = (float)jWeaponMode["LongRange"];
            }
            if (jWeaponMode["RefireModifier"] != null)
            {
                this.RefireModifier = (int)jWeaponMode["RefireModifier"];
            }
            if (jWeaponMode["isBaseMode"] != null)
            {
                this.isBaseMode = (bool)jWeaponMode["isBaseMode"];
            }
            if (jWeaponMode["Instability"] != null)
            {
                this.Instability = (float)jWeaponMode["Instability"];
            }
            if (jWeaponMode["AttackRecoil"] != null)
            {
                this.AttackRecoil = (int)jWeaponMode["AttackRecoil"];
            }
            if (jWeaponMode["WeaponEffectID"] != null)
            {
                this.WeaponEffectID = (string)jWeaponMode["WeaponEffectID"];
            }
            if (jWeaponMode["EvasivePipsIgnored"] != null)
            {
                this.EvasivePipsIgnored = (float)jWeaponMode["EvasivePipsIgnored"];
            }
            if (jWeaponMode["IndirectFireCapable"] != null)
            {
                this.IndirectFireCapable = ((bool)jWeaponMode["IndirectFireCapable"] == true) ? TripleBoolean.True : TripleBoolean.False;
            }
            if (jWeaponMode["DirectFireModifier"] != null)
            {
                this.DirectFireModifier = (float)jWeaponMode["DirectFireModifier"];
            }
            if (jWeaponMode["DistantVariance"] != null)
            {
                this.DistantVariance = (float)jWeaponMode["DistantVariance"];
            }
            if (jWeaponMode["DamageMultiplier"] != null)
            {
                this.DamageMultiplier = (float)jWeaponMode["DamageMultiplier"];
            }
            if (jWeaponMode["DistantVarianceReversed"] != null)
            {
                this.DistantVarianceReversed = ((bool)jWeaponMode["DistantVarianceReversed"] == true) ? TripleBoolean.True : TripleBoolean.False;
            }
            if (jWeaponMode["DamageVariance"] != null)
            {
                this.DamageVariance = (float)jWeaponMode["DamageVariance"];
            }
            if (jWeaponMode["FlatJammingChance"] != null)
            {
                this.FlatJammingChance = (float)jWeaponMode["FlatJammingChance"];
            }
            if (jWeaponMode["GunneryJammingBase"] != null)
            {
                this.GunneryJammingBase = (float)jWeaponMode["GunneryJammingBase"];
            }
            if (jWeaponMode["GunneryJammingMult"] != null)
            {
                this.GunneryJammingMult = (float)jWeaponMode["GunneryJammingMult"];
            }
            if (jWeaponMode["AIHitChanceCap"] != null)
            {
                this.AIHitChanceCap = (float)jWeaponMode["AIHitChanceCap"];
            }
            if (jWeaponMode["Cooldown"] != null)
            {
                this.Cooldown = (int)jWeaponMode["Cooldown"];
            }
            if (jWeaponMode["AmmoCategory"] != null)
            {
                this.AmmoCategory = CustomAmmoCategories.find((string)jWeaponMode["AmmoCategory"]);
            }
            if (jWeaponMode["DamageOnJamming"] != null)
            {
                this.DamageOnJamming = ((bool)jWeaponMode["DamageOnJamming"] == true) ? TripleBoolean.True : TripleBoolean.False;
            }
            if (jWeaponMode["AOECapable"] != null)
            {
                this.AOECapable = ((bool)jWeaponMode["AOECapable"] == true) ? TripleBoolean.True : TripleBoolean.False;;
            }
            if (jWeaponMode["AlwaysIndirectVisuals"] != null)
            {
                this.AlwaysIndirectVisuals = ((bool)jWeaponMode["AlwaysIndirectVisuals"] == true) ? TripleBoolean.True : TripleBoolean.False;
            }
            if (jWeaponMode["HitGenerator"] != null)
            {
                try {
                    this.HitGenerator = (HitGeneratorType)Enum.Parse(typeof(HitGeneratorType), (string)jWeaponMode["HitGenerator"], true);
                } catch (Exception e) {
                    this.HitGenerator = HitGeneratorType.NotSet;
                }
                jWeaponMode.Remove("HitGenerator");
            }
            if (jWeaponMode["statusEffects"] != null)
            {
                if (jWeaponMode["statusEffects"].Type == JTokenType.Array)
                {
                    this.statusEffects.Clear();
                    JToken statusEffects = jWeaponMode["statusEffects"];
                    foreach (JObject statusEffect in statusEffects)
                    {
                        EffectData effect = new EffectData();
                        JSONSerializationUtility.FromJSON <EffectData>(effect, statusEffect.ToString());
                        this.statusEffects.Add(effect);
                    }
                }
            }
        }
 public override void FromJSON(string json)
 {
     JSONSerializationUtility.FromJSON <SwapTeamFactionGameLogic>(this, json);
 }
 public override void FromJSON(string json)
 {
     JSONSerializationUtility.FromJSON <SetChunkStateAtRandomActivator>(this, json);
 }
 public override void FromJSON(string json)
 {
     JSONSerializationUtility.FromJSON <DialogueActivator>(this, json);
 }
Beispiel #19
0
 public override void FromJSON(string json)
 {
     JSONSerializationUtility.FromJSON <DisablePilotDeathGameLogic>(this, json);
 }
 public override void FromJSON(string json)
 {
     JSONSerializationUtility.FromJSON <LanceSpawnedMessage>(this, json);
 }
Beispiel #21
0
        public static void Init(string directory, string settingsJSON)
        {
            Logger = HBS.Logging.Logger.GetLogger(ModName, LogLevel.Debug);

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

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

                SetupLogging(directory);


                var harmony = HarmonyInstance.Create($"{ModName}");
                harmony.PatchAll(Assembly.GetExecutingAssembly());
                Logger.Log("=========================================================");
                Logger.Log($"Loaded {ModName} v0.3.1 for bt 1.9");
                Logger.Log("=========================================================");
                Logger.LogDebug("done");
                Logger.LogDebug(JSONSerializationUtility.ToJSON(Settings));

                State         = new GameState();
                RefreshEvents = new Dictionary <string, List <IShopDescriptor> >();


                RegisterRefreshEvent("Daily");
                RegisterRefreshEvent("SystemChange");
                RegisterRefreshEvent("MonthEnd");
                RegisterRefreshEvent("ContractComplete");
                RegisterRefreshEvent("OwnerChange");

                if (Settings.SystemShop)
                {
                    RegisterShop(new SystemShop(), new List <string>()
                    {
                        "systemchange", "monthend"
                    });
                }
                if (Settings.FactionShop)
                {
                    RegisterShop(new FactionShop(), new List <string>()
                    {
                        "systemchange", "monthend"
                    });
                }
                if (Settings.BlackMarketShop)
                {
                    RegisterShop(new BlackMarketShop(), new List <string>()
                    {
                        "systemchange", "monthend"
                    });
                }
                if (Settings.BuyBackShop)
                {
                    BuyBack = new BuyBackShop();
                    RegisterShop(BuyBack, new List <string>()
                    {
                        "systemchange"
                    });
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
Beispiel #22
0
        public static void Init(string directory, string settingsJSON)
        {
            Logger = HBS.Logging.Logger.GetLogger("CustomComponents", LogLevel.Debug);
            SetupLogging(directory);

            try
            {
                try
                {
                    Settings = new CustomComponentSettings();
                    JSONSerializationUtility.FromJSON(Settings, settingsJSON);
                    HBS.Logging.Logger.SetLoggerLevel(Logger.Name, Settings.LogLevel);
                }
                catch (Exception e)
                {
                    Logger.LogError("Couldn't load settings", e);
                    Settings = new CustomComponentSettings();
                }
                Logger.LogError($"{Settings.TestEnableAllTags}");


                Settings.Complete();

                LogDebug(DType.ShowConfig, JSONSerializationUtility.ToJSON(Settings));


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

                Registry.RegisterSimpleCustomComponents(Assembly.GetExecutingAssembly());
                Validator.RegisterMechValidator(CategoryController.Shared.ValidateMech, CategoryController.Shared.ValidateMechCanBeFielded);

                Logger.Log("Loaded CustomComponents v0.9.7.1 for bt 1.5.1");

                Validator.RegisterMechValidator(TagRestrictionsHandler.Shared.ValidateMech, TagRestrictionsHandler.Shared.ValidateMechCanBeFielded);
                Validator.RegisterDropValidator(pre: TagRestrictionsHandler.Shared.ValidateDrop);

                if (Settings.RunAutofixer)
                {
                    if (Settings.FixDeletedComponents)
                    {
                        AutoFixer.Shared.RegisterMechFixer(AutoFixer.Shared.RemoveEmptyRefs);
                    }

                    if (Settings.FixSaveGameMech)
                    {
                        AutoFixer.Shared.RegisterSaveMechFixer(AutoFixer.Shared.ReAddFixed);
                        AutoFixer.Shared.RegisterSaveMechFixer(CategoryController.Shared.RemoveExcessDefaults);
                    }

                    if (Settings.FixDefaults)
                    {
                        AutoFixer.Shared.RegisterMechFixer(DefaultFixer.Shared.FixMechs);
                    }
                }
                Logger.LogDebug("done");
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
 public override void FromJSON(string json)
 {
     JSONSerializationUtility.FromJSON <CustomPlayerLanceSpawnerGameLogic>(this, json);
 }
 public void FromJSON(string json)
 {
     JSONSerializationUtility.FromJSON(this, json);
 }
        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);
        }
Beispiel #26
0
        public static void Init(string directory, string settingsJSON)
        {
            Logger = HBS.Logging.Logger.GetLogger("CustomSalvage", LogLevel.Debug);

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

                Settings.Complete();
                SetupLogging(directory);

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

#if USE_CC
                Logger.Log("Loaded CustomSalvageCC v0.4.2 for bt 1.8");
#else
                Logger.Log("Loaded CustomSalvageNonCC v0.4.2 for bt 1.8");
#endif

                switch (Settings.RecoveryType)
                {
                case RecoveryCalculationType.AlwaysRecover:
                    NeedRecovery = (result, contract) => true;
                    break;

                case RecoveryCalculationType.NeverRecover:
                    NeedRecovery = (result, contract) => false;
                    break;

                case RecoveryCalculationType.PartDestroyed:
                    NeedRecovery = RecoveryDelegates.PartDestroyed;
                    break;

                default:
                    NeedRecovery = RecoveryDelegates.VanilaRecovery;
                    break;
                }


                switch (Settings.LostMechAction)
                {
                case LostMechActionType.ReturnItemsAndPartsToPlayer:
                    LostUnitAction = LostUnitActions.ReturnItemsAndParts;
                    break;

                case LostMechActionType.MoveItemsToSalvage:
                    LostUnitAction = LostUnitActions.SalvageItems;
                    break;

                case LostMechActionType.MoveItemsAndPartsToSalvage:
                    LostUnitAction = LostUnitActions.SalvageItemsAndParts;
                    break;

                default:
                    LostUnitAction = LostUnitActions.ReturnItems;
                    break;
                }

                switch (Settings.PartCountType)
                {
                case PartCalculationType.VanilaAdjusted:
                    GetNumParts = PartsNumCalculations.VanilaAdjusted;
                    break;

                case PartCalculationType.PartDestroyed:
                    GetNumParts = PartsNumCalculations.PartDestroyed;
                    break;

                case PartCalculationType.PartDestroyedIgnoreCT:
                    GetNumParts = PartsNumCalculations.PartDestroyedNoCT;
                    break;

                default:
                    GetNumParts = PartsNumCalculations.Vanila;
                    break;
                }
#if USE_CC
                CustomComponents.Registry.RegisterSimpleCustomComponents(Assembly.GetExecutingAssembly());
#endif

                Logger.LogDebug("done");
                Logger.LogDebug(JSONSerializationUtility.ToJSON(Settings));
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }