-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathCustomCaskModEntry.cs
87 lines (76 loc) · 3.85 KB
/
CustomCaskModEntry.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 System;
using HarmonyLib;
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Objects;
using SObject = StardewValley.Object;
namespace CustomCaskMod
{
/// <summary>The mod entry class loaded by SMAPI.</summary>
public class CustomCaskModEntry : Mod
{
internal static DataLoader DataLoader { get; set; }
internal static IMonitor ModMonitor { get; set; }
internal new static IModHelper Helper { get; set; }
/*********
** Public methods
*********/
/// <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)
{
ModMonitor = Monitor;
Helper = helper;
helper.Events.GameLoop.GameLaunched += OnGameLaunched;
helper.Events.GameLoop.UpdateTicking += OnGameLoopOnUpdateTicking;
helper.Events.GameLoop.SaveLoaded += OnSaveLoaded;
Helper.ConsoleCommands.Add("config_reload_contentpacks_customcaskmod", "Reload all content packs for custom cask mod.", DataLoader.LoadContentPacksCommand);
}
private void OnGameLoopOnUpdateTicking(object sender, UpdateTickingEventArgs args)
{
if (args.Ticks != 120) return;
DataLoader.LoadContentPacksCommand();
Helper.Events.GameLoop.UpdateTicking -= OnGameLoopOnUpdateTicking;
}
/*********
** Private methods
*********/
/// <summary>Raised after the game is launched, right before the first update tick. This happens once per game session (unrelated to loading saves). All mods are loaded and initialized at this point, so this is a good time to set up mod integrations.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event data.</param>
private void OnGameLaunched(object sender, GameLaunchedEventArgs e)
{
DataLoader = new DataLoader(Helper, ModManifest);
var harmony = new Harmony("Digus.CustomCaskMod");
harmony.Patch(
original: AccessTools.Method(typeof(Cask), nameof(Cask.IsValidCaskLocation)),
prefix: new HarmonyMethod(typeof(CaskOverrides), nameof(CaskOverrides.IsValidCaskLocation)) { priority = Priority.VeryHigh }
);
harmony.Patch(
original: AccessTools.Method(typeof(Cask), nameof(Cask.checkForMaturity)),
prefix: new HarmonyMethod(typeof(CaskOverrides), nameof(CaskOverrides.checkForMaturity)) { priority = Priority.VeryHigh }
);
harmony.Patch(
original: AccessTools.Method(typeof(SObject), nameof(SObject.placementAction)),
prefix: new HarmonyMethod(typeof(CaskOverrides), nameof(CaskOverrides.placementAction))
);
harmony.Patch(
original: AccessTools.Method(typeof(Cask), nameof(Cask.performToolAction)),
transpiler: new HarmonyMethod(typeof(CaskOverrides), nameof(CaskOverrides.performToolAction_Transpiler))
);
harmony.Patch(
original: AccessTools.Method(typeof(SObject), nameof(SObject.TryApplyFairyDust)),
prefix: new HarmonyMethod(typeof(CaskOverrides), nameof(CaskOverrides.TryApplyFairyDust)) { priority = Priority.HigherThanNormal }
);
}
/// <summary>Raised after the player loads a save slot and the world is initialized.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event data.</param>
public static void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
{
DataLoader.LoadContentPacksCommand();
}
}
}