private void OnProgramTermination(ScriptTerminationReason reason) { m_terminationReason = reason; m_instance = null; m_assembly = null; m_echoOutput.Clear(); m_previousRunTimestamp = 0; }
private void OnProgramTermination(ScriptTerminationReason reason) { m_terminationReason = reason; m_instance = null; m_assembly = null; m_echoOutput.Clear(); m_runtime.Reset(); }
private void CompileAndCreateInstance(string program, string storage) { if (MySession.Static.EnableIngameScripts == false) { return; } m_terminationReason = ScriptTerminationReason.None; try { Assembly temp = null; MyGuiScreenEditor.CompileProgram(program, m_compilerErrors, ref temp); if (temp != null) { m_assembly = IlInjector.InjectCodeToAssembly("IngameScript_safe", temp, typeof(IlInjector).GetMethod("CountInstructions", BindingFlags.Public | BindingFlags.Static), typeof(IlInjector).GetMethod("CountMethodCalls", BindingFlags.Public | BindingFlags.Static)); var type = m_assembly.GetType("Program"); if (type != null) { m_instance = FormatterServices.GetUninitializedObject(type) as IMyGridProgram; var constructor = type.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null); string response; if (m_instance == null || constructor == null) { response = MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Exception_NoValidConstructor); SetDetailedInfo(response); return; } m_runtime.Reset(); m_instance.Runtime = m_runtime; m_instance.Storage = storage; m_instance.Me = this; m_instance.Echo = EchoTextToDetailInfo; RunSandboxedProgramAction(p => { constructor.Invoke(p, null); if (!m_instance.HasMainMethod) { if (m_echoOutput.Length > 0) { response = m_echoOutput.ToString(); } response = MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Exception_NoMain); OnProgramTermination(ScriptTerminationReason.NoEntryPoint); } }, out response); SetDetailedInfo(response); } } } catch (Exception ex) { string response = MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Exception_ExceptionCaught) + ex.Message; SetDetailedInfo(response); } }
private void CompileAndCreateInstance(string program, string storage) { if (MySession.Static.EnableIngameScripts == false) { return; } m_terminationReason = ScriptTerminationReason.None; try { Assembly temp = null; MyGuiScreenEditor.CompileProgram(program, m_compilerErrors, ref temp); if (temp != null) { m_assembly = IlInjector.InjectCodeToAssembly("IngameScript_safe", temp, typeof(IlInjector).GetMethod("CountInstructions", BindingFlags.Public | BindingFlags.Static), typeof(IlInjector).GetMethod("CountMethodCalls", BindingFlags.Public | BindingFlags.Static)); var type = m_assembly.GetType("Program"); if (type != null) { try { using (IlInjector.BeginRunBlock(MAX_NUM_EXECUTED_INSTRUCTIONS, MAX_NUM_METHOD_CALLS)) { m_instance = Activator.CreateInstance(type) as IMyGridProgram; } if (m_instance != null) { m_previousRunTimestamp = 0; m_instance.Storage = storage; m_instance.Me = this; m_instance.Echo = EchoTextToDetailInfo; } } catch (TargetInvocationException ex) { if (ex.InnerException != null) { string response = MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Exception_ExceptionCaught) + ex.InnerException.Message; if (DetailedInfo.ToString() != response) { MyMultiplayer.RaiseEvent(this, x => x.WriteProgramResponse, response); } } } } } } catch (Exception ex) { string response = MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Exception_ExceptionCaught) + ex.Message; if (DetailedInfo.ToString() != response) { MyMultiplayer.RaiseEvent(this, x => x.WriteProgramResponse, response); } } }
private void CompileAndCreateInstance(string program, string storage) { if (MySession.Static.EnableIngameScripts == false) { return; } m_terminationReason = ScriptTerminationReason.None; try { if (MyFakes.ENABLE_ROSLYN_SCRIPTS) { #if !XB1 m_assembly = MyScriptCompiler.Static.Compile( MyApiTarget.Ingame, Path.Combine(MyFileSystem.UserDataPath, GetAssemblyName()), MyScriptCompiler.Static.GetIngameScript(program, "Program", typeof(MyGridProgram).Name), m_compilerMessages).Result; m_compilerErrors.Clear(); m_compilerErrors.AddRange(m_compilerMessages.Select(m => m.Text)); CreateInstance(m_assembly, m_compilerErrors, storage); #else // XB1 #if !XB1_SKIPASSERTFORNOW System.Diagnostics.Debug.Assert(false, "No scripts on XB1"); #endif // !XB1_SKIPASSERTFORNOW #endif // XB1 } else { Assembly temp = null; MyGuiScreenEditor.CompileProgram(program, m_compilerErrors, ref temp); if (temp != null) { #if !XB1 // XB1_NOILINJECTOR m_assembly = IlInjector.InjectCodeToAssembly("IngameScript_safe", temp, typeof(IlInjector).GetMethod("CountInstructions", BindingFlags.Public | BindingFlags.Static), typeof(IlInjector).GetMethod("CountMethodCalls", BindingFlags.Public | BindingFlags.Static)); #else // XB1 System.Diagnostics.Debug.Assert(false, "No scripts on XB1"); return; #endif // XB1 CreateInstance(m_assembly, m_compilerErrors, storage); } } } catch (Exception ex) { string response = MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Exception_ExceptionCaught) + ex.Message; SetDetailedInfo(response); } }
private void CompileAndCreateInstance(string program, string storage) { if (MySession.Static.EnableIngameScripts == false) { return; } m_terminationReason = ScriptTerminationReason.None; try { if (MyFakes.ENABLE_ROSLYN_SCRIPTS) { m_assembly = MyScriptCompiler.Static.Compile( MyApiTarget.Ingame, Path.Combine(MyFileSystem.UserDataPath, GetAssemblyName()), MyScriptCompiler.Static.GetIngameScript(program, "Program", typeof(MyGridProgram).Name), m_compilerMessages).Result; m_compilerErrors.Clear(); m_compilerErrors.AddRange(m_compilerMessages.Select(m => m.Text)); CreateInstance(m_assembly, m_compilerErrors, storage); } else { Assembly temp = null; MyGuiScreenEditor.CompileProgram(program, m_compilerErrors, ref temp); if (temp != null) { m_assembly = IlInjector.InjectCodeToAssembly("IngameScript_safe", temp, typeof(IlInjector).GetMethod("CountInstructions", BindingFlags.Public | BindingFlags.Static), typeof(IlInjector).GetMethod("CountMethodCalls", BindingFlags.Public | BindingFlags.Static)); CreateInstance(m_assembly, m_compilerErrors, storage); } } } catch (Exception ex) { string response = MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Exception_ExceptionCaught) + ex.Message; SetDetailedInfo(response); } }
private void CompileAndCreateInstance(string program,string storage) { if (MySession.Static.EnableIngameScripts == false) { return; } m_terminationReason = ScriptTerminationReason.None; try { Assembly temp = null; MyGuiScreenEditor.CompileProgram(program, m_compilerErrors, ref temp); if (temp != null) { m_assembly = IlInjector.InjectCodeToAssembly("IngameScript_safe", temp, typeof(IlInjector).GetMethod("CountInstructions", BindingFlags.Public | BindingFlags.Static), typeof(IlInjector).GetMethod("CountMethodCalls", BindingFlags.Public | BindingFlags.Static)); var type = m_assembly.GetType("Program"); if (type != null) { try { using (IlInjector.BeginRunBlock(MAX_NUM_EXECUTED_INSTRUCTIONS, MAX_NUM_METHOD_CALLS)) { m_instance = Activator.CreateInstance(type) as IMyGridProgram; } if (m_instance != null) { m_previousRunTimestamp = 0; m_instance.Storage = storage; m_instance.Me = this; m_instance.Echo = EchoTextToDetailInfo; } } catch (TargetInvocationException ex) { if (ex.InnerException != null) { string response = MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Exception_ExceptionCaught) + ex.InnerException.Message; if (DetailedInfo.ToString() != response) { MyMultiplayer.RaiseEvent(this, x => x.WriteProgramResponse, response); } } } } } } catch (Exception ex) { string response = MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Exception_ExceptionCaught) + ex.Message; if (DetailedInfo.ToString() != response) { MyMultiplayer.RaiseEvent(this, x => x.WriteProgramResponse, response); } } }