[HELP] atan2 cant get it to work menu

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    kosacid's Avatar Active Member
    Reputation
    19
    Join Date
    May 2009
    Posts
    127
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [SOLVED] atan2 cant get it to work

    Solved
    header.h
    Code:
    #include <Windows.h>
    #include <iostream>
    #include <string>
    #include <list>
    #include <tlhelp32.h>
    #include <Shlwapi.h>
    
    #define foreach(lst, type, var) for(list< type >::iterator var = lst.begin(); (var != lst.end()); var++)
    #define KEYUP_FLAGS 0xC0000001
    #define PI 3.14159265
    using namespace std;
    typedef unsigned int uint;
    
    enum ObjectManager
    {
        CurMgrPointer = 0x9BE7E0,
        CurMgrOffset = 0x463C,
        NextObject = 0x3C,
        FirstObject = 0xC0,
        LocalGUID = 0xC8
    };
    
    enum WowObject
    {
        X = 0x790,
        Y = X + 0x4,
        Z = X + 0x8,
        RotationOffset = X + 0x10
    };
    
    struct INISECTIONVALUE
    {
    	string scKey;
    	string scValue;
    };
    
    struct COORDS
    {
    	float coordsX;
    	float coordsY;
    	float coordsZ;
    };
    
    void ReadProcMem(void *pAddress, void *pMem, int iSize);
    void WriteProcMem(void *pAddress, void *pMem, int iSize);
    void LoadSetting();
    void IniGetSection(string scFile, string scApp, list<INISECTIONVALUE> &lstValues);
    unsigned long GetPid(char *procName);
    DWORD GetBase(char* DllName, DWORD tPid);
    string GetParam(string scLine, char cSplitChar, uint iPos);
    float ToFloat(string scStr);
    UINT ReadCoords();
    void Rotation(float rotx, float roty);
    main.cpp
    Code:
    #include "header.h"
    
    string set_scNavFile;
    DWORD Pid;
    uint BaseAddress;
    bool MapMode = false;
    bool NavMode = false;
    float mx,my,mz,rot;
    int MapCounter;
    HWND hwnd;
    
    void LoadSetting()
    {
        char szCurDir[MAX_PATH];
        GetCurrentDirectory(sizeof(szCurDir), szCurDir);
        set_scNavFile = string(szCurDir) + "\\nav.ini";
    	Pid = GetPid("Wow.exe");
    	BaseAddress = GetBase("Wow.exe",Pid);
    	hwnd = ::FindWindow(NULL,"World of Warcraft");
    }
    
    int main(int argc, char* argv[])
    {
    	LoadSetting();
    	CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ReadCoords,NULL, 0, NULL);
    	while(true)
    	{
    		if(GetAsyncKeyState(VK_F1))
    		{
    			if(!MapMode)
    			{
    				MapMode = true;
    				NavMode = false;
    			    cout << "Map Mode" << endl;
    				FILE *map = fopen("nav.ini","w");
    				if(map!=NULL)
    				{
    					fprintf(map,"[nav]\n");	
    				}
    				fclose(map);
    				MapCounter = 0;
    			}
    		}
    		if(GetAsyncKeyState(VK_F2))
    		{
    			if(!NavMode)
    			{
    				MapMode = false;
    				NavMode = true;
    			    cout << "Nav Mode" << endl;
    			}
    		}
    		if(MapMode)
    		{
    			if(GetAsyncKeyState(VK_LBUTTON ))
    			{
    			    FILE *map = fopen("nav.ini","at");
    				if(map!=NULL)
    				{
    					fprintf(map,"%i=%f %f %f\n",MapCounter,mx,my,mz);
    					printf("%i=%f %f %f\n",MapCounter,mx,my,mz);
    			        MapCounter+=1;
    				}
    				fclose(map);
    				Sleep(1000);
    			}
    		}
    		if(NavMode)
    		{
    			list<INISECTIONVALUE>lstCoords;
    			list<COORDS>lstMain;
    			lstCoords.clear();
    			lstMain.clear();
    			IniGetSection(set_scNavFile, "nav", lstCoords);
    			foreach(lstCoords, INISECTIONVALUE,lst)
    			{
    				COORDS c;
    				c.coordsX = ToFloat(GetParam(lst->scValue,' ',0));
    				c.coordsY = ToFloat(GetParam(lst->scValue,' ',1));
    				c.coordsZ = ToFloat(GetParam(lst->scValue,' ',2));
    				lstMain.push_back(c);
    			}
    			foreach(lstMain,COORDS,lstC)
    			{
    				int timer=0;
    				::PostMessage(hwnd, WM_KEYDOWN, VK_UP, 0);
    				start:
    				if(GetAsyncKeyState(VK_F4))
    				{
    					::PostMessage(hwnd,WM_KEYUP,VK_UP,KEYUP_FLAGS);
    					NavMode = false;
    					break;
    				}
    				Rotation(lstC->coordsX, lstC->coordsY);
    				if(timer==250)
    				{
    					::PostMessage(hwnd,WM_KEYUP,VK_UP,KEYUP_FLAGS);
    					::PostMessage(hwnd, WM_KEYDOWN, VK_UP, 0);
    					timer=0;
    				}
    				timer += 1;
    				if((int)lstC->coordsX == (int)mx && (int)lstC->coordsY == (int)my)
    					goto end;
    				goto start;
                    end:
    				up:
    				if(mz - lstC->coordsZ < -0.1f)
    				{
    					::PostMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
    					Sleep(10);
    					goto up;
    				}
    				::PostMessage(hwnd,WM_KEYUP,VK_SPACE,KEYUP_FLAGS);
    				down:
    				if(mz - lstC->coordsZ > 0.1f)
    				{
    					::PostMessage(hwnd, WM_KEYDOWN, VkKeyScan('x'), 0);
    					Sleep(10);
    					goto down;
    				}
    				::PostMessage(hwnd,WM_KEYUP,VkKeyScan('x'),KEYUP_FLAGS);
    			}
    		}
    	}
    	return 0;
    }
    
    UINT ReadCoords()
    {
    	while(true)
    	{
    	    uint ObjectPointer;
    	    ReadProcMem((LPVOID)(BaseAddress + CurMgrPointer),&ObjectPointer,4);
    	    ReadProcMem((LPVOID)(ObjectPointer + CurMgrOffset),&ObjectPointer,4);
    	    UINT64 me;
    	    ReadProcMem((LPVOID)(ObjectPointer + LocalGUID),&me, 8);
    	    ReadProcMem((LPVOID)(ObjectPointer + FirstObject),&ObjectPointer,4);
    	    while (ObjectPointer != 0 && ObjectPointer % 2 == 0)
    	    {
    		    UINT64 cobj;
    		    ReadProcMem((LPVOID)(ObjectPointer + 0x30),&cobj, 8);
    		    if(me == cobj)
    		    {
    			    ReadProcMem((LPVOID)(ObjectPointer + X),&mx, 4);
    			    ReadProcMem((LPVOID)(ObjectPointer + Y),&my, 4);
    			    ReadProcMem((LPVOID)(ObjectPointer + Z),&mz, 4);
    			    ReadProcMem((LPVOID)(ObjectPointer + RotationOffset),&rot, 4);
    		    }
    		    ReadProcMem((LPVOID)(ObjectPointer + NextObject),&ObjectPointer,4);
    	    }
    	}
    }
    
    void Rotation(float rotx, float roty)
    {
    	uint ObjectPointer;
    	ReadProcMem((LPVOID)(BaseAddress + CurMgrPointer),&ObjectPointer,4);
    	ReadProcMem((LPVOID)(ObjectPointer + CurMgrOffset),&ObjectPointer,4);
    	UINT64 me;
    	ReadProcMem((LPVOID)(ObjectPointer + LocalGUID),&me, 8);
    	ReadProcMem((LPVOID)(ObjectPointer + FirstObject),&ObjectPointer,4);
    	while (ObjectPointer != 0 && ObjectPointer % 2 == 0)
    	{
    		UINT64 cobj;
    		ReadProcMem((LPVOID)(ObjectPointer + 0x30),&cobj, 8);
    		if(me == cobj)
    		{
    			float x, x2;
                float y, y2;
    			double result;
    			ReadProcMem((LPVOID)(ObjectPointer + X),&x, 4);
    			ReadProcMem((LPVOID)(ObjectPointer + Y),&y, 4);
    			ReadProcMem((LPVOID)(ObjectPointer + RotationOffset),&rot, 4);
                x2 = rotx;
                y2 = roty;
    			result = atan2 (y2 - y, x2 - x);
    			if(result < 0)
                    result+= PI * 2;
    			float temp = (float)result;
    			if( temp >= 0 && temp <= 6.2831853f )
    			    WriteProcMem((LPVOID)(ObjectPointer + RotationOffset),&temp, 4);
    		}
    		ReadProcMem((LPVOID)(ObjectPointer + NextObject),&ObjectPointer,4);
    	}
    }
    
    void ReadProcMem(void *pAddress, void *pMem, int iSize)
    {
    	HANDLE hProc = OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_WRITE|PROCESS_VM_READ, FALSE, Pid);
    	DWORD dwOld;
    	VirtualProtectEx(hProc, pAddress, iSize, PAGE_EXECUTE_READWRITE, &dwOld);
    	ReadProcessMemory(hProc, pAddress, pMem, iSize, 0);
    	CloseHandle(hProc);
    }
    
    void WriteProcMem(void *pAddress, void *pMem, int iSize)
    {
    	HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
    	DWORD dwOld;
    	VirtualProtectEx(hProc, pAddress, iSize, PAGE_EXECUTE_READWRITE, &dwOld);
    	WriteProcessMemory(hProc, pAddress, pMem, iSize, 0);
    	CloseHandle(hProc);
    }
    
    void IniGetSection(string scFile, string scApp, list<INISECTIONVALUE> &lstValues)
    {
    	lstValues.clear();
    	char szBuf[0xFFFF];
    	GetPrivateProfileSection(scApp.c_str(), szBuf, sizeof(szBuf), scFile.c_str());
    	char *szNext = szBuf;
    	while(strlen(szNext) > 0)
    	{
    		INISECTIONVALUE isv;
    		char szKey[0xFFFF] = "";
    		char szValue[0xFFFF] = "";
    		sscanf(szNext, "%[^=]=%[^\n]", szKey, szValue);
    		isv.scKey = szKey;
    		isv.scValue = szValue;
    		lstValues.push_back(isv);
    		szNext += strlen(szNext) + 1;
    	}
    }
    
    unsigned long GetPid(char *procName)
    {
       PROCESSENTRY32 pe;
       HANDLE thSnapshot;
       BOOL retval, ProcFound = false;
       thSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
       if(thSnapshot == INVALID_HANDLE_VALUE)
       {
          MessageBox(NULL, "Error: unable to create toolhelp snapshot","Error", NULL);
          return false;
       }
       pe.dwSize = sizeof(PROCESSENTRY32);
       retval = Process32First(thSnapshot, &pe);
       while(retval)
       {
          if(StrStrI(pe.szExeFile, procName) )
          {
             ProcFound = true;
             break;
          }
          retval    = Process32Next(thSnapshot,&pe);
          pe.dwSize = sizeof(PROCESSENTRY32);
       }
       if (!ProcFound) return 0;
       return pe.th32ProcessID;
    }
    
    DWORD GetBase(char* DllName, DWORD tPid)
    {
        HANDLE snapMod;
        MODULEENTRY32 me32;
        if (tPid == 0) return 0;
        snapMod = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, tPid);
        me32.dwSize = sizeof(MODULEENTRY32);
        if (Module32First(snapMod, &me32))
    	{
            do{
                  if (strcmp(DllName,me32.szModule) == 0)
    			  {
                      CloseHandle(snapMod);
                      return (DWORD) me32.modBaseAddr;
    			  }
    		}while(Module32Next(snapMod,&me32));
        }
        CloseHandle(snapMod);
    	return 0;
    }
    
    float ToFloat(string scStr)
    {
    	return (float)atof(scStr.c_str());
    }
    
    string GetParam(string scLine, char cSplitChar, uint iPos)
    {
    	uint i = 0, j = 0;
    	string scResult = "";
    	for(i = 0, j = 0; (i <= iPos) && (j < scLine.length()); j++)
    	{
    		if(scLine[j] == cSplitChar)
    		{
    			while(((j + 1) < scLine.length()) && (scLine[j+1] == cSplitChar))
    				j++; // skip "whitechar"
    			i++;
    			continue;
    		}
    		if(i == iPos)
    			scResult += scLine[j];
    	}
    	return scResult;
    }
    f1 makes a new nav.ini file as you move along just press the left mouse button to record the coords to file
    f2 it will start to follow the coords recorded to the file
    f4 resets back to the start
    Last edited by kosacid; 07-13-2012 at 08:49 AM. Reason: more info

    [HELP] atan2 cant get it to work
  2. #2
    dehe's Avatar Member
    Reputation
    1
    Join Date
    Mar 2012
    Posts
    17
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    this is how i handle facing:
    Code:
      o = new WoWMemory.Objects.CCreatureObject(CGlobals.ObjectManager.getObject(CGlobals.ObjectManager.Player.Target_GUID).BaseAdress);
                    double x = o.X - CGlobals.ObjectManager.Player.X;
                    double y = o.Y - CGlobals.ObjectManager.Player.Y;
    
                    double d=Math.Atan2(y,x);
                    
    
                    String sFacing = CGlobals.PlayerAction.CallAPIFunctionReturn("GetPlayerFacing()");//this is the Lua API called by Lua_DoString
                    sFacing = sFacing.Replace(".", ",");
                    double dFacing = double.Parse(sFacing);
                    double r = d - dFacing; 	  // substracting object rotation from absolute rotation
                    if (r < 1)
                        r *= -1;
    
                    if (r>2)
                    {
                        CGlobals.ObjectManager.Player.AttackTarget(0);
                    }
    Last edited by dehe; 07-02-2012 at 09:20 AM.

  3. #3
    kosacid's Avatar Active Member
    Reputation
    19
    Join Date
    May 2009
    Posts
    127
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bump
    im trying to get it to face a point on the map enyone got a working example eg you put the map coords in then the player faces that point
    even converting the results to float and righting direct to the ObjectPointer + RotationOffset is giving the same results
    so what am i doing wrong i know it will be some thing simple
    eny example will do for eny version just to show how its done
    Last edited by kosacid; 07-06-2012 at 05:48 AM. Reason: more info

  4. #4
    kosacid's Avatar Active Member
    Reputation
    19
    Join Date
    May 2009
    Posts
    127
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok worked it out its because the way the coords system in wow is messed up you have to swap the X Y input it wasent till i moved north i reliesed it was working on the X coord not the Y
    so insted of having
    mx = (float)atof(argv[1]);
    my = (float)atof(argv[2]);
    it is
    mx = (float)atof(argv[2]);
    my = (float)atof(argv[1]);
    Last edited by kosacid; 07-11-2012 at 05:35 PM. Reason: info

  5. #5
    kosacid's Avatar Active Member
    Reputation
    19
    Join Date
    May 2009
    Posts
    127
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have a question how safe is it to right direcly to the rotation ???
    i did test it for a while but im not too sure i dont quite like the idea of righting to addreses
    Last edited by kosacid; 07-12-2012 at 07:59 AM.

  6. #6
    Frosttall's Avatar Active Member
    Reputation
    64
    Join Date
    Feb 2011
    Posts
    261
    Thanks G/R
    16/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by kosacid View Post
    i have a question how safe is it to right direcly to the rotation ???
    i did test it for a while but im not too sure i dont quite like the idea of righting to addreses
    Sorry, but what do you try to ask?

    In the case that you mean "rotate" instead of "right", then is the answer: Yes.

    There is no problem.

  7. #7
    kosacid's Avatar Active Member
    Reputation
    19
    Join Date
    May 2009
    Posts
    127
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WriteProcMem((LPVOID)(ObjectPointer + RotationOffset),&temp, 4);
    as you can see im righting to that address not sure if its fine to do that or not
    suppose is the same as turning round with left mouse button and then clicking the right
    or am i just being to paranoid lol

  8. #8
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's called WriteProcMem and you "right" to an address?
    IIRC you are lucky and writing the rotation there is not just client side, which means it could work (search through the forums, I'm pretty sure it has been answered already).

  9. #9
    kosacid's Avatar Active Member
    Reputation
    19
    Join Date
    May 2009
    Posts
    127
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Bananenbrot ive altered the post to solved i was just asking if its safe to alter the rotation direct like what ive done
    its all working now

  10. #10
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think it is detectable, since you are modifying a field of a dynamically allocated object, which most probably isn't checked for.
    There might be a server-side check for rotation delta, though I highly doubt that based on how many people did that in the past.

  11. #11
    kosacid's Avatar Active Member
    Reputation
    19
    Join Date
    May 2009
    Posts
    127
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ive altered the code to make it a bit more smoth also added a thread to keep it constantly update but it works prity good now
    just ploted a course all the way round The Storm Peaks to find Time Lost
    Last edited by kosacid; 07-13-2012 at 08:16 AM.

  12. #12
    Frosttall's Avatar Active Member
    Reputation
    64
    Join Date
    Feb 2011
    Posts
    261
    Thanks G/R
    16/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't need a thread, just write the guid to CTM and push it with 0x1. The result will be a constant facing
    .

  13. #13
    kosacid's Avatar Active Member
    Reputation
    19
    Join Date
    May 2009
    Posts
    127
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Frosttall the threads for to keep the coords constantly update its nothing to do with movement, like you say though CTM is another way of doing it, but i did read in a few threads there was banns for using CTM so i didnt use it
    right time to make it into a MFC and clean it up a bit
    Last edited by kosacid; 07-13-2012 at 06:27 PM.

  14. #14
    Frosttall's Avatar Active Member
    Reputation
    64
    Join Date
    Feb 2011
    Posts
    261
    Thanks G/R
    16/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by kosacid View Post
    @Frosttall the threads for to keep the coords constantly update its nothing to do with movement, like you say though CTM is another way of doing it, but i did read in a few threads there was banns for using CTM so i didnt use it
    right time to make it into a MFC and clean it up a bit
    So what's the method you're using instead? Moving with the arrow-keys and press 'left' and 'right' to rotate?

    P.S. There has never been a problem with using CTM, only that you get disconnected if you're sending too many CTM-Requests in a little timespan.

  15. #15
    kosacid's Avatar Active Member
    Reputation
    19
    Join Date
    May 2009
    Posts
    127
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so is that why maby some are get caught out too much Requests also i noticed Lazy Bot says not to use it ?
    the way i do it is with the keys apart from the rotation i wright that direct its the only way i found to keep it acurate moving with keys left right is no good
    Last edited by kosacid; 07-14-2012 at 03:30 AM.

Page 1 of 2 12 LastLast

Similar Threads

  1. [Trinity] Help needed cant get it online
    By GodAmongDogs in forum WoW EMU Questions & Requests
    Replies: 7
    Last Post: 11-06-2011, 05:35 PM
  2. [Reskin] Dwarf to Iron Dwarf cant get it to Work!
    By Deathbringer123 in forum WoW ME Questions and Requests
    Replies: 2
    Last Post: 03-05-2011, 04:03 AM
  3. sgather guide please help!!. i cant get it working. getting errors.
    By duyee in forum WoW Bot Maps And Profiles
    Replies: 4
    Last Post: 02-26-2011, 03:02 PM
  4. Help i cant get my server to work for me and my cuzin
    By cdsingleton in forum WoW EMU Questions & Requests
    Replies: 2
    Last Post: 07-12-2009, 03:09 PM
  5. cant get server to work help!?
    By Denelly in forum World of Warcraft Emulator Servers
    Replies: 11
    Last Post: 10-30-2007, 03:11 PM
All times are GMT -5. The time now is 09:26 AM. 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