Advertisement
DjingaD

dota_camera_distance CVAR unlocker

Jan 23rd, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7.  
  8. namespace dotacamzoom
  9. {
  10.     class Program
  11.     {
  12.         #region pinvoke crap
  13.         [DllImport("kernel32.dll")]
  14.         static extern IntPtr LoadLibraryEx(string fileName, IntPtr file, LoadLibraryFlags flags);
  15.         [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
  16.         static extern IntPtr GetProcAddress(IntPtr module, string procName);
  17.         [DllImport("kernel32.dll", SetLastError = true)]
  18.         static extern bool ReadProcessMemory(
  19.           IntPtr hProcess,
  20.           IntPtr lpBaseAddress,
  21.           [Out] byte[] lpBuffer,
  22.           int dwSize,
  23.           out int lpNumberOfBytesRead
  24.          );
  25.         [DllImport("kernel32.dll", SetLastError = true)]
  26.         static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int nSize, out int lpNumberOfBytesWritten);
  27.  
  28.         [Flags]
  29.         enum LoadLibraryFlags : uint
  30.         {    
  31.              DONT_RESOLVE_DLL_REFERENCES = 0x00000001,
  32.              LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010,
  33.              LOAD_LIBRARY_AS_DATAFILE = 0x00000002,
  34.              LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040,
  35.              LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020,
  36.              LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008
  37.         }
  38.         #endregion
  39.  
  40.         static void Main(string[] args)
  41.         {
  42.             try
  43.             {
  44.                 Console.WriteLine("dota_camera_distance unlocker, by DjingaD");
  45.  
  46.                 Process dota = Process.GetProcesses().Where(x => x.ProcessName == "dota").FirstOrDefault();
  47.  
  48.                 if (dota == default(Process))
  49.                 {
  50.                     throw new Exception("dota.exe not found");
  51.                 }
  52.  
  53.                 ProcessModule vstdlib = null;
  54.  
  55.                 foreach (ProcessModule p in dota.Modules)
  56.                 {
  57.                     if (p.ModuleName == "vstdlib.dll")
  58.                     {
  59.                         vstdlib = p;
  60.                         break;
  61.                     }
  62.                 }
  63.  
  64.                 if (vstdlib == null)
  65.                 {
  66.                     throw new Exception("vstdlib not found");
  67.                 }
  68.  
  69.                 IntPtr vstdlibDll = LoadLibraryEx(vstdlib.FileName, IntPtr.Zero, LoadLibraryFlags.DONT_RESOLVE_DLL_REFERENCES);
  70.  
  71.                 if (vstdlibDll == IntPtr.Zero)
  72.                 {
  73.                     throw new Exception("couldnt load vstdlibDll");
  74.                 }
  75.  
  76.                 IntPtr createInterfaceFn = GetProcAddress(vstdlibDll, "CreateInterface");
  77.  
  78.                 if (createInterfaceFn == IntPtr.Zero)
  79.                 {
  80.                     throw new Exception("createInterfaceFn not found");
  81.                 }
  82.  
  83.                 IntPtr interfaces = createInterfaceFn;
  84.                 interfaces = IntPtr.Add(interfaces, 5);
  85.                 interfaces = IntPtr.Add(interfaces, Marshal.ReadInt32(interfaces) + 4);
  86.                 interfaces = IntPtr.Add(interfaces, 6);
  87.  
  88.                 interfaces = new IntPtr(Marshal.ReadInt32(interfaces) - vstdlibDll.ToInt32());
  89.  
  90.                 IntPtr vstdlibInterface = ReadIntPtr(dota, IntPtr.Add(interfaces, vstdlib.BaseAddress.ToInt32()));
  91.  
  92.                 IntPtr engineCVar = IntPtr.Zero;
  93.  
  94.                 while (vstdlibInterface != IntPtr.Zero)
  95.                 {
  96.                     string interfaceName = ReadString(dota, ReadIntPtr(dota, IntPtr.Add(vstdlibInterface, 0x04)));
  97.  
  98.                     if (interfaceName == "VEngineCvar007")
  99.                     {
  100.                         engineCVar = ReadIntPtr(dota, IntPtr.Add(ReadIntPtr(dota, vstdlibInterface), 1));
  101.                         break;
  102.                     }
  103.  
  104.                     vstdlibInterface = ReadIntPtr(dota, IntPtr.Add(vstdlibInterface, 0x08));
  105.                 }
  106.  
  107.                 if (engineCVar == IntPtr.Zero)
  108.                 {
  109.                     throw new Exception("Couldnt find VEngineCvar007");
  110.                 }
  111.  
  112.                 IntPtr cvar = ReadIntPtr(dota, IntPtr.Add(engineCVar, 0x34));
  113.                 cvar = IntPtr.Add(cvar, 0xC3 * 4);
  114.                 cvar = ReadIntPtr(dota, cvar);
  115.  
  116.                 while (cvar != IntPtr.Zero)
  117.                 {
  118.                     if (ReadInt(dota, cvar) == 0x0000D2C3)
  119.                     {
  120.                         cvar = ReadIntPtr(dota, IntPtr.Add(cvar, 0x04));
  121.                         break;
  122.                     }
  123.  
  124.                     cvar = ReadIntPtr(dota, IntPtr.Add(cvar, 0x0C));
  125.                 }
  126.  
  127.                 if (cvar == IntPtr.Zero)
  128.                 {
  129.                     throw new Exception("Cvar not found!");
  130.                 }
  131.  
  132.                 WriteInt(dota, IntPtr.Add(cvar, 0x14), 0x08);
  133.                 Console.WriteLine("dota_camera_distance cvar has been unlocked!");
  134.                 Console.ReadKey();
  135.             }
  136.             catch (Exception e)
  137.             {
  138.                 Console.WriteLine(e);
  139.                 Console.ReadKey();
  140.             }
  141.         }
  142.  
  143.         private static int ReadInt(Process proc, IntPtr offset)
  144.         {
  145.             byte[] buf = new byte[4];
  146.             int r;
  147.             ReadProcessMemory(proc.Handle, offset, buf, 4, out r);
  148.             return BitConverter.ToInt32(buf, 0);
  149.         }
  150.  
  151.         private static IntPtr ReadIntPtr(Process proc, IntPtr offset)
  152.         {
  153.             return new IntPtr(ReadInt(proc, offset));
  154.         }
  155.  
  156.         private static string ReadString(Process proc, IntPtr offset)
  157.         {
  158.             byte[] buf = new byte[128];
  159.             int r;
  160.             ReadProcessMemory(proc.Handle, offset, buf, 128, out r);
  161.  
  162.             int endIndex = 0;
  163.  
  164.             for (int i = 0; i < buf.Length; i++)
  165.             {
  166.                 if (buf[i] == '\0')
  167.                 {
  168.                     endIndex = i;
  169.                     break;
  170.                 }
  171.             }
  172.  
  173.             return ASCIIEncoding.ASCII.GetString(buf, 0, endIndex);
  174.         }
  175.  
  176.         private static void WriteInt(Process proc, IntPtr offset, int value)
  177.         {
  178.             byte[] buf = BitConverter.GetBytes(value);
  179.             int w;
  180.             WriteProcessMemory(proc.Handle, offset, buf, buf.Length, out w);
  181.         }
  182.     }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement