c# programming to read game data?

akloaklo

Supremacy Member
Joined
Nov 15, 2004
Messages
7,252
Reaction score
19
hi guys, I want to know what level of programming do I need to be able to code a program that reads data from a game ?

You can refer to the following link which is a code for a game reading the experience data.

Here are just some of the codes inside.
I'm guessing this is the pointer and the address?

IntPtr currentAddress = new IntPtr(0x01489F10);
How did the programmer know to use 0x01489F10 ??

What about this line:
var offsetList = new int[] { 0x10C };
What in the actual fug is 0x10C?

I do some programming like CRUD datafrom database, writing data using c# to excel but this type of programming confuse the hell out of me.

What areas do I need to read to learn all these?
Are these advance or basic stuff? Will a NUS/NTU graduate be able to code this program easily? Am I missing out on many common IT programming knowledge?

Just curious.

private IntPtr getCurrentBaseExperience(Process process)
{
var offsetList = new int[] { 0x10C };
var buffer = new byte[4];
var lpOutStorage = 0;
IntPtr currentAddress = new IntPtr(0x01489F10);

ReadProcessMemory(process.Handle, currentAddress, buffer, buffer.Length, out lpOutStorage);

https://bitbucket.org/Excrulon/tree-of-savior-experience-viewer/src/679452302a3d97c4dab0205652ef707b2ad16204/WindowsFormsApplication1/ExperienceViewerForm.cs?at=master&fileviewer=file-view-default
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,391
Reaction score
1,180
hi guys, I want to know what level of programming do I need to be able to code a program that reads data from a game ?

You can refer to the following link which is a code for a game reading the experience data.

Here are just some of the codes inside.
I'm guessing this is the pointer and the address?

IntPtr currentAddress = new IntPtr(0x01489F10);
How did the programmer know to use 0x01489F10 ??

What about this line:
var offsetList = new int[] { 0x10C };
What in the actual fug is 0x10C?

I do some programming like CRUD datafrom database, writing data using c# to excel but this type of programming confuse the hell out of me.

What areas do I need to read to learn all these?
Are these advance or basic stuff? Will a NUS/NTU graduate be able to code this program easily? Am I missing out on many common IT programming knowledge?

Just curious.

private IntPtr getCurrentBaseExperience(Process process)
{
var offsetList = new int[] { 0x10C };
var buffer = new byte[4];
var lpOutStorage = 0;
IntPtr currentAddress = new IntPtr(0x01489F10);

ReadProcessMemory(process.Handle, currentAddress, buffer, buffer.Length, out lpOutStorage);

https://bitbucket.org/Excrulon/tree-of-savior-experience-viewer/src/679452302a3d97c4dab0205652ef707b2ad16204/WindowsFormsApplication1/ExperienceViewerForm.cs?at=master&fileviewer=file-view-default

The short answer to "Are you missing on many common IT programming knowledge?" NO

The better answer to "Are you missing on many (missing)common(missing) IT programming knowledge?" YES

What you are observing is another process attaching to the one running by the game. That is why you see in the codes having
Code:
Process[] processes = Process.GetProcessesByName("Client_tos");

I'm not well verse with C#, but it's not hard to read what that program you have provided is doing.

Basically it's attaching itself to a process where the game is running and reading certain parts of the memory to get the game running values, namely the "experiences" and also how long more for the game player to reach the next level in the game.

You asked why
Code:
var offsetList = new int[] { 0x10C };

Why not, for example ?
Code:
var offsetList = new int[] { 0x99 };

What you don't observe that how the programer wrote this code is the inspection process of understanding the game software.

There are a few approaches doing this. One is disassemble the certain critical libraries or the programming that this game is running. It could be a Dynamic Linked Library, could be a plain EXEcutable.

Whether is it a game or a business application, the codes are not going to deviated from the architecture and the operating system it is running on. How functions are called, using stacks or registers ? How libraries interfaces are hooked on to ? What are the different segments of a program when loaded into the memory. Code segment, Text segment, Data segment. Understanding how variables in a program are loaded and aligned in the memory, depending on the architecture it is on 32bits, 64bits and more. How are different data types structured in the memory ? With or without padding ? 2's complement forms of an integer ?

All these knowledges allows you to understand how a program runs in a system and which are the variables when you fire up debugger and you can inspect them (provided you have the source code)

Lets assume I have the following program
Code:
$ cat coredump.c
#include <stdio.h>

char str[20] = "HELLO WORLD";

int main(int argc, char** argv) {
  printf("STARTING\n");
  getchar();
  printf("STRING:%s\n",str);
  getchar();
  return 0;
}

A very simple C program, I'm sure you can understand it. I compile it and run through a debugger as such
Code:
$ gcc -g -o coredump coredump.c
$ gdb ./coredump
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./coredump...done.

Now I inspect the variable of "str" and also wanted to know where in the memory it will be loaded.
Code:
(gdb) p str
$1 = "HELLO WORLD\000\000\000\000\000\000\000\000"
(gdb) p &str
$2 = (char (*)[20]) 0x601050 <str>
(gdb)

It tells you that this global variable will exist in the memory when the program is loaded at address 0x601050. Interesting right ?

if I run the program as-is, this will happens
Code:
(gdb) run
Starting program: /home/ubuntu/coredump
STARTING

STRING:HELLO WORLD

[Inferior 1 (process 20938) exited normally]
(gdb)

Since I'm running this program in the debugger, I can change the variable value and run the program and you will find the string printed out is different.

Code:
(gdb) start
Temporary breakpoint 1 at 0x4005cc: file coredump.c, line 6.
Starting program: /home/ubuntu/coredump

Temporary breakpoint 1, main (argc=1, argv=0x7fffffffe538) at coredump.c:6
6	  printf("STARTING\n");
(gdb) set {char [20]}0x601050="HELLO DAVID"
(gdb) continue
Continuing.
STARTING

STRING:HELLO DAVID

[Inferior 1 (process 20952) exited normally]
(gdb)

Did you notice how I change the value of the string using memory address ?
I can also use the debugger and change using variable name as such
Code:
(gdb) start
Temporary breakpoint 1 at 0x4005cc: file coredump.c, line 6.
Starting program: /home/ubuntu/coredump

Temporary breakpoint 1, main (argc=1, argv=0x7fffffffe538) at coredump.c:6
6	  printf("STARTING\n");
(gdb) set variable str = "HELLO PETER"
(gdb) continue
Continuing.
STARTING

STRING:HELLO PETER

[Inferior 1 (process 20965) exited normally]
(gdb)

All these discussion is still at the level where you have the program source code and you are running the program within the debugger. What if you don't have the source code ? Well you can dissemble a program back to somewhat similar to the original and inspect it. You can also perhaps perhaps a core dump of the memory and inspect the contents in the memory can make some guesses and trial and error. I wouldn't go into it. However I will show you how I can attach to a real running coredump program not running within the debugger and still change the variable value.

Starting the program
Code:
$ ./coredump
STARTING

Notice it get stucked at only printing the static "STARTING" string. I am going to start the debugger without loading a file, but rather attach to the running process of the program coredump
Code:
$ pidof coredump
20972
$ sudo gdb
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) attach 20972
Attaching to process 20972
Reading symbols from /home/ubuntu/coredump...done.
Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.19.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.19.so...done.
done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
0x00007f850b785810 in __read_nocancel () at ../sysdeps/unix/syscall-template.S:81
81	../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) set {char [20]}0x601050="HELLO CELINE"
(gdb) detach
Detaching from program: /home/ubuntu/coredump, process 20972
(gdb) quit

The program coredump is still running. I press enter to release the getchar function and it will proceed as such
Code:
$ ./coredump
STARTING

STRING:HELLO CELINE

$

So you see if you have good understanding of how a program runs in the system and also how to get you hands around it. You can just do anything running in the system.

Answering one of your enquiries. How much education in programming do you need to learn all these and do you need to be a University student ? Answer is NO.

You will find no lack of university students that doesn't know all these stuffs and I am daring to say, you will find after 50 years even these university students work until they retire and could be earning 10K per month at high posts and STILL they wouldn't know these stuffs if they don't go and learn them.

Knowledge like these are not common nowadays because the job scope doesn't require them to go down to such low level of debugging. For most programming assignments in the real world situation, they can be easily solved using STDOUT printing. Not kidding you at all, it's somewhat more straight forward and a lot easier to just print to the standard out and inspect using the concept of hypothesis where the problem could exist and test if it is the case.

Going down to debugging level and understanding stack frames, registers, memory segments are much low level techniques which are employed in the past when debugging tools are not as elaborate as today.

That doesn't mean you shouldn't know, just that there is less opportunities for you to learn. But you can observe right now, if you want to "cheat" in a game, this is one possible attempt and you need to understand foundational skills to pull such stunts off.

You can learn complex large systems and that is one direction of learning Computers. There is the micro world that less and less people need to or wanted to touch on, because they don't necessarily brings in money, but these knowledge makes you grow and makes you a much better programmer whom potentially perform better having your mind is trained in different manner.

