Пример #1
0
        public static void ApplyUpdateFiles(string pluginDirectory)
        {
            var pluginTempUpdateDir = Path.Combine(pluginDirectory, UpdateTempDir);

            if (Directory.Exists(pluginTempUpdateDir))
            {
                PluginUpdateLog.Clear();

                var backupDir = Path.Combine(pluginDirectory, UpdateBackupDir);

                if (Directory.Exists(backupDir))
                {
                    FileOperationAPIWrapper.MoveToRecycleBin(backupDir);
                }

                var logFilePAth = Path.Combine(pluginDirectory, "%PluginUpdateLog.txt");
                if (File.Exists(logFilePAth))
                {
                    File.Delete(logFilePAth);
                }

                if (MoveDirectoryFiles(pluginDirectory, pluginTempUpdateDir, pluginDirectory))
                {
                    PluginUpdateLog.Add("Deleting temp dir:\t" + pluginTempUpdateDir);
                    Directory.Delete(pluginTempUpdateDir, true);
                }
                else
                {
                    BasePlugin.LogMessage("PoeHUD PluginUpdater: some files wasn't moved or replaced while update (check %PluginUpdateLog.txt). You can move them manually: " + pluginTempUpdateDir, 20);
                    File.WriteAllLines(logFilePAth, PluginUpdateLog.ToArray());
                }
            }
        }
Пример #2
0
        public static void ApplyTheme(string fileName)
        {
            var theme = LoadTheme(fileName, true);

            if (theme == null)
            {
                BasePlugin.LogMessage($"Can't find theme file {fileName}, loading default.", 3);
                theme = LoadTheme(DefaultThemeName, true);
                if (theme == null)
                {
                    BasePlugin.LogMessage($"Can't find default theme file {DefaultThemeName}, Generating default and saving...", 3);
                    theme = GenerateDefaultTheme();
                    SaveTheme(theme, DefaultThemeName);
                }
            }
            ApplyTheme(theme);
        }
Пример #3
0
        public static void LoadPluginFromDirectory(string directory)
        {
            var dInfo = new DirectoryInfo(directory);

            if (!dInfo.Exists)
            {
                BasePlugin.LogMessage("PoeHUD.LoadPluginFromDirectory: Directory doesn't exist: " + directory, 10);
                return;
            }

            var directoryDlls = dInfo.GetFiles("*.dll", SearchOption.TopDirectoryOnly);

            foreach (var dll in directoryDlls)
            {
                BasePlugin.API.TryLoadDll(dll.FullName, directory);
            }
        }
Пример #4
0
        private void DllChanged(object sender, FileSystemEventArgs e)
        {
            if (!MainMenuWindow.Settings.AutoReloadDllOnChanges.Value)
            {
                return;
            }
            if (e.FullPath != _dllPath)
            {
                return;                         //Watchin only dll file
            }
            //Events being raised multiple times https://stackoverflow.com/questions/1764809/filesystemwatcher-changed-event-is-raised-twice
            var lastWriteTime = File.GetLastWriteTime(e.FullPath);

            if (Math.Abs((lastWriteTime - _lastWrite).TotalSeconds) < 1)
            {
                return;
            }

            _lastWrite = lastWriteTime;

            if (!File.Exists(_dllPath))
            {
                State = PluginState.Reload_DllNotFound;
                return;
            }

            try
            {
                ReloadPlugin(true);
                BasePlugin.LogMessage($"Reloaded dll: {Path.GetFileName(_dllPath)}", 3);
            }
            catch (Exception ex)
            {
                BasePlugin.LogError($"Cannot reload dll: {Path.GetFileName(_dllPath)}, Error: {ex.Message}", 3);
            }
        }
