Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- from ctypes import wintypes
- import json
- import websockets
- import tkinter as tk
- import ctypes
- loop = asyncio.new_event_loop()
- asyncio.set_event_loop(loop)
- tkapp = tk.Tk()
- players={}
- player_overlay_state={}
- async def hello(websocket, path):
- try:
- while True:
- data = json.loads(await websocket.recv())
- match data["Operation"]:
- case "New":
- if data["Position"]:
- OpenNewTextLabel(data["Name"],data["Position"]["x"],data["Position"]["y"])
- await websocket.send("Update Overlay")
- case "Reposition":
- if data["Position"] and players[data["Name"]]:
- players[data["Name"]].geometry(f"100x100+{data['Position']['x']}+{data['Position']['y']}")
- case "Resize":
- if data["Position"] and players[data["Name"]]:
- players[data["Name"]].geometry(f"{data['Size']['x']}x{data['Size']['y']}+{data['Position']['x']}+{data['Position']['y']}")
- case "Destroy":
- players[data["name"]].destroy()
- players[data["name"]] = None
- player_overlay_state[data["name"]] = None
- finally:
- pass
- async def tk_main(root):
- while True:
- root.update()
- await asyncio.sleep(0.05)
- start_server = websockets.serve(hello, 'localhost', 1820)
- def GetWindowRectFromName(name:str)-> tuple:
- hwnd = ctypes.windll.user32.FindWindowW(0, name)
- rect = wintypes.RECT()
- ctypes.windll.user32.GetWindowRect(hwnd, ctypes.pointer(rect))
- return (rect.left, rect.top, rect.right, rect.bottom)
- def on_closing(win):
- print(win)
- def OpenNewTextLabel(name,x,y):
- # Toplevel object which will
- # be treated as a new window
- if not name in players:
- players[name] = tk.Toplevel(tkapp)
- players[name].overrideredirect(True)
- players[name].lift()
- players[name].wm_attributes("-topmost", True)
- players[name].geometry(f"100x100+{x}+{y}")
- players[name].attributes("-alpha", 0.1)
- players[name].protocol("WM_DELETE_WINDOW", on_closing)
- _, _, width, height = GetWindowRectFromName("Roblox")
- loop.run_until_complete(start_server)
- tkmain = asyncio.ensure_future(tk_main(tkapp),loop=loop)
- try:
- loop.run_forever()
- except KeyboardInterrupt:
- tkmain.cancel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement