embed plugin loader directly into the launcher
This commit is contained in:
100
PluginLoader/Data/ModPlugin.cs
Normal file
100
PluginLoader/Data/ModPlugin.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System.Reflection;
|
||||
using System.Xml.Serialization;
|
||||
using ProtoBuf;
|
||||
using Sandbox.Graphics.GUI;
|
||||
using VRage.Game;
|
||||
using VRage.GameServices;
|
||||
|
||||
namespace PluginLoader.Data;
|
||||
|
||||
[ProtoContract]
|
||||
public class ModPlugin : PluginData, ISteamItem
|
||||
{
|
||||
private bool isLegacy;
|
||||
|
||||
private string modLocation;
|
||||
|
||||
public override string Source => "Mod";
|
||||
|
||||
[ProtoMember(1)]
|
||||
[XmlArray]
|
||||
[XmlArrayItem("Id")]
|
||||
public ulong[] DependencyIds { get; set; } = new ulong[0];
|
||||
|
||||
[XmlIgnore] public ModPlugin[] Dependencies { get; set; } = new ModPlugin[0];
|
||||
|
||||
public string ModLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (modLocation != null)
|
||||
return modLocation;
|
||||
modLocation = Path.Combine(Path.GetFullPath(@"..\..\..\workshop\content\244850\"), WorkshopId.ToString());
|
||||
if (Directory.Exists(modLocation) && !Directory.Exists(Path.Combine(modLocation, "Data")))
|
||||
{
|
||||
var legacyFile = Directory.EnumerateFiles(modLocation, "*_legacy.bin").FirstOrDefault();
|
||||
if (legacyFile != null)
|
||||
{
|
||||
isLegacy = true;
|
||||
modLocation = legacyFile;
|
||||
}
|
||||
}
|
||||
|
||||
return modLocation;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Exists => Directory.Exists(ModLocation) || (isLegacy && File.Exists(modLocation));
|
||||
|
||||
[XmlIgnore] public ulong WorkshopId { get; private set; }
|
||||
|
||||
public override string Id
|
||||
{
|
||||
get => base.Id;
|
||||
set
|
||||
{
|
||||
base.Id = value;
|
||||
WorkshopId = ulong.Parse(Id);
|
||||
}
|
||||
}
|
||||
|
||||
public override Assembly GetAssembly()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override bool TryLoadAssembly(out Assembly a)
|
||||
{
|
||||
a = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
MyGuiSandbox.OpenUrl("https://steamcommunity.com/workshop/filedetails/?id=" + Id,
|
||||
UrlOpenMode.SteamOrExternalWithConfirm);
|
||||
}
|
||||
|
||||
public MyObjectBuilder_Checkpoint.ModItem GetModItem()
|
||||
{
|
||||
var modItem = new MyObjectBuilder_Checkpoint.ModItem(WorkshopId, "Steam");
|
||||
modItem.SetModData(new WorkshopItem(ModLocation));
|
||||
return modItem;
|
||||
}
|
||||
|
||||
public MyModContext GetModContext()
|
||||
{
|
||||
var modContext = new MyModContext();
|
||||
modContext.Init(GetModItem());
|
||||
modContext.Init(WorkshopId.ToString(), null, ModLocation);
|
||||
return modContext;
|
||||
}
|
||||
|
||||
private class WorkshopItem : MyWorkshopItem
|
||||
{
|
||||
public WorkshopItem(string folder)
|
||||
{
|
||||
Folder = folder;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user