This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModEntry.cs
87 lines (70 loc) · 2.3 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
using Harmony;
using SpaceCore;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewModdingAPI.Utilities;
using StardewValley;
using System;
using System.Collections.Generic;
namespace XPMultiplier.Space
{
public sealed class ModConfig
{
public Dictionary<string, byte> CustomSkill = new Dictionary<string, byte>()
{
{ "spacechase0.Cooking", 1 }
};
public KeybindList ReloadKey { get; set; } = new KeybindList(SButton.F12);
}
public sealed class ModEntry : Mod
{
public override void Entry(IModHelper helper)
{
LoadConfig();
helper.Events.Input.ButtonsChanged += OnButtonsChanged;
try
{
HarmonyInstance harmony = HarmonyInstance.Create(ModManifest.UniqueID);
harmony.Patch(
original: AccessTools.Method(typeof(Skills), nameof(Skills.AddExperience)),
prefix: new HarmonyMethod(typeof(SpaceXP), nameof(SpaceXP.Prefix)));
}
catch (Exception e)
{
Monitor.Log(e.Message, LogLevel.Error);
}
helper.ConsoleCommands.Add("list_skills", "list all skills registered to SpaceCore.", ShowSkills);
}
private void ShowSkills(string command, string[] args)
{
Monitor.Log(Skills.GetSkillList().Join(x => Skills.GetSkill(x).Id, "\n"), LogLevel.Info);
}
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>();
SpaceXP.Skills = Config.CustomSkill;
}
public ModConfig Config;
}
public static class SpaceXP
{
public static Dictionary<string, byte> Skills { get; set; } = new Dictionary<string, byte>();
public static void Prefix(string skillName, ref int amt)
{
if (amt <= 0)
return;
if (Skills.ContainsKey(skillName))
{
amt *= Skills[skillName];
}
}
}
}