-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUniGame_Launcher_one.au3
745 lines (702 loc) · 38.8 KB
/
UniGame_Launcher_one.au3
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
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=icon.ico
#AutoIt3Wrapper_Outfile=UniGame_Launcher_one.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UPX_Parameters=-9 --strip-relocs=0 --compress-exports=0 --compress-icons=0
#AutoIt3Wrapper_Res_Description=UniGame Launcher
#AutoIt3Wrapper_Res_Fileversion=1.5.1.47
#AutoIt3Wrapper_Res_ProductVersion=1.5.1.47
#AutoIt3Wrapper_Res_LegalCopyright=2017-2020, SalFisher47
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/tl /sf /sv
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Region ;**** Pragma Compile ****
#pragma compile(Console, False)
#pragma compile(x64, False)
#pragma compile(ExecLevel, AsInvoker)
#pragma compile(Compatibility, vista, win7, win8, win81, win10)
#pragma compile(AutoItExecuteAllowed, True)
#pragma compile(InputBoxRes, True)
#pragma compile(Stripper, True)
#pragma compile(FileVersion, 1.5.1.47)
#pragma compile(ProductVersion, 1.5.1.47)
#pragma compile(ProductName, 'UniGame Launcher')
#pragma compile(FileDescription, 'UniGame Launcher')
#pragma compile(LegalCopyright, '2017-2020, SalFisher47')
#pragma compile(CompanyName, 'SalFisher47')
#pragma compile(InternalName, 'UniGame Launcher')
#pragma compile(OriginalFilename, UniGame_Launcher_one.exe)
#EndRegion ;**** Pragma Compile ****
; === UniGame_Launcher_one.au3 =====================================================================================================
; Title .........: UniGame Launcher
; Version .......: 1.5.0.47
; AutoIt Version : 3.3.14.5
; Language ......: English
; Description ...: Universal Game Launcher one
; Author(s) .....: SalFisher47
; Last Modified .: June 23, 2020 - last compiled on June 23, 2020
; ==================================================================================================================================
#include <Array.au3>
#include <File.au3>
#include <WinAPI.au3>
#include <ProcessConstants.au3>
#include <StringConstants.au3>
#include "_Include\_UDF\Zip_Functions.au3" ; thanks to wraithdu - https://www.autoitscript.com/forum/topic/116565-zip-udf-zipfldrdll-library/#comments
Global $Env_RoamingAppData = @AppDataDir, _
$Env_LocalAppData = @LocalAppDataDir, _
$Env_ProgramData = @AppDataCommonDir, _
$Env_UserProfile = @UserProfileDir, _
$Env_SavedGames = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}")
If @error Then $Env_SavedGames = $Env_UserProfile & "\Saved Games"
Global $7z_dir = $Env_ProgramData & "\SalFisher47\7za", $7z = $7z_dir & "\7za.exe"
$Ini = @ScriptDir & "\" & StringTrimRight(@ScriptName, 4) & ".ini"
$ini_RunAdmin = IniRead($ini, "launcher", "run_admin", "")
$ini_1stRun = IniRead($ini, "launcher", "1st_run", "")
$_1st_run_ini = "_1st_run.ini"
; check for game path and add it to ini file in C:\ProgramData\SalFisher47\UniGame Launcher
If Not FileExists(@AppDataCommonDir & "\SalFisher47\UniGame Launcher") Then DirCreate(@AppDataCommonDir & "\SalFisher47\UniGame Launcher")
$Ini_ProgramData = @AppDataCommonDir & "\SalFisher47\UniGame Launcher\" & StringTrimRight(@ScriptName, 4) & ".ini"
FileInstall("ProgramData.ini", $Ini_ProgramData, 0)
; check if _1st_run.zip exists, when 1st_run = 1 in ini file
If $ini_1stRun == 1 Then
If Not FileExists(@ScriptDir & "\_1st_run.zip") Then
; $_1st_run_ini = "_1st_run_example.ini"
FileInstall("_1st_run.zip", @ScriptDir & "\_1st_run.zip", 0)
FileInstall("ProgramData.ini", $Ini_ProgramData, 1)
EndIf
EndIf
; check for 7za.exe, unpack it to C:\ProgramData\SalFisher47\7za if not present
; disabled now, using Zip_Functions.au3
;If Not FileExists($7z) Then
; DirCreate($7z_dir)
; FileInstall("_FileInstall\7za\7za.exe", $7z_dir & "\7za.exe", 0)
; FileInstall("_FileInstall\7za\7-Zip.chm", $7z_dir & "\7-Zip.chm", 0)
; FileInstall("_FileInstall\7za\License.txt", $7z_dir & "\License.txt", 0)
; FileInstall("_FileInstall\7za\Readme.txt", $7z_dir & "\Readme.txt", 0)
;EndIf
$exe_run = IniRead($Ini, "Exe", "exe_run", "")
$exe_path_full = @ScriptDir & "\" & $exe_run
$exe_only = StringTrimLeft($exe_path_full, StringInStr($exe_path_full, "\", 0, -1))
$exe_path_only = StringTrimRight($exe_path_full, StringLen($exe_only)+1)
$exe_cmd = IniRead($Ini, "Exe", "exe_cmd", "")
If $exe_cmd <> "" Then
If $CmdLineRaw <> "" Then
If $CmdLineRaw <> $exe_cmd Then
$exe_cmd = $exe_cmd & " " & $CmdLineRaw
EndIf
EndIf
EndIf
$exe_compat = IniRead($Ini, "Exe", "exe_compat", "")
$exe_run_alt = IniRead($Ini, "Exe", "exe_run_alt", "")
$exe_path_full_alt = @ScriptDir & "\" & $exe_run_alt
$exe_only_alt = StringTrimLeft($exe_path_full_alt, StringInStr($exe_path_full_alt, "\", 0, -1))
$exe_path_only_alt = StringTrimRight($exe_path_full_alt, StringLen($exe_only_alt)+1)
$exe_cmd_alt = IniRead($Ini, "Exe", "exe_cmd_alt", "")
If $exe_cmd_alt <> "" Then
If $CmdLineRaw <> "" Then
If $CmdLineRaw <> $exe_cmd_alt Then
$exe_cmd_alt = $exe_cmd_alt & " " & $CmdLineRaw
EndIf
EndIf
EndIf
$exe_compat_alt = IniRead($Ini, "Exe", "exe_compat_alt", "")
$run_next = IniRead($Ini, "Exe", "run_next", 0)
; convert cpu affinity mask from binary to hexadecimal
$affinity_mask_bin = IniRead($Ini, "process", "affinity_mask", "")
If $affinity_mask_bin <> "" Then
$affinity_mask_dec = _Bin2Dec($affinity_mask_bin)
$affinity_mask_hex = Hex($affinity_mask_dec)
For $i = 1 To StringLen($affinity_mask_hex)
If StringLeft($affinity_mask_hex, 1) == 0 Then
$affinity_mask_hex = StringTrimLeft($affinity_mask_hex, 1)
EndIf
Next
$affinity_mask_hex = "0x" & $affinity_mask_hex
EndIf
; real game exe
$exeR = IniRead($Ini, "process", "exe_real", "")
If $exeR == "" Then
$exeR = $exe_run
$exeR_path_full = $exe_path_full
$exeR_only = $exe_only
$exeR_path_only = $exe_path_only
Else
$exeR_path_full = @ScriptDir & "\" & $exeR
$exeR_only = StringTrimLeft($exeR_path_full, StringInStr($exeR_path_full, "\", 0, -1))
$exeR_path_only = StringTrimRight($exeR_path_full, StringLen($exeR_only)+1)
EndIf
; check for savegame path and add it to ini file in C:\ProgramData\SalFisher47\UniGame Launcher
$ini_Savegame_dir = IniRead($ini, "savegame", "savegame_dir", "")
$ini_Savegame_subdir = IniRead($ini, "savegame", "savegame_subdir", "")
$Savegame_dir = ""
Switch $ini_Savegame_dir
Case "MyDocs"
$Savegame_dir = @MyDocumentsDir & "\" & $ini_Savegame_subdir
Case "_MyDocs_"
$Savegame_dir = @MyDocumentsDir & "\" & $ini_Savegame_subdir
Case "PublicDocs"
$Savegame_dir = @DocumentsCommonDir & "\" & $ini_Savegame_subdir
Case "_PublicDocs_"
$Savegame_dir = @DocumentsCommonDir & "\" & $ini_Savegame_subdir
Case "RoamingAppData"
$Savegame_dir = $Env_RoamingAppData & "\" & $ini_Savegame_subdir
Case "_RoamingAppData_"
$Savegame_dir = $Env_RoamingAppData & "\" & $ini_Savegame_subdir
Case "LocalAppData"
$Savegame_dir = $Env_LocalAppData & "\" & $ini_Savegame_subdir
Case "_LocalAppData_"
$Savegame_dir = $Env_LocalAppData & "\" & $ini_Savegame_subdir
Case "ProgramData"
$Savegame_dir = $Env_ProgramData & "\" & $ini_Savegame_subdir
Case "_ProgramData_"
$Savegame_dir = $Env_ProgramData & "\" & $ini_Savegame_subdir
Case "SavedGames"
$Savegame_dir = $Env_SavedGames & "\" & $ini_Savegame_subdir
Case "_SavedGames_"
$Savegame_dir = $Env_SavedGames & "\" & $ini_Savegame_subdir
Case "UserProfile"
$Savegame_dir = @UserProfileDir & "\" & $ini_Savegame_subdir
Case "_UserProfile_"
$Savegame_dir = @UserProfileDir & "\" & $ini_Savegame_subdir
Case "GameDir"
$Savegame_dir = @ScriptDir & "\" & $ini_Savegame_subdir
Case "_GameDir_"
$Savegame_dir = @ScriptDir & "\" & $ini_Savegame_subdir
EndSwitch
; kill incompatible processes before starting the game
$Ini_kill_process = IniRead($Ini, "process", "end_process", "")
$Kill_process = ""
If $Ini_kill_process <> "" Then
$Kill_process = StringSplit($Ini_kill_process, ", ", $STR_ENTIRESPLIT)
For $i = 1 To $Kill_process[0]
If ProcessExists($Kill_process[$i]) Then
ProcessClose($Kill_process[$i])
Sleep(50)
EndIf
Next
EndIf
; intialize some variables and read fireall settings
Local $sName, $sPath, $sPort, $sRule, $sDelete, $sBin, $run_firewall
$Ini_firewall_block_in = IniRead($Ini, "Firewall", "exe_block_inbound", "")
$Ini_firewall_block_in_check = IniRead($Ini_ProgramData, "Firewall", "exe_block_inbound", "")
If $Ini_firewall_block_in <> $Ini_firewall_block_in_check Then
IniWrite($Ini_ProgramData, "Firewall", "exe_block_inbound", " " & $Ini_firewall_block_in)
$run_firewall = 1
EndIf
$firewall_block_in = ""
If $Ini_firewall_block_in <> "" Then $firewall_block_in = StringSplit($Ini_firewall_block_in, ", ", $STR_ENTIRESPLIT)
$Ini_firewall_block_out = IniRead($Ini, "Firewall", "exe_block_outbound", "")
$Ini_firewall_block_out_check = IniRead($Ini_ProgramData, "Firewall", "exe_block_outbound", "")
If $Ini_firewall_block_out <> $Ini_firewall_block_out_check Then
IniWrite($Ini_ProgramData, "Firewall", "exe_block_outbound", " " & $Ini_firewall_block_out)
$run_firewall = 1
EndIf
$firewall_block_out = ""
If $Ini_firewall_block_out <> "" Then $firewall_block_out = StringSplit($Ini_firewall_block_out, ", ", $STR_ENTIRESPLIT)
$Ini_exe_block_Reset = IniRead($Ini, "Firewall", "exe_block_Reset", 0)
$Ini_exe_block_Reset_check = IniRead($Ini_ProgramData, "Firewall", "exe_block_Reset", 0)
If $Ini_exe_block_Reset <> $Ini_exe_block_Reset_check Then
IniWrite($Ini_ProgramData, "Firewall", "exe_block_Reset", " " & $Ini_exe_block_Reset)
$run_firewall = 1
EndIf
$Ini_ports_open_tcp = IniRead($Ini, "Firewall", "port_open_TCP", "")
$Ini_ports_open_tcp_check = IniRead($Ini_ProgramData, "Firewall", "port_open_TCP", "")
If $Ini_ports_open_tcp <> $Ini_ports_open_tcp_check Then
IniWrite($Ini_ProgramData, "Firewall", "port_open_TCP", " " & $Ini_ports_open_tcp)
$run_firewall = 1
EndIf
$ports_open_tcp = ""
If $Ini_ports_open_tcp <> "" Then $ports_open_tcp = StringSplit($Ini_ports_open_tcp, ", ", $STR_ENTIRESPLIT)
$Ini_ports_open_udp = IniRead($Ini, "Firewall", "port_open_UDP", "")
$Ini_ports_open_udp_check = IniRead($Ini_ProgramData, "Firewall", "port_open_UDP", "")
If $Ini_ports_open_udp <> $Ini_ports_open_udp_check Then
IniWrite($Ini_ProgramData, "Firewall", "port_open_UDP", " " & $Ini_ports_open_udp)
$run_firewall = 1
EndIf
$ports_open_udp = ""
If $Ini_ports_open_udp <> "" Then $ports_open_udp = StringSplit($Ini_ports_open_udp, ", ", $STR_ENTIRESPLIT)
$Ini_port_open_Reset = IniRead($Ini, "Firewall", "port_open_Reset", 0)
$Ini_port_open_Reset_check = IniRead($Ini_ProgramData, "Firewall", "port_open_Reset", 0)
If $Ini_port_open_Reset <> $Ini_port_open_Reset_check Then
IniWrite($Ini_ProgramData, "Firewall", "port_open_Reset", " " & $Ini_port_open_Reset)
$run_firewall = 1
EndIf
;$desktopRatio = Round(@DesktopWidth/@DesktopHeight, 2) --- not used now
; check if running as administrator, then execute _RunMain, _RunBefore & _RunAfter functions
If IniRead($Ini_ProgramData, "game", "game_path", "") <> @ScriptDir Then
$first_launch = 1
IniWrite($Ini_ProgramData, "game", "game_path", " " & @ScriptDir)
If IniRead($Ini_ProgramData, "game", "savegame_path", "") <> $Savegame_dir Then
IniWrite($Ini_ProgramData, "game", "savegame_path", " " & $Savegame_dir)
EndIf
If $ini_RunAdmin == 1 Then
_RunAdmin()
Exit
Else
If $run_firewall <> 1 Then
_RunMain()
Exit
Else
_RunAdmin()
Exit
EndIf
EndIf
Else
If IsAdmin() Then
$first_launch = 1
If IniRead($Ini_ProgramData, "game", "savegame_path", "") <> $Savegame_dir Then
IniWrite($Ini_ProgramData, "game", "savegame_path", " " & $Savegame_dir)
EndIf
_RunMain()
FileDelete(StringTrimRight(@ScriptFullPath, 3) & "a3x") ; delete .a3x script when running through a3x wrapper
Exit
Else
If $run_firewall <> 1 Then
$first_launch = 0
If IniRead($Ini_ProgramData, "game", "savegame_path", "") <> $Savegame_dir Then
IniWrite($Ini_ProgramData, "game", "savegame_path", " " & $Savegame_dir)
EndIf
_RunMain()
FileDelete(StringTrimRight(@ScriptFullPath, 3) & "a3x") ; delete .a3x script when running through a3x wrapper
Exit
Else
$first_launch = 1
If IniRead($Ini_ProgramData, "game", "savegame_path", "") <> $Savegame_dir Then
IniWrite($Ini_ProgramData, "game", "savegame_path", " " & $Savegame_dir)
EndIf
_RunAdmin()
If IsAdmin() Then FileDelete(StringTrimRight(@ScriptFullPath, 3) & "a3x") ; delete .a3x script when running through a3x wrapper
Exit
EndIf
EndIf
EndIf
; use this only if you want launcher friendly paths for ini files in C:\ProgramData\SalFisher47\UniGame Launcher
; $Savegame_dir = IniRead($Ini_ProgramData, "game", "savegame_path", "")
;_ReplaceStringInFile($ini_1stRun_open_file[$j], @MyDocumentsDir, "_MyDocs_")
;_ReplaceStringInFile($ini_1stRun_open_file[$j], @DocumentsCommonDir, "_PublicDocs_")
;_ReplaceStringInFile($ini_1stRun_open_file[$j], @LocalAppDataDir, "_LocalAppData_")
;_ReplaceStringInFile($ini_1stRun_open_file[$j], @AppDataDir, "_RoamingAppData_")
;_ReplaceStringInFile($ini_1stRun_open_file[$j], @AppDataCommonDir, "_ProgramData_")
;_ReplaceStringInFile($ini_1stRun_open_file[$j], @UserProfileDir, "_UserProfile_")
;_ReplaceStringInFile($ini_1stRun_open_file[$j], $Env_SavedGames, "_SavedGames_")
;_ReplaceStringInFile($ini_1stRun_open_file[$j], @ScriptDir, "_GameDir_")
Func _1st_run()
;$Unpack_Line_1st_run_7z = ' x -y -o' & '"' & @ScriptDir & '\_1st_run' & '"' & ' ' & '"' & @ScriptDir & "\_1st_run.7z" ; unpack whole archive
;$Unpack_Line_1st_run_ini = ' x -y -o' & '"' & @TempDir & '\_1st_run' & '"' & ' ' & '"' & @ScriptDir & "\_1st_run.7z" & '"' & ' ' & '"' & '_1st_run.ini' & '"' ; unpack only '_1st_run.ini' from archive
;$Unpack_Line_1st_run_dir = ' x -y -o' & '"' & @TempDir & '\_1st_run\destination_folder_name' & '"' & ' ' & '"' & @ScriptDir & "\_1st_run.7z" & '"' & ' ' & '"' & 'source_folder_name' & '\*' & '"' ; unpack 'source_folder_name' from archive
;ShellExecuteWait("7za.exe", $Unpack_Line_1st_run_7z, $7z_dir, "", @SW_HIDE) ; disabled now, using Zip_Functions.au3
_Zip_UnzipAll(@ScriptDir & "\_1st_run.zip", @ScriptDir & "\_1st_run")
;---
Local $ini_1stRun_copy_from[1], $ini_1stRun_copy_to[1], $ini_1stRun_open_file[1], $ini_1stRun_file_cmd[1]
For $i = 1 To 9
_ArrayAdd($ini_1stRun_copy_from, IniRead(@ScriptDir & "\_1st_run\" & $_1st_run_ini, "copy", "copy_from" & $i, ""))
If $ini_1stRun_copy_from[$i] <> "" Then
Switch StringLeft($ini_1stRun_copy_from[$i], 8)
Case "_SaveDir"
$ini_1stRun_copy_from[$i] = StringReplace($ini_1stRun_copy_from[$i], "_SaveDir_", $Savegame_dir)
Case "_MyDocs_"
$ini_1stRun_copy_from[$i] = StringReplace($ini_1stRun_copy_from[$i], "_MyDocs_", @MyDocumentsDir)
Case "_PublicD"
$ini_1stRun_copy_from[$i] = StringReplace($ini_1stRun_copy_from[$i], "_PublicDocs_", @DocumentsCommonDir )
Case "_LocalAp"
$ini_1stRun_copy_from[$i] = StringReplace($ini_1stRun_copy_from[$i], "_LocalAppData_", @LocalAppDataDir)
Case "_Roaming"
$ini_1stRun_copy_from[$i] = StringReplace($ini_1stRun_copy_from[$i], "_RoamingAppData_", @AppDataDir)
Case "_Program"
$ini_1stRun_copy_from[$i] = StringReplace($ini_1stRun_copy_from[$i], "_ProgramData_", @AppDataCommonDir)
Case "_UserPro"
$ini_1stRun_copy_from[$i] = StringReplace($ini_1stRun_copy_from[$i], "_UserProfile_", @UserProfileDir)
Case "_SavedGa"
$ini_1stRun_copy_from[$i] = StringReplace($ini_1stRun_copy_from[$i], "_SavedGames_", $Env_SavedGames)
Case "_GameDir"
$ini_1stRun_copy_from[$i] = StringReplace($ini_1stRun_copy_from[$i], "_GameDir_", @ScriptDir)
Case Else
$ini_1stRun_copy_from[$i] = @ScriptDir & "\_1st_run\" & $ini_1stRun_copy_from[$i]
EndSwitch
EndIf
_ArrayAdd($ini_1stRun_copy_to, IniRead(@ScriptDir & "\_1st_run\" & $_1st_run_ini, "copy", "copy_to" & $i, ""))
If $ini_1stRun_copy_to[$i] <> "" Then
Switch StringLeft($ini_1stRun_copy_to[$i], 8)
Case "_SaveDir"
$ini_1stRun_copy_to[$i] = StringReplace($ini_1stRun_copy_to[$i], "_SaveDir_", $Savegame_dir)
Case "_MyDocs_"
$ini_1stRun_copy_to[$i] = StringReplace($ini_1stRun_copy_to[$i], "_MyDocs_", @MyDocumentsDir)
Case "_PublicD"
$ini_1stRun_copy_to[$i] = StringReplace($ini_1stRun_copy_to[$i], "_PublicDocs_", @DocumentsCommonDir )
Case "_LocalAp"
$ini_1stRun_copy_to[$i] = StringReplace($ini_1stRun_copy_to[$i], "_LocalAppData_", @LocalAppDataDir)
Case "_Roaming"
$ini_1stRun_copy_to[$i] = StringReplace($ini_1stRun_copy_to[$i], "_RoamingAppData_", @AppDataDir)
Case "_Program"
$ini_1stRun_copy_to[$i] = StringReplace($ini_1stRun_copy_to[$i], "_ProgramData_", @AppDataCommonDir)
Case "_UserPro"
$ini_1stRun_copy_to[$i] = StringReplace($ini_1stRun_copy_to[$i], "_UserProfile_", @UserProfileDir)
Case "_SavedGa"
$ini_1stRun_copy_to[$i] = StringReplace($ini_1stRun_copy_to[$i], "_SavedGames_", $Env_SavedGames)
Case "_GameDir"
$ini_1stRun_copy_to[$i] = StringReplace($ini_1stRun_copy_to[$i], "_GameDir_", @ScriptDir)
EndSwitch
EndIf
If $ini_1stRun_copy_to[$i] == $Savegame_dir Then
If DirGetSize($ini_1stRun_copy_to[$i]) <> 0 Then
DirCopy($ini_1stRun_copy_to[$i], $ini_1stRun_copy_to[$i] & "_1st_run", 1)
FileCreateShortcut($ini_1stRun_copy_to[$i] & "_1st_run", $ini_1stRun_copy_to[$i] & "\_1st_run.lnk")
DirCopy($ini_1stRun_copy_from[$i], $ini_1stRun_copy_to[$i], 1)
Else
DirCopy($ini_1stRun_copy_from[$i], $ini_1stRun_copy_to[$i], 1)
EndIf
Else
DirCopy($ini_1stRun_copy_from[$i], $ini_1stRun_copy_to[$i], 1)
EndIf
Next
For $j = 1 To 9
_ArrayAdd($ini_1stRun_open_file, IniRead(@ScriptDir & "\_1st_run\" & $_1st_run_ini, "open", "open_file" & $j, ""))
If $ini_1stRun_open_file[$j] <> "" Then
Switch StringLeft($ini_1stRun_open_file[$j], 8)
Case "_SaveDir"
$ini_1stRun_open_file[$j] = StringReplace($ini_1stRun_open_file[$j], "_SaveDir_", $Savegame_dir)
Case "_MyDocs_"
$ini_1stRun_open_file[$j] = StringReplace($ini_1stRun_open_file[$j], "_MyDocs_", @MyDocumentsDir)
Case "_PublicD"
$ini_1stRun_open_file[$j] = StringReplace($ini_1stRun_open_file[$j], "_PublicDocs_", @DocumentsCommonDir )
Case "_LocalAp"
$ini_1stRun_open_file[$j] = StringReplace($ini_1stRun_open_file[$j], "_LocalAppData_", @LocalAppDataDir)
Case "_Roaming"
$ini_1stRun_open_file[$j] = StringReplace($ini_1stRun_open_file[$j], "_RoamingAppData_", @AppDataDir)
Case "_Program"
$ini_1stRun_open_file[$j] = StringReplace($ini_1stRun_open_file[$j], "_ProgramData_", @AppDataCommonDir)
Case "_UserPro"
$ini_1stRun_open_file[$j] = StringReplace($ini_1stRun_open_file[$j], "_UserProfile_", @UserProfileDir)
Case "_SavedGa"
$ini_1stRun_open_file[$j] = StringReplace($ini_1stRun_open_file[$j], "_SavedGames_", $Env_SavedGames)
Case "_GameDir"
$ini_1stRun_open_file[$j] = StringReplace($ini_1stRun_open_file[$j], "_GameDir_", @ScriptDir)
Case Else
$ini_1stRun_open_file[$j] = @ScriptDir & "\_1st_run\" & $ini_1stRun_open_file[$j]
EndSwitch
EndIf
_ArrayAdd($ini_1stRun_file_cmd, IniRead(@ScriptDir & "\_1st_run\" & $_1st_run_ini, "open", "file_cmd" & $j, ""))
If $ini_1stRun_file_cmd[$j] <> "" Then
If $CmdLineRaw <> "" Then
If $CmdLineRaw <> $ini_1stRun_file_cmd[$j] Then
$ini_1stRun_file_cmd[$j] = $ini_1stRun_file_cmd[$j] & " " & $CmdLineRaw
EndIf
EndIf
EndIf
$open_file_only = StringTrimLeft($ini_1stRun_open_file[$j], StringInStr($ini_1stRun_open_file[$j], "\", 0, -1))
$open_file_path_only = StringTrimRight($ini_1stRun_open_file[$j], StringLen($open_file_only)+1)
$open_file_extension = StringRight($open_file_only, 4)
If $ini_1stRun_open_file[$j] <> "" Then
Switch $open_file_extension
Case ".au3", ".a3x"
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_SaveDir_", $Savegame_dir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_MyDocs_", @MyDocumentsDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_PublicDocs_", @DocumentsCommonDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_LocalAppData_", @LocalAppDataDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_RoamingAppData_", @AppDataDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_ProgramData_", @AppDataCommonDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_UserProfile_", @UserProfileDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_SavedGames_", $Env_SavedGames)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_GameDir_", @ScriptDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_LauncherName_", @ScriptName)
ShellExecuteWait(@ScriptFullPath, ' /AutoIt3ExecuteScript ' & '"' & $ini_1stRun_open_file[$j] & '"', $open_file_path_only)
Case ".bat", ".ps1"
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_SaveDir_", $Savegame_dir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_MyDocs_", @MyDocumentsDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_PublicDocs_", @DocumentsCommonDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_LocalAppData_", @LocalAppDataDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_RoamingAppData_", @AppDataDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_ProgramData_", @AppDataCommonDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_UserProfile_", @UserProfileDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_SavedGames_", $Env_SavedGames)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_GameDir_", @ScriptDir)
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_LauncherName_", @ScriptName)
Switch $open_file_extension
Case ".bat"
FileInstall("_FileInstall\run_scripts\bat_script.au3", $ini_1stRun_open_file[$j] & '.au3', 1)
Case ".ps1"
FileInstall("_FileInstall\run_scripts\bat_script.au3", $ini_1stRun_open_file[$j] & '.au3', 1)
If FileExists(StringTrimRight($ini_1stRun_open_file[$j], 4) & '.bat') Then
FileCopy(StringTrimRight($ini_1stRun_open_file[$j], 4) & '.bat', StringTrimRight($ini_1stRun_open_file[$j], 4) & '_1st_run.bat', 1)
FileInstall("_FileInstall\run_scripts\ps1_script.bat", StringTrimRight($ini_1stRun_open_file[$j], 4) & '.bat', 1)
Else
FileInstall("_FileInstall\run_scripts\ps1_script.bat", StringTrimRight($ini_1stRun_open_file[$j], 4) & '.bat', 1)
EndIf
EndSwitch
_ReplaceStringInFile($ini_1stRun_open_file[$j] & '.au3', "_file_path_", '"' & StringTrimRight($ini_1stRun_open_file[$j], 4) & ".bat" & '"')
;RunWait(@ScriptFullPath & ' /AutoIt3ExecuteScript ' & '"' & $ini_1stRun_open_file[$j] & '.au3' & '"') ; for some reason this runs a second similarly named launcher if present, so we're gonna use ShellExecuteWait instead which prevents this from happening
ShellExecuteWait(@AutoItExe, ' /AutoIt3ExecuteScript ' & '"' & $ini_1stRun_open_file[$j] & '.au3' & '"', @ScriptDir)
Case ".reg"
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_SaveDir_", StringReplace($Savegame_dir, "\", "\\"))
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_MyDocs_", StringReplace(@MyDocumentsDir, "\", "\\"))
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_PublicDocs_", StringReplace(@DocumentsCommonDir, "\", "\\"))
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_LocalAppData_", StringReplace(@LocalAppDataDir, "\", "\\"))
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_RoamingAppData_", StringReplace(@AppDataDir, "\", "\\"))
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_ProgramData_", StringReplace(@AppDataCommonDir, "\", "\\"))
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_UserProfile_", StringReplace(@UserProfileDir, "\", "\\"))
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_SavedGames_", StringReplace($Env_SavedGames, "\", "\\"))
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_GameDir_", StringReplace(@ScriptDir, "\", "\\"))
_ReplaceStringInFile($ini_1stRun_open_file[$j], "_LauncherName_", @ScriptName)
FileInstall("_FileInstall\run_scripts\bat_script.au3", $ini_1stRun_open_file[$j] & '.au3', 1)
If FileExists(StringTrimRight($ini_1stRun_open_file[$j], 4) & '.bat') Then
FileCopy(StringTrimRight($ini_1stRun_open_file[$j], 4) & '.bat', StringTrimRight($ini_1stRun_open_file[$j], 4) & '_1st_run.bat', 1)
FileInstall("_FileInstall\run_scripts\reg_script_silent.bat", StringTrimRight($ini_1stRun_open_file[$j], 4) & '.bat', 1)
Else
FileInstall("_FileInstall\run_scripts\reg_script_silent.bat", StringTrimRight($ini_1stRun_open_file[$j], 4) & '.bat', 1)
EndIf
_ReplaceStringInFile($ini_1stRun_open_file[$j] & '.au3', "_file_path_", '"' & StringTrimRight($ini_1stRun_open_file[$j], 4) & ".bat" & '"')
;RunWait(@ScriptFullPath & ' /AutoIt3ExecuteScript ' & '"' & $ini_1stRun_open_file[$j] & '.au3' & '"') ; for some reason this runs a second similarly named launcher if present, so we're gonna use ShellExecuteWait instead which prevents this from happening
ShellExecuteWait(@AutoItExe, ' /AutoIt3ExecuteScript ' & '"' & $ini_1stRun_open_file[$j] & '.au3' & '"', @ScriptDir)
Case Else
ShellExecuteWait($open_file_only, $ini_1stRun_file_cmd[$j], $open_file_path_only)
EndSwitch
EndIf
Next
DirRemove(@ScriptDir & "\_1st_run", 1)
For $k = 1 to 9
If FileExists(StringTrimRight($ini_1stRun_open_file[$k], 4) & '_1st_run.bat') Then
FileDelete(StringTrimRight($ini_1stRun_open_file[$k], 4) & '.bat')
FileMove(StringTrimRight($ini_1stRun_open_file[$k], 4) & '_1st_run.bat', StringTrimRight($ini_1stRun_open_file[$k], 4) & '.bat', 1)
EndIf
Next
EndFunc
Func _RunBefore_FirstLaunch()
; add commands here to run before game exe at first launch
EndFunc
Func _RunAfter_FirstLaunch()
; add commands here to run after game exe at first launch
EndFunc
Func _RunBefore_EveryLaunch()
; add commands here to run before game exe at every launch, except the first one
EndFunc
Func _RunAfter_EveryLaunch()
; add commands here to run after game exe at every launch, except the first one
EndFunc
Func _RunMain() ; main script
RegRead('HKCU\Software\Valve\Steam', 'SteamPath')
If @error Then
RegWrite('HKCU\Software\Valve\Steam', 'SteamExe','REG_SZ','d:/steam/steam.exe')
RegWrite('HKCU\Software\Valve\Steam', 'SteamPath','REG_SZ','d:/steam')
RegWrite('HKLM\SOFTWARE\Valve\Steam', 'InstallPath','REG_SZ','D:\Steam')
EndIf
If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", $exe_path_full) <> $exe_compat Then
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", $exe_path_full, "REG_SZ", $exe_compat)
EndIf
If $Savegame_dir <> "" Then
If Not FileExists($Savegame_dir) Then DirCreate($Savegame_dir)
FileCreateShortcut($Savegame_dir, @ScriptDir & "\_savegame.lnk")
EndIf
If $first_launch == 1 Then
If $Ini_exe_block_Reset <> 1 Then
If $Ini_firewall_block_in <> "" Then
For $i = 1 To $firewall_block_in[0]
_FirewallBlockExe("_Block " & "'" & StringTrimLeft($firewall_block_in[$i], StringInStr($firewall_block_in[$i], "\", 0, -1)) & "'" & " - SalFisher47", @ScriptDir & "\" & $firewall_block_in[$i], "inbound", 1)
Next
EndIf
If $Ini_firewall_block_out <> "" Then
For $i = 1 To $firewall_block_out[0]
_FirewallBlockExe("_Block " & "'" & StringTrimLeft($firewall_block_out[$i], StringInStr($firewall_block_out[$i], "\", 0, -1)) & "'" & " - SalFisher47", @ScriptDir & "\" & $firewall_block_out[$i], "outbound", 1)
Next
EndIf
Else
If $Ini_firewall_block_in <> "" Then
For $i = 1 To $firewall_block_in[0]
_FirewallAllowExe("_Block " & "'" & StringTrimLeft($firewall_block_in[$i], StringInStr($firewall_block_in[$i], "\", 0, -1)) & "'" & " - SalFisher47", @ScriptDir & "\" & $firewall_block_in[$i], "inbound", 1)
Next
EndIf
If $Ini_firewall_block_out <> "" Then
For $i = 1 To $firewall_block_out[0]
_FirewallAllowExe("_Block " & "'" & StringTrimLeft($firewall_block_out[$i], StringInStr($firewall_block_out[$i], "\", 0, -1)) & "'" & " - SalFisher47", @ScriptDir & "\" & $firewall_block_out[$i], "outbound", 1)
Next
EndIf
EndIf
If $Ini_port_open_Reset <> 1 Then
If $Ini_ports_open_tcp <> "" Then
For $i = 1 To $ports_open_tcp[0]
_FirewallOpenTCP("_Open TCP port " & $ports_open_tcp[$i] & " - SalFisher47", $ports_open_tcp[$i], "inbound", 1)
_FirewallOpenTCP("_Open TCP port " & $ports_open_tcp[$i] & " - SalFisher47", $ports_open_tcp[$i], "outbound", 1)
Next
EndIf
If $Ini_ports_open_udp <> "" Then
For $i = 1 To $ports_open_udp[0]
_FirewallOpenUDP("_Open UDP port " & $ports_open_udp[$i] & " - SalFisher47", $ports_open_udp[$i], "inbound", 1)
_FirewallOpenUDP("_Open UDP port " & $ports_open_udp[$i] & " - SalFisher47", $ports_open_udp[$i], "outbound", 1)
Next
EndIf
Else
If $Ini_ports_open_tcp <> "" Then
For $i = 1 To $ports_open_tcp[0]
_FirewallCloseTCP("_Open TCP port " & $ports_open_tcp[$i] & " - SalFisher47", $ports_open_tcp[$i], "inbound", 1)
_FirewallCloseTCP("_Open TCP port " & $ports_open_tcp[$i] & " - SalFisher47", $ports_open_tcp[$i], "outbound", 1)
Next
EndIf
If $Ini_ports_open_udp <> "" Then
For $i = 1 To $ports_open_udp[0]
_FirewallCloseUDP("_Open UDP port " & $ports_open_udp[$i] & " - SalFisher47", $ports_open_udp[$i], "inbound", 1)
_FirewallCloseUDP("_Open UDP port " & $ports_open_udp[$i] & " - SalFisher47", $ports_open_udp[$i], "outbound", 1)
Next
EndIf
EndIf
; add commands here to run before game exe at first launch
If $ini_1stRun == 1 Then _1st_run()
;_RunBefore_FirstLaunch()
If $affinity_mask_bin <> "" Then
If $exe_run_alt <> "" Then
If $run_next <> 1 Then
ShellExecute($exe_only_alt, " " & $exe_cmd_alt, $exe_path_only_alt)
$pid = ProcessWait($exe_only_alt)
_WinAPI_SetProcessAffinityMask(_WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION+$PROCESS_SET_INFORMATION, False, $pid), $affinity_mask_hex)
Else
ShellExecute($exe_only_alt, " " & $exe_cmd_alt, $exe_path_only_alt)
$pid = ProcessWait($exe_only_alt)
_WinAPI_SetProcessAffinityMask(_WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION+$PROCESS_SET_INFORMATION, False, $pid), $affinity_mask_hex)
;ProcessWait($exe_only_alt) --- not used now
ProcessWaitClose($exe_only_alt)
Sleep(250)
If Not ProcessExists($exe_only) Then
ShellExecute($exe_only, " " & $exe_cmd, $exe_path_only)
$pid = ProcessWait($exeR_only)
_WinAPI_SetProcessAffinityMask(_WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION+$PROCESS_SET_INFORMATION, False, $pid), $affinity_mask_hex)
EndIf
EndIf
Else
ShellExecute($exe_only, " " & $exe_cmd, $exe_path_only)
$pid = ProcessWait($exeR_only)
_WinAPI_SetProcessAffinityMask(_WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION+$PROCESS_SET_INFORMATION, False, $pid), $affinity_mask_hex)
EndIf
Else
If $exe_run_alt <> "" Then
If $run_next <> 1 Then
ShellExecute($exe_only_alt, " " & $exe_cmd_alt, $exe_path_only_alt)
Else
ShellExecute($exe_only_alt, " " & $exe_cmd_alt, $exe_path_only_alt)
ProcessWait($exe_only_alt)
ProcessWaitClose($exe_only_alt)
Sleep(250)
If Not ProcessExists($exe_only) Then
ShellExecute($exe_only, " " & $exe_cmd, $exe_path_only)
EndIf
EndIf
Else
ShellExecute($exe_only, " " & $exe_cmd, $exe_path_only)
EndIf
EndIf
; add commands here to run after game exe at first launch
;_RunAfter_FirstLaunch()
Else
; add commands here to run before game exe at every launch, except the first one
;_RunBefore_EveryLaunch()
If $affinity_mask_bin <> "" Then
ShellExecute($exe_only, " " & $exe_cmd, $exe_path_only)
$pid = ProcessWait($exeR_only)
_WinAPI_SetProcessAffinityMask(_WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION+$PROCESS_SET_INFORMATION, False, $pid), $affinity_mask_hex)
Else
ShellExecute($exe_only, " " & $exe_cmd, $exe_path_only)
EndIf
; add commands here to run after game exe at every launch, except the first one
;_RunAfter_EveryLaunch()
EndIf
EndFunc
Func _RunAdmin() ; run main script as admin on first launch
If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", @ScriptDir & "\" & StringTrimRight(@ScriptName, 4) & ".exe") <> "RUNASADMIN" Then
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", @ScriptDir & "\" & StringTrimRight(@ScriptName, 4) & ".exe", "REG_SZ", "RUNASADMIN")
EndIf
;---
ShellExecute(StringTrimRight(@ScriptName, 4) & ".exe", $CmdLineRaw, @ScriptDir)
;---
If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", @ScriptDir & "\" & StringTrimRight(@ScriptName, 4) & ".exe") == "RUNASADMIN" Then
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", @ScriptDir & "\" & StringTrimRight(@ScriptName, 4) & ".exe", "REG_SZ", "")
EndIf
EndFunc
Func _FirewallBlockExe($sName, $sPath, $sRule, $sDelete)
Switch $sRule
Case "inbound"
If $sDelete == 1 Then
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall delete rule name = " & Chr(34) & $sName & Chr(34) & " program = " & Chr(34) & $sPath & Chr(34) & " dir = in", "", @SW_HIDE)
EndIf
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall add rule name = " & Chr(34) & $sName & Chr(34) & " dir = in action = block program = " & Chr(34) & $sPath & Chr(34) & " enable = yes", "", @SW_HIDE)
Case "outbound"
If $sDelete == 1 Then
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall delete rule name = " & Chr(34) & $sName & Chr(34) & " program = " & Chr(34) & $sPath & Chr(34) & " dir = out", "", @SW_HIDE)
EndIf
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall add rule name = " & Chr(34) & $sName & Chr(34) & " dir = out action = block program = " & Chr(34) & $sPath & Chr(34) & " enable = yes", "", @SW_HIDE)
EndSwitch
EndFunc
Func _FirewallAllowExe($sName, $sPath, $sRule, $sDelete)
Switch $sRule
Case "inbound"
If $sDelete == 1 Then
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall delete rule name = " & Chr(34) & $sName & Chr(34) & " program = " & Chr(34) & $sPath & Chr(34) & " dir = in", "", @SW_HIDE)
EndIf
;RunWait(@ComSpec & " /c " & "netsh advfirewall firewall add rule name = " & Chr(34) & $sName & Chr(34) & " dir = in action = allow program = " & Chr(34) & $sPath & Chr(34) & " enable = yes", "", @SW_HIDE)
Case "outbound"
If $sDelete == 1 Then
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall delete rule name = " & Chr(34) & $sName & Chr(34) & " program = " & Chr(34) & $sPath & Chr(34) & " dir = out", "", @SW_HIDE)
EndIf
;RunWait(@ComSpec & " /c " & "netsh advfirewall firewall add rule name = " & Chr(34) & $sName & Chr(34) & " dir = out action = allow program = " & Chr(34) & $sPath & Chr(34) & " enable = yes", "", @SW_HIDE)
EndSwitch
EndFunc
Func _FirewallOpenTCP($sName, $sPort, $sRule, $sDelete)
Switch $sRule
Case "inbound"
If $sDelete == 1 Then
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall delete rule name = " & Chr(34) & $sName & Chr(34) & " protocol = TCP localport = " & $sPort & " dir = in", "", @SW_HIDE)
EndIf
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall add rule name = " & Chr(34) & $sName & Chr(34) & " dir = in action = allow protocol = TCP localport = " & $sPort, "", @SW_HIDE)
Case "outbound"
If $sDelete == 1 Then
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall delete rule name = " & Chr(34) & $sName & Chr(34) & " protocol = TCP localport = " & $sPort & " dir = out", "", @SW_HIDE)
EndIf
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall add rule name = " & Chr(34) & $sName & Chr(34) & " dir = out action = allow protocol = TCP localport = " & $sPort, "", @SW_HIDE)
EndSwitch
EndFunc
Func _FirewallCloseTCP($sName, $sPort, $sRule, $sDelete)
Switch $sRule
Case "inbound"
If $sDelete == 1 Then
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall delete rule name = " & Chr(34) & $sName & Chr(34) & " protocol = TCP localport = " & $sPort & " dir = in", "", @SW_HIDE)
EndIf
;RunWait(@ComSpec & " /c " & "netsh advfirewall firewall add rule name = " & Chr(34) & $sName & Chr(34) & " dir = in action = allow protocol = TCP localport = " & $sPort, "", @SW_HIDE)
Case "outbound"
If $sDelete == 1 Then
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall delete rule name = " & Chr(34) & $sName & Chr(34) & " protocol = TCP localport = " & $sPort & " dir = out", "", @SW_HIDE)
EndIf
;RunWait(@ComSpec & " /c " & "netsh advfirewall firewall add rule name = " & Chr(34) & $sName & Chr(34) & " dir = out action = allow protocol = TCP localport = " & $sPort, "", @SW_HIDE)
EndSwitch
EndFunc
Func _FirewallOpenUDP($sName, $sPort, $sRule, $sDelete)
Switch $sRule
Case "inbound"
If $sDelete == 1 Then
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall delete rule name = " & Chr(34) & $sName & Chr(34) & " protocol = UDP localport = " & $sPort & " dir = in", "", @SW_HIDE)
EndIf
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall add rule name = " & Chr(34) & $sName & Chr(34) & " dir = in action = allow protocol = UDP localport = " & $sPort, "", @SW_HIDE)
Case "outbound"
If $sDelete == 1 Then
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall delete rule name = " & Chr(34) & $sName & Chr(34) & " protocol = UDP localport = " & $sPort & " dir = out", "", @SW_HIDE)
EndIf
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall add rule name = " & Chr(34) & $sName & Chr(34) & " dir = out action = allow protocol = UDP localport = " & $sPort, "", @SW_HIDE)
EndSwitch
EndFunc
Func _FirewallCloseUDP($sName, $sPort, $sRule, $sDelete)
Switch $sRule
Case "inbound"
If $sDelete == 1 Then
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall delete rule name = " & Chr(34) & $sName & Chr(34) & " protocol = UDP localport = " & $sPort & " dir = in", "", @SW_HIDE)
EndIf
;RunWait(@ComSpec & " /c " & "netsh advfirewall firewall add rule name = " & Chr(34) & $sName & Chr(34) & " dir = in action = allow protocol = UDP localport = " & $sPort, "", @SW_HIDE)
Case "outbound"
If $sDelete == 1 Then
RunWait(@ComSpec & " /c " & "netsh advfirewall firewall delete rule name = " & Chr(34) & $sName & Chr(34) & " protocol = UDP localport = " & $sPort & " dir = out", "", @SW_HIDE)
EndIf
;RunWait(@ComSpec & " /c " & "netsh advfirewall firewall add rule name = " & Chr(34) & $sName & Chr(34) & " dir = out action = allow protocol = UDP localport = " & $sPort, "", @SW_HIDE)
EndSwitch
EndFunc
Func _Bin2Dec($sBin)
Return BitOr((StringLen($sBin) > 1 ? BitShift(_Bin2Dec(StringTrimRight($sBin, 1)), -1) : 0), StringRight($sBin, 1))
EndFunc ; https://www.autoitscript.com/forum/topic/163035-dec2bin-bin2dec/
Func _Dec2Bin($sBin)
Return (BitShift($sBin, 1) ? _Dec2Bin(BitShift($sBin, 1)) : "") & BitAnd($sBin, 1)
EndFunc ; https://www.autoitscript.com/forum/topic/163035-dec2bin-bin2dec/