[QUESTION] C++ GettingInstanceMap?

06/02/2021 13:42 senpaiex#1
Hello everyone,
Im trying to get near vids from instance map. But maybe im using/calling something wrong. Im not sure. This is my code;

Code:
typedef std::map<DWORD, DWORD*>	TCharacterInstanceMap;

typedef DWORD* (__thiscall* tCPythonCharacterManagerGetInstancePtr)(void* This, DWORD VirtualID);
static tCPythonCharacterManagerGetInstancePtr CPythonCharacterManagerGetInstancePtr;

static DWORD pCPythonCharacterManagerGetInstancePtr;

static DWORD iCPythonCharacterManagerInstance;
static DWORD pCPythonCharacterManagerInstance;

pCPythonCharacterManagerInstance = globals::hEntryBaseAddress + globals::CPChrMgrIns;
iCPythonCharacterManagerInstance = *reinterpret_cast<DWORD*>(pCPythonCharacterManagerInstance);

pCPythonCharacterManagerGetInstancePtr = globals::hEntryBaseAddress + globals::CPChrMgrIns_Addr
CPythonCharacterManagerGetInstancePtr = (tCPythonCharacterManagerGetInstancePtr)(pCPythonCharacterManagerGetInstancePtr);

static DWORD* CharacterManagerGetInstancePtr(int vid)
{
    try
    {
        return CPythonCharacterManagerGetInstancePtr((void*)(iCPythonCharacterManagerInstance + 4), vid);
    }
    catch (...)
    {
        return NULL;
    }
}


int GetNearInstanceListSizeTest() {
    TCharacterInstanceMap m_kAliveInstMap;
    m_kAliveInstMap = *(TCharacterInstanceMap*)(*reinterpret_cast<DWORD*>(*reinterpret_cast<DWORD*>(iCPythonCharacterManagerInstance + 32) + 4));
    //int myVID = PlayerGetMainCharacterIndex();
    return m_kAliveInstMap.size();
}
This line giving crash;

Code:
m_kAliveInstMap = *(TCharacterInstanceMap*)(*reinterpret_cast<DWORD*>(*reinterpret_cast<DWORD*>(iCPythonCharacterManagerInstance + 32) + 4));
What you think, whats wrong with this? Thanks everyone..
06/02/2021 19:39 MrCrisp#2
I'm on mobile right now and can not look at the source.
Are you sure the typedef of the instance map is correct? Isn't the second item of the pair a pointer of an instance type or something?

As far as I can remember, you need to have a struct definition of the instances. Otherwise your program will crash.
06/03/2021 00:29 senpaiex#3
Quote:
Originally Posted by MrCrisp View Post
I'm on mobile right now and can not look at the source.
Are you sure the typedef of the instance map is correct? Isn't the second item of the pair a pointer of an instance type or something?

As far as I can remember, you need to have a struct definition of the instances. Otherwise your program will crash.
Isn't it already DWORD* is a pointer? Yeah probably i need to define struct but idk how it should be. Im looking for it but i couldnt find anything yet. Im stuck :(
06/03/2021 15:47 nogamaS#4
On which server do you want to use it?

for example: If the client binary is compiled with vs2008 (vc90) the std::map of vs2019 (vc142) is incompatible and leads to crashes.

for official servers (vc90) this should help:
€: cant post link, google "BF2 STD library (VS 2005, 08 & 10)"
06/03/2021 23:58 senpaiex#5
Quote:
Originally Posted by nogamaS View Post
On which server do you want to use it?

for example: If the client binary is compiled with vs2008 (vc90) the std::map of vs2019 (vc142) is incompatible and leads to crashes.

for official servers (vc90) this should help:
€: cant post link, google "BF2 STD library (VS 2005, 08 & 10)"
Yes official servers. Im using vs19 (vc142). Maybe u re right. Thank you my friend i'll search about this.
06/04/2021 03:10 MrCrisp#6
Quote:
Originally Posted by nogamaS View Post
On which server do you want to use it?

for example: If the client binary is compiled with vs2008 (vc90) the std::map of vs2019 (vc142) is incompatible and leads to crashes.

for official servers (vc90) this should help:
€: cant post link, google "BF2 STD library (VS 2005, 08 & 10)"
Unlikely. They should be backwards compatible.
@[Only registered and activated users can see links. Click Here To Register...]
Is your offset correct? Did you found it with ReClass?
06/04/2021 15:10 nogamaS#7
Quote:
Originally Posted by MrCrisp View Post
Unlikely. They should be backwards compatible.
@[Only registered and activated users can see links. Click Here To Register...]
Is your offset correct? Did you found it with ReClass?
Well, I had crashes with vc142's std::map and official servers binary. Solved it by using the posted STD classes
06/05/2021 04:05 MrCrisp#8
Quote:
Originally Posted by nogamaS View Post
Well, I had crashes with vc142's std::map and official servers binary. Solved it by using the posted STD classes
Oh, nice! Glad it actually did work :)
06/06/2021 11:01 senpaiex#9
Thanks everyone, specially @[Only registered and activated users can see links. Click Here To Register...] for helping me. He is very nice person :)