LUA function sorcery menu

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    uncledolan's Avatar Member
    Reputation
    16
    Join Date
    Apr 2012
    Posts
    98
    Thanks G/R
    3/6
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    LUA function sorcery

    I apologize in advance if this is a retarded question, I'm a scrub that's trying to learn and I haven't slept much in the past few days as I've been obsessively working on this. In short, I'm playing with a few things and at the moment I'm able to successfully register new LUA functions and call them from in game. Cool. My next goal was to pass the entity/object list to the game the same way Firehack does, which is where I've been stuck for the last 2 days.

    I can pass the entity addresses to the LUA stack and retrieve them in game, but I'm losing my shit completely trying to understand how can I pass these addresses as parameters to other functions (UnitName, UnitCanAttack etc.) the way Firehack does. Can't comprehend what type of wizardry is allowing this to take place.

    LUA function sorcery
  2. #2
    bigtimt's Avatar Active Member
    Reputation
    41
    Join Date
    Mar 2008
    Posts
    100
    Thanks G/R
    2/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will either have to detour the get unit by token function and parse object pointers or pass unit ids to lua instead of pointers

  3. #3
    uncledolan's Avatar Member
    Reputation
    16
    Join Date
    Apr 2012
    Posts
    98
    Thanks G/R
    3/6
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    What do you mean by unit IDs? I attempted entity IDs at entity+0x24 but that didn't seem to work.

  4. #4
    bigtimt's Avatar Active Member
    Reputation
    41
    Join Date
    Mar 2008
    Posts
    100
    Thanks G/R
    2/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See this page for what I meant by unit id UnitId | WoWWiki | Fandom powered by Wikia.

    You would have to figure out which unit id your object is, and not every object has an applicable unitid. If you were going to do it this way you might as well just use lua by itself. The best way to go about what you are trying to do is to hook GetGUIDFromToken.

  5. #5
    uncledolan's Avatar Member
    Reputation
    16
    Join Date
    Apr 2012
    Posts
    98
    Thanks G/R
    3/6
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Much appreciated, I haven't quite gotten it working yet but I'm on the right track now.

  6. #6
    l0l1dk's Avatar Elite User

    Reputation
    499
    Join Date
    Sep 2010
    Posts
    342
    Thanks G/R
    1/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm doing it in FH by hooking Script_GetGUIDFromToken, which is the function that resolves unit IDs into GUIDs, and making it so if a pointer is passed as a unit ID it'll be translated into the GUID.

  7. #7
    uncledolan's Avatar Member
    Reputation
    16
    Join Date
    Apr 2012
    Posts
    98
    Thanks G/R
    3/6
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Makes perfect sense now. I was slamming my head against a wall last night trying to understand why it wasn't working. Thanks guys

    Update:

    So working on this further, I've found the function and am attempting to hook it. I'm using DarthTon's Blackbone library but my game keeps crashing...

    struct WoWGUID
    {
    uint8_t Data[16];
    };

    bool __fastcall myHookFunc(const char*& token, WoWGUID& guid, bool& b1, bool& b2)
    {
    MessageBoxA(NULL, token, "", MB_OK);
    return true;
    }

    -------------------------------------------------------------------------------------

    typedef bool(__fastcall *token2guid)(const char*, WoWGUID, bool, bool);
    DWORD_PTR funcAddr = (wowBaseAddr + 0x650360);
    token2guid TokenGUIDFunc = (token2guid)funcAddr;

    blackbone:etour<token2guid> det;

    det.Hook(TokenGUIDFunc, &myHookFunc, blackbone::HookType::HWBP,blackbone::CallOrder::HookFirst, blackbone::ReturnMethod::UseOriginal);
    First message box immediately after injection containing token "player", followed by a crash with an access violation error. Not quite sure what's throwing that. Would someone enlighten a polite scrub? :confused: I also attempted an inline hook just to see if it would work, but it doesn't seem to be writing anything to memory.
    LUA function sorcery-oypxaek-png
    Last edited by uncledolan; 11-22-2016 at 06:27 AM.

  8. #8
    uncledolan's Avatar Member
    Reputation
    16
    Join Date
    Apr 2012
    Posts
    98
    Thanks G/R
    3/6
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'm a retard, I wasn't checking if token was null.

    Edit: Can't seem to make hook function work properly. Added a messagebox to see if token was passing properly and it throws another access violation. I'm returning false every time to not throw the previous error.

    bool __fastcall myHookFunc(const char*& token, WoWGUID& guid, bool& b1, bool& b2)
    {
    if (token)
    {
    MessageBoxA(NULL, token, "", MB_OK);
    return false;
    }
    else
    {
    return false;
    }
    }

    LUA function sorcery-wtf-png

    Edit 2: Unless I set CallOrder::NoOriginal I also still get the 0x000000000000 access violation. Ready to jump out of the window.
    Last edited by uncledolan; 11-22-2016 at 10:00 AM.

  9. Thanks Jadd (1 members gave Thanks to uncledolan for this useful post)
  10. #9
    Wildbreath's Avatar Contributor
    Reputation
    162
    Join Date
    Feb 2012
    Posts
    121
    Thanks G/R
    2/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by l0l1dk View Post
    I'm doing it in FH by hooking Script_GetGUIDFromToken, which is the function that resolves unit IDs into GUIDs, and making it so if a pointer is passed as a unit ID it'll be translated into the GUID.
    but when i passed guidptr to ClntObjMgrObjectPtr it always return 0 :\
    guids still "two ulongs" struct?
    Code:
            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            private delegate IntPtr ClntObjMgrObjectPtrDelegate(IntPtr guid, int unk);
            private static ClntObjMgrObjectPtrDelegate ClntObjMgrObjectPtrHandler;
    
    
            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            internal delegate bool GetGuidByKeywordDelegate(IntPtr token, int unk0, IntPtr guid, int unk1, int unk2);
            private static GetGuidByKeywordDelegate GetGuidByKeywordHandler;
            private static GetGuidByKeywordDelegate _GetGuidByKeyword;
    
            GetGuidByKeywordHandler = Memory.Instance.RegisterDelegate<GetGuidByKeywordDelegate>(Main.Offsets["GetGuidByKeyword"]);
            Memory.Instance.Detours.CreateAndApply(GetGuidByKeywordHandler, _GetGuidByKeyword = GetGuidByKeywordDetour, "GetGuidByKeywordDetour");
    
            private static bool GetGuidByKeywordDetour(IntPtr token, int unk0, IntPtr guidptr, int unk1, int unk2)
            {
                string tokenstr = Marshal.PtrToStringAnsi(token);
    
    
                if (tokenstr != null && tokenstr != string.Empty && tokenstr.All(Char.IsDigit))
                {
                    if (!ObjectManager.IsInGame) return false;
                    Int32 ptr = 0;
                    Int32.TryParse(tokenstr, out ptr);
                    if (ptr > 0)
                    {
                        WoWGUID retguid = new WoWGUID(new IntPtr(ptr));
                        if (retguid == WoWGUID.Invalid) return false;
                        Marshal.StructureToPtr(retguid, guidptr, true);
                        return true;
                    }
                    return false;
                }
                return (bool)Memory.Instance.Detours["GetGuidByKeywordDetour"].CallOriginal(token, unk0, guidptr, unk1, unk2);
            }
    
            public static IntPtr GetUnitPtrByKeyword(string token)
            {
                IntPtr ret = IntPtr.Zero;
                WoWGUID guid = new WoWGUID();
                IntPtr guidptr = Marshal.AllocHGlobal(Marshal.SizeOf(guid));
                IntPtr strptr = Marshal.StringToHGlobalAnsi(token);
                _GetGuidByKeyword(strptr, 0, guidptr, 0, 0);
                ret = ClntObjMgrObjectPtrHandler(guidptr, -1); // always 0 for "digit" token string
                Marshal.FreeHGlobal(guidptr);
    
    
                return ret;
            }
    Last edited by Wildbreath; 11-23-2016 at 09:43 AM.

  11. #10
    aeo's Avatar Contributor
    Reputation
    135
    Join Date
    Apr 2007
    Posts
    286
    Thanks G/R
    97/68
    Trade Feedback
    7 (100%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The game also has 2 functions GUIDtoString and GUIDFromString. When i did this I Used those functions to pass the object reference back and forth to my new functions as well as hooking the GetGUIDFromToken function

    Code:
    boolhookGetGUIDFromToken(constchar*&a1,WOWGUID&a2,bool&a3,bool&a4){
    
        if (a1)
        {
            WOWGUID orig =  WOWGUID();
            int result = orig.fromString((char*)a1);
            if (result != 0)
            {
                    a2 = orig;
                    return true;
            }
        }
        return false; }

    to convert GUID or player,party,ect strings in my new functions i used this :

    Code:
    CGObject_C*GetUnitFromString(constchar*identifier){
        CGObject_C* unit = (CGObject_C*)GetUnitFromName(identifier);
        if (!unit)
        {
            WOWGUID orig =  WOWGUID();
            int result = orig.fromString((char*)identifier);
            if (result != 0)
            {    
                unit = ObjectMgr::GetObjectPtr(orig,TypeMask::TYPEMASK_OBJECT);
            }
    
        }
        return unit; }
    Hope it helps, Its old code not pretty by worked.

    Edit: Blackbone help:
    Code:
    detGetGUIDByKeyword.Hook(oGetGUIDByKeyword, &hookGetGUIDFromToken, HookType::HWBP, CallOrder::HookLast, ReturnMethod::UseOriginal)
    Last edited by aeo; 11-23-2016 at 01:58 PM.

  12. Thanks Wildbreath, lolp1 (2 members gave Thanks to aeo for this useful post)
  13. #11
    l0l1dk's Avatar Elite User

    Reputation
    499
    Join Date
    Sep 2010
    Posts
    342
    Thanks G/R
    1/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Wildbreath View Post
    but when i passed guidptr to ClntObjMgrObjectPtr it always return 0 :\
    guids still "two ulongs" struct?
    Code:
            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            private delegate IntPtr ClntObjMgrObjectPtrDelegate(IntPtr guid, int unk);
            private static ClntObjMgrObjectPtrDelegate ClntObjMgrObjectPtrHandler;
    
    
            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            internal delegate bool GetGuidByKeywordDelegate(IntPtr token, int unk0, IntPtr guid, int unk1, int unk2);
            private static GetGuidByKeywordDelegate GetGuidByKeywordHandler;
            private static GetGuidByKeywordDelegate _GetGuidByKeyword;
    
            GetGuidByKeywordHandler = Memory.Instance.RegisterDelegate<GetGuidByKeywordDelegate>(Main.Offsets["GetGuidByKeyword"]);
            Memory.Instance.Detours.CreateAndApply(GetGuidByKeywordHandler, _GetGuidByKeyword = GetGuidByKeywordDetour, "GetGuidByKeywordDetour");
    
            private static bool GetGuidByKeywordDetour(IntPtr token, int unk0, IntPtr guidptr, int unk1, int unk2)
            {
                string tokenstr = Marshal.PtrToStringAnsi(token);
    
    
                if (tokenstr != null && tokenstr != string.Empty && tokenstr.All(Char.IsDigit))
                {
                    if (!ObjectManager.IsInGame) return false;
                    Int32 ptr = 0;
                    Int32.TryParse(tokenstr, out ptr);
                    if (ptr > 0)
                    {
                        WoWGUID retguid = new WoWGUID(new IntPtr(ptr));
                        if (retguid == WoWGUID.Invalid) return false;
                        Marshal.StructureToPtr(retguid, guidptr, true);
                        return true;
                    }
                    return false;
                }
                return (bool)Memory.Instance.Detours["GetGuidByKeywordDetour"].CallOriginal(token, unk0, guidptr, unk1, unk2);
            }
    
            public static IntPtr GetUnitPtrByKeyword(string token)
            {
                IntPtr ret = IntPtr.Zero;
                WoWGUID guid = new WoWGUID();
                IntPtr guidptr = Marshal.AllocHGlobal(Marshal.SizeOf(guid));
                IntPtr strptr = Marshal.StringToHGlobalAnsi(token);
                _GetGuidByKeyword(strptr, 0, guidptr, 0, 0);
                ret = ClntObjMgrObjectPtrHandler(guidptr, -1); // always 0 for "digit" token string
                Marshal.FreeHGlobal(guidptr);
    
    
                return ret;
            }
    I've got ClntObjMgrObjectPtr as:
    Code:
    void* (* ClntObjMgrObjectPtr)(SmartGUID GUID, uint32_t TypeFlags);
    and SmartGUID as:
    Code:
    struct SmartGUID
    {
    	uint64_t Low;
    	uint64_t High;
    };
    Here's a slightly simplified version of my Script_GetGUIDFromToken detour if it helps:
    Code:
    bool Script_GetGUIDFromToken_Detour (const char* Token, bool Unknown1, SmartGUID& GUID, bool Unknown2, bool Unknown3) noexcept
    {
    	constexpr auto PointerLength = sizeof("0x") - 1 + sizeof(void*) * 2;
    	if (Token && strlen(Token) == PointerLength && Token[0] == '0' && Token[1] == 'x')
    	{
    		auto Pointer = reinterpret_cast<void*>(
    #ifdef _WIN64
    			stoull
    #else
    			stoul
    #endif
    			(Token, nullptr, 0)
    		);
    
    		auto Object = GetObjectWithPointer(Pointer);
    		if (Object)
    		{
    			GUID = Object->GetGUID();
    		}
    
    		return Object != nullptr;
    	}
    
    	return Original(Token, Unknown1, GUID, Unknown2, Unknown3);
    }

  14. Thanks Wildbreath (1 members gave Thanks to l0l1dk for this useful post)
  15. #12
    uncledolan's Avatar Member
    Reputation
    16
    Join Date
    Apr 2012
    Posts
    98
    Thanks G/R
    3/6
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Going to dive back into this once I'm home, you guys are amazing. Immensely appreciate the help.

  16. #13
    Wildbreath's Avatar Contributor
    Reputation
    162
    Join Date
    Feb 2012
    Posts
    121
    Thanks G/R
    2/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don't know what i'm doing wrong, but ClntObjMgrObjectPtr always return 0, even though the correct GUID (or pointer to GUID) pass
    tried to use callback of EnumVisibleObjects and use return value to pass as object pointer (i think pointer to GUID is game unit pointer, correct me if wrong) - but fail, functions alarmed about the write to protected memory -_-

  17. #14
    l0l1dk's Avatar Elite User

    Reputation
    499
    Join Date
    Sep 2010
    Posts
    342
    Thanks G/R
    1/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Wildbreath View Post
    don't know what i'm doing wrong, but ClntObjMgrObjectPtr always return 0, even though the correct GUID (or pointer to GUID) pass
    tried to use callback of EnumVisibleObjects and use return value to pass as object pointer (i think pointer to GUID is game unit pointer, correct me if wrong) - but fail, functions alarmed about the write to protected memory -_-
    Is the Script_GetGUIDFromToken detour giving the correct GUIDs?

  18. #15
    Wildbreath's Avatar Contributor
    Reputation
    162
    Join Date
    Feb 2012
    Posts
    121
    Thanks G/R
    2/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes... and it works for player, target and etc. but for "pointed" units fail

Page 1 of 2 12 LastLast

Similar Threads

  1. Big List of Lua Functions
    By Lytle69 in forum WoW EMU Guides & Tutorials
    Replies: 0
    Last Post: 10-15-2008, 03:02 AM
  2. LUA Function Thread
    By steveo123 in forum WoW EMU Questions & Requests
    Replies: 3
    Last Post: 10-13-2008, 08:54 AM
  3. [Guide] How to use local LUA function!
    By Dartignan in forum WoW EMU Guides & Tutorials
    Replies: 0
    Last Post: 08-05-2008, 09:28 PM
  4. Replies: 22
    Last Post: 05-29-2008, 03:52 PM
  5. [Question] Lua functions
    By Lich King in forum World of Warcraft Emulator Servers
    Replies: 5
    Last Post: 04-10-2008, 07:39 PM
All times are GMT -5. The time now is 11:51 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search