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++ | Help with WriteProcessMemory | Preview Included
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
DEVCORE
Cheater
Reputation: 0

Joined: 11 Aug 2018
Posts: 28

PostPosted: Mon Aug 20, 2018 1:59 am    Post subject: Reply with quote

OK with many days figuring what is the problem I have found out. It is my curly braces and my declarations position. Which I am not really sure about though.

Please compare the 2 pictures I have uploaded one is my old code and the other is my new code.

In the new code picture I have deleted some curly braces and I have moved the address declarations to another position etc please check if I have all the positioning in the new code picture right and is all my braces right aswell?

Or was the positioning of the declarations addresses and offset correct just the only thing wrong was the positioning of the: DWORD RifleAmmoAddress = LocalPlayerBasePointer + AmmoOffset ? Please give me some tips to avoid this mess in future.

============================================================



new working code jpeg.jpg
 Description:
 Filesize:  198.39 KB
 Viewed:  3113 Time(s)

new working code jpeg.jpg



old code not working jpeg.jpg
 Description:
 Filesize:  164.1 KB
 Viewed:  3114 Time(s)

old code not working jpeg.jpg


Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Mon Aug 20, 2018 5:17 am    Post subject: Reply with quote

The second one is using LocalPlayerBasePointer on line 35 before you set it with RPM on line 48.

As for avoiding it in the future, pay attention to the order things will be done in. Saying x = y+1 is not like in math where afterwards anytime you see x you use y+1 instead, it is literally setting x to the current value of y + 1 and afterwards anytime you see x it uses that value (until it is changed).

Also enable warnings and pay attention to them! You should have gotten one for using an uninitialized variable.



Only the braces for main and the first else (line 17) are necessary. Braces are unneeded for if-statements and loops unless you want more than one line of code to run (a compound-statement). Though some style guides recommend always having them so you can't come back later and add a line that you think will only run when it's true because it's indented like the first but ends up running all the time because the language doesn't actually care about indentation.

I'd also personally recommend just having a return in the if(!hWnd) and then you don't need an else+braces, same for if(!hProcess). That will keep the code from being unnecessarily indented which can make it harder to read in long code.

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
DEVCORE
Cheater
Reputation: 0

Joined: 11 Aug 2018
Posts: 28

PostPosted: Thu Aug 30, 2018 12:23 am    Post subject: Reply with quote

FreeER wrote:
I'd also personally recommend just having a return in the if(!hWnd) and then you don't need an else+braces, same for if(!hProcess). That will keep the code from being unnecessarily indented which can make it harder to read in long code.


Sorry for the late reply, I'm gonna include the new edited version there will be 2 pictures included.

- Are all the brackets all good now and is the coding right?

- Another question, you see where I am adding text to the console. Like I want to build a menu. Example:
MENU:
PRESS F1 - TURN ON/OFF
PRESS F2 - TURN ON/OFF

How should I position the text? Or I can position it anywhere? Abit confused sorry.

I really appreciate your help and time, thanks.



main_edited_part1of2_jpeg.jpg
 Description:
 Filesize:  156.22 KB
 Viewed:  3055 Time(s)

main_edited_part1of2_jpeg.jpg



main_edited_part2of2_jpeg.jpg
 Description:
 Filesize:  134.77 KB
 Viewed:  3055 Time(s)

main_edited_part2of2_jpeg.jpg


Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Thu Aug 30, 2018 5:36 am    Post subject: Reply with quote

Quote:
- Are all the brackets all good now and is the coding right?
does it do what you want? If so, probably yes, if not then, obviously not.

btw. pastebin / github etc. are much better ways to share code since we can control the font size or copy paste it into an editor with working folding or regex searches, personal syntax highlighting, add comments etc.

Quote:
How should I position the text? Or I can position it anywhere?
anywhere? If you have a gui in theory you could probably position it off screen and then move it on screen whenever you want the user to see it...if you just have a console app then standard C++ really doesn't give you any control over such things. I think window's conio has a gotoxy, and it may have a way to just set a char buffer, so it can be done but it's probably not worth it. Just print whatever you want and anytime you update it print a bunch of new lines (or use system("cls") since you only care about windows) and reprint everything.
_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
DEVCORE
Cheater
Reputation: 0

Joined: 11 Aug 2018
Posts: 28

PostPosted: Fri Aug 31, 2018 10:27 am    Post subject: Reply with quote

FreeER wrote:
Quote:
...


Have one more question please look at my latest picture as reference:

- You see where the headings are that are commented out. Rifle Ammo Function and Pistol Ammo Function in picture #2.
Inside that do you see where I have all my cout, “Your current rifle ammo is”, “Enter the value you want” etc.
I have placed them at those specific location because that the order of steps I’m thinking in my head.
But should I position them all together as one whole menu instead of separating them like this? If you have a look at picture #1 I have the heading Welcome To The Game Console Trainer seperate. Should I put all the cout together with the cout menu heading? Keeping the cout seperate from the rpm/wpm function? Or does it need to be separated and placed exactly where you want it to be executed like how I did it?



I hope you understand what I mean....
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Fri Aug 31, 2018 10:38 am    Post subject: Reply with quote

Just keep them in order that way you don't have to worry about things being done out of order and reusing the same variable overwriting the value before it was used or not putting a prompt before cin etc.
_________________
https://github.com/FreeER/ has a few CE related repos
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
Goto page Previous  1, 2
Page 2 of 2

 
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