public RunPathHandler(ModConfig config, IModHelper helper, IMonitor monitor, ActiveSaveData activeSaveData) : base(config, helper, monitor) { this.activeSaveData = activeSaveData; }
public override void Entry(IModHelper helper) { GameEvents.HalfSecondTick += this.GameEvents_HalfSecondTick; config = helper.ReadConfig <Config>(); }
public ModPatchManager(IModHelper helper) { Harmony = HarmonyInstance.Create(helper.ModRegistry.ModID); PatchList = new List <IClassPatch>(); }
public override void Entry(IModHelper helper) { Utils.Reflection = helper.Reflection; if (helper.ModRegistry.IsLoaded("cat.fruittreesanywhere")) { this.Monitor.Log("You have both this mod, and the old version ('Fruit Trees Anywhere') installed!", LogLevel.Error); this.Monitor.Log( "In order for this mod to work properly, you need to delete the FruitTreesAnywhere folder!", LogLevel.Error); this.Monitor.Log( "This mod does everything the old version does and fruit tree junimo harvesting, so please delete FruitTreesAnywhere!", LogLevel.Error); SaveEvents.AfterLoad += this.ShowErrorMessage; return; } BetterFruitTreesConfig config = helper.ReadConfig <BetterFruitTreesConfig>(); IInitializable pHelper = new PlacementHelper(config); pHelper.Init(); if (config.Disable_Fruit_Tree_Junimo_Harvesting) { return; } Utils.HarvestThreeAtOnce = config.Wait_To_Harvest_Fruit_Trees_Until_They_Have_Three_Fruits__Then_Harvest_All_Three_At_Once; HarmonyInstance harmony = HarmonyInstance.Create("cat.betterfruittrees"); Type junimoHarvesterType = Utils.GetSDVType("Characters.JunimoHarvester"); IList <Tuple <string, Type, Type> > replacements = new List <Tuple <string, Type, Type> > { { "foundCropEndFunction", junimoHarvesterType, typeof(FoundCropEndFunctionPatch) }, { "tryToHarvestHere", junimoHarvesterType, typeof(TryToHarvestHerePatch) }, { "update", junimoHarvesterType, typeof(UpdatePatch) }, { "areThereMatureCropsWithinRadius", Utils.GetSDVType("Buildings.JunimoHut"), typeof(AreThereMatureCropsWithinRadiusPatch) } }; foreach (Tuple <string, Type, Type> replacement in replacements) { MethodInfo original = replacement.Item2 .GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public).ToList() .Find(m => m.Name == replacement.Item1); MethodInfo prefix = replacement.Item3.GetMethods(BindingFlags.Static | BindingFlags.Public) .FirstOrDefault(item => item.Name == "Prefix"); MethodInfo postfix = replacement.Item3.GetMethods(BindingFlags.Static | BindingFlags.Public) .FirstOrDefault(item => item.Name == "Postfix"); harmony.Patch(original, prefix == null ? null : new HarmonyMethod(prefix), postfix == null ? null : new HarmonyMethod(postfix)); } }
public override void Entry(IModHelper helper) { GameEvents.UpdateTick += onUpdate; }
public static Map loadTmx(IModHelper modHelper, string mapName, string path) { var tmap = new TiledMap(Path.Combine(modHelper.DirectoryPath, path)); var xmap = new Map(mapName); addTiledPropertiesToXTile(tmap.Properties, xmap.Properties); var tileMapping = new Dictionary <int, TileMapping>(); var animMapping = new Dictionary <int, TileAnimation>(); foreach (var ttileSheet in tmap.Tilesets) { // xTile wants things like "Mines/mine", not "Mines/mine.png" string image = ttileSheet.Image.Source; if (image.EndsWith(".png")) { string dir = Path.GetDirectoryName(path); string tempKey = Path.Combine(dir, image); string actualKey = modHelper.Content.GetActualAssetKey(tempKey); Log.debug($"{dir} | {image} | {tempKey} | {actualKey} "); image = Path.Combine(Path.GetDirectoryName(path), image); modHelper.Content.Load <Texture2D>(image); image = modHelper.Content.GetActualAssetKey(image); } var xtileSheet = new TileSheet(xmap, image, new Size(ttileSheet.Columns, ttileSheet.TileCount / ttileSheet.Columns), new Size(tmap.TileWidth, tmap.TileHeight)); addTiledPropertiesToXTile(ttileSheet.Properties, xtileSheet.Properties); xtileSheet.Id = ttileSheet.Name; xtileSheet.Spacing = new Size(ttileSheet.Spacing, ttileSheet.Spacing); xtileSheet.Margin = new Size(ttileSheet.Margin, ttileSheet.Margin); for (int i = 0; i < ttileSheet.TileCount; ++i) { tileMapping.Add(ttileSheet.FirstGlobalId + i, new TileMapping(xtileSheet, i)); } foreach (var ttile in ttileSheet.Tiles) { addTiledPropertiesToXTile(ttile.Properties, xtileSheet.TileIndexProperties[ttile.Id]); if (ttile.Animation != null && ttile.Animation.Count > 0) { List <int> tanimFrames = new List <int>(); foreach (var ttileAnim in ttile.Animation) { tanimFrames.Add(ttileSheet.FirstGlobalId + ttileAnim.TileId); } animMapping.Add(ttileSheet.FirstGlobalId + ttile.Id, new TileAnimation(tanimFrames.ToArray <int>(), ttile.Animation[0].Duration)); } } xmap.AddTileSheet(xtileSheet); } var tobjectGroups = new List <TiledObjectGroup>(); foreach (var tlayer_ in tmap.Layers) { if (tlayer_ is TiledTileLayer) { var tlayer = tlayer_ as TiledTileLayer; // Note that the tile size needs to be * 4. Otherwise, you will break collisions and many other things. // Yes, even if you don't use the loaded map. Creating the layer is enough. // For some reason vanilla has a tilesize of 16 for tilesheets, but 64 for the layers. // I mean, I knew the game was scaled up, but that's kinda odd. // Anyways, whenever you create a layer with a different tile size, it changes the tile size // of EVERY OTHER LAYER IN EXISTANCE to match. And guess what, that breaks things. // I spent hours figuring this out. I don't care about the underlying cause. I just want to mod. var xlayer = new Layer(tlayer.Name, xmap, new Size(tmap.Width, tmap.Height), new Size(tmap.TileWidth * 4, tmap.TileHeight * 4)); addTiledPropertiesToXTile(tlayer.Properties, xlayer.Properties); if (tlayer.Data.Compression != TiledData.CompressionType.NoCompression) { throw new InvalidDataException("Compressed tile data is not supported."); } if (tlayer.Data.Encoding == TiledData.EncodingType.NoEncoding || tlayer.Data.Encoding == TiledData.EncodingType.Xml) { for (int i = 0; i < tlayer.Data.Tiles.Count; ++i) { var ttile = tlayer.Data.Tiles[i]; int ix = i % tmap.Width; int iy = i / tmap.Width; var xtile = new StaticTile(xlayer, tileMapping[ttile.GlobalId].tileSheet, BlendMode.Alpha, tileMapping[ttile.GlobalId].tileId); xlayer.Tiles[ix, iy] = xtile; } } else if (tlayer.Data.Encoding == TiledData.EncodingType.Csv) { string[] ttiles = string.Join("", tlayer.Data.Data).Split(','); for (int i = 0; i < ttiles.Length; ++i) { var ttile = int.Parse(ttiles[i]); if (!tileMapping.ContainsKey(ttile)) { continue; } int ix = i % tmap.Width; int iy = i / tmap.Width; Tile xtile = null; if (animMapping.ContainsKey(ttile)) { TileAnimation tanim = animMapping[ttile]; var xanimTiles = new StaticTile[tanim.tileIds.Length]; for (int ia = 0; ia < xanimTiles.Length; ++ia) { xanimTiles[ia] = new StaticTile(xlayer, tileMapping[tanim.tileIds[ia]].tileSheet, BlendMode.Alpha, tileMapping[tanim.tileIds[ia]].tileId); } xtile = new AnimatedTile(xlayer, xanimTiles, tanim.duration); } else { xtile = new StaticTile(xlayer, tileMapping[ttile].tileSheet, BlendMode.Alpha, tileMapping[ttile].tileId); } xlayer.Tiles[ix, iy] = xtile; } } else { throw new InvalidDataException("Tile data encoding type " + tlayer.Data.Encoding + " not supported."); } xmap.AddLayer(xlayer); } else if (tlayer_ is TiledObjectGroup) { tobjectGroups.Add(tlayer_ as TiledObjectGroup); } } foreach (var tobjectGroup in tobjectGroups) { var xlayer = xmap.GetLayer(tobjectGroup.Name); if (xlayer == null) { continue; } foreach (var tobj in tobjectGroup.Objects) { if (tobj.Name != "TileData" || tobj.Width != tmap.TileWidth || tobj.Height != tmap.TileWidth || tobj.Properties.Count == 0) { continue; } int x = (int)tobj.X / tmap.TileWidth; int y = (int)tobj.Y / tmap.TileWidth; if (xlayer.Tiles[new Location(x, y)] == null) { Log.warn("Tile property for non-existant tile; skipping"); continue; } addTiledPropertiesToXTile(tobj.Properties, xlayer.Tiles[new Location(x, y)].Properties); } } return(xmap); }
public override void Entry(IModHelper helper) { ModConfig = Helper.ReadConfig <SummitConfig>(); GameEvents.UpdateTick += GameEvents_UpdateTick; GraphicsEvents.OnPreRenderHudEvent += GraphicsEvents_OnPreRenderHudEvent; }
public static void Initialize(IModHelper _helper, IMonitor _monitor, ModConfig _config) { helper = _helper; monitor = _monitor; config = _config; }
public override void Entry(IModHelper helper) { config = helper.ReadConfig <C>(); base.Entry(helper); }
public static bool doesExist(bool failed, ref TileSheet t, IContentPack contentPack, IModHelper helper, string tileSheetPath) { if (!failed) { FileInfo tileSheetFile = new FileInfo(Path.Combine(contentPack != null ? contentPack.DirectoryPath : helper.DirectoryPath, tileSheetPath)); FileInfo tileSheetFileVanilla = new FileInfo(Path.Combine(PyUtils.ContentPath, "Content", "Maps", t.ImageSource + ".xnb")); if (!tileSheetFileVanilla.Exists) { tileSheetFileVanilla = new FileInfo(Path.Combine(PyUtils.ContentPath, "Content", t.ImageSource + ".xnb")); } else { t.ImageSource = @"Maps/" + t.ImageSource; } return(tileSheetFile.Exists && !tileSheetFileVanilla.Exists); } else { Texture2D ts = null; Texture2D tsv = null; try { ts = contentPack != null?contentPack.LoadAsset <Texture2D>(tileSheetPath) : helper.Content.Load <Texture2D>(tileSheetPath); } catch { } try { tsv = helper.Content.Load <Texture2D>(tileSheetPath, ContentSource.GameContent); } catch { } try { if (tsv == null) { tsv = helper.Content.Load <Texture2D>("Maps//" + tileSheetPath, ContentSource.GameContent); } } catch { } return(ts != null && tsv == null); } }
public static Map Load(string path, IModHelper helper, bool syncTexturesToClients, IContentPack contentPack) { Dictionary <TileSheet, Texture2D> tilesheets = Helper.Reflection.GetField <Dictionary <TileSheet, Texture2D> >(Game1.mapDisplayDevice, "m_tileSheetTextures").GetValue(); Map map = tmx2map(Path.Combine(contentPack != null ? contentPack.DirectoryPath : helper.DirectoryPath, path)); string fileName = new FileInfo(path).Name; for (int i = 0; i < map.TileSheets.Count; i++) { var t = map.TileSheets[i]; t.ImageSource = t.ImageSource.Replace(".png", ""); string[] seasons = new string[] { "summer_", "fall_", "winter_" }; string tileSheetPath = path.Replace(fileName, t.ImageSource + ".png"); bool failed = PyUtils.ContentPath == "failed"; if ((doesExist(failed, ref t, contentPack, helper, tileSheetPath) && tilesheets.Find(k => k.Key.ImageSource == t.ImageSource).Key == null)) { Texture2D tilesheet = contentPack != null?contentPack.LoadAsset <Texture2D>(tileSheetPath) : helper.Content.Load <Texture2D>(tileSheetPath); if (!Injected.Contains(t.ImageSource)) { tilesheet.inject(t.ImageSource); Injected.Add(t.ImageSource); } if (!Injected.Contains("Maps/" + t.ImageSource)) { tilesheet.inject("Maps/" + t.ImageSource); Injected.Add("Maps/" + t.ImageSource); } if (syncTexturesToClients && Game1.IsMultiplayer && Game1.IsServer) { foreach (Farmer farmhand in Game1.otherFarmers.Values) { PyNet.sendGameContent(t.ImageSource, tilesheet, farmhand, (b) => Monitor.Log("Syncing " + t.ImageSource + " to " + farmhand.Name + ": " + (b ? "successful" : "failed"), b ? LogLevel.Info : LogLevel.Warn)); } } if (t.ImageSource.Contains("spring_")) { foreach (string season in seasons) { string seasonPath = path.Replace(fileName, t.ImageSource.Replace("spring_", season)); FileInfo seasonFile = new FileInfo(Path.Combine(contentPack != null ? contentPack.DirectoryPath : helper.DirectoryPath, seasonPath + ".png")); if (seasonFile.Exists && tilesheets.Find(k => k.Key.ImageSource == t.ImageSource.Replace("spring_", season)).Key == null) { Texture2D seasonTilesheet = contentPack != null?contentPack.LoadAsset <Texture2D>(seasonPath + ".png") : helper.Content.Load <Texture2D>(seasonPath + ".png"); string seasonTextureName = t.ImageSource.Replace("spring_", season); if (!Injected.Contains(seasonTextureName)) { seasonTilesheet.inject(seasonTextureName); Injected.Add(seasonTextureName); } if (!Injected.Contains("Maps/" + seasonTextureName)) { seasonTilesheet.inject("Maps/" + seasonTextureName); Injected.Add("Maps/" + seasonTextureName); } if (syncTexturesToClients && Game1.IsMultiplayer && Game1.IsServer) { foreach (Farmer farmhand in Game1.otherFarmers.Values) { PyNet.sendGameContent(new string[] { seasonTextureName, "Maps/" + seasonTextureName }, seasonTilesheet, farmhand, (b) => Monitor.Log("Syncing " + seasonTextureName + " to " + farmhand.Name + ": " + (b ? "successful" : "failed"), b ? LogLevel.Info : LogLevel.Warn)); } } } } } } } map.LoadTileSheets(Game1.mapDisplayDevice); return(map); }
internal static MemoryStream xnb2tmx(string path, IModHelper helper, ContentSource contentSource) { Map map = helper.Content.Load <Map>(path, contentSource); return(map2tmx(map)); }
public static Map Load(string path, IModHelper helper, IContentPack contentPack = null) { return(Load(path, helper, false, contentPack)); }
public override void Entry(IModHelper helper) { loadContentPacks(); Helper.ConsoleCommands.Add("plan", "Imports the contents of a planner export into your farm", (s, p) => importFarm(p)); Helper.ConsoleCommands.Add("planweb", "Imports the contents of a planner id from the web into your farm", (s, p) => importFarmWeb(p)); }
public SnakeMinigame(IModHelper helper) { ShouldQuit = false; Initialize(helper); StartGame(); }
public override void Entry(IModHelper helper) { ModHelper = helper; Util.Helper = helper; Util.Monitor = Monitor; Util.ModInstance = this; Conf = helper.ReadConfig <Config>(); IModEvents Events = Helper.Events; Events.Input.ButtonPressed += OnButtonPressed; Events.GameLoop.UpdateTicked += OnGameUpdateEvent; Events.Display.RenderedHud += OnPostRenderHud; Events.Display.RenderedActiveMenu += OnPostRenderGui; Events.Display.MenuChanged += OnMenuChanged; Events.GameLoop.Saving += OnBeforeSave; Events.GameLoop.DayStarted += OnDayStarted; Conf.CpuThresholdFishing = Util.Cap(Conf.CpuThresholdFishing, 0, 0.5f); Conf.HealthToEatRatio = Util.Cap(Conf.HealthToEatRatio, 0.1f, 0.8f); Conf.StaminaToEatRatio = Util.Cap(Conf.StaminaToEatRatio, 0.1f, 0.8f); Conf.AutoCollectRadius = (int)Util.Cap(Conf.AutoCollectRadius, 1, 3); Conf.AutoHarvestRadius = (int)Util.Cap(Conf.AutoHarvestRadius, 1, 3); Conf.AutoPetRadius = (int)Util.Cap(Conf.AutoPetRadius, 1, 3); Conf.AutoWaterRadius = (int)Util.Cap(Conf.AutoWaterRadius, 1, 3); Conf.AutoDigRadius = (int)Util.Cap(Conf.AutoDigRadius, 1, 3); Conf.AutoShakeRadius = (int)Util.Cap(Conf.AutoShakeRadius, 1, 3); Conf.MachineRadius = (int)Util.Cap(Conf.MachineRadius, 1, 3); Conf.RadiusCraftingFromChests = (int)Util.Cap(Conf.RadiusCraftingFromChests, 1, 5); Conf.IdleTimeout = (int)Util.Cap(Conf.IdleTimeout, 1, 300); Conf.ScavengingRadius = (int)Util.Cap(Conf.ScavengingRadius, 1, 3); Conf.AnimalHarvestRadius = (int)Util.Cap(Conf.AnimalHarvestRadius, 1, 3); if (ModChecker.IsCoGLoaded(helper)) { Monitor.Log("CasksOnGround detected."); IsCoGOn = true; } if (ModChecker.IsCALoaded(helper)) { Monitor.Log("CasksAnywhere detected."); IsCAOn = true; } if (ModChecker.IsCCLoaded(helper)) { Monitor.Log("Convenient Chests detected. JOE's CraftingFromChests feature will be disabled and won't patch the game."); Conf.CraftingFromChests = false; IsCCOn = true; } else { HarmonyPatcher.Init(); } helper.WriteConfig(Conf); MineIcons.Init(helper); }
public static void Initialize(IMonitor monitor, IModHelper helper, ModConfig config) { Monitor = monitor; Config = config; Helper = helper; }
public ShowTravelingMerchant(IModHelper helper) { _helper = helper; }
/// <summary>The mod entry point, called after the mod is first loaded.</summary> /// <param name="helper">Provides simplified APIs for writing mods.</param> public override void Entry(IModHelper helper) { Api = new ModApi(); }
/// <summary>Checks whether a config file should be used with the currently loaded farm.</summary> /// <param name="config">The FarmConfig to be checked.</param> /// <returns>True if the file should be used with the current farm; false otherwise.</returns> public static bool CheckFileConditions(FarmConfig config, IContentPack pack, IModHelper helper) { Monitor.Log("Checking file conditions...", LogLevel.Trace); //check "reset main data folder" flag //NOTE: it's preferable to do this as the first step; it's intended to be a one-off cleaning process, rather than a conditional effect if (config.File_Conditions.ResetMainDataFolder && MConfig.EnableContentPackFileChanges) //if "reset" is true and file changes are enabled { if (pack != null) //if this is part of a content pack { //attempt to load the content pack's global save data ContentPackSaveData packSave = null; try { packSave = pack.ReadJsonFile <ContentPackSaveData>(Path.Combine("data", "ContentPackSaveData.save")); //load the content pack's global save data (null if it doesn't exist) } catch (Exception ex) { Monitor.Log($"Warning: This content pack's save data could not be parsed correctly: {pack.Manifest.Name}", LogLevel.Warn); Monitor.Log($"Affected file: data/ContentPackSaveData.save", LogLevel.Warn); Monitor.Log($"Please delete the file and/or contact the mod's developer.", LogLevel.Warn); Monitor.Log($"The content pack will be skipped until this issue is fixed. The auto-generated error message is displayed below:", LogLevel.Warn); Monitor.Log($"----------", LogLevel.Warn); Monitor.Log($"{ex.Message}", LogLevel.Warn); return(false); //disable this content pack's config, since it may require this process to function } if (packSave == null) //no global save data exists for this content pack { packSave = new ContentPackSaveData(); } if (!packSave.MainDataFolderReset) //if this content pack has NOT reset the main data folder yet { Monitor.Log($"ResetMainDataFolder requested by content pack: {pack.Manifest.Name}", LogLevel.Debug); string dataPath = Path.Combine(helper.DirectoryPath, "data"); //the path to this mod's data folder DirectoryInfo dataFolder = new DirectoryInfo(dataPath); //an object representing this mod's data directory if (dataFolder.Exists) //the data folder exists { Monitor.Log("Attempting to archive data folder...", LogLevel.Trace); try { string archivePath = Path.Combine(helper.DirectoryPath, "data", "archive", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss")); DirectoryInfo archiveFolder = Directory.CreateDirectory(archivePath); //create a timestamped archive folder foreach (FileInfo file in dataFolder.GetFiles()) //for each file in dataFolder { file.MoveTo(Path.Combine(archiveFolder.FullName, file.Name)); //move each file to archiveFolder } } catch (Exception ex) { Monitor.Log($"Warning: This content pack attempted to archive Farm Type Manager's data folder but failed: {pack.Manifest.Name}", LogLevel.Warn); Monitor.Log($"Please report this issue to Farm Type Manager's developer. This might also be fixed by manually removing your FarmTypeManager/data/ files.", LogLevel.Warn); Monitor.Log($"The content pack will be skipped until this issue is fixed. The auto-generated error message is displayed below:", LogLevel.Warn); Monitor.Log($"----------", LogLevel.Warn); Monitor.Log($"{ex.Message}", LogLevel.Warn); return(false); //disable this content pack's config, since it may require this process to function } } else //the data folder doesn't exist { Monitor.Log("Data folder not found; assuming it was deleted or not yet generated.", LogLevel.Trace); } packSave.MainDataFolderReset = true; //update save data } pack.WriteJsonFile(Path.Combine("data", "ContentPackSaveData.save"), packSave); //update the content pack's global save data file Monitor.Log("Data folder archive successful.", LogLevel.Trace); } else //if this is NOT part of a content pack { Monitor.Log("This farm's config file has ResetMainDataFolder = true, but this setting only works for content packs.", LogLevel.Info); } } //check farm type if (config.File_Conditions.FarmTypes != null && config.File_Conditions.FarmTypes.Length > 0) { Monitor.Log("Farm type condition(s) found. Checking...", LogLevel.Trace); bool validType = false; foreach (string type in config.File_Conditions.FarmTypes) //for each listed farm type { if (type.Equals("All", StringComparison.OrdinalIgnoreCase) || type.Equals("Any", StringComparison.OrdinalIgnoreCase)) //if "all" or "any" is listed { validType = true; break; //skip the rest of these checks } switch (Game1.whichFarm) //compare to the current farm type { case (int)Utility.FarmTypes.Standard: if (type.Equals("Standard", StringComparison.OrdinalIgnoreCase) || type.Equals("Default", StringComparison.OrdinalIgnoreCase) || type.Equals("Normal", StringComparison.OrdinalIgnoreCase)) { validType = true; } break; case (int)Utility.FarmTypes.Riverland: if (type.Equals("Riverland", StringComparison.OrdinalIgnoreCase) || type.Equals("Fishing", StringComparison.OrdinalIgnoreCase) || type.Equals("Fish", StringComparison.OrdinalIgnoreCase)) { validType = true; } break; case (int)Utility.FarmTypes.Forest: if (type.Equals("Forest", StringComparison.OrdinalIgnoreCase) || type.Equals("Foraging", StringComparison.OrdinalIgnoreCase) || type.Equals("Forage", StringComparison.OrdinalIgnoreCase) || type.Equals("Woodland", StringComparison.OrdinalIgnoreCase)) { validType = true; } break; case (int)Utility.FarmTypes.Hilltop: if (type.Equals("Hill-top", StringComparison.OrdinalIgnoreCase) || type.Equals("Hilltop", StringComparison.OrdinalIgnoreCase) || type.Equals("Mining", StringComparison.OrdinalIgnoreCase) || type.Equals("Mine", StringComparison.OrdinalIgnoreCase)) { validType = true; } break; case (int)Utility.FarmTypes.Wilderness: if (type.Equals("Wilderness", StringComparison.OrdinalIgnoreCase) || type.Equals("Combat", StringComparison.OrdinalIgnoreCase) || type.Equals("Monster", StringComparison.OrdinalIgnoreCase)) { validType = true; } break; } if (validType) //if a valid weather condition was listed { break; //skip the rest of these checks } } if (validType) //if a valid farm type was listed { Monitor.Log("Farm type matched a setting. File allowed.", LogLevel.Trace); } else { Monitor.Log("Farm type did NOT match any settings. File disabled.", LogLevel.Trace); return(false); //prevent config use } } //check farmer name if (config.File_Conditions.FarmerNames != null && config.File_Conditions.FarmerNames.Length > 0) { Monitor.Log("Farmer name condition(s) found. Checking...", LogLevel.Trace); bool validName = false; foreach (string name in config.File_Conditions.FarmerNames) //for each listed name { if (name.Equals(Game1.player.Name, StringComparison.OrdinalIgnoreCase)) //if the name matches the current player's { validName = true; break; //skip the rest of these checks } } if (validName) //if a valid farmer name was listed { Monitor.Log("Farmer name matched a setting. File allowed.", LogLevel.Trace); } else { Monitor.Log("Farmer name did NOT match any settings. File disabled.", LogLevel.Trace); return(false); //prevent config use } } //check save file names (technically the save folder name) if (config.File_Conditions.SaveFileNames != null && config.File_Conditions.SaveFileNames.Length > 0) { Monitor.Log("Save file name condition(s) found. Checking...", LogLevel.Trace); bool validSave = false; foreach (string saveName in config.File_Conditions.SaveFileNames) //for each listed save name { if (saveName.Equals(Constants.SaveFolderName, StringComparison.OrdinalIgnoreCase)) //if the name matches the current player's save folder name { validSave = true; break; //skip the rest of these checks } } if (validSave) //if a valid save name was listed { Monitor.Log("Save file name matched a setting. File allowed.", LogLevel.Trace); } else { Monitor.Log("Save file name did NOT match any settings. File disabled.", LogLevel.Trace); return(false); //prevent config use } } //check whether other mods exist if (config.File_Conditions.OtherMods != null && config.File_Conditions.OtherMods.Count > 0) { Monitor.Log("Other mod condition(s) found. Checking...", LogLevel.Trace); bool validMods = true; //whether all entries are accurate (true by default, unlike most other settings) foreach (KeyValuePair <string, bool> entry in config.File_Conditions.OtherMods) //for each mod entry in OtherMods { bool validEntry = !(entry.Value); //whether the current entry is accurate (starts false if the mod should exist; starts true if the mod should NOT exist) foreach (IModInfo mod in helper.ModRegistry.GetAll()) //for each mod currently loaded by SMAPI { if (entry.Value == true) //if the mod should exist { if (entry.Key.Equals(mod.Manifest.UniqueID, StringComparison.OrdinalIgnoreCase)) //if this mod's UniqueID matches the OtherMods entry { validEntry = true; //this entry is valid break; //skip the rest of these checks } } else //if the mod should NOT exist { if (entry.Key.Equals(mod.Manifest.UniqueID, StringComparison.OrdinalIgnoreCase)) //if this mod's UniqueID matches the OtherMods entry { validEntry = false; //this entry is invalid break; //skip the rest of these checks } } } if (validEntry) //if the current mod entry is valid { Monitor.Log($"Mod check successful: \"{entry.Key}\" {(entry.Value ? "does exist" : "does not exist")}.", LogLevel.Trace); } else //if the current mod entry is NOT valid { Monitor.Log($"Mod check failed: \"{entry.Key}\" {(entry.Value ? "does not exist" : "does exist")}.", LogLevel.Trace); validMods = false; break; //skip the rest of these checks } } if (validMods) //if all mod entries in the list are valid { Monitor.Log("The OtherMods list matches the player's mods. File allowed.", LogLevel.Trace); } else //if any entries were NOT valid { Monitor.Log("The OtherMods list does NOT match the player's mods. File disabled.", LogLevel.Trace); return(false); //prevent config use } } return(true); //all checks were successful; config should be used }
public ShowBirthdayIcon(IModHelper helper) { _events = helper.Events; _helper = helper; }
public ShopHarvestPrices(IModHelper helper) { _helper = helper; }
/********* ** Public methods *********/ /// <summary>The mod entry point, called after the mod is first loaded.</summary> /// <param name="helper">Provides simplified APIs for writing mods.</param> public override void Entry(IModHelper helper) { helper.Events.Player.Warped += OnWarped; helper.Events.GameLoop.TimeChanged += OnTimeChanged; }
/// <summary>Initializes methods used to retrieve exclusion data.</summary> public static void InitializeDataHelper(IModHelper helper) { helper.Events.Content.AssetRequested += Content_AssetRequested; helper.Events.Player.Warped += Player_Warped_InvalidateCache; }
public void Initialise(ref IModHelper helper) { this.helper = helper; }
/// <summary> /// The mod entry point, called after the mod is first loaded. /// Loads config file and adds method to the event of starting a new day. /// </summary> /// <param name="helper">Provides simplified APIs for writing mods.</param> public override void Entry(IModHelper helper) { helper.Events.GameLoop.DayStarted += OnDayStarted; treeOverhaulConfig = helper.ReadConfig <TreeOverhaulConfig>(); }
public override void Entry(IModHelper helper) { helper.Events.Display.MenuChanged += this.Menu; helper.Events.GameLoop.SaveLoaded += this.Load; }
// call this method from your Entry class public static void Initialize(IMonitor monitor, IModHelper helper) { Monitor = monitor; Helper = helper; }
public virtual void resetTexture(IModHelper helper) { TextureSheet = new Texture2DExtended(helper, TextureSheet.path); }
/// <summary>The mod entry point, called after the mod is first loaded.</summary> public override void Entry(IModHelper helper) { // Initialize mod Initialize(helper); }