public ContentPackObject(string modPath, string contentPath, ContentPackManifest manifest, ContentConfig content, WhenDictionary config) { this.ModPath = modPath; this.ContentPath = contentPath; this.Manifest = manifest; this.Content = content; this.Config = config; }
public override void Entry(IModHelper help) { this.Config = this.Helper.ReadConfig <ModConfig>(); Logger = this.Monitor; EnabledAssets = new Dictionary <string, bool>(); ModHelper = help; EnableMod = this.Config.EnableMod; this.HDAssetManager = new HDAssetManager(help); this.ContentPackManager = new ContentPackManager(this.HDAssetManager); this.Helper.Events.Input.ButtonPressed += OnButtonPressed; this.Helper.Events.Player.Warped += OnWarped; this.Helper.Events.GameLoop.DayStarted += OnDayStarted; foreach (var asset in this.Config.LoadAssets) { string loadSection = asset.Key.Substring(0, asset.Key.LastIndexOf("/")); bool enabled = asset.Value && this.Config.LoadSections.GetValueSafe(loadSection); AddEnabledAsset(asset.Key, enabled); if (enabled) { string assetFile = Path.Combine(this.Config.AssetsPath, asset.Key) + ".png"; if (File.Exists(Path.Combine(help.DirectoryPath, assetFile))) { this.HDAssetManager.AddAssetFile(asset.Key, assetFile); } } } string[] contentPackDirs = Directory.GetDirectories(Path.Combine(help.DirectoryPath, "..")); foreach (string dir in contentPackDirs) { string manifestFile = Path.Combine(dir, "manifest.json"); if (Directory.GetParent(manifestFile).Name.StartsWith(".")) { continue; } ContentPackManifest manifest = null; try { manifest = this.Helper.ReadJsonFile <ContentPackManifest>(manifestFile); } catch (Exception e) { continue; } if (manifest != null && this.Config.LoadContentPacks.TryGetValue(manifest.UniqueID, out bool load) && load) { this.Monitor.Log($"Reading content pack: {manifest.Name} {manifest.Version}"); WhenDictionary configChoices = null; try { configChoices = this.Helper.ReadJsonFile <WhenDictionary>(Path.Combine(dir, "config.json")); } catch (Exception e) { this.Monitor.Log($"Failed to read config.json for {manifest.Name} {manifest.Version}"); continue; } if (configChoices == null) { configChoices = new WhenDictionary(); } ContentConfig contentConfig = null; try { contentConfig = this.Helper.ReadJsonFile <ContentConfig>(Path.Combine(dir, "content.json")); } catch (Exception e) { this.Monitor.Log($"Failed to read content.json for {manifest.Name} {manifest.Version}"); continue; } if (contentConfig == null) { continue; } string contentPath = Path.Combine(help.DirectoryPath, this.Config.ContentPacksPath, manifest.UniqueID); Directory.CreateDirectory(contentPath); ContentPackObject contentPack = new ContentPackObject(dir, contentPath, manifest, contentConfig, configChoices); this.ContentPackManager.AddContentPack(contentPack); } } HarmonyInstance instance = HarmonyInstance.Create("NinthWorld.HDSprites"); DrawFix.InitializePatch(instance); instance.PatchAll(Assembly.GetExecutingAssembly()); }