Exemple #1
0
        private void OverlayRenderCurrentPath()
        {
            if (AmeisenBot.WowInterface.MovementEngine.Path != null &&
                AmeisenBot.WowInterface.MovementEngine.Path.Count > 0)
            {
                List <Vector3> currentNodes = AmeisenBot.WowInterface.MovementEngine.Path.ToList();

                for (int i = 0; i < currentNodes.Count; ++i)
                {
                    Vector3 start = currentNodes[i];
                    Vector3 end   = i == 0 ? AmeisenBot.WowInterface.ObjectManager.Player.Position : currentNodes[i - 1];

                    System.Drawing.Color lineColor = System.Drawing.Color.White;
                    System.Drawing.Color startDot  = System.Drawing.Color.Cyan;
                    System.Drawing.Color endDot    = i == 0 ? System.Drawing.Color.Orange : i == currentNodes.Count ? System.Drawing.Color.Orange : System.Drawing.Color.Cyan;

                    Memory.Win32.Rect windowRect = XMemory.GetWindowPosition(AmeisenBot.WowInterface.XMemory.Process.MainWindowHandle);
                    if (OverlayMath.WorldToScreen(windowRect, AmeisenBot.WowInterface.ObjectManager.Camera, start, out System.Drawing.Point startPoint) &&
                        OverlayMath.WorldToScreen(windowRect, AmeisenBot.WowInterface.ObjectManager.Camera, end, out System.Drawing.Point endPoint))
                    {
                        Overlay.AddLine(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, lineColor);
                        Overlay.AddRectangle(startPoint.X - 4, startPoint.Y - 4, 7, 7, startDot);
                        Overlay.AddRectangle(endPoint.X - 4, endPoint.Y - 4, 7, 7, endDot);
                    }
                }
            }
        }
Exemple #2
0
 public HookManager(XMemory xMemory, IOffsetList offsetList, ObjectManager objectManager, IAmeisenBotCache botCache)
 {
     XMemory       = xMemory;
     OffsetList    = offsetList;
     ObjectManager = objectManager;
     BotCache      = botCache;
 }
Exemple #3
0
 public RunAsmHookModule(Action <IntPtr> onUpdate, Action tick, XMemory xMemory, uint allocSize)
 {
     XMemory      = xMemory;
     AllocSize    = allocSize;
     OnDataUpdate = onUpdate;
     Tick         = tick;
 }
Exemple #4
0
        public WowObject UpdateRawWowObject(XMemory xMemory)
        {
            if (xMemory.ReadStruct(DescriptorAddress, out RawWowObject rawWowObject))
            {
                RawWowObject = rawWowObject;
            }

            return(this);
        }
Exemple #5
0
 public void Clear(StringBuffer stringBuffer, ArrayPoolApi_I <char> bufferPool)
 {
     if (stringBuffer.Buffer != null)
     {
         XMemory.ReturnBuffer(bufferPool, stringBuffer.Buffer);
         stringBuffer.Buffer = null;
     }
     stringBuffer.Position = 0;
 }
Exemple #6
0
 public void InteractWithUnit(WowUnit unit, float turnSpeed = 20.9f, float distance = 3f)
 {
     XMemory.Write(OffsetList.ClickToMoveX, unit.Position.X);
     XMemory.Write(OffsetList.ClickToMoveY, unit.Position.Y);
     XMemory.Write(OffsetList.ClickToMoveZ, unit.Position.Z);
     XMemory.Write(OffsetList.ClickToMoveTurnSpeed, turnSpeed);
     XMemory.Write(OffsetList.ClickToMoveDistance, distance);
     XMemory.Write(OffsetList.ClickToMoveGuid, unit.Guid);
     XMemory.Write(OffsetList.ClickToMoveAction, (int)ClickToMoveType.Interact);
 }
