Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


String manipulation c++

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Sat Aug 01, 2009 9:34 am    Post subject: String manipulation c++ Reply with quote

Hello.

i need to generate an array that looks like this:

Code:

005EF568  B0 9C 5A 00 FF FF FF 7F  °œZ.ÿÿÿ
005EF570  0D 00 00 00 4D 00 6F 00  ....M.o.
005EF578  72 00 65 00 20 00 53 00  r.e. .S.
005EF580  65 00 74 00 74 00 69 00  e.t.t.i.
005EF588  6E 00 67 00 73           n.g.s



the B0 9C 5A 00 FF FF FF 7F 0D 00 00 00 are always there.

0D resembles the length of the string "More Settings" and is variable.
This array needs to be made at runtime because i want to insert my own string instead of "More Settings" and the array size and the 9th byte depend on the size of that string.
Moreover, the string needs to be stored as an unicode string as you can see.

Can anyone help me out?


FYI:
The game that i play uses this kind of string storage, and then calls the address of the array to draw it.

a bit like this:

int __cdecl drawText_t(int address, float x, float y)
{
}
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Aug 01, 2009 12:42 pm    Post subject: Reply with quote

Hex edit the address or hook the function and filter for that specific address then replace the address with yours.
_________________
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Sun Aug 02, 2009 12:28 am    Post subject: Reply with quote

C++ you want, C++ you shall have. I'd done this with some lower level stuff, like C.

Code:
#include <iostream>
#include <string>
#include <sstream>

namespace GameX
{
   class String
   {
   private:
      static const unsigned char m_header[8];
      std::string m_str;

   public:
      String(std::wstring ws)
      { this->Assign( ws ); }
      String(const String &s)
      { this->m_str = s.m_str; }

      /* Note, Data() will leave 0x00 0x00 in the end,
       * but shouldn't matter, it just requires a little more space,
       * but I'm being lazy.
       */
      void* Data()
      { return (void*)this->m_str.c_str(); }

      String& Assign(std::wstring ws);

      String& operator=(std::wstring ws)
      { return this->Assign(ws); }
   };

   const unsigned char String::m_header[8] = { 0xB0, 0x9C, 0x5A, 0x00, 0xFF, 0xFF, 0xFF, 0x7F };

   String& String::Assign(std::wstring ws)
   {
      int i = ws.length();
      this->m_str.assign( (const char*)this->m_header, sizeof( this->m_header ) );
      this->m_str.append( (const char*)&i, sizeof(int) );
      this->m_str.append( (const char*)ws.c_str(), i*sizeof(wchar_t) );

      return *this;
   }

} // namespace GameX

int main(int argc, char *argv[])
{
   GameX::String str( L"More Settings" );
   std::cout << std::hex << str.Data() << std::endl;
   str.Assign( L"Even More Settings" );
   std::cout << std::hex << str.Data() << std::endl;
   str = L"All the Setting";
   std::cout << std::hex << str.Data() << std::endl;
   GameX::String str2( str );
   std::cout << std::hex << str2.Data() << std::endl;

   return EXIT_SUCCESS;
}
If it's worth doing, it's worth over doing!
Back to top
View user's profile Send private message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Sun Aug 02, 2009 9:20 am    Post subject: Reply with quote

Thanks! this is exactly what i wanted. I will love you forever Razz
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites