/// <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);
         }
     }
 }
예제 #2
0
        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();
        }
예제 #3
0
파일: Core.cs 프로젝트: Cyral/Staxel-Alloy
        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);
            }
        }
예제 #5
0
 public Mod(ModHost host)
 {
     Host      = host;
     IsEnabled = true;
 }
예제 #6
0
 public TestMod(ModHost host) : base(host)
 {
 }