nitro_plugin 0.30.0

Plugin loading and definition for Nitrolaunch
Documentation
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
use std::collections::{HashMap, HashSet};

use nitro_config::ConfigKind;
use nitro_config::instance::{InstanceConfig, WrapperCommand};
use nitro_config::template::TemplateConfig;
use nitro_instance::addon::Addon;
use nitro_pkg::repo::{PackageFlag, RepoMetadata};
use nitro_pkg::script_eval::AddonInstructionData;
use nitro_pkg::{PackageContentType, PackageSearchResults, RecommendedPackage, RequiredPackage};
use nitro_shared::UpdateDepth;
use nitro_shared::id::{InstanceID, TemplateID};
use nitro_shared::lang::translate::LanguageMap;
use nitro_shared::loaders::Loader;
use nitro_shared::minecraft::VersionEntry;
use nitro_shared::minecraft::{AddonKind, SkinVariant};
use nitro_shared::minecraft::{Cape, MinecraftUserProfile, Skin};
use nitro_shared::pkg::{PackageID, PackageQueryDepth, PackageSearchParameters};
use nitro_shared::versions::VersionPattern;
use nitro_shared::{Side, versions::VersionInfo};
use serde::{Deserialize, Serialize};

use crate::control::Control;

use super::Hook;

macro_rules! def_hook {
	($struct:ident, $name:literal, $desc:literal, $arg:ty, $res:ty, $version:literal, $asynchronous:literal, $($extra:tt)*) => {
		#[doc = $desc]
		pub struct $struct;

		impl Hook for $struct {
			type Arg = $arg;
			type Result = $res;

			fn get_name_static() -> &'static str {
				$name
			}

			fn get_version() -> u16 {
				$version
			}

			fn is_asynchronous() -> bool {
				$asynchronous
			}

			$(
				$extra
			)*
		}
	};

	($struct:ident, $name:literal, $desc:literal, $arg:ty, $res:ty, $version:literal, $($extra:tt)*) => {
		def_hook!($struct, $name, $desc, $arg, $res, $version, false, $($extra)*);
	};
}

def_hook!(
	OnLoad,
	"on_load",
	"Hook for when a plugin is loaded",
	(),
	(),
	1,
	true,
);

def_hook!(
	StartWorker,
	"start_worker",
	"Hook for starting a long-running worker alongside the plugin runner",
	(),
	(),
	1,
	true,
);

def_hook!(
	Subcommand,
	"subcommand",
	"Hook for when a command's subcommands are run",
	SubcommandArg,
	(),
	3,
	fn get_takes_over() -> bool {
		true
	}
);

/// Argument to the Subcommand hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct SubcommandArg {
	/// Arguments for the subcommand, with the first element being the subcommand itself
	pub args: Vec<String>,
	/// Supercommand for the subcommand
	pub supercommand: Option<String>,
	/// Finalized instance configs
	pub instances: HashMap<InstanceID, InstanceConfig>,
}

def_hook!(
	AddVersions,
	"add_versions",
	"Hook for adding extra versions to the version manifest",
	UpdateDepth,
	Vec<VersionEntry>,
	2,
	true,
);

def_hook!(
	OnInstanceSetup,
	"on_instance_setup",
	"Hook for doing work when setting up an instance for update or launch",
	OnInstanceSetupArg,
	OnInstanceSetupResult,
	5,
);

def_hook!(
	AfterInstanceSetup,
	"after_instance_setup",
	"Hook for doing instance setup work after the core instance has been created",
	OnInstanceSetupArg,
	OnInstanceSetupResult,
	1,
);

