Solved What is the practical use of Array's in Game Hacking

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

maxownage01

Jr.Coder
Full Member
Nobleman
Apr 23, 2015
69
493
1
I've just started learning Array's but I can think of a practical use for them. Can someone provide an example where they are used.
Thanks.
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,118
78,998
2,392
On the other hand many people use arrays over vectors, to avoid bloating their application with STL. I prefer the vector only when I have to add and remove objects from a list

Practical use for arrays? Arrays exist because not using arrays is completely IMPRACTICAL! Why would you create player class objects like this:
C++:
playerClass player1;
playerClass player2;
playerClass player3;
playerClass player4;
When you can just do this:
C++:
playerClass players[4];
 

Nazalas

Coder
Dank Tier VIP
Dank Tier Donator
May 20, 2015
99
3,963
3
Arrays are useful anytime that you need to store data in a collection. Most people using c++ will however go with the STL Vector. It is more powerful and more flexible. The most common use that you will find for arrays in game hacking would probably be for char arrays. I have used them to store bytes that I want to write to memory.

For example:
C++:
DWORD AmmoAddy = 0x004637E9;
char  AmmoNewOpCode[] = "\x90\x90";
memcpy((LPVOID)AmmoAddy , AmmoNewOpCode, 2);
This is just a simple example but you probably want to look into Vectors for most things.
 

NTvalk

Hacker
Meme Tier VIP
Jul 6, 2013
499
3,108
8
Rake;40695 said:
On the other hand many people use arrays over vectors, to avoid bloating their application with STL. I prefer the vector only when I have to add and remove objects from a list

Practical use for arrays? Arrays exist because not using arrays is completely IMPRACTICAL! Why would you create player class objects like this:
C++:
playerClass player1;
playerClass player2;
playerClass player3;
playerClass player4;
When you can just do this:
C++:
playerClass players[4];
Why wouldnt u want STL, its good.
 

bitm0de

Newbie
Full Member
Feb 28, 2016
19
358
2
Arrays are useful anytime that you need to store data in a collection. Most people using c++ will however go with the STL Vector. It is more powerful and more flexible. The most common use that you will find for arrays in game hacking would probably be for char arrays. I have used them to store bytes that I want to write to memory.

For example:
C++:
DWORD AmmoAddy = 0x004637E9;
char  AmmoNewOpCode[] = "\x90\x90";
memcpy((LPVOID)AmmoAddy , AmmoNewOpCode, 2);
This is just a simple example but you probably want to look into Vectors for most things.
Arrays like this aren't super useful however. If you want a bunch of named opcodes, that's where an array of character arrays might be a bit more useful. Linked list if you want to avoid the STL or if you're using C, even though you're increasing the number of cache misses, otherwise perhaps an std::unordered_map<OpcodeID, const unsigned char *> for easy key-value-pair access to a constant string literal defining the opcodes within a hashtable. For optimization reasons too, you might as well just define the literal as a const char *, or put the string literal in directly to the function as an argument if you only have a couple locations to use that string.'char AmmoNewOpCode[] ' means that it can be editable, which you probably don't want, 'const' should be used there IMO, but as soon as you use [], it's copied into writable memory too if you care about such small performance issues.

Rake points out the most obvious reason to use arrays, but it's probably the most important one really. In addition to the fact that if you know the size of the collection of data that you need to store, there's hardly any point in using a vector.

NTvalk - And the reason why you wouldn't want to use the STL is because it's bloat for the game hack, and it might even possibly be slower if you have a good method written out using pointers instead of classes, iterators, allocators, etc... This is the reason why things in the STL are sometimes slower than C function equivalents. It takes a few extra CPU cycles to initialize all of those things. It might come in handy with things like vectors and maps, and a few things to do with asynchronous methods because writing stuff like that out on your own can become daunting depending on your desired implementation and functionality, as well as depending on how much scalability you want from your code. Personally, I think there are a few good things from the STL, but as soon as you abuse it and start using templates... Template specialization will destroy you -- things get bloated really fast..
 
