KernelDataInstaller.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears 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. #include <fstream>
  16. #include "installer/formats/DiskImage.h"
  17. #include "installer/extractors/KernelDataInstaller.h"
  18. KernelDataInstaller::KernelDataInstaller(DiskImage& disk_image):
  19. kernel_(*disk_image.filePath("data/kernel/KERNEL.BIN")), exe_path_(*disk_image.filePath("ff7.exe")
  20. ){
  21. for (int i = 0; i < 416; i ++) prices_[i] = 50;
  22. }
  23. KernelDataInstaller::~KernelDataInstaller(){}
  24. void KernelDataInstaller::ReadPrices(){
  25. File exe_file(exe_path_);
  26. exe_file.SetOffset(0x00514518); // Items, weapons, armors, accessories start here
  27. for (int i = 0; i < 320; i ++) prices_[i] = exe_file.readU32LE();
  28. exe_file.SetOffset(0x00514B18); // Materias start here
  29. for (int i = 320; i < 416; i ++) prices_[i] = exe_file.readU32LE();
  30. }
  31. void KernelDataInstaller::WriteShops(std::string file_name){
  32. // Shop inventories are a table of 80 records of 84 bytes in ff7.exe: u16 type, u16 number of
  33. // entries, and 10 entries of u32 kind (0: item, weapon, armor or accessory; 1: materia) and u32
  34. // index (the index of the item as in the prices table, or the ID of the materia).
  35. const int SHOP_TABLE_OFFSET = 0x00512AD8;
  36. const int SHOP_COUNT = 80;
  37. std::fstream file;
  38. file.open(file_name, std::ios::out);
  39. if (!file) return;
  40. File exe_file(exe_path_);
  41. file << "-- Inventory of each shop. Prices are the ones of the items and the materia.\n"
  42. << "-- type: kind of shop (1: weapons, 2: items, 3: materia...). Entries are {materia, id}.\n"
  43. << "Game.Shops = {}\n";
  44. for (int s = 0; s < SHOP_COUNT; s ++){
  45. exe_file.SetOffset(SHOP_TABLE_OFFSET + s * 84);
  46. u16 type = exe_file.readU16LE();
  47. u16 count = exe_file.readU16LE();
  48. file << "Game.Shops[" << s << "] = {\n type = " << type << ",\n items = {";
  49. for (int i = 0; i < 10; i ++){
  50. u32 kind = exe_file.readU32LE();
  51. u32 index = exe_file.readU32LE();
  52. if (i >= count) continue;
  53. file << "\n {" << (kind == 1 ? "true" : "false") << ", " << index << "},";
  54. }
  55. file << "\n }\n}\n";
  56. }
  57. }