Exemple #7
0
 public void InteractWithObject(WowObject obj, float turnSpeed = 20.9f, float distance = 3f)
 {
     XMemory.Write(OffsetList.ClickToMoveX, obj.Position.X);
     XMemory.Write(OffsetList.ClickToMoveY, obj.Position.Y);
     XMemory.Write(OffsetList.ClickToMoveZ, obj.Position.Z);
     XMemory.Write(OffsetList.ClickToMoveTurnSpeed, turnSpeed);
     XMemory.Write(OffsetList.ClickToMoveDistance, distance);
     XMemory.Write(OffsetList.ClickToMoveGuid, obj.Guid);
     XMemory.Write(OffsetList.ClickToMoveAction, (int)ClickToMoveType.InteractObject);
 }
Exemple #8
0
        public AmeisenBotStateMachine(
            string botDataPath,
            Process wowProcess,
            AmeisenBotConfig config,
            XMemory xMemory,
            IOffsetList offsetList,
            ObjectManager objectManager,
            CharacterManager characterManager,
            HookManager hookManager,
            EventHookManager eventHookManager,
            IAmeisenBotCache botCache,
            IPathfindingHandler pathfindingHandler,
            IMovementEngine movementEngine,
            ICombatClass combatClass)
        {
            AmeisenLogger.Instance.Log("Starting AmeisenBotStateMachine...", LogLevel.Verbose);

            BotDataPath      = botDataPath;
            Config           = config;
            XMemory          = xMemory;
            OffsetList       = offsetList;
            ObjectManager    = objectManager;
            CharacterManager = characterManager;
            HookManager      = hookManager;
            EventHookManager = eventHookManager;
            BotCache         = botCache;

            LastObjectUpdate = DateTime.Now;
            LastGhostCheck   = DateTime.Now;
            LastEventPull    = DateTime.Now;

            LastState    = AmeisenBotState.None;
            UnitLootList = new Queue <ulong>();

            States = new Dictionary <AmeisenBotState, State>()
            {
                { AmeisenBotState.None, new StateNone(this, config) },
                { AmeisenBotState.StartWow, new StateStartWow(this, config, wowProcess, xMemory) },
                { AmeisenBotState.Login, new StateLogin(this, config, offsetList, characterManager) },
                { AmeisenBotState.LoadingScreen, new StateLoadingScreen(this, xMemory, config, objectManager) },
                { AmeisenBotState.Idle, new StateIdle(this, config, offsetList, objectManager, characterManager, hookManager, eventHookManager, combatClass, UnitLootList) },
                { AmeisenBotState.Dead, new StateDead(this, config, objectManager, hookManager) },
                { AmeisenBotState.Ghost, new StateGhost(this, config, offsetList, objectManager, characterManager, hookManager, pathfindingHandler, movementEngine) },
                { AmeisenBotState.Following, new StateFollowing(this, config, objectManager, characterManager, pathfindingHandler, movementEngine) },
                { AmeisenBotState.Attacking, new StateAttacking(this, config, objectManager, characterManager, hookManager, pathfindingHandler, movementEngine, combatClass) },
                { AmeisenBotState.Repairing, new StateRepairing(this, config, objectManager, hookManager, characterManager, pathfindingHandler, movementEngine) },
                { AmeisenBotState.Selling, new StateSelling(this, config, objectManager, hookManager, characterManager, pathfindingHandler, movementEngine) },
                { AmeisenBotState.Healing, new StateEating(this, config, objectManager, characterManager) },
                { AmeisenBotState.InsideAoeDamage, new StateInsideAoeDamage(this, config, objectManager, characterManager, pathfindingHandler, movementEngine) },
                { AmeisenBotState.Looting, new StateLooting(this, config, offsetList, objectManager, characterManager, hookManager, pathfindingHandler, movementEngine, UnitLootList) }
            };

            CurrentState = States.First();
            CurrentState.Value.Enter();
        }
Exemple #9
0
        public WowCorpse UpdateRawWowCorpse(XMemory xMemory)
        {
            UpdateRawWowObject(xMemory);

            if (xMemory.ReadStruct(DescriptorAddress + RawWowObject.EndOffset, out RawWowCorpse rawWowCorpse))
            {
                RawWowCorpse = rawWowCorpse;
            }

            return(this);
        }
Exemple #10
0
        public WowPlayer UpdateRawWowPlayer(XMemory xMemory)
        {
            UpdateRawWowUnit(xMemory);

            if (xMemory.ReadStruct(DescriptorAddress + RawWowObject.EndOffset + RawWowUnit.EndOffset, out RawWowPlayer rawWowPlayer))
            {
                RawWowPlayer = rawWowPlayer;
            }

            return(this);
        }
