player *me needs to hold the player's data. Player's data is taken from a particular address using *(player**). How else you would have player's data in player *me ?
Ok, this is from kibbles aimbot tutorial and i have been building on it. I made an assault cube teleporter, but the only part i don't get is why when i make the class for the player i must do this to access the variables:
Code:// player is the class player *me = *(player**)addie of player struct;
I can understand the player *me part. It's just saying that me is going to be a pointer to the player class. I also understand that *().... is making a void pointer to something. What i don't understand is (player**)addie. I know it's dereferencing it, but why? I don't understand why it is needed to make a void pointer to the struct then dereference it. If anyone can explain this i would really appreciate it. THanks.
player *me needs to hold the player's data. Player's data is taken from a particular address using *(player**). How else you would have player's data in player *me ?
258456 (08-27-2011)
player** <- This is known as pointer-to-pointer. Where two asterisks show that two level of pointers are involved.
Suppose you have two integers i and j. And two pointers x and y, that point to those integers. I can write this:
[highlight=c]int **PointerToPointer;
int i = 5, j = 10;
int *ptint1 = &i;
int *ptint2 = &j;[/highlight]
Then I can assign PointerToPointer, the ptint1 pointer.
[highlight=c]PointerToPointer = &ptint1;[/highlight]
Now PointerToPointer points to ptint1 pointer, which in turn points to i [Value of 5].
Now, if I write this:
[highlight=c]PointerToPointer = &ptint2;[/highlight]
I have changed the pointer pointed by PointerToPointer [Which was pointing at ptint1], to obtain a copy of ptint2, so that ptint1 now points at j [Value of 10] variable.
PointerToPointer now references the pointer ptint1 and ptint1 references the variable i.
So, your code uses two level of pointers to reach to the actual data, that the player class requires and then return the resulting pointer to the calling pointer variable that is; *me.
If you still have confusion, feel free to ask.
258456 (08-27-2011)
so basically it's *(player) to say that i am making a void pointer to player, and then *(player*) means that i am making a void pointer to a player pointer, and then *(player**) means that i made a void pointer to a pointer to a player to another pointer. Lol, this is kind of confusing, but i think i understand it a little bit better.
Yes. I know this is confusing. Here's a very simple example that can help you understand it:
[highlight=c]int **PointerToPointer;
int i = 5, j = 10;
int *ptint1 = &i;
int *ptint2 = &j;
PointerToPointer = &ptint1;
cout << ptint1 << endl;
cout << PointerToPointer << endl;
cout << **PointerToPointer << endl;
_getch();[/highlight]
Here's the output of this:
[highlight=c]0016FCB4 //Address of i variable.
0016FC9C //Address of ptint1 (that points to variable i)
5 //Using pointer to pointer to get the value stored in variable i[/highlight]
Try playing with the above code. It will help you understand it better.
Last edited by Hassan; 08-27-2011 at 07:06 PM.
258456 (08-27-2011)
This:
Is not making a void pointer, rather it's dereferencing a double level pointer (hence the player**), so basically it's gone up one level in the pointer, leaving you with just player*, rather than player**. The way I look at it is that the "pre-parenthesis" asterisks, cancel the asterisks inside the brackets, and if there is the same amount of "pre-parenthesis" asterisks, then you've dereferenced the whole thing.Code:*(player**)
so:
Some more examples of multi-level pointers:Code:*(player**) leaves you with a player* *(player***) leaves you with a player** **(player**) leaves you with a player **(player***) leaves you with a player* just like in this example: int *x = new int; *(int*)x = 15; //the int* cast was completely unnecessary here, but I used it to illustrate that complete deref occurred, and you're assigning the value of 15 to the base level int.
[highlight=C]
int *w = (int*)malloc(sizeof(int)); //sorry, C code. Can use "new int" if you want in C++.
*w = 15; //dereference w and assign the value.
int **x = &w; //second level pointer. pointer-to-pointer
int ***y = &x; //move another level up. p2p2p now.
int *z = **(int***)y; //dereference 2 levels of pointers, now back to p2p.
*z = 20; //final dereference, back to base level. Assign 20.
printf("%d\n", *w); //check whether x changed too after the multi-pointer deref.
[/highlight]
Hope that clarifies some stuff.
Last edited by Jason; 08-27-2011 at 09:44 PM.
You can win the rat race,Originally Posted by Jeremy S. Anderson
But you're still nothing but a fucking RAT.
++Latest Projects++
[Open Source] Injection Library
Simple PE Cipher
FilthyHooker - Simple Hooking Class
CLR Injector - Inject .NET dlls with ease
Simple Injection - An in-depth look
MPGH's .NET SDK
eJect - Simple Injector
Basic PE Explorer (BETA)
258456 (08-27-2011)
/Marked Solved. GJ Jason <3
258456 (08-27-2011)
GJ to you to Hassan. You and Jason are the most helpful people in this forum. I just saw the thread in which Liz was picking the new minion, and I gotta say, that nobody else stood a chance. No matter who posted there it was going to come down to you and Jason. Thanks a bunch guys, I really like what you've done with the C++ forum Hassan cuz now i can actually receive help to my problems and not flame. Congrats and thanks again Hassan and Jason.
Hassan (08-27-2011)
Glad to be of use Started learning C this semester at Uni so I can actually help out with some C/C++ questions now.
You can win the rat race,Originally Posted by Jeremy S. Anderson
But you're still nothing but a fucking RAT.
++Latest Projects++
[Open Source] Injection Library
Simple PE Cipher
FilthyHooker - Simple Hooking Class
CLR Injector - Inject .NET dlls with ease
Simple Injection - An in-depth look
MPGH's .NET SDK
eJect - Simple Injector
Basic PE Explorer (BETA)