/// <summary> /// Check to see if any mods have loaded that we didn't catch. /// These will usually be dependencies since these get loaded automatically. /// </summary> protected virtual void CheckLoadedModList() { foreach (ModInfo mi in modList) { if (ModHost.IsModInUse(mi.path) && !loadedMods.ContainsKey(mi.identifier)) { gameManager.ConsoleWindow.WriteLine($"Found stray mod {mi.identifier}."); LoadMod(mi); } } }
public ModLoader() { Mods = new List <Mod>(); Host = new ModHost(); Core = new Core(Host); WriteBreak(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Alloy - Staxel Modding API"); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine("https://github.com/Cyral/Alloy\n"); Console.ForegroundColor = ConsoleColor.Gray; LoadMods(); }
public Core(ModHost host) { Host = host; Communicator = Host.Communicator; Instance = this; Connections = new Dictionary <Player, ClientServerConnection>(); Communicator.Chat += (player, message) => { var blob = BlobAllocator.Blob(true); blob.SetString("response", message); SendPacket(player, DataPacketKind.ConsoleResponse, blob); }; Communicator.Disconnect += (player, reason) => { // TODO: Make this better... Connections[player]._connection.Close(); }; }
public virtual bool LoadMod(ModInfo modInfo) { if (loadedMods.ContainsKey(modInfo.identifier)) { gameManager.ConsoleWindow.WriteLine($"Mod {modInfo.identifier} is already loaded."); return(false); } ModHost mod = Mod.Load(modInfo.path); try { if (mod.IsModLoaded) { if (mod.Assets.Exists("ModDefinition")) { ModDefinition modDefinition = mod.Assets.Load("ModDefinition") as ModDefinition; loadedMods.Add(modInfo.identifier, mod); modManager.mods.Add(modInfo.identifier, modDefinition); gameManager.ConsoleWindow.WriteLine($"Loaded mod {modInfo.identifier}."); CheckLoadedModList(); return(true); } throw new Exception($"No ModDefinition found."); } throw new Exception($"{mod.LoadResult.Error}"); }catch (Exception e) { gameManager.ConsoleWindow.WriteLine($"Failed loading mod {modInfo.identifier}: {e.Message}"); if (mod.IsModLoaded) { mod.UnloadMod(); } CheckLoadedModList(); return(false); } }
public Mod(ModHost host) { Host = host; IsEnabled = true; }
public TestMod(ModHost host) : base(host) { }