Exemple #11
0
        public ObjectManager(XMemory xMemory, IOffsetList offsetList, IAmeisenBotCache botCache)
        {
            IsWorldLoaded = true;

            WowObjects = new List <WowObject>();
            XMemory    = xMemory;
            OffsetList = offsetList;
            BotCache   = botCache;

            EnableClickToMove();
        }
Exemple #12
0
        public WowItem UpdateRawWowItem(XMemory xMemory)
        {
            UpdateRawWowObject(xMemory);

            if (xMemory.ReadStruct(DescriptorAddress + RawWowObject.EndOffset, out RawWowItem rawWowItem))
            {
                RawWowItem = rawWowItem;
            }

            return(this);
        }
Exemple #13
0
        public WowUnit UpdateRawWowUnit(XMemory xMemory)
        {
            UpdateRawWowObject(xMemory);

            if (xMemory.ReadStruct(DescriptorAddress + RawWowObject.EndOffset, out RawWowUnit rawWowUnit))
            {
                RawWowUnit = rawWowUnit;
            }

            return(this);
        }
Exemple #14
0
 private void SaveWowWindowPosition()
 {
     try
     {
         Config.WowWindowRect = XMemory.GetWindowPosition(XMemory.Process.MainWindowHandle);
     }
     catch (Exception e)
     {
         AmeisenLogger.Instance.Log($"Failed to save wow window position:\n{e.ToString()}", LogLevel.Error);
     }
 }
Exemple #15
0
 private void SaveBotWindowPosition()
 {
     try
     {
         Config.BotWindowRect = XMemory.GetWindowPosition(Process.GetCurrentProcess().MainWindowHandle);
     }
     catch (Exception e)
     {
         AmeisenLogger.Instance.Log($"Failed to save bot window position:\n{e.ToString()}", LogLevel.Error);
     }
 }
Exemple #16
0
        public void EnsureSize(StringBuffer stringBuffer, ArrayPoolApi_I <char> bufferPool, int appendLength)
        {
            char[] newBuffer = XMemory.RentBuffer(bufferPool, (stringBuffer.Position + appendLength) * 2);

            if (stringBuffer.Buffer != null)
            {
                Array.Copy(stringBuffer.Buffer, newBuffer, stringBuffer.Position);
                XMemory.ReturnBuffer(bufferPool, stringBuffer.Buffer);
            }

            stringBuffer.Buffer = newBuffer;
        }
        protected override bool PrepareAsm()
        {
            byte[] luaJumpBytes = Encoding.ASCII.GetBytes("JumpOrAscendStart();AscendStop()");

            if (XMemory.AllocateMemory(4, out IntPtr executeAddress) &&
                XMemory.AllocateMemory(40, out IntPtr dataAddress) &&
                XMemory.AllocateMemory((uint)(luaJumpBytes.Length + 1), out IntPtr commandAddress))
            {
                WowInterface.XMemory.WriteBytes(commandAddress, luaJumpBytes);

                ExecuteAddress = executeAddress;
                CommandAddress = commandAddress;
                DataAddress    = dataAddress;

                IntPtr distancePointer = dataAddress;
                IntPtr startPointer    = IntPtr.Add(distancePointer, 0x4);
                IntPtr endPointer      = IntPtr.Add(startPointer, 0xC);
                IntPtr resultPointer   = IntPtr.Add(endPointer, 0xC);

                XMemory.Fasm.Clear();

                XMemory.Fasm.AppendLine("X:");
                XMemory.Fasm.AppendLine($"TEST DWORD [{executeAddress}], 1");
                XMemory.Fasm.AppendLine("JE @out");

                XMemory.Fasm.AppendLine("PUSH 0");
                XMemory.Fasm.AppendLine("PUSH 0x120171");
                XMemory.Fasm.AppendLine($"PUSH {distancePointer}");
                XMemory.Fasm.AppendLine($"PUSH {resultPointer}");
                XMemory.Fasm.AppendLine($"PUSH {endPointer}");
                XMemory.Fasm.AppendLine($"PUSH {startPointer}");
                XMemory.Fasm.AppendLine($"CALL {WowInterface.OffsetList.FunctionTraceline}");
                XMemory.Fasm.AppendLine("ADD ESP, 0x18");

                XMemory.Fasm.AppendLine("TEST AL, 1");
                XMemory.Fasm.AppendLine("JE @out");

                XMemory.Fasm.AppendLine("PUSH 0");
                XMemory.Fasm.AppendLine($"PUSH {commandAddress}");
                XMemory.Fasm.AppendLine($"PUSH {commandAddress}");
                XMemory.Fasm.AppendLine($"CALL {WowInterface.OffsetList.FunctionLuaDoString}");
                XMemory.Fasm.AppendLine("ADD ESP, 0xC");

                XMemory.Fasm.AppendLine($"MOV DWORD [{executeAddress}], 0");
                XMemory.Fasm.AppendLine("@out:");
                XMemory.Fasm.AppendLine("RET");

                return(true);
            }

            return(false);
        }
