-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
LAOPLUS.cs
279 lines (244 loc) · 11.2 KB
/
LAOPLUS.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
using System;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using BepInEx.Logging;
using HarmonyLib;
using System.Collections.Generic;
using System.Net.Http;
using System.Reflection;
using LAOPLUS.Notification;
using UnityEngine;
namespace LAOPLUS
{
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
// ReSharper disable once InconsistentNaming
// ReSharper disable once ClassNeverInstantiated.Global
public class LAOPLUS : BasePlugin
{
internal new static ManualLogSource Log;
static readonly HttpClient HttpClient = new();
const string ConfigDiscordLabel = "Discord";
public static ConfigEntry<string> ConfigDiscordWebhookUrl;
public static ConfigEntry<bool> ConfigDiscordWebhookEnabled;
const string ConfigNotificationLabel = "Notification / 通知";
// public static ConfigEntry<bool> ConfigNotificationEnabled;
public static ConfigEntry<bool> ConfigUnitDropNotificationEnabled;
public static ConfigEntry<bool> ConfigEquipItemDropNotificationEnabled;
const string ConfigScrollLabel = "Scroll / スクロール";
public static ConfigEntry<float> ConfigScrollPatchMultiplier;
public static ConfigEntry<bool> ConfigPreventsScrollingOoB;
const string ConfigLobbyLabel = "Lobby / ロビー";
public static ConfigEntry<bool> ConfigPreventLobbyCameraAutoRevertEnabled;
const string ConfigBaseLabel = "Base / 基地";
public static ConfigEntry<bool> ConfigAutoPressRestartWhenRewarded;
const string ConfigLoggingLabel = "Logging / ログ";
public static ConfigEntry<bool> ConfigLoggingBattleLog;
const string ConfigOtherLabel = "Other / その他";
public static ConfigEntry<bool> ConfigInstantRerollOnPremiumLoginRewardEnabled;
public static ConfigEntry<bool> ConfigShowTheNumberOfItemsInItemTooltipEnabled;
public static ConfigEntry<bool> ConfigShowTheNumberOfItemsInExBuyModalEnabled;
static readonly List<INotificationClient> NotificationClients = new();
static void ConfigDiscordWebhookUrlChangedHandler(object sender, EventArgs e)
{
RemoveAllClientsFromNotificationClients();
if (e is not SettingChangedEventArgs newEvent)
{
return;
}
var newClient = CreateDiscordWebhookClient(
newEvent.ChangedSetting.BoxedValue.ToString()
);
AddClientToNotificationClients(newClient);
SendTestMessageToAllNotificationClients();
}
static DiscordWebhookClient CreateDiscordWebhookClient(string webhookUrl)
{
if (string.IsNullOrEmpty(webhookUrl))
{
return null;
}
try
{
var client = new DiscordWebhookClient(HttpClient, webhookUrl);
return client;
}
catch (Exception e)
{
Log.LogError($"Failed to create DiscordWebhookClient: {webhookUrl}");
Log.LogError(e.Message);
return null;
}
}
static void AddClientToNotificationClients(INotificationClient client)
{
if (client == null)
{
return;
}
try
{
NotificationClients.Add(client);
Log.LogInfo($"Notification Client Added: {client.Uri}");
}
catch (Exception e)
{
Log.LogError(e.ToString());
}
}
static void RemoveAllClientsFromNotificationClients()
{
NotificationClients.Clear();
Log.LogInfo("All Notification Clients Cleared");
}
static void SendTestMessageToAllNotificationClients()
{
Log.LogInfo($"{NotificationClients.Count} notification client(s) loaded.");
SendMessageToAllNotificationClients(
$"{MyPluginInfo.PLUGIN_NAME} v{MyPluginInfo.PLUGIN_VERSION} loaded!"
);
}
static void InitNotificationClients()
{
// Discord Webhook
var discordWebhookUrl = ConfigDiscordWebhookUrl.Value;
var discordWebhookClient = CreateDiscordWebhookClient(discordWebhookUrl);
AddClientToNotificationClients(discordWebhookClient);
SendTestMessageToAllNotificationClients();
}
public static void SendMessageToAllNotificationClients(string message)
{
NotificationClients.ForEach(w => w.SendMessageAsync(message));
}
public static void SendUnitDropNotificationToAllNotificationClients(
string unitName,
string unitLinkUrl,
string unitImageUrl
)
{
NotificationClients.ForEach(
w => w.SendUnitDropNotificationAsync(unitName, unitLinkUrl, unitImageUrl)
);
}
public static void SendItemDropNotificationToAllNotificationClients(
string itemName,
string itemDescription,
string itemLinkUrl,
string itemImageUrl
)
{
NotificationClients.ForEach(
w =>
w.SendEquipItemDropNotificationAsync(
itemName,
itemDescription,
itemLinkUrl,
itemImageUrl
)
);
}
public override void Load()
{
Log = base.Log;
Log.LogInfo($"{MyPluginInfo.PLUGIN_NAME} v{MyPluginInfo.PLUGIN_VERSION} is loaded!");
HttpClient.DefaultRequestHeaders.Add(
"User-Agent",
$"{MyPluginInfo.PLUGIN_NAME}/{MyPluginInfo.PLUGIN_VERSION}"
);
// Discord
ConfigDiscordWebhookUrl = Config.Bind(
ConfigDiscordLabel,
"Webhook URL",
"",
"Discord webhook URL"
);
ConfigDiscordWebhookUrl.SettingChanged += ConfigDiscordWebhookUrlChangedHandler;
ConfigDiscordWebhookEnabled = Config.Bind(
ConfigDiscordLabel,
"Send a notification / 通知を送信する",
true,
"Toggles whether all notifications are disabled or enabled.\n"
+ "すべての通知の無効・有効を切り替えます"
);
// Notifications / 通知
ConfigUnitDropNotificationEnabled = Config.Bind(
ConfigNotificationLabel,
"Unit Drop Notification / ユニットドロップ通知",
true,
"Toggles whether unit drop notifications are disabled or enabled.\n"
+ "ユニットドロップ通知の無効・有効を切り替えます\n"
+ "Currently only supports SS ranks. / 現在SSランクのみ対応しています"
);
ConfigEquipItemDropNotificationEnabled = Config.Bind(
ConfigNotificationLabel,
"Equip Item Drop Notification / 装備品ドロップ通知",
true,
"Toggles whether equip item drop notifications are disabled or enabled.\n"
+ "装備品ドロップ通知の無効・有効を切り替えます\n"
+ "Currently only supports SS ranks. / 現在SSランクのみ対応しています"
);
// Scroll / スクロール
ConfigScrollPatchMultiplier = Config.Bind(
ConfigScrollLabel,
"Scroll Multiplier / スクロール倍率",
6.0f,
"Wheel scroll multiplier for combatant, equipment list, etc.\n"
+ "戦闘員・装備リストなどのホイールスクロール倍率"
);
ConfigPreventsScrollingOoB = Config.Bind(
ConfigScrollLabel,
"Disable Scrolling to Out of Bounds / 範囲外へのスクロールを無効にする",
true,
"Prevents scrolling outside the bounds of items when scrolling in the list.\n"
+ "リストでのスクロール時に項目の範囲外までスクロールしないようにします"
);
// Lobby / ロビー
ConfigPreventLobbyCameraAutoRevertEnabled = Config.Bind(
ConfigLobbyLabel,
"Prevent Camera Auto Revert / カメラの自動移動を防ぐ",
false,
"Prevents the camera from returning to the center when moving the camera in the lobby.\n"
+ "ロビーでのカメラ移動時にカメラが自動で中央に戻らないようにします"
);
// Base / 基地
ConfigAutoPressRestartWhenRewarded = Config.Bind(
ConfigBaseLabel,
"Automatic restart when rewarded / 受取時自動再作動",
true,
"When you receive the production reward at the production facility in base, automatically press the restart button in the pop-up.\n"
+ "基地の生産施設にて製作報酬を受取時、自動でポップアップ内の再作動ボタンを押します"
);
// Logging / ログ
ConfigLoggingBattleLog = Config.Bind(
ConfigLoggingLabel,
"Output battle log / バトルログを出力",
false,
"Output battle log to BepinEx log output.\n" + "バトルログをBepinExのログに出力する"
);
// Other / その他
ConfigInstantRerollOnPremiumLoginRewardEnabled = Config.Bind(
ConfigOtherLabel,
"Instant Reroll on Premium Login Reward / プレミアムログインボーナスの振り直しを高速化",
true,
"Remove the animation wait when reroll the Premium Login Reward.\n"
+ "プレミアムログインボーナス振り直し時の表示待機時間を削除します"
);
ConfigShowTheNumberOfItemsInItemTooltipEnabled = Config.Bind(
ConfigOtherLabel,
"Show the Number of Items in Item Tooltip / アイテム詳細ツールチップに所持数を表示",
true,
"Show the number of items in item detail tooltip.\n"
+ "アイテム長押し時に表示される項目詳細情報にそのアイテムの所持数を表示します"
);
ConfigShowTheNumberOfItemsInExBuyModalEnabled = Config.Bind(
ConfigOtherLabel,
"Show the Number of Items in Item Exchange Modal / アイテム交換所の交換画面に所持数を表示",
true,
"Show the number of items in item exchange modal.\n"
+ "アイテム交換所の交換画面にそのアイテムの所持数を表示します"
);
InitNotificationClients();
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
}
}
}