Skip to content

Commit

Permalink
Change the way plugin DLLs are loaded to allow multiple clients on lo…
Browse files Browse the repository at this point in the history
…cal machine
  • Loading branch information
silentbaws committed Nov 19, 2020
1 parent db520ca commit 380dd6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ExamplePlugin/Info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"Name": "Awesome Example Mod",
"AssemblyName": "ExamplePlugin.dll",
"StartupMethod": "ExamplePlugin.Main:Load",
"ServerVersion": "0.9.2",
"ServerVersion": "0.11.0",
"DependencyZIP": "ExampleClientPlugin.zip"
}
9 changes: 5 additions & 4 deletions XLMultiplayer/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ public static void LoadPlugins() {

foreach (string folder in Directory.GetDirectories(pluginDirectory)) {
if(!Main.pluginList.Where(p => p.path == folder).Any()) {
string infoFile = Path.Combine(folder, "Info.json");
if (File.Exists(infoFile)) {
Plugin newPlugin = JsonConvert.DeserializeObject<Plugin>(File.ReadAllText(infoFile));
string infoFile = Path.Combine(folder, "Info.json");
if (File.Exists(infoFile)) {
Plugin newPlugin = JsonConvert.DeserializeObject<Plugin>(File.ReadAllText(infoFile));
UnityModManager.Logger.Log(newPlugin.path);
pluginList.Add(new Plugin(newPlugin.dllName, newPlugin.startMethod, folder, SendMessageFromPlugin));

Expand All @@ -223,7 +223,8 @@ public static void LoadPlugins() {
// TODO: Add log statements
string targetDLLFile = Path.Combine(plugin.path, plugin.dllName);
if (!File.Exists(targetDLLFile)) continue;
var loadedDLL = Assembly.LoadFile(targetDLLFile);
byte[] dllContents = File.ReadAllBytes(targetDLLFile);
var loadedDLL = Assembly.Load(dllContents);

Traverse.Create(plugin).Property("loadedDLL").SetValue(loadedDLL);

Expand Down

0 comments on commit 380dd6e

Please sign in to comment.