/// Argument for the OnInstanceSetup hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct OnInstanceSetupArg {
	/// The ID of the instance
	pub id: String,
	/// The side of the instance
	pub side: Option<Side>,
	/// Path to the instance's directory
	pub inst_dir: Option<String>,
	/// Version info for the instance
	pub version_info: VersionInfo,
	/// The current version of the instance before being updated to the one in version_info. Can be used to detect version changes.
	pub old_version: Option<String>,
	/// The loader of the instance
	pub loader: Loader,
	/// The current version of the loader, as stored in the lockfile. Can be used to detect version changes.
	pub current_loader_version: Option<String>,
	/// The desired version of the loader
	pub desired_loader_version: VersionPattern,
	/// Instance configuration
	pub config: InstanceConfig,
	/// Path to the Nitrolaunch internal dir
	pub internal_dir: String,
	/// The depth to update at
	pub update_depth: UpdateDepth,
	/// Path to the JVM
	pub jvm_path: String,
	/// Path to the vanilla game JAR
	pub game_jar_path: String,
	/// Classpath for the launched instance. May be slightly incomplete, and only available for AfterInstanceSetup
	pub classpath: Option<String>,
}

/// Result from the OnInstanceSetup hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct OnInstanceSetupResult {
	/// Optional override for the main class
	pub main_class_override: Option<String>,
	/// Optional override for the path to the game JAR file
	pub jar_path_override: Option<String>,
	/// Optional extension to the classpath, as a list of paths
	pub classpath_extension: Vec<String>,
	/// Optional new version for the loader
	pub loader_version: Option<String>,
	/// Optional additional JVM args
	pub jvm_args: Vec<String>,
	/// Optional additional game args
	pub game_args: Vec<String>,
	/// Additional wrapper commands
	pub wrappers: Vec<WrapperCommand>,
	/// Whether to skip adding the game JAR to the final classpath
	pub exclude_game_jar: bool,
}

def_hook!(
	RemoveLoader,
	"remove_loader",
	"Hook for removing a loader from an instance when the loader or version changes",
	OnInstanceSetupArg,
	(),
	1,
);

def_hook!(
	AfterPackagesInstalled,
	"after_packages_installed",
	"Hook for doing work on an instance after packages are installed on that instance",
	AfterPackagesInstalledArg,
	(),
	2,
);

/// Argument for the AfterPackagesInstalled hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct AfterPackagesInstalledArg {
	/// The ID of the instance
	pub id: String,
	/// The side of the instance
	pub side: Option<Side>,
	/// Path to the instance's directory
	pub inst_dir: Option<String>,
	/// Version info for the instance
	pub version_info: VersionInfo,
	/// The loader of the instance
	pub loader: Loader,
	/// Instance configuration
	pub config: InstanceConfig,
	/// Path to the Nitrolaunch internal dir
	pub internal_dir: String,
	/// The depth to update at
	pub update_depth: UpdateDepth,
}

def_hook!(
	OnInstanceLaunch,
	"on_instance_launch",
	"Hook for doing work before an instance is launched",
	InstanceLaunchArg,
	(),
	2,
);

def_hook!(
	WhileInstanceLaunch,
	"while_instance_launch",
	"Hook for running sibling processes with an instance when it is launched",
	InstanceLaunchArg,
	(),
	2,
	true,
);

def_hook!(
	OnInstanceStop,
	"on_instance_stop",
	"Hook for doing work when an instance is stopped gracefully",
	InstanceLaunchArg,
	(),
	2,
);

def_hook!(
	ReplaceInstanceLaunch,
	"replace_instance_launch",
	"Hook for replacing the launch behavior of an instance without a game dir",
	InstanceLaunchArg,
	Option<ReplaceInstanceLaunchResult>,
	2,
);

/// Result from the ReplaceInstanceLaunch hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct ReplaceInstanceLaunchResult {
	/// The PID of the newly spawned instance process
	pub pid: u32,
	/// An optional path for the stdout of the instance, if you aren't using the one that nitro provides you
	pub stdout_path: Option<String>,
}

def_hook!(
	UpdateWorldFiles,
	"update_world_files",
	"Hook for when shared world files are updated",
	InstanceLaunchArg,
	(),
	1,
);

