-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.py
More file actions
1670 lines (1408 loc) · 75.6 KB
/
cmd.py
File metadata and controls
1670 lines (1408 loc) · 75.6 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import sys
import re
import json
import shutil
import zipfile
import subprocess
import threading
import urllib.request
import platform
from datetime import datetime
from io import BytesIO
import tkinter as tk
from tkinter import ttk, messagebox, filedialog
import webbrowser
from pathlib import Path
# Platform-specific imports
IS_WINDOWS = platform.system() == "Windows"
IS_LINUX = platform.system() == "Linux"
if IS_WINDOWS:
import winreg
import ctypes
else:
winreg = None
ctypes = None
# --- EXTERNAL LIBRARIES ---
try:
from PIL import Image, ImageTk
HAS_PIL = True
except ImportError:
HAS_PIL = False
try:
# Requires: pip install tkinterdnd2
from tkinterdnd2 import DND_TEXT, TkinterDnD
HAS_DND = True
except ImportError:
HAS_DND = False
# --- CONFIGURATION ---
STEAMCMD_URL = "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip"
CONFIG_FILE = "bz_mod_config.json"
class ToolTip:
def __init__(self, widget, text, bg="#1a1a1a", fg="#00ffff"):
self.widget = widget
self.text = text
self.bg = bg
self.fg = fg
self.tip_window = None
widget.bind("<Enter>", self.show_tip)
widget.bind("<Leave>", self.hide_tip)
def show_tip(self, event=None):
x = self.widget.winfo_rootx() + 25
y = self.widget.winfo_rooty() + 20
self.tip_window = tw = tk.Toplevel(self.widget)
tw.wm_overrideredirect(True)
tw.wm_geometry(f"+{x}+{y}")
label = tk.Label(tw, text=self.text, justify='left',
background=self.bg, foreground=self.fg,
relief='solid', borderwidth=1, font=("Consolas", "9"))
label.pack(ipadx=1)
def hide_tip(self, event=None):
if self.tip_window:
self.tip_window.destroy()
self.tip_window = None
class BZModMaster:
def __init__(self, root):
self.root = root
self.root.title("Battlezone Mod Engine")
self.root.geometry("1150x850")
if getattr(sys, 'frozen', False):
self.base_dir = os.path.dirname(sys.executable)
self.resource_dir = sys._MEIPASS
else:
self.base_dir = os.path.dirname(os.path.abspath(__file__))
self.resource_dir = self.base_dir
# --- GAME DEFINITIONS ---
self.games = {
"BZ98R": {
"name": "Battlezone 98 Redux",
"appid": "301650",
"gog_ids": ["1454067812", "1459427445"],
"exe": "battlezone98redux.exe",
"font_file": "BZONE.ttf",
"font_name": "BZONE",
"icon_file": "bz98.png",
"colors": {
"bg": "#0a0a0a", "fg": "#d4d4d4",
"highlight": "#00ff00", "dark_highlight": "#004400", "accent": "#00ffff"
}
},
"BZCC": {
"name": "Battlezone Combat Commander",
"appid": "624970",
"gog_ids": ["1193046833"],
"exe": "battlezone2.exe",
"font_file": "BGM.ttf",
"font_name": "BankGothic",
"icon_file": "bz2.png",
"colors": {
"bg": "#0a0a0a", "fg": "#d4d4d4",
"highlight": "#00aaff", "dark_highlight": "#002244", "accent": "#88ccff"
}
}
}
self.load_custom_fonts()
self.load_game_icons()
icon_path = os.path.join(self.resource_dir, "modman.ico")
if os.path.exists(icon_path):
try: self.root.iconbitmap(icon_path)
except: pass
self.bin_dir = os.path.join(self.base_dir, "bin")
self.config = self.load_config()
# Determine active game
self.current_game_key = self.config.get("last_game", "BZ98R")
if self.current_game_key not in self.games: self.current_game_key = "BZ98R"
self.apply_theme_vars()
self.root.configure(bg=self.colors["bg"])
self.use_physical_var = tk.BooleanVar(value=self.config.get("use_physical", False))
self.advanced_mode_var = tk.BooleanVar(value=self.config.get("advanced_mode", False))
# Load game-specific path or fallback to legacy global path
saved_path = self.config.get(f"path_{self.current_game_key}", "")
if not saved_path and self.current_game_key == "BZ98R":
saved_path = self.config.get("game_path", "")
self.path_var = tk.StringVar(value=saved_path)
self.steamcmd_var = tk.StringVar(value=self.config.get("steamcmd_path", ""))
self.cache_var = tk.StringVar(value=self.config.get("cache_path", os.path.join(self.base_dir, "workshop_cache")))
self.mod_id_var = tk.StringVar()
self.image_cache = {}
# Threading & Process Control
self.stop_event = threading.Event()
self.active_processes = []
self.task_count = 0
self.task_lock = threading.Lock()
self.setup_ui()
self.check_admin()
if not self.path_var.get(): self.auto_detect_gog()
if not self.steamcmd_var.get(): self.auto_detect_steamcmd()
self.toggle_ui_mode()
threading.Thread(target=self.initialize_engine, daemon=True).start()
def load_custom_fonts(self):
self.available_fonts = []
if not IS_WINDOWS:
return # Font loading not needed on Linux
for key, g in self.games.items():
font_path = os.path.join(self.resource_dir, g["font_file"])
if os.path.exists(font_path):
try:
# Check return value: > 0 means success
if ctypes.windll.gdi32.AddFontResourceExW(font_path, 0x10, 0) > 0:
self.available_fonts.append(g["font_name"])
except: pass
def load_game_icons(self):
self.game_icons = {}
if not HAS_PIL: return
for key, g in self.games.items():
try:
p = os.path.join(self.resource_dir, g["icon_file"])
if os.path.exists(p):
img = Image.open(p).resize((48, 48), Image.Resampling.LANCZOS)
self.game_icons[key] = ImageTk.PhotoImage(img)
except: pass
def apply_theme_vars(self):
g = self.games[self.current_game_key]
self.colors = g["colors"]
# Fallback to Consolas if custom font didn't load
self.current_font = g["font_name"] if g["font_name"] in self.available_fonts else "Consolas"
def load_config(self):
if os.path.exists(CONFIG_FILE):
try:
with open(CONFIG_FILE, 'r') as f:
data = json.load(f)
# Convert relative paths back to absolute
for key in ["game_path", "steamcmd_path", "cache_path", "path_BZ98R", "path_BZCC"]:
if key in data and data[key] and not os.path.isabs(data[key]):
data[key] = os.path.normpath(os.path.join(self.base_dir, data[key]))
return data
except: return {}
return {}
def save_config(self, *args):
def make_rel(path):
if not path: return ""
try:
if os.path.splitdrive(path)[0].lower() == os.path.splitdrive(self.base_dir)[0].lower():
return os.path.relpath(path, self.base_dir)
except: pass
return path
# Update current game path in config before saving
self.config[f"path_{self.current_game_key}"] = self.path_var.get()
self.config["last_game"] = self.current_game_key
self.config["steamcmd_path"] = self.steamcmd_var.get()
self.config["cache_path"] = self.cache_var.get()
self.config["use_physical"] = self.use_physical_var.get()
self.config["advanced_mode"] = self.advanced_mode_var.get()
# Convert paths to relative for storage
storage_config = self.config.copy()
for k, v in storage_config.items():
if "path" in k and isinstance(v, str):
storage_config[k] = make_rel(v)
with open(CONFIG_FILE, 'w') as f: json.dump(storage_config, f, indent=4)
def setup_ui(self):
style = ttk.Style()
style.theme_use('default')
self.update_styles(style)
# --- TABS MAIN STRUCTURE ---
self.tabs = ttk.Notebook(self.root)
self.dl_tab = ttk.Frame(self.tabs)
self.manage_tab = ttk.Frame(self.tabs)
self.tabs.add(self.dl_tab, text=" DOWNLOADER ")
self.tabs.add(self.manage_tab, text=" MANAGE MODS ")
self.tabs.pack(fill="both", expand=True)
self.tabs.bind("<<NotebookTabChanged>>", self.on_tab_change)
# ==========================================
# TAB 1: DOWNLOADER
# ==========================================
# System Configuration
cfg = ttk.LabelFrame(self.dl_tab, text=" SYSTEM CONFIGURATION ", padding=10)
cfg.pack(fill="x", padx=10, pady=5)
# Game Switcher Row
game_row = ttk.Frame(cfg)
game_row.grid(row=0, column=0, columnspan=4, sticky="ew", pady=(0, 10))
self.target_game_label = ttk.Label(game_row, text="TARGET GAME:", font=(self.current_font, 12, "bold"))
self.target_game_label.pack(side="left")
game_names = [g["name"] for g in self.games.values()]
self.game_selector = ttk.Combobox(game_row, values=game_names, state="readonly", width=40)
target_name = self.games[self.current_game_key]["name"]
if target_name in game_names:
self.game_selector.current(game_names.index(target_name))
else:
self.game_selector.current(0)
self.game_selector.pack(side="left", padx=10)
self.game_selector.bind("<<ComboboxSelected>>", self.switch_game)
ttk.Checkbutton(game_row, text="Advanced Mode", variable=self.advanced_mode_var,
command=self.toggle_ui_mode).pack(side="right", padx=10)
self.icon_label = tk.Label(game_row, bg=self.colors["bg"])
self.icon_label.pack(side="left", padx=5)
self.update_game_icon()
# Path Rows
paths = [
("Game Path:", self.path_var, self.browse_game, "path_entry",
"Where the game executable is installed."),
("SteamCMD:", self.steamcmd_var, self.browse_steamcmd, "steamcmd_entry",
"If you have SteamCMD installed, point to it here.\nIf you aren't sure you can leave it default or choose a new location."),
("Mod Cache:", self.cache_var, self.browse_cache, "cache_entry",
"Location where mods are downloaded locally before being linked to the game.")
]
self.path_ui_elements = []
for i, (txt, var, cmd, attr, tip) in enumerate(paths):
row_idx = i + 1
widgets = {'default_text': txt}
l = ttk.Label(cfg, text=txt)
l.grid(row=row_idx, column=0, sticky="w")
widgets['label'] = l
h_lbl = tk.Label(cfg, text="?", width=2, bg="#222", fg=self.colors['accent'], font=("Consolas", 8, "bold"), cursor="hand2")
h_lbl.grid(row=row_idx, column=1, padx=(0, 5))
ToolTip(h_lbl, tip, bg="#1a1a1a", fg=self.colors['accent'])
widgets['help'] = h_lbl
ent = ttk.Entry(cfg, textvariable=var)
ent.grid(row=row_idx, column=2, sticky="ew", padx=5)
setattr(self, attr, ent)
widgets['entry'] = ent
b = ttk.Button(cfg, text="BROWSE", width=10, command=cmd)
b.grid(row=row_idx, column=3, pady=2)
widgets['browse'] = b
extras = []
if "Cache" in txt:
extras.append(ttk.Button(cfg, text="OPEN", width=8, command=lambda v=var: self.open_generic_folder(v)))
extras.append(ttk.Button(cfg, text="CLEAR", width=8, command=self.clear_cache))
elif "Game" in txt:
extras.append(ttk.Button(cfg, text="DETECT", width=8, command=lambda: self.auto_detect_gog(verbose=True)))
extras.append(ttk.Button(cfg, text="OPEN", width=8, command=lambda v=var: self.open_generic_folder(v)))
elif "Steam" in txt:
extras.append(ttk.Button(cfg, text="DETECT", width=8, command=lambda: self.auto_detect_steamcmd(verbose=True)))
extras.append(ttk.Button(cfg, text="OPEN", width=8, command=lambda v=var: self.open_generic_folder(v)))
for idx, btn in enumerate(extras):
btn.grid(row=row_idx, column=4 + idx, pady=2, padx=(0, 5))
widgets['extras'] = extras
self.path_ui_elements.append(widgets)
cfg.columnconfigure(2, weight=1)
# Mod Queue (Preview & Input)
prev = ttk.LabelFrame(self.dl_tab, text=" MOD QUEUE ", padding=10)
prev.pack(fill="x", padx=10, pady=5)
thumb_container = tk.Frame(prev, bg="#050505", width=150, height=150,
highlightthickness=1, highlightbackground=self.colors['dark_highlight'])
thumb_container.pack(side="left", padx=10)
thumb_container.pack_propagate(False)
self.thumb_container = thumb_container # Ref for theme update
self.thumb_label = tk.Label(thumb_container, bg="#050505")
self.thumb_label = tk.Label(thumb_container, bg="#050505", text="ADD MOD\nLINK OR ID",
fg=self.colors['accent'], font=(self.current_font, 10, "bold"), wraplength=140)
self.thumb_label.pack(expand=True, fill="both")
info_frame = ttk.Frame(prev)
info_frame.pack(side="left", fill="both", expand=True)
self.mod_name_label = ttk.Label(info_frame, text="READY FOR COMMAND", foreground=self.colors['accent'], font=(self.current_font, 11, "bold"))
self.mod_name_label.pack(anchor="w", pady=(0, 5))
self.mod_url_label = ttk.Label(info_frame, text="MOD URL OR ID:", font=(self.current_font, 8))
self.mod_url_label.pack(anchor="w")
self.mod_entry = ttk.Entry(info_frame, textvariable=self.mod_id_var)
self.mod_entry.pack(fill="x", pady=5)
if HAS_DND:
self.mod_entry.drop_target_register(DND_TEXT)
self.mod_entry.dnd_bind('<<Drop>>', lambda e: self.mod_id_var.set(e.data.strip("{}")))
self.thumb_label.drop_target_register(DND_TEXT)
self.thumb_label.dnd_bind('<<Drop>>', lambda e: self.mod_id_var.set(e.data.strip("{}")))
self.mod_id_var.trace_add("write", self.on_input_change)
# Context Menu for Inputs
self.input_menu = tk.Menu(self.root, tearoff=0, bg="#1a1a1a", fg=self.colors['fg'])
self.input_menu.add_command(label="PASTE FROM CLIPBOARD", command=self.paste_from_clipboard)
self.thumb_label.bind("<Button-3>", self.show_input_menu)
self.mod_entry.bind("<Button-3>", self.show_input_menu)
btn_row = ttk.Frame(info_frame)
btn_row.pack(fill="x", pady=5)
self.dl_btn = ttk.Button(btn_row, text="INSTALL MOD", command=self.start_download, style="Success.TButton")
self.dl_btn.pack(side="left", padx=(0, 5))
self.launch_btn = ttk.Button(btn_row, text="LAUNCH GAME", command=self.launch_game)
self.launch_btn.pack(side="left")
self.workshop_btn = ttk.Button(btn_row, text="WORKSHOP", command=self.open_workshop)
self.workshop_btn.pack(side="left", padx=5)
self.stop_btn = ttk.Button(btn_row, text="STOP", command=self.stop_operation, state="disabled")
self.stop_btn.pack(side="left", padx=5)
# HUD Log
log_header = ttk.Frame(self.dl_tab)
log_header.pack(fill="x", padx=10, pady=(5, 0))
self.hud_log_label = ttk.Label(log_header, text=" HUD LOG ", foreground=self.colors['highlight'], font=(self.current_font, 11, "bold"))
self.hud_log_label.pack(side="left")
ttk.Button(log_header, text="CLEAR", width=8, command=self.clear_hud_log).pack(side="right")
self.log_box = tk.Text(self.dl_tab, state="disabled", font=("Consolas", 10), bg="#050505", fg=self.colors['fg'], height=12)
self.log_box.pack(fill="both", expand=True, padx=10, pady=5)
# Log tags
self.log_box.tag_config("timestamp", foreground="#444444")
self.log_box.tag_config("success", foreground=self.colors['highlight'])
self.log_box.tag_config("warning", foreground="#ffff44")
self.log_box.tag_config("error", foreground="#ff4444")
self.log_box.tag_config("info", foreground=self.colors['accent'])
self.progress = ttk.Progressbar(self.dl_tab, style="BZ.Horizontal.TProgressbar", mode="determinate")
self.progress.pack(fill="x", padx=10, pady=10)
self.progress_label = tk.Label(self.dl_tab, text="IDLE", bg="#050505", fg="#666666", font=("Consolas", 8))
self.progress_label.place(in_=self.progress, relx=0.5, rely=0.5, anchor="center")
# ==========================================
# TAB 2: MANAGE MODS
# ==========================================
self.tree = ttk.Treeview(self.manage_tab, columns=("Name", "ID", "Status", "Version", "Date"), show="tree headings")
self.tree.column("#0", width=45, anchor="center", stretch=False)
self.tree.heading("#0", text="")
for col in ["Name", "ID", "Status", "Version", "Date"]:
self.tree.heading(col, text=col.upper(), command=lambda c=col: self.sort_tree(c, False))
self.tree.column(col, anchor="center", width=100)
self.tree.column("Name", width=250)
self.tree.pack(fill="both", expand=True, padx=10, pady=10)
self.tree.bind("<Button-3>", self.show_mod_menu)
self.tree.bind("<ButtonPress-1>", self.on_tree_press)
self.tree.bind("<B1-Motion>", self.on_tree_motion)
manage_ctrl = ttk.Frame(self.manage_tab)
manage_ctrl.pack(fill="x", padx=10, pady=5)
ttk.Button(manage_ctrl, text="CHECK FOR UPDATES", command=self.refresh_list).pack(side="left")
ttk.Button(manage_ctrl, text="SELECT ALL", command=self.select_all_mods).pack(side="left", padx=5)
self.manage_help_lbl = tk.Label(manage_ctrl, text="?", width=2, bg="#222", fg=self.colors['accent'], font=("Consolas", 8, "bold"), cursor="hand2")
self.manage_help_lbl.pack(side="left", padx=10)
self.manage_help_tip = ToolTip(self.manage_help_lbl, "CONTROLS:\n• Double-Click: Toggle Enable/Disable\n• Right-Click: Context Menu\n• Drag/Shift+Click: Multi-Select", bg="#1a1a1a", fg=self.colors['accent'])
ttk.Button(manage_ctrl, text="UPDATE ALL", command=self.update_all_mods).pack(side="right")
# Context Menu
self.mod_menu = tk.Menu(self.root, tearoff=0, bg="#1a1a1a", fg=self.colors['fg'])
self.mod_menu.add_command(label="ENABLE (LINK)", command=self.enable_mod)
self.mod_menu.add_command(label="DISABLE (UNLINK)", command=self.disable_mod)
self.mod_menu.add_separator()
self.mod_menu.add_command(label="UPDATE MOD", command=lambda: self.update_selected_mod(force=False))
self.mod_menu.add_command(label="FORCE UPDATE", command=lambda: self.update_selected_mod(force=True))
self.mod_menu.add_command(label="DELETE FROM DISK", command=self.delete_mod_physically)
self.update_tree_tags()
def toggle_ui_mode(self):
advanced = self.advanced_mode_var.get()
# 0: Game Path, 1: SteamCMD, 2: Cache
self.set_row_visibility(0, show_row=advanced, simple=not advanced)
self.set_row_visibility(1, show_row=advanced, simple=not advanced)
self.set_row_visibility(2, show_row=True, simple=not advanced)
# Update Cache Label
cache_widgets = self.path_ui_elements[2]
cache_widgets['label'].config(text="Download Folder:" if not advanced else cache_widgets['default_text'])
# Update Simple Mode Texts
if not advanced:
self.thumb_label.config(text="DRAG MOD LINK HERE\nOR COPY/PASTE")
self.mod_url_label.config(text="PASTE WORKSHOP LINK HERE:")
else:
self.thumb_label.config(text="ADD MOD\nLINK OR ID")
self.mod_url_label.config(text="MOD URL OR ID:")
# Buttons
if not advanced:
self.workshop_btn.pack_forget()
self.launch_btn.pack_forget()
self.stop_btn.pack_forget()
else:
# Repack to ensure order
for btn in [self.dl_btn, self.launch_btn, self.workshop_btn, self.stop_btn]:
btn.pack_forget()
self.dl_btn.pack(side="left", padx=(0, 5))
self.launch_btn.pack(side="left")
self.workshop_btn.pack(side="left", padx=5)
self.stop_btn.pack(side="left", padx=5)
def set_row_visibility(self, index, show_row, simple):
widgets = self.path_ui_elements[index]
if show_row:
widgets['label'].grid()
widgets['entry'].grid()
widgets['browse'].grid()
if simple:
widgets['help'].grid_remove()
for w in widgets['extras']: w.grid_remove()
else:
widgets['help'].grid()
for w in widgets['extras']: w.grid()
else:
widgets['label'].grid_remove()
widgets['entry'].grid_remove()
widgets['browse'].grid_remove()
widgets['help'].grid_remove()
for w in widgets['extras']: w.grid_remove()
def update_styles(self, style):
main_font = (self.current_font, 10)
bold_font = (self.current_font, 11, "bold")
c = self.colors
# --- GLOBAL STYLES ---
style.configure(".", background=c["bg"], foreground=c["fg"], font=main_font, bordercolor=c["dark_highlight"])
style.configure("TFrame", background=c["bg"])
style.configure("TNotebook", background=c["bg"], borderwidth=0)
style.configure("TNotebook.Tab", background="#1a1a1a", foreground=c["fg"], padding=[10, 2])
style.map("TNotebook.Tab", background=[("selected", c["dark_highlight"])], foreground=[("selected", c["highlight"])])
style.configure("TLabelframe", background=c["bg"], bordercolor=c["highlight"])
style.configure("TLabelframe.Label", background=c["bg"], foreground=c["highlight"], font=bold_font)
style.configure("TLabel", background=c["bg"], foreground=c["fg"])
style.configure("TEntry", fieldbackground="#1a1a1a", foreground=c["accent"], insertcolor=c["highlight"])
style.configure("BZ.Horizontal.TProgressbar", thickness=15, background=c["highlight"], troughcolor="#050505")
style.configure("TButton", background="#1a1a1a", foreground=c["fg"])
style.map("TButton", background=[("active", c["dark_highlight"])], foreground=[("active", c["highlight"])])
style.configure("Success.TButton", foreground=c["highlight"], font=bold_font)
style.configure("Treeview", background="#0a0a0a", foreground=c["fg"], fieldbackground="#0a0a0a", rowheight=40)
style.map("Treeview", background=[("selected", c["accent"])], foreground=[("selected", "#000000")])
def update_game_icon(self):
if not hasattr(self, 'icon_label'): return
c = self.colors
icon = self.game_icons.get(self.current_game_key)
if icon:
self.icon_label.config(image=icon, bg=c["bg"], highlightbackground=c["highlight"], highlightthickness=1, bd=0)
self.icon_label.image = icon
else:
self.icon_label.config(image="", width=0, bd=0, highlightthickness=0)
def update_tree_tags(self):
c = self.colors
self.tree.tag_configure('active', foreground=c['highlight'])
self.tree.tag_configure('inactive', foreground="#666666")
def switch_game(self, event=None):
selected_name = self.game_selector.get()
# Find key by name
new_key = next((k for k, v in self.games.items() if v["name"] == selected_name), "BZ98R")
if new_key == self.current_game_key: return
# Save current state
self.save_config()
# Switch
self.current_game_key = new_key
self.apply_theme_vars()
# Update Path Var
saved_path = self.config.get(f"path_{self.current_game_key}", "")
self.path_var.set(saved_path)
# Update UI Styles
style = ttk.Style()
self.update_styles(style)
# Update Manual Widgets
c = self.colors
self.root.configure(bg=c["bg"])
self.log_box.configure(fg=c["fg"])
self.log_box.tag_config("success", foreground=c['highlight'])
self.log_box.tag_config("info", foreground=c['accent'])
self.mod_name_label.configure(foreground=c['accent'], font=(self.current_font, 11, "bold"))
self.hud_log_label.configure(foreground=c['highlight'], font=(self.current_font, 11, "bold"))
self.thumb_label.configure(fg=c['accent'], font=(self.current_font, 10, "bold"))
self.target_game_label.configure(font=(self.current_font, 12, "bold"))
self.mod_url_label.configure(font=(self.current_font, 8))
self.thumb_container.configure(highlightbackground=c['dark_highlight'])
self.mod_menu.configure(fg=c['fg'])
self.input_menu.configure(fg=c['fg'])
if hasattr(self, 'manage_help_lbl'):
self.manage_help_lbl.configure(fg=c['accent'])
self.manage_help_tip.fg = c['accent']
self.update_tree_tags()
self.update_game_icon()
self.log(f"Switched to {self.games[new_key]['name']}", "info")
self.initialize_engine()
self.refresh_list()
self.save_config()
if self.mod_id_var.get():
self.is_valid_mod = False
self.mod_name_label.config(text="VALIDATING...", foreground=c['fg'])
self.on_input_change()
def clear_hud_log(self):
self.log_box.config(state="normal")
self.log_box.delete("1.0", "end")
self.log_box.config(state="disabled")
def log(self, message, tag=None):
self.root.after(0, lambda: self._log_impl(message, tag))
def _log_impl(self, message, tag=None):
# Simple Mode Filter: Only show tagged messages (Success, Warning, Error, Info)
if not self.advanced_mode_var.get() and tag is None:
return
self.log_box.config(state="normal")
ts = datetime.now().strftime("[%H:%M:%S] ")
self.log_box.insert("end", ts, "timestamp")
if tag:
self.log_box.insert("end", f"{message}\n", tag)
else:
self.log_box.insert("end", f"{message}\n")
self.log_box.see("end")
self.log_box.config(state="disabled")
def start_task(self):
with self.task_lock:
if self.task_count == 0:
self.stop_event.clear()
self.root.after(0, lambda: self.stop_btn.config(state="normal"))
self.task_count += 1
def end_task(self, callback=None):
with self.task_lock:
self.task_count -= 1
if self.task_count <= 0:
self.task_count = 0
self.root.after(0, lambda: self.stop_btn.config(state="disabled"))
self.root.after(0, self.reset_progress)
if callback:
self.root.after(1000, callback)
def stop_operation(self):
self.stop_event.set()
self.log("Stopping operations...", "warning")
for p in list(self.active_processes):
try: p.terminate()
except: pass
def get_dependencies(self, mid):
"""Scrapes the Steam Workshop page for required items."""
url = f"https://steamcommunity.com/sharedfiles/filedetails/?id={mid}&l=english"
try:
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
with urllib.request.urlopen(req) as r:
html = r.read().decode('utf-8')
# Robustly find the requiredItemsContainer block by counting divs
start_match = re.search(r'<div[^>]*class="requiredItemsContainer"[^>]*>', html)
if start_match:
start_idx = start_match.end()
balance = 1
idx = start_idx
while balance > 0 and idx < len(html):
next_open = html.find('<div', idx)
next_close = html.find('</div>', idx)
if next_close == -1: break
if next_open != -1 and next_open < next_close:
balance += 1
idx = next_open + 4
else:
balance -= 1
idx = next_close + 6
block = html[start_idx:idx]
return list(set(re.findall(r'id=(\d+)', block)))
except Exception as e:
self.log(f"Dependency Check Failed: {e}", "warning")
pass
return []
def update_batch_progress(self, item_percent, completed_count, total_items):
if total_items == 0: return
item_percent = min(100.0, max(0.0, item_percent))
total_percent = ((completed_count * 100.0) + item_percent) / total_items
self.progress.stop()
self.progress.config(mode="determinate", value=total_percent)
if completed_count == total_items:
self.progress_label.config(text="100% - COMPLETE")
else:
self.progress_label.config(text=f"{int(total_percent)}% (Item {completed_count + 1}/{total_items})")
self.dl_btn.config(text=f"DL {completed_count + 1}/{total_items} ({int(item_percent)}%)")
def _abort_download_ui(self):
self.dl_btn.config(text="INSTALL MOD", state="normal")
self.reset_progress()
self.end_task()
def _prompt_deps_and_start(self, queue, deps, sc_path, cache_path, game_path):
try:
if deps:
if messagebox.askyesno("Dependencies Found", f"This mod requires {len(deps)} other items.\nDownload them as well?"):
queue.extend(deps)
except Exception as e:
self.log(f"Dependency prompt failed: {e}", "warning")
use_physical = self.resolve_deploy_mode(game_path, self.use_physical_var.get())
if use_physical is None:
self._abort_download_ui()
return
self.dl_btn.config(state="disabled", text="ENGINE ACTIVE")
self.progress.config(mode="indeterminate")
self.progress.start(10)
self.progress_label.config(text="INITIALIZING...", fg=self.colors['accent'])
threading.Thread(target=self.download_logic, args=(queue, sc_path, cache_path, game_path, use_physical), daemon=True).start()
def start_download(self):
mid = self.sanitize_id(self.mod_id_var.get())
if not mid:
self.dl_btn.config(text="NO MOD ID")
self.root.after(2000, lambda: self.dl_btn.config(text="INSTALL MOD", state="normal"))
return
# FINAL GATEKEEPER: Check validation flag
if hasattr(self, 'is_valid_mod') and not self.is_valid_mod:
current_game_name = self.games[self.current_game_key]["name"]
messagebox.showerror("Validation Error", f"Target Mod ID does not belong to {current_game_name}.\nDownload Aborted.")
return
queue = [mid]
sc_path = self.steamcmd_var.get()
cache_path = self.cache_var.get()
game_path = self.path_var.get()
self.dl_btn.config(state="disabled", text="CHECKING DEPS...")
self.progress.config(mode="indeterminate")
self.progress.start(10)
self.progress_label.config(text="CHECKING DEPS...", fg=self.colors['accent'])
self.start_task()
def deps_worker():
deps = []
try:
deps = self.get_dependencies(mid)
except Exception as e:
self.log(f"Dependency Check Failed: {e}", "warning")
self.root.after(0, lambda: self._prompt_deps_and_start(queue, deps, sc_path, cache_path, game_path))
threading.Thread(target=deps_worker, daemon=True).start()
def download_logic(self, mod_ids, sc_path, cache_path, game_path, use_physical):
if isinstance(mod_ids, str): mod_ids = [mod_ids]
try:
current_appid = self.games[self.current_game_key]["appid"]
final_sc_path = self.ensure_steamcmd(sc_path)
cache = os.path.abspath(cache_path)
# Force SteamCMD to use English to ensure regex matching works
sc_dir = os.path.dirname(final_sc_path)
console_cfg = os.path.join(sc_dir, "SteamConsole.txt")
if not os.path.exists(console_cfg):
with open(console_cfg, "w") as f:
f.write('@Language "english"\n')
total_items = len(mod_ids)
self.log(f"Batch processing {total_items} items...", "info")
# Build Batch Command
cmd = [final_sc_path, "+force_install_dir", cache, "+login", "anonymous"]
for mid in mod_ids:
mod_path = os.path.join(cache, "steamapps/workshop/content", current_appid, mid)
if os.path.exists(mod_path):
self.log(f"Queueing update: {mid}", "warning")
else:
self.log(f"Queueing download: {mid}", "info")
cmd.extend(["+workshop_download_item", current_appid, mid])
cmd.append("+quit")
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1, creationflags=subprocess.CREATE_NO_WINDOW)
self.active_processes.append(p)
completed_count = 0
last_log_time = 0
while True:
if self.stop_event.is_set():
p.terminate()
break
line = p.stdout.readline()
if not line:
break
clean = line.strip()
if clean:
# Regex for SteamCMD progress: "progress: 23.45"
progress_match = re.search(r'progress:\s*(\d+\.\d+)', clean)
current_time = datetime.now().timestamp()
if "Success. Downloaded item" in clean:
completed_count += 1
self.log(f"Success: {clean.split('item')[-1].strip()} ({completed_count}/{total_items})", "success")
self.root.after(0, lambda c=completed_count, t=total_items: self.update_batch_progress(0, c, t))
elif "Error" in clean or "Failed" in clean:
self.log(clean, "error")
elif progress_match:
val = float(progress_match.group(1))
self.root.after(0, lambda v=val, c=completed_count, t=total_items: self.update_batch_progress(v, c, t))
elif "Verifying" in clean:
self.root.after(0, lambda c=completed_count, t=total_items: self.dl_btn.config(text=f"VERIFYING {c+1}/{t}..."))
elif "Update state" not in clean:
# Throttle "Downloading" and "Extracting" spam
if "Downloading" in clean or "Extracting" in clean:
if current_time - last_log_time > 1.0: # Log at most once per second
self.log(clean)
last_log_time = current_time
else:
self.log(clean)
p.wait()
if p in self.active_processes: self.active_processes.remove(p)
# Process Links for all items
for mid in mod_ids:
src = os.path.normpath(os.path.join(cache, "steamapps/workshop/content", current_appid, mid))
dst = os.path.normpath(os.path.join(game_path, "mods", mid))
if os.path.exists(src):
deployed_ok = False
if not os.path.exists(os.path.dirname(dst)): os.makedirs(os.path.dirname(dst))
if use_physical:
if os.path.lexists(dst):
self.remove_existing_path(dst)
shutil.copytree(src, dst)
deployed_ok = True
else:
if not os.path.lexists(dst):
try:
result = subprocess.run(
f'mklink /J "{dst}" "{src}"',
shell=True,
timeout=10,
capture_output=True,
text=True,
check=True
)
except subprocess.TimeoutExpired:
self.log(f"Link creation timed out for {mid}", "error")
except subprocess.CalledProcessError as e:
err = e.stderr.strip() if e.stderr else "Unknown error"
self.log(f"Link creation failed for {mid}: {err}", "error")
except Exception as e:
self.log(f"Link creation failed for {mid}: {e}", "error")
deployed_ok = os.path.lexists(dst)
if deployed_ok:
self.log(f"Deployment complete: {mid}", "success")
else:
self.log(f"Deployment failed: {mid}", "error")
self.root.after(0, lambda: self.dl_btn.config(text="DEPLOYED"))
self.root.after(3000, lambda: self.dl_btn.config(text="INSTALL MOD", state="normal"))
except Exception as e: self.log(f"CRITICAL: {e}", "error")
finally:
self.end_task(self.refresh_list if not self.stop_event.is_set() else None)
def update_progress(self, value):
self.progress.stop()
self.progress.config(mode="determinate", value=value)
self.progress_label.config(text=f"DOWNLOADING {int(value)}%")
if value < 100: self.dl_btn.config(text=f"DOWNLOADING {int(value)}%")
def reset_progress(self):
self.progress.stop()
self.progress.config(mode="determinate", value=0)
self.progress_label.config(text="IDLE", fg="#666666")
def on_input_change(self, *args):
mid = self.sanitize_id(self.mod_id_var.get())
if mid and len(mid) >= 8:
threading.Thread(target=self.fetch_preview, args=(mid,), daemon=True).start()
def open_workshop(self):
appid = self.games[self.current_game_key]["appid"]
webbrowser.open(f"https://steamcommunity.com/app/{appid}/workshop/")
def fetch_preview(self, mid):
try:
url = f"https://steamcommunity.com/sharedfiles/filedetails/?id={mid}&l=english"
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
with urllib.request.urlopen(req) as r:
html = r.read().decode('utf-8')
# VALIDATION: Check for Current Game App ID
target_appid = self.games[self.current_game_key]["appid"]
app_match = re.search(r'steamcommunity\.com/app/(\d+)', html)
current_app = app_match.group(1) if app_match else None
if current_app and current_app != target_appid:
self.is_valid_mod = False
self.root.after(0, lambda: self.mod_name_label.config(text="INVALID GAME DETECTED", foreground="#ff0000"))
return
self.is_valid_mod = True
name = re.search(r'<div class="workshopItemTitle">(.*?)</div>', html)
thumb = re.search(r'id="ActualImage"\s+src="([^"]+)"', html)
if not thumb: thumb = re.search(r'<link rel="image_src" href="([^"]+)">', html)
title = name.group(1).strip() if name else f"ID: {mid}"
self.root.after(0, lambda: self.mod_name_label.config(text=title, foreground=self.colors['accent']))
if HAS_PIL and thumb:
with urllib.request.urlopen(thumb.group(1)) as i:
img = Image.open(BytesIO(i.read())).resize((150, 150), Image.Resampling.LANCZOS)
photo = ImageTk.PhotoImage(img)
self.root.after(0, lambda p=photo: self.update_thumb(p))
except Exception as e:
self.log(f"Metadata Fetch Error: {e}", "error")
def update_thumb(self, photo):
self.thumb_label.config(image=photo)
self.thumb_label.image = photo
def show_input_menu(self, event):
self.input_menu.post(event.x_root, event.y_root)
def paste_from_clipboard(self):
try:
self.mod_id_var.set(self.root.clipboard_get())
except: pass
def sanitize_id(self, input_str):
match = re.search(r'id=(\d+)', input_str)
return match.group(1) if match else (input_str.strip() if input_str.strip().isdigit() else None)
def initialize_engine(self):
game_name = self.games[self.current_game_key]["name"]
self.log(f"{game_name} Engine Initializing...", "info")
# Check Game Path - Logic adjusted for your test environment
game_exe = os.path.join(self.path_var.get(), self.games[self.current_game_key]["exe"])
if not os.path.exists(game_exe):
self.log("NOTICE: Executable not found. Running in Virtual/Test mode.", "warning")
self.path_entry.configure(foreground="#ffff44") # Yellow for "Mock Mode"
else:
self.log(f"System Link Established: {game_exe}", "success")
self.path_entry.configure(foreground=self.colors['accent'])
# Check SteamCMD
if not os.path.exists(self.steamcmd_var.get()):
self.log("WARNING: SteamCMD missing. Downloads disabled.", "warning")
self.steamcmd_entry.configure(foreground="#ffff44")
else:
self.log("SteamCMD Binary: Verified.", "success")
self.log("Ready for mod deployment.", "info")
def ensure_steamcmd(self, target):
if not target:
target = os.path.join(self.bin_dir, "steamcmd.exe")
self.root.after(0, lambda: self.steamcmd_var.set(target))
if not os.path.exists(target):
target_dir = os.path.dirname(target)
self.log(f"SteamCMD missing. Downloading to {target_dir}...", "warning")
os.makedirs(target_dir, exist_ok=True)
zip_p = os.path.join(target_dir, "sc.zip")
try:
urllib.request.urlretrieve(STEAMCMD_URL, zip_p)
with zipfile.ZipFile(zip_p, 'r') as z: z.extractall(target_dir)
os.remove(zip_p)
self.log("SteamCMD installed successfully.", "success")
except Exception as e:
self.log(f"SteamCMD Setup Error: {e}", "error")
raise e
return target
def check_admin(self):
if IS_WINDOWS and ctypes:
if not ctypes.windll.shell32.IsUserAnAdmin():
self.log("NOTICE: Non-Admin mode detected.", "error")
self.show_admin_warning()
# Linux doesn't need admin for symlinks
def show_admin_warning(self):
self.admin_frame = tk.Frame(self.dl_tab, bg="#330000", pady=2)
children = self.dl_tab.winfo_children()
if children:
self.admin_frame.pack(side="top", fill="x", padx=10, pady=(5,0), before=children[0])
else:
self.admin_frame.pack(side="top", fill="x", padx=10, pady=5)
lbl = tk.Label(self.admin_frame, text="⚠ ADMIN OR NTFS REQUIRED FOR JUNCTIONS",
bg="#330000", fg="#ff5555", font=("Consolas", 10, "bold"))
lbl.pack(side="left", padx=10)
btn = ttk.Button(self.admin_frame, text="RELAUNCH AS ADMIN", command=self.relaunch_admin)
btn.pack(side="right", padx=5, pady=2)
ToolTip(lbl, "Windows requires NTFS to create junctions.\nIf your game is on exFAT, use Physical Copy or move to NTFS.")
def relaunch_admin(self):