-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcc_build_scenarios_shared.py
824 lines (696 loc) · 35.3 KB
/
mcc_build_scenarios_shared.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
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
import os
import glob
import shutil
import subprocess
import tkinter as tk
from tkinter import ttk
from tkinter import font
from tkinter import filedialog
from tkinter import messagebox
#-------------------------------------- GLOBAL VARIABLES BEGIN ----------------------------------
h2ek_path = ""
h3ek_path = ""
odstek_path = ""
hrek_path = ""
h4ek_path = ""
h2amp_path = ""
allmaps_filepath = ""
#-------------------------------------- GLOBAL VARIABLES END ------------------------------------
#-------------------------------------- GLOBAL FUNCTIONS BEGIN ----------------------------------
def run_executable_in_another_directory(executable_path, arguments):
executable_folder = os.path.dirname(executable_path)
os.chdir(executable_folder)
arguments.insert(0, str(executable_path))
subprocess.run(arguments)
def update_tasks(progress_var, stage, total_stages, window):
progress_var.set(stage / total_stages * 100)
#-------------------------------------- GLOBAL FUNCTIONS END ------------------------------------
#-------------------------------------- H2 BEGIN ------------------------------------------------
def h2(scenarios_list, window):
stage_count = 0
total_stages = 4 # H2 4 by default, not including the actual map files
for map in scenarios_list:
total_stages += 1
# Progress bar
window.geometry('450x700')
progress_label = tk.Label(window, text="Removing old data")
progress_label.grid(row=13, column=1, padx=20, pady=5)
progress_var = tk.DoubleVar()
progress_bar = ttk.Progressbar(window, variable=progress_var, maximum=100)
progress_bar.grid(row=14, column=1, padx=20, pady=5, columnspan=3, sticky="ew")
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
window.update()
print("Halo 2")
platform = "win64"
no_extra_prints = "-batch"
build_flags = "compress|resource_sharing|multilingual_sounds"
build_flags_sp = "compress|resource_sharing|multilingual_sounds|remastered_support"
build_flags_mp = "compress|resource_sharing|multilingual_sounds|mp_tag_sharing"
engine_path = h2ek_path
tool_exe = os.path.join(engine_path, "tool.exe")
maps_folder = os.path.join(engine_path, "h2_maps_win64_dx11")
# 1 - Delete everything from maps to avoid stale data corrupting the process
print("Delete everything from maps to avoid stale data corrupting the process")
shutil.rmtree(maps_folder, ignore_errors=True)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Generating mainmenu.map")
window.update()
# 2 - Generate mainmenu.map
print("Generate mainmenu.map")
argument_list = [no_extra_prints, "build-cache-file", "scenarios\\ui\\mainmenu\\mainmenu", platform, build_flags]
run_executable_in_another_directory(tool_exe, argument_list)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Generating shared.map")
window.update()
# 3 - Generate shared.map
print("Generate shared.map")
argument_list = [no_extra_prints, "build-cache-file", "scenarios\\shared\\shared", platform, build_flags]
run_executable_in_another_directory(tool_exe, argument_list)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Generating single_player_shared.map")
window.update()
# 4 - Generate single_player_shared.map
print("Generate single_player_shared.map")
argument_list = [no_extra_prints, "build-cache-file", "scenarios\\shared\\single_player_shared", platform, build_flags]
run_executable_in_another_directory(tool_exe, argument_list)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
window.update()
# 5 - Generate cache files
print("Generate cache files")
for map in scenarios_list:
progress_label.config(text="Building " + os.path.basename(map) + ".map")
window.update()
if "solo" in map:
argument_list = [no_extra_prints, "build-cache-file", map, platform, build_flags_sp]
else:
argument_list = [no_extra_prints, "build-cache-file", map, platform, build_flags_mp]
run_executable_in_another_directory(tool_exe, argument_list)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Finished!")
window.update()
print("\n\nFinished successfully. Built map files are in \"H2EK\\h2_maps_win64_dx11\"")
messagebox.showinfo("Success", "Finished successfully. Built map files are in \"H2EK\\h2_maps_win64_dx11\"")
#-------------------------------------- H2 END --------------------------------------------------
#-------------------------------------- H3/ODST/REACH BEGIN -------------------------------------
def preH4(scenarios_list, engine, window):
stage_count = 0
total_stages = 11 # H3/Reach 12 by default, not including the actual map files, ODST + 1
for map in scenarios_list:
total_stages += 1
# Progress bar
window.geometry('450x700')
progress_label = tk.Label(window, text="Creating cache_builder folder")
progress_label.grid(row=13, column=1, padx=20, pady=5)
progress_var = tk.DoubleVar()
progress_bar = ttk.Progressbar(window, variable=progress_var, maximum=100)
progress_bar.grid(row=14, column=1, padx=20, pady=5, columnspan=3, sticky="ew")
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
window.update()
# Engine type
if engine == "Halo 3":
print("Halo 3")
engine_path = h3ek_path
if engine == "Halo 3: ODST":
print("ODST")
engine_path = odstek_path
total_stages += 1 # ODST has one extra stage
if engine == "Halo Reach":
print("Reach")
engine_path = hrek_path
short_name = os.path.basename(engine_path)
tool_exe = os.path.join(engine_path, "tool.exe")
map_languages = os.path.join(engine_path, "AllLanguages.txt")
maps_folder = os.path.join(engine_path, "maps")
sound_codex = os.path.join(
engine_path, "cache_builder", "sounds_file_codex.bin")
dvd_prop_list = os.path.join(
engine_path, "cache_builder", "dvd_prop_list.txt")
platform_is_pc = True
target_platform = "pc"
LANGUAGE = "english"
VERSION = "0"
SHARED_SOUNDS = "use-shared-sounds"
DEDICATED_SERVER = ""
USE_FMOD_DATA = "use-fmod-data" if platform_is_pc else ""
# Create the cache builder folder if necessary
print("Create the cache builder folder if necessary")
cache_builder_folder = os.path.join(engine_path, "cache_builder")
os.makedirs(cache_builder_folder, exist_ok=True)
# 1 - Delete everything from cache_builder to avoid stale data corrupting the process
print("Delete everything from cache_builder to avoid stale data corrupting the process")
shutil.rmtree(cache_builder_folder, ignore_errors=True)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Deleting old maps")
window.update()
# 2 - Delete maps and RSA manifests from the maps folder
print("Delete maps and RSA manifests from the maps folder")
for file in os.listdir(maps_folder):
if file.endswith(".map") or file.startswith("security"):
os.remove(os.path.join(maps_folder, file))
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
window.update()
# 3 Build sound index for all maps
print("Build sound index for all maps")
# ODST specific command:
if engine == "Halo 3: ODST":
progress_label.config(text="Running ODST-specific sound command - this one takes a while")
window.update()
print("Running build-cache-file-cache-sounds-index. This can appear to freeze for a while, please be patient.")
run_executable_in_another_directory(tool_exe, ["build-cache-file-cache-sounds-index", "shared"])
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Building sound index")
window.update()
progress_label.config(text="Building sound index")
window.update()
for map in scenarios_list:
if os.path.exists(sound_codex):
argument_list = ["build-cache-file-cache-sounds-index", map, "append", target_platform]
run_executable_in_another_directory(tool_exe, argument_list)
else:
argument_list = ["build-cache-file-cache-sounds-index", map, target_platform]
run_executable_in_another_directory(tool_exe, argument_list)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Building sound cache files")
window.update()
# 4 Build sound cache files
print("Build sound cache files")
language_files = [LANGUAGE] if platform_is_pc else [
line.strip() for line in open(map_languages, "r")]
for language_file in language_files:
argument_list = ["build-cache-file-cache-sounds", target_platform, language_file, VERSION, USE_FMOD_DATA, DEDICATED_SERVER]
run_executable_in_another_directory(tool_exe, argument_list)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Generating full shared.map")
window.update()
# 5 - Generate full shared.map
print("Generate full shared.map")
argument_list = ["build-cache-file-cache-shared-first", target_platform, LANGUAGE, VERSION, "optimizable", SHARED_SOUNDS, USE_FMOD_DATA, DEDICATED_SERVER]
run_executable_in_another_directory(tool_exe, argument_list)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Generating full campaign.map")
window.update()
# 6 - Generate full campaign.map
print("Generate full campaign.map")
argument_list = ["build-cache-file-cache-campaign-second", target_platform, LANGUAGE, VERSION, "optimizable", USE_FMOD_DATA, DEDICATED_SERVER]
run_executable_in_another_directory(tool_exe, argument_list)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Building intermediate files for scenarios")
window.update()
# 7 - Generate intermediate files for levels
print("Generate intermediate files for levels")
for map in scenarios_list:
scenario_relative_path = os.path.join(
engine_path, "tags", f"{map}.scenario")
if os.path.exists(scenario_relative_path):
argument_list = ["build-cache-file-language-version-optimizable-use-sharing", LANGUAGE, VERSION, map, target_platform, SHARED_SOUNDS, USE_FMOD_DATA, DEDICATED_SERVER]
run_executable_in_another_directory(tool_exe, argument_list)
else:
print(f"Missing {scenario_relative_path}")
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Creating prop list")
window.update()
# 8 - Create dvd_prop_list.txt
print("Create prop list")
with open(dvd_prop_list, "w") as prop_list:
for map in scenarios_list:
map_name = os.path.splitext(os.path.basename(map))[0]
prop_list.write(
f"..\\cache_builder\\to_optimize\\{map_name}.cache_file_resource_gestalt\n")
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Copying files")
window.update()
# 9 - Copy shared.map and campaign.map to optimize directory
print("Copy shared.map and campaign.map to optimize directory")
dest_folder = os.path.join(cache_builder_folder, "to_optimize")
os.makedirs(dest_folder, exist_ok=True)
shared_map_src = os.path.join(maps_folder, "shared.map")
campaign_map_src = os.path.join(maps_folder, "campaign.map")
language_map_src = os.path.join(maps_folder, f"{LANGUAGE}.map")
shutil.copy2(shared_map_src, os.path.join(dest_folder, "shared.map"))
if os.path.exists(campaign_map_src):
shutil.copy2(campaign_map_src, os.path.join(dest_folder, "campaign.map"))
if os.path.exists(language_map_src):
shutil.copy2(language_map_src, os.path.join(
dest_folder, f"{LANGUAGE}.map"))
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Generating shared intermediate files")
window.update()
# 10 - Generate shared intermediate files
print("Generate shared intermediate files")
argument_list = ["generate-final-shared-layout", dvd_prop_list, target_platform, DEDICATED_SERVER]
run_executable_in_another_directory(tool_exe, argument_list)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
window.update()
# 11 - Generate optimized level cache files
print("Generate optimized level cache files")
for map in scenarios_list:
progress_label.config(text="Building " + os.path.basename(map) + ".map")
window.update()
scenario_relative_path = os.path.join(
engine_path, "tags", f"{map}.scenario")
if os.path.exists(scenario_relative_path):
argument_list = ["build-cache-file-generate-new-layout", map, target_platform, USE_FMOD_DATA, DEDICATED_SERVER]
run_executable_in_another_directory(tool_exe, argument_list)
else:
print(f"Missing {scenario_relative_path}")
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Generating optimised shared.map")
window.update()
# 12 - Generate optimized shared.map
print("Generate optimized shared.map")
argument_list = ["build-cache-file-link", "shared", target_platform, USE_FMOD_DATA, DEDICATED_SERVER]
run_executable_in_another_directory(tool_exe, argument_list)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Generating optimised campaign.map")
window.update()
# 13 - Generate optimized campaign.map
print("Generate optimized campaign.map")
argument_list = ["build-cache-file-link", "campaign", target_platform, USE_FMOD_DATA, DEDICATED_SERVER]
run_executable_in_another_directory(tool_exe, argument_list)
progress_label.config(text="Finished!")
window.update()
print("\n\nFinished successfully. Built map files are in \"" + short_name + "\\maps\"")
messagebox.showinfo("Success", "Finished successfully. Built map files are in \"" + short_name + "\\maps\"")
#-------------------------------------- H3/ODST/REACH END ---------------------------------------
#-------------------------------------- HALO 4 BEGIN --------------------------------------------
def build_cache_sharing(arg, tool_path):
run_executable_in_another_directory(tool_path, ["build-cache-file-language-version-optimizable-use-sharing", "english", "0", arg, "pc"])
def generate_new_layout(arg, tool_path):
fileName = os.path.splitext(os.path.basename(arg))[0]
run_executable_in_another_directory(tool_path, ["build-cache-file-generate-new-layout", fileName, "pc"])
def h4plus(selected_scens, engine, window):
stage_count = 0
total_stages = 8 # 8 by default, not including the actual map files
for map in selected_scens:
total_stages += 1
# Progress bar
window.geometry('450x700')
progress_label = tk.Label(window, text="Creating cache_builder folder")
progress_label.grid(row=13, column=1, padx=20, pady=5)
progress_var = tk.DoubleVar()
progress_bar = ttk.Progressbar(window, variable=progress_var, maximum=100)
progress_bar.grid(row=14, column=1, padx=20, pady=5, columnspan=3, sticky="ew")
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
window.update()
if engine == "Halo 4":
print("Halo 4")
engine_path = h4ek_path
if engine == "Halo 2: AMP":
print("H2AMP")
engine_path = h2amp_path
short_name = os.path.basename(engine_path)
tool_path = os.path.join(engine_path, "tool.exe")
# 1 Delete old cache_builder folder, remove existing .map files
shutil.rmtree(os.path.join(engine_path, "cache_builder"), ignore_errors=True)
files_to_delete = os.path.join(engine_path, "maps", "*.map")
for f in glob.glob(files_to_delete):
os.remove(f)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Generate full shared.map")
window.update()
# 2 Build shared map
run_executable_in_another_directory(tool_path, ["build-cache-file-cache-shared-first", "english", "0", "pc"])
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Generate full campaign.map")
window.update()
# 3 Build campaign map
run_executable_in_another_directory(tool_path, ["build-cache-file-cache-campaign-second", "english", "0", "pc"])
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
window.update()
# 4 Build scenarios
for scenario in selected_scens:
progress_label.config(text="Building " + os.path.basename(scenario) + ".map")
window.update()
build_cache_sharing(scenario, tool_path)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Copying files")
window.update()
# 5 Copy maps
shutil.copy(os.path.join(engine_path, "maps", "shared.map"), os.path.join(engine_path, "cache_builder", "to_optimize"))
if os.path.exists(os.path.join(engine_path, "maps", "campaign.map")):
shutil.copy(os.path.join(engine_path, "maps", "campaign.map"), os.path.join(engine_path, "cache_builder", "to_optimize"))
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Remove old prop list, generate new one")
window.update()
# 6 Remove old dvd_prop_list, build new
dvd_prop_list = os.path.join(engine_path, "built_dvd_prop_list.txt")
if os.path.exists(dvd_prop_list):
os.remove(dvd_prop_list)
for filename in glob.glob(os.path.join(engine_path, "cache_builder\\to_optimize\\*.cache_file_resource_gestalt")):
with open(dvd_prop_list, "a") as file:
file.write(f"../cache_builder/to_optimize/{os.path.basename(filename)}\n")
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Building final sharing layout")
window.update()
# 7 Build the final sharing layout file
run_executable_in_another_directory(tool_path, ["generate-final-shared-layout", dvd_prop_list, "pc"])
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Finalising map files")
window.update()
# 8 Finalise maps
for filename in glob.glob(os.path.join(engine_path, "cache_builder\\to_optimize\\*.cache_file_resource_gestalt")):
generate_new_layout(filename, tool_path)
update_tasks(progress_var, stage_count, total_stages, window)
stage_count += 1
progress_label.config(text="Relinking files")
window.update()
# 9 And relink
run_executable_in_another_directory(tool_path, ["build-cache-file-link", "shared", "pc"])
run_executable_in_another_directory(tool_path, ["build-cache-file-link", "campaign", "pc"])
progress_label.config(text="Finished!")
window.update()
print("\n\nFinished successfully. Built map files are in \"" + short_name + "\\maps\"")
messagebox.showinfo("Success", "Finished successfully. Built map files are in \"" + short_name + "\\maps\"")
#-------------------------------------- HALO 4 END ----------------------------------------------
def open_scenario_file(text_box, engine):
global h2ek_path, h3ek_path, odstek_path, hrek_path, h4ek_path, h2amp_path
def add_path():
text_box["state"] = "normal"
text_box.insert(tk.END, file_path + "\n")
text_box["state"] = "disabled"
file_path = filedialog.askopenfilename(filetypes=[("Scenario Files", "*.scenario")])
file_path_full = file_path
if file_path:
# Extract the desired part of the file path
file_path = os.path.normpath(file_path) # Normalize path separators
index = file_path.find("\\tags\\")
if index != -1:
file_path = file_path[index + 6:-9] # Strip "/tags/" and ".scenario" extension
# Check if filepath is already added
if text_box.search(file_path, "1.0", tk.END):
print("Scenario already added")
messagebox.showwarning("Warning", "Scenario already added, not adding it again!")
else:
# Check if filepath is valid for the given engine
if engine.get() == "Halo 2":
if "H2EK/tags" not in file_path_full:
messagebox.showerror("Error", "Scenario filepath does not look valid for selected engine!")
else:
add_path()
if h2ek_path == "":
index = file_path_full.find("/H2EK/")
if index != -1:
h2ek_path = os.path.normpath(file_path_full[:index + len("/H2EK/")])
print(h2ek_path)
else:
messagebox.showerror("Error", "Please contact the developer, this should not have happened")
exit(-3)
elif engine.get() == "Halo 3":
if "H3EK/tags" not in file_path_full:
messagebox.showerror("Error", "Scenario filepath does not look valid for selected engine!")
else:
add_path()
if h3ek_path == "":
index = file_path_full.find("/H3EK/")
if index != -1:
h3ek_path = os.path.normpath(file_path_full[:index + len("/H3EK/")])
print(h3ek_path)
else:
messagebox.showerror("Error", "Please contact the developer, this should not have happened")
exit(-3)
elif engine.get() == "Halo 3: ODST":
if "H3ODSTEK/tags" not in file_path_full:
messagebox.showerror("Error", "Scenario filepath does not look valid for selected engine!")
else:
add_path()
if odstek_path == "":
index = file_path_full.find("/H3ODSTEK/")
if index != -1:
odstek_path = os.path.normpath(file_path_full[:index + len("/H3ODSTEK/")])
print(odstek_path)
else:
messagebox.showerror("Error", "Please contact the developer, this should not have happened")
exit(-3)
elif engine.get() == "Halo Reach":
if "HREK/tags" not in file_path_full:
messagebox.showerror("Error", "Scenario filepath does not look valid for selected engine!")
else:
add_path()
if hrek_path == "":
index = file_path_full.find("/HREK/")
if index != -1:
hrek_path = os.path.normpath(file_path_full[:index + len("/HREK/")])
print(hrek_path)
else:
messagebox.showerror("Error", "Please contact the developer, this should not have happened")
exit(-3)
elif engine.get() == "Halo 4":
if "H4EK/tags" not in file_path_full:
messagebox.showerror("Error", "Scenario filepath does not look valid for selected engine!")
else:
add_path()
if h4ek_path == "":
index = file_path_full.find("/H4EK/")
if index != -1:
h4ek_path = os.path.normpath(file_path_full[:index + len("/H4EK/")])
print(h4ek_path)
else:
messagebox.showerror("Error", "Please contact the developer, this should not have happened")
exit(-3)
elif engine.get() == "Halo 2: AMP":
if "H2AMPEK/tags" not in file_path_full:
messagebox.showerror("Error", "Scenario filepath does not look valid for selected engine!")
else:
add_path()
if h2amp_path == "":
index = file_path_full.find("/H2AMPEK/")
if index != -1:
h2amp_path = os.path.normpath(file_path_full[:index + len("/H2AMPEK/")])
print(h2amp_path)
else:
messagebox.showerror("Error", "Please contact the developer, this should not have happened")
exit(-3)
else:
# User has cancelled
print("Cancelled")
def open_txt_file(allmaps_box, compile_button):
global allmaps_filepath
def add_allmaps_path(path_to_add):
allmaps_box["state"] = "normal"
allmaps_box.delete("1.0", tk.END)
allmaps_box.insert(tk.END, path_to_add)
allmaps_box["state"] = "disabled"
allmaps_path = filedialog.askopenfilename(filetypes=[("Text Files", "*.txt")], initialfile="AllMaps.txt")
# Check if the selected file is "AllMaps.txt"
if allmaps_path and not any(allmaps_path.lower().endswith(ext.lower()) for ext in ["AllMaps.txt", "AllMapsSP.txt", "AllMapsMP.txt"]):
messagebox.showerror("Error", "File is not an \"AllMaps.txt\" file")
compile_button["state"] = "disabled"
return
elif allmaps_path == "":
print("User didn't select txt")
compile_button["state"] = "disabled"
else:
valid_eks = ["H2EK", "H3EK", "H3ODSTEK", "HREK", "H4EK", "H2AMPEK"]
if any (substring in allmaps_path for substring in valid_eks):
print("AllMaps.txt is inside valid EK")
allmaps_filepath = allmaps_path
add_allmaps_path(allmaps_filepath)
compile_button["state"] = "normal"
else:
# Txt is not in any known EK
messagebox.showerror("Error", "AllMaps.txt not located in editing kit root folder.")
return
def remove_selected_line(text_box):
selected_index = text_box.tag_ranges("highlight")
if selected_index:
line_start, line_end = selected_index
line_content = text_box.get(line_start, line_end)
text_box["state"] = "normal"
text_box.delete(line_start, line_end)
text_box["state"] = "disabled"
print("Removed line:", line_content.strip())
def compile_scenarios(text_box, engine, window, allmaps, comp_button):
global allmaps_filepath
global h2ek_path
global h3ek_path
global odstek_path
global hrek_path
global h4ek_path
global h2amp_path
scenarios_list = []
# Check that text box isn't empty
if (text_box.get("1.0", "end-1c") == "") and not allmaps.get():
print("Empty")
messagebox.showerror("Error", "No scenarios added. Aborting compile process.")
else:
if allmaps.get() == False:
scenarios_list = text_box.get("1.0", "end-1c").splitlines()
engine_type = engine.get()
else:
# Grab scenarios list from txt
print("Open allmaps.txt")
try:
with open(allmaps_filepath, "r") as file:
maps = file.readlines()
maps = [line.strip() for line in maps]
except FileNotFoundError:
messagebox.showerror("Error", "Could not find AllMaps.txt")
print("AllMaps not found error")
return
except Exception as e:
messagebox.showerror("Error", "Unknown file error: " + e)
print("Unknown file error: " + e)
for map_path in maps:
# Check that scenario is valid/exists
full_scen_path = os.path.normpath(os.path.dirname(allmaps_filepath) + "/tags/" + map_path + ".scenario")
if os.path.exists(full_scen_path):
scenarios_list.append(map_path)
else:
print("Scenario path " + map_path + " is invalid")
messagebox.showerror("Error", "The following scenario path cannot be found. Please check the filepaths in AllMaps.txt for errors:\n" + full_scen_path)
return
# Set EK path
if "H2EK" in allmaps_filepath:
print("H2 allmaps.txt")
index = allmaps_filepath.find("H2EK")
h2ek_path = allmaps_filepath[:index + len("H2EK")]
engine_type = "Halo 2"
elif "H3EK" in allmaps_filepath:
print("H3 allmaps.txt")
index = allmaps_filepath.find("H3EK")
h3ek_path = allmaps_filepath[:index + len("H3EK")]
engine_type = "Halo 3"
elif "H3ODSTEK" in allmaps_filepath:
print("ODST allmaps.txt")
index = allmaps_filepath.find("H3ODSTEK")
odstek_path = allmaps_filepath[:index + len("H3ODSTEK")]
engine_type = "Halo 3: ODST"
elif "HREK" in allmaps_filepath:
print("HR allmaps.txt")
index = allmaps_filepath.find("HREK")
hrek_path = allmaps_filepath[:index + len("HREK")]
engine_type = "Halo Reach"
elif "H4EK" in allmaps_filepath:
print("H4 allmaps.txt")
index = allmaps_filepath.find("H4EK")
h4ek_path = allmaps_filepath[:index + len("H4EK")]
engine_type = "Halo 4"
elif "H2AMPEK" in allmaps_filepath:
print("H2A allmaps.txt")
index = allmaps_filepath.find("H2AMPEK")
h2amp_path = allmaps_filepath[:index + len("H2AMPEK")]
engine_type = "Halo 2: AMP"
print("Compiling scenarios")
if engine_type in ["Halo 3", "Halo 3: ODST", "Halo Reach"]:
preH4(scenarios_list, engine_type, window)
elif engine_type == "Halo 2":
h2(scenarios_list, window)
elif engine_type in ["Halo 4", "Halo 2: AMP"]:
h4plus(scenarios_list, engine_type, window)
else:
print("Something else has gone horrifically wrong")
exit(-2)
comp_button["state"] = "normal"
def main():
global progress_var
def highlight_line(event):
# Remove the "highlight" tag from any previously highlighted line
text_box.tag_remove("highlight", "1.0", "end")
# Add the "highlight" tag to the clicked line
text_box.tag_add("highlight", "current linestart", "current lineend+1c")
def on_checkbox_click():
checkbox_ticked = use_allmaps.get()
if checkbox_ticked:
# Disable control buttons
add_button["state"] = "disabled"
remove_button["state"] = "disabled"
selected_label["state"] = "disabled"
ek_entry["state"] = "disabled"
folder_label["state"] = "disabled"
compile_button["state"] = "disabled"
allmaps_select_label["state"] = "normal"
allmaps_box["state"] = "normal"
allmaps_button["state"] = "normal"
else:
# Enable control buttons
add_button["state"] = "normal"
remove_button["state"] = "normal"
selected_label["state"] = "normal"
ek_entry["state"] = "normal"
folder_label["state"] = "normal"
compile_button["state"] = "normal"
allmaps_select_label["state"] = "disabled"
allmaps_box["state"] = "disabled"
allmaps_button["state"] = "disabled"
# Window creation
window = tk.Tk()
window.title('MCC Build Optimized Maps Tool')
window.geometry('450x580')
window.resizable(width=False, height=False)
# Information header
header_font = font.Font(size=10, weight='bold')
info_label = tk.Label(window, text='Supported: H2, H3, ODST, HR, H4, H2AMP', font=header_font)
info_label.grid(row=0, column=1, padx=5, pady=5)
# Get engine version
style = ttk.Style()
style.theme_use('vista')
selected_engine = tk.StringVar(window)
selected_engine.set("Halo 3") # Default to H3
folder_label = tk.Label(window, text='Select engine version:')
folder_label.grid(row=2, column=1, padx=5, pady=5)
ek_entry = ttk.Combobox(window, textvariable=selected_engine, values=["Halo 2", "Halo 3", "Halo 3: ODST", "Halo Reach", "Halo 4", "Halo 2: AMP"], state="readonly")
ek_entry.grid(row=3, column=1, padx=20, pady=5)
# Use AllMaps checkbox
use_allmaps = tk.BooleanVar()
checkbox = tk.Checkbutton(window, text="Use AllMaps.txt", variable=use_allmaps, command=on_checkbox_click)
checkbox.grid(row=4, column=1, padx=5, pady=5)
# AllMaps txt selection
allmaps_select_label = tk.Label(window, text="AllMaps.txt file:")
allmaps_select_label.grid(row=5, column=1, padx=5, pady=1)
allmaps_select_label["state"] = "disabled"
allmaps_box = tk.Text(window, height=3, width=50)
allmaps_box.grid(row=6, column=1, padx=5, pady=1)
allmaps_box["state"] = "disabled"
allmaps_button = tk.Button(window, text="Choose AllMaps.txt", command=lambda: open_txt_file(allmaps_box, compile_button))
allmaps_button.grid(row=7, column=1, padx=5, pady=1)
allmaps_button["state"] = "disabled"
# Text box
selected_label = tk.Label(window, text='Selected scenario paths:')
selected_label.grid(row=8, column=1, padx=5, pady=5)
text_box = tk.Text(window, wrap=tk.WORD, height=10, width=50)
text_box.tag_configure("highlight", background="blue", foreground="white")
text_box.bind("<1>", highlight_line)
text_box.grid(row=9, column=1, padx=20, pady=5)
text_box["state"] = "disabled"
# Add button
add_button = tk.Button(window, text="Add Scenario", command=lambda : open_scenario_file(text_box, ek_entry))
add_button.grid(row=10, column=1, padx=20, pady=5)
# Remove button
remove_button = tk.Button(window, text="Remove Selected Scenario", command=lambda : remove_selected_line(text_box))
remove_button.grid(row=11, column=1, padx=20, pady=5)
# Compile button
compile_button = tk.Button(window, text="Compile Scenarios!", command=lambda : compile_scenarios(text_box, ek_entry, window, use_allmaps, compile_button))
compile_button.grid(row=12, column=1, padx=20, pady=30)
window.mainloop()
if __name__ == "__main__":
main()