-
Notifications
You must be signed in to change notification settings - Fork 3
/
ModEntry.cs
117 lines (92 loc) · 3.08 KB
/
ModEntry.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
using System;
using System.Reflection;
using HarmonyLib;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewModdingAPI.Utilities;
using StardewValley;
namespace XPMultiplier
{
public sealed class ModConfig
{
public float General { get; set; } = 1;
public float Combat { get; set; } = 1;
public float Farming { get; set; } = 1;
public float Fishing { get; set; } = 1;
public float Mining { get; set; } = 1;
public float Foraging { get; set; } = 1;
public float Luck { get; set; } = 1;
public KeybindList ReloadKey { get; set; } = new KeybindList(SButton.F9);
}
public sealed class ModEntry : Mod
{
public override void Entry(IModHelper helper)
{
LoadConfig();
helper.Events.Input.ButtonsChanged += OnButtonsChanged;
try
{
var harmony = new Harmony(ModManifest.UniqueID);
MethodInfo prefix = AccessTools.Method(typeof(Farmer), nameof(Farmer.gainExperience));
harmony.Patch(
original: AccessTools.Method(typeof(Farmer), nameof(Farmer.gainExperience)),
prefix: new HarmonyMethod(typeof(GainXP), nameof(GainXP.Prefix)));
}
catch (Exception e)
{
Monitor.Log(e.Message, LogLevel.Error);
}
}
private void OnButtonsChanged(object sender, ButtonsChangedEventArgs arg)
{
if (Config.ReloadKey.JustPressed())
{
LoadConfig();
Monitor.Log("Reload Config", LogLevel.Trace);
}
}
private void LoadConfig()
{
Config = Helper.ReadConfig<ModConfig>();
}
internal static ModConfig Config;
}
public static class GainXP
{
public static void Prefix(Farmer __instance, int which, ref int howMuch)
{
if (howMuch <= 0)
return;
if (ModEntry.Config.General <= 1)
{
switch (which)
{
case 0:
Mul(ref howMuch, ModEntry.Config.Farming);
break;
case 1:
Mul(ref howMuch, ModEntry.Config.Fishing);
break;
case 2:
Mul(ref howMuch, ModEntry.Config.Foraging);
break;
case 3:
Mul(ref howMuch, ModEntry.Config.Mining);
break;
case 4:
Mul(ref howMuch, ModEntry.Config.Combat);
break;
case 5:
Mul(ref howMuch, ModEntry.Config.Luck);
break;
}
return;
}
Mul(ref howMuch, ModEntry.Config.General);
}
private static void Mul(ref int howMuch, float by)
{
howMuch = (int)(howMuch * by);
}
}
}