示例#1
0
        public 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 mod = new ModInfo();

            mod.GameAssembly = symbols != null
                ? AppDomain.CurrentDomain.Load(assembly, symbols)
                : AppDomain.CurrentDomain.Load(assembly);

            _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);
        }
示例#2
0
        protected void InitMod <T>(Assembly assembly) where T : GameShared
        {
            var mod = new ModInfo {
                GameAssembly = assembly
            };

            _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)
            {
                var entryPointInstance = (T)Activator.CreateInstance(entryPoint);
                entryPointInstance.SetTestingCallbacks(_testingCallbacks);
                mod.EntryPoints.Add(entryPointInstance);
            }

            _mods.Add(mod);
        }