private void DisassemblyEditor_LostFocus(object sender, RoutedEventArgs e) { UndertaleCode code = this.DataContext as UndertaleCode; if (code == null) { return; // Probably loaded another data.win or something. } UndertaleData data = (Application.Current.MainWindow as MainWindow).Data; try { var instructions = Assembler.Assemble(DisassemblyEditor.Text, data); code.Replace(instructions); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Assembler error", MessageBoxButton.OK, MessageBoxImage.Error); return; } CurrentDisassembled = null; CurrentDecompiled = null; CurrentGraphed = null; DisassembleCode(code); DisassemblyView.Visibility = Visibility.Visible; DisassemblyEditor.Visibility = Visibility.Collapsed; }
private void DecompiledEditor_LostFocus(object sender, RoutedEventArgs e) { UndertaleCode code = this.DataContext as UndertaleCode; if (code == null) { return; // Probably loaded another data.win or something. } if (code.DuplicateEntry) { return; } UndertaleData data = (Application.Current.MainWindow as MainWindow).Data; CompileContext compileContext = Compiler.CompileGMLText(DecompiledEditor.Text, data, code); if (compileContext.HasError) { MessageBox.Show(compileContext.ResultError, "Compiler error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (!compileContext.SuccessfulCompile) { MessageBox.Show(compileContext.ResultAssembly, "Compile failed", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { var instructions = Assembler.Assemble(compileContext.ResultAssembly, data); code.Replace(instructions); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Assembler error", MessageBoxButton.OK, MessageBoxImage.Error); return; } // Show new code, decompiled. CurrentDisassembled = null; CurrentDecompiled = null; CurrentGraphed = null; DecompileCode(code); DecompiledView.Visibility = Visibility.Visible; DecompiledEditor.Visibility = Visibility.Collapsed; }
void SafeImport(string codeName, string gmlCode, bool IsGML, bool destroyASM = true, bool CheckDecompiler = false, bool throwOnError = false) { UndertaleCode code = Data.Code.ByName(codeName); try { if (IsGML) { code.ReplaceGML(gmlCode, Data); // Write to profile if necessary. string path = Path.Combine(ProfilesFolder, Data.ToolInfo.CurrentMD5, "Temp", codeName + ".gml"); if (File.Exists(path)) { File.WriteAllText(path, GetDecompiledText(code)); } } else { var instructions = Assembler.Assemble(gmlCode, Data); code.Replace(instructions); if (destroyASM) { NukeProfileGML(codeName); } } } catch (Exception ex) { if (!CheckDecompiler) { string errorText = $"Code import error at {(IsGML ? "GML" : "ASM")} code \"{codeName}\":\n\n{ex.Message}"; this.ShowWarning(errorText); if (throwOnError) { throw new ScriptException("*codeImportError*"); } } else { code.ReplaceGML("", Data); } } }
void SafeImport(string codeName, string gmlCode, bool IsGML, bool destroyASM = true, bool CheckDecompiler = false, bool throwOnError = false) { UndertaleCode code = Data.Code.ByName(codeName); try { if (IsGML) { code.ReplaceGML(gmlCode, Data); } else { var instructions = Assembler.Assemble(gmlCode, Data); code.Replace(instructions); if (destroyASM) { NukeProfileGML(codeName); } } } catch (Exception ex) { if (!CheckDecompiler) { string errorText = $"Code import error at {(IsGML ? "GML" : "ASM")} code \"{codeName}\":\n\n{ex.Message}"; Console.Error.WriteLine(errorText); if (throwOnError) { throw new ScriptException("*codeImportError*"); } } else { code.ReplaceGML("", Data); } } }
private void DisassemblyEditor_LostFocus(object sender, RoutedEventArgs e) { if (!DisassemblyFocused) { return; } if (DisassemblyEditor.IsReadOnly) { return; } DisassemblyFocused = false; if (!DisassemblyChanged) { return; } UndertaleCode code = this.DataContext as UndertaleCode; if (code == null) { return; // Probably loaded another data.win or something. } if (code.DuplicateEntry) { return; } // Check to make sure this isn't an element inside of the textbox, or another tab IInputElement elem = Keyboard.FocusedElement; if (elem is UIElement) { if (e != null && e.RoutedEvent?.Name != "CtrlK" && (elem as UIElement).IsDescendantOf(DisassemblyEditor)) { return; } } UndertaleData data = (Application.Current.MainWindow as MainWindow).Data; try { var instructions = Assembler.Assemble(DisassemblyEditor.Text, data); code.Replace(instructions); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Assembler error", MessageBoxButton.OK, MessageBoxImage.Error); return; } // Get rid of old code CurrentDisassembled = null; CurrentDecompiled = null; CurrentGraphed = null; // Tab switch if (e == null) { return; } // Disassemble new code DisassembleCode(code); }
private void DecompiledEditor_LostFocus(object sender, RoutedEventArgs e) { if (!DecompiledFocused) { return; } if (DecompiledEditor.IsReadOnly) { return; } DecompiledFocused = false; if (!DecompiledChanged) { return; } UndertaleCode code = this.DataContext as UndertaleCode; if (code == null) { return; // Probably loaded another data.win or something. } if (code.DuplicateEntry) { return; } // Check to make sure this isn't an element inside of the textbox, or another tab IInputElement elem = Keyboard.FocusedElement; if (elem is UIElement) { if (e != null && e.RoutedEvent?.Name != "CtrlK" && (elem as UIElement).IsDescendantOf(DecompiledEditor)) { return; } } UndertaleData data = (Application.Current.MainWindow as MainWindow).Data; CompileContext compileContext = Compiler.CompileGMLText(DecompiledEditor.Text, data, code); if (compileContext.HasError) { MessageBox.Show(compileContext.ResultError, "Compiler error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (!compileContext.SuccessfulCompile) { MessageBox.Show(compileContext.ResultAssembly, "Compile failed", MessageBoxButton.OK, MessageBoxImage.Error); return; } //The code should only be written after being successfully edited (if it doesn't successfully assemble for some reason, don't write it). bool CodeEditSuccessful = false; try { var instructions = Assembler.Assemble(compileContext.ResultAssembly, data); code.Replace(instructions); CodeEditSuccessful = true; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Assembler error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (CodeEditSuccessful && !(Application.Current.MainWindow as MainWindow).Data.GMS2_3) { try { string path = Path.Combine(TempPath, code.Name.Content + ".gml"); if (SettingsWindow.ProfileModeEnabled) { // Write text, only if in the profile mode. File.WriteAllText(path, DecompiledEditor.Text); } else { // Destroy file with comments if it's been edited outside the profile mode. // We're dealing with the decompiled code only, it has to happen. // Otherwise it will cause a desync, which is more important to prevent. if (File.Exists(path)) { File.Delete(path); } } } catch (Exception exc) { MessageBox.Show("Error during writing of GML code to profile:\n" + exc.ToString()); } } // Show new code, decompiled. CurrentDisassembled = null; CurrentDecompiled = null; CurrentGraphed = null; // Tab switch if (e == null) { return; } // Decompile new code DecompileCode(code); }