Ejemplo n.º 1
0
        public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch)
        {
            this.StartInfo          = info;
            this.loggingLevelSwitch = loggingLevelSwitch;

            this.Configuration   = DalamudConfiguration.Load(info.ConfigurationPath);
            this.localizationMgr = new Localization(this.StartInfo.WorkingDirectory);

            if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride))
            {
                this.localizationMgr.SetupWithLangCode(this.Configuration.LanguageOverride);
            }
            else
            {
                this.localizationMgr.SetupWithUiCulture();
            }

            this.baseDirectory = info.WorkingDirectory;

            this.unloadSignal = new ManualResetEvent(false);

            // Initialize the process information.
            this.targetModule = Process.GetCurrentProcess().MainModule;
            this.SigScanner   = new SigScanner(this.targetModule, true);

            // Initialize game subsystem
            this.Framework = new Framework(this.SigScanner, this);

            // Initialize managers. Basically handlers for the logic
            this.CommandManager = new CommandManager(this, info.Language);
            SetupCommands();

            this.ChatHandlers    = new ChatHandlers(this);
            this.NetworkHandlers = new NetworkHandlers(this, this.Configuration.OptOutMbCollection);

            this.Data = new DataManager(this.StartInfo.Language);
            this.Data.Initialize();

            this.ClientState = new ClientState(this, info, this.SigScanner);

            this.BotManager = new DiscordBotManager(this, this.Configuration.DiscordFeatureConfig);

            this.WinSock2 = new WinSockHandlers();

            try {
                this.InterfaceManager         = new InterfaceManager(this, this.SigScanner);
                this.InterfaceManager.OnDraw += BuildDalamudUi;
            } catch (Exception e) {
                Log.Information(e, "Could not init interface.");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialize all Dalamud subsystems and start running on the main thread.
        /// </summary>
        /// <param name="info">The <see cref="DalamudStartInfo"/> containing information needed to initialize Dalamud.</param>
        private static void RunThread(DalamudStartInfo info)
        {
            // Setup logger
            var levelSwitch = InitLogging(info.WorkingDirectory);

            // Load configuration first to get some early persistent state, like log level
            var configuration = DalamudConfiguration.Load(info.ConfigurationPath);

            // Set the appropriate logging level from the configuration
#if !DEBUG
            levelSwitch.MinimumLevel = configuration.LogLevel;
#endif

            // Log any unhandled exception.
            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
            TaskScheduler.UnobservedTaskException      += OnUnobservedTaskException;

            var finishSignal = new ManualResetEvent(false);

            try
            {
                Log.Information(new string('-', 80));
                Log.Information("Initializing a session..");

                // This is due to GitHub not supporting TLS 1.0, so we enable all TLS versions globally
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls;

                var dalamud = new Dalamud(info, levelSwitch, finishSignal, configuration);
                Log.Information("Starting a session..");

                // Run session
                dalamud.LoadTier1();
                dalamud.WaitForUnload();

                dalamud.Dispose();
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Unhandled exception on main thread.");
            }
            finally
            {
                TaskScheduler.UnobservedTaskException      -= OnUnobservedTaskException;
                AppDomain.CurrentDomain.UnhandledException -= OnUnhandledException;

                Log.Information("Session has ended.");
                Log.CloseAndFlush();

                finishSignal.Set();
            }
        }
        public static DalamudConfiguration Load(string path)
        {
            DalamudConfiguration deserialized;

            try
            {
                deserialized = JsonConvert.DeserializeObject <DalamudConfiguration>(File.ReadAllText(path));
            }
            catch (Exception ex)
            {
                Log.Warning(ex, "Failed to load DalamudConfiguration at {0}", path);
                deserialized = new DalamudConfiguration();
            }

            deserialized.ConfigPath = path;

            return(deserialized);
        }
Ejemplo n.º 4
0
        public Dalamud(DalamudStartInfo info)
        {
            this.StartInfo     = info;
            this.Configuration = DalamudConfiguration.Load(info.ConfigurationPath);

            this.baseDirectory = info.WorkingDirectory;

            this.unloadSignal = new ManualResetEvent(false);

            // Initialize the process information.
            this.targetModule = Process.GetCurrentProcess().MainModule;
            this.sigScanner   = new SigScanner(this.targetModule);

            // Initialize game subsystem
            Framework = new Framework(this.sigScanner, this);

            // Initialize managers. Basically handlers for the logic
            CommandManager = new CommandManager(this, info.Language);
            SetupCommands();

            ChatHandlers    = new ChatHandlers(this);
            NetworkHandlers = new NetworkHandlers(this, this.Configuration.OptOutMbCollection);

            this.ClientState = new ClientState(this, info, this.sigScanner, this.targetModule);

            this.BotManager = new DiscordBotManager(this, this.Configuration.DiscordFeatureConfig);

            this.PluginManager = new PluginManager(this, info.PluginDirectory, info.DefaultPluginDirectory);

            this.IconReplacer = new IconReplacer(this, this.sigScanner);

            this.WinSock2 = new WinSockHandlers();

            try {
                this.PluginManager.LoadPlugins();
            } catch (Exception ex) {
                Framework.Gui.Chat.PrintError(
                    "[XIVLAUNCHER] There was an error loading additional plugins. Please check the log for more details.");
                Log.Error(ex, "Plugin load failed.");
            }
        }
Ejemplo n.º 5
0
        private static LoggingLevelSwitch InitLogging(string baseDirectory, DalamudConfiguration configuration)
        {
#if DEBUG
            var logPath = Path.Combine(baseDirectory, "dalamud.log");
#else
            var logPath = Path.Combine(baseDirectory, "..", "..", "..", "dalamud.log");
#endif

            var levelSwitch = new LoggingLevelSwitch();

#if DEBUG
            levelSwitch.MinimumLevel = LogEventLevel.Verbose;
#else
            levelSwitch.MinimumLevel = configuration.LogLevel;
#endif
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Async(a => a.File(logPath, fileSizeLimitBytes: 5 * 1024 * 1024, rollOnFileSizeLimit: true))
                         .WriteTo.Sink(SerilogEventSink.Instance)
                         .MinimumLevel.ControlledBy(levelSwitch)
                         .CreateLogger();

            return(levelSwitch);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Dalamud"/> class.
        /// </summary>
        /// <param name="info">DalamudStartInfo instance.</param>
        /// <param name="loggingLevelSwitch">LoggingLevelSwitch to control Serilog level.</param>
        /// <param name="finishSignal">Signal signalling shutdown.</param>
        /// <param name="configuration">The Dalamud configuration.</param>
        public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch, ManualResetEvent finishSignal, DalamudConfiguration configuration)
        {
            this.ApplyProcessPatch();

            Service <Dalamud> .Set(this);

            Service <DalamudStartInfo> .Set(info);

            Service <DalamudConfiguration> .Set(configuration);

            this.LogLevelSwitch = loggingLevelSwitch;

            this.unloadSignal = new ManualResetEvent(false);
            this.unloadSignal.Reset();

            this.finishUnloadSignal = finishSignal;
            this.finishUnloadSignal.Reset();
        }
Ejemplo n.º 7
0
        public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch)
        {
            this.StartInfo          = info;
            this.loggingLevelSwitch = loggingLevelSwitch;

            this.Configuration = DalamudConfiguration.Load(info.ConfigurationPath);

            this.baseDirectory = info.WorkingDirectory;

            this.unloadSignal = new ManualResetEvent(false);

            // Initialize the process information.
            this.targetModule = Process.GetCurrentProcess().MainModule;
            this.SigScanner   = new SigScanner(this.targetModule, true);

            // Initialize game subsystem
            this.Framework = new Framework(this.SigScanner, this);

            this.ClientState = new ClientState(this, info, this.SigScanner);

            this.WinSock2 = new WinSockHandlers();

            AssetManager.EnsureAssets(this.baseDirectory).ContinueWith(async task => {
                if (task.IsCanceled || task.IsFaulted)
                {
                    throw new Exception("Could not ensure assets.", task.Exception);
                }

                this.LocalizationManager = new Localization(this.StartInfo.WorkingDirectory);
                if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride))
                {
                    this.LocalizationManager.SetupWithLangCode(this.Configuration.LanguageOverride);
                }
                else
                {
                    this.LocalizationManager.SetupWithUiCulture();
                }

                var pluginDir = this.StartInfo.PluginDirectory;
                if (this.Configuration.DoPluginTest)
                {
                    pluginDir = Path.Combine(pluginDir, "..", "testPlugins");
                }

                PluginRepository = new PluginRepository(this, pluginDir, this.StartInfo.GameVersion);

                if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_INTERFACE") ?? "false"))
                {
                    try
                    {
                        InterfaceManager         = new InterfaceManager(this, this.SigScanner);
                        InterfaceManager.OnDraw += BuildDalamudUi;

                        InterfaceManager.Enable();
                    }
                    catch (Exception e)
                    {
                        Log.Information(e, "Could not init interface.");
                    }
                }

                Data = new DataManager(this.StartInfo.Language);
                await Data.Initialize(this.baseDirectory);

                SeStringManager = new SeStringManager(Data);

                NetworkHandlers = new NetworkHandlers(this, this.Configuration.OptOutMbCollection);

                // Initialize managers. Basically handlers for the logic
                CommandManager = new CommandManager(this, info.Language);
                SetupCommands();

                ChatHandlers = new ChatHandlers(this);
                // Discord Bot Manager
                BotManager = new DiscordBotManager(this, this.Configuration.DiscordFeatureConfig);
                BotManager.Start();

                if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false"))
                {
                    try
                    {
                        PluginRepository.CleanupPlugins();

                        PluginManager = new PluginManager(this, pluginDir, this.StartInfo.DefaultPluginDirectory);
                        PluginManager.LoadPlugins();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "Plugin load failed.");
                    }
                }

                this.Framework.Enable();
                this.ClientState.Enable();

                IsReady = true;
            });
        }
