Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

LoL Camera tweaks (now with toggle and smoothing!)

By: a guest on Apr 5th, 2013  |  syntax: C  |  size: 2.89 KB  |  hits: 41  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include "Win32Tools/Win32Tools.h"
  2. #include "MemProc/MemProc.h"
  3. #include "Vector/Vector2D.h"
  4.  
  5. #include <winuser.h>
  6.  
  7. typedef struct {
  8.         DWORD addrX, addrY;
  9.         Vector2D v;
  10. } Pos;
  11.  
  12. Pos *
  13. pos_new (MemProc *mp, DWORD addrX, DWORD addrY)
  14. {
  15.         Pos *p;
  16.  
  17.         if ((p = malloc(sizeof(Pos))) == NULL)
  18.                 return NULL;
  19.  
  20.         p->addrX = addrX + mp->base_addr;
  21.         p->addrY = addrY + mp->base_addr;
  22.  
  23.         vector2D_set_pos (
  24.                 &p->v,
  25.                 read_memory_as_float(mp->proc, p->addrX),
  26.                 read_memory_as_float(mp->proc, p->addrY)
  27.         );
  28.  
  29.         return p;
  30. }
  31.  
  32. void
  33. pos_refresh (MemProc *mp, Pos *p)
  34. {
  35.         vector2D_set_pos (
  36.                 &p->v,
  37.                 read_memory_as_float(mp->proc, p->addrX),
  38.                 read_memory_as_float(mp->proc, p->addrY)
  39.         );
  40. }
  41.  
  42. void
  43. pos_set (MemProc *mp, Pos *p, float newX, float newY)
  44. {
  45.         vector2D_set_pos (&p->v, newX, newY);
  46.  
  47.         write_memory_as_float(mp->proc, p->addrX, newX);
  48.         write_memory_as_float(mp->proc, p->addrY, newY);
  49. }
  50.  
  51. int main()
  52. {
  53.         MemProc *mp = memproc_new("League of Legends.exe", "League of Legends (TM) Client");
  54.  
  55.         if (!mp->proc)
  56.         {
  57.                 error("Please launch a game");
  58.                 return 0;
  59.         }
  60.  
  61.         Pos *cam   = pos_new(mp, 0x039F713C, 0x039F7144);
  62.         Pos *champ = pos_new(mp, 0x039F7318, 0x039F7320);
  63.         Pos *mouse = pos_new(mp, 0x039F7324, 0x039F732C);
  64.  
  65.         float target_x = 0.0, target_y = 0.0;
  66.         float cam_x = 0.0, cam_y = 0.0;
  67.  
  68.         float lerp_rate = 0.003;    // this controls smoothing, smaller values mean slower camera movement
  69.         float threshold = 0.1;      // minimum threshold before calculations halted because camera is "close enough"
  70.  
  71.         int update_frames = 5;      // poll position data every x frames
  72.         int frame_count = 0;
  73.  
  74.         BOOL enabled = TRUE;
  75.  
  76.         int vkToggleKey = VK_F11;   // which key toggles the camera adjustments
  77.         short last_toggle_state = 0;
  78.  
  79.         while (1)
  80.         {
  81.             // listen for toggle key
  82.             short new_toggle_state = GetKeyState(vkToggleKey);
  83.             if (new_toggle_state != last_toggle_state && new_toggle_state >= 0)
  84.             enabled = !enabled;
  85.         last_toggle_state = new_toggle_state;
  86.  
  87.         // to allow minimap navigation, also disabled if LMB is down
  88.         if (GetKeyState(VK_LBUTTON) < 0)
  89.             continue;
  90.  
  91.         // skip if not enabled
  92.             if (!enabled)
  93.             continue;
  94.  
  95.             if (frame_count == 0)
  96.         {
  97.             // Get the position from the game
  98.             pos_refresh(mp, cam);
  99.             pos_refresh(mp, champ);
  100.             pos_refresh(mp, mouse);
  101.         }
  102.         else if (frame_count++ >= update_frames)
  103.             frame_count = 0;
  104.  
  105.         target_x = (champ->v.x + mouse->v.x) / 2.0;
  106.         target_y = (champ->v.y + mouse->v.y) / 2.0;
  107.  
  108.         if (abs(target_x - cam->v.x) > threshold)
  109.             cam_x = cam->v.x + ((target_x - cam->v.x) * lerp_rate);
  110.  
  111.         if (abs(target_y - cam->v.y) > threshold)
  112.             cam_y = cam->v.y + ((target_y - cam->v.y) * lerp_rate);
  113.  
  114.                 pos_set(mp, cam, cam_x, cam_y);
  115.  
  116.                 Sleep(1);
  117.         }
  118.  
  119.     return 0;
  120. }