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#] Getting values from memory and small questions

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Undercoversn
How do I cheat?
Reputation: 0

Joined: 09 Aug 2015
Posts: 5

PostPosted: Sun Aug 09, 2015 2:43 am    Post subject: [C#] Getting values from memory and small questions Reply with quote

Hi,

I'm trying to make a special trainer for Dark Souls 1/2 in C#, I've watched some video's and it looks pretty easy. Now I've found a Dark Souls 2 table with some pointers and offsets but I'm wondering what values I should use.

These are the pointers/offsets I'm going to use:
Code:
<CheatEntry>
          <ID>4</ID>
          <Description>"Health"</Description>
          <Color>80000008</Color>
          <VariableType>4 Bytes</VariableType>
          <Address>DarkSoulsII.exe+FB3E3C</Address>
          <Offsets>
            <Offset>FC</Offset>
            <Offset>74</Offset>
          </Offsets>
        </CheatEntry>
        <CheatEntry>
          <ID>7</ID>
          <Description>"Max Health"</Description>
          <Color>80000008</Color>
          <VariableType>4 Bytes</VariableType>
          <Address>DarkSoulsII.exe+FB3E3C</Address>
          <Offsets>
            <Offset>104</Offset>
            <Offset>74</Offset>
          </Offsets>
</CheatEntry>


This is my C# template code (very incomplete):
Code:
        Note: I'll have some other vars (ints) to save the maxhp, currenthp, tofillhp, ...
       
        bool UnlimitedHealth = false;
        string HealthPointer = "004CF220"; //incorrect value
        int[] HealthOffset = { 0x2 }; //incorrect value
        int HealthToFill = <calculated value>;

the following is triggered when the user presses a key or click enable:
        int bytesWritten;
        byte[] valueToWrite = BitConverter.GetBytes(HealthToFill);
        string writtenAddress = myMemory.PointerWrite((IntPtr)pointerAddress, valueToWrite, pointerOffset, out bytesWritten);
        myMemory.CloseHandle();

On button click this gets activated.


To clarify what I want to do with Dark Souls 1/2 is to create a trainer that makes the game easier for the people that just want to enjoy the game, but not unlimited health. What I want to do is take the current health for ex. 7000, detect changes for ex (-1000), devide the change by 2 and add it to the health pool. And set max to 6500 so it doesn't loop. Also when healing (health goes up) i could set an if statement that it doesn't do the calculation/halfing. When dead I'd pause it. I'd make it perfect but I just need a push in the right direction.

I know C# but I never tried memory editing before, is what I'm trying to do possible? How do I get the game values? Thanks!
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 09, 2015 5:40 am    Post subject: Reply with quote

Yes you are entirely able to do what you are asking. Here is some pseudo code to simulate what you are asking:
Code:
int prevHealth = 0;

while (true)
{
    // Read the current health value..
    int currHealth = ReadHealthValue();

    // Set our previous health value if it has not been set yet..
    if (prevHealth == 0)
    {
        prevHealth = currHealth;
        continue;
    }

    // Next check for differences in health..
    if ((currHealth < prevHealth) && (prevHealth - currHealth) >= 1000)
    {
        currHealth /= 2;
        SetHealthValue(prevHealth + currHealth);
    }
}


Granted based on your post it does not sound like you are really familiar with C# or making a trainer with it. I would suggest taking the time to learn the language first so you understand what you are doing and not just copy/pasting a bunch of code from random YouTube videos and not really understanding how to use it.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Undercoversn
How do I cheat?
Reputation: 0

Joined: 09 Aug 2015
Posts: 5

PostPosted: Sun Aug 09, 2015 6:00 am    Post subject: Reply with quote

atom0s wrote:
Yes you are entirely able to do what you are asking. Here is some pseudo code to simulate what you are asking:
Code:
int prevHealth = 0;

while (true)
{
    // Read the current health value..
    int currHealth = ReadHealthValue();

    // Set our previous health value if it has not been set yet..
    if (prevHealth == 0)
    {
        prevHealth = currHealth;
        continue;
    }

    // Next check for differences in health..
    if ((currHealth < prevHealth) && (prevHealth - currHealth) >= 1000)
    {
        currHealth /= 2;
        SetHealthValue(prevHealth + currHealth);
    }
}


Granted based on your post it does not sound like you are really familiar with C# or making a trainer with it. I would suggest taking the time to learn the language first so you understand what you are doing and not just copy/pasting a bunch of code from random YouTube videos and not really understanding how to use it.


Hi, thanks for taking your time to help me out. I'm not that familiar with making trainers or memory editing, I'm currently learning the language at college and indeed my knowledge is limited to what they teach me, but I'm willing to learn more when I have time Smile I should've said understanding of C#.

What about the pointers? I'm a little bit confused as the pointer I have for health adjustment has 2 offsets, do I combine em? I've made a trainer for small games like dlc quest but the pointers i've used never looked like "DarkSoulsII.exe+FB3E3C". That's all I need to know.

Thanks for your assistance! =)
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Aug 09, 2015 8:06 am    Post subject: Reply with quote

