Skip to content

Commit

Permalink
Merge pull request #9 from s0t7x/refactor
Browse files Browse the repository at this point in the history
reintroducing infinite item usage for latest svn
  • Loading branch information
s0t7x authored Nov 20, 2024
2 parents ccce9fd + b96eba9 commit c813444
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 62 deletions.
115 changes: 56 additions & 59 deletions example-mods/basics_mod/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,44 +132,6 @@ class NoFallDamage : public _Mod
}
};

class NoCraftCost : public _Mod
{
public:
NoCraftCost(ModContext* modContext) : _Mod(modContext)
{
// Pattern matching the AOB scan for the original code in the target process.
const char* pattern = "\x43\x8B\x74\xF5\x04";
const char* mask = "xxxxx";

// Base address of the module (the game).
uintptr_t baseAddress = (uintptr_t)GetModuleHandle(NULL);

// Find the pattern within the game memory (scans within 16MB).
uintptr_t address = Mem::FindPattern(pattern, mask, baseAddress, 0x1000000);

// If the address was found, proceed with allocating memory and creating the detour.
if (address)
{
// The modded code that will replace the original instructions at the found address.
uint8_t modCode[] = {
0x43, 0x8B, 0x74, 0xF5, 0x04, // - mov esi,[r13 + r14 * 8 + 04]
0xBE, 0x00, 0x00, 0x00, 0x00, // - mov esi,00000000
0xE9, 0x00, 0x00, 0x00, 0x00 // - jmp
};

// Creating the detour by replacing the original code with our custom modCode.
mod = new Mem::Detour(address, modCode, sizeof(modCode), false, 0);

// Calculate the jump address and update the shellcode.
mod->shellcode->updateValue<uint32_t>(
sizeof(modCode) - 4, (uint32_t)(mod->patch->data->address + mod->patch->data->size)
- ((uint32_t)((uintptr_t)mod->shellcode->data->address
+ mod->shellcode->data->size))
);
}
}
};

class InfiniteItemUse : public _Mod
{
public:
Expand All @@ -178,26 +140,26 @@ class InfiniteItemUse : public _Mod
InfiniteItemUse(ModContext* modContext) : _Mod(modContext)
{
// AOB patterns for the original code in the target process.
const char* pattern1 = "\x45\x29\x7E\x04\x41\x2B\xEF"; // First AOB
const char* pattern2 = "\x33\xC9\x49\x89\x0E"; // Second AOB
const char* pattern1 = "\x49\x89\x0E\x41\x2B"; // First AOB
const char* pattern2 = "\x45\x29\x7E\x04\x41\x2B\xEF"; // Second AOB

// Base address of the module (the game).
uintptr_t baseAddress = (uintptr_t)GetModuleHandle(NULL);

// Find the patterns within the game memory (scans within 16MB).
uintptr_t address1 = Mem::FindPattern(pattern1, "xxxxxxx", baseAddress, 0xF0000000);
uintptr_t address2 = Mem::FindPattern(pattern2, "xxxxx", baseAddress, 0xF0000000);
uintptr_t address1 = Mem::FindPattern(pattern1, "xxxxx", baseAddress, 0xF0000000);
uintptr_t address2 = Mem::FindPattern(pattern2, "xxxxxxx", baseAddress, 0xF0000000);

// Check if both addresses were found.
if (address1 && address2)
{
// Allocate memory for new instructions to be injected at address1.
uint8_t modCode1[] = {
0x49, 0x83, 0xFB, 0x01, 0x0F, 0x85, 0x08, 0x00, 0x00, 0x00, 0x44, 0x29, 0xFD, 0xE9, 0x00, 0x00, 0x00, 0x00
0x41, 0xBF, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x00, 0x00, 0x00, 0x00, 0xE9, 0x00, 0x00, 0x00, 0x00
};

// Creating the detour for the first address.
mod = new Mem::Detour(address1, modCode1, sizeof(modCode1), false, 2);
mod = new Mem::Detour(address1, modCode1, sizeof(modCode1), false, 1);

// Calculate the jump address for the first detour.
mod->shellcode->updateValue<uint32_t>(
Expand All @@ -208,21 +170,17 @@ class InfiniteItemUse : public _Mod

// Allocate memory for new instructions to be injected at address2.
uint8_t modCode2[] = {
0x31, 0xC9, // xor ecx, ecx
0x49, 0x83, 0xFB, 0x01,
0x0F, 0x84, 0x03, 0x00, 0x00, 0x00,
0x49, 0x89, 0x0E,
0xE9, 0x00, 0x00, 0x00, 0x00 // jmp
0x41, 0xBF, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x00, 0x00, 0x00, 0x00, 0xE9, 0x00, 0x00, 0x00, 0x00
};

// Creating the detour for the second address.
free_ItemUseMod2 = new Mem::Detour(address2, modCode2, sizeof(modCode2), false);
free_ItemUseMod2 = new Mem::Detour(address2, modCode2, sizeof(modCode2), false, 2);

// Calculate the jump address for the second detour.
free_ItemUseMod2->shellcode->updateValue<uint32_t>(
sizeof(modCode2) - 4, (uint32_t)(free_ItemUseMod2->patch->data->address + free_ItemUseMod2->patch->data->size)
- ((uint32_t)((uintptr_t)free_ItemUseMod2->shellcode->data->address
+ free_ItemUseMod2->shellcode->data->size - 4))
+ free_ItemUseMod2->shellcode->data->size))
);
}
}
Expand All @@ -249,6 +207,44 @@ class InfiniteItemUse : public _Mod
}
};

