Results 1 to 2 of 2
  1. #1
    faceofdevil's Avatar
    Join Date
    Jul 2009
    Gender
    female
    Posts
    77
    Reputation
    9
    Thanks
    6

    [help] Adding to a Existing Buffer

    My brain isnt working for some reason and i dont know what is wrong...

    I'm trying to add a header to this buffer once the buffer has been determined.

    EXAMPLE: 00 00 00 00 = 4 bytes wich is the size i would then add +2 to make it 6..

    so the new buffer would be 06 00 00 00 00 00

    Code:
    usigned int Size;
    unsigned char * newbuffer = new unsigned char[ Size + 2 ];
    
    int m = Size + 2;
    
    // copy data from the Buffer to newbuffer  
    memcpy( newbuffer + 2 * sizeof( unsigned char ), Buffer, sizeof( unsigned char ) * Size );
    
    // swap buffers
    delete [] Buffer;
    Buffer = newbuffer;
    Size = m;
    this seems to work but the new buffer just gives junk data in the array..

    like... 45 23 00 00 00 00 = 6 size....

    instead of it being 06 00 00 00 00 00

  2. #2
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Code:
    unsigned int Size;
    unsigned char * newbuffer = new unsigned char[ Size + 2 ];
    Size will be whatever is stored in memory(so random untill you initialize it as something)

    Also, an int is 4 bytes, so if you only want a two byte header use
    Code:
    unsigned short Size = reinterpret_cast<unsigned short>(sizeof(Buffer));
    Now, to allocate memory you could use malloc(size)
    So your code will be something along the lines of this:
    Code:
    char *buffer = malloc(Size+2);
    buffer[0] = Size;
    memcpy(buffer[2], oldBuffer, Size);
    Make sure to initialize Size though(or allocate memory for the new buffer AFTER you used sizeof(oldbuffer)
    Ah we-a blaze the fyah, make it bun dem!

Similar Threads

  1. [SOLVED]adding menus to existing mods
    By Erige in forum Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    Replies: 5
    Last Post: 09-11-2010, 05:10 PM
  2. [HELP] Adding new items in QChaosZombieMod in shop
    By xurple in forum Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    Replies: 4
    Last Post: 09-05-2010, 10:04 AM
  3. [Noob] Help adding no recoil
    By TayxPwnage in forum Combat Arms Hack Coding / Programming / Source Code
    Replies: 7
    Last Post: 08-28-2010, 06:01 AM
  4. [Help] Inserting bunkers too existing maps
    By Erige in forum Call of Duty Modern Warfare 2 Help
    Replies: 15
    Last Post: 08-25-2010, 06:11 PM
  5. SERIOUSLY I NEED UR HELP!!!- added info
    By Tall kiwi in forum Combat Arms Help
    Replies: 8
    Last Post: 09-28-2009, 11:06 PM