FieldWalkmeshInstruction.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/FieldWalkmeshInstruction.h"
  22. #include "decompiler/field/FieldEngine.h"
  23. #include "decompiler/field/FieldCodeGenerator.h"
  24. #include "decompiler/field/FieldDisassembler.h"
  25. void FieldWalkmeshInstruction::ProcessInst(
  26. Function& func, ValueStack&, Engine* engine, CodeGenerator *code_gen
  27. ){
  28. FunctionMetaData md(func.metadata);
  29. //std::cout << "WMesh opcode: " << opcode_ << "\n";
  30. switch (opcode_){
  31. case OPCODES::SLIP:
  32. // Lets the player slide along the walls or not.
  33. code_gen->AddOutputLine(
  34. (boost::format("entity_manager:set_player_slip(%1%)")
  35. % FieldCodeGenerator::FormatBool(params_[0]->GetUnsigned())).str()
  36. );
  37. break;
  38. case OPCODES::UC: ProcessUC(code_gen); break;
  39. case OPCODES::IDLCK:
  40. // Triangle id, on or off
  41. code_gen->AddOutputLine(
  42. (boost::format("walkmesh:lock_walkmesh(%1%, %2%)")
  43. % params_[0]->GetUnsigned()
  44. % FieldCodeGenerator::FormatBool(params_[1]->GetUnsigned())).str());
  45. break;
  46. case OPCODES::LINE: ProcessLINE(code_gen, md.GetEntityName()); break;
  47. case OPCODES::LINON: ProcessLINON(code_gen); break;
  48. case OPCODES::SLINE: code_gen->WriteTodo(md.GetEntityName(), "SLINE"); break;
  49. default:
  50. code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
  51. md.GetEntityName(), address_, opcode_
  52. ));
  53. }
  54. }
  55. void FieldWalkmeshInstruction::ProcessUC(CodeGenerator* code_gen){
  56. code_gen->AddOutputLine((
  57. boost::format("entity_manager:player_lock(%1%)")
  58. % FieldCodeGenerator::FormatBool(params_[0]->GetUnsigned())
  59. ).str());
  60. }
  61. void FieldWalkmeshInstruction::ProcessLINE(CodeGenerator* code_gen, const std::string& entity){
  62. float xa = params_[0]->GetSigned();
  63. float ya = params_[1]->GetSigned();
  64. float za = params_[2]->GetSigned();
  65. float xb = params_[3]->GetSigned();
  66. float yb = params_[4]->GetSigned();
  67. float zb = params_[5]->GetSigned();
  68. // Scale down. TODO: Why this number?
  69. xa *= 0.00781249709639;
  70. ya *= 0.00781249709639;
  71. za *= 0.00781249709639;
  72. xb *= 0.00781249709639;
  73. yb *= 0.00781249709639;
  74. zb *= 0.00781249709639;
  75. // Just print as a comment.
  76. code_gen->AddOutputLine(
  77. "-- LINE (" + std::to_string(xa) + ", " + std::to_string(ya) + ", " + std::to_string(za)
  78. + ")-(" + std::to_string(xb) + ", " +std::to_string(yb) + ", " + std::to_string(zb) + ")"
  79. );
  80. }
  81. void FieldWalkmeshInstruction::ProcessLINON(CodeGenerator* code_gen){
  82. std::string on = ((params_[0]->GetSigned() == 1) ? "true" : "false");
  83. code_gen->AddOutputLine("self.on = " + on);
  84. }