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#] how to add and subtract from a value?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
flash harry
Newbie cheater
Reputation: 0

Joined: 19 Jun 2010
Posts: 16

PostPosted: Sat Jul 24, 2010 5:53 am    Post subject: [C#] how to add and subtract from a value? Reply with quote

hi, i have made a trainer in C# with buttons to set values like so:

Code:
        private void button1_Click(object sender, EventArgs e)
        {
            preader.ReadProcess = myprocesses[0];
            preader.OpenProcess();

            int byteswritten;
            float value;
            byte[] memory;
            value = 0.5F;
            memory = BitConverter.GetBytes(value);
            preader.WriteProcessMemory((IntPtr)0x345291FC, memory, out byteswritten);
        }


but my question is how do i add/subtract from a value instead of writing it

eg: say for example the value is 1140 and i want to subtract 300 to make the value = 840

plz help.
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Sat Jul 24, 2010 5:58 am    Post subject: Reply with quote

Code:
float f = 0.0f;
size_t size;
ReadProcessMemory(hProcess, (LPCVOID)0x345291FC, &f, sizeof(float), &size);
f -= 300.0f;
WriteProcessMemory(hProcess, (LPCVOID)0x345291FC, &f, sizeof(float), &size);
Now, do the same using your preader thing. Dunno about pointerless C#, but well, you get the idea.

Also, this isn't very efficient for constant writing.
Back to top
View user's profile Send private message
flash harry
Newbie cheater
Reputation: 0

Joined: 19 Jun 2010
Posts: 16

PostPosted: Sat Jul 24, 2010 7:59 am    Post subject: Reply with quote

Jani wrote:
Code:
float f = 0.0f;
size_t size;
ReadProcessMemory(hProcess, (LPCVOID)0x345291FC, &f, sizeof(float), &size);
f -= 300.0f;
WriteProcessMemory(hProcess, (LPCVOID)0x345291FC, &f, sizeof(float), &size);


Thank you very much for your time

but im not sure how to use this, i must be going wrong somwhere.

ive only been using C# for 3 days now and am making slow progress, i can now write values to an address and also NOP an address im just stuck now on this add/sub.


so i have an address (its static) 0x345287A0 FLOAT and i need to add/subtract 300 from it,

could somone be so kind to post how this would look inside a button function

Code:
private void button1_Click(object sender, EventArgs e)
        {
           
        }


so then i can see how it should look and work and also see where im going wrong.

many thanks in advance for helping.
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: Sat Jul 24, 2010 9:02 am    Post subject: Reply with quote

You've been using C# for only 3 days and already messing with memory editing?
I suggest you to take it easy and relax if you want to understand every step you take in programming

_________________
Stylo
Back to top
View user's profile Send private message
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Sat Jul 24, 2010 9:09 am    Post subject: Reply with quote

In the same button store the current value so when you write it,
it would be currentVal + memory or currentVal - memory

Would you like another reader thats easier to use?
Your code seems like alot just for one address
From this
Code:
preader.ReadProcess = myprocesses[0];
            preader.OpenProcess();
            int byteswritten;
            float value = 0.5F; 
            byte[] memory;
            memory = BitConverter.GetBytes(value);
            preader.WriteProcessMemory((IntPtr)0x345291FC, memory, out byteswritten);


To this
Code:
Mem.WriteFloat(0x345291FC, 0.5F);

And to subtract 300 from the value it would be
Code:
float Val = Mem.ReadFloat(0x345291FC);
            Mem.WriteFloat(0x345291FC, Val - 0.5F);

Just giz a shout and i'll sort a source out for ya.

_________________
Back to top
View user's profile Send private message
flash harry
Newbie cheater
Reputation: 0

Joined: 19 Jun 2010
Posts: 16

PostPosted: Sat Jul 24, 2010 1:00 pm    Post subject: Reply with quote

Pingo wrote:
In the same button store the current value so when you write it,
it would be currentVal + memory or currentVal - memory

Would you like another reader thats easier to use?
Your code seems like alot just for one address
From this
Code:
preader.ReadProcess = myprocesses[0];
            preader.OpenProcess();
            int byteswritten;
            float value = 0.5F; 
            byte[] memory;
            memory = BitConverter.GetBytes(value);
            preader.WriteProcessMemory((IntPtr)0x345291FC, memory, out byteswritten);


To this
Code:
Mem.WriteFloat(0x345291FC, 0.5F);

And to subtract 300 from the value it would be
Code:
float Val = Mem.ReadFloat(0x345291FC);
            Mem.WriteFloat(0x345291FC, Val - 0.5F);

Just giz a shout and i'll sort a source out for ya.


another reader, wow that looks so much better, that would be great stuff if you could sort out the source, nice one Pingo top job.

@Stylo i have a strange method of learning, i like to throw myself in at the deep end and work backwards, strange i know but it works for me.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Jul 24, 2010 2:50 pm    Post subject: Reply with quote

Pingo wrote:
Code:
float Val = Mem.ReadFloat(0x345291FC);
            Mem.WriteFloat(0x345291FC, Val - 0.5F);

Just giz a shout and i'll sort a source out for ya.


Why don't you just write a generic function instead of having one for each data type?
Back to top
View user's profile Send private message
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Sat Jul 24, 2010 3:17 pm    Post subject: Reply with quote

slovach wrote:
Pingo wrote:
Code:
float Val = Mem.ReadFloat(0x345291FC);
            Mem.WriteFloat(0x345291FC, Val - 0.5F);

Just giz a shout and i'll sort a source out for ya.


Why don't you just write a generic function instead of having one for each data type?

because im stupid and lazy

_________________
Back to top
View user's profile Send private message
flash harry
Newbie cheater
Reputation: 0

Joined: 19 Jun 2010
Posts: 16

PostPosted: Sun Jul 25, 2010 6:31 am    Post subject: Reply with quote

Still struggling with this add/sub stuff so i decided to leave it for the moment and move onto somthing else....... hotkeys Smile

trainer is starting to look great with some nice cheats etc... but they all are activated with buttons (so i cant run the game fullscreen).

is there an easy way to bind hotkeys to these buttons? i would like to use the F1-F2-F3 keys etc... to activate and deactivate cheats.

ive googled loads and am now suffering from a severe case of information overload.

what would be the simplest way to add hotkeys to my already existing buttons?

F1=button1 etc...
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Jul 25, 2010 10:38 am    Post subject: Reply with quote

Stylo wrote:
You've been using C# for only 3 days and already messing with memory editing?
I suggest you to take it easy and relax if you want to understand every step you take in programming


I would agree with Stylo, if you just started C#, you should really slow down and actually start learning the language itself and not just copy paste things from other people and assume you know how it works.

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

Joined: 12 Jul 2007
Posts: 571

PostPosted: Sun Jul 25, 2010 11:34 am    Post subject: Reply with quote

flash harry wrote:
Still struggling with this add/sub stuff so i decided to leave it for the moment and move onto somthing else....... hotkeys Smile

trainer is starting to look great with some nice cheats etc... but they all are activated with buttons (so i cant run the game fullscreen).

is there an easy way to bind hotkeys to these buttons? i would like to use the F1-F2-F3 keys etc... to activate and deactivate cheats.

ive googled loads and am now suffering from a severe case of information overload.

what would be the simplest way to add hotkeys to my already existing buttons?

F1=button1 etc...

I PMed you that source yesterday. It has a add/sub and hotkey example.

_________________
Back to top
View user's profile Send private message
flash harry
Newbie cheater
Reputation: 0

Joined: 19 Jun 2010
Posts: 16

PostPosted: Mon Jul 26, 2010 4:38 am    Post subject: Reply with quote

Thanks Pingo looks great but im getting error when trying to compile

Code:
Warning   1   Referenced assembly 'obj\Release\Blank App.exe' targets a different processor than the application.   Blank App


Any ideas?


*EDIT* Nvm i have it all working perfectly now,

thank you so much Pingo 10/10

without being too much of a pain in the arse i have 1 more question for you.

how to freeze the value at an address?

i did try to PM you but it said im not worthy enough to use the PM system yet ROFL
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Jul 27, 2010 4:24 am    Post subject: Reply with quote

flash harry wrote:
how to freeze the value at an address?
Poor man's way: constantly write the value to the address (this is what CE does when you tick "freeze"). You could also block the writing operation. That would do better job.
Back to top
View user's profile Send private message
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Tue Jul 27, 2010 6:59 am    Post subject: Reply with quote

PMed my email. I'll show ya some basic stuff.
_________________
Back to top
View user's profile Send private message
flash harry
Newbie cheater
Reputation: 0

Joined: 19 Jun 2010
Posts: 16

PostPosted: Thu Aug 12, 2010 3:47 pm    Post subject: Reply with quote

Pingo wrote:
PMed my email. I'll show ya some basic stuff.


Thx pingo ive sent you an email

very sorry if im a pain in the arse Very Happy
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 1, 2  Next
Page 1 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