-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathMod.cs
218 lines (195 loc) · 8.08 KB
/
Mod.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
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 interface IApi
{
public bool IsPoorQuality(StardewValley.Object obj);
public bool IsWonderfulQuality(StardewValley.Object obj);
public void MakePoorQuality(StardewValley.Object obj);
public void MakeWonderfulQuality(StardewValley.Object obj);
}
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();
}
public override object GetApi(IModInfo mod)
{
return new Api();
}
}
public class Api : IApi
{
public bool IsPoorQuality(StardewValley.Object obj)
{
return obj.Quality == -2;
}
public bool IsWonderfulQuality(StardewValley.Object obj)
{
return obj.Quality == 6;
}
public void MakePoorQuality(StardewValley.Object obj)
{
obj.Quality = -2;
}
public void MakeWonderfulQuality(StardewValley.Object obj)
{
obj.Quality = 6;
}
}
[HarmonyPatch(typeof(Cask), nameof(Cask.performObjectDropInAction))]
public static class CaskObjectDropInPatch
{
public static IEnumerable<CodeInstruction> Transpiler(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> Transpiler(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 = 0;
return false;
}
if (quality == 4)
{
__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 == 4)
{
__result = 6;
return false;
}
if (quality == -2)
{
__result = 0;
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.heldObject.Value.Quality == 6 ? Mod.wonderfulTex : Mod.poorTex;
spriteBatch.Draw(quality_sheet, destination, quality_rect, Color.White * 0.95f, 0f, Vector2.Zero, SpriteEffects.None, (float)((y + 1) * 64 + 1) / 10000f);
}
}
}
}