Ejemplo n.º 8
0
        public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch)
        {
            this.StartInfo          = info;
            this.loggingLevelSwitch = loggingLevelSwitch;

            this.Configuration = DalamudConfiguration.Load(info.ConfigurationPath);

            this.baseDirectory = info.WorkingDirectory;

            this.unloadSignal = new ManualResetEvent(false);

            // Initialize the process information.
            this.targetModule = Process.GetCurrentProcess().MainModule;
            this.SigScanner   = new SigScanner(this.targetModule, true);

            // Initialize game subsystem
            this.Framework = new Framework(this.SigScanner, this);

            this.ClientState = new ClientState(this, info, this.SigScanner);

            this.WinSock2 = new WinSockHandlers();

            AssetManager.EnsureAssets(this.baseDirectory).ContinueWith(async task => {
                if (task.IsCanceled || task.IsFaulted)
                {
                    throw new Exception("Could not ensure assets.", task.Exception);
                }

                this.localizationMgr = new Localization(this.StartInfo.WorkingDirectory);
                if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride))
                {
                    this.localizationMgr.SetupWithLangCode(this.Configuration.LanguageOverride);
                }
                else
                {
                    this.localizationMgr.SetupWithUiCulture();
                }

                try {
                    this.InterfaceManager         = new InterfaceManager(this, this.SigScanner);
                    this.InterfaceManager.OnDraw += BuildDalamudUi;

                    this.InterfaceManager.Enable();
                } catch (Exception e) {
                    Log.Information(e, "Could not init interface.");
                }

                this.Data = new DataManager(this.StartInfo.Language);
                await this.Data.Initialize(this.baseDirectory);

                // TODO: better way to do this?  basically for lumina injection
                SeString.Dalamud = this;

                this.NetworkHandlers = new NetworkHandlers(this, this.Configuration.OptOutMbCollection);

                // Initialize managers. Basically handlers for the logic
                this.CommandManager = new CommandManager(this, info.Language);
                SetupCommands();

                this.ChatHandlers = new ChatHandlers(this);
                // Discord Bot Manager
                this.BotManager = new DiscordBotManager(this, this.Configuration.DiscordFeatureConfig);
                this.BotManager.Start();

                try
                {
                    this.PluginManager = new PluginManager(this, this.StartInfo.PluginDirectory, this.StartInfo.DefaultPluginDirectory);
                    this.PluginManager.LoadPlugins();

                    this.PluginRepository = new PluginRepository(PluginManager, this.StartInfo.PluginDirectory, this.StartInfo.GameVersion);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Plugin load failed.");
                }

                IsReady = true;
            });

            this.conditionDebugWindow = new ConditionDebugWindow(this);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Start and initialize Dalamud subsystems.
        /// </summary>
        public void Start()
        {
            try
            {
                this.Configuration = DalamudConfiguration.Load(this.StartInfo.ConfigurationPath);

                // Initialize the process information.
                this.TargetModule = Process.GetCurrentProcess().MainModule;
                this.SigScanner   = new SigScanner(this.TargetModule, true);

                Log.Information("[START] Scanner OK!");

                this.AntiDebug = new AntiDebug(this.SigScanner);
#if DEBUG
                AntiDebug.Enable();
#endif

                Log.Information("[START] AntiDebug OK!");

                // Initialize game subsystem
                this.Framework = new Framework(this.SigScanner, this);

                Log.Information("[START] Framework OK!");

                this.WinSock2 = new WinSockHandlers();

                Log.Information("[START] WinSock OK!");

                this.NetworkHandlers = new NetworkHandlers(this, this.StartInfo.OptOutMbCollection);

                Log.Information("[START] NH OK!");

                this.ClientState = new ClientState(this, this.StartInfo, this.SigScanner);

                Log.Information("[START] CS OK!");

                this.LocalizationManager = new Localization(Path.Combine(this.AssetDirectory.FullName, "UIRes", "loc", "dalamud"), "dalamud_");
                if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride))
                {
                    this.LocalizationManager.SetupWithLangCode(this.Configuration.LanguageOverride);
                }
                else
                {
                    this.LocalizationManager.SetupWithUiCulture();
                }

                Log.Information("[START] LOC OK!");

                this.PluginRepository =
                    new PluginRepository(this, this.StartInfo.PluginDirectory, this.StartInfo.GameVersion);

                Log.Information("[START] PREPO OK!");

                var isInterfaceLoaded = false;
                if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_INTERFACE") ?? "false"))
                {
                    try
                    {
                        this.InterfaceManager = new InterfaceManager(this, this.SigScanner);

                        this.InterfaceManager.Enable();
                        isInterfaceLoaded = true;

                        Log.Information("[START] IM OK!");

                        this.InterfaceManager.WaitForFontRebuild();
                    }
                    catch (Exception e)
                    {
                        Log.Information(e, "Could not init interface.");
                    }
                }

                this.Data = new DataManager(this.StartInfo.Language, this.InterfaceManager);
                try
                {
                    this.Data.Initialize(this.AssetDirectory.FullName);
                }
                catch (Exception e)
                {
                    Log.Error(e, "Could not initialize DataManager.");
                    this.Unload();
                    return;
                }

                Log.Information("[START] Data OK!");

                this.SeStringManager = new SeStringManager(this.Data);

                Log.Information("[START] SeString OK!");

                // Initialize managers. Basically handlers for the logic
                this.CommandManager  = new CommandManager(this, this.StartInfo.Language);
                this.DalamudCommands = new DalamudCommands(this);
                this.DalamudCommands.SetupCommands();

                Log.Information("[START] CM OK!");

                this.ChatHandlers = new ChatHandlers(this);

                Log.Information("[START] CH OK!");

                if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false"))
                {
                    try
                    {
                        this.PluginRepository.CleanupPlugins();

                        Log.Information("[START] PRC OK!");

                        this.PluginManager = new PluginManager(
                            this,
                            this.StartInfo.PluginDirectory,
                            this.StartInfo.DefaultPluginDirectory);
                        this.PluginManager.LoadPlugins();

                        Log.Information("[START] PM OK!");
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "Plugin load failed.");
                    }
                }

                this.Framework.Enable();
                Log.Information("[START] Framework ENABLE!");

                this.ClientState.Enable();
                Log.Information("[START] CS ENABLE!");

                this.DalamudUi = new DalamudInterface(this);
                this.InterfaceManager.OnDraw += this.DalamudUi.Draw;

                Log.Information("[START] DUI OK!");

                this.IsReady = true;

                Troubleshooting.LogTroubleshooting(this, isInterfaceLoaded);

                Log.Information("Dalamud is ready.");
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Dalamud::Start() failed.");
                this.Unload();
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Runs tier 2 of the Dalamud initialization process.
        /// </summary>
        public void LoadTier2()
        {
            try
            {
                this.Configuration = DalamudConfiguration.Load(this.StartInfo.ConfigurationPath);

                this.AntiDebug = new AntiDebug(this.SigScanner);
#if DEBUG
                this.AntiDebug.Enable();
#endif

                Log.Information("[T2] AntiDebug OK!");


                this.WinSock2 = new WinSockHandlers();

                Log.Information("[T2] WinSock OK!");

                this.NetworkHandlers = new NetworkHandlers(this, this.StartInfo.OptOutMbCollection);

                Log.Information("[T2] NH OK!");

                this.ClientState = new ClientState(this, this.StartInfo, this.SigScanner);

                Log.Information("[T2] CS OK!");

                this.LocalizationManager = new Localization(Path.Combine(this.AssetDirectory.FullName, "UIRes", "loc", "dalamud"), "dalamud_");
                if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride))
                {
                    this.LocalizationManager.SetupWithLangCode(this.Configuration.LanguageOverride);
                }
                else
                {
                    this.LocalizationManager.SetupWithUiCulture();
                }

                Log.Information("[T2] LOC OK!");

                if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_INTERFACE") ?? "false"))
                {
                    try
                    {
                        this.InterfaceManager = new InterfaceManager(this, this.SigScanner);

                        this.InterfaceManager.Enable();

                        Log.Information("[T2] IM OK!");
                    }
                    catch (Exception e)
                    {
                        Log.Information(e, "Could not init interface.");
                    }
                }

                this.Data = new DataManager(this.StartInfo.Language, this.InterfaceManager);
                try
                {
                    this.Data.Initialize(this.AssetDirectory.FullName);
                }
                catch (Exception e)
                {
                    Log.Error(e, "Could not initialize DataManager.");
                    this.Unload();
                    return;
                }

                Log.Information("[T2] Data OK!");

                this.SeStringManager = new SeStringManager(this.Data);

                Log.Information("[T2] SeString OK!");

                // Initialize managers. Basically handlers for the logic
                this.CommandManager  = new CommandManager(this, this.StartInfo.Language);
                this.DalamudCommands = new DalamudCommands(this);
                this.DalamudCommands.SetupCommands();

                Log.Information("[T2] CM OK!");

                this.ChatHandlers = new ChatHandlers(this);

                Log.Information("[T2] CH OK!");

                this.ClientState.Enable();
                Log.Information("[T2] CS ENABLE!");

                this.SystemMenu = new DalamudSystemMenu(this);
                this.SystemMenu.Enable();

                this.IsReady = true;
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Tier 2 load failed.");
                this.Unload();
            }
        }