Exemple #18
0
        public CharacterManager(XMemory xMemory, AmeisenBotConfig config, IOffsetList offsetList, ObjectManager objectManager, HookManager hookManager)
        {
            XMemory       = xMemory;
            OffsetList    = offsetList;
            ObjectManager = objectManager;
            HookManager   = hookManager;
            Config        = config;

            KeyMap = new Dictionary <VirtualKeys, bool>();

            Inventory      = new CharacterInventory(hookManager);
            Equipment      = new CharacterEquipment(hookManager);
            SpellBook      = new SpellBook(hookManager);
            ItemComparator = new ItemLevelComparator();
            Skills         = new List <string>();
        }
Exemple #19
0
        public AmeisenBotOverlay(XMemory xMemory)
        {
            XMemory            = xMemory;
            LinesToRender      = new List <(SolidBrush, (Point, Point))>();
            RectanglesToRender = new List <(SolidBrush, (Point, Point))>();

            OverlayWindow = new StickyWindow(xMemory.Process.MainWindowHandle)
            {
                IsTopmost = true,
                IsVisible = true,
                FPS       = 30
            };

            OverlayWindow.Create();

            Gfx = new Graphics(OverlayWindow.Handle, OverlayWindow.Width, OverlayWindow.Height);
            Gfx.Setup();
        }
Exemple #20
0
        public HunterBeastmastery(ObjectManager objectManager, CharacterManager characterManager, HookManager hookManager, XMemory xMemory)
        {
            ObjectManager    = objectManager;
            CharacterManager = characterManager;
            HookManager      = hookManager;
            XMemory          = xMemory;
            CooldownManager  = new CooldownManager(characterManager.SpellBook.Spells);

            Spells = new Dictionary <string, Spell>();
            CharacterManager.SpellBook.OnSpellBookUpdate += () =>
            {
                Spells.Clear();
                foreach (Spell spell in CharacterManager.SpellBook.Spells)
                {
                    Spells.Add(spell.Name, spell);
                }
            };
        }
Exemple #21
0
        public AmeisenBotOverlay(XMemory xMemory)
        {
            XMemory            = xMemory;
            LinesToRender      = new();
            RectanglesToRender = new();

            OverlayWindow = new(xMemory.Process.MainWindowHandle)
            {
                IsTopmost = true,
                IsVisible = true,
                FPS       = 30
            };

            OverlayWindow.Create();

            Gfx = new(OverlayWindow.Handle, OverlayWindow.Width, OverlayWindow.Height);
            Gfx.Setup();
        }
Exemple #22
0
 private void LoadBotWindowPosition()
 {
     if (AccountName.Length > 0)
     {
         try
         {
             if (Config.BotWindowRect != new Rect()
             {
                 Left = -1, Top = -1, Right = -1, Bottom = -1
             })
             {
                 XMemory.SetWindowPosition(Process.GetCurrentProcess().MainWindowHandle, Config.BotWindowRect, false);
                 AmeisenLogger.Instance.Log("AmeisenBot", $"Loaded bot window position: {Config.BotWindowRect}", LogLevel.Verbose);
             }
         }
         catch (Exception e)
         {
             AmeisenLogger.Instance.Log("AmeisenBot", $"Failed to set bot window position:\n{e.ToString()}", LogLevel.Error);
         }
     }
 }
Exemple #23
0
 private void LoadWowWindowPosition()
 {
     if (AccountName.Length > 0)
     {
         try
         {
             if (Config.WowWindowRect != new Rect()
             {
                 Left = -1, Top = -1, Right = -1, Bottom = -1
             })
             {
                 XMemory.SetWindowPosition(XMemory.Process.MainWindowHandle, Config.WowWindowRect);
                 AmeisenLogger.Instance.Log($"Loaded wow window position: {Config.WowWindowRect}", LogLevel.Verbose);
             }
         }
         catch (Exception e)
         {
             AmeisenLogger.Instance.Log($"Failed to set wow window position:\n{e.ToString()}", LogLevel.Error);
         }
     }
 }
Exemple #24
0
        protected override bool PrepareAsm()
        {
            byte[] luaBytes    = Encoding.ASCII.GetBytes(Lua);
            byte[] luaVarBytes = Encoding.ASCII.GetBytes(VarName);

            if (XMemory.AllocateMemory(4, out IntPtr returnAddress) &&
                XMemory.AllocateMemory((uint)(luaBytes.Length + 1), out IntPtr commandAddress) &&
                XMemory.AllocateMemory((uint)(luaVarBytes.Length + 1), out IntPtr varAddress))
            {
                XMemory.WriteBytes(commandAddress, luaBytes);
                XMemory.WriteBytes(varAddress, luaVarBytes);

                ReturnAddress  = returnAddress;
                CommandAddress = commandAddress;
                VarAddress     = varAddress;

                XMemory.Fasm.Clear();

                XMemory.Fasm.AppendLine("X:");

                XMemory.Fasm.AppendLine("PUSH 0");
                XMemory.Fasm.AppendLine($"PUSH {commandAddress}");
                XMemory.Fasm.AppendLine($"PUSH {commandAddress}");
                XMemory.Fasm.AppendLine($"CALL {WowInterface.OffsetList.FunctionLuaDoString}");
                XMemory.Fasm.AppendLine("ADD ESP, 0xC");

                XMemory.Fasm.AppendLine($"CALL {WowInterface.OffsetList.FunctionGetActivePlayerObject}");
                XMemory.Fasm.AppendLine("MOV ECX, EAX");
                XMemory.Fasm.AppendLine("PUSH -1");
                XMemory.Fasm.AppendLine($"PUSH {varAddress}");
                XMemory.Fasm.AppendLine($"CALL {WowInterface.OffsetList.FunctionGetLocalizedText}");
                XMemory.Fasm.AppendLine($"MOV DWORD [{returnAddress}], EAX");

                XMemory.Fasm.AppendLine($"RET");

                return(true);
            }

            return(false);
        }
Exemple #25
0
        public override void Execute()
        {
            if (!StateMachine.ShouldExit && File.Exists(Config.PathToWowExe))
            {
                if (WowInterface.WowProcess == null || WowInterface.WowProcess.HasExited)
                {
                    AmeisenLogger.I.Log("StartWow", "Starting WoW Process");
                    WowInterface.WowProcess = XMemory.StartProcessNoActivate($"\"{Config.PathToWowExe}\" -windowed -d3d9");

                    AmeisenLogger.I.Log("StartWow", "Waiting for input idle");
                    WowInterface.WowProcess.WaitForInputIdle();
                }

                if (WowInterface.WowProcess != null && !WowInterface.WowProcess.HasExited)
                {
                    AmeisenLogger.I.Log("StartWow", $"Attaching XMemory to {WowInterface.WowProcess.ProcessName}:{WowInterface.WowProcess.Id}");

                    try
                    {
                        if (WowInterface.XMemory.Attach(WowInterface.WowProcess))
                        {
                            try
                            {
                                OnWoWStarted?.Invoke();
                            }
                            catch (Exception ex) { AmeisenLogger.I.Log("StartWow", $"Error at OnWoWStarted:\n{ex}"); }

                            AmeisenLogger.I.Log("StartWow", $"Switching to login state...");
                            StateMachine.SetState(BotState.Login);
                        }
                        else
                        {
                            AmeisenLogger.I.Log("StartWow", $"Attaching XMemory failed...");
                        }
                    }
                    catch (Exception e) { AmeisenLogger.I.Log("StartWow", $"Attaching XMemory failed:\n{e}"); }
                }
            }
        }
