Search data type

10/26/2012 15:22 RunzelEier#1
hi,

im looking for a data type.
this might sound a bit strange, so i will try to explain it to you.

i want to write a dll for a game, which reads some memoryvalues.
but strings are stored in a very weird way.

if the length of the string is smaller than 7 the string is directly stored in the object. But if the length of the string is bigger than 6 it is stored as a pointer to the string.

so here is what i do:
i wrote my own class which trys to recreate this behavior: cMyString
it looks like this:
cMyString.h
PHP Code:
#ifndef CMYCLASS_H
#define CMYCLASS_H
    
class cMyString
    
{
    public:
        
std::wstring getText();
    private:
        
std::wstring text;
        
DWORD nothing[3];//to get the right offset for len
        
int len;
    };
#endif 
cMyString.cpp
PHP Code:
#include "stdafx.h"
#include "cMyString.h"

std::wstring cMyString::getText()
{
    if(
len 7)
    {
        return 
text//i would need to dereference this and make it into a wstring
    
}else{
        return 
text;//only this works
    
}

How i use it:
e.g. to get the name of the mob: i search the mob's address in memory, cast it to my mob class, and then i add a offset to get to its name and cast this to a cMyString* and try to get the text
PHP Code:
std::wstring cEntity::getName()
{
    return ((
cMyString*)(this+NameOffset))->getText();

But i have no clue how i should make the string smaller than 7 Character work.

So my question is, how could i make it work
or even better
is there already a data type which beheaves like that, because i can hardly believe the game developers made up such a weird data type
10/26/2012 17:29 Nightblizard#2
That's some pretty strange behaviour, are you sure about that?

Anyway, let me think about it.
The first thing I noticed is, that you're using std::wstring inside your class. I'm not sure how you're using it to interoperate with the game, but sizeof(std::wstring) != sizeof(wchar_t*). If the games class stores a pointer to an array of wchars, it will not work.
Furthermore, where in the games class is the pointer stored and where are the 6 characters? This is important to mention, because we don't know anything about said class. And if the code is just 1 byte off, it won't work.

From what I gathered it might be something like this:

Code:
class WeirdAssString
{
private:
	wchar_t* mTextPointer;
	wchar_t mText[6];
	BYTE mUnk[22];
	int mLength;
};
But again, you didn't provide enough information, so we can't help you.
10/26/2012 21:47 RunzelEier#3
solved the problem by using wchar_t*

PHP Code:
wchar_tcMyString::getText()
{
    if(
len 7)
    {
        return (
wchar_t*)&text;
    } else {
        return 
text;
    }