diff --git a/Arma.Studio.SqfVmDebugger/PluginMain.cs b/Arma.Studio.SqfVmDebugger/PluginMain.cs index d48b543..b3a0e7b 100644 --- a/Arma.Studio.SqfVmDebugger/PluginMain.cs +++ b/Arma.Studio.SqfVmDebugger/PluginMain.cs @@ -160,30 +160,39 @@ await Task.Run(() => Logger.Warning($"No config file located for PBO {pbo.Name}."); } } - if (!hasConfig) - { - Logger.Error("No config files available."); - break; - } // Apply Breakpoints foreach (var breakpoint in this.GetApplication().MainWindow.BreakpointManager.Breakpoints) { this.SetBreakpoint(breakpoint); } - // Run CfgFunctions script + if (hasConfig) { + // Run CfgFunctions script var text = this.CfgFunctionsScript; var preprocessed = this.Virtualmachine.PreProcess(text, "SqfVmDebugger/CfgFunctions.sqf"); this.Virtualmachine.ParseSqf(preprocessed, "SqfVmDebugger/CfgFunctions.sqf"); this.State = EDebugState.Running; execResult = this.Virtualmachine.Start(); + Logger.Diagnostic($"Result of Start: {execResult}"); + } + else + { + Logger.Warning("No config files available. Trying to use currently open document."); + var editorDocument = this.GetApplication().MainWindow.ActiveDockable as Data.UI.IEditorDocument; + if (editorDocument != null && editorDocument.File.Extension == ".sqf") + { + var text = editorDocument.GetContents(); + var preprocessed = this.Virtualmachine.PreProcess(text, editorDocument.TextEditorInstance.File.FullPath); + this.Virtualmachine.ParseSqf(preprocessed, editorDocument.TextEditorInstance.File.FullPath); + this.State = EDebugState.Running; + execResult = this.Virtualmachine.Start(); + Logger.Diagnostic($"Result of Start: {execResult}"); + } + else + { + Logger.Error("Found nothing to run."); + } } - //var text = textEditorDocuments.GetContents(); - //var preprocessed = this.Virtualmachine.PreProcess(text, textEditorDocuments.TextEditorInstance.File.FullPath); - //this.Virtualmachine.ParseSqf(preprocessed, textEditorDocuments.TextEditorInstance.File.FullPath); - //this.State = EDebugState.Running; - //execResult = this.Virtualmachine.Start(); - Logger.Diagnostic($"Result of Start: {execResult}"); break; case EDebugAction.Stop: execResult = this.Virtualmachine.Abort(); @@ -247,7 +256,7 @@ public IEnumerable GetHaltInfos() { if (this.Virtualmachine == null) { - throw new InvalidOperationException(); + return Array.Empty(); } Logger.Diagnostic($"IEnumerable GetHaltInfos()"); var callstack = this.Virtualmachine.GetCallstack(); diff --git a/Arma.Studio/UI/RuntimeBackgroundRenderer.cs b/Arma.Studio/UI/RuntimeBackgroundRenderer.cs index 8387be4..22c2e07 100644 --- a/Arma.Studio/UI/RuntimeBackgroundRenderer.cs +++ b/Arma.Studio/UI/RuntimeBackgroundRenderer.cs @@ -48,7 +48,7 @@ public void Draw(TextView textView, DrawingContext drawingContext) { if (this.Editor.Document == null || App.MWContext.Debugger is null || - App.MWContext.Debugger.State == Data.Debugging.EDebugState.Running) + App.MWContext.Debugger.State != Data.Debugging.EDebugState.Halted) { return; }