Skip to content

Commit

Permalink
added new cheat functions
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmoCortney committed Oct 17, 2023
1 parent 4ad72e5 commit 6b38937
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
102 changes: 102 additions & 0 deletions MungPlex/Cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ MungPlex::Cheats::Cheats()
_lua.set_function("WriteArrayInt64", &writeArrayInt64);
_lua.set_function("WriteArrayFloat", &writeArrayFloat);
_lua.set_function("WriteArrayDouble", &writeArrayDouble);
_lua.set_function("FillAndSlideInt8", &fillAndSlideInt8);
_lua.set_function("FillAndSlideInt16", &fillAndSlideInt16);
_lua.set_function("FillAndSlideInt32", &fillAndSlideInt32);
_lua.set_function("FillAndSlideInt64", &fillAndSlideInt64);
_lua.set_function("FillAndSlideFloat", &fillAndSlideFloat);
_lua.set_function("FillAndSlideDouble", &fillAndSlideDouble);

_lua.set_function("IsInRange", &isInRange);
_lua.set_function("GetModuleAddress", &getModuleAddress);
_lua.set_function("CopyMemory", &copyMemory);

_lua.set_function("LogText", &logText);
_lua.set_function("LogUInt8", &logUInt8);
Expand Down Expand Up @@ -464,6 +471,101 @@ void MungPlex::Cheats::writeArrayDouble(const uint64_t address, const sol::table
}
}

void MungPlex::Cheats::fillAndSlideInt8(const uint64_t address, const int64_t addressIncrement, const int8_t value, const int8_t valueIncrement, const uint8_t count)
{
uint64_t addr = address;
int8_t val = value;

for (uint32_t i = 0; i < count; ++i)
{
writeInt8(addr, val);
addr += addressIncrement;
val += valueIncrement;
}
}

void MungPlex::Cheats::fillAndSlideInt16(const uint64_t address, const int64_t addressIncrement, const int16_t value, const int16_t valueIncrement, const uint16_t count)
{
uint64_t addr = address;
int16_t val = value;

for (uint32_t i = 0; i < count; ++i)
{
writeInt16(addr, val);
addr += addressIncrement;
val += valueIncrement;
}
}

void MungPlex::Cheats::fillAndSlideInt32(const uint64_t address, const int64_t addressIncrement, const int32_t value, const int32_t valueIncrement, const uint32_t count)
{
uint64_t addr = address;
int32_t val = value;

for (uint32_t i = 0; i < count; ++i)
{
writeInt32(addr, val);
addr += addressIncrement;
val += valueIncrement;
}
}

void MungPlex::Cheats::fillAndSlideInt64(const uint64_t address, const int64_t addressIncrement, const int64_t value, const int64_t valueIncrement, const uint32_t count)
{
uint64_t addr = address;
int64_t val = value;

for (uint32_t i = 0; i < count; ++i)
{
writeInt64(addr, val);
addr += addressIncrement;
val += valueIncrement;
}
}

void MungPlex::Cheats::fillAndSlideFloat(const uint64_t address, const int64_t addressIncrement, const float value, const float valueIncrement, const uint32_t count)
{
uint64_t addr = address;
float val = value;

for (uint32_t i = 0; i < count; ++i)
{
writeFloat(addr, val);
addr += addressIncrement;
val += valueIncrement;
}
}

void MungPlex::Cheats::fillAndSlideDouble(const uint64_t address, const int64_t addressIncrement, const double value, const double valueIncrement, const uint32_t count)
{
uint64_t addr = address;
double val = value;

for (uint32_t i = 0; i < count; ++i)
{
writeDouble(addr, val);
addr += addressIncrement;
val += valueIncrement;
}
}

void MungPlex::Cheats::copyMemory(const uint64_t source, const uint64_t destination, const uint32_t size)
{
const int sourceIndex = GetInstance().getRangeIndex(source);
const int destinationIndex = GetInstance().getRangeIndex(destination);

if (sourceIndex == -1 || GetInstance().getRangeIndex(destinationIndex + size) == -1)
return;

void* src = static_cast<char*>(GetInstance()._regions[sourceIndex].BaseLocationProcess) + source - GetInstance()._regions[sourceIndex].Base;
void* dest = static_cast<char*>(GetInstance()._regions[destinationIndex].BaseLocationProcess) + destination - GetInstance()._regions[destinationIndex].Base;

char* buf = new char[size];
Xertz::SystemInfo::GetProcessInfo(GetInstance()._pid).ReadExRAM(buf, src, size);
Xertz::SystemInfo::GetProcessInfo(GetInstance()._pid).WriteExRAM(buf, dest, size);
delete[] buf;
}

bool MungPlex::Cheats::isInRange(const uint64_t ptr, const uint64_t start, const uint64_t end)
{
return ptr >= start && ptr < end;
Expand Down
7 changes: 7 additions & 0 deletions MungPlex/Cheats.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ namespace MungPlex
static void writeArrayInt64(const uint64_t address, const sol::table arr);
static void writeArrayFloat(const uint64_t address, const sol::table arr);
static void writeArrayDouble(const uint64_t address, const sol::table arr);
static void fillAndSlideInt8(const uint64_t address, const int64_t addressIncrement, const int8_t value, const int8_t valueIncrement, const uint8_t count);
static void fillAndSlideInt16(const uint64_t address, const int64_t addressIncrement, const int16_t value, const int16_t valueIncrement, const uint16_t count);
static void fillAndSlideInt32(const uint64_t address, const int64_t addressIncrement, const int32_t value, const int32_t valueIncrement, const uint32_t count);
static void fillAndSlideInt64(const uint64_t address, const int64_t addressIncrement, const int64_t value, const int64_t valueIncrement, const uint32_t count);
static void fillAndSlideFloat(const uint64_t address, const int64_t addressIncrement, const float value, const float valueIncrement, const uint32_t count);
static void fillAndSlideDouble(const uint64_t address, const int64_t addressIncrement, const double value, const double valueIncrement, const uint32_t count);
template <typename dataType> void writeValue(uint64_t writeAddress, dataType writeValue)
{
if (_isBigEndian)
Expand All @@ -147,6 +153,7 @@ namespace MungPlex

static bool isInRange(const uint64_t ptr, const uint64_t start, const uint64_t end);
static uint64_t getModuleAddress(const char* moduleName);
static void copyMemory(const uint64_t source, const uint64_t destination, const uint32_t size);

static void logText(const char* text);
static void logUInt8(const uint8_t value, const bool hex = false);
Expand Down

0 comments on commit 6b38937

Please sign in to comment.