public static bool Prefix(PurchaseAnimalsMenu __instance, int x, int y, bool ___freeze, bool ___onFarm, bool ___namingAnimal) { if (!Config.EnableMod || Game1.IsFading() || ___freeze || ___onFarm || ___namingAnimal) { return(true); } if (femaleButt != null && femaleButt.containsPoint(x, y)) { currentSex = Sexes.Female; } else if (maleButt != null && maleButt.containsPoint(x, y)) { currentSex = Sexes.Male; } else if (intersexButt != null && intersexButt.containsPoint(x, y)) { currentSex = Sexes.Intersex; } else { return(true); } SMonitor.Log($"Set current sex to {currentSex}"); return(false); }
public static void GameLoop_DayStarted(object sender, DayStartedEventArgs e) { ResetDivorces(); ResetSpouses(Game1.player); foreach (GameLocation location in Game1.locations) { if (ReferenceEquals(location.GetType(), typeof(FarmHouse))) { PlaceSpousesInFarmhouse(location as FarmHouse); } } if (Game1.IsMasterGame) { Game1.getFarm().addSpouseOutdoorArea(Game1.player.spouse == null ? "" : Game1.player.spouse); farmHelperSpouse = GetRandomSpouse(Game1.MasterPlayer); } foreach (Farmer f in Game1.getAllFarmers()) { var spouses = GetSpouses(f, true).Keys; foreach (string s in spouses) { SMonitor.Log($"{f.Name} is married to {s}"); } } }
public static void SoundInTheNightEvent_tickUpdate_Prefix(SoundInTheNightEvent __instance, NetInt ___behavior, ref int ___timer, ref bool ___playedSound, GameTime time) { if (!Config.EnableMod || ___behavior != 1) { return; } var e = time.ElapsedGameTime.Milliseconds; if (___timer + e > 3500 && !playedDefence && (defence < 0 || defence > struckSound)) { SMonitor.Log("Playing defence sound"); Game1.playSound(Config.DefenceSound); playedDefence = true; } if (___timer + e > 5300 && !playedExplode && (defence < 0 || defence > struckSound)) { SMonitor.Log("Playing explode sound"); Game1.playSound(Config.ExplodeSound); playedExplode = true; } if (___timer + e > 5300 && struckSound < strikeLocations.Count - 1) { struckSound++; playedDefence = false; playedExplode = false; ___playedSound = false; ___timer = 1000; } }
public static void Prefix(FarmAnimal __instance, string type, ref string __state) { if (!Config.EnableMod) return; SMonitor.Log($"Starting creating new {type}"); __state = type; }
public static void ReloadSpouses(Farmer farmer) { currentSpouses[farmer.UniqueMultiplayerID] = new Dictionary <string, NPC>(); currentUnofficialSpouses[farmer.UniqueMultiplayerID] = new Dictionary <string, NPC>(); string ospouse = farmer.spouse; if (ospouse != null) { currentSpouses[farmer.UniqueMultiplayerID].Add(ospouse, Game1.getCharacterFromName(ospouse)); } SMonitor.Log($"Checking for extra spouses in {farmer.friendshipData.Count()} friends"); foreach (string friend in farmer.friendshipData.Keys) { if (farmer.friendshipData[friend].IsMarried() && friend != farmer.spouse) { var npc = Game1.getCharacterFromName(friend, true); if (npc != null) { currentSpouses[farmer.UniqueMultiplayerID].Add(friend, npc); currentUnofficialSpouses[farmer.UniqueMultiplayerID].Add(friend, npc); } } } SMonitor.Log($"reloaded {currentSpouses.Count} spouses for {farmer.Name}"); }
private static bool Object_initializeLightSource_Prefix(Object __instance, Vector2 tileLocation) { if (!Config.EnableMod) { return(true); } LightData light = null; if (lightDataDict.ContainsKey(__instance.ParentSheetIndex + "")) { light = lightDataDict[__instance.ParentSheetIndex + ""]; } else if (lightDataDict.ContainsKey(__instance.Name)) { light = lightDataDict[__instance.Name]; } else { return(true); } SMonitor.Log($"Adding light to {__instance.Name}"); int identifier = (int)(tileLocation.X * 2000f + tileLocation.Y); __instance.lightSource = new LightSource(light.textureIndex, new Vector2(tileLocation.X * 64f + light.offset.X, tileLocation.Y * 64f + light.offset.Y), light.radius, new Color(255 - light.color.R, 255 - light.color.G, 255 - light.color.B, 255 - light.color.A), identifier, LightSource.LightContext.None, 0L); __instance.isLamp.Value = light.isLamp; __instance.IsOn = true; return(false); }
public static void GameLoop_DayStarted(object sender, DayStartedEventArgs e) { if (!Context.IsMainPlayer) { return; } if (!Game1.isRaining && !Game1.IsWinter && Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth).Equals("Sat")) { Farmer farmer = Game1.player; //Game1.getFarm().addSpouseOutdoorArea(Game1.player.spouse == null ? "" : Game1.player.spouse); var spouses = farmer.friendshipData.Pairs.Where(f => f.Value.IsMarried()).Select(f => f.Key).ToList(); NPC ospouse = farmer.getSpouse(); if (ospouse != null) { spouses.Add(ospouse.Name); } foreach (string name in spouses) { NPC npc = Game1.getCharacterFromName(name); if (outdoorAreas.dict.ContainsKey(name) || (farmer.spouse.Equals(npc.Name) && name != "Krobus")) { SMonitor.Log($"placing {name} outdoors"); npc.setUpForOutdoorPatioActivity(); } } } }
public static IEnumerable <CodeInstruction> Tree_draw_Transpiler(IEnumerable <CodeInstruction> instructions) { SMonitor.Log($"Transpiling Tree_draw"); var codes = new List <CodeInstruction>(instructions); var newCodes = new List <CodeInstruction>(); int count = 0; for (int i = 0; i < codes.Count; i++) { if (i > 0 && codes[i].opcode == OpCodes.Callvirt && (MethodInfo)codes[i].operand == AccessTools.Method(typeof(SpriteBatch), nameof(SpriteBatch.Draw), new System.Type[] { typeof(Texture2D), typeof(Vector2), typeof(Rectangle?), typeof(Color), typeof(float), typeof(Vector2), typeof(float), typeof(SpriteEffects), typeof(float) })) { SMonitor.Log($"Switching draw {count}"); var ci = new CodeInstruction(OpCodes.Ldc_I4, count++); ci.MoveLabelsFrom(codes[i]); newCodes.Add(ci); newCodes.Add(new CodeInstruction(OpCodes.Ldarg_0)); newCodes.Add(new CodeInstruction(OpCodes.Ldarg_2)); newCodes.Add(new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ModEntry), nameof(ModEntry.DrawTree)))); } else { newCodes.Add(codes[i]); } } return(newCodes.AsEnumerable()); }
public static bool Prefix(PurchaseAnimalsMenu __instance, ref FarmAnimal ___animalBeingPurchased, int ___priceOfAnimal) { if (!Config.EnableMod || animalsToBuy <= 1) { return(true); } animalsToBuy--; Game1.addHUDMessage(new HUDMessage(___animalBeingPurchased.isMale() ? Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11311", ___animalBeingPurchased.displayName) : Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11314", ___animalBeingPurchased.displayName), 1)); string type = ___animalBeingPurchased.type.Value; if (!SHelper.ModRegistry.IsLoaded("aedenthorn.LivestockChoices")) { if (type.EndsWith(" Chicken") && !type.Equals("Void Chicken") && !type.Equals("Golden Chicken")) { type = "Chicken"; } else if (type.EndsWith(" Cow")) { type = "Cow"; } } ___animalBeingPurchased = new FarmAnimal(type, new Multiplayer().getNewID(), Game1.player.UniqueMultiplayerID); SMonitor.Log($"next animal type: {___animalBeingPurchased.type}; price {___priceOfAnimal}, funds left {Game1.player.Money}"); return(false); }
private static void breakStone_Postfix(GameLocation __instance, ref bool __result, int indexOfStone, int x, int y, Farmer who, Random r) { SMonitor.Log($"Checking for custom ore in stone {indexOfStone}"); CustomOreNode node = customOreNodesList.Find(n => n.parentSheetIndex == indexOfStone); if (node == null) { return; } SMonitor.Log($"Got custom ore in stone {indexOfStone}"); OreLevelRange gotRange = null; foreach (OreLevelRange range in node.oreLevelRanges) { if (IsInRange(range, __instance, false)) { gotRange = range; break; } } if (gotRange == null) { SMonitor.Log($"No range for {indexOfStone}!", LogLevel.Warn); return; } int addedOres = who.professions.Contains(18) ? 1 : 0; SMonitor.Log($"custom node has {node.dropItems.Count} potential items."); foreach (DropItem item in node.dropItems) { if (Game1.random.NextDouble() < item.dropChance * gotRange.dropChanceMult / 100) { SMonitor.Log($"dropping item {item.itemIdOrName}"); if (!int.TryParse(item.itemIdOrName, out int itemId)) { foreach (KeyValuePair <int, string> kvp in Game1.objectInformation) { if (kvp.Value.StartsWith(item.itemIdOrName + "/")) { itemId = kvp.Key; break; } } } Game1.createMultipleObjectDebris(itemId, x, y, addedOres + (int)Math.Round(r.Next(item.minAmount, (Math.Max(item.minAmount + 1, item.maxAmount + 1)) + ((r.NextDouble() < who.LuckLevel / 100f) ? item.luckyAmount : 0) + ((r.NextDouble() < who.MiningLevel / 100f) ? item.minerAmount : 0)) * gotRange.dropMult), who.UniqueMultiplayerID, __instance); } } int experience = (int)Math.Round(node.exp * gotRange.expMult); who.gainExperience(3, experience); __result = experience > 0; }
public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { SMonitor.Log($"Transpiling FruitTree.draw"); var codes = new List <CodeInstruction>(instructions); bool found1 = false; int which = 0; for (int i = 0; i < codes.Count; i++) { if (!found1 && i < codes.Count - 2 && codes[i].opcode == OpCodes.Ldc_I4_1 && codes[i + 1].opcode == OpCodes.Ldc_R4 && (float)codes[i + 1].operand == 1E-07f) { SMonitor.Log("shifting bottom of tree draw layer offset"); codes[i + 1].opcode = OpCodes.Ldarg_0; found1 = true; } if (i > 0 && i < codes.Count - 15 && codes[i].opcode == OpCodes.Ldsfld && (FieldInfo)codes[i].operand == AccessTools.Field(typeof(Game1), nameof(Game1.objectSpriteSheet)) && codes[i + 15].opcode == OpCodes.Call && (MethodInfo)codes[i + 15].operand == AccessTools.PropertyGetter(typeof(Color), nameof(Color.White))) { SMonitor.Log("modifying fruit color"); codes[i + 15].opcode = OpCodes.Call; codes.Insert(i + 15, new CodeInstruction(OpCodes.Ldc_I4, which++)); codes.Insert(i + 15, new CodeInstruction(OpCodes.Ldarg_0)); } if (found1 && which >= 2) { break; } } return(codes.AsEnumerable()); }
public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { SMonitor.Log($"Transpiling Tree.draw"); var codes = new List <CodeInstruction>(instructions); for (int i = 0; i < codes.Count; i++) { if (codes[i].opcode == OpCodes.Ldfld && (FieldInfo)codes[i].operand == typeof(Vector2).GetField(nameof(Vector2.Y))) { SMonitor.Log("replacing Y position with method"); codes.Insert(i + 1, new CodeInstruction(OpCodes.Call, typeof(ModEntry).GetMethod(nameof(ModEntry.GetCurrentTreeY)))); i++; } if (i < codes.Count - 1 && codes[i].opcode == OpCodes.Ldc_R4 && (float)codes[i].operand == 0.0001f && codes[i + 1].opcode == OpCodes.Callvirt && (MethodInfo)codes[i + 1].operand == typeof(SpriteBatch).GetMethod(nameof(SpriteBatch.Draw), new Type[] { typeof(Texture2D), typeof(Vector2), typeof(Rectangle?), typeof(Color), typeof(float), typeof(Vector2), typeof(float), typeof(SpriteEffects), typeof(float) })) { SMonitor.Log("replacing seed layerDepth with method"); codes[i].opcode = OpCodes.Ldarg_2; codes[i].operand = null; codes.Insert(i + 1, new CodeInstruction(OpCodes.Call, typeof(ModEntry).GetMethod(nameof(ModEntry.GetCurrentTreeY)))); i++; } } return(codes.AsEnumerable()); }
public static void FarmHouse_resetLocalState_Postfix(ref FarmHouse __instance) { try { if (!Config.EnableMod) { return; } Farmer f = __instance.owner; if (f == null) { return; } foreach (var kvp in currentRoomData) { CheckSpouseThing(__instance, kvp.Value); } if (GetSpouses(f, 0).ContainsKey("Sebastian") && Game1.netWorldState.Value.hasWorldStateID("sebastianFrog")) { if (Game1.random.NextDouble() < 0.1 && Game1.timeOfDay > 610) { DelayedAction.playSoundAfterDelay("croak", 1000, null, -1); } } } catch (Exception ex) { SMonitor.Log($"Failed in {nameof(FarmHouse_resetLocalState_Postfix)}:\n{ex}", LogLevel.Error); } }
public static void DropHardwood(Tree tree, int index, int x, int y, int number, GameLocation location) { if (!dropDict.ContainsKey(tree.treeType.Value.ToString())) { Game1.createMultipleObjectDebris(index, x, y, number, location); } else { Random r; if (Game1.IsMultiplayer) { Game1.recentMultiplayerRandom = new Random(x * 1000 + y); r = Game1.recentMultiplayerRandom; } else { r = new Random((int)Game1.uniqueIDForThisGame + (int)Game1.stats.DaysPlayed + x * 7 + y * 11); } foreach (var item in dropDict[tree.treeType.Value.ToString()].hardwood) { int amount = GetDropAmount(item); if (Game1.getFarmer(AccessTools.FieldRefAccess <Tree, NetLong>(tree, "lastPlayerToHit").Value).professions.Contains(14)) { if (item.min == 0 && item.max == 0) { while (r.NextDouble() < 0.5) { amount++; } } else { amount += (int)(amount * 0.25f + 0.9f); } } amount = (int)Math.Round(amount * item.mult); if (tree.growthStage.Value > 5) { amount += (int)Math.Round(amount * Math.Min(Config.MaxDaysSizeIncrease, tree.growthStage.Value - 5) * Config.LootIncreasePerDay); } //SMonitor.Log($"Dropping {amount}x {item.id}"); if (amount <= 0) { return; } for (int i = 0; i < amount; i++) { Object obj = GetObjectFromID(item.id, 1, GetQuality(item)); if (obj == null) { SMonitor.Log($"error getting object from id {item.id}", StardewModdingAPI.LogLevel.Warn); break; } Game1.createItemDebris(obj, new Vector2(x, y) * 64, Game1.random.Next(4), location, -1); } } } }
private static void SetStats(ref Farmer instance, bool newFarmer = false) { Dictionary <string, int> skillSet = new Dictionary <string, int>(); foreach (string name in skillNames) { if (!instance.modData.TryGetValue(modDataKey + name, out string skillString) || !int.TryParse(skillString, out int skill)) { skill = Config.BaseStatValue; SetModData(instance, name, skill); } skillSet[name] = skill; } if (newFarmer || GetStatValue(instance, "exp") < 0) { SetModData(instance, "exp", 0); } int level = GetExperienceLevel(instance); instance.maxHealth = (int)Math.Max(1, level * Config.BaseHealthPerLevel * (1 + Config.ConHealthBonus * GetStatMod(skillSet["con"]))); instance.MaxStamina = (int)Math.Max(1, level * Config.BaseStaminaPerLevel * (1 + Config.ConStaminaBonus * GetStatMod(skillSet["con"]))); if (newFarmer) { instance.health = instance.maxHealth; instance.stamina = instance.MaxStamina; } SMonitor.Log($"Farmer health {instance.health}/{instance.maxHealth}, stamina {instance.stamina}/{instance.MaxStamina}"); }
private static void DropItems(Tree tree, List <ItemData> itemlist, int x, int y, GameLocation location, float mult = 1) { foreach (var item in itemlist) { int amount = (int)Math.Round(GetDropAmount(item) * mult * item.mult); if (tree.growthStage.Value > 5) { amount += (int)Math.Round(amount * Math.Min(Config.MaxDaysSizeIncrease, tree.growthStage.Value - 5) * Config.LootIncreasePerDay); } if (amount <= 0) { return; } SMonitor.Log($"Dropping {amount}x {item.id}"); for (int i = 0; i < amount; i++) { Object obj = GetObjectFromID(item.id, 1, GetQuality(item)); if (obj == null) { SMonitor.Log($"error getting object from id {item.id}", StardewModdingAPI.LogLevel.Warn); break; } Game1.createItemDebris(obj, new Vector2(x, y) * 64, Game1.random.Next(4), location, -1); } } }
private static int GetBaseWeaponSpeed(MeleeWeapon weapon, Farmer who) { int speed = 400; if (Config.EnableMod && who == Game1.player) { int speedMod = 0; var str = GetStatValue(who, "str", Config.BaseStatValue); var con = GetStatValue(who, "con", Config.BaseStatValue); var dex = GetStatValue(who, "dex", Config.BaseStatValue); switch (weapon.type.Value) { case 1: // dagger speedMod = Config.DexDaggerSpeedBonus * GetStatMod(dex); break; case 2: // club speedMod = Config.StrClubSpeedBonus * GetStatMod(str); break; case 3: // sword speedMod = Config.ConSwordSpeedBonus * GetStatMod(con); break; } SMonitor.Log($"Modifying weapon speed {speed} - {speedMod}"); speed -= speedMod; } return(speed); }
public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { SMonitor.Log($"Transpiling DayTimeMoneyBox.draw"); var codes = new List <CodeInstruction>(instructions); for (int i = 0; i < codes.Count; i++) { if (i < codes.Count - 3 && codes[i].opcode == OpCodes.Ldc_I4_S && codes[i].operand is sbyte && (sbyte)codes[i].operand == 100 && codes[i + 1].opcode == OpCodes.Rem && codes[i + 2].opcode == OpCodes.Call && codes[i + 2].operand.Equals(AccessTools.Method(typeof(StringBuilderFormatEx), nameof(StringBuilderFormatEx.AppendEx), new Type[] { typeof(StringBuilder), typeof(int) })) && codes[i + 7].opcode == OpCodes.Ldfld && (FieldInfo)codes[i + 7].operand == AccessTools.Field(typeof(DayTimeMoneyBox), "_padZeros")) { SMonitor.Log("Overriding minute display"); codes[i + 9].opcode = OpCodes.Nop; codes[i + 8].opcode = OpCodes.Nop; codes[i + 7].opcode = OpCodes.Nop; codes[i + 6].opcode = OpCodes.Nop; codes[i + 5].opcode = OpCodes.Nop; codes[i + 4].opcode = OpCodes.Nop; codes[i + 2].opcode = OpCodes.Callvirt; codes[i + 2].operand = AccessTools.Method(typeof(StringBuilder), nameof(StringBuilder.Append), new Type[] { typeof(string) }); codes.Insert(i + 2, new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ModEntry), nameof(ModEntry.GetActualMinutes)))); break; } } return(codes.AsEnumerable()); }
private static void Utility_tryToPlaceItem_Postfix(GameLocation location, Item item, int x, int y, bool __result) { if (!Config.EnableMod || !__result || (!SHelper.Input.IsDown(Config.ModButton) && !SHelper.Input.IsDown(Config.StraightModButton)) || !IsValidItem(item)) { return; } SMonitor.Log($"Planting all; straight {SHelper.Input.IsDown(Config.StraightModButton)}, full {SHelper.Input.IsDown(Config.ModButton)}"); List <Point> placeables = new List <Point>(); GetPlaceable(x / 64, y / 64, x / 64, y / 64, placeables); SMonitor.Log($"Got {placeables.Count} placeable tiles"); Vector2 start = new Vector2(x / 64, y / 64); placeables.Sort(delegate(Point p1, Point p2) { return(Vector2.Distance(start, p1.ToVector2()).CompareTo(Vector2.Distance(start, p2.ToVector2()))); }); foreach (var p in placeables) { if (!Game1.player.currentLocation.terrainFeatures.TryGetValue(p.ToVector2(), out TerrainFeature t) || t is not HoeDirt) { continue; } if (((Object)Game1.player.ActiveObject).placementAction(Game1.player.currentLocation, p.X * 64, p.Y * 64, Game1.player)) { Game1.player.reduceActiveItemByOne(); } if (!IsValidItem(Game1.player.ActiveObject) || item.ParentSheetIndex != Game1.player.ActiveObject.ParentSheetIndex) { return; } } }
private static int ChangeQuality(Crop crop, HoeDirt hoeDirt, int quality) { if (!Config.EnableMod || crop.indexOfHarvest.Value == 771 || crop.indexOfHarvest.Value == 889) { return(quality); } float factor = 0; if (Config.ColorVariationQualityFactor > 0) { if (hoeDirt.modData.TryGetValue(redVarKey, out string redVarString) && float.TryParse(redVarString, NumberStyles.Float, CultureInfo.InvariantCulture, out float redVarFloat) && hoeDirt.modData.TryGetValue(redVarKey, out string greenVarString) && float.TryParse(greenVarString, NumberStyles.Float, CultureInfo.InvariantCulture, out float greenVarFloat) && hoeDirt.modData.TryGetValue(redVarKey, out string blueVarString) && float.TryParse(blueVarString, NumberStyles.Float, CultureInfo.InvariantCulture, out float blueVarFloat) ) { factor += (redVarFloat + greenVarFloat + blueVarFloat) / 3 * Config.ColorVariationQualityFactor / 100f; } } if (Config.SizeVariationQualityFactor > 0 && hoeDirt.modData.TryGetValue(sizeVarKey, out string sizeVarString) && float.TryParse(sizeVarString, NumberStyles.Float, CultureInfo.InvariantCulture, out float sizeVarFloat)) { factor += sizeVarFloat * Config.SizeVariationQualityFactor / 100f; } var newQuality = Math.Clamp((int)Math.Round(quality + factor), 0, 4); if (newQuality == 3) { newQuality = 2; } SMonitor.Log($"Changed quality from {quality} to {newQuality}; var factor {factor}"); return(newQuality); }
private static void GetFarmHouseSpouseRooms(FarmHouse fh, List <string> orderableSpouses, out List <string> orderedSpouses, out List <string> customSpouses) { SMonitor.Log($"Getting {orderableSpouses.Count} spouse rooms"); customSpouses = new List <string>(); for (int i = orderableSpouses.Count - 1; i >= 0; i--) { if (ModEntry.customRoomData.TryGetValue(orderableSpouses[i], out SpouseRoomData srd) && !srd.islandFarmHouse && (srd.upgradeLevel == fh.upgradeLevel || srd.upgradeLevel < 0) && srd.startPos.X > -1) { SMonitor.Log($"{orderableSpouses[i]} has custom spouse room"); customSpouses.Add(orderableSpouses[i]); orderableSpouses.RemoveAt(i); } } orderedSpouses = new List <string>(); string[] roomOrder = Config.SpouseRoomOrder.Split(','); foreach (string str in roomOrder) { string s = str.Trim(); if (orderableSpouses.Contains(s)) { SMonitor.Log($"{s} has custom room order"); orderedSpouses.Add(s); orderableSpouses.Remove(s); } } foreach (string str in orderableSpouses) { SMonitor.Log($"{str} has no customization"); orderedSpouses.Add(str); Config.SpouseRoomOrder += (Config.SpouseRoomOrder.Trim().Length > 0 ? "," : "") + str; } SHelper.WriteConfig(Config); }
public static bool NPC_setUpForOutdoorPatioActivity_Prefix(NPC __instance) { if (!Config.EnableMod || outdoorAreas == null || outdoorAreas.dict.Count == 0 || !outdoorAreas.dict.ContainsKey(__instance.Name)) { if (Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth).Equals("Sat") && Game1.MasterPlayer.spouse != __instance.Name) { SMonitor.Log($"preventing {__instance.Name} from going to spouse patio"); return(false); } return(true); } Vector2 patio_location = __instance.GetSpousePatioPosition(); if (NPC.checkTileOccupancyForSpouse(Game1.getLocationFromName(outdoorAreas.dict[__instance.Name].location), patio_location, "")) { return(false); } Game1.warpCharacter(__instance, outdoorAreas.dict[__instance.Name].location, patio_location); __instance.popOffAnyNonEssentialItems(); __instance.currentMarriageDialogue.Clear(); __instance.addMarriageDialogue("MarriageDialogue", "patio_" + __instance.Name, false, new string[0]); __instance.Schedule = new Dictionary <int, SchedulePathDescription>(); __instance.setTilePosition((int)patio_location.X, (int)patio_location.Y); __instance.shouldPlaySpousePatioAnimation.Value = true; return(false); }
public static void ReplaceString(string path, ref string text, object[] subs = null, int gender = -1) { if (text.Contains("\"")) { return; } string original = text; string substring = ""; string modifiedPath; if (subs != null) { substring = "`"; for (int i = 0; i < subs.Length; i++) { substring += subs[i] + "`"; } } bool found = false; for (int i = 2; i >= 0; i--) { if (found || text.Contains("{" + i + "}")) { found = true; substring = "{" + i + "}`" + substring; } } if (substring != "") { substring = "`" + substring; } if (path.StartsWith(extraPrefix) && extraAllowed.Contains(path.Substring(extraPrefix.Length))) { modifiedPath = path.Replace(extraPrefix, extraReplacePrefix); } else if (path.StartsWith(charactersPrefix) && charactersAllowed.Contains(path.Substring(charactersPrefix.Length))) { modifiedPath = path.Replace(charactersPrefix, charactersReplacePrefix); } else if ( (path.StartsWith(NPCPrefix) && NPCAllowed.Contains(path.Substring(NPCPrefix.Length))) || (path.StartsWith(eventPrefix) && eventChanges.Contains(path.Substring(eventPrefix.Length))) || (path.StartsWith(utilityPrefix) && utilityChanges.Contains(path.Substring(utilityPrefix.Length))) ) { modifiedPath = path.Replace(CSPrefix, CSReplacePrefix); } else { return; } text = "<" + $"{modifiedPath}{substring}" + (gender > -1 ? ($"[{gender}]") : "") + ">"; var x = Environment.StackTrace; SMonitor.Log($"preparing string {original} for replacement: {text}"); }
private static bool Utility_playerCanPlaceItemHere_Prefix() { if (Config.EnableMod && (Game1.dayOfMonth != 0 || Game1.year != 1 || Game1.currentSeason != "spring")) { SMonitor.Log($"Repeating {Utility.getDateString()}"); Game1.dayOfMonth--; } }
private static void Pet_dayUpdate_Postfix(Pet __instance, bool __state, ref int ____currentBehavior) { if (__state) { SMonitor.Log("Setting pet to farm position"); WarpPetToBed(__instance, Game1.getFarm(), ref ____currentBehavior, true); } }
private static void Game1__newDayAfterFade_Prefix() { if (Config.EnableMod && (Game1.dayOfMonth != 0 || Game1.year != 1 || Game1.currentSeason != "spring")) { SMonitor.Log($"Repeating {Utility.getDateString()}"); Game1.dayOfMonth--; } }
private static void Furniture_placementAction_Postfix(Furniture __instance) { if (!Config.EnableMod) { return; } SMonitor.Log($"furniture name {__instance.Name}"); }
public static void Postfix(FarmAnimal __instance, string type, string __state) { if (!Config.EnableMod || __state == type || (!type.EndsWith("Chicken") && !type.EndsWith("Cow"))) return; SMonitor.Log($"Creating new {__state}, was {type}"); __instance.type.Value = __state; __instance.reloadData(); }
public static IEnumerable <CodeInstruction> SeedMakerMachine_SetInput_Transpiler(IEnumerable <CodeInstruction> instructions) { SMonitor.Log($"patching SeedMakerMachine_SetInput"); var codes = new List <CodeInstruction>(instructions); bool gotSeedAmount = false; bool gotAncientSeedChance = false; bool gotMixedSeedChance = false; bool gotMixedSeedAmount = false; for (int i = 0; i < codes.Count; i++) { if (codes[i].opcode == OpCodes.Ret && codes[i - 1].opcode == OpCodes.Ldc_I4_1) { break; } if (gotSeedAmount) { if (gotAncientSeedChance) { if (gotMixedSeedChance) { if (gotMixedSeedAmount) { break; } else if (codes[i].opcode == OpCodes.Ldc_I4_5 && codes[i - 1].opcode == OpCodes.Ldc_I4_1) { gotMixedSeedAmount = true; SMonitor.Log($"got mixed seed amount!"); codes[i - 1] = new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ModEntry), nameof(ModEntry.GetMinMixedSeeds))); codes[i] = new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ModEntry), nameof(ModEntry.GetMaxMixedSeeds))); } } else if (codes[i].opcode == OpCodes.Ldc_R8 && (double)codes[i].operand == 0.02) { gotMixedSeedChance = true; SMonitor.Log($"got mixed seed chance!"); codes[i] = new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ModEntry), nameof(ModEntry.GetMixedSeedChance))); } } else if (codes[i].opcode == OpCodes.Ldc_R8 && (double)codes[i].operand == 0.005) { gotAncientSeedChance = true; SMonitor.Log($"got ancient seed chance!"); codes[i] = new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ModEntry), nameof(ModEntry.GetAncientSeedChance))); } } else if (codes[i].opcode == OpCodes.Ldc_I4_4 && codes[i - 1].opcode == OpCodes.Ldc_I4_1) { gotSeedAmount = true; SMonitor.Log($"got seed amount!"); codes[i - 1] = new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ModEntry), nameof(ModEntry.GetMinSeeds))); codes[i] = new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ModEntry), nameof(ModEntry.GetMaxSeeds))); } } return(codes.AsEnumerable()); }
public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { SMonitor.Log($"Transpiling Object.placementAction"); var codes = new List <CodeInstruction>(instructions); bool found1 = false; bool found2 = false; bool found3 = false; bool found4 = false; for (int i = 0; i < codes.Count; i++) { if (i > 0 && i > 0 && i < codes.Count - 1 && codes[i - 1].opcode == OpCodes.Brfalse_S && codes[i + 1].opcode == OpCodes.Ldstr && (string)codes[i + 1].operand == "Strings\\StringsFromCSFiles:Object.cs.13060") { SMonitor.Log("adding extra check for tree blocking placement"); var ci = new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ModEntry), nameof(ModEntry.TreesBlock))); codes[i].MoveLabelsTo(ci); codes.Insert(i, codes[i - 1]); codes.Insert(i, ci); i += 2; found1 = true; } else if (!found2 && i > 0 && i < codes.Count - 6 && codes[i + 1].opcode == OpCodes.Ldstr && (string)codes[i + 1].operand == "Strings\\StringsFromCSFiles:Object.cs.13060_Fruit") { SMonitor.Log("adding extra check for fruit tree blocking placement"); codes.Insert(i, codes[i - 1]); codes.Insert(i, new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ModEntry), nameof(ModEntry.FruitTreesBlock)))); i += 2; found2 = true; } else if (!found3 && codes[i].opcode == OpCodes.Callvirt && (MethodInfo)codes[i].operand == AccessTools.Method(typeof(Object), nameof(Object.isSapling))) { SMonitor.Log("found isSapling"); found3 = true; } else if (found3 && !found4 && i < codes.Count - 110 && codes[i].opcode == OpCodes.Ldloc_0 && codes[i + 1].opcode == OpCodes.Ldfld && codes[i + 2].opcode == OpCodes.Isinst && ((Type)codes[i + 2].operand).Name == "Farm") { SMonitor.Log("adding sapling tile / map check override method"); for (int j = i; j < codes.Count - 3; j++) { if (codes[j + 3].opcode == OpCodes.Ldstr && (string)codes[j + 3].operand == "dirtyHit") { var ci = new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ModEntry), nameof(ModEntry.CanPlantAnywhere))); codes[i].MoveLabelsTo(ci); codes.Insert(i, new CodeInstruction(OpCodes.Brtrue, codes[j + 1].labels[0])); codes.Insert(i, ci); break; } } found4 = true; } if (found1 && found2 && found3 && found4) { break; } } return(codes.AsEnumerable()); }