// Unpatched
class NoCraftCost : public _Mod
{
public:
NoCraftCost(ModContext* modContext) : _Mod(modContext)
{
// Pattern matching the AOB scan for the original code in the target process.
const char* pattern = "\x43\x8B\x74\xF5\x04";
const char* mask = "xxxxx";

// Base address of the module (the game).
uintptr_t baseAddress = (uintptr_t)GetModuleHandle(NULL);

// Find the pattern within the game memory (scans within 16MB).
uintptr_t address = Mem::FindPattern(pattern, mask, baseAddress, 0x1000000);

// If the address was found, proceed with allocating memory and creating the detour.
if (address)
{
// The modded code that will replace the original instructions at the found address.
uint8_t modCode[] = {
0x43, 0x8B, 0x74, 0xF5, 0x04, // - mov esi,[r13 + r14 * 8 + 04]
0xBE, 0x00, 0x00, 0x00, 0x00, // - mov esi,00000000
0xE9, 0x00, 0x00, 0x00, 0x00 // - jmp
};

// Creating the detour by replacing the original code with our custom modCode.
mod = new Mem::Detour(address, modCode, sizeof(modCode), false, 0);

// Calculate the jump address and update the shellcode.
mod->shellcode->updateValue<uint32_t>(
sizeof(modCode) - 4, (uint32_t)(mod->patch->data->address + mod->patch->data->size)
- ((uint32_t)((uintptr_t)mod->shellcode->data->address
+ mod->shellcode->data->size))
);
}
}
};
// BROKEN! Actually does opposite of what it should... :(
class BypassWorldBorders : public _Mod
{
Expand Down Expand Up @@ -305,7 +301,7 @@ class BypassWorldBorders : public _Mod
LOG_CLASS("Deactivated BypassWorldBorders");
}
};

// Unpatched
class BypassAltarLimit : public _Mod
{
public:
Expand Down Expand Up @@ -403,18 +399,20 @@ class BasicsMod : public Mod
else if (!noFallDamageEnabled && noFallDamage->active)
noFallDamage->deactivate();

bool noCraftCostEnabled = modContext->config.GetBool(modKey, "no_craft_cost", false);
if (noCraftCostEnabled && !noCraftCost->active)
noCraftCost->activate();
else if (!noCraftCostEnabled && noCraftCost->active)
noCraftCost->deactivate();

bool infiniteItemUseEnabled = modContext->config.GetBool(modKey, "inf_item_use", false);
if (infiniteItemUseEnabled && !infiniteItemUse->active)
infiniteItemUse->activate();
else if (!infiniteItemUseEnabled && infiniteItemUse->active)
infiniteItemUse->deactivate();

// // Unpatched
/* bool noCraftCostEnabled = modContext->config.GetBool(modKey, "no_craft_cost", false);
if (noCraftCostEnabled && !noCraftCost->active)
noCraftCost->activate();
else if (!noCraftCostEnabled && noCraftCost->active)
noCraftCost->deactivate();
bool bypassWorldBordersEnabled = modContext->config.GetBool(modKey, "bypass_world_borders", false);
if (bypassWorldBordersEnabled && !bypassWorldBorders->active)
bypassWorldBorders->activate();
Expand All @@ -425,8 +423,7 @@ class BasicsMod : public Mod
if (bypassAltarLimitEnabled && !bypassAltarLimit->active)
bypassAltarLimit->activate();
else if (!bypassAltarLimitEnabled && bypassAltarLimit->active)
bypassAltarLimit->deactivate();

bypassAltarLimit->deactivate();*/
}

ModMetaData GetMetaData() {
Expand Down
6 changes: 3 additions & 3 deletions example-mods/flight_mod/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class FlightMod : public Mod
public:
void Load(ModContext* modContext)
{
// F3 0F 10 05 ? ? ? ? ? ? ? ? F2 0F 11 4C 24 60
const char* pattern = "\xF3\x0F\x10\x05\x00\x00\x00\x00\xF2\x0F\x11\x4C\x24\x60";
const char* mask = "xxxx????xxxxxx";
// F3 0F 10 05 ?? ?? ?? ?? F2 0F 11 4C 24 60
const char* pattern = "\xF3\x0F\x10\x05";
const char* mask = "xxxx";

uintptr_t baseAddress = (uintptr_t)GetModuleHandle(NULL);
uintptr_t address = Mem::FindPattern(pattern, mask, baseAddress, 0x1000000); // Scan 16MB
Expand Down

0 comments on commit c813444

Please sign in to comment.