/// Argument for the OnInstanceLaunch and WhileInstanceLaunch hooks
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct InstanceLaunchArg {
	/// The ID of the instance
	pub id: String,
	/// The side of the instance
	pub side: Option<Side>,
	/// Path to the instance's directory
	pub inst_dir: Option<String>,
	/// Version info for the instance
	pub version_info: VersionInfo,
	/// The instance's configuration
	pub config: InstanceConfig,
	/// The PID of the instance process
	pub pid: Option<u32>,
	/// The classpath used in the launch command. Will not be available in the on_instance_launch hook.
	pub classpath: Option<String>,
	/// The path to the file containing the instance stdout and stderr. Will not be available in the on_instance_launch hook.
	pub stdout_path: Option<String>,
	/// The path to the file containing the instance stdin. Will not be available in the on_instance_launch hook.
	pub stdin_path: Option<String>,
}

def_hook!(
	CustomPackageInstruction,
	"custom_package_instruction",
	"Hook for handling custom instructions in packages",
	CustomPackageInstructionArg,
	CustomPackageInstructionResult,
	1,
	true,
);

/// Argument for the CustomPackageInstruction hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct CustomPackageInstructionArg {
	/// The ID of the package
	pub pkg_id: String,
	/// The name of the custom command
	pub command: String,
	/// Any additional arguments supplied to the command
	pub args: Vec<String>,
}

/// Result from the CustomPackageInstruction hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct CustomPackageInstructionResult {
	/// Whether the instruction was handled by this plugin
	pub handled: bool,
	/// The output of addon requests
	pub addon_reqs: Vec<AddonInstructionData>,
	/// The output dependencies
	pub deps: Vec<Vec<RequiredPackage>>,
	/// The output conflicts
	pub conflicts: Vec<PackageID>,
	/// The output recommendations
	pub recommendations: Vec<RecommendedPackage>,
	/// The output bundled packages
	pub bundled: Vec<PackageID>,
	/// The output compats
	pub compats: Vec<(PackageID, PackageID)>,
	/// The output package extensions
	pub extensions: Vec<PackageID>,
	/// The output notices
	pub notices: Vec<String>,
}

def_hook!(
	HandleAuth,
	"handle_auth",
	"Hook for handling authentication for custom account types",
	HandleAuthArg,
	HandleAuthResult,
	1,
);

/// Argument for the HandleAuth hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct HandleAuthArg {
	/// The ID of the account
	pub account_id: String,
	/// The custom type of the account
	pub account_type: String,
}

/// Result from the HandleAuth hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct HandleAuthResult {
	/// Whether the auth for this account type was handled by this plugin
	pub handled: bool,
	/// The resulting account profile
	pub profile: Option<MinecraftUserProfile>,
}

def_hook!(
	AddTranslations,
	"add_translations",
	"Hook for adding extra translations to Nitrolaunch",
	(),
	LanguageMap,
	1,
	true,
);

def_hook!(
	AddInstanceTransferFormats,
	"add_instance_transfer_formats",
	"Hook for adding information about instance transfer formats",
	(),
	Vec<InstanceTransferFormat>,
	1,
);

/// Information about an instance transfer format
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct InstanceTransferFormat {
	/// The ID for this format
	pub id: String,
	/// A display name for this format
	pub name: String,
	/// A CSS color for this format
	pub color: Option<String>,
	/// Info for the import side of this format
	pub import: Option<InstanceTransferFormatDirection>,
	/// Info for the export side of this format
	pub export: Option<InstanceTransferFormatDirection>,
	/// Info for the migration side of this format
	pub migrate: Option<InstanceTransferFormatDirection>,
	/// Whether a side must be specified when importing this format
	pub needs_import_side: bool,
}

/// Information about a side of an instance transfer format
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct InstanceTransferFormatDirection {
	/// Support status of the modloader
	pub modloader: InstanceTransferFeatureSupport,
	/// Support status of the mods
	pub mods: InstanceTransferFeatureSupport,
	/// Support status of the launch settings
	pub launch_settings: InstanceTransferFeatureSupport,
}

