-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfg.ps1
More file actions
1107 lines (968 loc) · 41 KB
/
cfg.ps1
File metadata and controls
1107 lines (968 loc) · 41 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
#requires -version 7.0
<#
.SYNOPSIS
Import a mod for the game from either a folder or zip file.
.DESCRIPTION
This script provides a Windows UI to select and import a mod from either:
- A folder containing index.js (directly or in src/ subfolder)
- A zip file containing the mod structure
The mod will be imported to GameRun/mods/ and the LBA2.cfg file will be updated.
.NOTES
Requires PowerShell 7.0 or later
Requires Windows Forms (available on Windows)
#>
param(
[Parameter(Mandatory = $false)]
[switch]$LangSelectOnly,
[Parameter(Mandatory = $false)]
[switch]$DontShowSuccess
)
# Ensure we're running PowerShell 7+
if ($PSVersionTable.PSVersion.Major -lt 7) {
Write-Error "This script requires PowerShell 7.0 or later. Current version: $($PSVersionTable.PSVersion)"
exit 1
}
# Add Windows Forms assembly
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Global variables
$script:GameRunModsPath = "GameRun/mods"
$script:DebugLBACfgPath = "Debug/LBA2.cfg"
$script:ReleaseLBACfgPath = "Release/LBA2.cfg"
$script:LanguageAction = $null
function Get-LanguageSettingsFromCfg {
<#
.SYNOPSIS
Reads current Language and LanguageCD settings from a cfg file
#>
param(
[Parameter(Mandatory = $true)]
[string]$ConfigPath
)
$defaultResult = @{
TextLanguage = "English"
AudioLanguage = "English"
}
if (-not (Test-Path $ConfigPath)) {
return $defaultResult
}
try {
$content = Get-Content $ConfigPath
$textLanguage = "English"
$audioLanguage = "English"
foreach ($line in $content) {
$trimmedLine = $line.TrimStart()
if ($trimmedLine.StartsWith("Language:")) {
$textLanguage = ($trimmedLine -replace "Language:\s*", "").Trim()
}
elseif ($trimmedLine.StartsWith("LanguageCD:")) {
$audioLanguage = ($trimmedLine -replace "LanguageCD:\s*", "").Trim()
}
}
return @{
TextLanguage = $textLanguage
AudioLanguage = $audioLanguage
}
}
catch {
Write-Host "Error reading language settings from ${ConfigPath}: $($_.Exception.Message)" -ForegroundColor Yellow
return $defaultResult
}
}
function Show-LanguageSelectionDialog {
<#
.SYNOPSIS
Shows a dialog for selecting text and audio languages
#>
param(
[Parameter(Mandatory = $false)]
[string]$InitialTextLanguage = "English",
[Parameter(Mandatory = $false)]
[string]$InitialAudioLanguage = "English",
[Parameter(Mandatory = $false)]
[string]$ConfigType = "Release"
)
# Available languages based on the cfg comments
$textLanguages = @("English", "Français", "Deutsch", "Español", "Italiano", "Portugues")
$audioLanguages = @("English", "Français", "Deutsch")
# Create main form
$form = New-Object System.Windows.Forms.Form
$form.Text = "Language Selection ($ConfigType)"
$form.Size = New-Object System.Drawing.Size(410, 450)
$form.StartPosition = "CenterScreen"
$form.FormBorderStyle = "FixedDialog"
$form.MaximizeBox = $false
$form.MinimizeBox = $false
# Text Language Group
$groupTextLang = New-Object System.Windows.Forms.GroupBox
$groupTextLang.Location = New-Object System.Drawing.Point(20, 20)
$groupTextLang.Size = New-Object System.Drawing.Size(340, 180)
$groupTextLang.Text = "Text Language"
$form.Controls.Add($groupTextLang)
# Text language radio buttons
$textRadioButtons = @{}
$yPos = 25
foreach ($lang in $textLanguages) {
$radio = New-Object System.Windows.Forms.RadioButton
$radio.Location = New-Object System.Drawing.Point(15, $yPos)
$radio.Size = New-Object System.Drawing.Size(300, 20)
$radio.Text = $lang
$radio.Name = "text_$lang"
if ($lang -eq $InitialTextLanguage) { $radio.Checked = $true }
$textRadioButtons[$lang] = $radio
$groupTextLang.Controls.Add($radio)
$yPos += 25
}
# Audio Language Group
$groupAudioLang = New-Object System.Windows.Forms.GroupBox
$groupAudioLang.Location = New-Object System.Drawing.Point(20, 220)
$groupAudioLang.Size = New-Object System.Drawing.Size(340, 110)
$groupAudioLang.Text = "Audio Language"
$form.Controls.Add($groupAudioLang)
# Audio language radio buttons
$audioRadioButtons = @{}
$yPos = 25
foreach ($lang in $audioLanguages) {
$radio = New-Object System.Windows.Forms.RadioButton
$radio.Location = New-Object System.Drawing.Point(15, $yPos)
$radio.Size = New-Object System.Drawing.Size(300, 20)
$radio.Text = $lang
$radio.Name = "audio_$lang"
if ($lang -eq $InitialAudioLanguage) { $radio.Checked = $true }
$audioRadioButtons[$lang] = $radio
$groupAudioLang.Controls.Add($radio)
$yPos += 25
}
# Confirm button
$buttonConfirm = New-Object System.Windows.Forms.Button
$buttonConfirm.Location = New-Object System.Drawing.Point(100, 360)
$buttonConfirm.Size = New-Object System.Drawing.Size(180, 30)
$buttonConfirm.Text = "Confirm Language Selection"
$buttonConfirm.Add_Click({
# Get selected languages
$selectedTextLang = $null
$selectedAudioLang = $null
foreach ($lang in $textLanguages) {
if ($textRadioButtons[$lang].Checked) {
$selectedTextLang = $lang
break
}
}
foreach ($lang in $audioLanguages) {
if ($audioRadioButtons[$lang].Checked) {
$selectedAudioLang = $lang
break
}
}
# Store results in form tag for retrieval
$form.Tag = @{
TextLanguage = $selectedTextLang
AudioLanguage = $selectedAudioLang
}
$form.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.Close()
})
$form.Controls.Add($buttonConfirm)
# Cancel button
$buttonCancel = New-Object System.Windows.Forms.Button
$buttonCancel.Location = New-Object System.Drawing.Point(300, 360)
$buttonCancel.Size = New-Object System.Drawing.Size(80, 30)
$buttonCancel.Text = "Cancel"
$buttonCancel.Add_Click({
$form.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.Close()
})
$form.Controls.Add($buttonCancel)
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
return $form.Tag
}
return $null
}
function Show-MainDialog {
<#
.SYNOPSIS
Shows a dialog for selecting mod source (folder or zip file)
#>
# Check if cfg files exist first (needed for form sizing)
$releaseExists = Test-Path $script:ReleaseLBACfgPath
$debugExists = Test-Path $script:DebugLBACfgPath
# Create main form
$form = New-Object System.Windows.Forms.Form
$form.Text = "LBA2 IdaJS Tools"
# Adjust form height based on button layout
$formHeight = 240 # Base height
if ($debugExists) {
$formHeight = 280 # Extra height when both buttons are present vertically
}
$form.Size = New-Object System.Drawing.Size(450, $formHeight)
$form.StartPosition = "CenterScreen"
$form.FormBorderStyle = "FixedDialog"
$form.MaximizeBox = $false
$form.MinimizeBox = $false
# Mod Import Section
$labelModImport = New-Object System.Windows.Forms.Label
$labelModImport.Location = New-Object System.Drawing.Point(20, 20)
$labelModImport.Size = New-Object System.Drawing.Size(400, 20)
$labelModImport.Text = "Import Mod:"
$labelModImport.Font = New-Object System.Drawing.Font("Microsoft Sans Serif", 9, [System.Drawing.FontStyle]::Bold)
$form.Controls.Add($labelModImport)
# Folder button
$buttonFolder = New-Object System.Windows.Forms.Button
$buttonFolder.Location = New-Object System.Drawing.Point(50, 50)
$buttonFolder.Size = New-Object System.Drawing.Size(120, 30)
$buttonFolder.Text = "Select Folder"
$buttonFolder.Add_Click({
$form.DialogResult = [System.Windows.Forms.DialogResult]::Yes
$form.Close()
})
$form.Controls.Add($buttonFolder)
# Zip file button
$buttonZip = New-Object System.Windows.Forms.Button
$buttonZip.Location = New-Object System.Drawing.Point(250, 50)
$buttonZip.Size = New-Object System.Drawing.Size(120, 30)
$buttonZip.Text = "Select ZIP File"
$buttonZip.Add_Click({
$form.DialogResult = [System.Windows.Forms.DialogResult]::No
$form.Close()
})
$form.Controls.Add($buttonZip)
# Other Settings Section
$labelOtherSettings = New-Object System.Windows.Forms.Label
$labelOtherSettings.Location = New-Object System.Drawing.Point(20, 100)
$labelOtherSettings.Size = New-Object System.Drawing.Size(400, 20)
$labelOtherSettings.Text = "Other Settings:"
$labelOtherSettings.Font = New-Object System.Drawing.Font("Microsoft Sans Serif", 9, [System.Drawing.FontStyle]::Bold)
$form.Controls.Add($labelOtherSettings)
# Language Settings buttons configuration
$languageButtons = @()
$currentY = 130
# Define button configurations based on existence
if ($releaseExists) {
$languageButtons += @{
Text = "Language Settings"
Action = "LanguageRelease"
Enabled = $true
Tooltip = $null
}
}
if ($debugExists) {
$languageButtons += @{
Text = "Language Settings (Debug)"
Action = "LanguageDebug"
Enabled = $true
Tooltip = $null
}
}
# Add grayed out Release button if needed
if (-not $releaseExists) {
$languageButtons += @{
Text = "Language Settings"
Action = $null
Enabled = $false
Tooltip = "Run project setup first"
}
}
# Create and position buttons
foreach ($buttonConfig in $languageButtons) {
$button = New-Object System.Windows.Forms.Button
$button.Location = New-Object System.Drawing.Point(50, $currentY)
$button.Size = New-Object System.Drawing.Size(140, 40)
$button.Text = $buttonConfig.Text
$button.Enabled = $buttonConfig.Enabled
if ($buttonConfig.Action) {
# Create click handler with proper variable scoping
$button | Add-Member -MemberType NoteProperty -Name "ActionValue" -Value $buttonConfig.Action
$button.Add_Click({
$script:LanguageAction = $this.ActionValue
$form.DialogResult = [System.Windows.Forms.DialogResult]::Retry
$form.Close()
})
}
# Add warning label for disabled buttons instead of tooltip
if ($buttonConfig.Tooltip) {
$warningLabel = New-Object System.Windows.Forms.Label
$warningLabel.Location = New-Object System.Drawing.Point(50, ($currentY + 45))
$warningLabel.Size = New-Object System.Drawing.Size(300, 20)
$warningLabel.Text = $buttonConfig.Tooltip
$warningLabel.ForeColor = [System.Drawing.Color]::Red
$warningLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif", 8, [System.Drawing.FontStyle]::Italic)
$form.Controls.Add($warningLabel)
$currentY += 25 # Extra space for the warning label
}
$form.Controls.Add($button)
$currentY += 45
}
# Cancel button - positioned to the right of the language buttons
$buttonCancel = New-Object System.Windows.Forms.Button
$buttonCancel.Location = New-Object System.Drawing.Point(250, 130)
$buttonCancel.Size = New-Object System.Drawing.Size(80, 30)
$buttonCancel.Text = "Cancel"
$buttonCancel.Add_Click({
$form.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.Close()
})
$form.Controls.Add($buttonCancel)
return $form.ShowDialog()
}
function Select-ModFolder {
<#
.SYNOPSIS
Opens a folder browser dialog to select a mod folder
#>
$folderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$folderBrowser.Description = "Select the mod folder containing index.js"
$folderBrowser.ShowNewFolderButton = $false
if ($folderBrowser.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
return $folderBrowser.SelectedPath
}
return $null
}
function Select-ModZipFile {
<#
.SYNOPSIS
Opens a file dialog to select a mod zip file
#>
$fileDialog = New-Object System.Windows.Forms.OpenFileDialog
$fileDialog.Title = "Select the mod ZIP file"
$fileDialog.Filter = "ZIP files (*.zip)|*.zip|All files (*.*)|*.*"
$fileDialog.FilterIndex = 1
if ($fileDialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
return $fileDialog.FileName
}
return $null
}
function Test-IndexJsExists {
<#
.SYNOPSIS
Tests if index.js exists in the specified path or src subfolder
#>
param(
[Parameter(Mandatory = $true)]
[string]$Path
)
$indexJsPath = Join-Path $Path "index.js"
$srcIndexJsPath = Join-Path $Path "src/index.js"
if (Test-Path $indexJsPath) {
return @{ Found = $true; Path = $indexJsPath; IsInSrc = $false }
}
elseif (Test-Path $srcIndexJsPath) {
return @{ Found = $true; Path = $srcIndexJsPath; IsInSrc = $true }
}
else {
return @{ Found = $false; Path = $null; IsInSrc = $false }
}
}
function Confirm-Overwrite {
<#
.SYNOPSIS
Shows a confirmation dialog for overwriting existing mod
#>
param(
[Parameter(Mandatory = $true)]
[string]$ModName
)
$result = [System.Windows.Forms.MessageBox]::Show(
"Mod '$ModName' already exists. Do you want to overwrite it?",
"Overwrite Confirmation",
[System.Windows.Forms.MessageBoxButtons]::YesNo,
[System.Windows.Forms.MessageBoxIcon]::Question
)
return $result -eq [System.Windows.Forms.DialogResult]::Yes
}
function Import-ModFromFolder {
<#
.SYNOPSIS
Imports a mod from a selected folder
#>
param(
[Parameter(Mandatory = $true)]
[string]$FolderPath
)
try {
Write-Host "Importing mod from folder: $FolderPath"
# Check if index.js exists
$indexJsTest = Test-IndexJsExists -Path $FolderPath
if (-not $indexJsTest.Found) {
[System.Windows.Forms.MessageBox]::Show(
"No index.js file found in the selected folder or src subfolder.",
"Error",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Error
)
return $false
}
# Get mod folder name
$modName = Split-Path $FolderPath -Leaf
$destModPath = Join-Path $script:GameRunModsPath $modName
# Check if destination exists and confirm overwrite
if (Test-Path $destModPath) {
if (-not (Confirm-Overwrite -ModName $modName)) {
Write-Host "Import cancelled by user."
return $false
}
Remove-Item $destModPath -Recurse -Force
}
# Create destination directory
New-Item -Path $destModPath -ItemType Directory -Force | Out-Null
# Handle different source scenarios
if ($indexJsTest.IsInSrc) {
# Case 3: index.js is in src folder - copy contents of src folder + media folder if exists
$sourceDir = Join-Path $FolderPath "src"
Write-Host "Found index.js in src folder, copying all contents from src recursively"
# Copy all files and folders from src directory
$items = Get-ChildItem -Path $sourceDir -Force
foreach ($item in $items) {
$destItemPath = Join-Path $destModPath $item.Name
if ($item.PSIsContainer) {
Copy-Item -Path $item.FullName -Destination $destItemPath -Recurse -Force
Write-Host "Copied folder from src: $($item.Name)"
}
else {
Copy-Item -Path $item.FullName -Destination $destItemPath -Force
Write-Host "Copied file from src: $($item.Name)"
}
}
# Also check for media folder at the same level as src
$mediaPath = Join-Path $FolderPath "media"
if (Test-Path $mediaPath) {
$destMediaPath = Join-Path $destModPath "media"
Copy-Item -Path $mediaPath -Destination $destMediaPath -Recurse -Force
Write-Host "Copied media folder from root"
}
}
else {
# Case 4: index.js is in root - copy all contents of the folder
$sourceDir = $FolderPath
Write-Host "Found index.js in root folder, copying all contents recursively"
# Copy all files and folders from source directory
$items = Get-ChildItem -Path $sourceDir -Force
foreach ($item in $items) {
$destItemPath = Join-Path $destModPath $item.Name
if ($item.PSIsContainer) {
Copy-Item -Path $item.FullName -Destination $destItemPath -Recurse -Force
Write-Host "Copied folder: $($item.Name)"
}
else {
Copy-Item -Path $item.FullName -Destination $destItemPath -Force
Write-Host "Copied file: $($item.Name)"
}
}
}
return $modName
}
catch {
Write-Host "Error in Import-ModFromFolder: $($_.Exception.Message)" -ForegroundColor Red
[System.Windows.Forms.MessageBox]::Show(
"Failed to import mod from folder: $($_.Exception.Message)",
"Import Error",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Error
)
return $false
}
}
function Import-ModFromZip {
<#
.SYNOPSIS
Imports a mod from a selected zip file
#>
param(
[Parameter(Mandatory = $true)]
[string]$ZipPath
)
Write-Host "Importing mod from zip: $ZipPath"
# Create temporary directory
$tempPath = Join-Path $env:TEMP "ModImport_$(Get-Random)"
New-Item -Path $tempPath -ItemType Directory -Force | Out-Null
try {
# Extract zip file
Expand-Archive -Path $ZipPath -DestinationPath $tempPath -Force
# Find index.js in extracted contents
$extractedContents = Get-ChildItem $tempPath
$indexJsInfo = $null
$modSourcePath = $null
$modName = $null
# Check root level first - only look for index.js directly in root
$rootIndexJsPath = Join-Path $tempPath "index.js"
if (Test-Path $rootIndexJsPath) {
$indexJsInfo = @{ Found = $true; Path = $rootIndexJsPath; IsInSrc = $false }
$modSourcePath = $tempPath
$modName = [System.IO.Path]::GetFileNameWithoutExtension($ZipPath)
}
else {
# Check one level down (subfolders) - only look for index.js directly in subfolder root
foreach ($item in $extractedContents) {
if ($item.PSIsContainer) {
$subfolderIndexJsPath = Join-Path $item.FullName "index.js"
if (Test-Path $subfolderIndexJsPath) {
$indexJsInfo = @{ Found = $true; Path = $subfolderIndexJsPath; IsInSrc = $false }
$modSourcePath = $item.FullName
$modName = $item.Name
break
}
}
}
}
if (-not $indexJsInfo) {
[System.Windows.Forms.MessageBox]::Show(
"No index.js file found in the ZIP file (checked root and one level down).",
"Error",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Error
)
return $false
}
# Create destination mod path
$destModPath = Join-Path $script:GameRunModsPath $modName
# Check if destination exists and confirm overwrite
if (Test-Path $destModPath) {
if (-not (Confirm-Overwrite -ModName $modName)) {
Write-Host "Import cancelled by user."
return $false
}
Remove-Item $destModPath -Recurse -Force
}
# Create destination directory
New-Item -Path $destModPath -ItemType Directory -Force | Out-Null
# For ZIP files, index.js is always in the root of the source directory
$sourceDir = $modSourcePath
if ($modSourcePath -eq $tempPath) {
Write-Host "Found index.js in ZIP root, copying all contents recursively"
}
else {
Write-Host "Found index.js in subfolder root, copying all contents recursively"
}
# Copy all files and folders from source directory
$items = Get-ChildItem -Path $sourceDir -Force
foreach ($item in $items) {
$destItemPath = Join-Path $destModPath $item.Name
if ($item.PSIsContainer) {
Copy-Item -Path $item.FullName -Destination $destItemPath -Recurse -Force
Write-Host "Copied folder: $($item.Name)"
}
else {
Copy-Item -Path $item.FullName -Destination $destItemPath -Force
Write-Host "Copied file: $($item.Name)"
}
}
return $modName
}
finally {
# Clean up temporary directory
if (Test-Path $tempPath) {
Remove-Item $tempPath -Recurse -Force
}
}
}
function Update-LanguageInSingleLBACfg {
<#
.SYNOPSIS
Updates Language and LanguageCD settings in a single LBA2.cfg file
#>
param(
[Parameter(Mandatory = $true)]
[string]$ConfigPath,
[Parameter(Mandatory = $true)]
[string]$TextLanguage,
[Parameter(Mandatory = $true)]
[string]$AudioLanguage
)
if (-not (Test-Path $ConfigPath)) {
Write-Host "LBA2.cfg file not found at: $ConfigPath" -ForegroundColor Yellow
return $false
}
try {
$content = Get-Content $ConfigPath
$languageUpdated = $false
$languageCDUpdated = $false
# Update existing lines
for ($i = 0; $i -lt $content.Length; $i++) {
$line = $content[$i]
$trimmedLine = $line.TrimStart()
if ($trimmedLine.StartsWith("Language:")) {
$content[$i] = $line -replace "Language:.*", "Language: $TextLanguage"
$languageUpdated = $true
Write-Host "Updated Language setting in ${ConfigPath} to: $TextLanguage"
}
elseif ($trimmedLine.StartsWith("LanguageCD:")) {
$content[$i] = $line -replace "LanguageCD:.*", "LanguageCD: $AudioLanguage"
$languageCDUpdated = $true
Write-Host "Updated LanguageCD setting in ${ConfigPath} to: $AudioLanguage"
}
}
# Add missing settings at the beginning if not found
$newContent = @()
$addedSettings = @()
if (-not $languageUpdated) {
$addedSettings += "Language: $TextLanguage"
Write-Host "Added Language setting to ${ConfigPath}: $TextLanguage"
}
if (-not $languageCDUpdated) {
$addedSettings += "LanguageCD: $AudioLanguage"
Write-Host "Added LanguageCD setting to ${ConfigPath}: $AudioLanguage"
}
if ($addedSettings.Count -gt 0) {
# Add new settings at the beginning of the file
$newContent += $addedSettings
$newContent += ""
$newContent += $content
}
else {
$newContent = $content
}
Set-Content -Path $ConfigPath -Value $newContent
Write-Host "Successfully updated language settings in $ConfigPath"
return $true
}
catch {
Write-Host "Error updating language settings in ${ConfigPath}: $($_.Exception.Message)" -ForegroundColor Red
return $false
}
}
function Update-SingleLanguageSettings {
<#
.SYNOPSIS
Updates Language and LanguageCD settings in a specific LBA2.cfg file
#>
param(
[Parameter(Mandatory = $true)]
[string]$ConfigPath,
[Parameter(Mandatory = $true)]
[string]$TextLanguage,
[Parameter(Mandatory = $true)]
[string]$AudioLanguage,
[Parameter(Mandatory = $true)]
[string]$ConfigType,
[Parameter(Mandatory = $false)]
[switch]$DontShowSuccess
)
if (-not (Test-Path $ConfigPath)) {
[System.Windows.Forms.MessageBox]::Show(
"$ConfigType configuration file not found. Please build the project first.",
"Error",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Error
)
return $false
}
Write-Host "Updating $ConfigType configuration language settings..."
if (Update-LanguageInSingleLBACfg -ConfigPath $ConfigPath -TextLanguage $TextLanguage -AudioLanguage $AudioLanguage) {
if (-not $DontShowSuccess) {
[System.Windows.Forms.MessageBox]::Show(
"Successfully updated $ConfigType language settings.$([Environment]::NewLine)Text Language: $TextLanguage$([Environment]::NewLine)Audio Language: $AudioLanguage",
"Language Settings Updated",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Information
)
}
return $true
}
else {
[System.Windows.Forms.MessageBox]::Show(
"Failed to update $ConfigType language settings. Please check the error messages above.",
"Error",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Error
)
return $false
}
}
function Update-SingleLBACfg {
<#
.SYNOPSIS
Updates a single LBA2.cfg file to set the mod
#>
param(
[Parameter(Mandatory = $true)]
[string]$ConfigPath,
[Parameter(Mandatory = $true)]
[string]$ModName
)
if (-not (Test-Path $ConfigPath)) {
Write-Host "LBA2.cfg file not found at: $ConfigPath" -ForegroundColor Yellow
return $false
}
try {
$content = Get-Content $ConfigPath
$updated = $false
for ($i = 0; $i -lt $content.Length; $i++) {
$line = $content[$i]
$trimmedLine = $line.TrimStart()
if ($trimmedLine.StartsWith("Mod:")) {
$content[$i] = $line -replace "Mod:.*", "Mod: $ModName"
$updated = $true
break
}
}
if ($updated) {
Set-Content -Path $ConfigPath -Value $content
Write-Host "Updated ${ConfigPath} with mod: $ModName"
}
else {
# No 'Mod:' line found, add one after "Configuration file" line or at the beginning
Write-Host "No 'Mod:' line found in ${ConfigPath}, adding new one"
# Look for "Configuration file" line
$configLineIndex = -1
for ($i = 0; $i -lt $content.Length; $i++) {
if ($content[$i] -match "Configuration file") {
$configLineIndex = $i
break
}
}
if ($configLineIndex -ge 0) {
# Insert after the "Configuration file" line
Write-Host "Found 'Configuration file' line, adding Mod line after it"
$newContent = @()
$newContent += $content[0..$configLineIndex]
$newContent += "Mod: $ModName"
$newContent += ""
if ($configLineIndex + 1 -lt $content.Length) {
$newContent += $content[($configLineIndex + 1)..($content.Length - 1)]
}
}
else {
# Add at the beginning if no "Configuration file" line found
Write-Host "No 'Configuration file' line found, adding Mod line at the beginning"
$newContent = @("Mod: $ModName", "") + $content
}
Set-Content -Path $ConfigPath -Value $newContent
Write-Host "Added new Mod line to ${ConfigPath} with mod: $ModName"
}
return $true
}
catch {
Write-Host "Error updating ${ConfigPath}: $($_.Exception.Message)" -ForegroundColor Red
return $false
}
}
function Update-LBACfg {
<#
.SYNOPSIS
Updates LBA2.cfg files in Debug and/or Release folders to set the mod
#>
param(
[Parameter(Mandatory = $true)]
[string]$ModName
)
$debugExists = Test-Path $script:DebugLBACfgPath
$releaseExists = Test-Path $script:ReleaseLBACfgPath
if (-not $debugExists -and -not $releaseExists) {
[System.Windows.Forms.MessageBox]::Show(
"Neither Debug nor Release folder found. Cannot update LBA2.cfg files.",
"Warning",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Warning
)
return $false
}
$updateCount = 0
$totalAttempts = 0
# Update Debug config if Debug folder exists
if ($debugExists) {
$totalAttempts++
Write-Host "Updating Debug configuration..."
if (Update-SingleLBACfg -ConfigPath $script:DebugLBACfgPath -ModName $ModName) {
$updateCount++
}
}
# Update Release config if Release folder exists
if ($releaseExists) {
$totalAttempts++
Write-Host "Updating Release configuration..."
if (Update-SingleLBACfg -ConfigPath $script:ReleaseLBACfgPath -ModName $ModName) {
$updateCount++
}
}
if ($updateCount -eq 0) {
[System.Windows.Forms.MessageBox]::Show(
"Failed to update any LBA2.cfg files. Please check the error messages above.",
"Error",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Error
)
return $false
}
else {
Write-Host "Successfully updated $updateCount of $totalAttempts configuration files."
return $true
}
}
# Main execution
function Main {
try {
Write-Host "LBA2 IdaJs configuration Tool"
Write-Host "=============================="
# Check if we should only show language selection for Release
if ($LangSelectOnly) {
Write-Host "Language selection only mode for Release configuration"
# Check if Release cfg exists
if (-not (Test-Path $script:ReleaseLBACfgPath)) {
Write-Error "Release configuration file not found at: $script:ReleaseLBACfgPath"
Write-Error "Please build the Release configuration first."
exit 1
}
# Show Release language selection dialog directly
$currentSettings = Get-LanguageSettingsFromCfg -ConfigPath $script:ReleaseLBACfgPath
$languageSelection = Show-LanguageSelectionDialog -InitialTextLanguage $currentSettings.TextLanguage -InitialAudioLanguage $currentSettings.AudioLanguage -ConfigType "Release"
if ($languageSelection) {
Update-SingleLanguageSettings -ConfigPath $script:ReleaseLBACfgPath -TextLanguage $languageSelection.TextLanguage -AudioLanguage $languageSelection.AudioLanguage -ConfigType "Release" -DontShowSuccess:$DontShowSuccess
Write-Host "Language settings updated successfully."
}
else {
Write-Host "Language selection cancelled."
}
return # Exit after language selection in this mode
}
# Ensure GameRun/mods directory exists (only needed for full mode)
if (-not (Test-Path $script:GameRunModsPath)) {
New-Item -Path $script:GameRunModsPath -ItemType Directory -Force | Out-Null
Write-Host "Created mods directory: $script:GameRunModsPath"
}
# Main dialog loop - keeps showing main dialog until user chooses to exit
do {
$continueLoop = $false
# Show selection dialog
$dialogResult = Show-MainDialog
switch ($dialogResult) {
([System.Windows.Forms.DialogResult]::Retry) {
# User chose language settings
try {
$languageSelection = $null
if ($script:LanguageAction -eq "LanguageRelease") {
# Handle Release language settings
$currentSettings = Get-LanguageSettingsFromCfg -ConfigPath $script:ReleaseLBACfgPath
$languageSelection = Show-LanguageSelectionDialog -InitialTextLanguage $currentSettings.TextLanguage -InitialAudioLanguage $currentSettings.AudioLanguage -ConfigType "Release"
if ($languageSelection) {
Update-SingleLanguageSettings -ConfigPath $script:ReleaseLBACfgPath -TextLanguage $languageSelection.TextLanguage -AudioLanguage $languageSelection.AudioLanguage -ConfigType "Release" -DontShowSuccess:$DontShowSuccess
$continueLoop = $true # Return to main dialog after successful update
}
else {
Write-Host "Release language selection cancelled."
$continueLoop = $true # Return to main dialog
}
}
elseif ($script:LanguageAction -eq "LanguageDebug") {
# Handle Debug language settings
$currentSettings = Get-LanguageSettingsFromCfg -ConfigPath $script:DebugLBACfgPath
$languageSelection = Show-LanguageSelectionDialog -InitialTextLanguage $currentSettings.TextLanguage -InitialAudioLanguage $currentSettings.AudioLanguage -ConfigType "Debug"
if ($languageSelection) {
Update-SingleLanguageSettings -ConfigPath $script:DebugLBACfgPath -TextLanguage $languageSelection.TextLanguage -AudioLanguage $languageSelection.AudioLanguage -ConfigType "Debug" -DontShowSuccess:$DontShowSuccess
$continueLoop = $true # Return to main dialog after successful update
}
else {
Write-Host "Debug language selection cancelled."
$continueLoop = $true # Return to main dialog
}
}
# Reset the action
$script:LanguageAction = $null
}
catch {
Write-Host "Error during language settings: $($_.Exception.Message)" -ForegroundColor Red