Watched "The Martian" movie where one of the crew changes the program by patching some binary codes ? The scenario is POSSIBLE, but harder in normal software we see day to day because the code segment is normally protected by the Operating System and not allowed for unprivileged access to modify. But in theory it can be done. I hope you have fun learning new things reading this article.
 
Last edited:

KnightNiwrem

Senior Member
Joined
Jun 1, 2014
Messages
1,056
Reaction score
0
Answering one of your enquiries. How much education in programming do you need to learn all these and do you need to be a University student ? Answer is NO.

You will find no lack of university students that doesn't know all these stuffs and I am daring to say, you will find after 50 years even these university students work until they retire and could be earning 10K per month at high posts and STILL they wouldn't know these stuffs if they don't go and learn them.

Knowledge like these are not common nowadays because the job scope doesn't require them to go down to such low level of debugging. For most programming assignments in the real world situation, they can be easily solved using STDOUT printing. Not kidding you at all, it's somewhat more straight forward and a lot easier to just print to the standard out and inspect using the concept of hypothesis where the problem could exist and test if it is the case.

Going down to debugging level and understanding stack frames, registers, memory segments are much low level techniques which are employed in the past when debugging tools are not as elaborate as today.

Wait. Don't CS students learn about function calls, stack frames, memory pointers, and processes in CS2106?