Exemple #26
0
 public StringBuffer StringBuffer(ArrayPoolApi_I <char> bufferPool, int initalSize)
 {
     return(StringBuffer(XMemory.RentBuffer(bufferPool, initalSize)));
 }
Exemple #27
0
        public void WriteEscapedJavaScriptString(TextWriter writer, string s, char delimiter, bool appendDelimiters,
                                                 bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, ArrayPoolApi_I <char> bufferPool, ref char[] writeBuffer)
        {
            // leading delimiter
            if (appendDelimiters)
            {
                writer.Write(delimiter);
            }

            if (!string.IsNullOrEmpty(s))
            {
                int lastWritePosition = FirstCharToEscape(s, charEscapeFlags, stringEscapeHandling);
                if (lastWritePosition == -1)
                {
                    writer.Write(s);
                }
                else
                {
                    if (lastWritePosition != 0)
                    {
                        if (writeBuffer == null || writeBuffer.Length < lastWritePosition)
                        {
                            writeBuffer = XMemory.EnsureBufferSize(bufferPool, lastWritePosition, writeBuffer);
                        }

                        // write unchanged chars at start of text.
                        s.CopyTo(0, writeBuffer, 0, lastWritePosition);
                        writer.Write(writeBuffer, 0, lastWritePosition);
                    }

                    int length;
                    for (int i = lastWritePosition; i < s.Length; i++)
                    {
                        char c = s[i];

                        if (c < charEscapeFlags.Length && !charEscapeFlags[c])
                        {
                            continue;
                        }

                        string escapedValue;

                        switch (c)
                        {
                        case '\t':
                            escapedValue = @"\t";
                            break;

                        case '\n':
                            escapedValue = @"\n";
                            break;

                        case '\r':
                            escapedValue = @"\r";
                            break;

                        case '\f':
                            escapedValue = @"\f";
                            break;

                        case '\b':
                            escapedValue = @"\b";
                            break;

                        case '\\':
                            escapedValue = @"\\";
                            break;

                        case '\u0085':     // Next Line
                            escapedValue = @"\u0085";
                            break;

                        case '\u2028':     // Line Separator
                            escapedValue = @"\u2028";
                            break;

                        case '\u2029':     // Paragraph Separator
                            escapedValue = @"\u2029";
                            break;

                        default:
                            if (c < charEscapeFlags.Length || stringEscapeHandling == StringEscapeHandling.EscapeNonAscii)
                            {
                                if (c == '\'' && stringEscapeHandling != StringEscapeHandling.EscapeHtml)
                                {
                                    escapedValue = @"\'";
                                }
                                else if (c == '"' && stringEscapeHandling != StringEscapeHandling.EscapeHtml)
                                {
                                    escapedValue = @"\""";
                                }
                                else
                                {
                                    if (writeBuffer == null || writeBuffer.Length < UnicodeTextLength)
                                    {
                                        writeBuffer = XMemory.EnsureBufferSize(bufferPool, UnicodeTextLength, writeBuffer);
                                    }

                                    XStrings.ToCharAsUnicode(c, writeBuffer);

                                    // slightly hacky but it saves multiple conditions in if test
                                    escapedValue = EscapedUnicodeText;
                                }
                            }
                            else
                            {
                                escapedValue = null;
                            }
                            break;
                        }

                        if (escapedValue == null)
                        {
                            continue;
                        }

                        bool isEscapedUnicodeText = string.Equals(escapedValue, EscapedUnicodeText);

                        if (i > lastWritePosition)
                        {
                            length = i - lastWritePosition + ((isEscapedUnicodeText) ? UnicodeTextLength : 0);
                            int start = (isEscapedUnicodeText) ? UnicodeTextLength : 0;

                            if (writeBuffer == null || writeBuffer.Length < length)
                            {
                                char[] newBuffer = XMemory.RentBuffer(bufferPool, length);

                                // the unicode text is already in the buffer
                                // copy it over when creating new buffer
                                if (isEscapedUnicodeText)
                                {
                                    XDebug.Assert(writeBuffer != null, "Write buffer should never be null because it is set when the escaped unicode text is encountered.");

                                    Array.Copy(writeBuffer, newBuffer, UnicodeTextLength);
                                }

                                XMemory.ReturnBuffer(bufferPool, writeBuffer);

                                writeBuffer = newBuffer;
                            }

                            s.CopyTo(lastWritePosition, writeBuffer, start, length - start);

                            // write unchanged chars before writing escaped text
                            writer.Write(writeBuffer, start, length - start);
                        }

                        lastWritePosition = i + 1;
                        if (!isEscapedUnicodeText)
                        {
                            writer.Write(escapedValue);
                        }
                        else
                        {
                            writer.Write(writeBuffer, 0, UnicodeTextLength);
                        }
                    }

                    XDebug.Assert(lastWritePosition != 0);
                    length = s.Length - lastWritePosition;
                    if (length > 0)
                    {
                        if (writeBuffer == null || writeBuffer.Length < length)
                        {
                            writeBuffer = XMemory.EnsureBufferSize(bufferPool, length, writeBuffer);
                        }

                        s.CopyTo(lastWritePosition, writeBuffer, 0, length);

                        // write remaining text
                        writer.Write(writeBuffer, 0, length);
                    }
                }
            }

            // trailing delimiter
            if (appendDelimiters)
            {
                writer.Write(delimiter);
            }
        }