Пример #5
0
        public static List <CustomFilter> Parse(string[] filtersLines)
        {
            var allFilters = new List <CustomFilter>();

            for (var i = 0; i < filtersLines.Length; ++i)
            {
                var filterLine = filtersLines[i];

                filterLine = filterLine.Replace("\t", "");

                if (filterLine.StartsWith(COMMENTSYMBOL))
                {
                    continue;
                }
                if (filterLine.StartsWith(COMMENTSYMBOLALT))
                {
                    continue;
                }

                if (filterLine.Replace(" ", "").Length == 0)
                {
                    continue;
                }

                var nameIndex = filterLine.IndexOf(SYMBOL_NAMEDIVIDE);
                if (nameIndex == -1)
                {
                    BasePlugin.LogMessage("Filter parser: Can't find filter name in line: " + (i + 1), 5);
                    continue;
                }
                var newFilter = new CustomFilter {
                    Name = filterLine.Substring(0, nameIndex)
                };
                TrimName(ref newFilter.Name);

                var filterCommandsLine = filterLine.Substring(nameIndex + 1);

                var submenuIndex = filterCommandsLine.IndexOf(SYMBOL_SUBMENUNAME);
                if (submenuIndex != -1)
                {
                    newFilter.SubmenuName = filterCommandsLine.Substring(submenuIndex + 1);
                    filterCommandsLine    = filterCommandsLine.Substring(0, submenuIndex);
                }

                var filterCommands = filterCommandsLine.Split(SYMBOL_COMMANDSDIVIDE);

                var filterErrorParse = false;

                foreach (var command in filterCommands)
                {
                    if (string.IsNullOrEmpty(command.Replace(" ", "")))
                    {
                        continue;
                    }

                    if (command.Contains(SYMBOL_COMMAND_FILTER_OR))
                    {
                        var orFilterCommands = command.Split(SYMBOL_COMMAND_FILTER_OR);
                        var newOrFilter      = new BaseFilter {
                            BAny = true
                        };
                        newFilter.Filters.Add(newOrFilter);

                        foreach (var t in orFilterCommands)
                        {
                            if (ProcessCommand(newOrFilter, t))
                            {
                                continue;
                            }
                            filterErrorParse = true;
                            break;
                        }

                        if (filterErrorParse)
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (ProcessCommand(newFilter, command))
                        {
                            continue;
                        }

                        filterErrorParse = true;
                        break;
                    }
                }

                if (!filterErrorParse)
                {
                    allFilters.Add(newFilter);
                }
            }
            return(allFilters);
        }
Пример #6
0
        private static bool ProcessCommand(BaseFilter newFilter, string command)
        {
            TrimName(ref command);

            if (command.Contains(PARAMETER_IDENTIFIED))
            {
                var identCommand = new IdentifiedItemFilter {
                    BIdentified = command[0] != SYMBOL_NOT
                };
                newFilter.Filters.Add(identCommand);
                return(true);
            }

            if (command.Contains(PARAMETER_ISCORRUPTED))
            {
                var corruptedCommand = new CorruptedItemFilter {
                    BCorrupted = command[0] != SYMBOL_NOT
                };
                newFilter.Filters.Add(corruptedCommand);
                return(true);
            }

            if (command.Contains(PARAMETER_ISELDER))
            {
                var elderCommand = new ElderItemFiler {
                    IsElder = command[0] != SYMBOL_NOT
                };
                newFilter.Filters.Add(elderCommand);
                return(true);
            }

            if (command.Contains(PARAMETER_ISSHAPER))
            {
                var shaperCommand = new ShaperItemFiler {
                    IsShaper = command[0] != SYMBOL_NOT
                };
                newFilter.Filters.Add(shaperCommand);
                return(true);
            }

            if (!ParseCommand(command, out var parameter, out var operation, out var value))
            {
                BasePlugin.LogMessage("Filter parser: Can't parse filter part: " + command, 5);
                return(false);
            }

            var stringComp = new FilterParameterCompare {
                CompareString = value
            };
            var isNumeric = int.TryParse(value, out var n);

            if (isNumeric)
            {
                stringComp.CompareInt = n;
            }

            switch (parameter.ToLower( ))
            {
            case PARAMETER_CLASSNAME:
                stringComp.StringParameter = data => data.ClassName;
                break;

            case PARAMETER_NAME:
                stringComp.StringParameter = data => data.Name;
                break;

            case PARAMETER_BASENAME:
                stringComp.StringParameter = data => data.BaseName;
                break;

            case PARAMETER_PATH:
                stringComp.StringParameter = data => data.Path;
                break;

            case PARAMETER_RARITY:
                stringComp.StringParameter = data => data.Rarity.ToString( );
                break;

            case PARAMETER_QUALITY:
                stringComp.IntParameter    = data => data.ItemQuality;
                stringComp.StringParameter = data => data.ItemQuality.ToString( );
                break;

            case PARAMETER_MAP_TIER:
                stringComp.IntParameter    = data => data.MapTier;
                stringComp.StringParameter = data => data.MapTier.ToString( );
                break;

            case PARAMETER_ILVL:
                stringComp.IntParameter    = data => data.ItemLevel;
                stringComp.StringParameter = data => data.ItemLevel.ToString( );
                break;

            default:
                BasePlugin.LogMessage(
                    $"Filter parser: Parameter is not defined in code: {parameter}", 10);
                return(false);
            }

            switch (operation.ToLower( ))
            {
            case OPERATION_EQUALITY:
                stringComp.CompDeleg = data => stringComp.StringParameter(data).Equals(stringComp.CompareString);
                break;

            case OPERATION_NONEQUALITY:
                stringComp.CompDeleg = data => !stringComp.StringParameter(data).Equals(stringComp.CompareString);
                break;

            case OPERATION_CONTAINS:
                stringComp.CompDeleg = data => stringComp.StringParameter(data).Contains(stringComp.CompareString);
                break;

            case OPERATION_NOTCONTAINS:
                stringComp.CompDeleg = data => !stringComp.StringParameter(data).Contains(stringComp.CompareString);
                break;

            case OPERATION_BIGGER:
                if (stringComp.IntParameter == null)
                {
                    BasePlugin.LogMessage(
                        $"Filter parser error: Can't compare string parameter with {OPERATION_BIGGER} (numerical) operation. Statement: {command}",
                        10);
                    return(false);
                }
                stringComp.CompDeleg = data => stringComp.IntParameter(data) > stringComp.CompareInt;
                break;

            case OPERATION_LESS:
                if (stringComp.IntParameter == null)
                {
                    BasePlugin.LogMessage(
                        $"Filter parser error: Can't compare string parameter with {OPERATION_LESS} (numerical) operation. Statement: {command}",
                        10);
                    return(false);
                }
                stringComp.CompDeleg = data => stringComp.IntParameter(data) < stringComp.CompareInt;
                break;

            case OPERATION_LESSEQUAL:
                if (stringComp.IntParameter == null)
                {
                    BasePlugin.LogMessage(
                        $"Filter parser error: Can't compare string parameter with {OPERATION_LESSEQUAL} (numerical) operation. Statement: {command}",
                        10);
                    return(false);
                }
                stringComp.CompDeleg = data => stringComp.IntParameter(data) <= stringComp.CompareInt;
                break;

            case OPERATION_BIGGERQUAL:
                if (stringComp.IntParameter == null)
                {
                    BasePlugin.LogMessage(
                        $"Filter parser error: Can't compare string parameter with {OPERATION_BIGGERQUAL} (numerical) operation. Statement: {command}",
                        10);
                    return(false);
                }
                stringComp.CompDeleg = data => stringComp.IntParameter(data) >= stringComp.CompareInt;
                break;

            default:
                BasePlugin.LogMessage(
                    $"Filter parser: Operation is not defined in code: {operation}", 10);
                return(false);
            }

            newFilter.Filters.Add(stringComp);
            return(true);
        }
Пример #7
0
        public static void Parse(PluginToUpdate plugVariant)
        {
            try
            {
                var gitConfigFilePath = Path.Combine(plugVariant.PluginDirectory, ConfigFileName);

                if (File.Exists(gitConfigFilePath))
                {
                    plugVariant.bHasGitConfig = true;
                    var configLines = File.ReadAllLines(gitConfigFilePath);



                    var handleIgnore = false;
                    for (var i = 0; i < configLines.Length; i++)
                    {
                        var line = configLines[i];
                        if (line.StartsWith("#"))
                        {
                            continue;
                        }

                        var spacelessLine = line.Replace(" ", "");
                        if (spacelessLine.Replace("\r", "").Replace("\n", "").Length == 0)
                        {
                            continue;
                        }

                        if (handleIgnore)
                        {
                            plugVariant.IgnoredEntities.Add(line);
                            continue;
                        }
                        if (spacelessLine == OPTION_FILESIGNORE)
                        {
                            handleIgnore = true;
                            continue;
                        }

                        //Repository owner
                        var ownerIndex = line.IndexOf(OPTION_OWNER);
                        if (ownerIndex != -1)
                        {
                            plugVariant.RepoOwner = line.Substring(ownerIndex + OPTION_OWNER.Length);
                            TrimName(ref plugVariant.RepoOwner);
                            continue;
                        }

                        //Repository name
                        var reposNameIndex = line.IndexOf(OPTION_REPONAME);
                        if (reposNameIndex != -1)
                        {
                            plugVariant.RepoName = line.Substring(reposNameIndex + OPTION_REPONAME.Length);
                            TrimName(ref plugVariant.RepoName);
                            continue;
                        }

                        //Only from release
                        if (spacelessLine == OPTION_RELEASE)
                        {
                            if (plugVariant.UpdateVariant != ePluginSourceOfUpdate.Undefined)
                            {
                                BasePlugin.LogMessage(
                                    "PluginUpdater: " + plugVariant.PluginName +
                                    ",  both update variants (Release and Commit) is not allowed. Check GitUpdateConfig. Current update variant is: " +
                                    plugVariant.UpdateVariant, 10);
                            }
                            else
                            {
                                plugVariant.UpdateVariant = ePluginSourceOfUpdate.Release;
                            }
                            continue;
                        }

                        //Only from repository
                        if (spacelessLine == OPTION_REPOONLY)
                        {
                            if (plugVariant.UpdateVariant != ePluginSourceOfUpdate.Undefined)
                            {
                                BasePlugin.LogMessage(
                                    "PluginUpdater: " + plugVariant.PluginName +
                                    ",  both update variants (Release and Commit) is not allowed. Check GitUpdateConfig. Current update variant is: " +
                                    plugVariant.UpdateVariant, 10);
                            }
                            else
                            {
                                plugVariant.UpdateVariant = ePluginSourceOfUpdate.RepoBranch;
                            }
                            continue;
                        }

                        //Release tag regex filter
                        var tagIndex = line.IndexOf(OPTION_RELEASETAGREGEXFILTER);
                        if (tagIndex != -1)
                        {
                            plugVariant.ReleaseRegexTag = line.Substring(tagIndex + OPTION_RELEASETAGREGEXFILTER.Length);
                            TrimName(ref plugVariant.ReleaseRegexTag);
                            plugVariant.bCustomTag = true;
                        }

                        var branchNameIndex = line.IndexOf(OPTION_REPOBRANCH);
                        if (branchNameIndex != -1)
                        {
                            plugVariant.BranchName = line.Substring(branchNameIndex + OPTION_REPOBRANCH.Length);
                            TrimName(ref plugVariant.BranchName);
                        }
                    }

                    plugVariant.bAllowCheckUpdate = true;

                    if (string.IsNullOrEmpty(plugVariant.RepoOwner))
                    {
                        BasePlugin.LogError("PluginUpdater: Repository Owner is not defined in plugin: " + plugVariant.PluginName, 10);
                        plugVariant.UpdateState       = ePluginUpdateState.WrongConfig;
                        plugVariant.bAllowCheckUpdate = false;
                    }
                    if (string.IsNullOrEmpty(plugVariant.RepoName))
                    {
                        BasePlugin.LogError("PluginUpdater: Repository Name is not defined in plugin: " + plugVariant.PluginName, 10);
                        plugVariant.UpdateState       = ePluginUpdateState.WrongConfig;
                        plugVariant.bAllowCheckUpdate = false;
                    }
                    if (plugVariant.UpdateVariant == ePluginSourceOfUpdate.Undefined)
                    {
                        BasePlugin.LogError("PluginUpdater: Update type (Release or Repository) is not defined in plugin: " + plugVariant.PluginName, 10);
                        plugVariant.UpdateState       = ePluginUpdateState.WrongConfig;
                        plugVariant.bAllowCheckUpdate = false;
                    }
                }
            }
            catch
            {
                BasePlugin.LogError("PluginUpdater: Error while parsing git update config for plugin: " + plugVariant.PluginName, 10);
            }
        }
        public bool SwitchToTab(int tabIndex, FullRareSetManagerSettings Settings)
        {
            var latency = (int)GameController.Game.IngameState.CurLatency;
            // We don't want to Switch to a tab that we are already on
            var openLeftPanel = GameController.Game.IngameState.IngameUi.OpenLeftPanel;

            try
            {
                var stashTabToGoTo =
                    GameController.Game.IngameState.ServerData.StashPanel.GetStashInventoryByIndex(tabIndex)
                    .InventoryUiElement;

                if (stashTabToGoTo.IsVisible)
                {
                    return(true);
                }
            }
            catch
            {
                // Nothing to see here officer.
            }

            var _clickWindowOffset = GameController.Window.GetWindowRectangle().TopLeft;
            // We want to maximum wait 20 times the Current Latency before giving up in our while loops.
            var maxNumberOfTries = latency * 20 > 2000 ? latency * 20 / WHILE_DELAY : 2000 / WHILE_DELAY;

            if (tabIndex > 30)
            {
                return(SwitchToTabViaArrowKeys(tabIndex));
            }

            var stashPanel = GameController.Game.IngameState.ServerData.StashPanel;

            try
            {
                var viewAllTabsButton = GameController.Game.IngameState.ServerData.StashPanel.ViewAllStashButton;

                if (stashPanel.IsVisible && !viewAllTabsButton.IsVisible)
                {
                    // The user doesn't have a view all tabs button, eg. 4 tabs.
                    return(SwitchToTabViaArrowKeys(tabIndex));
                }

                var dropDownTabElements = GameController.Game.IngameState.ServerData.StashPanel.ViewAllStashPanel;

                if (!dropDownTabElements.IsVisible)
                {
                    var pos = viewAllTabsButton.GetClientRect();
                    Mouse.SetCursorPosAndLeftClick(pos.Center + _clickWindowOffset, Settings.ExtraDelay);
                    //Thread.Sleep(200);
                    Thread.Sleep(latency + Settings.ExtraDelay);
                    var brCounter = 0;

                    while (1 == 2 && !dropDownTabElements.IsVisible)
                    {
                        Thread.Sleep(WHILE_DELAY);

                        if (brCounter++ <= maxNumberOfTries)
                        {
                            continue;
                        }
                        BasePlugin.LogMessage($"1. Error in SwitchToTab: {tabIndex}.", 5);
                        return(false);
                    }

                    if (GameController.Game.IngameState.ServerData.StashPanel.TotalStashes > 30)
                    {
                        // TODO:Zafaar implemented something that allows us to get in contact with the ScrollBar.
                        Mouse.VerticalScroll(true, 5);
                        Thread.Sleep(latency + Settings.ExtraDelay);
                    }
                }


                // Dropdown menu have the following children: 0, 1, 2.
                // Where:
                // 0 is the icon (fx. chaos orb).
                // 1 is the name of the tab.
                // 2 is the slider.
                var        totalStashes = GameController.Game.IngameState.ServerData.StashPanel.TotalStashes;
                var        slider       = dropDownTabElements.Children[1].ChildCount == totalStashes;
                var        noSlider     = dropDownTabElements.Children[2].ChildCount == totalStashes;
                RectangleF tabPos;
                if (slider)
                {
                    tabPos = dropDownTabElements.GetChildAtIndex(1).GetChildAtIndex(tabIndex).GetClientRect();
                }
                else if (noSlider)
                {
                    tabPos = dropDownTabElements.GetChildAtIndex(2).GetChildAtIndex(tabIndex).GetClientRect();
                }
                else
                {
                    BasePlugin.LogError("Couldn't detect slider/non-slider, contact Preaches [Stashie]", 3);
                    return(false);
                }

                Mouse.SetCursorPosAndLeftClick(tabPos.Center + _clickWindowOffset, Settings.ExtraDelay);
                Thread.Sleep(latency + Settings.ExtraDelay);
            }
            catch (Exception e)
            {
                BasePlugin.LogError($"Error in GoToTab {tabIndex}: {e.Message}", 5);
                return(false);
            }

            Inventory stash;

            var counter = 0;

            do
            {
                Thread.Sleep(WHILE_DELAY);
                stash = stashPanel.VisibleStash;

                if (counter++ <= maxNumberOfTries)
                {
                    continue;
                }
                BasePlugin.LogMessage("2. Error opening stash: " + tabIndex, 5);
                return(true);
            } while (stash?.VisibleInventoryItems == null);
            return(true);
        }
