[C++] Zrozumienie "nietypowego" zapisu klasy 1121 4

O temacie

Autor Siemekk

Zaczęty 8.01.2017 roku

Wyświetleń 1121

Odpowiedzi 4

Siemekk

Siemekk

Złote Wrota
Untersturmfuhrer
posty2143
Propsy1151
ProfesjaProgramista
  • Złote Wrota
  • Untersturmfuhrer
Cześć. Od paru dni piszę sobie w C++ własny plugin. Mam mały problem ze zrozumieniem pewnej rzeczy... Mianowicie mam klasę:
#include "_ASTHookData.h"

#define _ON TRUE
#define _OFF FALSE

template <class T>
class CInvoke
{
CHookData m_data;

public:

CInvoke(int, PFUNC = NULL, BOOL = _ON); // Create hook-info

operator T(); // Return detour pointer to func
};

template <class T>
CInvoke<T>::CInvoke(int addr, PFUNC detour, BOOL bOn)
{
// Define hook-info data
m_data.Detour = detour;
m_data.Pointer = (T)addr;
m_data.Original = (T)addr;

// Register data
if(detour && bOn)
CCallBack::Attach(m_data);
}

template <class T>
CInvoke<T>::operator T()
{
return (T&)m_data.Pointer;
}
CInvoke- Gratt stworzył ją by ułatwić sobie pisanie funkcji(chyba hookujących).
Przykład użycia wygląda tak:
CInvoke< void(__thiscall*)(void*,float)> pSetFarZSca (Adres,nazwa funckcji, zBool)

void __fastcall pSetFarZSca (zCSkyControlerOutdoor* _this, void*, float farg)
{
NazwaFunkcji(_this,farg);
}
I teraz pytanie: O co chodzi :/ Rozumiem tylko tą część: pSetFarZSca (Adres,nazwa funckcji, zBool)
Ale nie umiem zrozumieć tego: CInvoke< void(__thiscall*)(void*,float)> O co tutaj chodzi? __thiscall to chyba z IDA się wzięło, void to chyba typ funkcji lol, a float to argument. Ale Bardzo bym prosił o wyjaśnienie jeżeli ktoś by potrafił :) Z góry dzięki.

P.S To jest z niepublikowanej wersji AST z numerkiem 003 XD
 

P.S A Splash w szafie i nie ma psychy by mi dać bana.

Lehona

Lehona

Użytkownicy
posty196
Propsy190
  • Użytkownicy
I hate C-style function pointer types, but void(__thiscall*)(void*,float) means the function returns void (doesn't return anything), has to be called via __thiscall (calling convention) and the function takes two parameters, one void* and one float.


There is not enough code to tell you what exactly is going on, but it looks like some interface for hooking functions with some sort of type-safety?
 
Unless specified otherwise, my posts are always about Gothic 2 Night of the Raven.

Siemekk

Siemekk

Złote Wrota
Untersturmfuhrer
posty2143
Propsy1151
ProfesjaProgramista
  • Złote Wrota
  • Untersturmfuhrer

Siemekk
Złote Wrota

[C++] Zrozumienie "nietypowego" zapisu klasy
#2 2017-01-08, 19:54(Ostatnia zmiana: 2017-01-08, 19:59)
This is all code from AST classes.
Anyway...
I wrote this:
void __fastcall DefineExternals(void* data);


CInvoke< void(__thiscall*)(void*) > pDefineExternals (0x006D4780,DefineExternals,_ON);

void __fastcall DefineExternals(void* data)
{
pDefineExternals(data);
parser->DefineExternal("Render_KinoBars",RenderCinemaScopes,T_VOID,0);
}
But parser hasn't work when i build plugin...(Game only launch menu image)I don't understand what's going on.
 

P.S A Splash w szafie i nie ma psychy by mi dać bana.

Lehona

Lehona

Użytkownicy
posty196
Propsy190
  • Użytkownicy
Uhm, you're hooking a function and in the attached function you call it again. It's an infinite loop.

Edit: At least I think that's what it does. No idea what those addresses are.
 
Unless specified otherwise, my posts are always about Gothic 2 Night of the Raven.

Siemekk

Siemekk

Złote Wrota
Untersturmfuhrer
posty2143
Propsy1151
ProfesjaProgramista
  • Złote Wrota
  • Untersturmfuhrer

Siemekk
Złote Wrota

[C++] Zrozumienie "nietypowego" zapisu klasy
#4 2017-01-08, 20:00(Ostatnia zmiana: 2017-01-08, 21:08)
I see my error. But, I don't know what is pointer to pDefineExternals(this. oCGame or zCParser.
My suggestion from this:
void __thiscall oCGame::DefineExternals_Ulfi(zCParser *)     
Edit:
Jak dobierać właściwie te parametry?
CInvoke< void(__thiscall*)(void*,zCParser*) > pDefineExternals (0x006D4780,DefineExternals,_ON);
To nie działa, mimo iż jednym z argumentów jest właśnie parser :/
 

P.S A Splash w szafie i nie ma psychy by mi dać bana.


0 użytkowników i 1 Gość przegląda ten wątek.
0 użytkowników
Do góry