Skip to content

Commit

Permalink
quaternion math for movement and a easier to interact with golf class
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorioum committed Nov 29, 2023
1 parent 1239300 commit 5ebd065
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 88 deletions.
1 change: 1 addition & 0 deletions ThorsGolfItHack/ThorsGolfItHack.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="golf.h" />
<ClInclude Include="memory.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
3 changes: 3 additions & 0 deletions ThorsGolfItHack/ThorsGolfItHack.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
<ClInclude Include="memory.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="golf.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
143 changes: 143 additions & 0 deletions ThorsGolfItHack/golf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#pragma once
#include "memory.h"
struct Vec3 {
float x;
float y;
float z;
};
struct Vec4 {
float x;
float y;
float z;
float w;
};
class Golf {
public:

uintptr_t golfBase;
uintptr_t physicsBase;
HANDLE h = 0;
public:

Golf() = delete;

Golf(HANDLE& h, DWORD procId) : camera(*this) {
this->h = h;
this->golfBase = Memory::GetModuleBaseAddress(procId, "GolfIt-Win64-Shipping.exe");
this->physicsBase = Memory::GetModuleBaseAddress(procId, "PhysX_64.dll");
}
const Vec3 getPos() {
uintptr_t dynamicPtrBaseAddr = golfBase + 0x05948FE8;
uintptr_t xAddr = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::xoffsets);
uintptr_t yAddr = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::yoffsets);
uintptr_t zAddr = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::zoffsets);
float x = Memory::readFloat(h, xAddr);
float y = Memory::readFloat(h, yAddr);
float z = Memory::readFloat(h, zAddr);
return Vec3(x, y, z);
}
void setPos(Vec3 pos) {
uintptr_t dynamicPtrBaseAddr = golfBase + 0x05948FE8;
uintptr_t xAddr = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::xoffsets);
uintptr_t yAddr = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::yoffsets);
uintptr_t zAddr = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::zoffsets);
WriteProcessMemory(h, (LPVOID)xAddr, &pos.x, sizeof(pos.x), nullptr);
WriteProcessMemory(h, (LPVOID)yAddr, &pos.y, sizeof(pos.y), nullptr);
WriteProcessMemory(h, (LPVOID)zAddr, &pos.z, sizeof(pos.z), nullptr);
}
const Vec3 getVel() {
uintptr_t dynamicPtrBaseAddr = golfBase + 0x05948FE8;
uintptr_t xAddr = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::xveloffsets);
uintptr_t yAddr = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::yveloffsets);
uintptr_t zAddr = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::zveloffsets);
float x = Memory::readFloat(h, xAddr);
float y = Memory::readFloat(h, yAddr);
float z = Memory::readFloat(h, zAddr);
return Vec3(x, y, z);
}
void setVel(Vec3 pos) {
uintptr_t dynamicPtrBaseAddr = golfBase + 0x05948FE8;
uintptr_t xAddr = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::xveloffsets);
uintptr_t yAddr = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::yveloffsets);
uintptr_t zAddr = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::zveloffsets);
WriteProcessMemory(h, (LPVOID)xAddr, &pos.x, sizeof(pos.x), nullptr);
WriteProcessMemory(h, (LPVOID)yAddr, &pos.y, sizeof(pos.y), nullptr);
WriteProcessMemory(h, (LPVOID)zAddr, &pos.z, sizeof(pos.z), nullptr);
}

Vec3 updateIfAddrChanged(Vec3 pos) {
uintptr_t dynamicPtrBaseAddr = golfBase + 0x05948FE8;
uintptr_t current = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::xveloffsets);
if (lastAddr != current) {
lastAddr = current;
return getPos();
}
return pos;
}
public:

class Camera {
public:

Camera() = delete;

Camera(Golf& golf) : golf(golf) {}

const Vec3 getPos() {
uintptr_t dynamicPtrBaseAddr = golf.golfBase + 0x057DD8C8;
uintptr_t xAddr = Memory::getPtrWithOffsets(golf.h, dynamicPtrBaseAddr, mem::cameraXOffsets);
uintptr_t yAddr = Memory::getPtrWithOffsets(golf.h, dynamicPtrBaseAddr, mem::cameraYOffsets);
uintptr_t zAddr = Memory::getPtrWithOffsets(golf.h, dynamicPtrBaseAddr, mem::cameraZOffsets);
float x = Memory::readFloat(golf.h, xAddr);
float y = Memory::readFloat(golf.h, yAddr);
float z = Memory::readFloat(golf.h, zAddr);
return Vec3(x, y, z);
}
const Vec4 getQuat() {
uintptr_t dynamicPtrBaseAddr = golf.golfBase + 0x057DD8C8;
uintptr_t xAddr = Memory::getPtrWithOffsets(golf.h, dynamicPtrBaseAddr, mem::cameraQuatXOffsets);
uintptr_t zAddr = Memory::getPtrWithOffsets(golf.h, dynamicPtrBaseAddr, mem::cameraQuatZOffsets);
uintptr_t yAddr = Memory::getPtrWithOffsets(golf.h, dynamicPtrBaseAddr, mem::cameraQuatYOffsets);
uintptr_t wAddr = Memory::getPtrWithOffsets(golf.h, dynamicPtrBaseAddr, mem::cameraQuatWOffsets);
float x = Memory::readFloat(golf.h, xAddr);
float z = Memory::readFloat(golf.h, zAddr);
float y = Memory::readFloat(golf.h, yAddr);
float w = Memory::readFloat(golf.h, wAddr);
return Vec4(x, y, z, w);
}

const float getQuatX() {
uintptr_t dynamicPtrBaseAddr = golf.golfBase + 0x057DD8C8;
uintptr_t xAddr = Memory::getPtrWithOffsets(golf.h, dynamicPtrBaseAddr, mem::cameraQuatXOffsets);
float x = Memory::readFloat(golf.h, xAddr);
return x;
}

const float getQuatZ() {
uintptr_t dynamicPtrBaseAddr = golf.golfBase + 0x057DD8C8;
uintptr_t zAddr = Memory::getPtrWithOffsets(golf.h, dynamicPtrBaseAddr, mem::cameraQuatZOffsets);
float z = Memory::readFloat(golf.h, zAddr);
return z;
}

const float getQuatY() {
uintptr_t dynamicPtrBaseAddr = golf.golfBase + 0x057DD8C8;
uintptr_t yAddr = Memory::getPtrWithOffsets(golf.h, dynamicPtrBaseAddr, mem::cameraQuatYOffsets);
float y = Memory::readFloat(golf.h, yAddr);
return y;
}

const float getQuatW() {
uintptr_t dynamicPtrBaseAddr = golf.golfBase + 0x057DD8C8;
uintptr_t wAddr = Memory::getPtrWithOffsets(golf.h, dynamicPtrBaseAddr, mem::cameraQuatWOffsets);
float w = Memory::readFloat(golf.h, wAddr);
return w;
}
private:
Golf& golf;
};
Camera camera;
private:

uintptr_t lastAddr = 0;
};
130 changes: 44 additions & 86 deletions ThorsGolfItHack/main.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#define WIN32_LEAN_AND_MEAN

#include "memory.h"
float speed = 4.0f;
#include "golf.h"


