Exemple #1
0
 private void Button4_Click(object sender, RoutedEventArgs e)
 {
     Result = DebugDataMode.NoDebug;
     Close();
 }
Exemple #2
0
 private void Button3_Click(object sender, RoutedEventArgs e)
 {
     Result = DebugDataMode.FullAssembler;
     Close();
 }
Exemple #3
0
        private async Task SaveFile(string filename)
        {
            if (Data == null || Data.UnsupportedBytecodeVersion)
            {
                return;
            }

            if (IsGMS2 == Visibility.Visible)
            {
                MessageBox.Show("This is not yet fully stable and may break. You have been warned.", "GMS2 game", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            LoaderDialog dialog = new LoaderDialog("Saving", "Saving, please wait...");

            dialog.Owner = this;
            FilePath     = filename;
            if (System.IO.Path.GetDirectoryName(FilePath) != System.IO.Path.GetDirectoryName(filename))
            {
                CloseChildFiles();
            }

            DebugDataMode debugMode = DebugDataMode.NoDebug;

            if (!Data.GeneralInfo.DisableDebugger) // TODO: I think the game itself can also use the .yydebug file on crash reports
            {
                DebugDataDialog debugDialog = new DebugDataDialog();
                debugDialog.Owner = this;
                debugDialog.ShowDialog();
                debugMode = debugDialog.Result;
                // TODO: Add an option to generate debug data for just selected scripts (to make running faster / make the full assembly not take forever to load)
            }
            Task t = Task.Run(() =>
            {
                try
                {
                    using (var stream = new FileStream(filename, FileMode.Create))
                    {
                        UndertaleIO.Write(stream, Data);
                    }

                    if (debugMode != DebugDataMode.NoDebug)
                    {
                        Debug.WriteLine("Generating debugger data...");
                        UndertaleDebugData debugData = DebugDataGenerator.GenerateDebugData(Data, debugMode);
                        using (FileStream stream = new FileStream(System.IO.Path.ChangeExtension(FilePath, ".yydebug"), FileMode.Create))
                        {
                            using (UndertaleWriter writer = new UndertaleWriter(stream))
                            {
                                debugData.FORM.Serialize(writer);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("An error occured while trying to save:\n" + e.Message, "Save error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                Dispatcher.Invoke(() =>
                {
                    dialog.Hide();
                });
            });

            dialog.ShowDialog();
            await t;
        }
Exemple #4
0
 private void Button1_Click(object sender, RoutedEventArgs e)
 {
     Result = DebugDataMode.Decompiled;
     Close();
 }
Exemple #5
0
        public static UndertaleDebugData GenerateDebugData(UndertaleData data, DebugDataMode mode)
        {
            if (mode == DebugDataMode.NoDebug)
            {
                return(null);
            }

            UndertaleDebugData debug = UndertaleDebugData.CreateNew();

            foreach (var code in data.Code)
            {
                if (mode == DebugDataMode.Decompiled)
                {
                    Debug.WriteLine("Decompiling " + code.Name.Content);
                    string output;
                    try
                    {
                        output = Decompiler.Decompiler.Decompile(code, data);
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.Message);
                        output = "/*\nEXCEPTION!\n" + e.ToString() + "\n*/";
                    }
                    debug.SourceCode.Add(new UndertaleScriptSource()
                    {
                        SourceCode = debug.Strings.MakeString(output)
                    });

                    UndertaleDebugInfo debugInfo = new UndertaleDebugInfo();
                    debugInfo.Add(new UndertaleDebugInfo.DebugInfoPair()
                    {
                        SourceCodeOffset = 0, BytecodeOffset = 0
                    });                                                                                                 // TODO: generate this too! :D
                    debug.DebugInfo.Add(debugInfo);
                }
                else
                {
                    StringBuilder      sb        = new StringBuilder();
                    UndertaleDebugInfo debugInfo = new UndertaleDebugInfo();

                    foreach (var instr in code.Instructions)
                    {
                        if (mode == DebugDataMode.FullAssembler || instr.Kind == UndertaleInstruction.Opcode.Pop || instr.Kind == UndertaleInstruction.Opcode.Popz || instr.Kind == UndertaleInstruction.Opcode.B || instr.Kind == UndertaleInstruction.Opcode.Bt || instr.Kind == UndertaleInstruction.Opcode.Bf || instr.Kind == UndertaleInstruction.Opcode.Ret || instr.Kind == UndertaleInstruction.Opcode.Exit)
                        {
                            debugInfo.Add(new UndertaleDebugInfo.DebugInfoPair()
                            {
                                SourceCodeOffset = (uint)sb.Length, BytecodeOffset = instr.Address * 4
                            });
                        }
                        sb.Append(instr.ToString(code, data.Variables));
                        sb.Append("\n");
                    }

                    debug.SourceCode.Add(new UndertaleScriptSource()
                    {
                        SourceCode = debug.Strings.MakeString(sb.ToString())
                    });
                    debug.DebugInfo.Add(debugInfo);
                }
            }
            foreach (var locals in data.CodeLocals)
            {
                debug.LocalVars.Add(locals);
            }

            return(debug);
        }