-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyPlugin.cs
97 lines (81 loc) · 3.6 KB
/
MyPlugin.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
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using AnimateOnTwos.Patches;
using Reptile;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.IO;
namespace AnimateOnTwos
{
[BepInPlugin(MyGUID, PluginName, VersionString)]
public class AnimateOnTwosPlugin : BaseUnityPlugin
{
private const string MyGUID = "com.cspotcode.AnimateOnTwos";
private const string PluginName = "AnimateOnTwos";
private const string VersionString = "1.0.0";
// Config
internal static int PlayerTargetFps = 24;
internal static int PedestrianTargetFps = 8;
public static string PlayerTargetFpsConfigKey = "Player animation fps";
public static string PedestrianTargetFpsConfigKey = "Pedestrian animation fps";
public static ConfigEntry<int> PlayerTargetFpsConfig;
public static ConfigEntry<int> PedestrianTargetFpsConfig;
private Harmony harmony;
public static Player player;
internal static ConditionalWeakTable<Player, AnimatorPatchState> PlayerPatchStates = new ConditionalWeakTable<Player, AnimatorPatchState>();
internal static ConditionalWeakTable<Pedestrian, AnimatorPatchState> PedestrianPatchStates = new ConditionalWeakTable<Pedestrian, AnimatorPatchState>();
internal static HashSet<Pedestrian> Pedestrians = new HashSet<Pedestrian>();
private FileSystemWatcher ConfigFileWatcher;
private object ConfigFileChangedLock = new object();
private bool ConfigDirty = false;
private void Awake()
{
harmony = new Harmony(MyGUID);
PlayerTargetFpsConfig = Config.Bind("General",
PlayerTargetFpsConfigKey,
PlayerTargetFps,
new ConfigDescription("Set to zero to disable effect",
new AcceptableValueRange<int>(0, 60)));
PedestrianTargetFpsConfig= Config.Bind("General",
PedestrianTargetFpsConfigKey,
PedestrianTargetFps,
new ConfigDescription("Set to zero to disable effect",
new AcceptableValueRange<int>(0, 60)));
PlayerTargetFpsConfig.SettingChanged += ConfigSettingChanged;
PedestrianTargetFpsConfig.SettingChanged += ConfigSettingChanged;
ConfigFileWatcher = new FileSystemWatcher
{
Path = Path.GetDirectoryName(Config.ConfigFilePath),
Filter = Path.GetFileName(Config.ConfigFilePath),
// NotifyFilter = NotifyFilters.Attributes | NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.CreationTime
};
ConfigFileWatcher.Changed += ConfigSettingChanged;
ConfigFileWatcher.EnableRaisingEvents = true;
ReloadConfig();
harmony.PatchAll(typeof(PlayerPatch));
harmony.PatchAll(typeof(PedestrianPatch));
}
private void ConfigSettingChanged(object sender, System.EventArgs e) {
lock(ConfigFileChangedLock) {
ConfigDirty = true;
}
}
private void ReloadConfig() {
lock(ConfigFileChangedLock) {
Config.Reload();
PlayerTargetFps = (int)PlayerTargetFpsConfig.BoxedValue;
PedestrianTargetFps = (int)PedestrianTargetFpsConfig.BoxedValue;
ConfigDirty = false;
}
}
private void Update() {
if(ConfigDirty) {
ReloadConfig();
}
PedestrianPatch.Update();
}
}
}