Пример #9
0
        public async void UpdatePlugin()
        {
            if (FilesToDownload.Count == 0)
            {
                BasePlugin.LogMessage(
                    "Plugin don't have download information (changed files or release zip is not found)", 10);
                return;
            }

            var updateDirectory = Path.Combine(PluginDirectory, PoeHUD_PluginsUpdater.UpdateTempDir);

            if (Directory.Exists(updateDirectory))
            {
                Directory.Delete(updateDirectory, true);
            }

            Directory.CreateDirectory(updateDirectory);

            if (UpdateVariant == ePluginSourceOfUpdate.Release)
            {
                #region Release

                InstallProgress = "Preparing to download...";

                try
                {
                    using (var webClient = new WebClient())
                    {
                        webClient.DownloadProgressChanged +=
                            (s, e) => { InstallProgress = "Downloading: " + e.ProgressPercentage + "%"; };

                        var downloadFile = FilesToDownload[0];

                        var filename = downloadFile.Path;
                        await webClient.DownloadFileTaskAsync(downloadFile.Url, downloadFile.Path);

                        InstallProgress = "Extracting zip...";
                        ZipFile.ExtractToDirectory(filename, updateDirectory);
                        InstallProgress = "Extracting: Ok";

                        File.Delete(filename);


                        var dirInfo      = new DirectoryInfo(updateDirectory);
                        var dirInfoDirs  = dirInfo.GetDirectories();
                        var dirInfoFiles = dirInfo.GetFiles();

                        if (dirInfoDirs.Length == 1 && dirInfoFiles.Length == 0)
                        {
                            InstallProgress = "Fixing files hierarchy..";
                            var subDir = dirInfoDirs[0];

                            foreach (var file in subDir.GetFiles())
                            {
                                var destFile = Path.Combine(updateDirectory, file.Name);
                                File.Move(file.FullName, destFile);
                            }
                            foreach (var directory in subDir.GetDirectories())
                            {
                                var destDir = Path.Combine(updateDirectory, directory.Name);
                                Directory.Move(directory.FullName, destDir);
                            }
                            Directory.Delete(subDir.FullName);
                        }


                        foreach (var ignoreFile in IgnoredEntities)
                        {
                            var ignorePath = Path.Combine(updateDirectory, ignoreFile);

                            if (File.Exists(ignorePath))
                            {
                                File.Delete(ignorePath);
                                BasePlugin.LogMessage("Ignore File: " + ignorePath, 5);
                            }
                            else if (Directory.Exists(ignorePath))
                            {
                                Directory.Delete(ignorePath, true);
                                BasePlugin.LogMessage("Ignore Directory: " + ignorePath, 5);
                            }
                        }

                        InstallProgress = "";

                        var versionFilePath = Path.Combine(updateDirectory, PoeHUD_PluginsUpdater.VersionFileName);
                        File.WriteAllText(versionFilePath, RemoteVersion + Environment.NewLine + RemoteTag);

                        UpdateState = ePluginUpdateState.ReadyToInstal;
                    }
                }
                catch (Exception ex)
                {
                    InstallProgress = "Error updating";
                    BasePlugin.LogError(
                        "Plugins Updater: Error while updating plugin: " + PluginName + ", Error: " + ex.Message, 10);
                }
                DoAfterUpdate(this);
                #endregion
            }
            else if (UpdateVariant == ePluginSourceOfUpdate.RepoBranch)
            {
                InstallProgress = "Preparing to download...";

                try
                {
                    var downloadCount   = FilesToDownload.Count;
                    var downloadedCount = 0;

                    using (var webClient = new WebClient())
                    {
                        webClient.DownloadProgressChanged +=
                            (s, e) =>
                        {
                            InstallProgress = "Downloading: " + downloadedCount + "/" + downloadCount + " (" +
                                              e.ProgressPercentage + "%)";
                        };

                        foreach (var downloadFile in FilesToDownload)
                        {
                            var downloadDir = Path.GetDirectoryName(downloadFile.Path);
                            if (!Directory.Exists(downloadDir))
                            {
                                Directory.CreateDirectory(downloadDir);
                            }

                            await webClient.DownloadFileTaskAsync(downloadFile.Url, downloadFile.Path);

                            InstallProgress = "Downloading: " + downloadedCount + "/" + downloadCount;
                            downloadedCount++;
                        }

                        InstallProgress = "";

                        UpdateState = ePluginUpdateState.ReadyToInstal;
                    }
                }
                catch (Exception ex)
                {
                    InstallProgress = "Error updating";
                    BasePlugin.LogError(
                        "Plugins Updater: Error while updating plugin: " + PluginName + ", Error: " + ex.Message, 10);
                }
                DoAfterUpdate(this);
            }
            else
            {
                BasePlugin.LogMessage("Update type is not supported in code: " + UpdateVariant, 5);
            }
        }