Last edited:

maxownage01

Jr.Coder
Full Member
Nobleman
Apr 23, 2015
69
493
1
Arrays like this aren't super useful however. If you want a bunch of named opcodes, that's where an array of character arrays might be a bit more useful. Linked list if you want to avoid the STL or if you're using C, even though you're increasing the number of cache misses, otherwise perhaps an std::unordered_map<OpcodeID, const unsigned char *> for easy key-value-pair access to a constant string literal defining the opcodes within a hashtable. For optimization reasons too, you might as well just define the literal as a const char *, or put the string literal in directly to the function as an argument if you only have a couple locations to use that string.'char AmmoNewOpCode[] ' means that it can be editable, which you probably don't want, 'const' should be used there IMO, but as soon as you use [], it's copied into writable memory too if you care about such small performance issues.

Rake points out the most obvious reason to use arrays, but it's probably the most important one really. In addition to the fact that if you know the size of the collection of data that you need to store, there's hardly any point in using a vector.

NTvalk - And the reason why you wouldn't want to use the STL is because it's bloat for the game hack, and it might even possibly be slower if you have a good method written out using pointers instead of classes, iterators, allocators, etc... This is the reason why things in the STL are sometimes slower than C function equivalents. It takes a few extra CPU cycles to initialize all of those things. It might come in handy with things like vectors and maps, and a few things to do with asynchronous methods because writing stuff like that out on your own can become daunting depending on your desired implementation and functionality, as well as depending on how much scalability you want from your code. Personally, I think there are a few good things from the STL, but as soon as you abuse it and start using templates... Template specialization will destroy you -- things get bloated really fast..
Good point, so if performance is an issue avoid array's if possible?
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,118
78,998
2,392
Good point, so if performance is an issue avoid array's if possible?
For simple everyday stuff use arrays. Someday you will be coding and think to yourself "I wish this array could do this" or "I wish there was an easier way to interact with this array" then you will look at using a "Container" i.e. vector or otherwise. It's a learning experience, go with the flow
 

bitm0de

Newbie
Full Member
Feb 28, 2016
19
358
2
Good point, so if performance is an issue avoid array's if possible?
Not arrays in general no, if you have a collection of numbers, then store it in an array. But if you have strings that you don't need to modify, you can declare them like this:
C++:
const char *str = "String literal";
Rather than:
C++:
const char str[] = "String literal";
Not a significant difference, but the first just means that it isn't copied into memory that you can write to.

If you removed the 'const' qualifier on both versions above, you would not get a segfault when writing to the second, but you would with the first. The second means that data is copied to memory region that you can write to, the first is a pointer to the original read-only memory location where that static string literal is stored. The reason is because string literals have static storage duration -- they aren't meant to be modified.

This is something that will really confuse a lot of beginners too when it comes to strings and modifying them, even more so if const-correctness is not used because the compiler will not warn you about modifying a string like this:
C++:
char *str = "testing";
I believe some will give a friendly warning about declaring a string like that however. Some further information: https://stackoverflow.com/questions/1704407/what-is-the-difference-between-char-s-and-char-s-in-c

Because the stack is used for the second version using [], this means that an additional operation to allocate for space on the stack by adjusting ESP must be done, and this could be avoided by using a pointer to the string literal instead. This is especially useful to understand when you are returning char pointers from functions. with 'char str[] = "..."', str is synonymous for a char pointer type just like 'char *str = "..."' is, but consider that the pointer is a pointer to the stack in the first, and read-only memory that will persist in the second. So...

This is not valid:
C++:
const char *f()
{
  const char str[] = "...";
  return str;
}
Because you'd have a dangling pointer, but this is valid:
C++:
const char *f()
{
  const char *str = "...";
  return str;
}
Because str has static-storage duration rather than automatic storage duration in this example.

Hope this all helps!
 
Last edited:
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods