-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
87 lines (74 loc) · 3.23 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
Author: Teeraphat Kullanankanjana
version: 0.1
Date: 12/04/2024
Description: Map Magnifier for Company of Hero 2
Copyright (C) 2024 Teeraphat Kullanankanjana. All right reserved.
"""
# Import Library
import cv2
import numpy as np
from pyautogui import screenshot
from tkinter import *
from PIL import Image, ImageTk
# Function to capture game window and resize it to fit GUI
def capture_game_window():
# Capture screenshot of the game window
game_window = screenshot(region=(game_window_x, game_window_y, game_window_width, game_window_height))
# Convert screenshot to OpenCV format (BGR)
game_frame = cv2.cvtColor(np.array(game_window), cv2.COLOR_RGB2BGR)
# Crop to the map area
map_area = game_frame[map_area_y:map_area_y + map_area_height, map_area_x:map_area_x + map_area_width]
# Resize to fit the GUI
resized_frame = cv2.resize(map_area, (output_width, output_height))
# Convert BGR to RGB format
return cv2.cvtColor(resized_frame, cv2.COLOR_BGR2RGB)
# Function to update displayed image
def update_image():
# Check if the root window still exists
if root.winfo_exists():
# Capture the game window and update the displayed image
game_frame = capture_game_window()
img = Image.fromarray(game_frame)
imgtk = ImageTk.PhotoImage(image=img)
label_img.imgtk = imgtk
label_img.configure(image=imgtk)
# Schedule the next update after 10 milliseconds
label_img.after(10, update_image)
# Read settings from text file
def read_settings(filename):
settings = {}
with open(filename, 'r') as file:
# Read each line in the settings file
for line in file:
# Split the line into key and value pairs
key, value = line.strip().split(':')
# Store the key-value pair in the settings dictionary after stripping whitespace
settings[key.strip()] = int(value.strip())
return settings
# Read settings from file
settings = read_settings("settings.txt")
# Game window parameters
game_window_x = settings['game_window_x'] # X coordinate of top-left corner of game window
game_window_y = settings['game_window_y'] # Y coordinate of top-left corner of game window
game_window_width = settings['game_window_width'] # Width of the game window
game_window_height = settings['game_window_height'] # Height of the game window
# Map area parameters
map_area_x = settings['map_area_x'] # X coordinate of top-left corner of map area
map_area_y = settings['map_area_y'] # Y coordinate of top-left corner of map area
map_area_width = settings['map_area_width'] # Width of the map area
map_area_height = settings['map_area_height'] # Height of the map area
# Output window size
output_width = settings['output_width'] # Width of the output window
output_height = settings['output_height'] # Height of the output window
# Create Tkinter window
root = Tk()
root.title("COH2 Map Magnifier")
root.geometry(f"{output_width}x{output_height}")
# Create label for displaying captured image
label_img = Label(root)
label_img.pack()
# Start capturing and updating image
update_image()
# Run the Tkinter event loop
root.mainloop()