0

so I have this code in my Memory.cpp

template<typename T>
T Memory::ReadMemory(const std::uintptr_t& baseAddress) const {
    T buffer = 0;
    ReadProcessMemory(this->m_pH, (LPCVOID)(baseAddress), &buffer, sizeof(buffer), NULL);
    return buffer;
}

And this code in my Base.cpp:

std::uintptr_t CBase::Get_CurrentIcon() const {
    return ptrMemory->ReadMemory<std::uintptr_t>(0x360);
}

byte CBase::Get_CurrentSlot() const {
    return ptrMemory->ReadMemory<byte>(0x420);
}

However that causes an unresolved external symbol error stating public: unsigned __int64 __cdecl Memory::ReadMemory<unsigned __int64>(unsigned __int64 const &)const.

So I was able to fix it with instead of using T, to add a ReadMemory for each used Data Type like this in my Memory.cpp.

template<>
std::uintptr_t Memory::ReadMemory(const std::uintptr_t& baseAddress) const {
    std::uintptr_t buffer = 0;
    ReadProcessMemory(this->m_pH, (LPCVOID)(baseAddress), &buffer, sizeof(buffer), NULL);
    return buffer;
}
 
template<>
byte Memory::ReadMemory(const std::uintptr_t& baseAddress) const {
    byte buffer = 0;
    ReadProcessMemory(this->m_pH, (LPCVOID)(baseAddress), &buffer, sizeof(buffer), NULL);
    return buffer;
}

However that feels kinda overcomplicated. Is there a better method to fix the issue?

0 Answers0