Skip to content

Commit

Permalink
Merge pull request #7 from Asiern/Replicant-v1.0.3.0
Browse files Browse the repository at this point in the history
Replicant v1.0.3.0
  • Loading branch information
Asiern authored Jul 30, 2021
2 parents 06e2dea + 2643dc3 commit 01bdee2
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 27 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int main()
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); //Look for memory leaks
ReplicantHook hook = ReplicantHook();
ReplicantHook hook = ReplicantHook(1); //Pass game version as parameter
cout << "Replicant Hook\n";
cout << "Hooking..." << endl;
//Hook to process
Expand Down Expand Up @@ -82,6 +82,12 @@ You can find all the used IDs and offsets [here](https://docs.google.com/spreads

## ReplicantHook Reference

#### Version codes

- `v1.0.0.0` > `0`

- `v1.0.3.0` > `1`

#### Methods

- `start` - attach the hook to `NieR Replicant ver.1.22474487139.exe` process
Expand Down
2 changes: 1 addition & 1 deletion Source/ReplicantHook/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main()
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); //Look for memory leaks

ReplicantHook hook = ReplicantHook();
ReplicantHook hook = ReplicantHook(1); //Pass game version as parameter
cout << "Replicant Hook\n";
cout << "Hooking..." << endl;
//Hook to process
Expand Down
23 changes: 23 additions & 0 deletions Source/ReplicantHook/Offsets.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include <Windows.h>

struct offsets {
uintptr_t entity;
uintptr_t actorPlayable;
uintptr_t model;
uintptr_t gold;
uintptr_t zone;
uintptr_t name;
uintptr_t health;
uintptr_t magic;
uintptr_t level;
uintptr_t playtime;
uintptr_t x;
uintptr_t y;
uintptr_t z;

//Cheats
uintptr_t InfiniteHealth;
uintptr_t InfiniteMagic;
};

84 changes: 61 additions & 23 deletions Source/ReplicantHook/ReplicantHook.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ReplicantHook.hpp"
#include <iostream>

DWORD ReplicantHook::_getProcessID(void)
{
Expand Down Expand Up @@ -45,14 +46,50 @@ uintptr_t ReplicantHook::_getModuleBaseAddress(DWORD procId, const wchar_t* modN
}

//Hook to NieR:Automata process
void ReplicantHook::_hook(void)
void ReplicantHook::_hook()
{

DWORD ID = this->_getProcessID();
if (ID <= 0)
return;
this->_pID = ID;
this->_baseAddress = this->_getModuleBaseAddress(ID, L"NieR Replicant ver.1.22474487139.exe");

//Get game version


switch (_version) {
case 0: {
_offsets.entity = 0x4372790;
_offsets.actorPlayable = 0x26F72D0;
_offsets.model = 0xB88280;
_offsets.gold = 0xBC;
_offsets.zone = 0x4;
_offsets.name = 0x2C;
_offsets.health = 0x4C;
_offsets.magic = 0x58;
_offsets.level = 0x64;
_offsets.playtime = 0x4A0;
_offsets.InfiniteHealth = 0x5D106DD;
_offsets.InfiniteMagic = 0x3BDB5E;
}
case 1: {
_offsets.entity = 0x4374A20;
_offsets.actorPlayable = 0x26F9560;
_offsets.model = 0xB892C0;
_offsets.gold = 0xBC;
_offsets.zone = 0x4;
_offsets.name = 0x2C;
_offsets.health = 0x4C;
_offsets.magic = 0x58;
_offsets.level = 0x64;
_offsets.playtime = 0x4A0;
_offsets.InfiniteHealth = 0x5F72DED;
_offsets.InfiniteMagic = 0x3BE2BE;
}
}
this->_hooked = true;

}
//unHook NieR:Automata
void ReplicantHook::_unHook(void)
Expand Down Expand Up @@ -103,8 +140,9 @@ void ReplicantHook::writeMemoryString(uintptr_t address, std::string value)
WriteProcessMemory(pHandle, (LPVOID)(this->_baseAddress + address), (LPCVOID)value.c_str(), BytesToWrite, &BytesWritten);
}

