FieldWalkmeshInstruction.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. switch (opcode_){
  30. case OPCODES::SLIP: code_gen->WriteTodo(md.GetEntityName(), "SLIP"); break;
  31. case OPCODES::UC: ProcessUC(code_gen); break;
  32. case OPCODES::IDLCK:
  33. // Triangle id, on or off
  34. code_gen->AddOutputLine(
  35. (boost::format("walkmesh:lock_walkmesh(%1%, %2%)")
  36. % params_[0]->GetUnsigned()
  37. % FieldCodeGenerator::FormatBool(params_[1]->GetUnsigned())).str());
  38. break;
  39. case OPCODES::LINE: ProcessLINE(code_gen, md.GetEntityName()); break;
  40. case OPCODES::LINON: code_gen->WriteTodo(md.GetEntityName(), "LINON"); break;
  41. case OPCODES::SLINE: code_gen->WriteTodo(md.GetEntityName(), "SLINE"); break;
  42. default:
  43. code_gen->AddOutputLine(FieldCodeGenerator::FormatInstructionNotImplemented(
  44. md.GetEntityName(), address_, opcode_
  45. ));
  46. }
  47. }
  48. void FieldWalkmeshInstruction::ProcessUC(CodeGenerator* code_gen){
  49. code_gen->AddOutputLine((
  50. boost::format("entity_manager:player_lock(%1%)")
  51. % FieldCodeGenerator::FormatBool(params_[0]->GetUnsigned())
  52. ).str());
  53. }
  54. void FieldWalkmeshInstruction::ProcessLINE(CodeGenerator* code_gen, const std::string& entity){
  55. float xa = params_[0]->GetSigned();
  56. float ya = params_[1]->GetSigned();
  57. float za = params_[2]->GetSigned();
  58. float xb = params_[3]->GetSigned();
  59. float yb = params_[4]->GetSigned();
  60. float zb = params_[5]->GetSigned();
  61. // Scale down. TODO: Why this number?
  62. xa *= 0.00781249709639;
  63. ya *= 0.00781249709639;
  64. za *= 0.00781249709639;
  65. xb *= 0.00781249709639;
  66. yb *= 0.00781249709639;
  67. zb *= 0.00781249709639;
  68. // Just print as a comment.
  69. code_gen->AddOutputLine(
  70. "-- LINE (" + std::to_string(xa) + ", " + std::to_string(ya) + ", " + std::to_string(za)
  71. + ")-(" + std::to_string(xb) + ", " +std::to_string(yb) + ", " + std::to_string(zb) + ")"
  72. );
  73. }