Exemplo n.º 1
0
        public static void Init(string modDirectory, string settingsJSON)
        {
            ModDir = modDirectory;

            Exception settingsE;

            try {
                Mod.Config = JsonConvert.DeserializeObject <ModConfig>(settingsJSON);
            } catch (Exception e) {
                settingsE  = e;
                Mod.Config = new ModConfig();
            }
            Mod.Config.Init();

            Log = new DeferringLogger(modDirectory, LogFilename, LogLabel, Config.Debug, Config.Trace);

            Assembly        asm = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);

            Log.Info?.Write($"Assembly version: {fvi.ProductVersion}");

            Log.Debug?.Write($"ModDir is:{modDirectory}");
            Log.Debug?.Write($"mod.json settings are:({settingsJSON})");
            Mod.Config.LogConfig();

            var harmony = HarmonyInstance.Create(HarmonyPackage);

            harmony.PatchAll(Assembly.GetExecutingAssembly());
        }
        public static void Init(string modDirectory, string settingsJSON)
        {
            Mod.ModDir = modDirectory;

            Exception settingsE = null;

            try
            {
                Mod.Config = JsonConvert.DeserializeObject <ModConfig>(settingsJSON);
            }
            catch (Exception e)
            {
                settingsE  = e;
                Mod.Config = new ModConfig();
            }

            Mod.Log = new DeferringLogger(modDirectory, LogName, LogLabel, Config.Debug, Config.Trace);

            // Read localization
            string localizationPath = Path.Combine(ModDir, "./mod_localized_text.json");

            try
            {
                string jsonS = File.ReadAllText(localizationPath);
                Mod.LocalizedText = JsonConvert.DeserializeObject <ModText>(jsonS);
            }
            catch (Exception e)
            {
                Mod.LocalizedText = new ModText();
                Log.Error?.Write(e, $"Failed to read localizations from: {localizationPath} due to error!");
            }
            Mod.LocalizedText.InitUnsetValues();

            Assembly        asm = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);

            Mod.Log.Info?.Write($"Assembly version: {fvi.ProductVersion}");

            Mod.Log.Debug?.Write($"ModDir is:{modDirectory}");
            Mod.Log.Debug?.Write($"mod.json settings are:({settingsJSON})");
            Mod.Config.LogConfig();

            if (settingsE != null)
            {
                Mod.Log.Info?.Write($"ERROR reading settings file! Error was: {settingsE}");
            }
            else
            {
                Mod.Log.Info?.Write($"INFO: No errors reading settings file.");
            }

            // Initialize custom components
            CustomComponents.Registry.RegisterSimpleCustomComponents(Assembly.GetExecutingAssembly());

            // Initialize harmony patches
            var harmony = HarmonyInstance.Create(HarmonyPackage);

            harmony.PatchAll(Assembly.GetExecutingAssembly());
        }
Exemplo n.º 3
0
        public static void Init(string modDirectory, string settingsJSON)
        {
            ModDir = modDirectory;

            Exception settingsE;

            try
            {
                Mod.Config = JsonConvert.DeserializeObject <ModConfig>(settingsJSON);
            }
            catch (Exception e)
            {
                settingsE  = e;
                Mod.Config = new ModConfig();
            }

            Log = new DeferringLogger(modDirectory, "clever_girl", Mod.Config.Debug, Mod.Config.Trace);

            Assembly        asm = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);

            Log.Info?.Write($"Assembly version: {fvi.ProductVersion}");

            Log.Debug?.Write($"ModDir is:{modDirectory}");
            Log.Debug?.Write($"mod.json settings are:({settingsJSON})");
            Mod.Config.LogConfig();

            var harmony = HarmonyInstance.Create(HarmonyPackage);

            // Initialize custom components
            CustomComponents.Registry.RegisterSimpleCustomComponents(Assembly.GetExecutingAssembly());

            // Patch for logging before all others as it's a non-interfering prefix
            if (Mod.Config.Profile)
            {
                ProfilePatches.PatchAllMethods(harmony);
            }

            // Hack to disable CAC processing of AI
            CustomAmmoCategories.DisableInternalWeaponChoose = true;

            harmony.PatchAll(asm);
        }
Exemplo n.º 4
0
        public static void Init(string modDirectory, string settingsJSON)
        {
            modDir = modDirectory;


            try
            {
                using (StreamReader reader = new StreamReader($"{modDir}/settings.json"))
                {
                    string jdata = reader.ReadToEnd();
                    settings = JsonConvert.DeserializeObject <Settings>(jdata);
                    settings.initHolders();
                }
            }

            catch (Exception ex)
            {
                // modLog.Error?.Write(ex);
            }

            modLog = new DeferringLogger(modDirectory, "DropCostEnhanced", "DCE", settings.debug, settings.trace);

            try
            {
                cachedDifficulty = 0f;
                cacheValidUntil  = DateTime.UtcNow;
                CustomComponents.Registry.RegisterSimpleCustomComponents(Assembly.GetExecutingAssembly());
                DropCostManager.Instance.Initialize();
                AmmoCostManager.Instance.Initialize();
                HeatCostManager.Instance.Initialize();
                DifficultyManager.Instance.Initialize();
            }
            catch (Exception e)
            {
                modLog.Error?.Write(e);
            }

            var harmony = HarmonyInstance.Create("ca.jwolf.DropCostsEnhanced");

            harmony.PatchAll(Assembly.GetExecutingAssembly());
        }