/// Support status of some feature in an instance transfer format
#[derive(Serialize, Deserialize, Default, Clone, Copy)]
#[serde(rename_all = "snake_case")]
pub enum InstanceTransferFeatureSupport {
	/// This feature is supported by the transfer
	#[default]
	Supported,
	/// This feature is unsupported by the nature of the format
	FormatUnsupported,
	/// This feature is not yet supported by the plugin
	PluginUnsupported,
}

def_hook!(
	ExportInstance,
	"export_instance",
	"Hook for exporting an instance",
	ExportInstanceArg,
	(),
	3,
);

/// Argument provided to the export_instance hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct ExportInstanceArg {
	/// The ID of the transfer format being used
	pub format: String,
	/// The ID of the instance
	pub id: String,
	/// The configuration of the instance
	pub config: InstanceConfig,
	/// The actual Minecraft version of the instance
	pub minecraft_version: String,
	/// The actual loader version of the instance
	pub loader_version: Option<String>,
	/// The directory where the instance game files are located
	pub inst_dir: String,
	/// The desired path for the resulting instance, as a file path
	pub result_path: String,
}

def_hook!(
	ImportInstance,
	"import_instance",
	"Hook for importing an instance",
	ImportInstanceArg,
	ImportInstanceResult,
	2,
);

/// Argument provided to the import_instance hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct ImportInstanceArg {
	/// The ID of the transfer format being used
	pub format: String,
	/// The ID of the new instance
	pub id: String,
	/// The path to the instance to import
	pub source_path: String,
	/// The desired directory for the resulting instance
	pub result_path: String,
	/// The desired side for the instance if it cannot be inferred from the format itself
	pub side: Option<Side>,
}

/// Result from the ImportInstance hook giving information about the new instance
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct ImportInstanceResult {
	/// The ID of the transfer format being used
	pub format: String,
	/// The configuration of the new instance
	pub config: InstanceConfig,
}

def_hook!(
	CheckMigration,
	"check_migration",
	"Hook for checking for presence of a launcher for migration",
	String,
	Option<CheckMigrationResult>,
	1,
);

/// Result from the CheckMigration hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct CheckMigrationResult {
	/// Available instances from this launcher
	pub instances: Vec<String>,
}

def_hook!(
	MigrateInstances,
	"migrate_instances",
	"Hook for migrating all instances from another launcher",
	MigrateInstancesArg,
	MigrateInstancesResult,
	2,
);

/// Argument for the MigrateInstances hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct MigrateInstancesArg {
	/// The ID of the transfer format being used
	pub format: String,
	/// The names of the instances to migrate, empty to migrate all of them
	pub instances: Option<Vec<String>>,
	/// Whether to copy the instance files or link the game dirs
	pub link: bool,
}

/// Result from the MigrateInstances hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct MigrateInstancesResult {
	/// The ID of the transfer format being used
	pub format: String,
	/// The configuration of the new instances
	pub instances: HashMap<String, InstanceConfig>,
}

/// An addon installed on a migrated instance
#[derive(Serialize, Deserialize)]
pub struct MigratedAddon {
	/// The unique ID of the addon in this package
	pub id: String,
	/// The paths to the addon
	pub paths: Vec<String>,
	/// What kind of addon this is
	pub kind: AddonKind,
	/// The currently installed addon version ID
	pub version: Option<String>,
}

def_hook!(
	AddSupportedLoaders,
	"add_supported_loaders",
	"Tell Nitrolaunch that you support installing extra loaders",
	(),
	Vec<Loader>,
	2,
);

def_hook!(
	AddInstances,
	"add_instances",
	"Hook for adding new instances",
	AddInstancesArg,
	HashMap<InstanceID, InstanceConfig>,
	1,
	true,
);

/// Argument for the AddInstances hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct AddInstancesArg {}

def_hook!(
	AddTemplates,
	"add_templates",
	"Hook for adding new templates",
	AddInstancesArg,
	HashMap<TemplateID, TemplateConfig>,
	1,
	true,
);

def_hook!(
	InjectPageScript,
	"inject_page_script",
	"Hook for running JavaScript on GUI pages",
	InjectPageScriptArg,
	String,
	1,
	true,
);

/// Argument for the InjectPageScript hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct InjectPageScriptArg {
	/// The identifier for the page
	pub page: String,
	/// The identifier for whatever 'thing' this page is representing. Could be an instance, template, anything else, or nothing.
	pub object: Option<String>,
}

def_hook!(
	AddSidebarButtons,
	"add_sidebar_buttons",
	"Hook for adding buttons to the GUI sidebar",
	(),
	Vec<SidebarButton>,
	1,
	true,
);

/// Data for a GUI sidebar button
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct SidebarButton {
	/// The inner HTML of the button
	pub html: String,
	/// Where the button should go when pressed
	pub href: String,
	/// What the current URL should equal to select this item
	pub selected_url: Option<String>,
	/// What the current URL should start with to select this item
	pub selected_url_start: Option<String>,
	/// The CSS color of this button
	pub color: String,
}

def_hook!(
	GetPage,
	"get_page",
	"Hook for adding pages to the GUI",
	String,
	Option<String>,
	1,
);

def_hook!(
	AddCustomPackageRepositories,
	"add_custom_package_repositories",
	"Hook for adding custom package repositories",
	(),
	Vec<AddCustomPackageRepositoriesResult>,
	1,
);

/// A single added package repository from the AddCustomPackageRepositories hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct AddCustomPackageRepositoriesResult {
	/// Whether the repository should be preferred or backup
	pub is_preferred: bool,
	/// The ID for the repository
	pub id: String,
	/// The metadata for the repository
	pub metadata: RepoMetadata,
}

def_hook!(
	QueryCustomPackageRepository,
	"query_custom_package_repository",
	"Hook for getting packages from a custom repository",
	QueryCustomPackageRepositoryArg,
	Option<CustomRepoQueryResult>,
	1,
);

/// Argument for the QueryCustomPackageRepository hook
#[derive(Serialize, Deserialize, Default)]
pub struct QueryCustomPackageRepositoryArg {
	/// The repository that is being queried
	pub repository: String,
	/// The package that is being asked for
	pub package: String,
	/// The depth of the package to be returned
	pub depth: PackageQueryDepth,
}

/// Result from querying a custom package repository
#[derive(Serialize, Deserialize)]
pub struct CustomRepoQueryResult {
	/// The contents of the package
	pub contents: String,
	/// The content type of the package
	pub content_type: PackageContentType,
	/// The flags for the package
	pub flags: HashSet<PackageFlag>,
}

def_hook!(
	SearchCustomPackageRepository,
	"search_custom_package_repository",
	"Hook for searching or browsing a custom package repository",
	SearchCustomPackageRepositoryArg,
	PackageSearchResults,
	1,
);

/// Argument for the SearchCustomPackageRepository hook
#[derive(Serialize, Deserialize, Default)]
pub struct SearchCustomPackageRepositoryArg {
	/// The repository that is being queried
	pub repository: String,
	/// The parameters for the search
	pub parameters: PackageSearchParameters,
}

def_hook!(
	PreloadPackages,
	"preload_packages",
	"Hook for loading multiple packages from a custom package repository",
	PreloadPackagesArg,
	(),
	1,
);

/// Argument for the PreloadPackages hook
#[derive(Serialize, Deserialize, Default)]
pub struct PreloadPackagesArg {
	/// The repository that is being queried
	pub repository: String,
	/// The packages that are being preloaded
	pub packages: Vec<String>,
}

def_hook!(
	SyncCustomPackageRepository,
	"sync_custom_package_repository",
	"Hook for updating the cache of a custom package repository",
	SyncCustomPackageRepositoryArg,
	(),
	1,
);

/// Argument for the SyncCustomPackageRepository hook
#[derive(Serialize, Deserialize, Default)]
pub struct SyncCustomPackageRepositoryArg {
	/// The repository that is being synced
	pub repository: String,
}

def_hook!(
	AddThemes,
	"add_themes",
	"Hook for adding new GUI themes",
	(),
	Vec<Theme>,
	1,
	true,
);

/// Data for a GUI theme
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct Theme {
	/// A unique ID for the theme
	pub id: String,
	/// The name of the theme
	pub name: String,
	/// A description for the theme
	pub description: Option<String>,
	/// The type of this theme
	pub r#type: ThemeType,
	/// The CSS data for the theme
	pub css: String,
	/// A css color that identifies this theme
	pub color: String,
}

/// Types of GUI themes
#[derive(Serialize, Deserialize, Default, Clone, Copy)]
#[serde(rename_all = "snake_case")]
pub enum ThemeType {
	/// A base theme that restyles most of the launcher
	#[default]
	Base,
	/// A light change that can be stacked with other overlay themes
	Overlay,
}

def_hook!(
	CustomAction,
	"custom_action",
	"Runs an arbitrary action on this plugin",
	CustomActionArg,
	serde_json::Value,
	1,
);

/// Argument for the CustomAction hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct CustomActionArg {
	/// The ID of the action
	pub id: String,
	/// The payload/argument for the action
	pub payload: serde_json::Value,
}

def_hook!(
	AddDropdownButtons,
	"add_dropdown_buttons",
	"Adds buttons to dropdowns in the GUI",
	(),
	Vec<DropdownButton>,
	1,
);

/// Button for GUI dropdowns
#[derive(Serialize, Deserialize)]
pub struct DropdownButton {
	/// The plugin which this button is from
	pub plugin: String,
	/// Which dropdown this button should be under
	pub location: DropdownButtonLocation,
	/// The icon for this button
	pub icon: String,
	/// The text for this button
	pub text: String,
	/// The CSS color for this button
	pub color: Option<String>,
	/// An optional tooltip for this button
	pub tip: Option<String>,
	/// The custom action to do when this button is clicked
	pub action: Option<String>,
	/// Javascript to run when this button is clicked
	pub on_click: Option<String>,
}

/// Location for a DropdownButton in the UI
#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
#[serde(rename_all = "snake_case")]
pub enum DropdownButtonLocation {
	/// Button on the instances page for adding an instance or template
	AddTemplateOrInstance,
	/// Button on an instance page for launching the instance
	InstanceLaunch,
	/// Button on an instance page for updating the instance
	InstanceUpdate,
	/// Button on an instance page for more options
	InstanceMoreOptions,
}

def_hook!(
	AddInstanceTiles,
	"add_instance_tiles",
	"Adds tiles to the instance page in the GUI",
	String,
	Vec<InstanceTile>,
	1,
	true,
);

/// Tile on the GUI instance page
#[derive(Serialize, Deserialize)]
pub struct InstanceTile {
	/// Unique ID for this tile
	pub id: String,
	/// HTML contents of this tile
	pub contents: String,
	/// The size of this tile
	pub size: InstanceTileSize,
}

/// Size of an InstanceTile
#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
#[serde(rename_all = "snake_case")]
pub enum InstanceTileSize {
	/// Spans one unit
	Small,
	/// Spans two units
	Large,
}

def_hook!(
	AddInstanceIcons,
	"add_instance_icons",
	"Adds default instance icons for the user to use",
	(),
	Vec<String>,
	1,
	true,
);

def_hook!(
	GetLoaderVersions,
	"get_loader_versions",
	"Gets the list of versions for a loader",
	GetLoaderVersionsArg,
	Vec<String>,
	1,
	true,
);

/// Argument for the GetLoaderVersions hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct GetLoaderVersionsArg {
	/// The loader to get versions for
	pub loader: Loader,
	/// The Minecraft version of the instance
	pub minecraft_version: String,
}

