forked from aedenthorn/StardewValleyMods
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17db97a
commit de1ac72
Showing
21 changed files
with
499 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<Version>1.0.0</Version> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<EnableHarmony>true</EnableHarmony> | ||
<Platforms>AnyCPU;x64</Platforms> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Remove="i18n\default.json" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="i18n\default.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="manifest.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using HarmonyLib; | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using StardewValley; | ||
using StardewValley.Audio; | ||
using StardewValley.Extensions; | ||
using StardewValley.Network; | ||
using StardewValley.Projectiles; | ||
using System; | ||
using System.Collections.Generic; | ||
using xTile.Dimensions; | ||
using xTile.Layers; | ||
using xTile.Tiles; | ||
using Object = StardewValley.Object; | ||
using Rectangle = Microsoft.Xna.Framework.Rectangle; | ||
|
||
namespace CloseDoors | ||
{ | ||
public partial class ModEntry | ||
{ | ||
public static Dictionary<GameLocation, Dictionary<Character, Point>> doorDict = new(); | ||
[HarmonyPatch(typeof(GameLocation), nameof(GameLocation.isCollidingPosition), new Type[] { typeof(Rectangle), typeof(xTile.Dimensions.Rectangle), typeof(bool), typeof(int), typeof(bool), typeof(Character), typeof(bool), typeof(bool), typeof(bool) })] | ||
public class GameLocation_isCollidingPosition_Patch | ||
{ | ||
public static void Postfix(GameLocation __instance, Rectangle position, xTile.Dimensions.Rectangle viewport, bool isFarmer, int damagesFarmer, bool glider, Character character, bool pathfinding, bool projectile, bool ignoreCharacterRequirement) | ||
{ | ||
if (!Config.ModEnabled) | ||
return; | ||
if (!isFarmer) | ||
{ | ||
if (((character != null) ? character.controller : null) != null && character.FacingDirection % 2 == 0) | ||
{ | ||
Layer buildings_layer = __instance.map.RequireLayer("Buildings"); | ||
Point tileLocation = character.FacingDirection == 2 ? new Point(position.Center.X / 64, position.Bottom / 64) : new Point(position.Center.X / 64, position.Top / 64); | ||
if (IsDoorOpen(__instance, tileLocation)) | ||
{ | ||
if(!doorDict.TryGetValue(__instance, out var dict)) | ||
{ | ||
doorDict[__instance] = new(); | ||
dict = new(); | ||
} | ||
dict[character] = tileLocation; | ||
} | ||
else if(doorDict.TryGetValue(__instance, out var dict) && dict.TryGetValue(character, out var point) && point == (character.FacingDirection == 2 ? tileLocation + new Point(0, -2) : tileLocation + new Point(0, 2))) | ||
{ | ||
dict.Remove(character); | ||
if(TryCloseDoor(__instance, point)) | ||
{ | ||
} | ||
} | ||
else if(character.FacingDirection == 0) | ||
{ | ||
Tile tile = buildings_layer.Tiles[tileLocation.X, tileLocation.Y]; | ||
if (tile != null && tile.Properties.ContainsKey("Action")) | ||
{ | ||
__instance.openDoor(new Location(tileLocation.X, tileLocation.Y), Game1.currentLocation.Equals(__instance)); | ||
} | ||
else | ||
{ | ||
tileLocation = new Point(position.Center.X / 64, position.Top / 64); | ||
tile = buildings_layer.Tiles[tileLocation.X, tileLocation.Y]; | ||
if (tile != null && tile.Properties.ContainsKey("Action")) | ||
{ | ||
__instance.openDoor(new Location(tileLocation.X, tileLocation.Y), Game1.currentLocation.Equals(__instance)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
[HarmonyPatch(typeof(GameLocation), nameof(GameLocation.performAction), new Type[] { typeof(string[]), typeof(Farmer), typeof(Location) })] | ||
public class GameLocation_performAction_Patch | ||
{ | ||
public static void Prefix(string[] action, Farmer who, Location tileLocation) | ||
{ | ||
if (!Config.ModEnabled) | ||
return; | ||
} | ||
} | ||
[HarmonyPatch(typeof(GameLocation), nameof(GameLocation.openDoor))] | ||
public class GameLocation_openDoor_Patch | ||
{ | ||
public static void Postfix(Location tileLocation, bool playSound) | ||
{ | ||
if (!Config.ModEnabled) | ||
return; | ||
} | ||
} | ||
[HarmonyPatch(typeof(InteriorDoor), "openDoorTiles")] | ||
public class InteriorDoor_openDoorTiles_Patch | ||
{ | ||
public static bool Prefix(InteriorDoor __instance) | ||
{ | ||
|
||
if (!Config.ModEnabled) | ||
return true; | ||
return true; | ||
} | ||
public static void Postfix(InteriorDoor __instance) | ||
{ | ||
|
||
if (!Config.ModEnabled) | ||
return; | ||
} | ||
} | ||
[HarmonyPatch(typeof(GameLocation), nameof(GameLocation.checkAction))] | ||
public class GameLocation_checkAction_Patch | ||
{ | ||
public static bool Prefix(GameLocation __instance, Location tileLocation, xTile.Dimensions.Rectangle viewport, Farmer who) | ||
{ | ||
if (!Config.ModEnabled) | ||
return true; | ||
if (!string.IsNullOrEmpty(__instance.doesTileHaveProperty(tileLocation.X, tileLocation.Y, "Action", "Buildings"))) | ||
return true; | ||
var tilePoint = new Point(tileLocation.X, tileLocation.Y); | ||
if (TryCloseDoor(__instance, tilePoint)) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace CloseDoors | ||
{ | ||
public interface IBuffFrameworkAPI | ||
{ | ||
public void UpdateBuffs(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using StardewModdingAPI; | ||
using StardewModdingAPI.Utilities; | ||
using StardewValley; | ||
|
||
namespace CloseDoors | ||
{ | ||
/// <summary>The API which lets other mods add a config UI through Generic Mod Config Menu.</summary> | ||
public interface IGenericModConfigMenuApi | ||
{ | ||
/********* | ||
** Methods | ||
*********/ | ||
/**** | ||
** Must be called first | ||
****/ | ||
/// <summary>Register a mod whose config can be edited through the UI.</summary> | ||
/// <param name="mod">The mod's manifest.</param> | ||
/// <param name="reset">Reset the mod's config to its default values.</param> | ||
/// <param name="save">Save the mod's current config to the <c>config.json</c> file.</param> | ||
/// <param name="titleScreenOnly">Whether the options can only be edited from the title screen.</param> | ||
/// <remarks>Each mod can only be registered once, unless it's deleted via <see cref="Unregister"/> before calling this again.</remarks> | ||
void Register(IManifest mod, Action reset, Action save, bool titleScreenOnly = false); | ||
|
||
/// <summary>Add a key binding at the current position in the form.</summary> | ||
/// <param name="mod">The mod's manifest.</param> | ||
/// <param name="getValue">Get the current value from the mod config.</param> | ||
/// <param name="setValue">Set a new value in the mod config.</param> | ||
/// <param name="name">The label text to show in the form.</param> | ||
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param> | ||
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param> | ||
void AddKeybind(IManifest mod, Func<SButton> getValue, Action<SButton> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null); | ||
|
||
/// <summary>Add a boolean option at the current position in the form.</summary> | ||
/// <param name="mod">The mod's manifest.</param> | ||
/// <param name="getValue">Get the current value from the mod config.</param> | ||
/// <param name="setValue">Set a new value in the mod config.</param> | ||
/// <param name="name">The label text to show in the form.</param> | ||
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param> | ||
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param> | ||
|
||
/// <summary>Add a key binding list at the current position in the form.</summary> | ||
/// <param name="mod">The mod's manifest.</param> | ||
/// <param name="getValue">Get the current value from the mod config.</param> | ||
/// <param name="setValue">Set a new value in the mod config.</param> | ||
/// <param name="name">The label text to show in the form.</param> | ||
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param> | ||
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param> | ||
void AddKeybindList(IManifest mod, Func<KeybindList> getValue, Action<KeybindList> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null); | ||
|
||
void AddBoolOption(IManifest mod, Func<bool> getValue, Action<bool> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null); | ||
|
||
/// <summary>Add an integer option at the current position in the form.</summary> | ||
/// <param name="mod">The mod's manifest.</param> | ||
/// <param name="getValue">Get the current value from the mod config.</param> | ||
/// <param name="setValue">Set a new value in the mod config.</param> | ||
/// <param name="name">The label text to show in the form.</param> | ||
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param> | ||
/// <param name="min">The minimum allowed value, or <c>null</c> to allow any.</param> | ||
/// <param name="max">The maximum allowed value, or <c>null</c> to allow any.</param> | ||
/// <param name="interval">The interval of values that can be selected.</param> | ||
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param> | ||
void AddNumberOption(IManifest mod, Func<int> getValue, Action<int> setValue, Func<string> name, Func<string> tooltip = null, int? min = null, int? max = null, int? interval = null, string fieldId = null); | ||
|
||
/// <summary>Add a string option at the current position in the form.</summary> | ||
/// <param name="mod">The mod's manifest.</param> | ||
/// <param name="getValue">Get the current value from the mod config.</param> | ||
/// <param name="setValue">Set a new value in the mod config.</param> | ||
/// <param name="name">The label text to show in the form.</param> | ||
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param> | ||
/// <param name="allowedValues">The values that can be selected, or <c>null</c> to allow any.</param> | ||
/// <param name="formatAllowedValue">Get the display text to show for a value from <paramref name="allowedValues"/>, or <c>null</c> to show the values as-is.</param> | ||
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param> | ||
void AddTextOption(IManifest mod, Func<string> getValue, Action<string> setValue, Func<string> name, Func<string> tooltip = null, string[] allowedValues = null, Func<string, string> formatAllowedValue = null, string fieldId = null); | ||
|
||
/// <summary>Remove a mod from the config UI and delete all its options and pages.</summary> | ||
/// <param name="mod">The mod's manifest.</param> | ||
void Unregister(IManifest mod); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using HarmonyLib; | ||
using Microsoft.Xna.Framework; | ||
using StardewModdingAPI; | ||
using StardewValley; | ||
using StardewValley.Audio; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace CloseDoors | ||
{ | ||
public partial class ModEntry | ||
{ | ||
private static bool TryCloseDoor(GameLocation location, Point tilePoint) | ||
{ | ||
foreach (var d in location.interiorDoors.Doors) | ||
{ | ||
if (d.Position == tilePoint) | ||
{ | ||
if (!d.Value) | ||
return false; | ||
location.playSound("doorClose", Utility.PointToVector2(tilePoint), null, SoundContext.Default); | ||
d.CleanUpLocalState(); | ||
d.ResetLocalState(); | ||
location.interiorDoors[tilePoint] = false; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
private static bool IsDoorOpen(GameLocation location, Point tilePoint) | ||
{ | ||
|
||
foreach (var d in location.interiorDoors.Doors) | ||
{ | ||
if (d.Position == tilePoint) | ||
{ | ||
return d.Value; | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using StardewModdingAPI; | ||
using StardewModdingAPI.Utilities; | ||
|
||
namespace CloseDoors | ||
{ | ||
public class ModConfig | ||
{ | ||
public bool ModEnabled { get; set; } = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using HarmonyLib; | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using StardewModdingAPI; | ||
using StardewModdingAPI.Utilities; | ||
using StardewValley; | ||
using StardewValley.Network; | ||
using StardewValley.Projectiles; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace CloseDoors | ||
{ | ||
/// <summary>The mod entry point.</summary> | ||
public partial class ModEntry : Mod | ||
{ | ||
|
||
public static IMonitor SMonitor; | ||
public static IModHelper SHelper; | ||
public static ModConfig Config; | ||
|
||
public static ModEntry context; | ||
|
||
public static string CloseDoorsKey = "aedenthorn.CloseDoors"; | ||
|
||
|
||
/// <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) | ||
{ | ||
Config = Helper.ReadConfig<ModConfig>(); | ||
|
||
context = this; | ||
|
||
SMonitor = Monitor; | ||
SHelper = helper; | ||
|
||
helper.Events.GameLoop.GameLaunched += GameLoop_GameLaunched; | ||
|
||
var harmony = new Harmony(ModManifest.UniqueID); | ||
harmony.PatchAll(); | ||
|
||
} | ||
|
||
private void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameLaunchedEventArgs e) | ||
{ | ||
|
||
// get Generic Mod Config Menu's API (if it's installed) | ||
var configMenu = Helper.ModRegistry.GetApi<IGenericModConfigMenuApi>("spacechase0.GenericModConfigMenu"); | ||
if (configMenu is not null) | ||
{ | ||
|
||
// register mod | ||
configMenu.Register( | ||
mod: ModManifest, | ||
reset: () => Config = new ModConfig(), | ||
save: () => Helper.WriteConfig(Config) | ||
); | ||
|
||
configMenu.AddBoolOption( | ||
mod: ModManifest, | ||
name: () => Helper.Translation.Get("GMCM_Option_ModEnabled_Name"), | ||
getValue: () => Config.ModEnabled, | ||
setValue: value => Config.ModEnabled = value | ||
); | ||
|
||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"GMCM_Option_ModEnabled_Name": "Mod Enabled", | ||
"GMCM_Option_EatTrigger_Name": "Eat Trigger", | ||
"GMCM_Option_EatLastSeconds_Name": "Duration (s)", | ||
"GMCM_Option_TransformKey_Name": "Key Trigger", | ||
"GMCM_Option_FireKey_Name": "Fire Key", | ||
"GMCM_Option_MoveSpeed_Name": "Move Speed", | ||
"GMCM_Option_Defense_Name": "Defense", | ||
"GMCM_Option_StaminaUse_Name": "Stamina Use", | ||
"GMCM_Option_FireDamage_Name": "Fire Damage", | ||
"GMCM_Option_FireDistance_Name": "Fire Distance", | ||
"GMCM_Option_TransformSound_Name": "Transform Sound", | ||
"GMCM_Option_FireSound_Name": "Mod", | ||
"dino-form": "Dino Form", | ||
"dino-buff-description": "Speed {0}\nDefense +{1}\nDemolish\nFire Breath" | ||
} |
Oops, something went wrong.