lolimoska

Untitled

Jun 13th, 2021
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. import pygame
  2. import win32api
  3. import win32con
  4. import win32gui
  5. import sys
  6. import os
  7. import keyboard
  8.  
  9. TRANSPARENT = (255, 0, 128)
  10. NOSIZE = 1
  11. NOMOVE = 2
  12. TOPMOST = -1
  13. NOT_TOPMOST = -2
  14.  
  15. class Vector:
  16. def __init__(self, x, y, w, h):
  17. self.x = x
  18. self.y = y
  19. self.w = w
  20. self.h = h
  21. def __ne__(self, other):
  22. this = self.x + self.y + self.w + self.h
  23. _other = other.x + other.y + other.w + other.h
  24. return this != _other
  25.  
  26. class Figure:
  27. def __init__(self, vector, color):
  28. self.vector = vector
  29. self.color = color
  30.  
  31. class Rectangle(Figure):
  32. def __init__(self, vector, color):
  33. self.type = "Rectangle"
  34. super().__init__(vector, color)
  35.  
  36. class Circle(Figure):
  37. def __init__(self, vector, color, thickness, radius):
  38. self.type = "Circle"
  39. self.thickness = thickness
  40. self.radius = radius
  41. super().__init__(vector, color)
  42.  
  43. class Line(Figure):
  44. def __init__(self, vector, color, thickness): #x = x1, y = y1, w = x2, h = y2
  45. self.type = "Line"
  46. self.thickness = thickness
  47. super().__init__(vector, color)
  48.  
  49. class Text(Figure):
  50. def __init__(self, vector, color, text, fontObject):
  51. self.type = "Text"
  52. self.text = text
  53. self.fontObject = fontObject
  54. super().__init__(vector, color)
  55.  
  56. class Overlay:
  57. def __init__(self, WindowTitle):
  58. self.figuresToDraw = []
  59.  
  60. #Get Target Window And Rect
  61. self.targetHwnd = win32gui.FindWindow(None, WindowTitle)
  62. if not self.targetHwnd:
  63. sys.exit(f"Window Not Found: {WindowTitle}")
  64. self.targetRect = self.GetTargetWindowRect()
  65.  
  66. #Init Pygame
  67. os.environ['SDL_VIDEO_WINDOW_POS'] = str(self.targetRect.x) + "," + str(self.targetRect.y)
  68. pygame.init()
  69. self.screen = pygame.display.set_mode((self.targetRect.w, self.targetRect.h), pygame.NOFRAME)
  70. self.hWnd = pygame.display.get_wm_info()['window']
  71. win32gui.SetWindowLong(self.hWnd, win32con.GWL_EXSTYLE, win32gui.GetWindowLong(self.hWnd, win32con.GWL_EXSTYLE) | win32con.WS_EX_LAYERED)
  72. win32gui.SetLayeredWindowAttributes(self.hWnd, win32api.RGB(*TRANSPARENT), 0, win32con.LWA_COLORKEY)
  73. win32gui.BringWindowToTop(self.hWnd)
  74. win32gui.SetWindowPos(self.hWnd, TOPMOST, 0, 0, 0, 0, NOMOVE | NOSIZE)
  75. self.window = True
  76.  
  77. def GetTargetWindowRect(self):
  78. rect = win32gui.GetWindowRect(self.targetHwnd)
  79. ret = Vector(rect[0], rect[1], rect[2] - rect[0], rect[3] - rect[1])
  80. return ret
  81.  
  82. def handle(self):
  83. win32gui.SetWindowPos(self.hWnd, TOPMOST, self.targetRect.x, self.targetRect.y, 0, 0, NOMOVE | NOSIZE)
  84. for event in pygame.event.get():
  85. if event.type == pygame.QUIT:
  86. self.window = False
  87. if self.targetRect != self.GetTargetWindowRect():
  88. self.targetRect = self.GetTargetWindowRect()
  89. win32gui.SetWindowPos(self.hWnd, TOPMOST, 0, 0, 0, 0, NOMOVE | NOSIZE)
  90. win32gui.MoveWindow(self.hWnd, self.targetRect.x, self.targetRect.y, self.targetRect.w, self.targetRect.h, True)
  91.  
  92. self.screen.fill(TRANSPARENT)
  93. for figure in self.figuresToDraw:
  94. if figure.type == "Rectangle":
  95. pygame.draw.rect(self.screen, figure.color, pygame.Rect(figure.vector.x, figure.vector.y, figure.vector.w, figure.vector.h))
  96. elif figure.type == "Circle":
  97. pygame.draw.circle(self.screen, figure.color, (figure.vector.x, figure.vector.y), figure.radius, figure.thickness)
  98. elif figure.type == "Line":
  99. pygame.draw.line(surface=self.screen, color=figure.color, start_pos=(figure.vector.x, figure.vector.y), end_pos=(figure.vector.w, figure.vector.h), width=figure.thickness)
  100. elif figure.type == "Text":
  101. self.screen.blit(figure.fontObject.render(figure.text, 1, figure.color), (figure.vector.x, figure.vector.y))
  102. self.figuresToDraw[:] = []
  103. pygame.display.update()
  104. pygame.time.Clock().tick(60)
  105.  
  106. def draw(self, figure : str, vector : Vector, color, thickness=None, radius=None, text=None, fontObject=None):
  107. if figure == "fillRect":
  108. self.figuresToDraw.append(Rectangle(vector, color))
  109. elif figure == "Circle":
  110. self.figuresToDraw.append(Circle(vector, color, thickness, radius))
  111. elif figure == "Line":
  112. self.figuresToDraw.append(Line(vector, color, thickness))
  113. elif figure == "Text":
  114. self.figuresToDraw.append(Text(vector, color, text, fontObject))
  115.  
  116. def CreateFont(self, fontName, fontSize, bold=False, italic=False):
  117. return pygame.font.SysFont(name=fontName, size=fontSize, bold=bold, italic=italic)
  118.  
  119.  
  120. targetWindow = input("Enter Window Title: ")
  121. overlay = Overlay(targetWindow)
  122.  
  123. font = overlay.CreateFont("Fixedsys", 15)
  124.  
  125. while overlay.window:
  126. # overlay.draw("fillRect", vector=Vector(30, 30, 60, 60), color=(255, 255, 255))
  127. # overlay.draw("Circle", vector=Vector(150, 150, 0, 0), color=(255, 0, 0), thickness=0, radius=20)
  128. # overlay.draw("Line", vector=Vector(100, 100, 600, 600), color=(255, 255, 255), thickness=5)
  129. overlay.draw("Text", vector=Vector(overlay.targetRect.w / 2, overlay.targetRect.h / 2, 0, 0), color=(0, 0, 0), text="Негры пидорасы", fontObject=font)
  130. overlay.handle()
Add Comment
Please, Sign In to add comment