-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.py
More file actions
177 lines (158 loc) · 5.96 KB
/
Copy pathmain.py
File metadata and controls
177 lines (158 loc) · 5.96 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# -*- coding: utf-8 -*-
# Initialize CUDA context early (before ONNX imports) so providers are detected
try:
import torch
_ = torch.cuda.is_available()
except ImportError:
pass
# -*- coding: utf-8 -*-
"""
Main entry point - preloads all static dependencies to validate at startup.
Dynamic imports (kmNet, TensorRT, numba, bettercam, etc.) are handled in their modules.
"""
# === Standard library ===
import copy
import ctypes
from ctypes import *
import gc
import glob
import json
import logging
import math
import os
import queue
from queue import Queue
import random
import socket
import string
import struct
import subprocess
import sys
import threading
from threading import Thread, Timer, Event
import time
import traceback
import warnings
from collections import deque
from concurrent.futures import ThreadPoolExecutor
from dataclasses import dataclass
from enum import IntEnum
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
import tkinter as tk
from tkinter import filedialog
# === Third-party: Core ===
import cv2
import numpy as np
import onnxruntime as rt
import requests
# === Third-party: GUI ===
import dearpygui.dearpygui as dpg
# === Third-party: Windows API ===
import win32api
import win32con
import win32gui
# === Third-party: Input ===
from pynput import keyboard, mouse
from pynput.keyboard import Key, KeyCode
import pydirectinput
from pyclick import HumanCurve
import serial
import serial.tools.list_ports
# === Third-party: Image processing ===
from PIL import Image
# === Third-party: Scientific ===
import scipy
from scipy.optimize import linear_sum_assignment
import filterpy
from filterpy.kalman import KalmanFilter
# === Third-party: Cryptography ===
from cryptography.fernet import Fernet
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives import padding
from cryptography.hazmat.backends import default_backend
# === Application entry point ===
from src.app import Aassist
def global_exception_hook(exctype, value, tb):
"""
Global exception hook to catch all unhandled exceptions.
"""
# Write detailed exception information to log file
with open('error_log.txt', 'a', encoding='utf-8') as f:
f.write(f"[Global Exception] {time.strftime('%Y-%m-%d %H:%M:%S')}\n")
f.write(''.join(traceback.format_exception(exctype, value, tb)))
f.write('\n')
# Display a friendly error message to the user
print('An unhandled exception occurred. Details have been written to error_log.txt. Please report this file to the developer.')
# Set custom global exception handler
sys.excepthook = global_exception_hook
def handle_tensorrt_error():
"""
Handle TensorRT-related import or initialization errors.
"""
# Print detailed guidance information to console
print('\n==================================================')
print('TensorRT-related error detected, but program will continue using ONNX inference')
print('If you want to use TensorRT acceleration, please install the following components:')
print('1. CUDA Toolkit')
print('2. cuDNN')
print('3. TensorRT')
print('4. For configuration tutorial, visit: https://www.yuque.com/huiyestudio/dqrld3/rislyof9zegdfira')
print('==================================================\n')
# Record error information to file
with open('tensorrt_error.txt', 'a', encoding='utf-8') as f:
f.write(f"[TensorRT Not Installed] {time.strftime('%Y-%m-%d %H:%M:%S')}\n")
f.write('Program will continue using ONNX inference\n\n')
# Main program entry point
if __name__ == '__main__':
valorant_instance = None
try:
try:
print('Starting program...')
try:
with open('error_log.txt', 'w', encoding='utf-8') as f:
f.write('')
except Exception:
pass
try:
# Try to start main program
valorant_instance = Aassist()
valorant_instance.start()
except ImportError as e:
# Catch import errors, especially TensorRT-related ones
error_str = str(e).lower()
if 'tensorrt' in error_str or 'cuda' in error_str or 'nvinfer' in error_str:
handle_tensorrt_error()
valorant_instance = Aassist()
valorant_instance.start()
else:
raise
except OSError as e:
# Catch OS errors, which may also be caused by missing GPU libraries
error_str = str(e).lower()
if 'nvinfer' in error_str or 'cudnn' in error_str or 'cuda' in error_str:
handle_tensorrt_error()
valorant_instance = Aassist()
valorant_instance.start()
else:
raise
except Exception as e:
# Catch all other exceptions during startup
with open('error_log.txt', 'w', encoding='utf-8') as f:
f.write(traceback.format_exc())
print('An error occurred. Details have been written to error_log.txt. Please report this file to the developer.')
input('Press Enter to exit...')
finally:
# Ensure resource cleanup when program exits
if valorant_instance is not None:
try:
print('Cleaning up program resources...')
valorant_instance._secure_cleanup()
print('Program resource cleanup completed')
except Exception as e:
# Handle exceptions that may occur during cleanup
print(f"Error cleaning up program resources: {e}")
with open('error_log.txt', 'a', encoding='utf-8') as f:
f.write(f"[Resource Cleanup Exception] {time.strftime('%Y-%m-%d %H:%M:%S')}\n")
f.write(f"Cleanup error: {str(e)}\n")
f.write(traceback.format_exc())
f.write('\n')