コード例 #1
0
ファイル: LoadMod.cs プロジェクト: Ephoie/EmpyrionWebAccess
        public void Game_Start(ModGameAPI dediAPI)
        {
            mDllNamesFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(GetType()).Location), "DllNames.txt");
            mGameAPI          = dediAPI;
            try
            {
                mGameAPI.Console_Write($"LoadMod(start): {mDllNamesFileName}");

                mAssemblyFileNames = File.ReadAllLines(mDllNamesFileName)
                                     .Select(L => L.Trim())
                                     .Where(L => !string.IsNullOrEmpty(L) && !L.StartsWith("#"))
                                     .ToArray();

                Array.ForEach(mAssemblyFileNames, LoadAssembly);

                if (mModInstance.Count == 1)
                {
                    mSingleModInstance = mModInstance.First();
                }

                mGameAPI.Console_Write($"LoadMod(finish:{mModInstance.Count}): {mDllNamesFileName}");
            }
            catch (Exception Error)
            {
                mGameAPI.Console_Write($"LoadMod: {mDllNamesFileName} -> {Error}");
            }
        }
コード例 #2
0
 private async Task SaveApiCall(Action aCall, ModInterface aMod, string aErrorInfo)
 {
     try
     {
         await Task.Run(aCall);
     }
     catch (Exception Error)
     {
         GameAPI.Console_Write($"Exception [{aMod}] {aErrorInfo} => {Error}");
     }
 }
コード例 #3
0
        private async Task SafeApiCall(Action aCall, ModInterface aMod, string aErrorInfo)
        {
            try
            {
                void SafeCall()
                {
                    try
                    {
                        aCall();
                    }
                    catch (Exception error)
                    {
                        GameAPI.Console_Write($"Exception [{aMod}] {aErrorInfo} => {error}");
                    }
                }

                await Task.Run(() => SafeCall());
            }
            catch (Exception Error)
            {
                GameAPI.Console_Write($"Exception [{aMod}] {aErrorInfo} => {Error}");
            }
        }
コード例 #4
0
ファイル: SimulationHost.cs プロジェクト: Lyceq/empyrion-dse
        public void Start()
        {
            switch (this.State)
            {
            case SimulationState.Paused:
                this.State = SimulationState.Running;
                break;

            case SimulationState.Stopped:
                this.State = SimulationState.Running;

                // Instantiate mods.
                foreach (ModDetails mod in this.Mods.Values)
                {
                    if (!string.IsNullOrEmpty(mod.LoadError))
                    {
                        continue;
                    }

                    try
                    {
                        foreach (Type type in mod.ModTypes)
                        {
                            object instance = mod.Assembly.CreateInstance(type.FullName);
                            this.ModInstances.Add(instance);
                            if (instance is IMod)
                            {
                                IMod i = (IMod)instance;
                                i.Init(this.IModApi);
                                if (this.IModInstanceLoaded != null)
                                {
                                    this.IModInstanceLoaded(this, i);
                                }
                            }

                            if (instance is ModInterface)
                            {
                                ModInterface i = (ModInterface)instance;
                                i.Game_Start(this.ModGameAPI);
                                if (this.ModInterfaceLoaded != null)
                                {
                                    this.ModInterfaceLoaded(this, i);
                                }
                            }
                        }
                    } catch (Exception ex)
                    {
                        Log.Warn($"Failed to load module {mod.ShortName}. {ex.Message}");
                    }
                }

                // Notify mods of any existing playfields.
                this.IApplication.TriggerPlayfieldLoaded();

                this.GameLoop              = new Thread(this.SimulatedGameLoop);
                this.GameLoop.Name         = "Empyrion Simulation Game Loop";
                this.GameLoop.IsBackground = true;
                this.GameLoop.Start();
                break;
            }
        }