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 


Simple Problem - Simple Question - C++

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
DEVCORE
Cheater
Reputation: 0

Joined: 11 Aug 2018
Posts: 28

PostPosted: Tue Sep 18, 2018 11:01 pm    Post subject: Simple Problem - Simple Question - C++ Reply with quote

I am separating my code instead of writing it all in main. Practicing to use header files to split up everything. Besides the point I have got a problem.

I am trying to define a function called ReadPlayerInformation() - Inside it I am defining ReadProcessMemory(hProcess) - The problem here is that hProcess is in the main.cpp, how can I use the handle hProcess? Because it cannot find the hProcess from the main? Will post my code below so it will be more easier to see.






[ AddressOffsets.cpp ]
Code:
#pragma once
#include <iostream>
#include <Windows.h>
#include "AddressOffsets.h"

void Player_t::ReadPlayerInformation()
{
   ReadProcessMemory(hProcess)  <<--- Problem here

}



[ Main.cpp ]


Code:
#include <iostream>
#include "Windows.h"
#include "ProcessMemory.h"
#include "AddressOffsets.h"


using namespace std;

int main()
{
   DWORD ProcessID;
   ProcessID = GetProcessID(L"csgo.exe");

   uintptr_t ModuleBaseAddress;
   ModuleBaseAddress = GetModuleBaseAddress(ProcessID, L"client_panorama.dll");

   HANDLE hProcess;
   hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, ProcessID);
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25253
Location: The netherlands

PostPosted: Tue Sep 18, 2018 11:17 pm    Post subject: Reply with quote

make it a global or pass it as a parameter to the constructor of Player_t
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
DEVCORE
Cheater
Reputation: 0

Joined: 11 Aug 2018
Posts: 28

PostPosted: Tue Sep 18, 2018 11:27 pm    Post subject: Reply with quote

Dark Byte wrote:
make it a global or pass it as a parameter to the constructor of Player_t


Any example on how to do it? Sorry really new to coding....
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8515
Location: 127.0.0.1

PostPosted: Wed Sep 19, 2018 12:05 pm    Post subject: Reply with quote

DEVCORE wrote:
Dark Byte wrote:
make it a global or pass it as a parameter to the constructor of Player_t


Any example on how to do it? Sorry really new to coding....


You should really take the time to learn what you are doing then instead of just immediately jumping into trying to write game hacks.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
DEVCORE
Cheater
Reputation: 0

Joined: 11 Aug 2018
Posts: 28

PostPosted: Wed Sep 26, 2018 9:55 pm    Post subject: Reply with quote

Dark Byte wrote:
make it a global or pass it as a parameter to the constructor of Player_t


UPDATE: Ok with countless learning from tutorials. I kind of understand abit now. Though how can I pass parameter as a constructer?

Because now I have made hProcess member variable in its own class. hProcess is in another class. For example hProcess member variable is in another class called class1.cpp. And class2.cpp which has Player_t class now needs that hProcess member variable inside its method which is the winapi RPM that requires the handle hProcess - By you’re advice how would I pass it to a constructor?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25253
Location: The netherlands

PostPosted: Wed Sep 26, 2018 11:34 pm    Post subject: Reply with quote

Look into class constructors and create one with a parameter for the handle and in there assign it to it's own variable

then do new Player_t(handle)

you can of coirse also malebit a public and then ObjectOfPlayer_t.itshandle=handle (or if you created it as a pointer then ObjectOfPlayer_t->itshandle=handle)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8515
Location: 127.0.0.1

PostPosted: Fri Sep 28, 2018 1:44 am    Post subject: Reply with quote

DEVCORE wrote:
Dark Byte wrote:
make it a global or pass it as a parameter to the constructor of Player_t


UPDATE: Ok with countless learning from tutorials. I kind of understand abit now. Though how can I pass parameter as a constructer?

Because now I have made hProcess member variable in its own class. hProcess is in another class. For example hProcess member variable is in another class called class1.cpp. And class2.cpp which has Player_t class now needs that hProcess member variable inside its method which is the winapi RPM that requires the handle hProcess - By you’re advice how would I pass it to a constructor?


You are asking pretty basic C++ questions here.. you should really take the time to learn what you are doing with the language first before trying to use it for game hacking. Using classes, function parameters, constructors etc. are all basic level stuff for C++.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
DEVCORE
Cheater
Reputation: 0

Joined: 11 Aug 2018
Posts: 28

PostPosted: Tue Oct 02, 2018 12:22 am    Post subject: Reply with quote

Dark Byte wrote:
Look into class constructors and create one with a parameter for the handle and in there assign it to it's own variable

then do new Player_t(handle)

you can of coirse also malebit a public and then ObjectOfPlayer_t.itshandle=handle (or if you created it as a pointer then ObjectOfPlayer_t->itshandle=handle)


Does that mean I need to create another new variable member called hProcess for Player_t struct when passing to constructor?

Is this correct? So every time I want to access a member variable from a different class inside current class. I will need to create a new member variable to assign what is passed through?

Code:

struct Player_t
{
Int hProcess;

Player_t(HANDLE h)
{
hProcess = h;
}

};
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 Gamehacking 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