ReplicantHook::ReplicantHook()
ReplicantHook::ReplicantHook(int version)
{
this->_version = version;
this->_hooked = false;
this->_baseAddress = 0;
this->actorPlayable = 0;
Expand Down Expand Up @@ -155,14 +193,14 @@ void ReplicantHook::hookStatus(void)

void ReplicantHook::update()
{
this->actorPlayable = readMemory <uintptr_t>(0x26F72D0);
this->gold = readMemory<int>(0x437284C);
this->zone = readMemoryString(0x4372794);
this->name = readMemoryString(0x43727BC);
this->health = readMemory<int>(0x43727DC);
this->magic = readMemory<float>(0x43727E8);
this->level = readMemory<int>(0x43727F4);
this->playtime = readMemory<double>(0x4372C30);
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);
Expand Down Expand Up @@ -225,37 +263,37 @@ float ReplicantHook::getZ()

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

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

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

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

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

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

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

void ReplicantHook::setX(float value)
Expand Down Expand Up @@ -283,17 +321,17 @@ void ReplicantHook::setPosition(float x, float y, float z)
void ReplicantHook::InfiniteHealth(bool enabled)
{
if (enabled)
_patch((BYTE*)(this->_baseAddress + 0x5D106DD), (BYTE*)"\x90\x90\x90\x90", 4);
_patch((BYTE*)(this->_baseAddress + _offsets.InfiniteHealth), (BYTE*)"\x90\x90\x90\x90", 4);
else
_patch((BYTE*)(this->_baseAddress + 0x5D106DD), (BYTE*)"\x89\x44\x81\x4C", 4);
_patch((BYTE*)(this->_baseAddress + _offsets.InfiniteHealth), (BYTE*)"\x89\x44\x81\x4C", 4);
}

void ReplicantHook::InfiniteMagic(bool enabled)
{
if (enabled)
_patch((BYTE*)(this->_baseAddress + 0x3BDB5E), (BYTE*)"\x90\x90\x90\x90\x90\x90", 6);
_patch((BYTE*)(this->_baseAddress + _offsets.InfiniteMagic), (BYTE*)"\x90\x90\x90\x90\x90\x90", 6);
else
_patch((BYTE*)(this->_baseAddress + 0x3BDB5E), (BYTE*)"\xF3\x0F\x11\x54\x81\x58", 6);
_patch((BYTE*)(this->_baseAddress + _offsets.InfiniteMagic), (BYTE*)"\xF3\x0F\x11\x54\x81\x58", 6);
}

constexpr unsigned int str2int(const char* str, int h = 0)
Expand Down Expand Up @@ -336,11 +374,11 @@ void ReplicantHook::setActorModel(std::string model)
modelBytes = (BYTE*)"\x6E\x69\x65\x72\x42\x00\x00"; //default nierB
break;
}
this->_patch((BYTE*)(this->_baseAddress + 0x0B88280), modelBytes, 7);
this->_patch((BYTE*)(this->_baseAddress + _offsets.model), modelBytes, 7);
}

std::string ReplicantHook::getActorModel()
{
return readMemoryString(0x0B88280);
return readMemoryString(_offsets.model);
}

6 changes: 4 additions & 2 deletions Source/ReplicantHook/ReplicantHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
#include <Windows.h>
#include <TlHelp32.h>
#include <string>

#include "Offsets.hpp"
class ReplicantHook
{
private:
DWORD _pID;
uintptr_t _baseAddress;
uintptr_t actorPlayable;
bool _hooked;
offsets _offsets;
int _version;

int gold;
std::string zone;
Expand All @@ -35,7 +37,7 @@ class ReplicantHook
void writeMemoryString(uintptr_t address, std::string value);

public:
ReplicantHook();
ReplicantHook(int version);
~ReplicantHook();
DWORD getProcessID(void);
uintptr_t getBaseAddress(void);
Expand Down
1 change: 1 addition & 0 deletions Source/ReplicantHook/ReplicantHook.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<ClCompile Include="ReplicantHook.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Offsets.hpp" />
<ClInclude Include="ReplicantHook.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
3 changes: 3 additions & 0 deletions Source/ReplicantHook/ReplicantHook.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
<ClInclude Include="ReplicantHook.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Offsets.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit 01bdee2

Please sign in to comment.