Exemple #28
0
        public AmeisenBot(string botDataPath, string accountName, AmeisenBotConfig config)
        {
            SetupLogging(botDataPath, accountName);
            AmeisenLogger.Instance.Log("AmeisenBot starting...", LogLevel.Master);

            string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

            AmeisenLogger.Instance.Log($"version: {version}", LogLevel.Master);

            Config = config;

            AccountName = accountName;
            AmeisenLogger.Instance.Log($"AccountName: {botDataPath}", LogLevel.Master);

            BotDataPath = botDataPath;
            AmeisenLogger.Instance.Log($"BotDataPath: {botDataPath}", LogLevel.Verbose);

            CurrentExecutionMs    = 0;
            CurrentExecutionCount = 0;
            stateMachineTimerBusy = 0;

            StateMachineTimer          = new Timer(config.StateMachineTickMs);
            StateMachineTimer.Elapsed += StateMachineTimerTick;

            OffsetList = new OffsetList335a();
            AmeisenLogger.Instance.Log($"Using OffsetList: {OffsetList.GetType().ToString()}", LogLevel.Master);

            XMemory            = new XMemory();
            BotCache           = new InMemoryBotCache(Path.Combine(BotDataPath, accountName, "cache.bin"));
            ObjectManager      = new ObjectManager(XMemory, OffsetList, BotCache);
            HookManager        = new HookManager(XMemory, OffsetList, ObjectManager, BotCache);
            CharacterManager   = new CharacterManager(XMemory, config, OffsetList, ObjectManager, HookManager);
            EventHookManager   = new EventHookManager(HookManager);
            PathfindingHandler = new NavmeshServerClient(Config.NavmeshServerIp, Config.NameshServerPort);
            MovementSettings   = new MovementSettings();
            MovemenEngine      = new SmartMovementEngine(
                () => ObjectManager.Player.Position,
                () => ObjectManager.Player.Rotation,
                CharacterManager.MoveToPosition,
                (Vector3 start, Vector3 end) => PathfindingHandler.GetPath(ObjectManager.MapId, start, end),
                CharacterManager.Jump,
                ObjectManager,
                MovementSettings);

            if (!Directory.Exists(BotDataPath))
            {
                Directory.CreateDirectory(BotDataPath);
                AmeisenLogger.Instance.Log($"Creating folder {botDataPath}", LogLevel.Verbose);
            }

            if (config.UseBuiltInCombatClass)
            {
                LoadDefaultCombatClass();
            }
            else
            {
                LoadCustomCombatClass();
            }

            if (CombatClass?.ItemComparator != null)
            {
                CharacterManager.ItemComparator = CombatClass.ItemComparator;
            }

            StateMachine = new AmeisenBotStateMachine(BotDataPath, WowProcess, Config, XMemory, OffsetList, ObjectManager, CharacterManager, HookManager, EventHookManager, BotCache, PathfindingHandler, MovemenEngine, CombatClass);
            StateMachine.OnStateMachineStateChanged += HandlePositionLoad;
        }
