public MainProgram() { if (!Directory.Exists(ConfigPath)) { Directory.CreateDirectory(ConfigPath); } string filePath = Path.Combine(ConfigPath, "Config.cfg"); PSettings = new PluginSettings(filePath); try { PSettings.LoadConfig(); } catch (Exception e) { new FileInfo(filePath).MoveTo(Path.Combine(ConfigPath, "BrokenConfig.cfg")); PSettings.SaveConfig(); MessageBox.Show($"载入配置文件失败:{e}\n损坏的配置文件已保存至BrokenConfig.cfg,新的配置文件已生成", "更多日志", MessageBoxButton.OK, MessageBoxImage.Warning); } if (PSettings.Enabled) { this.Start(); } SettingsWnd = new SettingsWindow(PSettings); DmjWnd = Application.Current.MainWindow; this.PluginName = "更多日志"; try { this.PluginAuth = BiliUtils.GetUserNameByUserId(35744708); } catch { this.PluginAuth = "Executor丶"; } this.PluginVer = Assembly.GetExecutingAssembly().GetName().Version.ToString(3); this.PluginDesc = "管理弹幕姬日志输出行为"; this.PluginCont = "*****@*****.**"; Type dmjType = DmjWnd.GetType(); DanmakuQueue = (Queue <DanmakuModel>)dmjType.GetField("_danmakuQueue", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic).GetValue(DmjWnd); Logging = dmjType.GetMethod("logging", BindingFlags.Instance | BindingFlags.Public); AddDMText = dmjType.GetMethod("AddDMText", BindingFlags.Instance | BindingFlags.Public); SendSSP = dmjType.GetMethod("SendSSP", BindingFlags.Instance | BindingFlags.Public); BaseProcDanmaku = dmjType.GetMethod("ProcDanmaku", BindingFlags.Instance | BindingFlags.NonPublic); Static = dmjType.GetField("Static", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic).GetValue(DmjWnd); AddUser = Static.GetType().GetMethod("AddUser", BindingFlags.Instance | BindingFlags.Public); DanmakuCountShow = Static.GetType().GetProperty("DanmakuCountShow", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public); EnabledShowError = dmjType.GetField("showerror_enabled", BindingFlags.Instance | BindingFlags.NonPublic); EnabledIgnoreSpam = dmjType.GetField("ignorespam_enabled", BindingFlags.Instance | BindingFlags.NonPublic); ((Thread)dmjType.GetField("ProcDanmakuThread", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic).GetValue(DmjWnd)).Abort(); new Thread(() => { while (true) { lock (DanmakuQueue) { var count = 0; if (DanmakuQueue.Any()) { count = (int)Math.Ceiling(DanmakuQueue.Count / 30.0); } for (var i = 0; i < count; i++) { if (DanmakuQueue.Any()) { var danmaku = DanmakuQueue.Dequeue(); ProcDanmaku(danmaku); if (danmaku.MsgType == MsgTypeEnum.Comment) { lock (Static) { AddDanmakuCountShow(); AddUser.Invoke(Static, new object[] { danmaku.UserName }); } } } } } Thread.Sleep(30); } }) { IsBackground = true }.Start(); }
//private PluginSettings PSettings { get; } public SettingsWindow(PluginSettings pSettings) { //PSettings = pSettings; InitializeComponent(); this.DataContext = pSettings; }