def_hook!(
	AddAccountTypes,
	"add_account_types",
	"Adds new available account types",
	(),
	Vec<AccountTypeInfo>,
	1,
);

/// Information about an account type
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct AccountTypeInfo {
	/// The ID of the account type
	pub id: String,
	/// The display name of the account type
	pub name: String,
	/// CSS color of the account type
	pub color: String,
}

def_hook!(
	AddJavaTypes,
	"add_java_types",
	"Adds new available Java types",
	(),
	Vec<JavaTypeInfo>,
	1,
);

/// Information about a Java type
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct JavaTypeInfo {
	/// The ID of the Java type
	pub id: String,
	/// The display name of the Java type
	pub name: String,
	/// CSS color of the Java type
	pub color: String,
}

def_hook!(
	InstallCustomJava,
	"install_custom_java",
	"Installs a custom Java type",
	InstallCustomJavaArg,
	Option<InstallCustomJavaResult>,
	1,
	true,
);

/// Argument for the InstallCustomJava hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct InstallCustomJavaArg {
	/// The Java that is being installed
	pub kind: String,
	/// The major version of Java to install
	pub major_version: String,
	/// Update depth for the install
	pub update_depth: UpdateDepth,
}

/// Result from the InstallCustomJava hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct InstallCustomJavaResult {
	/// The path to the Java installation, containing a bin/java(.exe) executable
	pub path: String,
	/// The version of the resulting installation
	pub version: String,
}

def_hook!(
	SaveInstanceConfig,
	"save_instance_config",
	"Creates or updates config for a plugin instance",
	SaveInstanceConfigArg,
	(),
	1,
	true,
);

/// Argument for the SaveInstanceConfig hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct SaveInstanceConfigArg {
	/// The ID of the instance
	pub id: String,
	/// The configuration to save
	pub config: InstanceConfig,
}

def_hook!(
	SaveTemplateConfig,
	"save_template_config",
	"Creates or updates config for a plugin template",
	SaveTemplateConfigArg,
	(),
	1,
	true,
);

/// Argument for the SaveTemplateConfig hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct SaveTemplateConfigArg {
	/// The ID of the template
	pub id: String,
	/// The configuration to save
	pub config: TemplateConfig,
}

def_hook!(
	DeleteInstance,
	"delete_instance",
	"Deletes a plugin instance",
	SaveInstanceConfigArg,
	(),
	1,
	false,
);

def_hook!(
	DeleteTemplate,
	"delete_template",
	"Deletes a plugin template",
	SaveTemplateConfigArg,
	(),
	1,
	false,
);

def_hook!(
	GetInstanceLogs,
	"get_instance_logs",
	"Gets the list of available log IDs for an instance",
	GetInstanceLogsArg,
	Vec<String>,
	1,
	true,
);

/// Argument for the GetInstanceLogs hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct GetInstanceLogsArg {
	/// The ID of the instance
	pub id: String,
	/// The configuration of the instance
	pub config: InstanceConfig,
}

def_hook!(
	GetInstanceLog,
	"get_instance_log",
	"Gets the contents of a specific log for an instance",
	GetInstanceLogArg,
	String,
	1,
	true,
);

/// Argument for the GetInstanceLog hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct GetInstanceLogArg {
	/// The ID of the instance
	pub instance_id: String,
	/// The ID of the log
	pub log_id: String,
	/// The configuration of the instance
	pub config: InstanceConfig,
}

def_hook!(
	GetAccountCosmetics,
	"get_account_cosmetics",
	"Gets the available cosmetics for a custom account",
	GetAccountCosmeticsArg,
	GetAccountCosmeticsResult,
	1,
	true,
);

/// Argument for the GetAccountCosmetics hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct GetAccountCosmeticsArg {
	/// The ID of the account
	pub id: String,
	/// The account kind of the account
	pub kind: String,
}