Exemplo n.º 5
0
        public static void Init(string modDirectory, string settingsJSON)
        {
            ModDir = modDirectory;

            Exception settingsE = null;

            try {
                Mod.Config = JsonConvert.DeserializeObject <ModConfig>(settingsJSON);
            } catch (Exception e) {
                settingsE  = e;
                Mod.Config = new ModConfig();
            }

            Log = new DeferringLogger(modDirectory, LogName, LogLabel, Config.Debug, Config.Trace);

            Assembly        asm = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);

            Log.Info?.Write($"Assembly version: {fvi.ProductVersion}");

            // Initialize the mod settings
            Mod.Config.Init();

            Log.Debug?.Write($"ModDir is:{modDirectory}");
            Log.Debug?.Write($"mod.json settings are:({settingsJSON})");
            Mod.Config.LogConfig();

            if (settingsE != null)
            {
                Log.Info?.Write($"ERROR reading settings file! Error was: {settingsE}");
            }
            else
            {
                Log.Info?.Write($"INFO: No errors reading settings file.");
            }

            // Initialize modules
            var harmony = HarmonyInstance.Create(HarmonyPackage);

            harmony.PatchAll(Assembly.GetExecutingAssembly());
        }
Exemplo n.º 6
0
        public static void Init(string modDirectory, string settingsJSON)
        {
            modDir = modDirectory;

            try {
                using (StreamReader reader = new StreamReader($"{modDir}/settings.json")) {
                    string jdata = reader.ReadToEnd();
                    settings = JsonConvert.DeserializeObject <Settings>(jdata);
                }
                modLog = new DeferringLogger(modDirectory, "WarTechIIC", "WIIC", settings.debug, settings.trace);
                modLog.Debug?.Write($"Loaded settings from {modDir}/settings.json. Version {typeof(Settings).Assembly.GetName().Version}");
            }

            catch (Exception e) {
                settings = new Settings();
                modLog   = new DeferringLogger(modDir, "WarTechIIC", "WIIC", true, true);
                modLog.Error?.Write(e);
            }

            var harmony = HarmonyInstance.Create("blue.winds.WarTechIIC");

            harmony.PatchAll(Assembly.GetExecutingAssembly());
        }
Exemplo n.º 7
0
        public static void Init(string modDirectory, string settingsJSON)
        {
            ModDir = modDirectory;

            Exception settingsE = null;

            try {
                Mod.Config = JsonConvert.DeserializeObject <ModConfig>(settingsJSON);
            } catch (Exception e) {
                settingsE  = e;
                Mod.Config = new ModConfig();
            }

            Log = new DeferringLogger(modDirectory, LogName, Config.Debug, Config.Trace);

            Assembly        asm = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);

            Log.Info?.Write($"Assembly version: {fvi.ProductVersion}");

            Log.Debug?.Write($"ModDir is:{modDirectory}");
            Log.Debug?.Write($"mod.json settings are:({settingsJSON})");

            // Initialize the mod settings
            Mod.Config.Init();
            Mod.Config.LogConfig();

            if (settingsE != null)
            {
                Log.Info?.Write($"ERROR reading settings file! Error was: {settingsE}");
            }
            else
            {
                Log.Info?.Write($"INFO: No errors reading settings file.");
            }

            // Read localization
            string localizationPath = Path.Combine(ModDir, "./mod_localized_text.json");

            try
            {
                string jsonS = File.ReadAllText(localizationPath);
                Mod.LocalizedText = JsonConvert.DeserializeObject <ModText>(jsonS);
            }
            catch (Exception e)
            {
                Mod.LocalizedText = new ModText();
                Log.Error?.Write(e, $"Failed to read localizations from: {localizationPath} due to error!");
            }

            var harmony = HarmonyInstance.Create(HarmonyPackage);

            // Initialize modules
            CombatFixes.InitModule(harmony);
            MiscFixes.InitModule(harmony);
            UIFixes.InitModule(harmony);

            // Enable DEBUG below to print a log of emitted IL to the desktop. Useful for debugging transpilers
            //HarmonyInstance.DEBUG = true;
            harmony.PatchAll(Assembly.GetExecutingAssembly());

            // Setup the diag for me
            //Helper.DiagnosticLogger.PatchAllMethods();
        }