Пример #10
0
 public void LogMessage(object message, float displayTime)
 {
     BasePlugin.LogMessage(message, displayTime);
 }
Пример #11
0
        public static List <RefillProcessor> Parse(string pluginDir)
        {
            var refills = new List <RefillProcessor>();

            var refillConfigPath = Path.Combine(pluginDir, REFILL_CONFIG);

            if (!File.Exists(refillConfigPath))
            {
                return(refills);
            }

            var configLines = File.ReadAllLines(refillConfigPath);

            for (var i = 0; i < configLines.Length; i++)
            {
                var configLine = configLines[i];
                configLine = configLine.Replace("\t", "");
                if (configLine.Replace(" ", "").Length == 0)
                {
                    continue;
                }
                if (configLine.StartsWith(SYMBOL_IGNORE) || configLine.StartsWith(SYMBOL_IGNORE2))
                {
                    continue;
                }

                var newRefill = new RefillProcessor();

                var nameIndex = configLine.IndexOf(SYMBOL_NAMEDIVIDER, StringComparison.Ordinal);

                if (nameIndex == -1)
                {
                    BasePlugin.LogMessage(
                        $"Refill parser: Can't find refill name in line: {configLine}. Name should have \":\" divider.", 10);
                    continue;
                }

                newRefill.MenuName = configLine.Substring(0, nameIndex);
                TrimName(ref newRefill.MenuName);

                configLine = configLine.Substring(nameIndex + SYMBOL_NAMEDIVIDER.Length);

                var configLineParams = configLine.Split(SYMBOL_PARAMETERSDIVIDER);

                if (configLineParams.Length != 4)
                {
                    BasePlugin.LogMessage(
                        $"Refill parser: Config line should have 4 parameters (ClassName,StackSize,InventoryX,InventoryY): {configLine}, Ignoring refill..", 10);
                    continue;
                }

                newRefill.CurrencyClass = configLineParams[0];
                TrimName(ref newRefill.CurrencyClass);

                if (!int.TryParse(configLineParams[1], out newRefill.StackSize))
                {
                    BasePlugin.LogMessage(
                        $"Refill parser: Can't parse StackSize from 2nd parameter in line: {configLine} (line num: {i + 1}), Ignoring refill..",
                        10);
                    continue;
                }

                if (!int.TryParse(configLineParams[2], out newRefill.InventPos.X))
                {
                    BasePlugin.LogMessage(
                        $"Refill parser: Can't parse InventoryX from 3rd parameter in line: {configLine} (line num: {i + 1}), Ignoring refill..",
                        10);
                    continue;
                }
                if (newRefill.InventPos.X < 1 || newRefill.InventPos.X > 12)
                {
                    BasePlugin.LogMessage(
                        $"Refill parser: InventoryX should be in range 1-12, current value: {newRefill.InventPos.X}  (line num: {i + 1}), Ignoring refill..",
                        10);
                    continue;
                }

                if (!int.TryParse(configLineParams[3], out newRefill.InventPos.Y))
                {
                    BasePlugin.LogMessage(
                        $"Refill parser: Can't parse InventoryY from 4th parameter in line: {configLine} (line num: {i + 1}), Ignoring refill..",
                        10);
                    continue;
                }
                if (newRefill.InventPos.Y < 1 || newRefill.InventPos.Y > 5)
                {
                    BasePlugin.LogMessage(
                        $"Refill parser: InventPosY should be in range 1-5, current value: {newRefill.InventPos.Y} (line num: {i + 1}), Ignoring refill..",
                        10);
                    continue;
                }

                // Convert to zero based index.
                newRefill.InventPos.X--;
                newRefill.InventPos.Y--;

                refills.Add(newRefill);
            }
            return(refills);
        }
