Example #1
0
        private static void RecompilePlugins()
        {
            if (BotMain.IsRunning)
            {
                BotMain.Stop(false, "Recompiling Plugin!");
                while (BotMain.BotThread.IsAlive)
                {
                    Thread.Sleep(0);
                }
            }

            var EnabledPlugins = PluginManager.GetEnabledPlugins().ToArray();

            foreach (var p in PluginManager.Plugins)
            {
                p.Enabled = false;
            }

            PluginManager.ShutdownAllPlugins();

            Logger.DBLog.DebugFormat("Disposing All Routines");
            foreach (var r in RoutineManager.Routines)
            {
                r.Dispose();
            }



            string sDemonBuddyPath    = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            string sTrinityPluginPath = FolderPaths.PluginPath;

            CodeCompiler FunkyCode = new CodeCompiler(sTrinityPluginPath);

            //FunkyCode.ParseFilesForCompilerOptions();
            Logger.DBLog.DebugFormat("Recompiling Funky Bot");
            FunkyCode.Compile();
            Logger.DBLog.DebugFormat(FunkyCode.CompiledToLocation);

            Logger.DBLog.DebugFormat("Clearing all treehooks");
            TreeHooks.Instance.ClearAll();

            Logger.DBLog.DebugFormat("Disposing of current bot");
            BotMain.CurrentBot.Dispose();

            Logger.DBLog.DebugFormat("Removing old Assemblies");
            CodeCompiler.DeleteOldAssemblies();

            BrainBehavior.CreateBrain();

            Logger.DBLog.DebugFormat("Reloading Plugins");
            PluginManager.ReloadAllPlugins(sDemonBuddyPath + @"\Plugins\");

            Logger.DBLog.DebugFormat("Enabling Plugins");
            PluginManager.SetEnabledPlugins(EnabledPlugins);

            Logger.DBLog.DebugFormat("Reloading Routines");
            RoutineManager.Reload();
        }
Example #2
0
        /// <summary>
        /// Installs the latest version of the Trinity routine
        /// </summary>
        private static void InstallTrinityRoutine()
        {
            FileManager.CleanupOldRoutines();

            Logger.LogNormal("Combat routine is not installed or is not latest version, installing! {0}", FileManager.GetFileHeader(FileManager.CombatRoutineSourcePath));
            FileManager.CopyFile(FileManager.CombatRoutineSourcePath, FileManager.CombatRoutineDestinationPath);

            RoutineManager.Reload();
        }
Example #3
0
        public void OnInitialize()
        {
            bool        BotWasRunning = BotMain.IsRunning;
            SplitButton FunkyButton   = null;


            BotMain.OnStop  += EventHandlers.FunkyBotStop;
            BotMain.OnStart += EventHandlers.FunkyBotStart;


            bool FunkyCombatRoutineCurrent = RoutineManager.Current != null &&
                                             !String.IsNullOrEmpty(RoutineManager.Current.Name) && RoutineManager.Current.Name == "Funky";

            if (FunkyCombatRoutineCurrent)
            {
                #region FunkyButtonHandlerHook
                try
                {
                    Window mainWindow = App.Current.MainWindow;
                    var    tab        = mainWindow.FindName("tabControlMain") as TabControl;
                    if (tab == null)
                    {
                        return;
                    }
                    var infoDumpTab = tab.Items[0] as TabItem;
                    if (infoDumpTab == null)
                    {
                        return;
                    }
                    var grid = infoDumpTab.Content as Grid;
                    if (grid == null)
                    {
                        return;
                    }
                    FunkyButton = grid.FindName("Funky") as SplitButton;
                    if (FunkyButton != null)
                    {
                        Logger.DBLog.DebugFormat("Funky Button handler added");
                    }
                    else
                    {
                        SplitButton[] splitbuttons = grid.Children.OfType <SplitButton>().ToArray();
                        if (splitbuttons.Any())
                        {
                            foreach (var item in splitbuttons)
                            {
                                if (item.Name.Contains("Funky"))
                                {
                                    FunkyButton = item;
                                    break;
                                }
                            }
                        }
                    }
                    initFunkyButton = true;
                }
                catch
                {
                    Logger.DBLog.InfoFormat("Could not find Funky Button! Safely handled exception.");
                    initFunkyButton = false;
                }
                #endregion
            }

            string sRoutinePath         = FolderPaths.sDemonBuddyPath + @"\Routines\Funky\";
            string sPluginRoutineFolder = FolderPaths.sDemonBuddyPath + @"\Plugins\FunkyBot\CombatRoutine\";

            //DateTime RoutineCombatDate=System.IO.File.GetLastWriteTime(sRoutinePath+"CombatRoutine.cs");
            //DateTime RoutineDebugDate=System.IO.File.GetLastWriteTime(sRoutinePath+"RoutineDebug.cs");
            //DateTime PluginCombatDate=System.IO.File.GetLastWriteTime(sPluginRoutineFolder+"CombatRoutine");
            //DateTime PluginDebugDate=System.IO.File.GetLastWriteTime(sPluginRoutineFolder+"RoutineDebug");
            //bool RoutineFilesMismatch=RoutineCombatDate.CompareTo(PluginCombatDate)>0||RoutineDebugDate.CompareTo(PluginDebugDate)>0;
            if (!initFunkyButton)
            {
                //stop bot
                if (BotWasRunning)
                {
                    // Zeta.CommonBot.BotMain.Stop();
                }

                FunkyButton = null;
                FolderPaths.sDemonBuddyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                Logger.DBLog.DebugFormat("Reloading combat routine..");

                //Create Folder
                if (!Directory.Exists(sRoutinePath))
                {
                    Directory.CreateDirectory(sRoutinePath);
                }

                //Copy Files
                File.Copy(sPluginRoutineFolder + "CombatRoutine", sRoutinePath + "CombatRoutine.cs", true);
                File.Copy(sPluginRoutineFolder + "RoutineDebug", sRoutinePath + "RoutineDebug.cs", true);


                //Recompile Routine
                //Zeta.Common.Compiler.CodeCompiler FunkyRoutineCode=new Zeta.Common.Compiler.CodeCompiler(sRoutinePath);
                //FunkyRoutineCode.ParseFilesForCompilerOptions();
                //FunkyRoutineCode.Compile();
                //Logger.DBLog.DebugFormat(FunkyRoutineCode.CompiledToLocation);

                //Reload Routines
                RoutineManager.Reload();

                //remove
                File.Delete(sRoutinePath + "RoutineDebug.cs");
                File.Delete(sRoutinePath + "CombatRoutine.cs");
                Directory.Delete(sRoutinePath);

                //Search again..
                bool funkyRoutine = RoutineManager.Routines.Any(r => r.Name == "Funky");
                if (funkyRoutine)
                {
                    Logger.DBLog.DebugFormat("Setting Combat Routine to Funky");
                    RoutineManager.Current = RoutineManager.Routines.First(r => r.Name == "Funky");

                    #region FunkyButtonHandlerHook
                    try
                    {
                        FunkyButton     = FindFunkyButton();
                        initFunkyButton = true;
                    }
                    catch (Exception ex)
                    {
                        Logger.DBLog.InfoFormat("Could not find Funky Button! Safely handled exception.");
                        initFunkyButton = false;
                        Logger.DBLog.InfoFormat(ex.Message + "\r\n" + ex.StackTrace + "\r\n" + ex.Source);
                    }
                    #endregion
                }
                else
                {
                    //Failed to find the routine..
                    Logger.DBLog.InfoFormat("Failure to set Funky Routine because Routines cannot be reloaded again! Closing Demonbuddy...");
                    Process.GetCurrentProcess().CloseMainWindow();
                    return;
                }
            }



            if (initFunkyButton && FunkyButton != null)
            {
                Logger.DBLog.DebugFormat("Funky Split Button Click Handler Added");
                FunkyButton.Click += FunkyWindow.buttonFunkySettingDB_Click;
            }

            ObjectCache.SnoUnitPropertyCache = CacheUnitIDs.DeserializeFromXML();
            ObjectCache.FakeCacheObject      = new CacheObject(Vector3.Zero, TargetType.None, 0d, "Fake Target", 1f);

            //Update Account Details..
            Bot.Character.Account.UpdateCurrentAccountDetails();
            Logger.DBLogFile = DateTime.Now.ToString("yyyy-MM-dd hh.mm") + ".txt";
            Logger.Write(LogLevel.User, "Init Logger Completed!");

            //Generate Checksum for Update Check
            Process.Start(FolderPaths.sTrinityPluginPath + @"\CheckSum.exe");
            if (Updater.UpdateAvailable())
            {
                string dbPathString = Assembly.GetEntryAssembly().Location;
                string dbExePath    = Path.GetFullPath(dbPathString);
                Process.GetCurrentProcess().CloseMainWindow();
                Process.Start(dbExePath);
                return;
            }

            //test
        }