Also, you mean my use of gdb to debug C programs makes me an abnormal university student? :(
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,391
Reaction score
1,180
Wait. Don't CS students learn about function calls, stack frames, memory pointers, and processes in CS2106?

Also, you mean my use of gdb to debug C programs makes me an abnormal university student? :(

How many uses it all the time, that often to make it the default tool for debugging ? In fact, having bulk of the technologies today are mostly mobile and web, do you foresee the usage of such low level debuggers common grounds among the vast number of software engineers in the industry ?

How many knows function calls to the extend where depending on different ABI, arguments don't necessarily has to be in the stack ? How about extending functions into OOP context, having virtual symbol tables and all these ? The entry point to even get started with all these is often informational in university and hardly practice, unless your job scope are embedded systems, native desktop application software design and so forth.

Using gdb to debug C programs are useful, but a lot of times, we have alternatives to just make debugging simple. Perhaps also moving beyond C, talking about Ruby, Python, Perl, Java or other more complex systems, gdb could be analogous to using a scalpel to slaughter a cow.

A lot of times you don't need to see to know what is going on, just the way I think about it. Computing as an Art.

No it doesn't make you abnormal, it is just you choose to do it this way :) CS2016 merely scratches the surface on these subjects actually.
 

KnightNiwrem

Senior Member
Joined
Jun 1, 2014
Messages
1,056
Reaction score
0
How many uses it all the time, that often to make it the default tool for debugging ? In fact, having bulk of the technologies today are mostly mobile and web, do you foresee the usage of such low level debuggers common grounds among the vast number of software engineers in the industry ?

How many knows function calls to the extend where depending on different ABI, arguments don't necessarily has to be in the stack ? How about extending functions into OOP context, having virtual symbol tables and all these ? The entry point to even get started with all these is often informational in university and hardly practice, unless your job scope are embedded systems, native desktop application software design and so forth.

Using gdb to debug C programs are useful, but a lot of times, we have alternatives to just make debugging simple. Perhaps also moving beyond C, talking about Ruby, Python, Perl, Java or other more complex systems, gdb could be analogous to using a scalpel to slaughter a cow.

A lot of times you don't need to see to know what is going on, just the way I think about it. Computing as an Art.

No it doesn't make you abnormal, it is just you choose to do it this way :) CS2016 merely scratches the surface on these subjects actually.

I mean, even if we don't deal with gdb all the time, I would still expect them to be *able* to use it. Of course, it depends on the use case - like you said, it would be slaughtering a cow with a scapel, otherwise.

Function call with registers and MIPS assembly is seen in CS2100 though. Why should it not be applicable to all CS students?

Virtual symbol table and closure is seen in CS1101S, even if there is no "real" stack or heap in Javascript - it is still a useful tool to see Objects that way.

Being able to write programs without knowing what goes beneath it is a feature of Computing, I agree. It is the power of abstraction.
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,391
Reaction score
1,180
I mean, even if we don't deal with gdb all the time, I would still expect them to be *able* to use it. Of course, it depends on the use case - like you said, it would be slaughtering a cow with a scapel, otherwise.

Function call with registers and MIPS assembly is seen in CS2100 though. Why should it not be applicable to all CS students?

Virtual symbol table and closure is seen in CS1101S, even if there is no "real" stack or heap in Javascript - it is still a useful tool to see Objects that way.

Being able to write programs without knowing what goes beneath it is a feature of Computing, I agree. It is the power of abstraction.

Good point, but let's get back to reality. How many CS students right now knows what I have did and how I have did it? It is just a really simple demonstration.

If you need some numbers, go do a survey among ur CS friends :)

Learning something and practicing something is 2 different things. I don't discourage anyone to know what I knew and how I do things, my real question here is how many and how often
 

KnightNiwrem

Senior Member
Joined
Jun 1, 2014
Messages
1,056
Reaction score
0
Good point, but let's get back to reality. How many CS students right now knows what I have did and how I have did it? It is just a really simple demonstration.

If you need some numbers, go do a survey among ur CS friends :)

Learning something and practicing something is 2 different things. I don't discourage anyone to know what I knew and how I do things, my real question here is how many and how often

Time to fire them. What difference is there from a CS student who don't know anything mentioned here, compared to a code monkey from India? :(
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,391
Reaction score
1,180
You have some say in hiring, right? What do you do? :(

The problem is larger than choosing just good or bad Developers. No firms out there will want a bad developer even if they are cheap.

Good Developers are not easy to come by. If your company only want to take in good Developers, that means your company will never scale.

Yes some company can earn big bucks with very niche skill sets, but it is normally not by choice but by chance. There are a lot more general companies than niche ones, so a successful business concept cannot be based on niche resources.

The key in my opinion is process. Identify which are the good ones and which are the average ones. Give the good ones the nurture and environment to grow, give the average ones processes to conform.

Not everyone can be tech leads, not all wanted to be leaders. For your business to scale, it has to be dependent largely on general resources. Too niche and you have high risks.

That is why frameworks and high level programming languages are attractive. It lowers the playing field, but it create mass competency where you find less differentiator

There was a time I thought training a bunch of good Developers is the way to go. Then as I grow more I see it is a bottleneck for the company. You need core teams that are good, and average Developers for the rest. You need to strive more better quality but not majority through progress, but thru occasional recruitment and chance.
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ. Forum members and moderators are responsible for their own posts.

Please refer to our Community Guidelines and Standards, Terms of Service and Member T&Cs for more information.
Top