Пример #12
0
        public bool SwitchToTab(int tabIndex)
        {
            var latency = (int)GameController.Game.IngameState.CurLatency;
            // We don't want to Switch to a tab that we are already on
            var openLeftPanel = GameController.Game.IngameState.IngameUi.OpenLeftPanel;

            try
            {
                var stashTabToGoTo =
                    GameController.Game.IngameState.ServerData.StashPanel.GetStashInventoryByIndex(tabIndex)
                    .InventoryUiElement;

                if (stashTabToGoTo.IsVisible)
                {
                    return(true);
                }
            }
            catch
            {
                // Nothing to see here officer.
            }

            // We want to maximum wait 20 times the Current Latency before giving up in our while loops.
            var maxNumberOfTries  = latency * 20 > 2000 ? latency * 20 / WHILE_DELAY : 2000 / WHILE_DELAY;
            var clickWindowOffset = GameController.Window.GetWindowRectangle().TopLeft;

            if (tabIndex > 30)
            {
                return(SwitchToTabViaArrowKeys(tabIndex));
            }

            var stashPanel = GameController.Game.IngameState.ServerData.StashPanel;

            try
            {
                // Obs, this method only works with 31 stashtabs on 1920x1080, since you have to scroll at 32 tabs, and the frame stays in place.
                var viewAllTabsButton = GameController.Game.IngameState.ServerData.StashPanel.ViewAllStashButton;

                if (stashPanel.IsVisible && !viewAllTabsButton.IsVisible)
                {
                    // The user doesn't have a view all tabs button, eg. 4 tabs.
                    return(SwitchToTabViaArrowKeys(tabIndex));
                }

                var parent = openLeftPanel.Children[2].Children[0].Children[1].Children[3];
                var dropDownTabElements = parent.Children[2];

                var totalStashes = GameController.Game.IngameState.ServerData.StashPanel.TotalStashes;
                if (totalStashes > 30)
                {
                    dropDownTabElements = parent.Children[1];
                }

                if (!dropDownTabElements.IsVisible)
                {
                    var pos = viewAllTabsButton.GetClientRect();

                    Mouse.SetCursorPosAndLeftClick(pos.Center + clickWindowOffset);

                    var brCounter = 0;

                    while (!dropDownTabElements.IsVisible)
                    {
                        Thread.Sleep(WHILE_DELAY);

                        if (brCounter++ <= maxNumberOfTries)
                        {
                            continue;
                        }
                        BasePlugin.LogMessage($"1. Error in SwitchToTab: {tabIndex}.", 5);
                        return(false);
                    }

                    if (totalStashes > 30)
                    {
                        // TODO:Zafaar implemented something that allows us to get in contact with the ScrollBar.
                        Mouse.VerticalScroll(true, 5);
                        Thread.Sleep(latency + 50);
                    }
                }

                var tabPos = dropDownTabElements.Children[tabIndex].GetClientRect();

                Mouse.SetCursorPosAndLeftClick(tabPos.Center + clickWindowOffset);
                Thread.Sleep(latency);
            }
            catch (Exception e)
            {
                BasePlugin.LogError($"Error in GoToTab {tabIndex}: {e.Message}", 5);
                return(false);
            }

            Inventory stash;

            var counter = 0;

            do
            {
                Thread.Sleep(WHILE_DELAY);
                stash = stashPanel.VisibleStash;

                if (counter++ <= maxNumberOfTries)
                {
                    continue;
                }
                BasePlugin.LogMessage("2. Error opening stash: " + tabIndex, 5);
                return(false);
            } while (stash?.VisibleInventoryItems == null);
            return(true);
        }
