-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpookboxPlugin.cs
More file actions
123 lines (111 loc) · 4.9 KB
/
Copy pathSpookboxPlugin.cs
File metadata and controls
123 lines (111 loc) · 4.9 KB
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
118
119
120
121
122
123
using System.Reflection;
using UnityEngine;
using ContentWarningShop;
using ContentWarningShop.Localisation;
using Spookbox.Behaviour;
using Spookbox.Settings;
using Steamworks;
using Zorro.Settings;
namespace Spookbox
{
public class SpookboxPlugin
{
public const string MOD_GUID = "xerren.cwspookbox";
public const string MOD_NAME = "Spöökbox";
public const string MOD_VER = ThisAssembly.AssemblyVersion;
private const string ASSETBUNDLE_NAME = "spookbox";
internal static string PluginDirPath => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
/// <summary>
/// Asset bundle containing all the mod's assets.
/// </summary>
internal static AssetBundle? _bundle;
/// <summary>
/// Base <see cref="ScriptableObject"/> <see cref="Item"/>. All spawned items are configured from this.
/// </summary>
internal static Item? _spookboxItem;
/// <summary>
/// The Item GUID used by the Spookbox item. Not directly used, but encoded in the dll for convenience.
/// </summary>
public const string SPOOKBOX_GUID = "91f31218-6507-4bef-928d-e76b33f44a51";
private static Callback<LobbyCreated_t> cb_onLobbyCreated;
private const string ALERT_META_GUID = "bigslapTunes";
internal static readonly SynchronisedMetadata<bool> AlertMonsters = new($"{MOD_GUID}_{ALERT_META_GUID}", true);
private const string INF_BATTERY_META_GUID = "infiniteBattery";
internal static readonly SynchronisedMetadata<bool> InfiniteBattery = new($"{MOD_GUID}_{INF_BATTERY_META_GUID}", false);
/// <summary>
/// Loads the basics of the mod, initialises the Spöökbox item.
/// </summary>
internal static void InitialisePlugin()
{
if (cb_onLobbyCreated != null)
return;
var path = Path.Join(PluginDirPath, ASSETBUNDLE_NAME);
_bundle = AssetBundle.LoadFromFile(path);
_spookboxItem = _bundle.LoadAsset<Item>("Spookbox");
_spookboxItem.itemObject.AddComponent<SpookboxBehaviour>();
_spookboxItem.SetDefaultTooltips($"{ShopLocalisation.UseGlyph} Play;{ShopLocalisation.ZoomGlyph} Select Track");
Shop.RegisterItem(_spookboxItem);
Shop.RegisterCustomDataEntries();
Mixtape.Load();
// Detect local lobby creation so we can overwrite any potential leftover settings
cb_onLobbyCreated = Callback<LobbyCreated_t>.Create(Steam_LobbyCreated);
Logger.Log($"Setup complete.");
}
/// <summary>
/// Ensures all settings are loaded.
/// </summary>
/// <remarks>
/// This is mainly important for the scenario where the player installed the mod after the game was launched,
/// as settings are not loaded into the global settings repository in that workflow.
/// </remarks>
internal static void RegisterSettings()
{
// Key bindings
RegisterGameSetting<BoomboxLocalVolumeSetting>();
RegisterGameSetting<BoomboxVolumeUpBindSetting>();
RegisterGameSetting<BoomboxVolumeDownBindSetting>();
// Mechanic settings
RegisterGameSetting<BoomboxAlertSetting>();
RegisterGameSetting<BoomboxInfiniteBatterySetting>();
RegisterGameSetting<BoomboxPriceSetting>();
// "Fake" settings
RegisterGameSetting<BoomboxOpenTracksFolderSetting>();
RegisterGameSetting<BoomboxRescanMixtapeFolderSetting>();
//
Logger.Log($"Settings registered.");
}
private static void Steam_LobbyCreated(LobbyCreated_t e)
{
if (e.m_eResult != EResult.k_EResultOK)
{
return;
}
ApplyGameSetting<BoomboxAlertSetting>();
ApplyGameSetting<BoomboxInfiniteBatterySetting>();
ApplyGameSetting<BoomboxPriceSetting>();
}
/// <summary>
/// Add a setting to <see cref="SettingsHandler"/> if an instance has not been added already.
/// </summary>
/// <typeparam name="T"></typeparam>
private static void RegisterGameSetting<T>() where T : Setting, new()
{
if (GameHandler.Instance.SettingsHandler.GetSetting<T>() == null)
{
GameHandler.Instance.SettingsHandler.AddSetting(new T());
}
}
/// <summary>
/// Force applies the current value of the setting, re-triggering its effects.
/// </summary>
/// <typeparam name="T"></typeparam>
private static void ApplyGameSetting<T>() where T : Setting, new()
{
var setting = GameHandler.Instance.SettingsHandler.GetSetting<T>();
if (setting != null)
{
setting.ApplyValue();
}
}
}
}