Skip to content

Commit

Permalink
Two new mods, one unreleased
Browse files Browse the repository at this point in the history
  • Loading branch information
spacechase0 committed May 14, 2022
1 parent 78a2cbe commit 6f9839f
Show file tree
Hide file tree
Showing 9 changed files with 318 additions and 1 deletion.
14 changes: 14 additions & 0 deletions AQualityMod/AQualityMod.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\common.targets" />
<Import Project="..\SpaceShared\SpaceShared.projitems" Label="Shared" />

<PropertyGroup>
<Version>1.0.0</Version>
<TargetFramework>net5.0</TargetFramework>
<EnableHarmony>true</EnableHarmony>
</PropertyGroup>

<ItemGroup>
<Folder Include="assets\" />
</ItemGroup>
</Project>
177 changes: 177 additions & 0 deletions AQualityMod/Mod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SpaceShared;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Objects;

namespace AQualityMod
{
public class Mod : StardewModdingAPI.Mod
{
public static Mod instance;
public static Texture2D wonderfulTex, poorTex;

public override void Entry(IModHelper helper)
{
instance = this;
Log.Monitor = Monitor;

wonderfulTex = Helper.ModContent.Load<Texture2D>("assets/wonderful.png");
poorTex = Helper.ModContent.Load<Texture2D>("assets/poor.png");

var harmony = new Harmony(ModManifest.UniqueID);
harmony.PatchAll();
}
}

[HarmonyPatch(typeof(Cask), nameof(Cask.performObjectDropInAction))]
public static class CaskObjectDropInPatch
{
public static IEnumerable<CodeInstruction> Transpile(ILGenerator gen, MethodBase original, IEnumerable<CodeInstruction> insns)
{
List<CodeInstruction> ret = new();
foreach (var insn in insns)
{
if (insn.opcode == OpCodes.Ldc_I4_4)
{
insn.opcode = OpCodes.Ldc_I4_6;
}
ret.Add(insn);
}
return ret;
}
}

[HarmonyPatch(typeof(Cask), nameof(Cask.checkForMaturity))]
public static class CaskCheckMaturityPatch
{
public static IEnumerable<CodeInstruction> Transpile(ILGenerator gen, MethodBase original, IEnumerable<CodeInstruction> insns)
{
List<CodeInstruction> ret = new();
foreach (var insn in insns)
{
if (insn.opcode == OpCodes.Ldc_I4_4)
{
insn.opcode = OpCodes.Ldc_I4_6;
}
ret.Add(insn);
}
return ret;
}
}

[HarmonyPatch(typeof(Cask), nameof(Cask.GetDaysForQuality))]
public static class CaskDaysForQualityPatch
{
public static bool Prefix(int quality, ref float __result)
{
if (quality == 6)
{
__result = 14;
return false;
}
if (quality == -2)
{
__result = 70;
return false;
}

return true;
}
}

[HarmonyPatch(typeof(Cask), nameof(Cask.GetNextQuality))]
public static class CaskNextQualityPatch
{
public static bool Prefix(int quality, ref int __result)
{
if (quality == 6)
{
__result = 28; // Should this be 14 to match the pattern of vanilla?
return false;
}
if (quality == -2)
{
__result = 70;
return false;
}

return true;
}
}

[HarmonyPatch(typeof(StardewValley.Object), "_PopulateContextTags")]
public static class ObjectContextTagPatch
{
public static void Postfix(StardewValley.Object __instance, HashSet<string> tags)
{
if (__instance.Quality == 6)
tags.Add("quality_wonderful");
else if (__instance.Quality == -2)
tags.Add("quality_poor");
}
}

[HarmonyPatch(typeof(StardewValley.Object), nameof(StardewValley.Object.drawInMenu))]
public static class ObjectDrawMenuQualityPatch
{
public static void Postfix(StardewValley.Object __instance, SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, StackDrawType drawStackNumber, Color color, bool drawShadow)
{
if (__instance.Quality != 6 && __instance.Quality != -2)
return;

if (drawStackNumber != 0)
{
Microsoft.Xna.Framework.Rectangle quality_rect = new( 0, 0, 8, 8 );
Texture2D quality_sheet = __instance.Quality == 6 ? Mod.wonderfulTex : Mod.poorTex;
float yOffset = (((int)__instance.quality < 4) ? 0f : (((float)Math.Cos((double)Game1.currentGameTime.TotalGameTime.Milliseconds * Math.PI / 512.0) + 1f) * 0.05f));
spriteBatch.Draw(quality_sheet, location + new Vector2(12f, 52f + yOffset), quality_rect, color * transparency, 0f, new Vector2(4f, 4f), 3f * scaleSize * (1f + yOffset), SpriteEffects.None, layerDepth);
}
}
}

[HarmonyPatch(typeof(ColoredObject), nameof(ColoredObject.drawInMenu))]
public static class ColoredObjectDrawMenuQualityPatch
{
public static void Postfix(StardewValley.Object __instance, SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, StackDrawType drawStackNumber, Color colorOverride, bool drawShadow)
{
if (__instance.Quality != 6 && __instance.Quality != -2)
return;

if (drawStackNumber != 0)
{
Microsoft.Xna.Framework.Rectangle quality_rect = new(0, 0, 8, 8);
Texture2D quality_sheet = __instance.Quality == 6 ? Mod.wonderfulTex : Mod.poorTex;
float yOffset = (((int)__instance.quality < 4) ? 0f : (((float)Math.Cos((double)Game1.currentGameTime.TotalGameTime.Milliseconds * Math.PI / 512.0) + 1f) * 0.05f));
spriteBatch.Draw(quality_sheet, location + new Vector2(12f, 52f + yOffset), quality_rect, Color.White * transparency, 0f, new Vector2(4f, 4f), 3f * scaleSize * (1f + yOffset), SpriteEffects.None, layerDepth);
}
}
}

[HarmonyPatch(typeof(Cask), nameof(Cask.draw))]
public static class CaskDrawQualityPatch
{
public static void Postfix(Cask __instance, SpriteBatch spriteBatch, int x, int y, float alpha)
{
if (__instance.heldObject.Value != null && (int)__instance.heldObject.Value.quality > 0)
{
if (__instance.heldObject.Value.Quality != 6 && __instance.heldObject.Value.Quality != -2)
return;

Vector2 scaleFactor = (((int)__instance.minutesUntilReady > 0) ? new Vector2(Math.Abs(__instance.scale.X - 5f), Math.Abs(__instance.scale.Y - 5f)) : Vector2.Zero);
scaleFactor *= 4f;
Vector2 position = Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64, y * 64 - 64));
Rectangle destination = new Rectangle((int)(position.X + 32f - 8f - scaleFactor.X / 2f) + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), (int)(position.Y + 64f + 8f - scaleFactor.Y / 2f) + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), (int)(16f + scaleFactor.X), (int)(16f + scaleFactor.Y / 2f));
Microsoft.Xna.Framework.Rectangle quality_rect = new(0, 0, 8, 8);
Texture2D quality_sheet = __instance.Quality == 10 ? Mod.wonderfulTex : Mod.poorTex;
spriteBatch.Draw(quality_sheet, destination, quality_rect, Color.White * 0.95f, 0f, Vector2.Zero, SpriteEffects.None, (float)((y + 1) * 64) / 10000f);
}
}
}
}
Binary file added AQualityMod/assets/poor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AQualityMod/assets/wonderful.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions AQualityMod/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Name": "A Quality Mod",
"Author": "spacechase0",
"Version": "1.0.0",
"Description": "...",
"UniqueID": "spacechase0.AQualityMod",
"EntryDll": "AQualityMod.dll",
"UpdateKeys": [ "Nexus:" ]
}
82 changes: 82 additions & 0 deletions ResponsiveKnockback/Mod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Runtime.CompilerServices;
using HarmonyLib;
using Microsoft.Xna.Framework;
using Netcode;
using SpaceShared;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Monsters;

