Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Fix EquipmentOverride
Browse files Browse the repository at this point in the history
  • Loading branch information
cursey committed Apr 23, 2021
1 parent b5d1328 commit d941be2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 8 additions & 0 deletions Core/Utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ namespace kanan {

std::string hexify(const uint8_t* data, size_t length);
std::string hexify(const std::vector<uint8_t>& data);

// Given the address of a relative offset, calculate the absolute address.
constexpr uintptr_t rel_to_abs(uintptr_t address, int offset = 4) {
auto rel = *(int*)(address);
auto ip = address + offset;

return ip + rel;
}
}
15 changes: 9 additions & 6 deletions Kanan/EquipmentOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "Kanan.hpp"
#include "Log.hpp"
#include "Utility.hpp"

#include "EquipmentOverride.hpp"

using namespace std;
Expand Down Expand Up @@ -141,14 +143,15 @@ namespace kanan {
m_equipmentOverrides[17].name = "Accessory 2";
m_equipmentOverrides[18].name = "Tail";

auto address = scan("client.exe", "55 8B EC 6A ? 68 ? ? ? ? 64 A1 ? ? ? ? 50 83 EC ? 53 56 57 A1 ? ? ? ? 33 C5 50 8D 45 F4 64 A3 ? ? ? ? 8B D9 8B 75 0C 8B 0D ? ? ? ?");
if (auto call_address = scan("client.exe", "E8 ? ? ? ? C7 45 FC ? ? ? ? 8D 4D C0 E8 ? ? ? ? 8B 45 B8")) {
log("[EquipmentOverride] Found address of call setEquipmentInfo %p", *call_address);

if (address) {
log("[EquipmentOverride] Found address of setEquipmentInfo %p", *address);
auto set_equip_info = rel_to_abs(*call_address + 1);

m_setEquipmentInfoHook = make_unique<FunctionHook>(*address, (uintptr_t)&EquipmentOverride::hookedSetEquipmentInfo);
}
else {
log("[EquipmentOverride] Found address of setEquipmentInfo %p", set_equip_info);

m_setEquipmentInfoHook = make_unique<FunctionHook>(set_equip_info, (uintptr_t)&EquipmentOverride::hookedSetEquipmentInfo);
} else {
log("[EquipmentOverride] Failed to find address of setEquipmentInfo!");
}

Expand Down

0 comments on commit d941be2

Please sign in to comment.