Пример #1
0
        /// <summary>
        /// Runs tier 3 of the Dalamud initialization process.
        /// </summary>
        public void LoadTier3()
        {
            try
            {
                Log.Information("[T3] START!");

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

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

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

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

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

                        Task.Run(() => this.PluginManager.LoadDeferredPlugins());

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

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

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

                Troubleshooting.LogTroubleshooting(this, this.InterfaceManager != null);

                Log.Information("Dalamud is ready.");
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Tier 3 load failed.");
                this.Unload();
            }
        }
Пример #2
0
        private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs args)
        {
            switch (args.ExceptionObject)
            {
            case Exception ex:
                Log.Fatal(ex, "Unhandled exception on AppDomain");
                Troubleshooting.LogException(ex, "DalamudUnhandled");

                var info = "Further information could not be obtained";
                if (ex.TargetSite != null && ex.TargetSite.DeclaringType != null)
                {
                    info = $"{ex.TargetSite.DeclaringType.Assembly.GetName().Name}, {ex.TargetSite.DeclaringType.FullName}::{ex.TargetSite.Name}";
                }

                const MessageBoxType flags = NativeFunctions.MessageBoxType.YesNo | NativeFunctions.MessageBoxType.IconError | NativeFunctions.MessageBoxType.SystemModal;
                var result = MessageBoxW(
                    Process.GetCurrentProcess().MainWindowHandle,
                    $"An internal error in a Dalamud plugin occurred.\nThe game must close.\n\nType: {ex.GetType().Name}\n{info}\n\nMore information has been recorded separately, please contact us in our Discord or on GitHub.\n\nDo you want to disable all plugins the next time you start the game?",
                    "Dalamud",
                    flags);

                if (result == (int)User32.MessageBoxResult.IDYES)
                {
                    Log.Information("User chose to disable plugins on next launch...");
                    var config = Service <DalamudConfiguration> .Get();

                    config.PluginSafeMode = true;
                    config.Save();
                }

                Environment.Exit(-1);

                break;

            default:
                Log.Fatal("Unhandled SEH object on AppDomain: {Object}", args.ExceptionObject);
                break;
            }
        }
Пример #3
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();
            }
        }
Пример #4
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);
            });
        }
Пример #5
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.");
        }