Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


c++ file input/output

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
123qwe
Newbie cheater
Reputation: 0

Joined: 26 Dec 2006
Posts: 21

PostPosted: Sat Feb 21, 2009 7:54 pm    Post subject: c++ file input/output Reply with quote

hey

for sum reason when i run my program it doesnt work as expected.

this is what i do.
1.load cursor co ords from txt file.
2.set cursor pos (to the ones from the file) and right click.

unfortuantly it doesnt do what i want it to, it doesnt move to the correct cursor position. it just goes to the top left hand of my monitor.

heres my code


Code:
#include <iostream>
#include <tchar.h>
#include <fstream>
#include "stdafx.h"
using namespace std;

DWORD SCP = (DWORD)GetProcAddress(LoadLibraryW(L"user32.dll"), "SetCursorPos") + 5;

__declspec(naked) BOOL WINAPI SetCursorPosX(int X, int Y)
{
   __asm
   {
      push   ebp
      mov    ebp, esp
      jmp    dword ptr [SCP]
   }
}

DWORD PMA = (DWORD)GetProcAddress(LoadLibraryW(L"user32.dll"), "PostMessageA") + 5;

__declspec(naked) BOOL WINAPI PostMessageX(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
   __asm
   {
      push   ebp
      mov    ebp, esp
      jmp    dword ptr [PMA]
   }
}

int righ[3];//r

HWND MuWndt = FindWindow("MU", NULL);
void load()
{

   ////////////right click
   ifstream toad("dw_dk.txt");
   int yucky;
   int rats = 0;
   while(toad >> yucky)
   {
      righ[rats] = yucky;
      rats++;
   }
}


int zop = 0;
DWORD WINAPI rightclick(LPVOID)
{
   if(zop == 0)
   {
      zop = 1;
      int i;
      while(1)
      {
         SetCursorPosX(righ[0], righ[1]);
         Sleep(100);
         PostMessageX(MuWndt, WM_RBUTTONDOWN, NULL, MAKELPARAM(righ[0], righ[1]));
         for(i = 0; i < 1000; i++)//100000
         {
            Sleep(10);
             if(GetAsyncKeyState(VK_NUMPAD2) || GetAsyncKeyState(VK_NUMPAD0) & 0x8000)
             {
               zop = 0;
               PostMessageX(MuWndt, WM_RBUTTONUP, NULL, MAKELPARAM(righ[0], righ[1]));
               return 0;
            }
         }
         PostMessageX(MuWndt, WM_RBUTTONUP, NULL, MAKELPARAM(righ[0], righ[1]));
         Sleep(1500);
         SetCursorPosX(righ[2], righ[3]);
         Sleep(500);
      }
   }
   return 0;
}

int main()
{
   load();
   while(1)
   {
      Sleep(10);
      if(GetAsyncKeyState(VK_NUMPAD2))
      {
         CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)&rightclick, 0, 0, NULL);
      }
          }

return 0;
}


thanks for any help!!!
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sun Feb 22, 2009 12:06 am    Post subject: Reply with quote

You have to convert the strings to integers.
Back to top
View user's profile Send private message MSN Messenger
123qwe
Newbie cheater
Reputation: 0

Joined: 26 Dec 2006
Posts: 21

PostPosted: Sun Feb 22, 2009 2:44 am    Post subject: Reply with quote

it's declared as an int though isnt it?

in the line
Code:
int righ[3];//r


because an int cannot store a string?

thanks
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sun Feb 22, 2009 3:23 am    Post subject: Reply with quote

You assigned a string into an integer.

Edit: Oh, you used the >> operator... so I guess the the coordinates in the text file are incorrect.


Last edited by Zerith on Sun Feb 22, 2009 5:07 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
123qwe
Newbie cheater
Reputation: 0

Joined: 26 Dec 2006
Posts: 21

PostPosted: Sun Feb 22, 2009 4:17 am    Post subject: Reply with quote

T___T but it says int in everything

Code:

   int yucky;
   int rats = 0; 


i really dont get it :/

please show me how its done sir
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sun Feb 22, 2009 5:09 am    Post subject: Reply with quote

Oh, my bad, I didn't see you used the >> operator.

Well, you tried reading righ[3] which is out of the array bounds, that's your first mistake.
Also check that the coordinates are correct, try debugging.
Back to top
View user's profile Send private message MSN Messenger
123qwe
Newbie cheater
Reputation: 0

Joined: 26 Dec 2006
Posts: 21

PostPosted: Sun Feb 22, 2009 5:20 am    Post subject: Reply with quote

Quote:
Oh, my bad, I didn't see you used the >> operator.

thats fine

all of the co ords printed fine.

i wasnt sure if it was being converted properly like u said about the string stuff, and i thought that was the reason it isnt working properly. but i really have no clue :/
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sun Feb 22, 2009 6:15 am    Post subject: Reply with quote

Your array size is only 3 and you're accessing the 4th cell (righ[3]), so if all the coordinates are correct it means you read more than 3 integers - index is out of range.

And what's SetCursorPosX? some hooked function? maybe the problem is in there.
Back to top
View user's profile Send private message MSN Messenger
123qwe
Newbie cheater
Reputation: 0

Joined: 26 Dec 2006
Posts: 21

PostPosted: Sun Feb 22, 2009 2:56 pm    Post subject: Reply with quote

yeh i fixed teh array stuff,still isnt working

heres setcursorposx and postmessagex


Code:
DWORD SCP = (DWORD)GetProcAddress(LoadLibraryW(L"user32.dll"), "SetCursorPos") + 5;

__declspec(naked) BOOL WINAPI SetCursorPosX(int X, int Y)
{
   __asm
   {
      push   ebp
      mov    ebp, esp
      jmp    dword ptr [SCP]
   }
}

DWORD PMA = (DWORD)GetProcAddress(LoadLibraryW(L"user32.dll"), "PostMessageA") + 5;

__declspec(naked) BOOL WINAPI PostMessageX(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
   __asm
   {
      push   ebp
      mov    ebp, esp
      jmp    dword ptr [PMA]
   }
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites