public BeatSaberQuestomConfig GetCurrentConfig(bool suppressImages = false) { using (var apkFileProvider = new ApkAssetsFileProvider(_apkFilename, ApkAssetsFileProvider.FileCacheMode.Memory, true)) { var manager = new AssetsManager(apkFileProvider, BSConst.GetAssetTypeMap(), false); manager.GetAssetsFile("globalgamemanagers"); var file11 = manager.GetAssetsFile(BSConst.KnownFiles.File11); var basicSaberModel = file11.FindAsset <GameObject>(x => x.Object.Name == "BasicSaberModel"); var basicSaber = file11.FindAsset <GameObject>(x => x.Object.Name == "BasicSaber"); var config = GetConfig(manager, suppressImages); //clear out any of the internal refs that were used so the GC can clean things up foreach (var p in config.Playlists) { p.CoverArtSprite = null; p.LevelPackObject = null; foreach (var song in p.SongList) { song.LevelData = null; song.SourceOgg = null; } } config.Saber = new SaberModel() { SaberID = GetCurrentSaberID(manager) }; return(config); } }
public void UpdateConfig(BeatSaberQuestomConfig config) { //todo: basic validation of the config if (_readOnly) { throw new InvalidOperationException("Cannot update in read only mode."); } using (var apkFileProvider = new ApkAssetsFileProvider(_apkFilename, ApkAssetsFileProvider.FileCacheMode.Memory, false)) { var manager = new AssetsManager(apkFileProvider, BSConst.GetAssetTypeMap(), false); manager.GetAssetsFile("globalgamemanagers"); //get existing playlists and their songs //compare with new ones //generate a diff //etc. UpdateColorConfig(manager, config.Colors); UpdateTextConfig(manager, config.TextChanges); if (!UpdateSaberConfig(manager, config.Saber)) { Log.LogErr("Saber failed to update. Aborting all changes."); } if (config.Playlists != null) { UpdateMusicConfig(manager, config, apkFileProvider); } else { Log.LogMsg("Playlists is null, song configuration will not be changed."); } Log.LogMsg("Serializing all assets..."); manager.WriteAllOpenAssets(); apkFileProvider.Save(); } }