Ejemplo n.º 11
0
        public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch)
        {
            this.StartInfo          = info;
            this.loggingLevelSwitch = loggingLevelSwitch;

            this.Configuration = DalamudConfiguration.Load(info.ConfigurationPath);

            this.baseDirectory = info.WorkingDirectory;

            this.unloadSignal = new ManualResetEvent(false);

            // Initialize the process information.
            this.targetModule = Process.GetCurrentProcess().MainModule;
            this.SigScanner   = new SigScanner(this.targetModule, true);

            // Initialize game subsystem
            this.Framework = new Framework(this.SigScanner, this);

            this.WinSock2 = new WinSockHandlers();

            NetworkHandlers = new NetworkHandlers(this, this.Configuration.OptOutMbCollection);

            this.ClientState = new ClientState(this, info, this.SigScanner);

            Task.Run(async() => {
                try {
                    var res = await AssetManager.EnsureAssets(this.baseDirectory);

                    if (!res)
                    {
                        Log.Error("One or more assets failed to download.");
                        Unload();
                        return;
                    }
                } catch (Exception e) {
                    Log.Error(e, "Error in asset task.");
                    Unload();
                    return;
                }

                this.LocalizationManager = new Localization(this.StartInfo.WorkingDirectory);
                if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride))
                {
                    this.LocalizationManager.SetupWithLangCode(this.Configuration.LanguageOverride);
                }
                else
                {
                    this.LocalizationManager.SetupWithUiCulture();
                }

                PluginRepository = new PluginRepository(this, this.StartInfo.PluginDirectory, this.StartInfo.GameVersion);

                var isInterfaceLoaded = false;
                if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_INTERFACE") ?? "false"))
                {
                    try
                    {
                        InterfaceManager         = new InterfaceManager(this, this.SigScanner);
                        InterfaceManager.OnDraw += BuildDalamudUi;

                        InterfaceManager.Enable();
                        isInterfaceLoaded = true;
                    }
                    catch (Exception e)
                    {
                        Log.Information(e, "Could not init interface.");
                    }
                }

                Data = new DataManager(this.StartInfo.Language);
                try {
                    await Data.Initialize(this.baseDirectory);
                } catch (Exception e) {
                    Log.Error(e, "Could not initialize DataManager.");
                    Unload();
                    return;
                }

                SeStringManager = new SeStringManager(Data);

#if DEBUG
                AntiDebug = new AntiDebug(this.SigScanner);
                AntiDebug.Enable();
#endif

                // Initialize managers. Basically handlers for the logic
                CommandManager = new CommandManager(this, info.Language);
                SetupCommands();

                ChatHandlers = new ChatHandlers(this);

                if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false"))
                {
                    try
                    {
                        PluginRepository.CleanupPlugins();

                        PluginManager = new PluginManager(this, this.StartInfo.PluginDirectory, this.StartInfo.DefaultPluginDirectory);
                        PluginManager.LoadPlugins();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "Plugin load failed.");
                    }
                }

                this.Framework.Enable();
                this.ClientState.Enable();

                IsReady = true;

                Troubleshooting.LogTroubleshooting(this, isInterfaceLoaded);
            });
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Dalamud"/> class.
        /// </summary>
        /// <param name="info">DalamudStartInfo instance.</param>
        /// <param name="loggingLevelSwitch">LoggingLevelSwitch to control Serilog level.</param>
        /// <param name="finishSignal">Signal signalling shutdown.</param>
        /// <param name="configuration">The Dalamud configuration.</param>
        public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch, ManualResetEvent finishSignal, DalamudConfiguration configuration)
        {
#if DEBUG
            Instance = this;
#endif
            this.StartInfo      = info;
            this.LogLevelSwitch = loggingLevelSwitch;
            this.Configuration  = configuration;

            // this.baseDirectory = info.WorkingDirectory;

            this.unloadSignal = new ManualResetEvent(false);
            this.unloadSignal.Reset();

            this.finishUnloadSignal = finishSignal;
            this.finishUnloadSignal.Reset();
        }
