Skip to content

Commit

Permalink
use offsets from base address of application instead of memory address'
Browse files Browse the repository at this point in the history
  • Loading branch information
Renari committed May 19, 2016
1 parent 846e812 commit 8dfb208
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
57 changes: 39 additions & 18 deletions FFXRT/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <Windows.h>
#include <TlHelp32.h>
#include <QTimer>
#include "mainwindow.h"
#include "ui_mainwindow.h"
Expand Down Expand Up @@ -42,8 +44,26 @@ void MainWindow::clearText() {
ui->rikkuText->setText("");
}

DWORD MainWindow::getBaseAddress(DWORD pid)
{
MODULEENTRY32 module;
module.dwSize = sizeof(MODULEENTRY32);
HANDLE moduleHandle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
if (moduleHandle) {
if(!Module32First(moduleHandle, &module)) {
return 0;
}
do {
if(!wcscmp(module.szModule, FFX_PROCESS_NAME)) {
return (unsigned int)module.modBaseAddr;
}
} while(Module32Next(moduleHandle, &module));
}
return 0;
}

void MainWindow::readMemoryAndSetText(HANDLE handle, QLabel *label, DWORD address) {
uint value = 0;
unsigned int value = 0;
ReadProcessMemory(handle,(void*)address,&value,sizeof(value),0);
label->setText(QString::number(value));
if(value > highestValue) {
Expand All @@ -63,29 +83,30 @@ void MainWindow::updateAffection() {
HWND ffx = FindWindow(FFX_CLASS_NAME, FFX_WINDOW_TITLE);
if (ffx) {
GetWindowThreadProcessId(ffx, &pid);
HANDLE ffxHandle = OpenProcess(PROCESS_VM_READ, false, pid);
if (ffxHandle) {
readMemoryAndSetText(ffxHandle, ui->yunaText, YUNA_ADDRESS);
readMemoryAndSetText(ffxHandle, ui->auronText, AURON_ADDRESS);
readMemoryAndSetText(ffxHandle, ui->kimahriText, KIMAHRI_ADDRESS);
readMemoryAndSetText(ffxHandle, ui->wakkaText, WAKKA_ADDRESS);
readMemoryAndSetText(ffxHandle, ui->luluText, LULU_ADDRESS);
readMemoryAndSetText(ffxHandle, ui->rikkuText, RIKKU_ADDRESS);
} else {
clearText();
DWORD baseAddress = getBaseAddress(pid);
if (baseAddress) {
HANDLE ffxHandle = OpenProcess(PROCESS_VM_READ, false, pid);
if (ffxHandle) {
readMemoryAndSetText(ffxHandle, ui->yunaText, baseAddress+YUNA_ADDRESS);
readMemoryAndSetText(ffxHandle, ui->auronText, baseAddress+AURON_ADDRESS);
readMemoryAndSetText(ffxHandle, ui->kimahriText, baseAddress+KIMAHRI_ADDRESS);
readMemoryAndSetText(ffxHandle, ui->wakkaText, baseAddress+WAKKA_ADDRESS);
readMemoryAndSetText(ffxHandle, ui->luluText, baseAddress+LULU_ADDRESS);
readMemoryAndSetText(ffxHandle, ui->rikkuText, baseAddress+RIKKU_ADDRESS);
return;
}
}
} else {
clearText();
}
clearText();
}

void MainWindow::resetPixmap() {
updatePixmap(ui->yunaText, false);
updatePixmap(ui->auronText, false);
updatePixmap(ui->yunaText, false);
updatePixmap(ui->auronText, false);
updatePixmap(ui->kimahriText, false);
updatePixmap(ui->wakkaText, false);
updatePixmap(ui->luluText, false);
updatePixmap(ui->rikkuText, false);
updatePixmap(ui->wakkaText, false);
updatePixmap(ui->luluText, false);
updatePixmap(ui->rikkuText, false);
}

void MainWindow::updatePixmap(QLabel *label, boolean heart) {
Expand Down
14 changes: 8 additions & 6 deletions FFXRT/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ class MainWindow : public QMainWindow
private:
Ui::MainWindow *ui;
QTimer *timer;
const DWORD YUNA_ADDRESS = 0x01CACAC0;
const DWORD AURON_ADDRESS = 0x01CACAC4;
const DWORD KIMAHRI_ADDRESS = 0x01CACAC8;
const DWORD WAKKA_ADDRESS = 0x01CACACC;
const DWORD LULU_ADDRESS = 0x01CACAD0;
const DWORD RIKKU_ADDRESS = 0x01CACAD4;
const DWORD YUNA_ADDRESS = 0xD2CAC0;
const DWORD AURON_ADDRESS = 0xD2CAC4;
const DWORD KIMAHRI_ADDRESS = 0xD2CAC8;
const DWORD WAKKA_ADDRESS = 0xD2CACC;
const DWORD LULU_ADDRESS = 0xD2CAD0;
const DWORD RIKKU_ADDRESS = 0xD2CAD4;
const LPCWSTR FFX_PROCESS_NAME = L"FFX.exe";
const LPCWSTR FFX_CLASS_NAME = L"PhyreFrameworkClass";
const LPCWSTR FFX_WINDOW_TITLE = L"FINAL FANTASY X";
uint highestValue = 0;
Expand All @@ -42,6 +43,7 @@ class MainWindow : public QMainWindow
QPixmap rikku;
QPixmap rikkuH;
void clearText();
DWORD getBaseAddress(DWORD);
void readMemoryAndSetText(HANDLE, QLabel*, DWORD);
void resetPixmap();
void updatePixmap(QLabel*, boolean);
Expand Down

0 comments on commit 8dfb208

Please sign in to comment.