Пример #13
0
        public void ReloadPlugin(bool actualyReload)
        {
            if (BPlugin != null)
            {
                BPlugin._OnClose(); //saving settings, closing opened threads (on plugin side)

                API.eRender        -= BPlugin._Render;
                API.eEntityAdded   -= BPlugin._EntityAdded;
                API.eEntityRemoved -= BPlugin._EntityRemoved;
                API.eClose         -= BPlugin._OnClose;
                API.eAreaChange    -= BPlugin._AreaChange;
                API.eInitialise    -= BPlugin._Initialise;
                BPlugin._OnPluginDestroyForHotReload();

                BPlugin = null;
                SettingPropertyDrawers.Clear();

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            Assembly asmToLoad;
            var      debugCymboldFilePath = _dllPath.Replace(".dll", ".pdb");

            if (File.Exists(debugCymboldFilePath))
            {
                var dbgCymboldBytes = File.ReadAllBytes(debugCymboldFilePath);
                asmToLoad = Assembly.Load(File.ReadAllBytes(_dllPath), dbgCymboldBytes);
            }
            else
            {
                asmToLoad = Assembly.Load(File.ReadAllBytes(_dllPath));
            }

            if (asmToLoad == null)
            {
                State = PluginState.Reload_DllNotFound;
                return;
            }

            var pluginType = asmToLoad.GetType(_fullTypeName);

            if (pluginType == null)
            {
                State = PluginState.Reload_ClassNotFound;
                return;
            }

            //Spawning a new plugin class instance
            object pluginClassObj = null;

            try
            {
                pluginClassObj = Activator.CreateInstance(pluginType);
            }
            catch (Exception ex)
            {
                BasePlugin.LogMessage($"Error loading plugin {Path.GetFileNameWithoutExtension(_dllPath)}: " + ex.Message, 3);
                State = PluginState.ErrorClassInstance;
                return;
            }

            BPlugin = pluginClassObj as BasePlugin;
            BPlugin.InitPlugin(this);
            Settings = BPlugin._LoadSettings();

            if (!string.IsNullOrEmpty(BPlugin.PluginName))
            {
                PluginName = BPlugin.PluginName;
            }

            API.eRender        += BPlugin._Render;
            API.eEntityAdded   += BPlugin._EntityAdded;
            API.eEntityRemoved += BPlugin._EntityRemoved;
            API.eClose         += BPlugin._OnClose;
            API.eInitialise    += BPlugin._Initialise;
            API.eAreaChange    += BPlugin._AreaChange;

            BPlugin._Initialise();

            if (actualyReload)
            {
                BPlugin._AreaChange(GameController.Instance.Area);
            }

            foreach (var entity in GameController.Instance.EntityListWrapper.Entities.ToList())
            {
                BPlugin._EntityAdded(entity);
            }
        }