Пример #1
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 IntraModLogger(modDirectory, LogName, Config.Debug, Config.Trace);

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

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

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

            if (settingsE != null)
            {
                Log.Info($"ERROR reading settings file! Error was: {settingsE}");
            }
            else
            {
                Log.Info($"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($"BT File is: {fileName} with btDir: {btDir}");
            if (Coordinator.CallSigns == null)
            {
                string filePath = Path.Combine(btDir, Mod.Config.Dialogue.CallsignsPath);
                Mod.Log.Debug($"Reading files from {filePath}");
                try {
                    Coordinator.CallSigns = File.ReadAllLines(filePath).ToList();
                } catch (Exception e) {
                    Mod.Log.Error("Failed to read callsigns from BT directory!");
                    Mod.Log.Error(e);
                    Coordinator.CallSigns = new List <string> {
                        "Alpha", "Beta", "Gamma"
                    };
                }
                Mod.Log.Debug($"Callsign count is: {Coordinator.CallSigns.Count}");
            }

            var harmony = HarmonyInstance.Create(HarmonyPackage);

            harmony.PatchAll(Assembly.GetExecutingAssembly());
        }
Пример #2
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 IntraModLogger(modDirectory, LogName, Config.Debug, Config.Trace);

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

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

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

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

            var harmony = HarmonyInstance.Create(HarmonyPackage);

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

            harmony.PatchAll(Assembly.GetExecutingAssembly());

            // Setup the diag for me
            //Helper.DiagnosticLogger.PatchAllMethods();
        }