Exemplo n.º 8
0
        public static void Init(string modDirectory, string settingsJSON)
        {
            ModDir = modDirectory;

            Exception settingsE = null;

            try
            {
                Mod.Config = JsonConvert.DeserializeObject <ModConfig>(settingsJSON);
            }
            catch (Exception e)
            {
                settingsE  = e;
                Mod.Config = new ModConfig();
            }

            Log = new DeferringLogger(modDirectory, LogName, Config.Debug, Config.Trace);

            Assembly        asm = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);

            Log.Info?.Write($"Assembly version: {fvi.ProductVersion}");

            Log.Debug?.Write($"ModDir is:{modDirectory}");
            Log.Debug?.Write($"mod.json settings are:({settingsJSON})");
            Mod.Config.LogConfig();

            if (settingsE != null)
            {
                Log.Info?.Write($"ERROR reading settings file! Error was: {settingsE}");
            }
            else
            {
                Log.Info?.Write($"INFO: No errors reading settings file.");
            }

            // Try to determine the battletech directory
            string fileName = Process.GetCurrentProcess().MainModule.FileName;
            string btDir    = Path.GetDirectoryName(fileName);

            Log.Debug?.Write($"BT File is: {fileName} with btDir: {btDir}");
            if (Coordinator.CallSigns == null)
            {
                string filePath = Path.Combine(btDir, Mod.Config.Dialogue.CallsignsPath);
                Mod.Log.Debug?.Write($"Reading files from {filePath}");
                try
                {
                    Coordinator.CallSigns = File.ReadAllLines(filePath).ToList();
                }
                catch (Exception e)
                {
                    Mod.Log.Error?.Write(e, "Failed to read callsigns from BT directory!");
                    Coordinator.CallSigns = new List <string> {
                        "Alpha", "Beta", "Gamma"
                    };
                }
                Mod.Log.Debug?.Write($"Callsign count is: {Coordinator.CallSigns.Count}");
            }

            var harmony = HarmonyInstance.Create(HarmonyPackage);

            harmony.PatchAll(Assembly.GetExecutingAssembly());
        }
Exemplo n.º 9
0
        public static void Init(string modDirectory, string settingsJSON)
        {
            ModDir = modDirectory;

            Exception settingsE = null;

            try
            {
                Mod.Config = JsonConvert.DeserializeObject <ModConfig>(settingsJSON);
            }
            catch (Exception e)
            {
                settingsE  = e;
                Mod.Config = new ModConfig();
            }
            Mod.Config.Init(); // Initialize color conversion & defaults

            Log        = new DeferringLogger(modDirectory, LogName, "HR", Mod.Config.Debug, Mod.Config.Trace);
            DossierLog = new DeferringLogger(modDirectory, $"{LogName}.{LogSuffixDossier}", "HR", Mod.Config.Debug, Mod.Config.Trace);

            Assembly        asm = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);

            Log.Info?.Write($"Assembly version: {fvi.ProductVersion}");

            // Read config
            Log.Debug?.Write($"ModDir is:{modDirectory}");
            Log.Debug?.Write($"mod.json settings are:({settingsJSON})");
            Mod.Config.LogConfig();
            if (settingsE != null)
            {
                Log.Info?.Write($"ERROR reading settings file! Error was: {settingsE}");
            }
            else
            {
                Log.Info?.Write($"INFO: No errors reading settings file.");
            }

            // Read crew name dictionary
            string namesPath = Path.Combine(ModDir, "./mod_names.json");

            try
            {
                string jsonS = File.ReadAllText(namesPath);
                Mod.CrewNames = JsonConvert.DeserializeObject <ModCrewNames>(jsonS);
                Log.Info?.Write($"Successfully read:" +
                                $" {Mod.CrewNames.Aerospace?.Count} aerospace crew names" +
                                $" {Mod.CrewNames.MechTech?.Count} mechtech crew names" +
                                $" {Mod.CrewNames.MedTech?.Count} medtech crew names" +
                                $" {Mod.CrewNames.Vehicle?.Count} vehicle crew names"
                                );
            }
            catch (Exception e)
            {
                Mod.CrewNames = new ModCrewNames();
                Log.Error?.Write(e, $"Failed to read names from: {namesPath} due to error!");
            }

            // Read localization
            string localizationPath = Path.Combine(ModDir, "./mod_localized_text.json");

            try
            {
                string jsonS = File.ReadAllText(localizationPath);
                Mod.LocalizedText = JsonConvert.DeserializeObject <ModText>(jsonS);
                Log.Info?.Write("Successfully read mod localization files.");
            }
            catch (Exception e)
            {
                Mod.LocalizedText = new ModText();
                Log.Error?.Write(e, $"Failed to read localizations from: {localizationPath} due to error!");
            }

            // Read lifepaths
            string lifepathsPath = Path.Combine(ModDir, "./lifepaths.json");

            try
            {
                string jsonS = File.ReadAllText(lifepathsPath);
                Mod.LifePathFamilies = JsonConvert.DeserializeObject <Dictionary <string, LifePathFamily> >(jsonS);
                Log.Info?.Write($"Successfully read {Mod.LifePaths?.Count} lifepath families.");

                LifePathHelper.InitAtModLoad();
            }
            catch (Exception e)
            {
                Mod.LocalizedText = new ModText();
                Log.Error?.Write(e, $"Failed to read lifepaths from: {lifepathsPath} due to error!");
            }


            // Initialize harmony
            var harmony = HarmonyInstance.Create(HarmonyPackage);

            harmony.PatchAll(Assembly.GetExecutingAssembly());
        }