-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
81 lines (69 loc) · 2.63 KB
/
Program.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
using StardewModdingAPI;
using System;
using StardewModdingAPI.Events;
namespace Starbot
{
public class Mod : StardewModdingAPI.Mod
{
internal static Mod instance;
internal static Random RNG = new Random(Guid.NewGuid().GetHashCode());
internal static bool BotActive = false;
internal static Input2 Input = new Input2();
public override void Entry(IModHelper helper)
{
instance = this;
//Input.Setup();
Helper.Events.Input.ButtonPressed += Input_ButtonPressed;
Helper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked;
Helper.Events.Multiplayer.ModMessageReceived += Routing.Multiplayer_ModMessageReceived;
}
private void GameLoop_UpdateTicked(object sender, UpdateTickedEventArgs e)
{
if (!BotActive) return;
Core.Update();
if (Core.WantsToStop)
{
Monitor.Log("Bot is going to stop itself to prevent further complications.", LogLevel.Warn);
ToggleBot();
}
}
private void Input_ButtonPressed(object sender, ButtonPressedEventArgs e)
{
bool shifting = false;
if (e.IsDown(SButton.LeftShift)) shifting = true;
if (e.IsDown(SButton.RightShift)) shifting = true;
//prevent vanilla from disabling the input simulator on esc key down
if (BotActive && e.IsDown(SButton.Escape)) Helper.Input.Suppress(SButton.Escape);
//bot toggle hotkey
if (e.Button == SButton.B && shifting)
{
if (!Context.IsWorldReady && !BotActive)
{
Monitor.Log("Cannot toggle bot in current game state.", LogLevel.Warn);
return;
}
Helper.Input.Suppress(SButton.B);
ToggleBot();
}
else if(e.Button == SButton.F)
{
Monitor.Log("Player location: " + StardewValley.Game1.player.currentLocation.NameOrUniqueName + ", " + StardewValley.Game1.player.getTileX() + ", " + StardewValley.Game1.player.getTileY());
}
}
private void ToggleBot()
{
BotActive = !BotActive;
Monitor.Log("Toggled bot status. Bot is now " + (BotActive ? "ON." : "OFF."), LogLevel.Warn);
if (!BotActive)
{
Input.UninstallSimulator();
Core.ReleaseKeys();
}
else
{
Input.InstallSimulator();
Core.Reset();
}
}
}
}