public override void OnApplicationStart() { Instance = this; base.OnApplicationStart(); ClassInjector.RegisterTypeInIl2Cpp <Grenade>(); ClassInjector.RegisterTypeInIl2Cpp <PinScript>(); ClassInjector.RegisterTypeInIl2Cpp <HandleScript>(); var folder = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(Application.dataPath), "UserData", "Grenades")); if (!folder.Exists) { folder.Create(); } else { foreach (var file in folder.EnumerateFiles("*.grenade")) { try { var bundle = AssetBundle.LoadFromFile(file.FullName); bundle.hideFlags = HideFlags.DontUnloadUnusedAsset; TextAsset text = bundle.LoadAsset <TextAsset>("Grenades.xml"); var xml = XDocument.Parse(text.text); foreach (var grenadeXml in xml.Root.Elements("Grenade")) { var prefab = bundle.LoadAsset <GameObject>((string)grenadeXml.Attribute("prefab")); prefab.hideFlags = HideFlags.DontUnloadUnusedAsset; Shaders.ReplaceDummyShaders(prefab); var guid = Guid.NewGuid(); prefab.name = guidPrefix + guid.ToString(); this.definitions[guid] = grenadeXml; var g = prefab.AddComponent <Grenade>(); SpawnMenu.AddItem(prefab, (string)grenadeXml.Attribute("name") ?? "[Grenade]", (int?)grenadeXml.Attribute("pool") ?? 4, (CategoryFilters)Enum.Parse(typeof(CategoryFilters), (string)grenadeXml.Attribute("category") ?? "GADGETS", true)); } } catch (Exception e) { Log.LogError($"Failed when loading grenade bundle: {file.Name}\n{e.Message}\n{e.StackTrace}"); } } } CustomMapIntegration.Init(); if (Environment.GetCommandLineArgs().Contains("--grenades.debug")) { void ExportXml() { foreach (var def in Instance.definitions.Values) { var file = Path.Combine(folder.FullName, $"exported_{(string)def.Attribute("name") ?? "noname"}.xml"); def.Save(file); } } var i = Interfaces.AddNewInterface("Grenades Debug", Color.green); i.CreateFunctionElement("Output all xml", Color.green, null, null, ExportXml); } }