Ejemplo n.º 1
0
 private static unsafe void PerfTestReadBytesDirect(ExternalProcessReader reader)
 {
     fixed(byte *ptr = reader.ReadBytes(LocalPlayerNumKnownSpells, MarshalCache <int> .Size, true))
     {
         int val = *(int *)ptr;
     }
 }
Ejemplo n.º 2
0
 private static byte[] ReadBytes(Process process, IntPtr address, int count)
 {
     using (var reader = new ExternalProcessReader(process))
     {
         return(reader.ReadBytes(address, count));
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     Attach all manipulation related classes to the passed process.
 ///     ObjectManager and Hook related operations will be available after this call
 /// </summary>
 /// <param name="process"></param>
 public static void AttachToProcess(Process process)
 {
     lock (LockObject)
     {
         try
         {
             if (process.HasExited)
             {
                 Logger.Warn("The process you have selected has exited. Please select another.");
                 return;
             }
             if (IsAttached)
             {
                 DetachFromProcess();
             }
             if (Offsets.FindOffsets(process))
             {
                 Memory = new ExternalProcessReader(process);
                 if (DxHook.Apply())
                 {
                     Memory.ProcessExited += (sender, args) => DetachFromProcess();
                     Logger.Info("Attached to: " + process.Id);
                     return;
                 }
             }
         }
         catch (Exception ex)
         {
             Logger.Error("Failed to attach do to an exception.", ex);
         }
         DetachFromProcess();
         Logger.Warn("Failed to attach to: " + process.Id);
     }
 }
Ejemplo n.º 4
0
        public IntPtr Find(ExternalProcessReader bm)
        {
            var start = FindStart(bm);

            start = Modifiers.Aggregate(start, (current, mod) => mod.Apply(bm, current));
            return(start - (int)bm.Process.MainModule.BaseAddress);
        }
Ejemplo n.º 5
0
 public Hook(Process wowProc)
 {
     Memory      = new ExternalProcessReader(wowProc);
     _dx3D       = new Dirext3D(wowProc);
     _wowProcess = wowProc;
     Installed   = false;
 }
Ejemplo n.º 6
0
 internal static void Initialize(Process proc)
 {
     try
     {
         WoW    = new ExternalProcessReader(proc);
         WoWD3D = new WoW.DirectX.Dirext3D(proc);
     }
     catch (Exception ex)
     {
         Debug.Log("Error: Failed to initialize WhiteFish.");
         Debug.Log(string.Format("Error: {0}", ex.Message));
     }
 }
Ejemplo n.º 7
0
 public IntPtr Apply(ExternalProcessReader bm, IntPtr address)
 {
     switch (Type)
     {
         case LeaType.Byte:
             return (IntPtr)bm.Read<byte>(address);
         case LeaType.Word:
             return (IntPtr)bm.Read<ushort>(address);
         case LeaType.Dword:
             return (IntPtr)bm.Read<uint>(address);
     }
     throw new InvalidDataException("Unknown LeaType");
 }
Ejemplo n.º 8
0
        public IntPtr Apply(ExternalProcessReader bm, IntPtr address)
        {
            switch (Type)
            {
            case LeaType.Byte:
                return((IntPtr)bm.Read <byte>(address));

            case LeaType.Word:
                return((IntPtr)bm.Read <ushort>(address));

            case LeaType.Dword:
                return((IntPtr)bm.Read <uint>(address));
            }
            throw new InvalidDataException("Unknown LeaType");
        }
Ejemplo n.º 9
0
        private static void SetObjectType(ExternalProcessReader memory, IntPtr ptr)
        {
            var vtmPtr = memory.Read <IntPtr>(ptr + Offsets.UIObject.GetTypeNameVfuncOffset);

            if (IsValidTypePtr(memory, vtmPtr))
            {
                var strPtr = memory.Read <IntPtr>(false, vtmPtr + 1);
                var str    = memory.ReadString(strPtr, Encoding.UTF8, 128);
                UIObjectTypeCache[ptr] = GetUIObjectTypeFromString(str);
            }
            else
            {
                UIObjectTypeCache[ptr] = UIObjectType.None;
            }
        }
Ejemplo n.º 10
0
 private static bool IsValidTypePtr(ExternalProcessReader memory, IntPtr ptr)
 {
     if (ptr == IntPtr.Zero)
     {
         return(false);
     }
     try
     {
         var bytes = memory.ReadBytes(ptr, 6);
         return(bytes[0] == 0xA1 /* mov */ && bytes[5] == 0xC3 /* retn */);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 ///     Attach all manipulation related classes to the passed process.
 ///     ObjectManager and Hook related operations will be available after this call
 /// </summary>
 /// <param name="process"></param>
 public static void AttachToProcess(Process process)
 {
     lock (LockObject)
     {
         try
         {
             if (process.HasExited)
             {
                 Logger.Warn("The process you have selected has exited. Please select another.");
                 return;
             }
             if (IsAttached)
             {
                 DetachFromProcess();
             }
             if (Offsets.FindOffsets(process))
             {
                 Memory = new ExternalProcessReader(process);
                 if (DxHook.Apply())
                 {
                     Memory.ProcessExited += (sender, args) => DetachFromProcess();
                     Logger.Info("Attached to: " + process.Id);
                     return;
                 }
             }
         }
         catch (FileNotFoundException ex)
         {
             if (ex.FileName.Contains("fasmdll_managed"))
             {
                 Logger.Fatal(
                     "You have not downloaded a required prerequisite for CoolFish. Please visit the following download page for the Visual C++ Redistributable: http://www.microsoft.com/en-us/download/details.aspx?id=40784 (Download the vcredist_x86.exe when asked)");
             }
             else
             {
                 Logger.Error("Failed to attach do to an exception. Missing File: " + ex.FileName, (Exception)ex);
             }
         }
         catch (Exception ex)
         {
             Logger.Error("Failed to attach do to an exception.", ex);
         }
         DetachFromProcess();
         Logger.Warn("Failed to attach to: " + process.Id);
     }
 }
Ejemplo n.º 12
0
        private IntPtr FindStart(ExternalProcessReader bm)
        {
            var mainModule = bm.Process.MainModule;
            var start = mainModule.BaseAddress;
            var size = mainModule.ModuleMemorySize;
            var patternLength = Bytes.Length;

            for (uint i = 0; i < size - patternLength; i += (uint)(CacheSize - patternLength))
            {
                byte[] cache = bm.ReadBytes(start + (int)i, CacheSize > size - i ? size - (int)i : CacheSize);
                for (uint i2 = 0; i2 < (cache.Length - patternLength); i2++)
                {
                    if (DataCompare(cache, i2))
                        return start + (int)(i + i2);
                }
            }
            throw new InvalidDataException(string.Format("Pattern {0} not found",Name));
        }
Ejemplo n.º 13
0
        private IntPtr FindStart(ExternalProcessReader bm)
        {
            var mainModule    = bm.Process.MainModule;
            var start         = mainModule.BaseAddress;
            var size          = mainModule.ModuleMemorySize;
            var patternLength = Bytes.Length;

            for (uint i = 0; i < size - patternLength; i += (uint)(CacheSize - patternLength))
            {
                byte[] cache = bm.ReadBytes(start + (int)i, CacheSize > size - i ? size - (int)i : CacheSize);
                for (uint i2 = 0; i2 < (cache.Length - patternLength); i2++)
                {
                    if (DataCompare(cache, i2))
                    {
                        return(start + (int)(i + i2));
                    }
                }
            }
            throw new InvalidDataException(string.Format("Pattern {0} not found", Name));
        }
Ejemplo n.º 14
0
        /// <summary>
        ///     Attach all manipulation related classes to the passed process.
        ///     ObjectManager and Hook related operations will be available after this call
        /// </summary>
        /// <param name="process"></param>
        public static void AttachToProcess(Process process)
        {
            if (WasCut)
            {
                return;
            }
            StopActiveBot();
            try
            {
                if (Offsets.FindOffsets(process))
                {
                    Memory = new ExternalProcessReader(process);


                    if (DxHook.Instance.Apply())
                    {
                        Logging.Write(LocalSettings.Translations["Attached to"] + ": " +
                                      process.Id);
                    }
                    else
                    {
                        Logging.Write(LocalSettings.Translations["Error"]);

                        Memory.Dispose();
                        Memory = null;
                    }
                }
                else
                {
                    Logging.Write(LocalSettings.Translations["Unhandled Exception"]);
                }
            }
            catch (Exception ex)
            {
                Logging.Write(LocalSettings.Translations["Unhandled Exception"]);
                Logging.Log(ex);
            }
        }
Ejemplo n.º 15
0
 public IntPtr Apply(ExternalProcessReader bm, IntPtr addr)
 {
     return (addr + (int)Offset);
 }
Ejemplo n.º 16
0
 public LuaTString(ExternalProcessReader memory, IntPtr address)
 {
     Address = address;
     _memory = memory;
     _luaTString = memory.Read<LuaTStringHeader>(address);
 }
Ejemplo n.º 17
0
        /// <summary>
        /// </summary>
        public static void DetachFromProcess()
        {
            lock (LockObject)
            {
                try
                {
                    StopActiveBot();
                    DxHook.Restore();
                    if (Memory != null)
                    {
                        Memory.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("Exception thrown while detaching from process", ex);
                }

                Memory = null;
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 ///     Attach all manipulation related classes to the passed process.
 ///     ObjectManager and Hook related operations will be available after this call
 /// </summary>
 /// <param name="process"></param>
 public static void AttachToProcess(Process process)
 {
     lock (LockObject)
     {
         try
         {
             if (process.HasExited)
             {
                 Logger.Warn("The process you have selected has exited. Please select another.");
                 return;
             }
             if (IsAttached)
             {
                 DetachFromProcess();
             }
             if (Offsets.FindOffsets(process))
             {
                 Memory = new ExternalProcessReader(process);
                 if (DxHook.Apply())
                 {
                     Memory.ProcessExited += (sender, args) => DetachFromProcess();
                     Logger.Info("Attached to: " + process.Id);
                     return;
                 }
             }
         }
         catch (Exception ex)
         {
             Logger.Error("Failed to attach do to an exception.", ex);
         }
         DetachFromProcess();
         Logger.Warn("Failed to attach to: " + process.Id);
     }
 }
Ejemplo n.º 19
0
        private static void Main(string[] args)
        {
            Process[] procs = Process.GetProcessesByName("Wow");

            if (!procs.Any())
            {
                Console.WriteLine("You must run WoW first!");
                Console.ReadLine();
                return;
            }

            // First-run caching stuff. This can cause the perf tests to be skewed.
            int size = MarshalCache <int> .Size;

            size += MarshalCache <IntPtr> .Size;
            size += MarshalCache <MarshalStruct> .Size;
            size += MarshalCache <NonMarshalStruct> .Size;
            Console.WriteLine(size);

            var reader = new ExternalProcessReader(procs.First());

            var timer = new Stopwatch();

            // Cache these. They are somewhat slow to grab.
            SafeMemoryHandle handle  = reader.ProcessHandle;
            IntPtr           imgBase = reader.ImageBase;

            // Get JIT to compile our stuffs kthx
            PerfTestKnownSpells(reader);
            PerfTestKnownSpellsRPMDirect(handle, imgBase);
            PerfTestReadBytesDirect(reader);
            PerfTestMarshalStructRead(reader);
            PerfTestNonMarshalStructRead(reader);

            timer.Start();

            for (int i = 0; i < 1000000; i++)
            {
                PerfTestKnownSpells(reader);
            }

            timer.Stop();
            // This will take ~5k ticks to run. It has to go through the helper funcs for abstraction
            Console.WriteLine("PerfTestKnownSpells Took " + (timer.ElapsedTicks / 1000000f));
            timer.Reset();

            timer.Start();

            // This should be the absolute fastest. It skips all the abstraction API and uses RPM directly
            for (int i = 0; i < 1000000; i++)
            {
                PerfTestKnownSpellsRPMDirect(handle, imgBase);
            }

            timer.Stop();
            Console.WriteLine("PerfTestKnownSpellsRPMDirect Took " + (timer.ElapsedTicks / 1000000f));
            timer.Reset();

            timer.Start();

            // This should be only slightly slower than RPMDirect. It derefs a byte buffer directly.
            for (int i = 0; i < 1000000; i++)
            {
                PerfTestReadBytesDirect(reader);
            }

            timer.Stop();
            Console.WriteLine("PerfTestReadBytesDirect Took " + (timer.ElapsedTicks / 1000000f));
            timer.Reset();

            timer.Start();

            // This should be only slightly slower than RPMDirect. It derefs a byte buffer directly.
            for (int i = 0; i < 1000000; i++)
            {
                PerfTestNonMarshalStructRead(reader);
            }

            timer.Stop();
            Console.WriteLine("PerfTestNonMarshalStructRead Took " + (timer.ElapsedTicks / 1000000f));
            timer.Reset();

            timer.Start();

            // This should be only slightly slower than RPMDirect. It derefs a byte buffer directly.
            for (int i = 0; i < 1000000; i++)
            {
                PerfTestMarshalStructRead(reader);
            }

            timer.Stop();
            Console.WriteLine("PerfTestMarshalStructRead Took " + (timer.ElapsedTicks / 1000000f));
            timer.Reset();

            Console.ReadLine();
        }
Ejemplo n.º 20
0
 internal LuaValue(ExternalProcessReader memory, LuaValueStruct luaValue)
 {
     _luaValue = luaValue;
     _memory   = memory;
 }
Ejemplo n.º 21
0
        internal static void Run(int?pId = null)
        {
            int?tmpPiD = pId;

            try
            {
                IntPtr?procHandle = null;
                if (tmpPiD == null)
                {
                    tmpPiD = LaunchWowProcess();
                }
                else
                {
                    procHandle = WinImports.OpenProcess(0x001F0FFF, false, tmpPiD.Value);
                }

                var proc = Process.GetProcessById(tmpPiD.Value);
                //MessageBox.Show("ID:" + proc.Id);


                if (procHandle == null)
                {
                    procHandle = proc.Handle;
                }
                //MessageBox.Show("Handle:" + proc.Handle);

                if (proc.Id == 0)
                {
                    MessageBox.Show(
                        "Couldnt get the WoW process. Is the path in Settings.xml right? If no delete it and rerun ZzukBot");
                    return;
                }
                proc.WaitForInputIdle();
                //MessageBox.Show("Wait for input handle");
                var reader = new ExternalProcessReader(proc);

                var loadDllPtr = WinImports.GetProcAddress(WinImports.GetModuleHandle("kernel32.dll"), "LoadLibraryW");
                //MessageBox.Show("loadDllPtr: " + loadDllPtr.ToString("X"));
                if (loadDllPtr == IntPtr.Zero)
                {
                    MessageBox.Show("Couldnt get address of LoadLibraryW");
                    return;
                }

                var LoaderStrPtr = reader.AllocateMemory(500);
                if (LoaderStrPtr == IntPtr.Zero)
                {
                    MessageBox.Show("Couldnt allocate memory 2");
                    return;
                }

                var LoaderStr =
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
                    + "\\Loader.dll";
                //MessageBox.Show(LoaderStr);

                var res = reader.WriteString(LoaderStrPtr, LoaderStr, Encoding.Unicode);
                if (!res)
                {
                    MessageBox.Show("Couldnt write dll path to WoW's memory");
                    return;
                }

                var test = WinImports.CreateRemoteThread(procHandle.Value, (IntPtr)null, (IntPtr)0, loadDllPtr,
                                                         LoaderStrPtr, 0,
                                                         (IntPtr)null);
                if (test
                    == (IntPtr)0)
                {
                    MessageBox.Show("Couldnt inject the dll");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 22
0
        internal static void Run(int?pId = null)
        {
            try
            {
                IntPtr?procHandle = null;
                if (pId == null)
                {
                    var doc     = XDocument.Load("..\\Settings\\Settings.xml");
                    var element = doc.Element("Settings");
                    var tmpPath = element.Element("Path").Value;

                    var si = new WinImports.STARTUPINFO();
                    WinImports.PROCESS_INFORMATION pi;
                    WinImports.CreateProcess(tmpPath, null,
                                             IntPtr.Zero, IntPtr.Zero, false,
                                             WinImports.ProcessCreationFlags.CREATE_DEFAULT_ERROR_MODE,
                                             IntPtr.Zero, null, ref si, out pi);
                    pId = (int)pi.dwProcessId;
                    //MessageBox.Show("1");
                }
                else
                {
                    procHandle = WinImports.OpenProcess(0x001F0FFF, false, pId.Value);
                }
                var proc = Process.GetProcessById(pId.Value);
                //MessageBox.Show("ID:" + proc.Id);


                if (procHandle == null)
                {
                    procHandle = proc.Handle;
                }
                //MessageBox.Show("Handle:" + proc.Handle);

                if (proc.Id == 0)
                {
                    MessageBox.Show(
                        "Couldnt get the WoW process. Is the path in Settings.xml right? If no delete it and rerun ZzukBot");
                    return;
                }
                proc.WaitForInputIdle();
                //MessageBox.Show("Wait for input handle");
                var reader = new ExternalProcessReader(proc);

                var loadDllPtr = WinImports.GetProcAddress(WinImports.GetModuleHandle("kernel32.dll"), "LoadLibraryW");
                //MessageBox.Show("loadDllPtr: " + loadDllPtr.ToString("X"));
                if (loadDllPtr == IntPtr.Zero)
                {
                    MessageBox.Show("Couldnt get address of LoadLibraryW");
                    return;
                }

                var LoaderStrPtr = reader.AllocateMemory(500);
                if (LoaderStrPtr == IntPtr.Zero)
                {
                    MessageBox.Show("Couldnt allocate memory 2");
                    return;
                }

                var LoaderStr =
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
                    + "\\Loader.dll";
                //MessageBox.Show(LoaderStr);

                var res = reader.WriteString(LoaderStrPtr, LoaderStr, Encoding.Unicode);
                if (!res)
                {
                    MessageBox.Show("Couldnt write dll path to WoW's memory");
                    return;
                }

                var test = WinImports.CreateRemoteThread(procHandle.Value, (IntPtr)null, (IntPtr)0, loadDllPtr,
                                                         LoaderStrPtr, 0,
                                                         (IntPtr)null);
                if (test
                    == (IntPtr)0)
                {
                    MessageBox.Show("Couldnt inject the dll");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 23
0
 public IntPtr Find(ExternalProcessReader bm)
 {
     var start = FindStart(bm);
     start = Modifiers.Aggregate(start, (current, mod) => mod.Apply(bm, current));
     return start - (int)bm.Process.MainModule.BaseAddress;
 }
Ejemplo n.º 24
0
 public LuaTable(ExternalProcessReader memory, IntPtr address)
 {
     Address   = address;
     _memory   = memory;
     _luaTable = _memory.Read <LuaTableStuct>(address);
 }
Ejemplo n.º 25
0
 public LuaTKey(ExternalProcessReader memory, LuaTKeyStruct luaTKeyStruct)
 {
     _luaTKeyStruct = luaTKeyStruct;
     _memory = memory;
 }
Ejemplo n.º 26
0
 private static unsafe void PerfTestReadBytesDirect(ExternalProcessReader reader)
 {
     fixed (byte* ptr = reader.ReadBytes(LocalPlayerNumKnownSpells, MarshalCache<int>.Size, true))
     {
         int val = *(int*) ptr;
     }
 }
Ejemplo n.º 27
0
 private static void PerfTestKnownSpells(ExternalProcessReader reader)
 {
     reader.Read<int>(LocalPlayerNumKnownSpells, true);
 }
Ejemplo n.º 28
0
 public LuaNode(ExternalProcessReader memory, IntPtr address)
 {
     Address  = address;
     _memory  = memory;
     _luaNode = memory.Read <LuaNodeStruct>(address);
 }
Ejemplo n.º 29
0
 internal LuaValue(ExternalProcessReader memory, LuaValueStruct luaValue)
 {
     _luaValue = luaValue;
     _memory = memory;
 }
Ejemplo n.º 30
0
 public LuaTable(ExternalProcessReader memory, IntPtr address)
 {
     Address = address;
     _memory = memory;
     _luaTable = _memory.Read<LuaTableStuct>(address);
 }
Ejemplo n.º 31
0
 public LuaNode(ExternalProcessReader memory, IntPtr address)
 {
     Address = address;
     _memory = memory;
     _luaNode = memory.Read<LuaNodeStruct>(address);
 }
Ejemplo n.º 32
0
        /// <summary>
        /// Injects the bot into the game client
        /// </summary>
        async Task Inject()
        {
            await Task.Run(() =>
            {
                try
                {
                    $"Loading path of WoW.exe from the settings".Log(Logs.PreInject);

                    $"Starting up the WoW process".Log(Logs.PreInject);

                    var si = new WinImports.STARTUPINFO();

                    WinImports.CreateProcess(Default.PathToWoW, null,
                                             IntPtr.Zero, IntPtr.Zero, false,
                                             WinImports.ProcessCreationFlags.CREATE_DEFAULT_ERROR_MODE,
                                             IntPtr.Zero, null, ref si, out WinImports.PROCESS_INFORMATION pi);

                    var proc = Process.GetProcessById((int)pi.dwProcessId);

                    if (proc.Id == 0)
                    {
                        MessageBox.Show(
                            "Couldnt get the WoW process. Is the path in Settings.xml right? If no delete it and rerun ZzukBot");

                        return;
                    }

                    $"Waiting for WoW process to initialise".Log(Logs.PreInject);

                    while (!proc.WaitForInputIdle(1000))
                    {
                        $"WaitForInputIdle returned false. Trying again".Log(Logs.PreInject);
                        proc.Refresh();
                    }

                    while (string.IsNullOrWhiteSpace(proc.MainWindowTitle))
                    {
                        Thread.Sleep(200);
                        proc.Refresh();
                    }

                    Thread.Sleep(2000);

                    $"Initialising new ProcessReader".Log(Logs.PreInject);

                    using (var reader = new ExternalProcessReader(proc))
                    {
                        $"Retrieving function addresses for injection".Log(Logs.PreInject);

                        var loadDllPtr = WinImports.GetProcAddress(WinImports.GetModuleHandle("kernel32.dll"), "LoadLibraryW");

                        if (loadDllPtr == IntPtr.Zero)
                        {
                            MessageBox.Show("Couldnt get address of LoadLibraryW");

                            return;
                        }

                        $"Allocating memory for injection".Log(Logs.PreInject);

                        var LoaderStrPtr = reader.AllocateMemory(1000);

                        if (LoaderStrPtr == IntPtr.Zero)
                        {
                            MessageBox.Show("Couldnt allocate memory 2");

                            return;
                        }

                        var LoaderStr = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Loader.dll";

                        $"Preparing Loader.dll for injection".Log(Logs.PreInject);

                        var res = reader.WriteString(LoaderStrPtr, LoaderStr, Encoding.Unicode);

                        if (!res)
                        {
                            MessageBox.Show("Couldnt write dll path to WoW's memory");

                            return;
                        }

                        Thread.Sleep(1000);

                        $"Starting injection".Log(Logs.PreInject);

                        if (WinImports.CreateRemoteThread(proc.Handle, (IntPtr)null, (IntPtr)0, loadDllPtr, LoaderStrPtr, 0, (IntPtr)null) == (IntPtr)0)
                        {
                            MessageBox.Show("Couldnt inject the dll");
                        }

                        Thread.Sleep(1);

                        "Freeing allocated memory for injection".Log(Logs.PreInject);

                        reader.FreeMemory(LoaderStrPtr);
                    }
                }
                catch (Exception e)
                {
                    $"Exception occured while injecting: {e.Message}".Log(Logs.PreInject);
                    MessageBox.Show(e.Message);
                }
            });
        }
Ejemplo n.º 33
0
 public LuaTString(ExternalProcessReader memory, IntPtr address)
 {
     Address     = address;
     _memory     = memory;
     _luaTString = memory.Read <LuaTStringHeader>(address);
 }
Ejemplo n.º 34
0
 public IntPtr Apply(ExternalProcessReader bm, IntPtr addr)
 {
     return(addr + (int)Offset);
 }
Ejemplo n.º 35
0
 private static void PerfTestMarshalStructRead(ExternalProcessReader reader)
 {
     reader.Read <MarshalStruct>(LocalPlayerNumKnownSpells, true);
 }
Ejemplo n.º 36
0
 private static void PerfTestMarshalStructRead(ExternalProcessReader reader)
 {
     reader.Read<MarshalStruct>(LocalPlayerNumKnownSpells, true);
 }
Ejemplo n.º 37
0
 public LuaTKey(ExternalProcessReader memory, LuaTKeyStruct luaTKeyStruct)
 {
     _luaTKeyStruct = luaTKeyStruct;
     _memory        = memory;
 }
Ejemplo n.º 38
0
        private static void Main(string[] args)
        {
            Process[] procs = Process.GetProcessesByName("Wow");

            if (!procs.Any())
            {
                Console.WriteLine("You must run WoW first!");
                Console.ReadLine();
                return;
            }

            // First-run caching stuff. This can cause the perf tests to be skewed.
            int size = MarshalCache<int>.Size;
            size += MarshalCache<IntPtr>.Size;
            size += MarshalCache<MarshalStruct>.Size;
            size += MarshalCache<NonMarshalStruct>.Size;
            Console.WriteLine(size);

            var reader = new ExternalProcessReader(procs.First());

            var timer = new Stopwatch();

            // Cache these. They are somewhat slow to grab.
            SafeMemoryHandle handle = reader.ProcessHandle;
            IntPtr imgBase = reader.ImageBase;
            // Get JIT to compile our stuffs kthx
            PerfTestKnownSpells(reader);
            PerfTestKnownSpellsRPMDirect(handle, imgBase);
            PerfTestReadBytesDirect(reader);
            PerfTestMarshalStructRead(reader);
            PerfTestNonMarshalStructRead(reader);

            timer.Start();

            for (int i = 0; i < 1000000; i++)
            {
                PerfTestKnownSpells(reader);
            }

            timer.Stop();
            // This will take ~5k ticks to run. It has to go through the helper funcs for abstraction
            Console.WriteLine("PerfTestKnownSpells Took " + (timer.ElapsedTicks / 1000000f));
            timer.Reset();

            timer.Start();

            // This should be the absolute fastest. It skips all the abstraction API and uses RPM directly
            for (int i = 0; i < 1000000; i++)
                PerfTestKnownSpellsRPMDirect(handle, imgBase);

            timer.Stop();
            Console.WriteLine("PerfTestKnownSpellsRPMDirect Took " + (timer.ElapsedTicks / 1000000f));
            timer.Reset();

            timer.Start();

            // This should be only slightly slower than RPMDirect. It derefs a byte buffer directly.
            for (int i = 0; i < 1000000; i++)
                PerfTestReadBytesDirect(reader);

            timer.Stop();
            Console.WriteLine("PerfTestReadBytesDirect Took " + (timer.ElapsedTicks / 1000000f));
            timer.Reset();

            timer.Start();

            // This should be only slightly slower than RPMDirect. It derefs a byte buffer directly.
            for (int i = 0; i < 1000000; i++)
                PerfTestNonMarshalStructRead(reader);

            timer.Stop();
            Console.WriteLine("PerfTestNonMarshalStructRead Took " + (timer.ElapsedTicks / 1000000f));
            timer.Reset();

            timer.Start();

            // This should be only slightly slower than RPMDirect. It derefs a byte buffer directly.
            for (int i = 0; i < 1000000; i++)
                PerfTestMarshalStructRead(reader);

            timer.Stop();
            Console.WriteLine("PerfTestMarshalStructRead Took " + (timer.ElapsedTicks / 1000000f));
            timer.Reset();

            Console.ReadLine();
        }
Ejemplo n.º 39
0
 private static void PerfTestKnownSpells(ExternalProcessReader reader)
 {
     reader.Read <int>(LocalPlayerNumKnownSpells, true);
 }