Example #1
0
        public void FastRandomStringOnlyLettersTest()
        {
            List <char> numbers = new() { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

            for (int i = 0; i < 16; ++i)
            {
                Assert.IsFalse(BotUtils.FastRandomStringOnlyLetters().Any(e => numbers.Contains(e)));
            }
        }
Example #2
0
        public WowInterface335a(IMemoryApi memoryApi)
        {
            Memory = memoryApi;

            OffsetList  = new();
            HookModules = new();

            // lua variable names for the event hook
            string handlerName     = BotUtils.FastRandomStringOnlyLetters();
            string tableName       = BotUtils.FastRandomStringOnlyLetters();
            string eventHookOutput = BotUtils.FastRandomStringOnlyLetters();

            // name of the frame used to capture wows events
            string eventHookFrameName = BotUtils.FastRandomStringOnlyLetters();

            EventManager = new(LuaDoString, eventHookFrameName);

            // module to process wows events.
            HookModules.Add(new RunLuaHookModule
                            (
                                (x) =>
            {
                if (x != IntPtr.Zero &&
                    memoryApi.ReadString(x, Encoding.UTF8, out string s) &&
                    !string.IsNullOrWhiteSpace(s))
                {
                    EventManager.OnEventPush(s);
                }
            },
                                null,
                                memoryApi,
                                Offsets,
                                $"{eventHookOutput}='['function {handlerName}(self,a,...)table.insert({tableName},{{time(),a,{{...}}}})end if {eventHookFrameName}==nil then {tableName}={{}}{eventHookFrameName}=CreateFrame(\"FRAME\"){eventHookFrameName}:SetScript(\"OnEvent\",{handlerName})else for b,c in pairs({tableName})do {eventHookOutput}={eventHookOutput}..'{{'for d,e in pairs(c)do if type(e)==\"table\"then {eventHookOutput}={eventHookOutput}..'\"args\": ['for f,g in pairs(e)do {eventHookOutput}={eventHookOutput}..'\"'..g..'\"'if f<=table.getn(e)then {eventHookOutput}={eventHookOutput}..','end end {eventHookOutput}={eventHookOutput}..']}}'if b<table.getn({tableName})then {eventHookOutput}={eventHookOutput}..','end else if type(e)==\"string\"then {eventHookOutput}={eventHookOutput}..'\"event\": \"'..e..'\",'else {eventHookOutput}={eventHookOutput}..'\"time\": \"'..e..'\",'end end end end end {eventHookOutput}={eventHookOutput}..']'{tableName}={{}}",
                                eventHookOutput
                            ));

            string staticPopupsVarName = BotUtils.FastRandomStringOnlyLetters();
            string oldPoupString       = string.Empty;

            // module that monitors the STATIC_POPUP windows.
            HookModules.Add(new RunLuaHookModule
                            (
                                (x) =>
            {
                if (x != IntPtr.Zero &&
                    memoryApi.ReadString(x, Encoding.UTF8, out string s) &&
                    !string.IsNullOrWhiteSpace(s))
                {
                    if (!oldPoupString.Equals(s, StringComparison.Ordinal))
                    {
                        OnStaticPopup?.Invoke(s);
                        oldPoupString = s;
                    }
                }
                else
                {
                    oldPoupString = string.Empty;
                }
            },
                                null,
                                memoryApi,
                                Offsets,
                                $"{staticPopupsVarName}=\"\"for b=1,STATICPOPUP_NUMDIALOGS do local c=_G[\"StaticPopup\"..b]if c:IsShown()then {staticPopupsVarName}={staticPopupsVarName}..b..\":\"..c.which..\"; \"end end",
                                staticPopupsVarName
                            ));

            string battlegroundStatusVarName = BotUtils.FastRandomStringOnlyLetters();
            string oldBattlegroundStatus     = string.Empty;

            // module to monitor the battleground (and queue) status.
            HookModules.Add(new RunLuaHookModule
                            (
                                (x) =>
            {
                if (x != IntPtr.Zero &&
                    memoryApi.ReadString(x, Encoding.UTF8, out string s) &&
                    !string.IsNullOrWhiteSpace(s))
                {
                    if (!oldBattlegroundStatus.Equals(s, StringComparison.Ordinal))
                    {
                        OnBattlegroundStatus?.Invoke(s);
                        oldBattlegroundStatus = s;
                    }
                }
                else
                {
                    oldBattlegroundStatus = string.Empty;
                }
            },
                                null,
                                memoryApi,
                                Offsets,
                                $"{battlegroundStatusVarName}=\"\"for b=1,MAX_BATTLEFIELD_QUEUES do local c,d,e,f,g,h=GetBattlefieldStatus(b)local i=GetBattlefieldTimeWaited(b)/1000;{battlegroundStatusVarName}={battlegroundStatusVarName}..b..\":\"..tostring(c or\"unknown\")..\":\"..tostring(d or\"unknown\")..\":\"..tostring(e or\"unknown\")..\":\"..tostring(f or\"unknown\")..\":\"..tostring(g or\"unknown\")..\":\"..tostring(h or\"unknown\")..\":\"..tostring(i or\"unknown\")..\";\"end",
                                battlegroundStatusVarName
                            ));

            // module to detect small obstacles that we can jump over
            HookModules.Add(new TracelineJumpHookModule
                            (
                                null,
                                (x) =>
            {
                IntPtr dataPtr = x.GetDataPointer();

                if (dataPtr != IntPtr.Zero && Player != null)
                {
                    Vector3 playerPosition = Player.Position;
                    playerPosition.Z      += 1.3f;

                    Vector3 pos = BotUtils.MoveAhead(playerPosition, Player.Rotation, 0.25f);
                    memoryApi.Write(dataPtr, (1.0f, playerPosition, pos));
                }
            },
                                memoryApi,
                                Offsets
                            ));

            ObjectManager = new(memoryApi, Offsets);

            Hook = new(memoryApi, Offsets, ObjectManager);
            Hook.OnGameInfoPush += ObjectManager.HookManagerOnGameInfoPush;
        }
Example #3
0
        public WowInterface548(WowMemoryApi memory)
        {
            Memory      = memory;
            HookModules = new();

            // lua variable names for the event hook
            string handlerName     = BotUtils.FastRandomStringOnlyLetters();
            string tableName       = BotUtils.FastRandomStringOnlyLetters();
            string eventHookOutput = BotUtils.FastRandomStringOnlyLetters();

            // name of the frame used to capture wows events
            string eventHookFrameName = BotUtils.FastRandomStringOnlyLetters();

            EventManager = new(LuaDoString, eventHookFrameName);

            // module to process wows events.
            HookModules.Add(new RunLuaHookModule
                            (
                                (x) =>
            {
                if (x != IntPtr.Zero &&
                    memory.ReadString(x, Encoding.UTF8, out string s) &&
                    !string.IsNullOrWhiteSpace(s))
                {
                    EventManager.OnEventPush(s);
                }
            },
                                null,
                                memory,
                                LuaEventHook.Get(eventHookFrameName, tableName, handlerName, eventHookOutput),
                                eventHookOutput
                            ));

            string staticPopupsVarName = BotUtils.FastRandomStringOnlyLetters();
            string oldPoupString       = string.Empty;

            // module that monitors the STATIC_POPUP windows.
            HookModules.Add(new RunLuaHookModule
                            (
                                (x) =>
            {
                if (x != IntPtr.Zero &&
                    memory.ReadString(x, Encoding.UTF8, out string s) &&
                    !string.IsNullOrWhiteSpace(s))
                {
                    if (!oldPoupString.Equals(s, StringComparison.Ordinal))
                    {
                        OnStaticPopup?.Invoke(s);
                        oldPoupString = s;
                    }
                }
                else
                {
                    oldPoupString = string.Empty;
                }
            },
                                null,
                                memory,
                                $"{staticPopupsVarName}=\"\"for b=1,STATICPOPUP_NUMDIALOGS do local c=_G[\"StaticPopup\"..b]if c:IsShown()then {staticPopupsVarName}={staticPopupsVarName}..b..\":\"..c.which..\"; \"end end",
                                staticPopupsVarName
                            ));

            string battlegroundStatusVarName = BotUtils.FastRandomStringOnlyLetters();
            string oldBattlegroundStatus     = string.Empty;

            // module to monitor the battleground (and queue) status.
            HookModules.Add(new RunLuaHookModule
                            (
                                (x) =>
            {
                if (x != IntPtr.Zero &&
                    memory.ReadString(x, Encoding.UTF8, out string s) &&
                    !string.IsNullOrWhiteSpace(s))
                {
                    if (!oldBattlegroundStatus.Equals(s, StringComparison.Ordinal))
                    {
                        OnBattlegroundStatus?.Invoke(s);
                        oldBattlegroundStatus = s;
                    }
                }
                else
                {
                    oldBattlegroundStatus = string.Empty;
                }
            },
                                null,
                                memory,
                                $"{battlegroundStatusVarName}=\"\"for b=1,2 do local c,d,e,f,g,h=GetBattlefieldStatus(b)local i=GetBattlefieldTimeWaited(b)/1000;{battlegroundStatusVarName}={battlegroundStatusVarName}..b..\":\"..tostring(c or\"unknown\")..\":\"..tostring(d or\"unknown\")..\":\"..tostring(e or\"unknown\")..\":\"..tostring(f or\"unknown\")..\":\"..tostring(g or\"unknown\")..\":\"..tostring(h or\"unknown\")..\":\"..tostring(i or\"unknown\")..\";\"end",
                                battlegroundStatusVarName
                            ));

            // module to detect small obstacles that we can jump over
            HookModules.Add(new TracelineJumpHookModule
                            (
                                null,
                                (x) =>
            {
                IntPtr dataPtr = x.GetDataPointer();

                if (dataPtr != IntPtr.Zero && Player != null)
                {
                    Vector3 playerPosition = Player.Position;
                    playerPosition.Z      += 1.3f;

                    Vector3 pos = BotUtils.MoveAhead(playerPosition, Player.Rotation, 0.25f);
                    memory.Write(dataPtr, (1.0f, playerPosition, pos));
                }
            },
                                memory
                            ));

            ObjectManager = new(memory);

            Hook = new(memory);
            Hook.OnGameInfoPush += ObjectManager.HookManagerOnGameInfoPush;
        }
Example #4
0
        public StateLogin(AmeisenBotFsm stateMachine, AmeisenBotConfig config, WowInterface wowInterface) : base(stateMachine, config, wowInterface)
        {
            LoginAttemptEvent = new(TimeSpan.FromMilliseconds(500));

            TracelineJumpHookModule jumpModule = new(null, null, wowInterface);

            jumpModule.Tick = () =>
            {
                // update Traceline Jump Check data
                if (Config.MovementSettings.EnableTracelineJumpCheck && wowInterface.Player != null)
                {
                    Vector3 playerPosition = wowInterface.Player.Position;
                    playerPosition.Z += wowInterface.MovementSettings.ObstacleCheckHeight;

                    Vector3 pos = BotUtils.MoveAhead(playerPosition, wowInterface.Player.Rotation, wowInterface.MovementSettings.ObstacleCheckDistance);

                    wowInterface.XMemory.Write(jumpModule.DataAddress, (1.0f, playerPosition, pos));
                }
            };

            string staticPopupsVarName       = BotUtils.FastRandomStringOnlyLetters();
            string battlegroundStatusVarName = BotUtils.FastRandomStringOnlyLetters();
            string handlerName        = BotUtils.FastRandomStringOnlyLetters();
            string tableName          = BotUtils.FastRandomStringOnlyLetters();
            string eventHookOutput    = BotUtils.FastRandomStringOnlyLetters();
            string eventHookFrameName = BotUtils.FastRandomStringOnlyLetters();

            wowInterface.EventHookManager.EventHookFrameName = eventHookFrameName;

            string oldPoupString         = string.Empty;
            string oldBattlegroundStatus = string.Empty;

            HookModules = new()
            {
                // Module to process wows events.
                new RunLuaHookModule((x) =>
                {
                    if (wowInterface.XMemory.ReadString(x, Encoding.UTF8, out string s, 8192))
                    {
                        wowInterface.EventHookManager?.OnEventPush(s);
                    }
                }, null, wowInterface, $"{eventHookOutput}='['function {handlerName}(self,a,...)table.insert({tableName},{{time(),a,{{...}}}})end if {eventHookFrameName}==nil then {tableName}={{}}{eventHookFrameName}=CreateFrame(\"FRAME\"){eventHookFrameName}:SetScript(\"OnEvent\",{handlerName})else for b,c in pairs({tableName})do {eventHookOutput}={eventHookOutput}..'{{'for d,e in pairs(c)do if type(e)==\"table\"then {eventHookOutput}={eventHookOutput}..'\"args\": ['for f,g in pairs(e)do {eventHookOutput}={eventHookOutput}..'\"'..g..'\"'if f<=table.getn(e)then {eventHookOutput}={eventHookOutput}..','end end {eventHookOutput}={eventHookOutput}..']}}'if b<table.getn({tableName})then {eventHookOutput}={eventHookOutput}..','end else if type(e)==\"string\"then {eventHookOutput}={eventHookOutput}..'\"event\": \"'..e..'\",'else {eventHookOutput}={eventHookOutput}..'\"time\": \"'..e..'\",'end end end end end {eventHookOutput}={eventHookOutput}..']'{tableName}={{}}", eventHookOutput),

                // Module that does a traceline in front of the character
                // to detect small obstacles that can be jumped over.
                jumpModule,

                // Modules that monitors the STATIC_POPUP windows.
                new RunLuaHookModule((x) =>
                {
                    if (wowInterface.XMemory.ReadString(x, Encoding.UTF8, out string s, 128))
                    {
                        if (!string.IsNullOrWhiteSpace(s))
                        {
                            if (!oldPoupString.Equals(s))
                            {
                                AmeisenLogger.I.Log("StaticPopups", s);
                                oldPoupString = s;
                            }
                        }
                        else
                        {
                            oldPoupString = string.Empty;
                        }
                    }
                }, null, wowInterface, $"{staticPopupsVarName}=\"\"for b=1,STATICPOPUP_NUMDIALOGS do local c=_G[\"StaticPopup\"..b]if c:IsShown()then {staticPopupsVarName}={staticPopupsVarName}..b..\":\"..c.which..\"; \"end end", staticPopupsVarName),

                // Module to monitor the battleground (and queue) status.
                new RunLuaHookModule((x) =>
                {
                    if (wowInterface.XMemory.ReadString(x, Encoding.UTF8, out string s, 128))
                    {
                        if (!string.IsNullOrWhiteSpace(s))
                        {
                            if (!oldBattlegroundStatus.Equals(s))
                            {
                                AmeisenLogger.I.Log("BgStatus", s);
                                oldBattlegroundStatus = s;
                            }
                        }
                        else
                        {
                            oldPoupString = string.Empty;
                        }
                    }
                }, null, wowInterface, $"{battlegroundStatusVarName}=\"\"for b=1,MAX_BATTLEFIELD_QUEUES do local c,d,e,f,g,h=GetBattlefieldStatus(b)local i=GetBattlefieldTimeWaited(b)/1000;{battlegroundStatusVarName}={battlegroundStatusVarName}..b..\":\"..tostring(c or\"unknown\")..\":\"..tostring(d or\"unknown\")..\":\"..tostring(e or\"unknown\")..\":\"..tostring(f or\"unknown\")..\":\"..tostring(g or\"unknown\")..\":\"..tostring(h or\"unknown\")..\":\"..tostring(i or\"unknown\")..\";\"end", battlegroundStatusVarName),
            };
        }