private void LoadContent() { if (ModEntry.SeasonTextures != null) { this.Monitor.Log("SeasonalImmersionMod::Entry has already been called previously, this shouldnt be happening!", LogLevel.Warn); } this.VerboseLog("Attempting to resolve content pack..."); if (Directory.Exists(Path.Combine(ModEntry.FilePath, "ContentPack"))) { this.Mode = ContentMode.Directory; } else if (File.Exists(Path.Combine(ModEntry.FilePath, "ContentPack.zip"))) { try { this.Zip = new ZipFile(Path.Combine(ModEntry.FilePath, "ContentPack.zip")); this.Mode = ContentMode.Zipped; } catch (Exception ex) { this.Monitor.Log($"Was unable to reference ContentPack.zip file, using internal content pack as a fallback.\n{ex.Message}\n{ex.StackTrace}", LogLevel.Error); this.Mode = ContentMode.Internal; } } else { this.Mode = ContentMode.Internal; } Stream stream = this.GetStream("manifest.json"); if (stream == null) { switch (this.Mode) { case ContentMode.Directory: this.Monitor.Log("Found `ContentPack` directory but the `manifest.json` file is missing, falling back to internal.", LogLevel.Error); this.Mode = ContentMode.Internal; stream = this.GetStream("manifest.json"); break; case ContentMode.Zipped: this.Monitor.Log("Found `ContentPack.zip` file but the `manifest.json` file is missing, falling back to internal.", LogLevel.Error); this.Mode = ContentMode.Internal; stream = this.GetStream("manifest.json"); break; } } if (stream == null && this.Mode == ContentMode.Internal) { this.Monitor.Log("Attempted to use internal ContentPack but could not resolve manifest, disabling mod.", LogLevel.Error); return; } this.VerboseLog($"Content pack resolved to mode: {this.Mode}"); ModEntry.SeasonTextures = new Dictionary <string, Dictionary <string, Texture2D> >(); ContentPackManifest manifest = JsonConvert.DeserializeObject <ContentPackManifest>(new StreamReader(stream).ReadToEnd(), new VersionConverter()); this.Monitor.Log($"Using the `{manifest.Name}` content pack, version {manifest.Version} by {manifest.Author}", LogLevel.Info); // Resolve content dir cause CA messes all stuffs up... List <string> Files; if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "Resources", Game1.content.RootDirectory, "XACT", "FarmerSounds.xgs"))) { Files = new List <string>(Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "Resources", Game1.content.RootDirectory, "Buildings")).Where(a => Path.GetExtension(a).Equals(".xnb"))); } else { Files = new List <string>(Directory.EnumerateFiles(Path.Combine(Game1.content.RootDirectory, "Buildings")).Where(a => Path.GetExtension(a).Equals(".xnb"))); } Files.AddRange(new[] { "Flooring.xnb", "Craftables.xnb", "Craftables_outdoor.xnb", "Craftables_indoor.xnb" }); foreach (string file in Files) { Dictionary <string, Texture2D> textures = new Dictionary <string, Texture2D>(); string name = Path.GetFileNameWithoutExtension(file); this.VerboseLog($"Checking if file is seasonal: {name}"); int count = 0; foreach (string season in ModEntry.Seasons) { Texture2D tex = this.GetTexture(Path.Combine(season, name + ".png")); if (tex == null) { continue; } count++; textures.Add(season, tex); } if (count != 4) { if (count > 0) { this.Monitor.Log($"Skipping file due to the textures being incomplete: {file}", LogLevel.Warn); } else { this.VerboseLog($"Skipping file due to there being no textures for it found: {file}"); } continue; } this.VerboseLog($"Making file seasonal: {file}"); ModEntry.SeasonTextures.Add(name, textures); } this.Helper.Events.Player.Warped += this.OnWarped; this.Helper.Events.GameLoop.DayStarted += this.OnDayStarted; this.Monitor.Log($"ContentPack processed, found [{ModEntry.SeasonTextures.Count}] seasonal files", LogLevel.Info); }
internal void LoadContent() { Monitor.Log("Attempting to resolve content pack...", LogLevel.Trace); if (Directory.Exists(Path.Combine(FilePath, "ContentPack"))) { Mode = 1; } else if (File.Exists(Path.Combine(FilePath, "ContentPack.zip"))) { try { Zip = new ZipFile(Path.Combine(FilePath, "ContentPack.zip")); Mode = 2; } catch (Exception ex) { Monitor.Log("Was unable to reference ContentPack.zip file, using internal content pack as a fallback." + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace, LogLevel.Error); Mode = 3; } } else { Mode = 3; } Monitor.Log("Content pack resolved to mode: " + Mode.ToString(), LogLevel.Trace); Stream stream = GetStream("manifest.json"); if (stream == null) { switch (Mode) { case 1: Monitor.Log("Found `ContentPack` directory but the `manifest.json` file is missing!", LogLevel.Error); break; case 2: Monitor.Log("Found `ContentPack.zip` file but the `manifest.json` file is missing!", LogLevel.Error); break; case 3: Monitor.Log("Attempted to use internal ContentPack, but could not resolve manifest!", LogLevel.Error); break; } return; } ContentPackManifest manifest = JsonConvert.DeserializeObject <ContentPackManifest>(new StreamReader(stream).ReadToEnd(), new VersionConverter()); Monitor.Log("Using the `" + manifest.Name + "` content pack, version " + manifest.Version + " by " + manifest.Author, LogLevel.Info); // Resolve content dir cause CA messes all stuffs up... List <string> Files; if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "Resources", Game1.content.RootDirectory, "XACT", "FarmerSounds.xgs"))) { Files = new List <string>(Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "Resources", Game1.content.RootDirectory, "Buildings")).Where(a => Path.GetExtension(a).Equals(".xnb"))); } else { Files = new List <string>(Directory.EnumerateFiles(Path.Combine(Game1.content.RootDirectory, "Buildings")).Where(a => Path.GetExtension(a).Equals(".xnb"))); } Files.AddRange(new[] { "Flooring.xnb", "Craftables.xnb", "Craftables_outdoor.xnb", "Craftables_indoor.xnb" }); foreach (string file in Files) { Dictionary <string, Texture2D> textures = new Dictionary <string, Texture2D>(); string name = Path.GetFileNameWithoutExtension(file); Monitor.Log("Checking if file is seasonal: " + name, LogLevel.Trace); int count = 0; foreach (string season in seasons) { Texture2D tex = GetTexture(Path.Combine(season, name + ".png")); if (tex == null) { continue; } count++; textures.Add(season, tex); } if (count != 4) { if (count > 0) { Monitor.Log("Skipping file due to the textures being incomplete: " + file, LogLevel.Warn); } else { Monitor.Log("Skipping file due to there being no textures for it found: " + file, LogLevel.Trace); } continue; } Monitor.Log("Making file seasonal: " + file, LogLevel.Trace); SeasonTextures.Add(name, textures); } }