FieldWindowInstruction.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * V-Gears
  3. * Copyright (C) 2022 V-Gears Team
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "decompiler/field/instruction/FieldWindowInstruction.h"
  19. #include "decompiler/field/FieldEngine.h"
  20. #include "decompiler/field/FieldCodeGenerator.h"
  21. #include "decompiler/field/FieldDisassembler.h"
  22. void FieldWindowInstruction::ProcessInst(
  23. Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
  24. ){
  25. FieldEngine& eng = static_cast<FieldEngine&>(*engine);
  26. FunctionMetaData md(func._metadata);
  27. switch (_opcode){
  28. case OPCODE::TUTOR: WriteTodo(code_gen, md.GetEntityName(), "TUTOR"); break;
  29. case OPCODE::WCLS: WriteTodo(code_gen, md.GetEntityName(), "WCLS"); break;
  30. case OPCODE::WSIZW: WriteTodo(code_gen, md.GetEntityName(), "WSIZW"); break;
  31. case OPCODE::WSPCL: WriteTodo(code_gen, md.GetEntityName(), "WSPCL"); break;
  32. case OPCODE::WNUMB: WriteTodo(code_gen, md.GetEntityName(), "WNUMB"); break;
  33. case OPCODE::STTIM: WriteTodo(code_gen, md.GetEntityName(), "STTIM"); break;
  34. case OPCODE::MESSAGE: ProcessMESSAGE(code_gen, eng.ScriptName()); break;
  35. case OPCODE::MPARA: WriteTodo(code_gen, md.GetEntityName(), "MPARA"); break;
  36. case OPCODE::MPRA2: WriteTodo(code_gen, md.GetEntityName(), "MPRA2"); break;
  37. case OPCODE::MPNAM: ProcessMPNAM(code_gen); break;
  38. case OPCODE::ASK: WriteTodo(code_gen, md.GetEntityName(), "ASK"); break;
  39. case OPCODE::MENU: WriteTodo(code_gen, md.GetEntityName(), "MENU"); break;
  40. case OPCODE::MENU2: ProcessMENU2(code_gen); break;
  41. case OPCODE::WINDOW: ProcessWINDOW(code_gen); break;
  42. case OPCODE::WMOVE: WriteTodo(code_gen, md.GetEntityName(), "WMOVE"); break;
  43. case OPCODE::WMODE: WriteTodo(code_gen, md.GetEntityName(), "WMODE"); break;
  44. case OPCODE::WREST: WriteTodo(code_gen, md.GetEntityName(), "WREST"); break;
  45. case OPCODE::WCLSE: ProcessWCLSE(code_gen); break;
  46. case OPCODE::WROW: WriteTodo(code_gen, md.GetEntityName(), "WROW"); break;
  47. case OPCODE::GWCOL: WriteTodo(code_gen, md.GetEntityName(), "GWCOL"); break;
  48. case OPCODE::SWCOL: WriteTodo(code_gen, md.GetEntityName(), "SWCOL"); break;
  49. default:
  50. code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
  51. md.GetEntityName(), _address, _opcode
  52. ));
  53. }
  54. }
  55. void FieldWindowInstruction::ProcessWINDOW(CodeGenerator* code_gen){
  56. // Init a new window. It won't be displayed until MESSAGE is used.
  57. auto windowId = _params[0]->getUnsigned();
  58. auto x = _params[1]->getUnsigned();
  59. auto y = _params[2]->getUnsigned();
  60. auto width = _params[3]->getUnsigned();
  61. auto height = _params[4]->getUnsigned();
  62. code_gen->AddOutputLine((
  63. boost::format("dialog:dialog_open(\"%1%\", %2%, %3%, %4%, %5%)")
  64. % windowId % x % y % width % height
  65. ).str());
  66. }
  67. void FieldWindowInstruction::ProcessMESSAGE(
  68. CodeGenerator* code_gen, const std::string& script_name
  69. ){
  70. // Displays a dialog in the WINDOW that has previously been initialized to display this dialog.
  71. auto window_id = _params[0]->getUnsigned();
  72. auto dialog_id = _params[1]->getUnsigned();
  73. code_gen->AddOutputLine((
  74. boost::format("dialog:dialog_set_text(\"%1%\", \"%2%_%3%\")")
  75. % window_id % script_name % dialog_id
  76. ).str());
  77. code_gen->AddOutputLine(
  78. (boost::format("dialog:dialog_wait_for_close(\"%1%\")") % window_id).str()
  79. );
  80. }
  81. void FieldWindowInstruction::ProcessWCLSE(CodeGenerator* code_gen){
  82. // Close a dialog.
  83. auto windowId = _params[0]->getUnsigned();
  84. code_gen->AddOutputLine((boost::format("dialog:dialog_close(\"%1%\")") % windowId).str());
  85. }
  86. void FieldWindowInstruction::ProcessMPNAM(CodeGenerator* code_gen){
  87. code_gen->AddOutputLine(
  88. (boost::format("-- field:map_name(%1%)") % _params[0]->getUnsigned()).str()
  89. );
  90. }
  91. void FieldWindowInstruction::ProcessMENU2(CodeGenerator* code_gen){
  92. code_gen->AddOutputLine((
  93. boost::format("-- field:menu_lock(%1%)")
  94. % FieldCodeGenerator::FormatBool(_params[0]->getUnsigned())
  95. ).str());
  96. }