float speedx = 4.0f;
float speedz = 4.0f;
float speedy = 4.0f;
bool flying = false;
float localx, localy, localz;
int main() {
float speed = 10.0f;
bool flying = false;
Vec3 localPos{};

DWORD procId = Memory::GetProcId("GolfIt-Win64-Shipping.exe");
if (!procId) {
std::cout << "Couldnt find process!";
Expand All @@ -20,113 +19,72 @@ int main() {

uintptr_t modulebase = Memory::GetModuleBaseAddress(procId, "GolfIt-Win64-Shipping.exe");

uintptr_t dynamicPtrBaseAddr = modulebase + 0x05948FE8;

Golf g = Golf(h, procId);

std::cout << "Flying: [OFF]";
uintptr_t lastY = 0;
localPos = g.getPos();
while (!GetAsyncKeyState(VK_END)) {
//get position addresses
uintptr_t xAddress = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::xoffsets);
uintptr_t yAddress = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::yoffsets);
uintptr_t zAddress = Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::zoffsets);

//toggle flying
if (GetAsyncKeyState(VK_RSHIFT)) {
flying = !flying;

if (flying) {
localx = Memory::readFloat(h, xAddress);
localy = Memory::readFloat(h, yAddress);
localz = Memory::readFloat(h, zAddress);
localPos = g.getPos();
std::cout << "Flying: [ON]" << std::endl;;
}
else {
std::cout << "Flying: [OFF]" << std::endl;
}
Sleep(200);
}
if (!flying) {
continue;
}
//set all velocity near 0
//if we set all velocity to zero it will detect the ball has stoped rolling and teleport end the stroke
/*float n = 24;
WriteProcessMemory(h, (LPVOID)Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::xveloffsets), &n, sizeof(localx), nullptr);
WriteProcessMemory(h, (LPVOID)Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::yveloffsets), &n, sizeof(localx), nullptr);
WriteProcessMemory(h, (LPVOID)Memory::getPtrWithOffsets(h, dynamicPtrBaseAddr, mem::zveloffsets), &n, sizeof(localx), nullptr);*/

if (flying) {
//set all velocity near 0
//if we set all velocity to zero it will detect the ball has stoped rolling and teleport end the stroke
g.setVel(Vec3(24, 24, 24));


//every time the hole is changed the address of the position does as well, update local position values to match the spawn
if (lastY != yAddress) {
lastY = yAddress;
localx = Memory::readFloat(h, xAddress);
localy = Memory::readFloat(h, yAddress);
localz = Memory::readFloat(h, zAddress);
}
//quaternion math wtf (i dont dont know why this works)
Vec4 q = g.camera.getQuat();
float dx = 1 - 2 * (q.y * q.y + q.z * q.z);
float dy = 2 * (q.x * q.y - q.w * q.z);
float dz = 2 * (q.x * q.z + q.w * q.y);

//movement logic
if (GetAsyncKeyState('W')) {
localPos.x += (dx * speed);
localPos.y += (dy * speed);
localPos.z += (dz * speed);

//movement logic
if (GetAsyncKeyState('W')) {
if (speedx < speed*3) {
speedx += 0.1f;
}
if (speedx < 0) {
speedx = speed;
}
localx += speedx;
}
if (GetAsyncKeyState('S')) {
if (speedx > -speed * 3) {
speedx -= 0.1f;
}
if (speedx > 0) {
speedx = -speed;
}
localx += speedx;
}
if (GetAsyncKeyState('A')) {
if (speedz > -speed * 3) {
speedz -= 0.1f;
}
if (speedz > 0) {
speedz = -speed;
}
localz += speedz;
}
if (GetAsyncKeyState('D')) {
if (speedz < speed * 3) {
speedz += 0.1f;
}
if (speedz < 0) {
speedz = speed;
if (GetAsyncKeyState('S')) {
localPos.x -= (dx * speed);
localPos.y -= (dy * speed);
localPos.z -= (dz * speed);
}
localz += speedz;
}
if (GetAsyncKeyState(VK_CONTROL)) {
if (speedy < speed * 3) {
speedy += 0.1f;
if (GetAsyncKeyState('A')) {

}
if (speedy < 0) {
speedy = speed;
if (GetAsyncKeyState('D')) {

}
localy += speedy;
}
if (GetAsyncKeyState(VK_LSHIFT)) {
if (speedy > -speed * 3) {
speedy -= 0.1f;
if (GetAsyncKeyState(VK_CONTROL)) {

}
if (speedy > 0) {
speedy = -speed;
if (GetAsyncKeyState(VK_LSHIFT)) {

}
localy += speedy;
}



//set the actual pos variables to the local ones
WriteProcessMemory(h, (LPVOID)xAddress, &localx, sizeof(localx), nullptr);
WriteProcessMemory(h, (LPVOID)yAddress, &localy, sizeof(localy), nullptr);
WriteProcessMemory(h, (LPVOID)zAddress, &localz, sizeof(localz), nullptr);

//set the actual pos variables to the local ones
localPos = g.updateIfAddrChanged(localPos);
g.setPos(localPos);
}
Sleep(1);
}

CloseHandle(h);
}
21 changes: 19 additions & 2 deletions ThorsGolfItHack/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@
#include <string>
#include <psapi.h>
#include <TlHelp32.h>
#include <functional>

namespace mem {
//"GolfIt-Win64-Shipping.exe"+0x05948FE8
std::vector <unsigned int> xoffsets = { 0x8,0x0,0x58,0x0,0x0,0x88, 0x10 };
std::vector <unsigned int> zoffsets = { 0x8,0x0,0x58,0x0,0x0,0x88, 0x14 };
std::vector <unsigned int> yoffsets = { 0x8,0x0,0x58,0x0,0x0,0x88, 0x18 };

std::vector <unsigned int> xveloffsets = { 0x8,0x0,0x58,0x0,0x0,0x88, 0x40 };
std::vector <unsigned int> zveloffsets = { 0x8,0x0,0x58,0x0,0x0,0x88, 0x44 };
std::vector <unsigned int> yveloffsets = { 0x8,0x0,0x58,0x0,0x0,0x88, 0x48 };
//"GolfIt-Win64-Shipping.exe"+057DD8C8
std::vector <unsigned int> cameraQuatXOffsets = { 0xE8,0x128,0x1A0,0xA0,0x28,0x130, 0x0 };
std::vector <unsigned int> cameraQuatZOffsets = { 0xE8,0x128,0x1A0,0xA0,0x28,0x130, 0x4 };
std::vector <unsigned int> cameraQuatYOffsets = { 0xE8,0x128,0x1A0,0xA0,0x28,0x130, 0x8 };
std::vector <unsigned int> cameraQuatWOffsets = { 0xE8,0x128,0x1A0,0xA0,0x28,0x130, 0xC };

std::vector <unsigned int> cameraXOffsets = { 0xE8,0x128,0x1A0,0xA0,0x28,0x130, 0x10 };
std::vector <unsigned int> cameraZOffsets = { 0xE8,0x128,0x1A0,0xA0,0x28,0x130, 0x14 };
std::vector <unsigned int> cameraYOffsets = { 0xE8,0x128,0x1A0,0xA0,0x28,0x130, 0x18 };

}


Expand Down Expand Up @@ -90,15 +102,20 @@ class Memory {
ReadProcessMemory(proc, (BYTE*)ptrVal, &val, sizeof(val), nullptr);
return val;
}
static float readChar(HANDLE proc, uintptr_t ptrVal) {
static char readChar(HANDLE proc, uintptr_t ptrVal) {
char val = 0;
ReadProcessMemory(proc, (BYTE*)ptrVal, &val, sizeof(val), nullptr);
return val;
}
static float readLong(HANDLE proc, uintptr_t ptrVal) {
static long readLong(HANDLE proc, uintptr_t ptrVal) {
long val = 0;
ReadProcessMemory(proc, (BYTE*)ptrVal, &val, sizeof(val), nullptr);
return val;
}
static bool readBool(HANDLE proc, uintptr_t ptrVal) {
bool val = 0;
ReadProcessMemory(proc, (BYTE*)ptrVal, &val, sizeof(val), nullptr);
return val;
}

};

0 comments on commit 5ebd065

Please sign in to comment.