forked from Kron4ek/minecraft-vortex-launcher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vlauncher_linux.pb
954 lines (738 loc) · 39.4 KB
/
vlauncher_linux.pb
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
EnableExplicit
Define.s workingDirectory = GetPathPart(ProgramFilename())
Global.s tempDirectory = GetTemporaryDirectory()
Global.i downloadOkButton
Global.i downloadThreadsAmount
Global.i asyncDownload
Global.i versionsGadget, playButton
Global.i progressBar, filesLeft, progressWindow, downloadingClientTextGadget
Global.i versionsDownloadGadget, downloadVersionButton
Global.i forceDownloadMissingLibraries
Global.s versionsManifestString
Define *FileBuffer
Define.i javaProgram
Define.i Event, font, ramGadget, nameGadget, javaPathGadget, argsGadget, downloadButton, settingsButton, launcherVersionGadget, launcherAuthorGadget
Define.i saveLaunchString, versionsTypeGadget, saveLaunchStringGadget, launchStringFile, inheritsJsonObject, jsonInheritsArgumentsModernMember
Define.i argsTextGadget, javaBinaryPathTextGadget, downloadThreadsTextGadget, downloadAllFilesGadget
Define.i gadgetsWidth, gadgetsHeight, gadgetsIndent, windowWidth, windowHeight
Define.i listOfFiles, jsonFile, jsonObject, jsonObjectObjects, fileSize, jsonJarMember, jsonArgumentsArray, jsonArrayElement, inheritsJson, clientSize
Define.i versionSecondDigit
Define.s playerName, ramAmount, clientVersion, javaBinaryPath, fullLaunchString, assetsIndex, clientUrl, fileHash, versionToDownload
Define.s assetsIndex, clientMainClass, clientArguments, inheritsClientJar, customLaunchArguments, clientJarFile, nativesPath, librariesString
Define.s uuid
Define.i downloadThread, downloadMissingLibraries, jsonArgumentsMember, jsonArgumentsModernMember, jsonInheritsFromMember
Define.i downloadMissingLibrariesGadget, downloadThreadsGadget, asyncDownloadGadget, saveSettingsButton, useCustomJavaGadget, useCustomParamsGadget, keepLauncherOpenGadget
Define.i i
Define.s playerNameDefault = "Name", ramAmountDefault = "700", javaBinaryPathDefault = "/usr/bin/java"
Define.s customLaunchArgumentsDefault = "-Xss1M -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=16M"
Define.s customOldLaunchArgumentsDefault = "-XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -Xmn128M"
Define.i downloadThreadsAmountDefault = 10
Define.i asyncDownloadDefault = 0
Define.i downloadMissingLibrariesDefault = 0
Define.i downloadAllFilesDefault = 0
Define.i versionsTypeDefault = 0
Define.i saveLaunchStringDefault = 0
Define.i useCustomJavaDefault = 0
Define.i useCustomParamsDefault = 0
Define.i keepLauncherOpenDefault = 0
Define.s launcherVersion = "1.1.9"
Define.s launcherDeveloper = "Kron(4ek)"
Declare assetsToResources(assetsIndex.s)
Declare progressWindow(clientVersion.s)
Declare findInstalledVersions()
Declare downloadFiles(downloadAllFiles.i)
Declare CreateDirectoryRecursive(path.s)
Declare generateProfileJson()
Declare.s parseVersionsManifest(versionType.i = 0, getClientJarUrl.i = 0, clientVersion.s = "")
Declare.s parseLibraries(clientVersion.s, prepareForDownload.i = 0)
Declare.s fileRead(pathToFile.s)
Declare.s removeSpacesFromVersionName(clientVersion.s)
SetCurrentDirectory(workingDirectory)
OpenPreferences("vortex_launcher.conf")
downloadThreadsAmount = ReadPreferenceInteger("DownloadThreads", downloadThreadsAmountDefault)
asyncDownload = ReadPreferenceInteger("AsyncDownload", asyncDownloadDefault)
DeleteFile(tempDirectory + "vlauncher_download_list.txt")
windowWidth = 250
windowHeight = 250
If OpenWindow(0, #PB_Ignore, #PB_Ignore, windowWidth, windowHeight, "Vortex Minecraft Launcher")
gadgetsWidth = windowWidth - 10
gadgetsHeight = 30
gadgetsIndent = 5
nameGadget = StringGadget(#PB_Any, gadgetsIndent, 5, gadgetsWidth, gadgetsHeight, ReadPreferenceString("Name", playerNameDefault))
SetGadgetAttribute(nameGadget, #PB_String_MaximumLength, 16)
ramGadget = StringGadget(#PB_Any, gadgetsIndent, 40, gadgetsWidth, gadgetsHeight, ReadPreferenceString("Ram", ramAmountDefault), #PB_String_Numeric)
GadgetToolTip(ramGadget, "Amount (megabytes) of memory to allocate for Minecraft")
SetGadgetAttribute(ramGadget, #PB_String_MaximumLength, 6)
versionsGadget = ComboBoxGadget(#PB_Any, gadgetsIndent, 75, gadgetsWidth, gadgetsHeight)
playButton = ButtonGadget(#PB_Any, gadgetsIndent, 120, gadgetsWidth, gadgetsHeight, "Play")
downloadButton = ButtonGadget(#PB_Any, gadgetsIndent, 160, gadgetsWidth, gadgetsHeight, "Downloader")
settingsButton = ButtonGadget(#PB_Any, gadgetsIndent, 200, gadgetsWidth, gadgetsHeight, "Settings")
If LoadFont(0, "Ariral", 10, #PB_Font_Bold)
SetGadgetFont(playButton, FontID(0))
SetGadgetFont(downloadButton, FontID(0))
EndIf
launcherAuthorGadget = TextGadget(#PB_Any, 2, windowHeight - 10, 70, 20, "by " + launcherDeveloper)
launcherVersionGadget = TextGadget(#PB_Any, windowWidth - 35, windowHeight - 10, 50, 20, "v" + launcherVersion)
If LoadFont(1, "Ariral", 7)
font = FontID(1) : SetGadgetFont(launcherAuthorGadget, font) : SetGadgetFont(launcherVersionGadget, font)
EndIf
findInstalledVersions()
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case playButton
ramAmount = GetGadgetText(ramGadget)
clientVersion = GetGadgetText(versionsGadget)
playerName = GetGadgetText(nameGadget)
javaBinaryPath = "java"
downloadMissingLibraries = ReadPreferenceInteger("DownloadMissingLibs", downloadMissingLibrariesDefault)
versionSecondDigit = Val(StringField(clientVersion, 2, "."))
If versionSecondDigit < 13
customLaunchArguments = customOldLaunchArgumentsDefault
Else
customLaunchArguments = customLaunchArgumentsDefault
EndIf
If FindString(clientVersion, " ")
clientVersion = removeSpacesFromVersionName(clientVersion)
EndIf
If forceDownloadMissingLibraries
downloadMissingLibraries = 1
EndIf
If FindString(playerName, " ")
playerName = ReplaceString(playerName, " ", "")
EndIf
If ReadPreferenceInteger("UseCustomJava", useCustomJavaDefault)
javaBinaryPath = ReadPreferenceString("JavaPath", javaBinaryPathDefault)
EndIf
If ReadPreferenceInteger("UseCustomParameters", useCustomParamsDefault)
customLaunchArguments = ReadPreferenceString("LaunchArguments", customLaunchArgumentsDefault)
EndIf
If ramAmount And Len(playerName) >= 3
If Val(ramAmount) < 350
ramAmount = "350"
MessageRequester("Warning", "You allocated too low amount of memory!" + #CRLF$ + #CRLF$ + "Allocated memory set to 350 MB to prevent crashes.")
EndIf
WritePreferenceString("Name", playerName)
WritePreferenceString("Ram", ramAmount)
WritePreferenceString("ChosenVer", clientVersion)
If RunProgram(javaBinaryPath, "-version", workingDirectory)
jsonFile = ParseJSON(#PB_Any, fileRead("versions/" + clientVersion + "/" + clientVersion + ".json"))
If jsonFile
jsonObject = JSONValue(jsonFile)
jsonJarMember = GetJSONMember(jsonObject, "jar")
jsonInheritsFromMember = GetJSONMember(jsonObject, "inheritsFrom")
If jsonJarMember
clientJarFile = GetJSONString(jsonJarMember)
clientJarFile = "versions/" + clientJarFile + "/" + clientJarFile + ".jar"
ElseIf jsonInheritsFromMember
inheritsClientJar = GetJSONString(jsonInheritsFromMember)
clientJarFile = "versions/" + inheritsClientJar + "/" + inheritsClientJar + ".jar"
ElseIf FileSize("versions/" + clientVersion + "/" + clientVersion + ".jar") > 0
clientJarFile = "versions/" + clientVersion + "/" + clientVersion + ".jar"
EndIf
nativesPath = "versions/" + StringField(clientJarFile, 2, "/") + "/natives"
If jsonInheritsFromMember
inheritsClientJar = GetJSONString(jsonInheritsFromMember)
inheritsJson = ParseJSON(#PB_Any, fileRead("versions/" + inheritsClientJar + "/" + inheritsClientJar + ".json"))
If inheritsJson
inheritsJsonObject = JSONValue(inheritsJson)
jsonInheritsArgumentsModernMember = GetJSONMember(inheritsJsonObject, "arguments")
librariesString + parseLibraries(inheritsClientJar, downloadMissingLibraries)
assetsIndex = GetJSONString(GetJSONMember(JSONValue(inheritsJson), "assets"))
Else
MessageRequester("Error", inheritsClientJar + ".json file is missing!") : Break
EndIf
Else
If GetJSONMember(jsonObject, "assets")
assetsIndex = GetJSONString(GetJSONMember(jsonObject, "assets"))
ElseIf versionSecondDigit < 6
assetsIndex = "pre-1.6"
Else
assetsIndex = "legacy"
EndIf
EndIf
If FileSize(clientJarFile) > 0
librariesString = parseLibraries(clientVersion, downloadMissingLibraries) + librariesString
clientMainClass = GetJSONString(GetJSONMember(jsonObject, "mainClass"))
jsonArgumentsMember = GetJSONMember(jsonObject, "minecraftArguments")
jsonArgumentsModernMember = GetJSONMember(jsonObject, "arguments")
If jsonArgumentsMember
clientArguments = GetJSONString(jsonArgumentsMember)
ElseIf jsonArgumentsModernMember
jsonArgumentsArray = GetJSONMember(jsonArgumentsModernMember, "game")
For i = 0 To JSONArraySize(jsonArgumentsArray) - 1
jsonArrayElement = GetJSONElement(jsonArgumentsArray, i)
If JSONType(jsonArrayElement) = #PB_JSON_String
clientArguments + " " + GetJSONString(jsonArrayElement) + " "
EndIf
Next
EndIf
If jsonInheritsArgumentsModernMember
jsonArgumentsArray = GetJSONMember(jsonInheritsArgumentsModernMember, "game")
For i = 0 To JSONArraySize(jsonArgumentsArray) - 1
jsonArrayElement = GetJSONElement(jsonArgumentsArray, i)
If JSONType(jsonArrayElement) = #PB_JSON_String
clientArguments + " " + GetJSONString(jsonArrayElement) + " "
EndIf
Next
EndIf
UseMD5Fingerprint()
uuid = StringFingerprint("OfflinePlayer:" + playerName, #PB_Cipher_MD5)
uuid = Left(uuid, 12) + LCase(Hex(Val("$" + Mid(uuid, 13, 2)) & $0f | $30)) + Mid(uuid, 15, 2) + LCase(Hex(Val("$" + Mid(uuid, 17, 2)) & $3f | $80)) + Right(uuid, 14)
clientArguments = ReplaceString(clientArguments, "${auth_player_name}", playerName)
clientArguments = ReplaceString(clientArguments, "${version_name}", clientVersion)
clientArguments = ReplaceString(clientArguments, "${game_directory}", workingDirectory)
clientArguments = ReplaceString(clientArguments, "${assets_root}", "assets")
clientArguments = ReplaceString(clientArguments, "${auth_uuid}", uuid)
clientArguments = ReplaceString(clientArguments, "${auth_access_token}", "00000000000000000000000000000000")
clientArguments = ReplaceString(clientArguments, "${user_properties}", "{}")
clientArguments = ReplaceString(clientArguments, "${user_type}", "mojang")
clientArguments = ReplaceString(clientArguments, "${version_type}", "client")
clientArguments = ReplaceString(clientArguments, "${assets_index_name}", assetsIndex)
clientArguments = ReplaceString(clientArguments, "${auth_session}", "00000000000000000000000000000000")
clientArguments = ReplaceString(clientArguments, "${game_assets}", "resources")
clientArguments = ReplaceString(clientArguments, " ", " ")
If assetsIndex = "pre-1.6" Or assetsIndex = "legacy"
assetsToResources(assetsIndex)
EndIf
If downloadMissingLibraries
downloadFiles(0)
EndIf
fullLaunchString = "-Xmx" + ramAmount + "M " + customLaunchArguments + " " + Chr(34) + "-Djava.library.path=" + nativesPath + Chr(34) + " -cp " + Chr(34) + librariesString + clientJarFile + Chr(34) + " " + clientMainClass + " " + clientArguments
RunProgram(javaBinaryPath, fullLaunchString, workingDirectory)
saveLaunchString = ReadPreferenceInteger("SaveLaunchString", saveLaunchStringDefault)
If saveLaunchString
DeleteFile("launch_string.txt")
launchStringFile = OpenFile(#PB_Any, "launch_string.txt")
WriteString(launchStringFile, Chr(34) + javaBinaryPath + Chr(34) + " " + fullLaunchString)
CloseFile(launchStringFile)
EndIf
If Not ReadPreferenceInteger("KeepLauncherOpen", keepLauncherOpenDefault)
Break
EndIf
Else
MessageRequester("Error", "Client jar file is missing!")
EndIf
FreeJSON(inheritsJson)
FreeJSON(jsonFile)
Else
MessageRequester("Error", "Client json file is missing!")
EndIf
Else
MessageRequester("Error", "Java not found! Check if Java installed." + #CRLF$ + #CRLF$ + "Or check if path to Java binary is correct.")
EndIf
Else
If playerName = ""
MessageRequester("Error", "Enter your desired name.")
ElseIf ramAmount = ""
MessageRequester("Error", "Enter RAM amount.")
ElseIf Len(playerName) < 3
MessageRequester("Error", "Name is too short! Minimum length is 3.")
EndIf
EndIf
Case downloadButton
InitNetwork()
*FileBuffer = ReceiveHTTPMemory("https://launchermeta.mojang.com/mc/game/version_manifest.json")
If *FileBuffer
If OpenWindow(1, #PB_Ignore, #PB_Ignore, 250, 140, "Client Downloader")
DisableGadget(downloadButton, 1)
ComboBoxGadget(325, 5, 5, 240, 30)
versionsDownloadGadget = 325
CheckBoxGadget(110, 5, 45, 240, 20, "Show all versions")
versionsTypeGadget = 110
SetGadgetState(versionsTypeGadget, ReadPreferenceInteger("ShowAllVersions", versionsTypeDefault))
CheckBoxGadget(817, 5, 70, 240, 20, "Redownload all files")
downloadAllFilesGadget = 817
SetGadgetState(downloadAllFilesGadget, ReadPreferenceInteger("RedownloadFiles", downloadAllFilesDefault))
downloadVersionButton = ButtonGadget(#PB_Any, 5, 100, 240, 30, "Download")
If IsThread(downloadThread) : DisableGadget(downloadVersionButton, 1) : EndIf
versionsManifestString = PeekS(*FileBuffer, MemorySize(*FileBuffer), #PB_UTF8)
FreeMemory(*FileBuffer)
parseVersionsManifest(GetGadgetState(versionsTypeGadget))
EndIf
Else
MessageRequester("Download Error", "Seems like you have no internet connection")
EndIf
Case versionsTypeGadget
ClearGadgetItems(versionsDownloadGadget)
parseVersionsManifest(GetGadgetState(versionsTypeGadget))
Case downloadVersionButton
versionToDownload = GetGadgetText(versionsDownloadGadget)
CreateDirectoryRecursive("versions/" + versionToDownload)
If ReceiveHTTPFile(parseVersionsManifest(GetGadgetState(versionsDownloadGadget), 1, versionToDownload), "versions/" + versionToDownload + "/" + versionToDownload + ".json")
DeleteFile(tempDirectory + "vlauncher_download_list.txt")
listOfFiles = OpenFile(#PB_Any, tempDirectory + "vlauncher_download_list.txt")
jsonFile = ParseJSON(#PB_Any, fileRead("versions/" + versionToDownload + "/" + versionToDownload + ".json"))
If jsonFile
jsonObject = JSONValue(jsonFile)
assetsIndex = GetJSONString(GetJSONMember(jsonObject, "assets"))
CreateDirectoryRecursive("assets/indexes")
ReceiveHTTPFile(GetJSONString(GetJSONMember(GetJSONMember(jsonObject, "assetIndex"), "url")), "assets/indexes/" + assetsIndex + ".json")
clientUrl = GetJSONString(GetJSONMember(GetJSONMember(GetJSONMember(jsonObject, "downloads"), "client"), "url"))
clientSize = GetJSONInteger(GetJSONMember(GetJSONMember(GetJSONMember(jsonObject, "downloads"), "client"), "size"))
WriteStringN(listOfFiles, clientUrl + "::" + "versions/" + versionToDownload + "/" + versionToDownload + ".jar" + "::" + clientSize)
FreeJSON(jsonFile)
EndIf
jsonFile = ParseJSON(#PB_Any, fileRead("assets/indexes/" + assetsIndex + ".json"))
If jsonFile
jsonObject = JSONValue(jsonFile)
jsonObjectObjects = GetJSONMember(jsonObject, "objects")
If ExamineJSONMembers(jsonObjectObjects)
While NextJSONMember(jsonObjectObjects)
fileHash = GetJSONString(GetJSONMember(GetJSONMember(jsonObjectObjects, JSONMemberKey(jsonObjectObjects)), "hash"))
fileSize = GetJSONInteger(GetJSONMember(GetJSONMember(jsonObjectObjects, JSONMemberKey(jsonObjectObjects)), "size"))
WriteStringN(listOfFiles, "http://resources.download.minecraft.net/" + Left(fileHash, 2) + "/" + fileHash + "::" + "assets/objects/" + Left(fileHash, 2) + "/" + fileHash + "::" + fileSize)
Wend
EndIf
FreeJSON(jsonFile)
EndIf
CloseFile(listOfFiles)
parseLibraries(versionToDownload, 1)
DisableGadget(playButton, 1)
progressWindow(versionToDownload)
downloadThread = CreateThread(@downloadFiles(), GetGadgetState(downloadAllFilesGadget))
Else
MessageRequester("Download Error", "Seems like you have no internet connection!")
EndIf
Case settingsButton
DisableGadget(settingsButton, 1)
If OpenWindow(3, #PB_Ignore, #PB_Ignore, 350, 315, "Vortex Launcher Settings")
argsTextGadget = TextGadget(#PB_Any, 5, 5, 80, 30, "Launch parameters:")
argsGadget = StringGadget(#PB_Any, 85, 5, 260, 30, ReadPreferenceString("LaunchArguments", customLaunchArgumentsDefault))
GadgetToolTip(argsGadget, "These parameters will be used to launch Minecraft")
javaBinaryPathTextGadget = TextGadget(#PB_Any, 5, 45, 80, 30, "Path to Java:")
javaPathGadget = StringGadget(#PB_Any, 85, 45, 260, 30, ReadPreferenceString("JavaPath", javaBinaryPathDefault))
GadgetToolTip(javaPathGadget, "Absolute path to Java binary")
downloadThreadsTextGadget = TextGadget(#PB_Any, 5, 85, 80, 30, "Download threads:")
downloadThreadsGadget = StringGadget(#PB_Any, 85, 85, 260, 30, ReadPreferenceString("DownloadThreads", Str(downloadThreadsAmountDefault)), #PB_String_Numeric)
GadgetToolTip(downloadThreadsGadget, "Higher numbers may speedup downloads (works only with multi-threads downloads)")
SetGadgetAttribute(downloadThreadsGadget, #PB_String_MaximumLength, 3)
CheckBoxGadget(311, 5, 125, 340, 20, "Fast multi-thread downloads (experimental)")
asyncDownloadGadget = 311
SetGadgetState(asyncDownloadGadget, ReadPreferenceInteger("AsyncDownload", asyncDownloadDefault))
downloadMissingLibrariesGadget = CheckBoxGadget(#PB_Any, 5, 150, 340, 20, "Download missing libraries on game start")
SetGadgetState(downloadMissingLibrariesGadget, ReadPreferenceInteger("DownloadMissingLibs", downloadMissingLibrariesDefault))
saveLaunchStringGadget = CheckBoxGadget(#PB_Any, 5, 175, 340, 20, "Save launch string to file")
GadgetToolTip(saveLaunchStringGadget, "Full launch string will be saved to launch_string.txt file")
SetGadgetState(saveLaunchStringGadget, ReadPreferenceInteger("SaveLaunchString", saveLaunchStringDefault))
CheckBoxGadget(312, 5, 200, 340, 20, "Use custom Java")
useCustomJavaGadget = 312
GadgetToolTip(useCustomJavaGadget, "Use custom Java instead of installed one")
SetGadgetState(useCustomJavaGadget, ReadPreferenceInteger("UseCustomJava", useCustomJavaDefault))
CheckBoxGadget(313, 5, 225, 340, 20, "Use custom launch parameters")
useCustomParamsGadget = 313
GadgetToolTip(useCustomParamsGadget, "Use custom parameters to launch Minecraft")
SetGadgetState(useCustomParamsGadget, ReadPreferenceInteger("UseCustomParameters", useCustomParamsDefault))
CheckBoxGadget(689, 5, 250, 340, 20, "Keep the launcher open")
keepLauncherOpenGadget = 689
GadgetToolTip(keepLauncherOpenGadget, "Keep the launcher open after launching the game")
SetGadgetState(keepLauncherOpenGadget, ReadPreferenceInteger("KeepLauncherOpen", keepLauncherOpenDefault))
saveSettingsButton = ButtonGadget(#PB_Any, 5, 275, 340, 20, "Save and apply")
DisableGadget(downloadThreadsGadget, Bool(Not GetGadgetState(asyncDownloadGadget)))
DisableGadget(javaPathGadget, Bool(Not GetGadgetState(useCustomJavaGadget)))
DisableGadget(argsGadget, Bool(Not GetGadgetState(useCustomParamsGadget)))
EndIf
Case useCustomParamsGadget
DisableGadget(argsGadget, Bool(Not GetGadgetState(useCustomParamsGadget)))
Case asyncDownloadGadget
If GetGadgetState(asyncDownloadGadget)
MessageRequester("Warning", "This option is experimental and may cause crashes." + #CRLF$ + #CRLF$ + "You have been warned!")
EndIf
DisableGadget(downloadThreadsGadget, Bool(Not GetGadgetState(asyncDownloadGadget)))
Case useCustomJavaGadget
DisableGadget(javaPathGadget, Bool(Not GetGadgetState(useCustomJavaGadget)))
Case saveSettingsButton
If GetGadgetText(downloadThreadsGadget) = "0" : SetGadgetText(downloadThreadsGadget, "5") : EndIf
WritePreferenceInteger("DownloadMissingLibs", GetGadgetState(downloadMissingLibrariesGadget))
WritePreferenceInteger("AsyncDownload", GetGadgetState(asyncDownloadGadget))
WritePreferenceInteger("SaveLaunchString", GetGadgetState(saveLaunchStringGadget))
WritePreferenceInteger("UseCustomJava", GetGadgetState(useCustomJavaGadget))
WritePreferenceInteger("UseCustomParameters", GetGadgetState(useCustomParamsGadget))
WritePreferenceInteger("KeepLauncherOpen", GetGadgetState(keepLauncherOpenGadget))
If GetGadgetState(useCustomJavaGadget)
WritePreferenceString("JavaPath", GetGadgetText(javaPathGadget))
EndIf
If GetGadgetState(asyncDownloadGadget)
WritePreferenceString("DownloadThreads", GetGadgetText(downloadThreadsGadget))
EndIf
If GetGadgetState(useCustomParamsGadget)
WritePreferenceString("LaunchArguments", GetGadgetText(argsGadget))
EndIf
downloadThreadsAmount = Val(GetGadgetText(downloadThreadsGadget))
asyncDownload = GetGadgetState(asyncDownloadGadget)
Case downloadOkButton
CloseWindow(progressWindow)
If IsGadget(playButton) : DisableGadget(playButton, 0) : EndIf
If IsGadget(downloadVersionButton) : DisableGadget(downloadVersionButton, 0) : EndIf
EndSelect
EndIf
If Event = #PB_Event_CloseWindow
If EventWindow() = 1
WritePreferenceInteger("ShowAllVersions", GetGadgetState(versionsTypeGadget))
WritePreferenceInteger("RedownloadFiles", GetGadgetState(downloadAllFilesGadget))
CloseWindow(1)
DisableGadget(downloadButton, 0)
ElseIf EventWindow() = progressWindow
If Not IsThread(downloadThread)
CloseWindow(progressWindow)
If IsGadget(playButton) : DisableGadget(playButton, 0) : EndIf
If IsGadget(downloadVersionButton) : DisableGadget(downloadVersionButton, 0) : EndIf
Else
MessageRequester("Download in progress", "Wait for download to complete!")
EndIf
ElseIf EventWindow() = 3
CloseWindow(3)
DisableGadget(settingsButton, 0)
EndIf
EndIf
Until Event = #PB_Event_CloseWindow And EventWindow() = 0
DeleteFile(tempDirectory + "vlauncher_download_list.txt")
EndIf
Procedure findInstalledVersions()
Protected.s dirName, chosenVer = ReadPreferenceString("ChosenVer", "")
Protected.i directory, chosenFound
directory = ExamineDirectory(#PB_Any, "versions", "*")
DisableGadget(playButton, 0)
DisableGadget(versionsGadget, 0)
If directory
While NextDirectoryEntry(directory)
If DirectoryEntryType(directory) = #PB_DirectoryEntry_Directory
dirName = DirectoryEntryName(directory)
If dirName <> ".." And dirName <> "."
If FileSize("versions/" + dirName + "/" + dirName + ".json") > -1
If Not chosenFound And dirName = chosenVer
chosenFound = 1
EndIf
AddGadgetItem(versionsGadget, -1, dirName)
EndIf
EndIf
EndIf
Wend
FinishDirectory(directory)
If chosenFound
SetGadgetText(versionsGadget, chosenVer)
Else
SetGadgetState(versionsGadget, 0)
EndIf
EndIf
If Not CountGadgetItems(versionsGadget)
DisableGadget(playButton, 1)
DisableGadget(versionsGadget, 1) : AddGadgetItem(versionsGadget, 0, "Versions not found") : SetGadgetState(versionsGadget, 0)
Else
generateProfileJson()
EndIf
EndProcedure
Procedure.s parseVersionsManifest(versionType.i = 0, getClientJarUrl.i = 0, clientVersion.s = "")
Protected.i jsonFile, jsonObject, jsonVersionsArray, jsonArrayElement, i
Protected.s url
jsonFile = ParseJSON(#PB_Any, versionsManifestString)
If jsonFile
jsonObject = JSONValue(jsonFile)
jsonVersionsArray = GetJSONMember(jsonObject, "versions")
For i = 0 To JSONArraySize(jsonVersionsArray) - 1
jsonArrayElement = GetJSONElement(jsonVersionsArray, i)
If getClientJarUrl = 0 And versionType = 0 And GetJSONString(GetJSONMember(jsonArrayElement, "type")) <> "release"
Continue
EndIf
If getClientJarUrl = 0
AddGadgetItem(versionsDownloadGadget, -1, GetJSONString(GetJSONMember(jsonArrayElement, "id")))
Else
If GetJSONString(GetJSONMember(jsonArrayElement, "id")) = clientVersion
url = GetJSONString(GetJSONMember(jsonArrayElement, "url"))
FreeJSON(jsonFile)
ProcedureReturn url
EndIf
EndIf
Next
FreeJSON(jsonFile)
Else
AddGadgetItem(versionsDownloadGadget, -1, "Error")
DisableGadget(downloadVersionButton, 1)
EndIf
SetGadgetState(versionsDownloadGadget, 0)
EndProcedure
Procedure.s parseLibraries(clientVersion.s, prepareForDownload.i = 0)
Protected.i jsonLibrariesArray, jsonArrayElement, jsonFile, fileSize, downloadListFile, zipFile
Protected.i jsonArtifactsMember, jsonDownloadsMember, jsonUrlMember, jsonClassifiersMember, jsonNativesLinuxMember
Protected.i jsonRulesMember, jsonRulesOsMember
Protected.i i, k
Protected.i allowLib
Protected.s libName, libsString, packFileName, url
Protected.s jsonRulesOsName
Protected Dim libSplit.s(3)
If prepareForDownload = 1
downloadListFile = OpenFile(#PB_Any, tempDirectory + "vlauncher_download_list.txt")
FileSeek(downloadListFile, Lof(downloadListFile), #PB_Relative)
EndIf
UseZipPacker()
jsonFile = ParseJSON(#PB_Any, fileRead("versions/" + clientVersion + "/" + clientVersion + ".json"))
If jsonFile
jsonLibrariesArray = GetJSONMember(JSONValue(jsonFile), "libraries")
For i = 0 To JSONArraySize(jsonLibrariesArray) - 1
jsonArrayElement = GetJSONElement(jsonLibrariesArray, i)
allowLib = 1
jsonRulesOsName = "empty"
jsonRulesMember = GetJSONMember(jsonArrayElement, "rules")
If jsonRulesMember
For k = 0 To JSONArraySize(jsonRulesMember) - 1
jsonRulesOsMember = GetJSONMember(GetJSONElement(jsonRulesMember, k), "os")
If jsonRulesOsMember
jsonRulesOsName = GetJSONString(GetJSONMember(jsonRulesOsMember, "name"))
EndIf
If GetJSONString(GetJSONMember(GetJSONElement(jsonRulesMember, k), "action")) = "allow"
If jsonRulesOsName <> "empty" And jsonRulesOsName <> "linux"
allowLib = 0
EndIf
Else
If jsonRulesOsName = "linux"
allowLib = 0
EndIf
EndIf
Next
EndIf
If allowLib
libName = GetJSONString(GetJSONMember(jsonArrayElement, "name"))
For k = 1 To 3
libSplit(k) = StringField(libName, k, ":")
Next
libName = ReplaceString(libSplit(1), ".", "/") + "/" + libSplit(2) + "/" + libSplit(3) + "/" + libSplit(2) + "-" + libSplit(3)
If prepareForDownload = 1
jsonDownloadsMember = GetJSONMember(jsonArrayElement, "downloads")
If jsonDownloadsMember
jsonArtifactsMember = GetJSONMember(jsonDownloadsMember, "artifact")
jsonClassifiersMember = GetJSONMember(jsonDownloadsMember, "classifiers")
If jsonClassifiersMember
jsonNativesLinuxMember = GetJSONMember(jsonClassifiersMember, "natives-linux")
If jsonNativesLinuxMember
url = GetJSONString(GetJSONMember(jsonNativesLinuxMember, "url"))
fileSize = GetJSONInteger(GetJSONMember(jsonNativesLinuxMember, "size"))
libName + "-natives-linux"
EndIf
ElseIf jsonArtifactsMember
url = GetJSONString(GetJSONMember(jsonArtifactsMember, "url"))
fileSize = GetJSONInteger(GetJSONMember(jsonArtifactsMember, "size"))
EndIf
Else
jsonUrlMember = GetJSONMember(jsonArrayElement, "url")
If jsonUrlMember
url = GetJSONString(jsonUrlMember) + libName + ".jar"
Else
url = "https://libraries.minecraft.net/" + libName + ".jar"
EndIf
EndIf
WriteStringN(downloadListFile, url + "::" + "libraries/" + libName + ".jar" + "::" + fileSize)
EndIf
If Not GetJSONMember(jsonArrayElement, "natives")
libsString + "libraries/" + libName + ".jar:"
Else
If Not Right(libName, 13) = "natives-linux"
zipFile = OpenPack(#PB_Any, "libraries/" + libName + "-natives-linux.jar")
Else
zipFile = OpenPack(#PB_Any, "libraries/" + libName + ".jar")
EndIf
If zipFile
CreateDirectoryRecursive("versions/" + clientVersion + "/natives")
If ExaminePack(zipFile)
While NextPackEntry(zipFile)
If PackEntryType(zipFile) = #PB_Packer_File
packFileName = PackEntryName(zipFile)
If FileSize("versions/" + clientVersion + "/natives/" + packFileName) < 1
UncompressPackFile(zipFile, "versions/" + clientVersion + "/natives/" + packFileName)
EndIf
EndIf
Wend
EndIf
ClosePack(zipFile)
EndIf
EndIf
EndIf
Next
EndIf
FreeJSON(jsonFile)
FreeArray(libSplit())
If prepareForDownload = 1 : CloseFile(downloadListFile) : EndIf
ProcedureReturn libsString
EndProcedure
Procedure downloadFiles(downloadAllFiles.i)
Protected Dim httpArray.i(downloadThreadsAmount)
Protected Dim strings.s(downloadThreadsAmount)
Protected Dim retries.i(downloadThreadsAmount)
Protected.i failedDownloads, succeededDownloads, linesTotal, lines, allowedRetries = 5
Protected.s string
Protected.i file, fileSize, requiredSize, i
Protected.i currentDownloads
Protected.i retries
file = ReadFile(#PB_Any, tempDirectory + "vlauncher_download_list.txt")
If file
While Eof(file) = 0
ReadString(file)
lines + 1
Wend
linesTotal = lines
FileSeek(file, 0)
If IsGadget(downloadVersionButton) : DisableGadget(downloadVersionButton, 1) : EndIf
If IsGadget(progressBar) : SetGadgetAttribute(progressBar, #PB_ProgressBar_Maximum, linesTotal) : EndIf
InitNetwork()
If asyncDownload
While (Eof(file) = 0 Or currentDownloads > 0) And failedDownloads <= 5
For i = 0 To downloadThreadsAmount
If httpArray(i) = 0
string = ReadString(file)
If string
fileSize = FileSize(StringField(string, 2, "::"))
requiredSize = Val(StringField(string, 3, "::"))
If (downloadAllFiles = 0 And (fileSize = -1 Or (requiredSize <> 0 And fileSize <> requiredSize))) Or downloadAllFiles = 1
CreateDirectoryRecursive(GetPathPart(StringField(string, 2, "::")))
httpArray(i) = ReceiveHTTPFile(StringField(string, 1, "::"), StringField(string, 2, "::"), #PB_HTTP_Asynchronous)
strings(i) = string
retries(i) = 0
currentDownloads + 1
Else
lines - 1
EndIf
EndIf
ElseIf HTTPProgress(httpArray(i)) = #PB_Http_Success
currentDownloads - 1
lines - 1
FinishHTTP(httpArray(i))
httpArray(i) = 0
ElseIf HTTPProgress(httpArray(i)) = #PB_Http_Failed
FinishHTTP(httpArray(i))
If retries(i) < allowedRetries
httpArray(i) = ReceiveHTTPFile(StringField(strings(i), 1, "::"), StringField(strings(i), 2, "::"), #PB_HTTP_Asynchronous)
retries(i) + 1
Else
retries(i) = 0
httpArray(i) = 0
failedDownloads + 1
currentDownloads - 1
EndIf
EndIf
Next
If IsGadget(progressBar) : SetGadgetState(progressBar, linesTotal - lines) : EndIf
If IsGadget(filesLeft) : SetGadgetText(filesLeft, "Files remaining: " + lines): EndIf
Delay(500)
Wend
Else
While Eof(file) = 0
string = ReadString(file)
If string
lines - 1
fileSize = FileSize(StringField(string, 2, "::"))
requiredSize = Val(StringField(string, 3, "::"))
If (downloadAllFiles = 0 And (fileSize = -1 Or (requiredSize <> 0 And fileSize <> requiredSize))) Or downloadAllFiles = 1
CreateDirectoryRecursive(GetPathPart(StringField(string, 2, "::")))
If ReceiveHTTPFile(StringField(string, 1, "::"), StringField(string, 2, "::"))
retries = 0
Else
If retries < allowedRetries
retries + 1
FileSeek(file, -1, #PB_Relative)
Continue
Else
failedDownloads = 1
Break
EndIf
EndIf
EndIf
EndIf
If IsGadget(progressBar) : SetGadgetState(progressBar, linesTotal - lines) : EndIf
If IsGadget(filesLeft) : SetGadgetText(filesLeft, "Files remaining: " + lines) : EndIf
Wend
EndIf
If failedDownloads
If IsGadget(filesLeft) : SetGadgetText(filesLeft, "Download failed! " + lines + " files left.") : EndIf
Else
If IsGadget(filesLeft) : SetGadgetText(filesLeft, "Download complete!") : EndIf
EndIf
If IsGadget(progressBar) : HideGadget(progressBar, 1) : EndIf
If IsGadget(downloadOkButton) : HideGadget(downloadOkButton, 0) : EndIf
ClearGadgetItems(versionsGadget)
findInstalledVersions()
CloseFile(file)
EndIf
FreeArray(httpArray())
FreeArray(strings())
DeleteFile(tempDirectory + "vlauncher_download_list.txt")
EndProcedure
Procedure progressWindow(clientVersion.s)
progressWindow = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 230, 95, "Download progress")
If progressWindow
downloadingClientTextGadget = TextGadget(#PB_Any, 5, 5, 220, 30, "Version: " + clientVersion)
filesLeft = TextGadget(#PB_Any, 5, 30, 220, 30, "Files remaining: unknown")
progressBar = ProgressBarGadget(#PB_Any, 5, 60, 220, 20, 0, 100, #PB_ProgressBar_Smooth)
downloadOkButton = ButtonGadget(#PB_Any, 5, 55, 220, 30, "OK")
HideGadget(downloadOkButton, 1)
EndIf
EndProcedure
Procedure CreateDirectoryRecursive(path.s)
Protected.s fullPath, pathElement
Protected.i i = 1
Repeat
pathElement = StringField(path, i, "/")
fullPath + pathElement + "/"
CreateDirectory(fullPath)
i + 1
Until pathElement = ""
EndProcedure
Procedure generateProfileJson()
Protected.s fileName = "launcher_profiles.json"
Protected.i file
Protected.i lastProfilesJsonSize = ReadPreferenceInteger("LastProfilesJsonSize", 89)
Protected.i fileSize = FileSize(fileName)
If fileSize <= 0
DeleteFile(fileName)
file = OpenFile(#PB_Any, fileName)
If file
WriteString(file, "{ " + Chr(34) + "profiles" + Chr(34) + ": { " + Chr(34) + "justProfile" + Chr(34) + ": { " + Chr(34) + "name" + Chr(34) + ": " + Chr(34) + "justProfile" + Chr(34) + ", ")
WriteString(file, Chr(34) + "lastVersionId" + Chr(34) + ": " + Chr(34) + "1.12.2" + Chr(34) + " } } }" + #CRLF$)
CloseFile(file)
EndIf
EndIf
fileSize = FileSize(fileName)
If fileSize <> lastProfilesJsonSize
forceDownloadMissingLibraries = 1
EndIf
WritePreferenceInteger("LastProfilesJsonSize", fileSize)
EndProcedure
Procedure.s fileRead(pathToFile.s)
Protected.i file
Protected.s fileContent
file = ReadFile(#PB_Any, pathToFile)
If file
Repeat
fileContent + ReadString(file) + #CRLF$
Until Eof(file)
CloseFile(file)
EndIf
ProcedureReturn fileContent
EndProcedure
Procedure assetsToResources(assetsIndex.s)
Protected.i jsonFile, jsonObject, jsonObjectObjects, fileSize
Protected.s fileHash, fileName
jsonFile = ParseJSON(#PB_Any, fileRead("assets/indexes/" + assetsIndex + ".json"))
If jsonFile
jsonObject = JSONValue(jsonFile)
jsonObjectObjects = GetJSONMember(jsonObject, "objects")
If ExamineJSONMembers(jsonObjectObjects)
While NextJSONMember(jsonObjectObjects)
fileHash = GetJSONString(GetJSONMember(GetJSONMember(jsonObjectObjects, JSONMemberKey(jsonObjectObjects)), "hash"))
fileSize = GetJSONInteger(GetJSONMember(GetJSONMember(jsonObjectObjects, JSONMemberKey(jsonObjectObjects)), "size"))
fileName = JSONMemberKey(jsonObjectObjects)
If FileSize("resources/" + fileName) <> fileSize
CreateDirectoryRecursive("resources/" + GetPathPart(fileName))
CopyFile("assets/objects/" + Left(fileHash, 2) + "/" + fileHash, "resources/" + fileName)
EndIf
Wend
EndIf
FreeJSON(jsonFile)
EndIf
EndProcedure
Procedure.s removeSpacesFromVersionName(clientVersion.s)
Protected.s newVersionName = ReplaceString(clientVersion, " ", "-")
RenameFile("versions/" + clientVersion + "/" + clientVersion + ".jar", "versions/" + clientVersion + "/" + newVersionName + ".jar")
RenameFile("versions/" + clientVersion + "/" + clientVersion + ".json", "versions/" + clientVersion + "/" + newVersionName + ".json")
RenameFile("versions/" + clientVersion, "versions/" + newVersionName)
ProcedureReturn newVersionName
EndProcedure