Exemple #29
0
        public void Execute()
        {
            // Override states
            // --------------->
            if (CurrentState.Key != BotState.None &&
                CurrentState.Key != BotState.StartWow)
            {
                // Handle Wow crash
                // ---------------- >
                if ((WowInterface.XMemory.Process == null || WowInterface.XMemory.Process.HasExited) &&
                    SetState(BotState.None))
                {
                    AmeisenLogger.I.Log("StateMachine", "WoW crashed", LogLevel.Verbose);

                    WowCrashed = true;
                    GetState <StateIdle>().FirstStart = true;

                    WowInterface.MovementEngine.Reset();
                    WowInterface.EventHookManager.Stop();

                    return;
                }

                AntiAfkEvent.Run();

                if (CurrentState.Key != BotState.Login &&
                    WowInterface.ObjectManager != null)
                {
                    if (!WowInterface.ObjectManager.RefreshIsWorldLoaded())
                    {
                        if (SetState(BotState.LoadingScreen, true))
                        {
                            OnStateOverride?.Invoke(CurrentState.Key);
                            AmeisenLogger.I.Log("StateMachine", "World is not loaded", LogLevel.Verbose);
                            return;
                        }
                    }
                    else
                    {
                        WowInterface.ObjectManager.UpdateWowObjects();
                        EventPullEvent.Run();

                        if (WowInterface.ObjectManager.Player != null)
                        {
                            if (!WowInterface.ObjectManager.Player.IsCasting)
                            {
                                WowInterface.MovementEngine.Execute();
                            }

                            if (WowInterface.ObjectManager.Player.IsDead)
                            {
                                // we are dead, state needs to release the spirit
                                if (SetState(BotState.Dead, true))
                                {
                                    OnStateOverride?.Invoke(CurrentState.Key);
                                    return;
                                }
                            }
                            else if (GhostCheckEvent.Run(out bool isGhost) &&
                                     isGhost &&
                                     SetState(BotState.Ghost, true))
                            {
                                OnStateOverride?.Invoke(CurrentState.Key);
                                return;
                            }

                            // we cant fight when we are dead or a ghost
                            if (CurrentState.Key != BotState.Dead &&
                                CurrentState.Key != BotState.Ghost &&
                                !WowInterface.Globals.IgnoreCombat &&
                                !(Config.IgnoreCombatWhileMounted && WowInterface.ObjectManager.Player.IsMounted) &&
                                (WowInterface.Globals.ForceCombat || WowInterface.ObjectManager.Player.IsInCombat || IsAnyPartymemberInCombat() ||
                                 WowInterface.ObjectManager.GetEnemiesInCombatWithUs <WowUnit>(WowInterface.ObjectManager.Player.Position, 100.0).Any()))
                            {
                                if (SetState(BotState.Attacking, true))
                                {
                                    OnStateOverride?.Invoke(CurrentState.Key);
                                    return;
                                }
                            }
                        }
                    }

                    // auto disable rendering when not in focus
                    if (Config.AutoDisableRender && RenderSwitchEvent.Run())
                    {
                        IntPtr foregroundWindow = XMemory.GetForegroundWindow();
                        WowInterface.HookManager.WowSetRenderState(foregroundWindow == WowInterface.XMemory.Process.MainWindowHandle);
                    }
                }
            }

            // execute the State and Movement
            CurrentState.Value.Execute();
            OnStateMachineTick?.Invoke();
        }
Exemple #30
0
 public StateStartWow(AmeisenBotStateMachine stateMachine, AmeisenBotConfig config, Process wowProcess, XMemory xMemory) : base(stateMachine)
 {
     Config     = config;
     WowProcess = wowProcess;
     XMemory    = xMemory;
 }