Advertisement
Guest User

QTS no. 7 - Dynamic format strings class

a guest
Jul 9th, 2010
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. /*
  2. -----------------------------------------
  3. * Game hacking QTS ( Quickie Tip Series )
  4. * no. 7 - Dynamic format strings class
  5. -----------------------------------------
  6. * Author: SEGnosis  - GHAnon.net
  7. * Thanks to:
  8. * bitterbanana      - No known site
  9. * Drunken Cheetah   - No known site
  10. * fatboy88      - No known site
  11. * Geek4Ever         - No known site
  12. * learn_more        - www.uc-forum.com
  13. * Novocaine         - http://ilsken.net/blog/?page_id=64
  14. * Philly0494        - No known site
  15. * Roverturbo        - www.uc-forum.com
  16. * SilentKarma       - www.halocoders.com - offline
  17. * Strife        - www.uc-forum.com
  18. * Wieter20      - No known site
  19. */
  20.  
  21. //----------------------------------//
  22. class C_Strings
  23. {
  24.     public:
  25.         C_Strings(); // Constructor
  26.         ~C_Strings(); // De-constructor        
  27.        
  28.         char* _sprintf( char* szString, ... ); // Prototype
  29.        
  30.         void AppendSprintfQueue( char* szNewSpace ); // Prototype
  31.         void ClearSprintfQueue( void ); // Prototype
  32.        
  33.     private:
  34.         DWORD* m_pdwSprintfQueue; // Pointer that will hold the address of the area that will hold the addresses of the allocated char strings
  35.         DWORD  m_dwSizeofSprintfQueue; // The number of allocated char strings
  36. }Strings; // Instance
  37. //----------------------------------//
  38.  
  39. //----------------------------------//
  40. C_Strings::C_Strings()
  41. {
  42.     m_pdwSprintfQueue = 0; // Default
  43.     m_dwSizeofSprintfQueue = 0; // Default
  44. }
  45. //----------------------------------//
  46. C_Strings::~C_Strings()
  47. {
  48.  
  49. }
  50. //----------------------------------//
  51.  
  52. //----------------------------------//
  53. char* C_Strings::_sprintf( char* szString, ... )
  54. {
  55.     char* szBuffer = new char[ 1024 ]; // Allocate a new char array of 1mb ( 1024 bytes )
  56.     AppendSprintfQueue( szBuffer ); // Store the address of the string in the queue
  57.    
  58.     va_list va_alist; // Make a new char*
  59.     va_start( va_alist, szString );
  60.     vsprintf( szBuffer, szString, va_alist); // Place string with parameters embedded into szBuffer
  61.     va_end  ( va_alist );
  62.    
  63.     return szBuffer; // return char string
  64. }
  65. //----------------------------------//
  66. void C_Strings::AppendSprintfQueue( char* szNewSpace )
  67. {
  68.     DWORD* pdwTemp = new DWORD[ ++m_dwSizeofSprintfQueue ]; // Create a new dword pointer of the m_dwSizeofSprintfQueue += 1
  69.    
  70.     if( m_pdwSprintfQueue ) // If m_pdwSprintfQueue has more than one index
  71.     {
  72.         memcpy( pdwTemp, m_pdwSprintfQueue, m_dwSizeofSprintfQueue * sizeof( DWORD ) ); // Save all the data from m_pdwSprintfQueue into pdwTemp
  73.         delete[] m_pdwSprintfQueue; // Free the data/memory in m_pdwSprintfQueue
  74.     }
  75.    
  76.     pdwTemp[ m_dwSizeofSprintfQueue - 1 ] = ( DWORD )szNewSpace; // Inside the last index, save the address of the new string
  77.  
  78.     m_pdwSprintfQueue = pdwTemp; // Give the pointer to m_pdwSprintfQueue
  79. }
  80. //----------------------------------//
  81. void C_Strings::ClearSprintfQueue( void )
  82. {
  83.     for( int i = 0; i < m_dwSizeofSprintfQueue; i++ )// Go through all the indexes of m_pdwSprintfQueue
  84.     {
  85.         char* pDel = ( char* )m_pdwSprintfQueue[ i ]; // Make a pointer that refrences the string
  86.        
  87.         delete[] pDel; // Free the memory in that pointer
  88.     }
  89.    
  90.     delete[] m_pdwSprintfQueue;  // Clear the queue of addresses
  91.     m_pdwSprintfQueue       = 0; // Default
  92.     m_dwSizeofSprintfQueue  = 0; // Default
  93. }
  94. //----------------------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement