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 Previous  1, 2
 
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: Sun Aug 15, 2010 6:44 am    Post subject: Reply with quote

Pingo or anyone plz help

i can read/write to static address like this:

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


but what about read/write to a pointer + offsets?

now i have "0x344107DC" and the offset is "18" but i dont know how to write it.

before when i was using "ProcessMemoryReaderLib" i would just write it like this:

Code:

preader.ReadProcess = myprocess[0];
            preader.OpenProcess();
           
            int byteswritten;
            int bytesread;
            int value;
            int pointerbase;
            byte[] memory;
           
            memory = preader.ReadProcessMemory((IntPtr)0x344107DC, 4, out bytesread);
            pointerbase = BitConverter.ToInt32(memory, 0);
            pointerbase += 0x18;
            value = 99;
            memory = BitConverter.GetBytes(value);
            preader.WriteProcessMemory((IntPtr)pointerbase, memory, out byteswritten);


but now using this new reader "CSharpProcessMemory" im stuck on how to write to a pointer + offsets.

im totally baffled now ive tried all sorts of combos but to no avail

a quick google for "CSharpProcessMemory" got this
pastebin . com/hyXMyUzz

which seems to be what i am using

any help is very much appreicated
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Sun Aug 15, 2010 8:03 am    Post subject: Reply with quote

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


Write a dll use C# ability to use extern.

In your dll

Code:

_asm {
     push esi
     pushad
     pushaf
     mov esi, address
     sub esi, 0x0000012C
     mov  [register+offset], esi
     popad
     popaf
     pop esi
}


I think will do what you want. My asm skills suck.

Where register is the location that your address is pointed from offset if there is an offset to that location from calling function. 0x0000012C is of course 300 in hex, which is what you need to set that address to.

codeproject(dor)com/KB/cs/unmanage(dot)aspx

Gives and example and source code for using C# to process asm from a dll.

I suggest you read Geri's post about asm.

forum.cheatengine(dot)org/viewtopic(dot)php?t=515593

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
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 Aug 15, 2010 10:27 am    Post subject: Reply with quote

flash harry wrote:
Pingo or anyone plz help

i can read/write to static address like this:

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


but what about read/write to a pointer + offsets?

now i have "0x344107DC" and the offset is "18" but i dont know how to write it.


Read the value of the pointer first then add your offset to it and read the needed data then.

flash harry wrote:
before when i was using "ProcessMemoryReaderLib" i would just write it like this:

Code:

preader.ReadProcess = myprocess[0];
            preader.OpenProcess();
           
            int byteswritten;
            int bytesread;
            int value;
            int pointerbase;
            byte[] memory;
           
            memory = preader.ReadProcessMemory((IntPtr)0x344107DC, 4, out bytesread);
            pointerbase = BitConverter.ToInt32(memory, 0);
            pointerbase += 0x18;
            value = 99;
            memory = BitConverter.GetBytes(value);
            preader.WriteProcessMemory((IntPtr)pointerbase, memory, out byteswritten);


but now using this new reader "CSharpProcessMemory" im stuck on how to write to a pointer + offsets.

im totally baffled now ive tried all sorts of combos but to no avail

a quick google for "CSharpProcessMemory" got this
pastebin . com/hyXMyUzz

which seems to be what i am using

any help is very much appreicated


Looking that the class you are using, firstly I would suggest writing your own as the way that one is setup is not needed in .NET and can be done with few functions.

But if you plan to keep using it you could do something like this:

Code:
ProcessMemory mem = new ProcessMemory("proc_name.exe");
uint uiPtr = mem.ReadUInt(0x344107DC);
uiPtr += 0x80;
uint uiVal = mem.ReadUInt(Convert.ToInt32(uiPtr));

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
flash harry
Newbie cheater
Reputation: 0

Joined: 19 Jun 2010
Posts: 16

PostPosted: Mon Aug 16, 2010 10:13 am    Post subject: Reply with quote

Thanks Wiccaan,

so if this is to read the pointer:
Quote:
ProcessMemory mem = new ProcessMemory("proc_name.exe");
uint uiPtr = mem.ReadUInt(0x344107DC);
uiPtr += 0x80;
uint uiVal = mem.ReadUInt(Convert.ToInt32(uiPtr));


