/********* ** Private methods *********/ /// <summary>Recursively find XNBs and register them with the content registry.</summary> /// <param name="root">The root path being searched.</param> /// <param name="path">The path for which to load XNBs.</param> private int LoadOverrides(string root, string path) { int files = 0; // log path { string relativePath = path.Replace(root + Path.DirectorySeparatorChar, Path.DirectorySeparatorChar.ToString()).Replace(root, Path.DirectorySeparatorChar.ToString()); this.Monitor.Log($"Scanning for files and directories in {relativePath}", LogLevel.Trace); } // load subfolders foreach (string dir in Directory.EnumerateDirectories(path)) { files += this.LoadOverrides(root, Path.Combine(path, dir)); } // load files foreach (string file in Directory.EnumerateFiles(path)) { string filePath = Path.Combine(path, Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file)); string from = filePath.Replace(root + Path.DirectorySeparatorChar, ""); this.Monitor.Log($"Redirecting: {from} ~> {filePath}.xnb", LogLevel.Trace); EntoFramework.GetContentRegistry().RegisterXnb(from, filePath); files++; } return(files); }
internal static void RealShop(object s, EventArgsMouseStateChanged e) { if (e.NewState.RightButton != ButtonState.Pressed) { ControlEvents.MouseChanged -= RealShop; try { if (!Configs.Compound.Shops.ContainsKey(_arguments[0])) { Game1.activeClickableMenu = new ShopMenu(new List <Item>(), 0, null); AdvancedLocationLoaderMod.Logger.Log("Unable to open shop, shop not found: " + _arguments[0], StardewModdingAPI.LogLevel.Error); } else { Configs.ShopConfig shop = Configs.Compound.Shops[_arguments[0]]; List <Item> stock = new List <Item>(); NPC portrait = new NPC(); EntoFramework.GetContentRegistry().RegisterXnb(shop.Portrait, shop.Portrait); portrait.Portrait = Game1.content.Load <Texture2D>(shop.Portrait); portrait.name = shop.Owner; foreach (Configs.ShopItem item in shop.Items) { if (!string.IsNullOrEmpty(item.Conditions) && !Conditions.CheckConditionList(item.Conditions, AdvancedLocationLoaderMod.ConditionResolver)) { continue; } StardewValley.Object result; if (item.Price != null) { result = new StardewValley.Object(item.Id, item.Stock, false, (int)item.Price); } else { result = new StardewValley.Object(item.Id, item.Stock, false, -1); } if (item.Stack > 1) { stock.Add(new StackableShopObject(result, item.Stack)); } else { stock.Add(result); } } if (stock.Count == 0) { AdvancedLocationLoaderMod.Logger.Log("No stock: " + _arguments[0] + ", if this is intended this message can be ignored.", StardewModdingAPI.LogLevel.Warn); } ShopMenu menu = new ShopMenu(stock); menu.portraitPerson = portrait; menu.potraitPersonDialogue = shop.Messages[_Random.Next(shop.Messages.Count)]; Game1.activeClickableMenu = menu; } } catch (Exception err) { AdvancedLocationLoaderMod.Logger.Log(StardewModdingAPI.LogLevel.Error, "Unable to open shop due to unexpected error: ", err); } } }
public override void Entry(IModHelper helper) { // init modPath = helper.DirectoryPath; Config = helper.ReadConfig <MorePetsConfig>(); // load textures EntoFramework.GetContentRegistry().RegisterTexture("paths_objects_MorePetsTilesheet", Path.Combine(modPath, "box.png")); this.LoadPetSkins(out CatTextures, out DogTextures); Monitor.Log($"Found [{CatTextures.Length}] Cat and [{DogTextures.Length}] Dog skins", LogLevel.Info); // hook events GameEvents.UpdateTick += GameEvents_UpdateTick; TimeEvents.AfterDayStarted += TimeEvents_AfterDayStarted; ControlEvents.ControllerButtonPressed += ControlEvents_ControllerButtonPressed; ControlEvents.MouseChanged += ControlEvents_MouseChanged; //LocationEvents.CurrentLocationChanged += LocationEvents_CurrentLocationChanged; helper.ConsoleCommands.Add("kill_pets", "Kills all the pets you adopted using MorePets, you monster", this.CommandFired_KillPets); // add console commands if (Config.DebugMode) { // DEV COMMANDS, kept in should they be needed in the future helper.ConsoleCommands .Add("spawn_pet", "Spawns either a `dog` or a `cat` depending on the given name | spawn_pet <type> <skin>", this.CommandFired_SpawnPet) .Add("test_adoption", "Triggers the adoption dialogue", this.CommandFired_TestAdoption); } // check version Version version = new Version(this.ModManifest.Version.MajorVersion, this.ModManifest.Version.MinorVersion, this.ModManifest.Version.PatchVersion); VersionChecker.AddCheck("MorePets", version, "https://raw.githubusercontent.com/Entoarox/StardewMods/master/VersionChecker/MorePets.json"); }
public static void ApplyPatches() { int stage = 0; try { stage++; // 1 SecondaryLocationManifest1_2 trueCompound = new SecondaryLocationManifest1_2(); AdvancedLocationLoaderMod.Logger.Log("Applying Patches...", LogLevel.Trace); // First we need to check any things we couldnt before foreach (Location obj in Compound.Locations) { if (Game1.getLocationFromName(obj.MapName) != null) { AdvancedLocationLoaderMod.Logger.Log("Unable to add location, it already exists: " + obj.ToString(), LogLevel.Error); } else { try { xTile.Map map = new LocalizedContentManager(Game1.content.ServiceProvider, Path.GetDirectoryName(obj.FileName)).Load <xTile.Map>(Path.GetFileName(obj.FileName)); MapSizes.Add(obj.MapName, new Point(map.DisplayWidth, map.DisplayHeight)); MapCache.Add(obj.MapName, map); AffectedLocations.Add(obj.MapName); trueCompound.Locations.Add(obj); } catch (Exception err) { AdvancedLocationLoaderMod.Logger.Log(LogLevel.Error, "Unable to add location, the map file caused a error when loaded: " + obj.ToString(), err); } } } stage++; // 2 foreach (Override obj in Compound.Overrides) { if (Game1.getLocationFromName(obj.MapName) == null) { AdvancedLocationLoaderMod.Logger.Log("Unable to override location, it does not exist: " + obj.ToString(), LogLevel.Error); } else { try { xTile.Map map = new LocalizedContentManager(Game1.content.ServiceProvider, Path.GetDirectoryName(obj.FileName)).Load <xTile.Map>(Path.GetFileName(obj.FileName)); MapSizes.Add(obj.MapName, new Point(map.DisplayWidth, map.DisplayHeight)); trueCompound.Overrides.Add(obj); } catch (Exception err) { AdvancedLocationLoaderMod.Logger.Log(LogLevel.Error, "Unable to override location, the map file caused a error when loaded: " + obj.ToString(), err); } } } stage++; // 3 trueCompound.Redirects = Compound.Redirects; stage++; // 4 foreach (Tilesheet obj in Compound.Tilesheets) { if (Game1.getLocationFromName(obj.MapName) == null && !AffectedLocations.Contains(obj.MapName)) { AdvancedLocationLoaderMod.Logger.Log("Unable to patch tilesheet, location does not exist: " + obj.ToString(), LogLevel.Error); } else { trueCompound.Tilesheets.Add(obj); } } stage++; // 5 foreach (Tile obj in Compound.Tiles) { string info = CheckTileInfo(obj); if (info != null) { if (info != "OPTIONAL") { AdvancedLocationLoaderMod.Logger.Log("Unable to apply tile patch, " + info + ":" + obj.ToString(), LogLevel.Error); continue; } } else if (obj.SheetId != null && (!TilesheetCache.ContainsKey(obj.MapName) || !TilesheetCache[obj.MapName].Contains(obj.SheetId))) { xTile.Map map = MapCache.ContainsKey(obj.MapName) ? MapCache[obj.MapName] : Game1.getLocationFromName(obj.MapName).map; if (map.GetTileSheet(obj.SheetId) == null) { AdvancedLocationLoaderMod.Logger.Log("Unable to apply tile patch, tilesheet does not exist:" + obj.ToString(), LogLevel.Error); continue; } } trueCompound.Tiles.Add(obj); } stage++; // 6 foreach (Property obj in Compound.Properties) { string info = CheckTileInfo(obj); if (info != null) { if (info != "OPTIONAL") { AdvancedLocationLoaderMod.Logger.Log("Unable to apply property patch, " + info + ":" + obj.ToString(), LogLevel.Error); } } else { trueCompound.Properties.Add(obj); } } stage++; // 7 foreach (Warp obj in Compound.Warps) { string info = CheckTileInfo(obj); if (info != null) { if (info != "OPTIONAL") { AdvancedLocationLoaderMod.Logger.Log("Unable to apply warp patch, " + info + ":" + obj.ToString(), LogLevel.Error); } } trueCompound.Warps.Add(obj); } stage++; // 8 foreach (Conditional obj in Compound.Conditionals) { Configs.Compound.Conditionals.Add(obj); } stage++; // 9 foreach (TeleporterList obj in Compound.Teleporters) { Configs.Compound.Teleporters.Add(obj); } stage++; // 10 // At this point any edits that showed problems have been removed, so now we can actually process everything foreach (Location obj in trueCompound.Locations) { Processors.ApplyLocation(obj); } stage++; // 11 foreach (Override obj in trueCompound.Overrides) { Processors.ApplyOverride(obj); } stage++; // 12 foreach (Redirect obj in trueCompound.Redirects) { EntoFramework.GetContentRegistry().RegisterXnb(obj.FromFile, obj.ToFile); } stage++; // 13 foreach (Tilesheet obj in trueCompound.Tilesheets) { Processors.ApplyTilesheet(obj); if (obj.Seasonal) { Configs.Compound.SeasonalTilesheets.Add(obj); } } stage++; // 14 foreach (Tile obj in trueCompound.Tiles) { Processors.ApplyTile(obj); if (!string.IsNullOrEmpty(obj.Conditions)) { Configs.Compound.DynamicTiles.Add(obj); } } stage++; // 15 foreach (Property obj in trueCompound.Properties) { Processors.ApplyProperty(obj); if (!string.IsNullOrEmpty(obj.Conditions)) { Configs.Compound.DynamicProperties.Add(obj); } } stage++; // 16 foreach (Warp obj in trueCompound.Warps) { Processors.ApplyWarp(obj); if (!string.IsNullOrEmpty(obj.Conditions)) { Configs.Compound.DynamicWarps.Add(obj); } } stage++; // 17 NPC.populateRoutesFromLocationToLocationList(); stage++; // 18 Compound = null; Conditionals = null; AffectedLocations = null; MapSizes = null; stage++; // 19 VerifyPatchIntegrity(); stage++; // 20 AdvancedLocationLoaderMod.Logger.Log("Patches have been applied", LogLevel.Debug); } catch (Exception err) { AdvancedLocationLoaderMod.Logger.ExitGameImmediately("Unable to patch the game, a unexpected error occured at stage " + stage.ToString(), err); } }