FieldWindowInstruction.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <iostream>
  19. #include <sstream>
  20. #include <boost/format.hpp>
  21. #include "decompiler/field/instruction/FieldWindowInstruction.h"
  22. #include "decompiler/field/FieldEngine.h"
  23. #include "decompiler/field/FieldCodeGenerator.h"
  24. #include "decompiler/field/FieldDisassembler.h"
  25. void FF7::FieldWindowInstruction::ProcessInst(
  26. Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
  27. ){
  28. FF7::FieldEngine& eng = static_cast<FF7::FieldEngine&>(*engine);
  29. FunctionMetaData md(func.metadata);
  30. switch (_opcode){
  31. case OPCODES::TUTOR: code_gen->WriteTodo(md.GetEntityName(), "TUTOR"); break;
  32. case OPCODES::WCLS: code_gen->WriteTodo(md.GetEntityName(), "WCLS"); break;
  33. case OPCODES::WSIZW: code_gen->WriteTodo(md.GetEntityName(), "WSIZW"); break;
  34. case OPCODES::WSPCL: code_gen->WriteTodo(md.GetEntityName(), "WSPCL"); break;
  35. case OPCODES::WNUMB: code_gen->WriteTodo(md.GetEntityName(), "WNUMB"); break;
  36. case OPCODES::STTIM: code_gen->WriteTodo(md.GetEntityName(), "STTIM"); break;
  37. case OPCODES::MESSAGE: ProcessMESSAGE(code_gen, eng.GetScriptName()); break;
  38. case OPCODES::MPARA: code_gen->WriteTodo(md.GetEntityName(), "MPARA"); break;
  39. case OPCODES::MPRA2: code_gen->WriteTodo(md.GetEntityName(), "MPRA2"); break;
  40. case OPCODES::MPNAM: ProcessMPNAM(code_gen); break;
  41. case OPCODES::ASK: code_gen->WriteTodo(md.GetEntityName(), "ASK"); break;
  42. case OPCODES::MENU: code_gen->WriteTodo(md.GetEntityName(), "MENU"); break;
  43. case OPCODES::MENU2: ProcessMENU2(code_gen); break;
  44. case OPCODES::WINDOW: ProcessWINDOW(code_gen); break;
  45. case OPCODES::WMOVE: code_gen->WriteTodo(md.GetEntityName(), "WMOVE"); break;
  46. case OPCODES::WMODE: code_gen->WriteTodo(md.GetEntityName(), "WMODE"); break;
  47. case OPCODES::WREST: code_gen->WriteTodo(md.GetEntityName(), "WREST"); break;
  48. case OPCODES::WCLSE: ProcessWCLSE(code_gen); break;
  49. case OPCODES::WROW: code_gen->WriteTodo(md.GetEntityName(), "WROW"); break;
  50. case OPCODES::GWCOL: code_gen->WriteTodo(md.GetEntityName(), "GWCOL"); break;
  51. case OPCODES::SWCOL: code_gen->WriteTodo(md.GetEntityName(), "SWCOL"); break;
  52. default:
  53. code_gen->AddOutputLine(FF7::FieldCodeGenerator::FormatInstructionNotImplemented(
  54. md.GetEntityName(), _address, _opcode
  55. ));
  56. }
  57. }
  58. void FF7::FieldWindowInstruction::ProcessWINDOW(CodeGenerator* code_gen){
  59. // Initializes a new window. It won't be displayed until MESSAGE is used.
  60. auto windowId = _params[0]->getUnsigned();
  61. auto x = _params[1]->getUnsigned();
  62. auto y = _params[2]->getUnsigned();
  63. auto width = _params[3]->getUnsigned();
  64. auto height = _params[4]->getUnsigned();
  65. code_gen->AddOutputLine((
  66. boost::format("dialog:dialog_open(\"%1%\", %2%, %3%, %4%, %5%)")
  67. % windowId % x % y % width % height
  68. ).str());
  69. }
  70. void FF7::FieldWindowInstruction::ProcessMESSAGE(
  71. CodeGenerator* code_gen, const std::string& script_name
  72. ){
  73. // Displays a dialog in the WINDOW that has previously been initialized to display this dialog.
  74. auto window_id = _params[0]->getUnsigned();
  75. auto dialog_id = _params[1]->getUnsigned();
  76. code_gen->AddOutputLine((
  77. boost::format("dialog:dialog_set_text(\"%1%\", \"%2%_%3%\")")
  78. % window_id % script_name % dialog_id
  79. ).str());
  80. code_gen->AddOutputLine(
  81. (boost::format("dialog:dialog_wait_for_close(\"%1%\")") % window_id).str()
  82. );
  83. }
  84. void FF7::FieldWindowInstruction::ProcessWCLSE(CodeGenerator* code_gen){
  85. // Close a dialog.
  86. auto windowId = _params[0]->getUnsigned();
  87. code_gen->AddOutputLine((boost::format("dialog:dialog_close(\"%1%\")") % windowId).str());
  88. }
  89. void FF7::FieldWindowInstruction::ProcessMPNAM(CodeGenerator* code_gen){
  90. code_gen->AddOutputLine(
  91. (boost::format("-- field:map_name(%1%)") % _params[0]->getUnsigned()).str()
  92. );
  93. }
  94. void FF7::FieldWindowInstruction::ProcessMENU2(CodeGenerator* code_gen){
  95. code_gen->AddOutputLine((
  96. boost::format("-- field:menu_lock(%1%)")
  97. % FF7::FieldCodeGenerator::FormatBool(_params[0]->getUnsigned())
  98. ).str());
  99. }