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++ Functions

 
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: Thu Jan 22, 2009 4:27 am    Post subject: C++ Functions Reply with quote

hello

how would i Load a txt file when my program starts and retrieve values from it before anyhting else happens?
and yes i know this code below doesnt work but i hope u understand what i need help with thanks.
e.g.

void loadtxt()
{
bla bla

return ARRAY (how do i do that?)
}

main()
{
loadtxt();
cout << ARRAY[1];
}
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Jan 22, 2009 4:45 am    Post subject: Reply with quote

first thing.
you cant return array when you declared a void function
if you want to return other value then void
replace the void with the type of value returned
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Thu Jan 22, 2009 5:35 am    Post subject: Reply with quote

Code:
#include <stdlib.h>

char *func()
{
  char *c; // =malloc(512);
  //..
  return c;
}

int main(int argc, char *argv[])
{
  char *c;
  c = func();
  // dealloc(c);
  return 0;
}

Code:
#include <stdlib.h>

void func(char *c)
{
  // Do something with c, eg.
  c[0] = 'a';
  return;
}

int main(int argc, char *argv[])
{
  char *c = malloc(1);
  func(c);
  dealloc(c);
  return 0;
}


You might also want to return the length of c. I wrote it with C, but w/e, you got the point. Also, here you don't actually return the array, but a pointer to memory where the stuff is.
Back to top
View user's profile Send private message
simondaking
How do I cheat?
Reputation: 0

Joined: 28 Nov 2008
Posts: 4

PostPosted: Thu Jan 22, 2009 10:48 am    Post subject: Reply with quote

Here is some code that shows you how to open a file and read its contents...

Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
    cout << "enter file name to read: ";

    string filename;
    getline(cin, filename);
    fstream fin(filename.c_str());

    while(fin)   
        cout << (char)fin.get();
}
Back to top
View user's profile Send private message
123qwe
Newbie cheater
Reputation: 0

Joined: 26 Dec 2006
Posts: 21

PostPosted: Thu Jan 22, 2009 6:44 pm    Post subject: Reply with quote

i'll give u my code and i'll show u what i mean =]


Code:

VOID LOAD()
{
      int turk[2];
      ifstream turka("repot.txt");
      int inaa;
      int poooo = 0;
      while(turka >> inaa)
      {
         turk[poooo] = inaa;
         poooo++;
      }
}

DWORD WINAPI leftclick(LPVOID)
{

      //DO LEFT CLICK HERE AT CURSOR POINT TURK[0], TURK[1]
   return 0;
}

int main()
{
load();

//IF NUMPAD 1 is pressed CREATE THREAD
return 0;
}



i have to load the variables from the file first cause once the game is loaded it uses to much resources and the file doesnt get opened quickly enough. when i try the above code it doesnt work(other then the obvious things i left out on purpose lol, otherwise the code is to big), it says undeclared turk[0].
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Thu Jan 22, 2009 7:34 pm    Post subject: Reply with quote

As is.. "turk" only exists in load(), you need to declare it in the global scope for other functions to access it.

Code:
int turk[2]; // global variable

void load()
{
      int turk[2]; // local variable, only available within this code block.
      ...
}
Back to top
View user's profile Send private message
123qwe
Newbie cheater
Reputation: 0

Joined: 26 Dec 2006
Posts: 21

PostPosted: Fri Jan 23, 2009 11:20 pm    Post subject: Reply with quote

omg i missed that LOL

thanks so much!!!!
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Sat Jan 24, 2009 3:28 am    Post subject: Reply with quote

pseudo code

GetWindowRect
calcute where pots are...(should work for any size window...(use GetPixel To find red and blue or w/e color your pots are)
use MouseMove and mouse_event to simulate hitting the pots and or find the hotkeys to use the pots?(most games have that now..)
and just use PostMessage to simulate key strokes alternitvly keybd_event would suffice..

regargs BanMe
Back to top
View user's profile Send private message MSN Messenger
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sat Jan 24, 2009 8:03 am    Post subject: Reply with quote

BanMe wrote:
pseudo code

GetWindowRect
calcute where pots are...(should work for any size window...(use GetPixel To find red and blue or w/e color your pots are)
use MouseMove and mouse_event to simulate hitting the pots and or find the hotkeys to use the pots?(most games have that now..)
and just use PostMessage to simulate key strokes alternitvly keybd_event would suffice..

regargs BanMe

type the wrong thing?

_________________
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