Retrieve base address of "DarkSoulsII.exe".
Add 0xFB3E3C to that address.
Read the value at that address.
Add 0xFC to that value.
Use that value as an address.
Read the value at that address.
Add 0x74 to that value.
Use that value as an address.
Read the value at that address.
There is your health.
Back to top
View user's profile Send private message
Undercoversn
How do I cheat?
Reputation: 0

Joined: 09 Aug 2015
Posts: 5

PostPosted: Sun Aug 09, 2015 8:24 am    Post subject: Reply with quote

Zanzer wrote:
Retrieve base address of "DarkSoulsII.exe".
Add 0xFB3E3C to that address.
Read the value at that address.
Add 0xFC to that value.
Use that value as an address.
Read the value at that address.
Add 0x74 to that value.
Use that value as an address.
Read the value at that address.
There is your health.


Thanks! I'll try it when I get home! Problem solved then Smile
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 09, 2015 1:21 pm    Post subject: Reply with quote

Check out the Process class for most of what you will need here:
https://msdn.microsoft.com/en-us/library/system.diagnostics.process%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

This is what you can use to find the running process as well as get its base module handle, and even a handle to use with Read/WriteProcessMemory.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Undercoversn
How do I cheat?
Reputation: 0

Joined: 09 Aug 2015
Posts: 5

PostPosted: Sun Aug 09, 2015 1:24 pm    Post subject: Reply with quote

Ok thanks for the link Smile !!
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sun Aug 09, 2015 1:42 pm    Post subject: Reply with quote

Zanzer wrote:
Retrieve base address of "DarkSoulsII.exe".
Add 0xFB3E3C to that address.
Read the value at that address.
Add 0xFC to that value.
Use that value as an address.
Read the value at that address.
Add 0x74 to that value.
Use that value as an address.
Read the value at that address.
There is your health.


Best turn the offset around (as they are stored the way the pointer window shows them, which is from bottom to top )

Retrieve base address of "DarkSoulsII.exe".
Add 0xFB3E3C to that address.
Read the value at that address.
Add 0x74 to that value.
Use that value as an address.
Read the value at that address.
Add 0xFC to that value.
Use that value as an address.
Read the value at that address.
There is your health.

_________________
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
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Aug 09, 2015 1:52 pm    Post subject: Reply with quote

Woops
Back to top
View user's profile Send private message
Undercoversn
How do I cheat?
Reputation: 0

Joined: 09 Aug 2015
Posts: 5

PostPosted: Sun Aug 09, 2015 2:22 pm    Post subject: Reply with quote

Dark Byte wrote:
Zanzer wrote:
Retrieve base address of "DarkSoulsII.exe".
Add 0xFB3E3C to that address.
Read the value at that address.
Add 0xFC to that value.
Use that value as an address.
Read the value at that address.
Add 0x74 to that value.
Use that value as an address.
Read the value at that address.
There is your health.


Best turn the offset around (as they are stored the way the pointer window shows them, which is from bottom to top )

Retrieve base address of "DarkSoulsII.exe".
Add 0xFB3E3C to that address.
Read the value at that address.
Add 0x74 to that value.
Use that value as an address.
Read the value at that address.
Add 0xFC to that value.
Use that value as an address.
Read the value at that address.
There is your health.


Hi thanks for your correction, I've tried creating the trainer but it's not working out so well so I give up, i might try again later after i've finished my studies (in 1 month). Thanks for all your help, this makes me feel like a total douche Sad after y'all tried to help me. I hope you don't hate me for this.
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 09, 2015 4:54 pm    Post subject: Reply with quote

Undercoversn wrote:

Hi thanks for your correction, I've tried creating the trainer but it's not working out so well so I give up, i might try again later after i've finished my studies (in 1 month). Thanks for all your help, this makes me feel like a total douche Sad after y'all tried to help me. I hope you don't hate me for this.


To be honest, I'm actually happy to read this. Most people that want to jump directly into game hacking without understanding things usually stay and continue to beg and never learn anything. Then once they do figure out how to copy paste enough stuff together to get something working, they gloat about it and how they are amazing programmers and never credit the work they copied from others.

So to hear you plan to take a step back and study first then take another shot at it is a nice change of how things normally are here.

_________________
- 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
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