how would i write a new value to that pointer?
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: Mon Aug 16, 2010 10:40 am    Post subject: Reply with quote

Using that class: (UInt value as example.)

Code:

// Obtain pointer value.
ProcessMemory mem = new ProcessMemory("proc_name.exe");
uint uiPtr = mem.ReadUInt(0x344107DC);
uiPtr += 0x80;
uint uiVal = mem.ReadUInt(Convert.ToInt32(uiPtr));

// Adjust and rewrite value.
uiVal -= 0x100;
mem.WriteUInt( uiPtr, uiVal );

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
flash harry
Newbie cheater
Reputation: 0

Joined: 19 Jun 2010
Posts: 16

PostPosted: Tue Aug 17, 2010 9:06 am    Post subject: Reply with quote

Wiccaan wrote:
Using that class: (UInt value as example.)

Code:

// Obtain pointer value.
ProcessMemory mem = new ProcessMemory("proc_name.exe");
uint uiPtr = mem.ReadUInt(0x344107DC);
uiPtr += 0x80;
uint uiVal = mem.ReadUInt(Convert.ToInt32(uiPtr));

// Adjust and rewrite value.
uiVal -= 0x100;
mem.WriteUInt( uiPtr, uiVal );


i gave this a try but im getting 2 error's

1. (The best overloaded method match for 'CSharpProcessMemory.ProcessMemory.WriteUInt(int, uint)' has some invalid arguments)

2. (Argument 1: cannot convert from 'uint' to 'int')

Sorry for being a pain but could you provide a "Float" example please if its not to much trouble.

Thanks in advance.
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: Tue Aug 17, 2010 9:48 am    Post subject: Reply with quote

Code:
// Obtain pointer.
ProcessMemory mem = new ProcessMemory("proc_name.exe");
uint uiPtr = mem.ReadUInt(0x344107DC);
uiPtr += 0x80;

// Obtain value.
float fValue = ReadFloat(Convert.ToInt32(uiPtr));
fValue -= 100.0f; // subtract 100

// Write new value back.
WriteFloat(Convert.ToInt32(uiPtr), fValue);


Should work, could be off though since I don't do things like this.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
flash harry
Newbie cheater
Reputation: 0

Joined: 19 Jun 2010
Posts: 16

PostPosted: Tue Aug 17, 2010 2:58 pm    Post subject: Reply with quote

Wiccaan wrote:
Code:
// Obtain pointer.
ProcessMemory mem = new ProcessMemory("proc_name.exe");
uint uiPtr = mem.ReadUInt(0x344107DC);
uiPtr += 0x80;

// Obtain value.
float fValue = ReadFloat(Convert.ToInt32(uiPtr));
fValue -= 100.0f; // subtract 100

// Write new value back.
WriteFloat(Convert.ToInt32(uiPtr), fValue);


Should work, could be off though since I don't do things like this.


Thanks very much its all working now


Using this:
Code:

            ProcessMemory mem = new ProcessMemory("Process Name");
            uint uiPtr = Mem.ReadUInt(0x344107E0);
            uiPtr += 0x5C;
            float Val = Mem.ReadFloat(Convert.ToInt32(uiPtr));
            Val = 60000;
            Mem.WriteFloat(Convert.ToInt32(uiPtr), Val);



Big thanks to Pingo and Wiccaan for helping me on this
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 19, 2010 1:58 pm    Post subject: Reply with quote

Having probs with hotkeys for pointers now Sad

My hotkey for static address like this:
Code:

            float Val = Mem.ReadFloat(0x345291FC);
            if (Mem.Keystate(Keys.F1))
            Mem.WriteFloat(0x345291FC, Val = -5F);


but i cant do the same with pointer Confused

i need to make this:
Code:

            if (Mem.Keystate(Keys.F6))

work with this:
Code:

            ProcessMemory mem = new ProcessMemory("Process Name");
            uint uiPtr = Mem.ReadUInt(0x344107E0);
            uiPtr += 0x5C;
            float Val = Mem.ReadFloat(Convert.ToInt32(uiPtr));
            Val = 60000;
            Mem.WriteFloat(Convert.ToInt32(uiPtr), Val);


i was hoping to just do this:
Code:

            if (Mem.Keystate(Keys.F6))
            ProcessMemory mem = new ProcessMemory("Process Name");
            uint uiPtr = Mem.ReadUInt(0x344107E0);
            uiPtr += 0x5C;
            float Val = Mem.ReadFloat(Convert.ToInt32(uiPtr));
            Val = 60000;
            Mem.WriteFloat(Convert.ToInt32(uiPtr), Val);


but im getting 2 errors:

1. A local variable named 'Val' is already defined in this scope.

2. Embedded statement cannot be a declaration or labeled statement.


so the problem i have now is i can use hotkeys on static address but not on pointers Confused

Any help is much appriciated.

--------------------------------------------------------------------

*EDIT* Nevermind i fixed it.... i forgot the brackets doh Very Happy

Code:

            if (Mem.Keystate(Keys.F6))
            {
                ProcessMemory mem = new ProcessMemory("Process Name");
                uint uiPtr = Mem.ReadUInt(0x344107E0);
                uiPtr += 0x5C;
                Mem.ReadFloat(Convert.ToInt32(uiPtr));
                Val = 60000;
                Mem.WriteFloat(Convert.ToInt32(uiPtr), Val);

            }


Silly me Very Happy
Back to top
View user's profile Send private message
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Tue Aug 24, 2010 2:20 am    Post subject: Reply with quote

[quote="flash harry"]Thanks Wiccaan,

so if this is to read the pointer:
Quote:
ProcessMemory mem = new ProcessMemory("proc_name.exe");
uint uiPtr = mem.ReadUInt(0x344107DC);
uiPtr += 0x80;
uint uiVal = mem.ReadUInt(Convert.ToInt32(uiPtr));


app reads the .exe/.dll module for pointers
say the game module is 400000
344107DC - 400000 = 340107DC
read/write pointers
Mem.ReadUInt(Mem.Pointer(true, 0x340107DC, 0x18));
Mem.WriteUInt(Mem.Pointer(true, 0x340107DC, 0x18), Value);// change Value for the actual value you wanna write.

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

Joined: 19 Jun 2010
Posts: 16

PostPosted: Tue Aug 24, 2010 3:07 pm    Post subject: Reply with quote

Thanks pingo thats easier,

ive also got another prob tho m8, i done a toggle on/off with hotkey and the first one worked fine but if i add another it wont work Sad

i know it is to do with the Mybool thing but im unsure as what to do with it, i know i need to change Mybool[0] to Mybool[1] but im not having any joy, ive tried allsorts but none seem to work so i must be doing it wrong.

big thanks for your help and time m8.
Back to top
View user's profile Send private message
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Thu Aug 26, 2010 5:04 pm    Post subject: Reply with quote

I pmed you the source again. It'l show 3 examples using 3 different bools.
_________________
Back to top
View user's profile Send private message
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Fri Aug 27, 2010 6:17 am    Post subject: Reply with quote

Sorry dude you'l need to redownload it again. It had an error Embarassed
Just use the same link

_________________
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: Fri Aug 27, 2010 5:17 pm    Post subject: Reply with quote

[quote="Pingo"]
flash harry wrote:
Thanks Wiccaan,

so if this is to read the pointer:
Quote:
ProcessMemory mem = new ProcessMemory("proc_name.exe");
uint uiPtr = mem.ReadUInt(0x344107DC);
uiPtr += 0x80;
uint uiVal = mem.ReadUInt(Convert.ToInt32(uiPtr));


app reads the .exe/.dll module for pointers
say the game module is 400000
344107DC - 400000 = 340107DC
read/write pointers
Mem.ReadUInt(Mem.Pointer(true, 0x340107DC, 0x18));
Mem.WriteUInt(Mem.Pointer(true, 0x340107DC, 0x18), Value);// change Value for the actual value you wanna write.


You should avoid embedding calls like this unless your functions specifically look for erroneous returns or you will get exceptions and issues, not to mention possible invalid reads/writes to locations of memory.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
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