-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathRustExtension.cs
More file actions
207 lines (181 loc) · 8.46 KB
/
RustExtension.cs
File metadata and controls
207 lines (181 loc) · 8.46 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
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
using System;
using System.Net;
using System.Reflection;
using System.Threading.Tasks;
using Oxide.Core;
using Oxide.Core.Extensions;
using Oxide.Plugins;
namespace Oxide.Game.Rust
{
/// <summary>
/// The extension class that represents this extension
/// </summary>
public class RustExtension : Extension
{
private const string OxideRustReleaseListUrl = "https://api.github.com/repos/OxideMod/Oxide.Rust/releases";
internal static Assembly Assembly = Assembly.GetExecutingAssembly();
internal static AssemblyName AssemblyName = Assembly.GetName();
internal static VersionNumber AssemblyVersion = new VersionNumber(AssemblyName.Version.Major, AssemblyName.Version.Minor, AssemblyName.Version.Build);
internal static string AssemblyAuthors = ((AssemblyCompanyAttribute)Attribute.GetCustomAttribute(Assembly, typeof(AssemblyCompanyAttribute), false)).Company;
private static readonly WebClient WebClient = new WebClient();
private static VersionNumber LatestExtVersion = AssemblyVersion;
/// <summary>
/// Gets whether this extension is for a specific game
/// </summary>
public override bool IsGameExtension => true;
/// <summary>
/// Gets the name of this extension
/// </summary>
public override string Name => "Rust";
/// <summary>
/// Gets the author of this extension
/// </summary>
public override string Author => AssemblyAuthors;
/// <summary>
/// Gets the version of this extension
/// </summary>
public override VersionNumber Version => AssemblyVersion;
/// <summary>
/// Default game-specific references for use in plugins
/// </summary>
public override string[] DefaultReferences => new[]
{
"0Harmony", "Facepunch.Network", "Facepunch.Steamworks.Posix", "Facepunch.System", "Facepunch.UnityEngine", "Facepunch.Steamworks.Win64", "Rust.Data", "Rust.FileSystem",
"Rust.Clans", "Rust.Clans.Local", "Rust.Global", "Rust.Localization", "Rust.Platform", "Rust.Platform.Common", "Rust.Platform.Steam", "Rust.Workshop", "Rust.World",
"System.Drawing", "UnityEngine.AIModule", "UnityEngine.AssetBundleModule", "UnityEngine.CoreModule", "UnityEngine.GridModule", "UnityEngine.ImageConversionModule",
"UnityEngine.PhysicsModule", "UnityEngine.TerrainModule", "UnityEngine.TerrainPhysicsModule", "UnityEngine.UI", "UnityEngine.UIModule", "UnityEngine.UIElementsModule",
"UnityEngine.UnityWebRequestAudioModule","UnityEngine.UnityWebRequestModule", "UnityEngine.UnityWebRequestTextureModule", "UnityEngine.UnityWebRequestWWWModule",
"UnityEngine.VehiclesModule", "netstandard"
};
/// <summary>
/// List of assemblies allowed for use in plugins
/// </summary>
public override string[] WhitelistAssemblies => new[]
{
"Assembly-CSharp", "Assembly-CSharp-firstpass", "DestMath", "Facepunch.Network", "Facepunch.System", "Facepunch.UnityEngine", "mscorlib", "Oxide.Core", "Oxide.Rust",
"RustBuild", "Rust.Data", "Rust.FileSystem", "Rust.Global", "Rust.Localization","Rust.Localization", "Rust.Platform.Common", "Rust.Platform.Steam", "System", "System.Core", "UnityEngine"
};
/// <summary>
/// List of namespaces allowed for use in plugins
/// </summary>
public override string[] WhitelistNamespaces => new[]
{
"ConVar", "Dest", "Facepunch", "Network", "Oxide.Game.Rust.Cui", "ProtoBuf", "PVT", "Rust", "Steamworks", "System.Collections",
"System.Security.Cryptography", "System.Text", "System.Threading.Monitor", "UnityEngine"
};
/// <summary>
/// List of filter matches to apply to console output
/// </summary>
public static string[] Filter =
{
"alphamapResolution is clamped to the range of",
"AngryAnt Behave version",
"Floating point textures aren't supported on this device",
"HDR RenderTexture format is not supported on this platform.",
"Image Effects are not supported on this platform.",
"Missing projectileID",
"Motion vectors not supported on a platform that does not support",
"The image effect Main Camera",
"The image effect effect -",
"Unable to find shaders",
"Unsupported encoding: 'utf8'",
"Warning, null renderer for ScaleRenderer!",
"[AmplifyColor]",
"[AmplifyOcclusion]",
"[CoverageQueries] Disabled due to unsupported",
"[CustomProbe]",
"[Manifest] URI IS",
"[SpawnHandler] populationCounts"
};
/// <summary>
/// Initializes a new instance of the RustExtension class
/// </summary>
/// <param name="manager"></param>
public RustExtension(ExtensionManager manager) : base(manager)
{
}
/// <summary>
/// Loads this extension
/// </summary>
public override void Load()
{
Manager.RegisterLibrary("Rust", new Libraries.Rust());
Manager.RegisterLibrary("Command", new Libraries.Command());
Manager.RegisterLibrary("Item", new Libraries.Item());
Manager.RegisterLibrary("Player", new Libraries.Player());
Manager.RegisterLibrary("Server", new Libraries.Server());
Manager.RegisterPluginLoader(new RustPluginLoader());
WebClient.Headers["User-Agent"] = $"Oxide.Rust {Version}";
}
/// <summary>
/// Loads plugin watchers used by this extension
/// </summary>
/// <param name="directory"></param>
public override void LoadPluginWatchers(string directory)
{
}
/// <summary>
/// Called when all other extensions have been loaded
/// </summary>
public override void OnModLoad()
{
CSharpPluginLoader.PluginReferences.UnionWith(DefaultReferences);
}
/// <summary>
/// Gets latest official Oxide.Rust build version
/// </summary>
/// <param name="callback">Callback to execute.<br/>
/// First argument is the version (latest, if request was successful, current otherwise)<br/>
/// Second argument is the exception indicating fail reason. Null if request was successful.
/// </param>
public void GetLatestVersion(Action<VersionNumber, Exception> callback)
{
if (callback == null)
{
throw new ArgumentNullException(nameof(callback), "Callback cannot be null");
}
if (LatestExtVersion > AssemblyVersion)
{
callback(LatestExtVersion, null);
}
else
{
GetLatestExtensionVersion().ContinueWith(
task =>
{
if (task.Exception == null)
{
LatestExtVersion = task.Result;
}
callback(LatestExtVersion, task.Exception?.InnerException);
}
);
}
}
private async Task<VersionNumber> GetLatestExtensionVersion()
{
string json = await WebClient.DownloadStringTaskAsync(OxideRustReleaseListUrl);
if (string.IsNullOrWhiteSpace(json))
{
throw new Exception("Could not retrieve latest Oxide.Rust version from GitHub API");
}
JSON.Array releaseArray = JSON.Array.Parse(json);
JSON.Object latest = releaseArray[0].Obj;
string tag = latest.GetString("tag_name");
if (string.IsNullOrWhiteSpace(tag))
{
throw new Exception("Tag name is undefined");
}
VersionNumber tagVersion = ParseVersionNumber(tag);
return tagVersion;
}
private VersionNumber ParseVersionNumber(string versionString) // definitely needs a unification inside the VersionNumber itself
{
string[] array = versionString.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
int major = int.Parse(array[0]);
int minor = int.Parse(array[1]);
int patch = int.Parse(array[2]);
return new VersionNumber(major, minor, patch);
}
}
}