我正在尝试创建一个指针访问类,其目标是简化对已知内存位置的访问。
至于现在我有这个类:
template<class T = DWORD> struct Pointer
{
private://minimum 2 params
std::vector<T> params;
Pointer()
{}
Pointer(T a)
{params.push_back(a);}
public:
Pointer(T a, T b)
{params.push_back(a);Pointer::Pointer(b);}
Pointer(T a, T b, T c)
{params.push_back(a);Pointer::Pointer(b,c);}
Pointer(T a, T b, T c, T d)
{params.push_back(a);Pointer::Pointer(b,c,d);}
Pointer(T a, T b, T c, T d, T e)
{params.push_back(a);Pointer::Pointer(b,c,d,e);}
Pointer(T a, T b, T c, T d, T e, T f)
{params.push_back(a);Pointer::Pointer(b,c,d,e,f);}
Pointer(T a, T b, T c, T d, T e, T f, T g)
{params.push_back(a);Pointer::Pointer(b,c,d,e,f,g);}
//all the way to ... z
T* ResolvePointer(/*,bool fallback = false*/)
{
T variable = params[0];
try
{
auto it = params.begin();
++it;
for(; it != params.end(); ++it)
variable = *reinterpret_cast<T*>(variable) + *it;
}
catch(...)
{
/*if(fallback){
static char fallback_location[2048];
variable = reinterpret_cast<T>(&fallback_location[0]);
}else{*/
variable = NULL;
//}
}
return reinterpret_cast<T*>(variable);
}
T* operator()()
{
return ResolvePointer();
}
};
但每当我叫它
(例如:
Player[slot].Money = Pointer<int>(0x00400000+0x008E98EC,0xD8+(0x4*slot),0xE4,0x00,0x4)();
),
params
向量总是只有a
:( _
我究竟做错了什么?我该如何解决这个问题?
PS:我想使用可变参数模板,但我正在使用MICROSOFT VISUAL C++ 11