Calling LUA Functions menu

User Tag List

Results 1 to 8 of 8
  1. #1
    cloud_wizard's Avatar Member
    Reputation
    5
    Join Date
    Dec 2008
    Posts
    44
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calling LUA Functions

    So this is what I've got so far... And I'm not even sure it will work. I haven't tried it yet. I'm afraid to, lol. Some of this is borrowed from starfish99's contribution: http://www.mmowned.com/forums/wow-me...et-result.html

    Code:
    string GetUnitGUID(string UnitID)
    {
    	HANDLE Handle = OpenProcess(PROCESS_ALL_ACCESS,FALSE,HBAI.Instance[HBAI.CurrentWoWInstance].PID);
    
    	string localGUID;
    
    	//UnitGUID LUA Function address
    	DWORD UnitGUID = 0x00565370;
    	//lua state address
    	DWORD LUAStateAddress = 0x012E87EC;
    
    	//get arguments from lua stack
    	DWORD LUAGetString = 0x007AD920;
    	DWORD LUAGetNumber = 0x007AD870;
    
    	//push results to lua stack
    	DWORD LUAPushString = 0x007ADB90;
    	DWORD LUAPushNumber = 0x007ADAE0;
    	DWORD LUAPushNil = 0x007ADAC0;
    
    	//this address shows which addon is call lua function, the value is addon's name(string)
    	DWORD CallingAddon = 0x012EA330;
           //Make WoW Think the blizz UI is calling this one
    	MemoryWriteInt(Handle,CallingAddon,0);
           //Call the LUA Function UnitGUID
    	MemoryWriteDWORD(Handle,LUAStateAddress,UnitGUID);
           //Add the UnitID to the parameters
    	MemoryWriteString(Handle,LUAPushString,UnitID);
           //Get the results!
    	localGUID = MemoryReadString(Handle,LUAGetString);
    
    	CloseHandle(Handle);	
           return localGUID;
    }
    Code:
    void MemoryWriteInt(HANDLE Handle, DWORD WriteAddress, int ValueToWrite)
    {
    	SIZE_T BytesToWrite = sizeof ValueToWrite;
    	SIZE_T BytesWritten;
    	WriteProcessMemory(Handle,(LPVOID)WriteAddress,ValueToWrite,BytesToWrite,&BytesWritten);
    }
    
    void MemoryWriteDWORD(HANDLE Handle, DWORD WriteAddress, DWORD ValueToWrite)
    {
    	SIZE_T BytesToWrite = sizeof ValueToWrite;
    	SIZE_T BytesWritten;
    	WriteProcessMemory(Handle,(LPVOID)WriteAddress,ValueToWrite,BytesToWrite,&BytesWritten);
    }
    string MemoryReadString(HANDLE Handle, DWORD ReadAddress)
    {
    	SIZE_T BytesRead;
    	int BytesToRead = sizeof(ReadAddress);
    	string ContentsOfAddress;
    	ReadProcessMemory(Handle,(LPCVOID)ReadAddress,&ContentsOfAddress,BytesToRead,&BytesRead);
    	return ContentsOfAddress;
    }
    
    void MemoryWriteString(HANDLE Handle, DWORD WriteAddress, string ValueToWrite)
    {
    	SIZE_T BytesToWrite = sizeof ValueToWrite;
    	SIZE_T BytesWritten;
    	WriteProcessMemory(Handle,(LPVOID)WriteAddress,ValueToWrite,BytesToWrite,&BytesWritten);
    }
    The concept: A unit ID (such as "player") goes in, and that unit's GUID comes out.

    Can it be done this way? Or do I have to use ASM? I couldn't figure out how to translate starfish99's code to C++ or else I'd have done it exactly as shown.

    Also, if ASM is the only way to do this... *sigh* ... How?

    Calling LUA Functions
  2. #2
    KRYPTON88's Avatar Banned
    Reputation
    97
    Join Date
    Oct 2008
    Posts
    180
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not Sure what this method looks like in C++, But it looks organized, Do you have project your working on that uses this or you just learning ? Keep it up bro

  3. #3
    starfish99's Avatar Corporal
    Reputation
    31
    Join Date
    May 2008
    Posts
    24
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you should define functions of Lua_PushString,Lua_GetString,etc.

    following codes show how to define a function,and how to translate delphi code to c++ code

    in delphi:

    const
    ptrLua_PushString = $007ADB90;

    type
    TLua_PushString = function(Lua_L,index,Zero:LongWord):PChar;cdecl;

    var
    Lua_PushString : TLua_PushString = Pointer(ptrLua_PushString);

    in c++

    typedef char* (__cdecl * TLua_PushString)(unsigned int Lua_L, unsigned int index, unsigned int Zero);
    TLua_PushString Lua_PushString = 0x007ADB90;

    about typedef in c++, you can see cyper's post in
    http://www.mmowned.com/forums/wow-me...nters-you.html
    Last edited by starfish99; 01-03-2009 at 11:10 PM.

  4. #4
    cloud_wizard's Avatar Member
    Reputation
    5
    Join Date
    Dec 2008
    Posts
    44
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by KRYPTON88 View Post
    Im not Sure what this method looks like in C++, But it looks organized, Do you have project your working on that uses this or you just learning ? Keep it up bro
    A little bit of both, learning as I go. Working on a bot that someone dropped on me. The idea has great potential, if I can get it finished.

  5. #5
    Sillyboy72's Avatar Member
    Reputation
    13
    Join Date
    Jan 2009
    Posts
    66
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know I already posted this in the other thread, but since you seem to be heading this direction... just pointing out again that your MemoryReadString busted. Sorry, I can't really help fix it... as I don't know how strings are stored in wow (fixed length, length prefixed, zero terminated... whatever). but you need to allocate some memory to read into, and you need to pass a reasonable size to ReadProcessMemory, not sizeof(ReadAddress)

  6. #6
    cloud_wizard's Avatar Member
    Reputation
    5
    Join Date
    Dec 2008
    Posts
    44
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Sillyboy72 View Post
    I know I already posted this in the other thread, but since you seem to be heading this direction... just pointing out again that your MemoryReadString busted. Sorry, I can't really help fix it... as I don't know how strings are stored in wow (fixed length, length prefixed, zero terminated... whatever). but you need to allocate some memory to read into, and you need to pass a reasonable size to ReadProcessMemory, not sizeof(ReadAddress)
    Strings in WoW are zero terminated, I'm pretty sure. But ... Why would I need to "allocate" memory for the string I'm reading? Isn't that done upon variable declaration? I don't follow what you're trying to say here...

  7. #7
    Sillyboy72's Avatar Member
    Reputation
    13
    Join Date
    Jan 2009
    Posts
    66
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because you aren't just "reading" memory... you are "copying" memory for this process space to yours. As such, you need someplace to stick the copy.

    If this were good old K&R c code...
    Code:
    char *mySrc = "this is my uber string";
    char *myDest;
    memcpy(myDest, mySrc, strlen(mySrc) + 1);
    This would blow up... because myDest doesn't point to any valid memory. This is pretty darn close to your problem.

  8. #8
    Xarg0's Avatar Member
    Reputation
    61
    Join Date
    Jan 2008
    Posts
    389
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Sillyboy72 View Post
    Because you aren't just "reading" memory... you are "copying" memory for this process space to yours. As such, you need someplace to stick the copy.

    If this were good old K&R c code...
    Code:
    char *mySrc = "this is my uber string";
    char *myDest;
    memcpy(myDest, mySrc, strlen(mySrc) + 1);
    This would blow up... because myDest doesn't point to any valid memory. This is pretty darn close to your problem.
    Well I'm pretty sure he's using the std::string class so he doesn't need to allocate memory manually, still he doesn't use ReadProcessMemory correctly as his bytestoread value will always be 4.

    Edit: just read your response to his other thread, you're completely right, he still needs to make sure he allocated enough space, when you use string methods to fill the string the string class will take care of that, but with ReadProcessMemory you could easily create an access violation, also I'm pretty sure you can't simply pass the address of your string object to as a target to ReadProcessMemory, you'd properly mess up the hole thing :>, it'd be easier for him to just use a char* and allocate enough space.
    Last edited by Xarg0; 01-04-2009 at 08:50 AM.
    I hacked 127.0.0.1

Similar Threads

  1. Game crashes when calling lua function before loading screen
    By avizer in forum WoW Memory Editing
    Replies: 6
    Last Post: 04-03-2013, 09:04 PM
  2. Calling lua functions requiering an hardware event
    By Frosttall in forum WoW Memory Editing
    Replies: 10
    Last Post: 12-22-2012, 11:19 AM
  3. Calling Lua Functions from DLL
    By Viano in forum WoW Memory Editing
    Replies: 19
    Last Post: 07-28-2009, 07:56 PM
  4. Call lua function and get result
    By starfish99 in forum WoW Memory Editing
    Replies: 4
    Last Post: 12-26-2008, 05:15 AM
  5. Replies: 22
    Last Post: 05-29-2008, 03:52 PM
All times are GMT -5. The time now is 08:08 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search