Ejemplo n.º 13
0
        public void Start()
        {
            Configuration = DalamudConfiguration.Load(StartInfo.ConfigurationPath);

            // Initialize the process information.
            TargetModule = Process.GetCurrentProcess().MainModule;
            SigScanner   = new SigScanner(TargetModule, true);

            AntiDebug = new AntiDebug(SigScanner);
#if DEBUG
            AntiDebug.Enable();
#endif

            // Initialize game subsystem
            Framework = new Framework(SigScanner, this);

            WinSock2 = new WinSockHandlers();

            NetworkHandlers = new NetworkHandlers(this, StartInfo.OptOutMbCollection);

            ClientState = new ClientState(this, StartInfo, SigScanner);

            LocalizationManager = new Localization(AssetDirectory.FullName);
            if (!string.IsNullOrEmpty(Configuration.LanguageOverride))
            {
                LocalizationManager.SetupWithLangCode(Configuration.LanguageOverride);
            }
            else
            {
                LocalizationManager.SetupWithUiCulture();
            }

            PluginRepository = new PluginRepository(this, StartInfo.PluginDirectory, StartInfo.GameVersion);

            DalamudUi = new DalamudInterface(this);

            var isInterfaceLoaded = false;
            if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_INTERFACE") ?? "false"))
            {
                try {
                    InterfaceManager         = new InterfaceManager(this, SigScanner);
                    InterfaceManager.OnDraw += DalamudUi.Draw;

                    InterfaceManager.Enable();
                    isInterfaceLoaded = true;
                } catch (Exception e) {
                    Log.Information(e, "Could not init interface.");
                }
            }

            Data = new DataManager(StartInfo.Language);
            try {
                Data.Initialize(AssetDirectory.FullName);
            } catch (Exception e) {
                Log.Error(e, "Could not initialize DataManager.");
                Unload();
                return;
            }

            SeStringManager = new SeStringManager(Data);

            // Initialize managers. Basically handlers for the logic
            CommandManager  = new CommandManager(this, StartInfo.Language);
            DalamudCommands = new DalamudCommands(this);
            DalamudCommands.SetupCommands();

            ChatHandlers = new ChatHandlers(this);

            if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false"))
            {
                try
                {
                    PluginRepository.CleanupPlugins();

                    PluginManager =
                        new PluginManager(this, StartInfo.PluginDirectory, StartInfo.DefaultPluginDirectory);
                    PluginManager.LoadPlugins();
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Plugin load failed.");
                }
            }

            Framework.Enable();
            ClientState.Enable();

            IsReady = true;

            Troubleshooting.LogTroubleshooting(this, isInterfaceLoaded);

            Log.Information("Dalamud is ready.");
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Dalamud"/> class.
        /// </summary>
        /// <param name="info">DalamudStartInfo instance.</param>
        /// <param name="loggingLevelSwitch">LoggingLevelSwitch to control Serilog level.</param>
        /// <param name="finishSignal">Signal signalling shutdown.</param>
        /// <param name="configuration">The Dalamud configuration.</param>
        public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch, ManualResetEvent finishSignal, DalamudConfiguration configuration)
        {
            this.ApplyProcessPatch();

            Service <Dalamud> .Set(this);

            Service <DalamudStartInfo> .Set(info);

            Service <DalamudConfiguration> .Set(configuration);

            this.LogLevelSwitch = loggingLevelSwitch;

            // TODO: Just for testing, force verbose logging
            this.LogLevelSwitch.MinimumLevel = LogEventLevel.Verbose;

            this.unloadSignal = new ManualResetEvent(false);
            this.unloadSignal.Reset();

            this.finishUnloadSignal = finishSignal;
            this.finishUnloadSignal.Reset();
        }