namespace ResponsiveKnockback
{
public class Mod : StardewModdingAPI.Mod
{
public static Mod instance;
public static ConditionalWeakTable<AbstractNetSerializable, Holder<bool>> sharedAuthority = new();

public override void Entry(IModHelper helper)
{
instance = this;
Log.Monitor = Monitor;

var harmony = new Harmony(ModManifest.UniqueID);
harmony.PatchAll();
}
}

[HarmonyPatch(typeof(AbstractNetSerializable), nameof(AbstractNetSerializable.MarkDirty))]
public static class ANSMarkDirtyPatch
{
public static bool Prefix(AbstractNetSerializable __instance)
{
if (!Mod.sharedAuthority.TryGetValue(__instance, out var varHolder))
return true;

if (!varHolder.Value && Game1.IsMasterGame)
return false;

return true;
}
}

[HarmonyPatch(typeof(Monster), "initNetFields")]
public static class MonsterNetFieldsPatch
{
public static void Postfix(Monster __instance)
{
Mod.sharedAuthority.Add(__instance.position.Field, new Holder<bool>() { Value = true });
}
}

[HarmonyPatch(typeof(Monster), nameof(Monster.setTrajectory))]
public static class MonsterSetTrajectoryPatch
{
public static void Postfix(Monster __instance, Vector2 trajectory)
{
if (!Game1.IsMasterGame)
{
if (Math.Abs(trajectory.X) > Math.Abs(__instance.xVelocity))
{
__instance.xVelocity = trajectory.X;
}
if (Math.Abs(trajectory.Y) > Math.Abs(__instance.yVelocity))
{
__instance.yVelocity = trajectory.Y;
}
}
}
}

[HarmonyPatch(typeof(Monster), nameof(Monster.update))]
public static class MonsterUpdatePatch
{
public static void Postfix(Monster __instance, GameTime time)
{
if (!Game1.IsMasterGame)
{
__instance.MovePosition(time, Game1.viewport, __instance.currentLocation);
}
}
}
}
10 changes: 10 additions & 0 deletions ResponsiveKnockback/ResponsiveKnockback.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\common.targets" />
<Import Project="..\SpaceShared\SpaceShared.projitems" Label="Shared" />

