public void LoadGameAssembly <T>(string diskPath)
            where T : GameShared
        {
            // TODO: Re-enable type check when it's not just a giant pain in the butt.
            // It slows down development too much and we need other things like System.Type fixed
            // before it can reasonably be re-enabled.
            AssemblyTypeChecker.DisableTypeCheck = true;
            AssemblyTypeChecker.DumpTypes        = true;
            if (!AssemblyTypeChecker.CheckAssembly(File.ReadAllBytes(diskPath)))
            {
                return;
            }

            var mod = new ModInfo();

            mod.GameAssembly = Assembly.LoadFrom(diskPath);

            _reflectionManager.LoadAssemblies(mod.GameAssembly);

            var entryPoints = mod.GameAssembly.GetTypes().Where(t => typeof(T).IsAssignableFrom(t)).ToArray();

            if (entryPoints.Length == 0)
            {
                Logger.WarningS("res", $"Assembly has no entry points: {mod.GameAssembly.FullName}");
            }

            foreach (var entryPoint in entryPoints)
            {
                mod.EntryPoints.Add(Activator.CreateInstance(entryPoint) as T);
            }

            _mods.Add(mod);
        }
Beispiel #2
0
        public virtual void LoadGameAssembly<T>(Stream assembly, Stream? symbols = null)
            where T : GameShared
        {
            // TODO: Re-enable type check when it's not just a giant pain in the butt.
            // It slows down development too much and we need other things like System.Type fixed
            // before it can reasonably be re-enabled.
            AssemblyTypeChecker.DisableTypeCheck = true;
            AssemblyTypeChecker.DumpTypes = false;
            if (!AssemblyTypeChecker.CheckAssembly(assembly))
                return;

            assembly.Position = 0;

            Assembly gameAssembly;
            if (_useLoadContext)
            {
                gameAssembly = _loadContext.LoadFromStream(assembly, symbols);
            }
            else
            {
                gameAssembly = Assembly.Load(assembly.CopyToArray(), symbols?.CopyToArray());
            }

            InitMod<T>(gameAssembly);
        }
Beispiel #3
0
        public virtual void LoadGameAssembly <T>(string diskPath)
            where T : GameShared
        {
            // TODO: Re-enable type check when it's not just a giant pain in the butt.
            // It slows down development too much and we need other things like System.Type fixed
            // before it can reasonably be re-enabled.
            AssemblyTypeChecker.DisableTypeCheck = true;
            AssemblyTypeChecker.DumpTypes        = false;

            if (!AssemblyTypeChecker.CheckAssembly(diskPath))
            {
                return;
            }

            Assembly assembly;

            if (_useLoadContext)
            {
                assembly = _loadContext.LoadFromAssemblyPath(diskPath);
            }
            else
            {
                assembly = Assembly.LoadFrom(diskPath);
            }
            InitMod <T>(assembly);
        }
Beispiel #4
0
        public virtual void LoadGameAssembly <T>(string diskPath)
            where T : GameShared
        {
            // TODO: Re-enable type check when it's not just a giant pain in the butt.
            // It slows down development too much and we need other things like System.Type fixed
            // before it can reasonably be re-enabled.
            AssemblyTypeChecker.DisableTypeCheck = true;
            AssemblyTypeChecker.DumpTypes        = true;
            if (!AssemblyTypeChecker.CheckAssembly(File.ReadAllBytes(diskPath)))
            {
                return;
            }

            InitMod <T>(Assembly.LoadFrom(diskPath));
        }
Beispiel #5
0
        public virtual void LoadGameAssembly <T>(byte[] assembly, byte[] symbols = null)
            where T : GameShared
        {
            // TODO: Re-enable type check when it's not just a giant pain in the butt.
            // It slows down development too much and we need other things like System.Type fixed
            // before it can reasonably be re-enabled.
            AssemblyTypeChecker.DisableTypeCheck = true;
            AssemblyTypeChecker.DumpTypes        = true;
            if (!AssemblyTypeChecker.CheckAssembly(assembly))
            {
                return;
            }

            var gameAssembly = symbols != null
                ? AppDomain.CurrentDomain.Load(assembly, symbols)
                : AppDomain.CurrentDomain.Load(assembly);

            InitMod <T>(gameAssembly);
        }