#include "Win32Tools/Win32Tools.h"
#include "MemProc/MemProc.h"
#include "Vector/Vector2D.h"
#include <winuser.h>
typedef struct {
DWORD addrX, addrY;
Vector2D v;
} Pos;
Pos *
pos_new (MemProc *mp, DWORD addrX, DWORD addrY)
{
Pos *p;
if ((p = malloc(sizeof(Pos))) == NULL)
return NULL;
p->addrX = addrX + mp->base_addr;
p->addrY = addrY + mp->base_addr;
vector2D_set_pos (
&p->v,
read_memory_as_float(mp->proc, p->addrX),
read_memory_as_float(mp->proc, p->addrY)
);
return p;
}
void
pos_refresh (MemProc *mp, Pos *p)
{
vector2D_set_pos (
&p->v,
read_memory_as_float(mp->proc, p->addrX),
read_memory_as_float(mp->proc, p->addrY)
);
}
void
pos_set (MemProc *mp, Pos *p, float newX, float newY)
{
vector2D_set_pos (&p->v, newX, newY);
write_memory_as_float(mp->proc, p->addrX, newX);
write_memory_as_float(mp->proc, p->addrY, newY);
}
int main()
{
MemProc *mp = memproc_new("League of Legends.exe", "League of Legends (TM) Client");
if (!mp->proc)
{
error("Please launch a game");
return 0;
}
Pos *cam = pos_new(mp, 0x039F713C, 0x039F7144);
Pos *champ = pos_new(mp, 0x039F7318, 0x039F7320);
Pos *mouse = pos_new(mp, 0x039F7324, 0x039F732C);
float target_x = 0.0, target_y = 0.0;
float cam_x = 0.0, cam_y = 0.0;
float lerp_rate = 0.003; // this controls smoothing, smaller values mean slower camera movement
float threshold = 0.1; // minimum threshold before calculations halted because camera is "close enough"
int update_frames = 5; // poll position data every x frames
int frame_count = 0;
BOOL enabled = TRUE;
int vkToggleKey = VK_F11; // which key toggles the camera adjustments
short last_toggle_state = 0;
while (1)
{
// listen for toggle key
short new_toggle_state = GetKeyState(vkToggleKey);
if (new_toggle_state != last_toggle_state && new_toggle_state >= 0)
enabled = !enabled;
last_toggle_state = new_toggle_state;
// to allow minimap navigation, also disabled if LMB is down
if (GetKeyState(VK_LBUTTON) < 0)
continue;
// skip if not enabled
if (!enabled)
continue;
if (frame_count == 0)
{
// Get the position from the game
pos_refresh(mp, cam);
pos_refresh(mp, champ);
pos_refresh(mp, mouse);
}
else if (frame_count++ >= update_frames)
frame_count = 0;
target_x = (champ->v.x + mouse->v.x) / 2.0;
target_y = (champ->v.y + mouse->v.y) / 2.0;
if (abs(target_x - cam->v.x) > threshold)
cam_x = cam->v.x + ((target_x - cam->v.x) * lerp_rate);
if (abs(target_y - cam->v.y) > threshold)
cam_y = cam->v.y + ((target_y - cam->v.y) * lerp_rate);
pos_set(mp, cam, cam_x, cam_y);
Sleep(1);
}
return 0;
}