Results 1 to 6 of 6
  1. #1
    edi472's Avatar
    Join Date
    Oct 2011
    Gender
    male
    Location
    Brazil
    Posts
    7
    Reputation
    10
    Thanks
    0

    A little doubt about structs with pointers

    Hey,

    I have the pointer to the structure of the player, and tested to access the values ​​I wanted, but I got a problem (in fact I'm not sure if it really is one), which consists of the following: I have, for example, the first element in this structure the player's health, the second to the eleventh unknown values​​, and on the twelfth I have the ammo player's primary weapon.

    My question is: I really need to add "char unknown" until the twelfth, or have some way to "pass" it? Drawing what I said:

    Code:
    // Is possible to do this? If yes, how?
    typedef struct {
    	int HP; // first element
            // second to eleventh are ignored in the struct
    	int SecAmmo; // twelfth
    } Player_Base;
    How I'm having to use (not very good):

    Code:
    typedef struct {
    	int HP;
            char unk2[128]; char unk3[128]; char unk4[128]; char unk5[128]; char unk6[128]; char unk7[128]; char unk8[128]; char unk9[128]; char unk10[128]; char unk11[128];
    	int SecAmmo; // 12
    } Player_Base;
    Thanks in advance.
    Last edited by edi472; 06-01-2013 at 12:46 PM.

  2. #2
    atom0s's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    403
    Reputation
    139
    Thanks
    104
    You need to make sure that your data is properly aligned size wise. Each entry in your structure needs to be properly typed to ensure when you cast from the pointer you are going to get the right alignment back in the structure.

    For example, this is how you can pad between the two for 4 bytes:

    Code:
    typedef struct {
        int HP; // (int = 4 bytes)
        unsigned char[4]; // (unsigned char = 1 byte, so this would total 4 bytes)
        int SecAmmo; // (int = 4 bytes)
    } Player_Base;
    Play with the size of the buffer between each entry that you are marking as unknown to ensure you have the proper distance.
    - Gone; this is another shit forum with children as administrators. Not worth contributing to.

  3. #3
    edi472's Avatar
    Join Date
    Oct 2011
    Gender
    male
    Location
    Brazil
    Posts
    7
    Reputation
    10
    Thanks
    0
    Hey, thanks for helping. I already do it a few minutes after I posted this topic.

    I used this:

    typedef struct {
    int HP[17]; // 1
    int SecAmmo[5]; // 18
    int PriAmmo[1]; // 21
    } Player_Base;
    However, I have another question, can you help me again?

    While I alert (show) HP, PriAmmo and SecAmmo it all works (show me the value of the address that I want), but, only in HP address I can change it. e.g:

    Player->HP[0] = 100; // new HP = 100, ok
    Player->SecAmmo[0] = 50; // not ok, it doesn't change, but MessageBox(... itoa (Player->Sec... )) tell me the right value

    Do you know what can be wrong here? Thanks again.

  4. #4
    Cernunnos's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    38
    Reputation
    10
    Thanks
    4
    Isn't your pointer pointing to a wrong address ? Or another address like an "copy" of the address that you want? Like another address in game to display text? I get an game with 3 address with the same value, one was the real one, the other two was for text or something like this.
    Last edited by Cernunnos; 06-02-2013 at 09:54 AM.

  5. #5
    edi472's Avatar
    Join Date
    Oct 2011
    Gender
    male
    Location
    Brazil
    Posts
    7
    Reputation
    10
    Thanks
    0
    I already solved this, yes, he is appotting to the right address, however, had a protect in this address (i removed and try to changed, it works!).

    Thanks for helping.

  6. #6
    atom0s's Avatar
    Join Date
    May 2013
    Gender
    male
    Posts
    403
    Reputation
    139
    Thanks
    104
    The way you are doing things is not correct for a structure.. You shouldn't be setting things like:
    int HP[17]

    This makes 17 ints related to HP so you could have:
    HP[0], HP[1] .. HP[16]

    From how you are explaining it, there is only the single HP object there so it should just be:
    int HP;

    And thats even assuming you have the size of the variable correct to begin with. After that you should have padding variable there:
    unsigned char Unknown0001[64]; // 4 * 16


    So you should have something like:
    Code:
    typedef struct {
        int HP;
        unsigned char Unknown0001[64];
        int SecAmmo;
        unsigned char Unknown0002[12];
        int PrimeAmmo;
    } Player_Base;
    - Gone; this is another shit forum with children as administrators. Not worth contributing to.

  7. The Following User Says Thank You to atom0s For This Useful Post:

    Cernunnos (06-02-2013)

Similar Threads

  1. Is anime a little shy about drugs?
    By EPDJ in forum Anime
    Replies: 19
    Last Post: 08-02-2017, 07:14 PM
  2. [Help] Doubts about Pointer + Offset / Handle :(
    By smoll25 in forum Visual Basic Programming
    Replies: 0
    Last Post: 07-02-2012, 03:28 PM
  3. [Help Request] little doubt with my PC
    By crappy74 in forum Combat Arms Help
    Replies: 0
    Last Post: 09-05-2011, 01:07 AM
  4. A little help with pointers!
    By GameArena in forum Combat Arms Coding Help & Discussion
    Replies: 3
    Last Post: 04-05-2011, 02:56 PM
  5. What to do with pointers?
    By scooby107 in forum WarRock - International Hacks
    Replies: 9
    Last Post: 04-28-2007, 02:04 PM