Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

70 řádky
2.2 KiB

  1. using RenderHookAPI;
  2. using RenderHookAPI.Hook;
  3. using RenderHookAPI.Interface;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Windows.Forms;
  10. namespace DamnOverSharp.Renderers.Graphic
  11. {
  12. public class GraphicRenderer
  13. {
  14. internal Process HookedProcess;
  15. private CaptureProcess CaptureProcess;
  16. private RenderHookAPI.Hook.Common.ImageElement FrameElement = new RenderHookAPI.Hook.Common.ImageElement();
  17. public GraphicRenderer(string processName)
  18. {
  19. CaptureConfig config = new CaptureConfig()
  20. {
  21. Direct3DVersion = Direct3DVersion.AutoDetect,
  22. ShowOverlay = true
  23. };
  24. CaptureInterface captureInterface = new CaptureInterface();
  25. captureInterface.RemoteMessage += new MessageReceivedEvent((msg) => Debug.WriteLine(msg));
  26. HookedProcess = Process.GetProcessesByName(processName).First();
  27. CaptureProcess = new CaptureProcess(HookedProcess, config, captureInterface);
  28. }
  29. public void Draw(Bitmap frame, Point topLeft, bool allowTransparency = true)
  30. {
  31. Draw(ImageToByteArray(frame, allowTransparency), topLeft);
  32. }
  33. public static byte[] ImageToByteArray(Image img, bool allowTransparency = true)
  34. {
  35. using (var stream = new MemoryStream())
  36. {
  37. img.Save(stream, allowTransparency ? System.Drawing.Imaging.ImageFormat.Png : System.Drawing.Imaging.ImageFormat.Jpeg);
  38. return stream.ToArray();
  39. }
  40. }
  41. public void Draw(byte[] frame, Point topLeft)
  42. {
  43. FrameElement.Location = topLeft;
  44. FrameElement.Image = frame;
  45. CaptureProcess.CaptureInterface.DrawOverlayInGame(new RenderHookAPI.Hook.Common.Overlay
  46. {
  47. Elements = new List<RenderHookAPI.Hook.Common.IOverlayElement>
  48. {
  49. FrameElement
  50. }
  51. });
  52. }
  53. public void Destroy()
  54. {
  55. HookManager.RemoveHookedProcess(HookedProcess.Id);
  56. CaptureProcess.Dispose();
  57. HookedProcess.Dispose();
  58. }
  59. }
  60. }