/// Result from the GetAccountCosmetics hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct GetAccountCosmeticsResult {
	/// The list of available skins
	pub skins: Vec<Skin>,
	/// The list of available capes
	pub capes: Vec<Cape>,
}

def_hook!(
	UploadSkin,
	"upload_skin",
	"Uploads and activates a skin for a custom account",
	UploadSkinArg,
	(),
	1,
	true,
);

/// Argument for the UploadSkin hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct UploadSkinArg {
	/// The ID of the account
	pub id: String,
	/// The account kind of the account
	pub kind: String,
	/// The skin data in png
	pub data: Vec<u8>,
	/// The variant of the skin
	pub variant: SkinVariant,
}

def_hook!(
	ActivateCape,
	"activate_cape",
	"Activates a cape for a custom account",
	ActivateCapeArg,
	(),
	1,
	true,
);

/// Argument for the ActivateCape hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct ActivateCapeArg {
	/// The ID of the account
	pub id: String,
	/// The account kind of the account
	pub kind: String,
	/// The ID of the cape to activate. If not present, deactivate the cape instead
	pub cape: Option<String>,
}

def_hook!(
	AddSkinRepositories,
	"add_skin_repositories",
	"Adds repositories for searching custom skins",
	(),
	Vec<SkinRepository>,
	1,
	true,
);

/// Result from the AddSkinRepositories hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct SkinRepository {
	/// The ID of the repository
	pub id: String,
	/// The display name of the repository
	pub name: String,
}

def_hook!(
	SearchSkinRepository,
	"search_skin_repository",
	"Searches a skin repository for skins",
	SearchSkinRepositoryArg,
	Vec<Skin>,
	1,
	true,
);

/// Argument for the SearchSkinRepository hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct SearchSkinRepositoryArg {
	/// The ID of the repository
	pub repository: String,
	/// The search string
	pub search: Option<String>,
}

def_hook!(
	AddInstanceConfigControls,
	"add_instance_config_controls",
	"Define additional config schema for instance or template config",
	AddInstanceConfigControlsArg,
	AddInstanceConfigControlsResult,
	1,
	true,
);

/// Argument for the AddInstanceConfigControls hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct AddInstanceConfigControlsArg {
	/// ID of the object. None if this is a new config or the base template.
	pub id: Option<String>,
	/// Kind of object we are getting schema for
	pub kind: ConfigKind,
	/// Plugin this config is from
	pub plugin: Option<String>,
}

/// Result from the AddInstanceConfigControls hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct AddInstanceConfigControlsResult {
	/// The list of new controls
	pub controls: Vec<Control>,
}

def_hook!(
	AddPluginConfigControls,
	"add_plugin_config_controls",
	"Define config schema for this plugin",
	(),
	Vec<Control>,
	1,
	true,
);

def_hook!(
	AddModpackFormats,
	"add_modpack_formats",
	"Add new formats for modpacks",
	(),
	Vec<ModpackFormat>,
	1,
	true,
);

/// Format for a modpack
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct ModpackFormat {
	/// ID for the format
	pub id: String,
	/// Display name of the format
	pub name: String,
	/// Corresponding instance transfer format for this modpack
	pub transfer_format: Option<String>,
}

def_hook!(
	InstallModpack,
	"install_modpack",
	"Installs a modpack",
	InstallModpackArg,
	InstallModpackResult,
	1,
	true,
);

/// Argument for the InstallModpack hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct InstallModpackArg {
	/// Format of the modpack
	pub format: String,
	/// Path to the modpack
	pub path: String,
	/// Path to the old version of the modpack
	pub old_path: Option<String>,
	/// Instance directory to install or update the modpack in
	pub target_path: String,
	/// Side of the instance
	pub side: Side,
}

/// Result from the InstallModpack hook
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct InstallModpackResult {
	/// The name of the modpack
	pub name: String,
	/// The list of packages installed by this modpack
	pub packages: Vec<String>,
	/// The addons installed by this modpack
	pub addons: Vec<Addon>,
}