Skip to content

Commit

Permalink
Merge pull request #8 from Asiern/fix-read/write-position
Browse files Browse the repository at this point in the history
fix: read/write position
  • Loading branch information
Asiern authored Jul 31, 2021
2 parents 01bdee2 + 15e8579 commit 8393f6d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
1 change: 1 addition & 0 deletions Source/ReplicantHook/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ int main()
cout << "Health " << hook.getHealth() << endl;
cout << "Gold " << hook.getGold() << endl;
cout << "Zone " << hook.getZone() << endl;
cout << "X: " << hook.getX() << " Y: " << hook.getY() << " Z: " << hook.getZ() << endl;
Sleep(500);
system("cls");
}
Expand Down
42 changes: 21 additions & 21 deletions Source/ReplicantHook/ReplicantHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ std::string ReplicantHook::readMemoryString(uintptr_t address)
{
char val[20];
HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, this->_pID);
ReadProcessMemory(pHandle, (LPCVOID)(this->_baseAddress + address), &val, sizeof(val), NULL);
ReadProcessMemory(pHandle, (LPCVOID)address, &val, sizeof(val), NULL);
CloseHandle(pHandle); //Close handle to prevent memory leaks
return std::string(val);
}
Expand All @@ -137,7 +137,7 @@ void ReplicantHook::writeMemoryString(uintptr_t address, std::string value)
SIZE_T BytesToWrite = value.length() + 1;
SIZE_T BytesWritten;
HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, this->_pID);
WriteProcessMemory(pHandle, (LPVOID)(this->_baseAddress + address), (LPCVOID)value.c_str(), BytesToWrite, &BytesWritten);
WriteProcessMemory(pHandle, (LPVOID)address, (LPCVOID)value.c_str(), BytesToWrite, &BytesWritten);
}

ReplicantHook::ReplicantHook(int version)
Expand Down Expand Up @@ -193,17 +193,17 @@ void ReplicantHook::hookStatus(void)

void ReplicantHook::update()
{
this->actorPlayable = readMemory <uintptr_t>(_offsets.actorPlayable);
this->gold = readMemory<int>(_offsets.entity + _offsets.gold);
this->zone = readMemoryString(_offsets.entity + _offsets.zone);
this->name = readMemoryString(_offsets.entity + _offsets.name);
this->health = readMemory<int>(_offsets.entity + _offsets.health);
this->magic = readMemory<float>(_offsets.entity + _offsets.magic);
this->level = readMemory<int>(_offsets.entity + _offsets.level);
this->playtime = readMemory<double>(_offsets.entity + _offsets.playtime);
this->x = readMemory<float>((uintptr_t)this->actorPlayable + 0x9C);
this->y = readMemory<float>((uintptr_t)this->actorPlayable + 0xAC);
this->z = readMemory<float>((uintptr_t)this->actorPlayable + 0xBC);
this->actorPlayable = readMemory <uintptr_t>(this->_baseAddress + _offsets.actorPlayable);
this->gold = readMemory<int>(this->_baseAddress + _offsets.entity + _offsets.gold);
this->zone = readMemoryString(this->_baseAddress + _offsets.entity + _offsets.zone);
this->name = readMemoryString(this->_baseAddress + _offsets.entity + _offsets.name);
this->health = readMemory<int>(this->_baseAddress + _offsets.entity + _offsets.health);
this->magic = readMemory<float>(this->_baseAddress + _offsets.entity + _offsets.magic);
this->level = readMemory<int>(this->_baseAddress + _offsets.entity + _offsets.level);
this->playtime = readMemory<double>(this->_baseAddress + _offsets.entity + _offsets.playtime);
this->x = readMemory<float>((uintptr_t)(this->actorPlayable + 0x9C));
this->y = readMemory<float>((uintptr_t)(this->actorPlayable + 0xAC));
this->z = readMemory<float>((uintptr_t)(this->actorPlayable + 0xBC));
}

bool ReplicantHook::isHooked(void)
Expand Down Expand Up @@ -263,37 +263,37 @@ float ReplicantHook::getZ()

void ReplicantHook::setGold(int value)
{
this->writeMemory(_offsets.entity + _offsets.gold, value);
this->writeMemory(this->_baseAddress + _offsets.entity + _offsets.gold, value);
}

void ReplicantHook::setZone(std::string value)
{
this->writeMemoryString(_offsets.entity + _offsets.zone, value);
this->writeMemoryString(this->_baseAddress + _offsets.entity + _offsets.zone, value);
}

void ReplicantHook::setName(std::string value)
{
this->writeMemoryString(_offsets.entity + _offsets.name, value);
this->writeMemoryString(this->_baseAddress + _offsets.entity + _offsets.name, value);
}

void ReplicantHook::setHealth(int value)
{
this->writeMemory(_offsets.entity + _offsets.health, value);
this->writeMemory(this->_baseAddress + _offsets.entity + _offsets.health, value);
}

void ReplicantHook::setMagic(float value)
{
this->writeMemory(_offsets.entity + _offsets.magic, value);
this->writeMemory(this->_baseAddress + _offsets.entity + _offsets.magic, value);
}

void ReplicantHook::setLevel(int value)
{
this->writeMemory(_offsets.entity + _offsets.level, value);
this->writeMemory(this->_baseAddress + _offsets.entity + _offsets.level, value);
}

void ReplicantHook::setPlaytime(double value)
{
this->writeMemory(_offsets.entity + _offsets.playtime, value);
this->writeMemory(this->_baseAddress + _offsets.entity + _offsets.playtime, value);
}

void ReplicantHook::setX(float value)
Expand Down Expand Up @@ -379,6 +379,6 @@ void ReplicantHook::setActorModel(std::string model)

std::string ReplicantHook::getActorModel()
{
return readMemoryString(_offsets.model);
return readMemoryString(this->_baseAddress + _offsets.model);
}

4 changes: 2 additions & 2 deletions Source/ReplicantHook/ReplicantHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ inline T ReplicantHook::readMemory(uintptr_t address)
{
T value;
HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, this->_pID);
ReadProcessMemory(pHandle, (LPCVOID)(this->_baseAddress + address), &value, sizeof(value), NULL);
ReadProcessMemory(pHandle, (LPCVOID)(address), &value, sizeof(value), NULL);
CloseHandle(pHandle); //Close handle to prevent memory leaks
return value;
}
Expand All @@ -97,7 +97,7 @@ template<typename T>
inline void ReplicantHook::writeMemory(uintptr_t address, T value)
{
HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, NULL, this->_pID);
WriteProcessMemory(pHandle, (LPVOID)(this->_baseAddress + address), &value, sizeof(value), NULL);
WriteProcessMemory(pHandle, (LPVOID)(address), &value, sizeof(value), NULL);
CloseHandle(pHandle);
}

0 comments on commit 8393f6d

Please sign in to comment.