-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
55 lines (48 loc) · 1.5 KB
/
Plugin.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
using BepInEx;
using BepInEx.Configuration;
using BepInEx.IL2CPP;
using BepInEx.Logging;
using BestHTTP;
using Il2CppSystem;
using EventArgs = System.EventArgs;
namespace HttpProxy
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BasePlugin
{
static ManualLogSource _log;
static ConfigEntry<string> _configHttpProxyURL;
public override void Load()
{
_log = Log;
_log.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
_configHttpProxyURL = Config.Bind(
"Proxy",
"HTTP Proxy URL",
"http://localhost:8888",
"A HTTP Proxy URL. If empty, no proxy will be used."
);
_configHttpProxyURL.SettingChanged += OnConfigChanged;
InitProxy();
}
static void InitProxy()
{
if (string.IsNullOrEmpty(_configHttpProxyURL.Value))
{
_log.LogInfo("No proxy will be used.");
HTTPManager.Proxy = null;
return;
}
_log.LogInfo($"Using proxy {_configHttpProxyURL.Value}.");
HTTPManager.Proxy = new HTTPProxy(new Uri(_configHttpProxyURL.Value));
}
static void OnConfigChanged(object sender, EventArgs e)
{
if (e is not SettingChangedEventArgs)
{
return;
}
InitProxy();
}
}
}