<PropertyGroup>
<Version>1.0.0</Version>
<TargetFramework>net5.0</TargetFramework>
<EnableHarmony>true</EnableHarmony>
</PropertyGroup>
</Project>
9 changes: 9 additions & 0 deletions ResponsiveKnockback/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Name": "Responsive Knockback",
"Author": "spacechase0",
"Version": "1.0.0",
"Description": "...",
"UniqueID": "spacechase0.ResponsiveKnockback",
"EntryDll": "ResponsiveKnockback.dll",
"UpdateKeys": [ "Nexus:" ]
}
18 changes: 17 additions & 1 deletion Spacechase0.Stardew.sln
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DyeableHats", "DyeableHats\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Designs", "Designs\Designs.csproj", "{1D6C6511-624C-4332-9E70-486F81A28888}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RaiseJunimos", "RaiseJunimos\RaiseJunimos.csproj", "{CB5BB6E2-D963-4A27-A3B9-1E4BB068983B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RaiseJunimos", "RaiseJunimos\RaiseJunimos.csproj", "{CB5BB6E2-D963-4A27-A3B9-1E4BB068983B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AQualityMod", "AQualityMod\AQualityMod.csproj", "{B5127FFB-A748-44FF-882E-5279B0F7B279}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResponsiveKnockback", "ResponsiveKnockback\ResponsiveKnockback.csproj", "{19EB9934-6F62-401B-9447-3661BAE212A0}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Expand All @@ -186,6 +190,7 @@ Global
SpaceShared\SpaceShared.projitems*{13ab4923-b6de-4872-9bb3-49e4c18f937c}*SharedItemsImports = 5
SpaceShared\SpaceShared.projitems*{157ad988-f4f3-4945-bc7e-f28181b39576}*SharedItemsImports = 5
SpaceShared\SpaceShared.projitems*{16c65e62-e346-4aea-809a-36ebc0442607}*SharedItemsImports = 5
SpaceShared\SpaceShared.projitems*{19eb9934-6f62-401b-9447-3661bae212a0}*SharedItemsImports = 5
SpaceShared\SpaceShared.projitems*{1c1289bd-f40b-4343-aa8a-4f151f887463}*SharedItemsImports = 5
SpaceShared\SpaceShared.projitems*{1c3d86aa-c048-4798-bec5-07d7269cce53}*SharedItemsImports = 5
SpaceShared\SpaceShared.projitems*{1d6c6511-624c-4332-9e70-486f81a28888}*SharedItemsImports = 5
Expand Down Expand Up @@ -244,6 +249,7 @@ Global
SpaceShared\SpaceShared.projitems*{b0bb0171-260e-40fe-95dc-4377ce916ff0}*SharedItemsImports = 5
SpaceSharedPatching\SpaceSharedPatching.projitems*{b0ef91ab-2dd6-4240-98d9-e965acf79f7c}*SharedItemsImports = 5
SpaceShared\SpaceShared.projitems*{b0ef91ab-2dd6-4240-98d9-e965acf79f7c}*SharedItemsImports = 5
SpaceShared\SpaceShared.projitems*{b5127ffb-a748-44ff-882e-5279b0f7b279}*SharedItemsImports = 5
SpaceShared\SpaceShared.projitems*{b6e809a4-263f-4912-905a-00175cfb8074}*SharedItemsImports = 5
SpaceSharedPatching\SpaceSharedPatching.projitems*{ba657cb4-93ed-4c3a-a66e-86954beb4ce6}*SharedItemsImports = 5
SpaceShared\SpaceShared.projitems*{ba657cb4-93ed-4c3a-a66e-86954beb4ce6}*SharedItemsImports = 5
Expand Down Expand Up @@ -560,6 +566,14 @@ Global
{CB5BB6E2-D963-4A27-A3B9-1E4BB068983B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB5BB6E2-D963-4A27-A3B9-1E4BB068983B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB5BB6E2-D963-4A27-A3B9-1E4BB068983B}.Release|Any CPU.Build.0 = Release|Any CPU
{B5127FFB-A748-44FF-882E-5279B0F7B279}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5127FFB-A748-44FF-882E-5279B0F7B279}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5127FFB-A748-44FF-882E-5279B0F7B279}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5127FFB-A748-44FF-882E-5279B0F7B279}.Release|Any CPU.Build.0 = Release|Any CPU
{19EB9934-6F62-401B-9447-3661BAE212A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19EB9934-6F62-401B-9447-3661BAE212A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19EB9934-6F62-401B-9447-3661BAE212A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19EB9934-6F62-401B-9447-3661BAE212A0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -584,6 +598,8 @@ Global
{695CDA6A-9398-4D71-9432-9763CC510020} = {8FEFBE16-BBBC-4EA0-829E-E5DCF15F0DFA}
{1D6C6511-624C-4332-9E70-486F81A28888} = {8FEFBE16-BBBC-4EA0-829E-E5DCF15F0DFA}
{CB5BB6E2-D963-4A27-A3B9-1E4BB068983B} = {8FEFBE16-BBBC-4EA0-829E-E5DCF15F0DFA}
{B5127FFB-A748-44FF-882E-5279B0F7B279} = {8FEFBE16-BBBC-4EA0-829E-E5DCF15F0DFA}
{19EB9934-6F62-401B-9447-3661BAE212A0} = {8FEFBE16-BBBC-4EA0-829E-E5DCF15F0DFA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {38EB01DD-BAE8-4977-9815-463F5F434FBF}
Expand Down

0 comments on commit 6f9839f

Please sign in to comment.