Advertisement
Scarlet

Monster Hunter Stories Save Editor Sauce

Oct 10th, 2016
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.85 KB | None | 0 0
  1. // Little lazy with this, but people seem to have been asking so hey, it's better than nothing.
  2. // Little to no error checking, should probably make that clear.
  3. // Anyway, this'll give you max money and max Mega Potions... Or Potions... It's one or the other.
  4.  
  5. #include "stdafx.h"
  6. #include <iostream>
  7. #include <fstream>
  8. #include <string>
  9. using namespace std;
  10.  
  11. struct SEditValues
  12. {
  13.     int offset;
  14.     int value;
  15. };
  16.  
  17. const SEditValues kMaxMoney = { 0x5B404, 9999999 };
  18. const SEditValues kMaxMegaPotions = { 0x1A, 999 };
  19.  
  20. class CHexEditing
  21. {
  22.  
  23. private:
  24.     fstream file;
  25.  
  26. public:
  27.     int LoadFile(string fileName);
  28.     void CloseFile();
  29.     void WriteToOffset(int offset, int value);
  30. };
  31.  
  32. int CHexEditing::LoadFile(string fileName)
  33. {
  34.     file.open(fileName, ios::in | ios::out | ios::binary);
  35.     if (file.is_open())
  36.     {
  37.         cout << "File Opened";
  38.         return 0;
  39.     }
  40.  
  41.     else
  42.     {
  43.         cout << "Unable to open file, is it in the same directory?" << endl;
  44.         system("pause");        // Fight me.
  45.         return 1;
  46.     }
  47. }
  48.  
  49. void CHexEditing::CloseFile()
  50. {
  51.     file.close();
  52.  
  53.     #ifdef _DEBUG
  54.     if (!file.is_open()) cout << "File Closed";
  55.     else cout << "File Not Closed";
  56.     cout << endl;
  57.     system("pause");
  58.     #endif
  59. }
  60.  
  61. void CHexEditing::WriteToOffset(int offset, int value)
  62. {
  63.     unsigned int valueToWrite = (unsigned int)value;
  64.  
  65.     file.seekp(offset);
  66.  
  67.     if (valueToWrite <= 0xFF)
  68.     {
  69.         file.put(valueToWrite);
  70.         return;
  71.     }
  72.  
  73.     else if (valueToWrite <= 0xFFFF)
  74.     {
  75.         unsigned short bytes[2];
  76.  
  77.         bytes[0] = (valueToWrite) & 0xFF;
  78.         bytes[1] = (valueToWrite >> 8) & 0xFF;
  79.  
  80.         file.put(bytes[0]);
  81.  
  82.         file.seekp(offset + 1);
  83.         file.put(bytes[1]);
  84.     }
  85.  
  86.     else if (valueToWrite <= 0xFFFFFFFF)
  87.     {
  88.         unsigned short bytes[4];
  89.        
  90.         bytes[0] = (valueToWrite) & 0xFF;
  91.         bytes[1] = (valueToWrite >> 8) & 0xFF;
  92.         bytes[2] = (valueToWrite >> 16) & 0xFF;
  93.         bytes[3] = (valueToWrite >> 24) & 0xFF;
  94.  
  95.         file.put(bytes[0]);
  96.  
  97.         file.seekp(offset + 1);
  98.         file.put(bytes[1]);
  99.  
  100.         file.seekp(offset + 2);
  101.         file.put(bytes[2]);
  102.  
  103.         file.seekp(offset + 3);
  104.         file.put(bytes[3]);
  105.     }
  106.  
  107.     else cout << "Look mango, that number is real big. Too big.";
  108.  
  109.     #ifdef _DEBUG
  110.     cout << valueToWrite << " written to file." << endl;
  111.     system("pause");
  112.     #endif
  113. }
  114.  
  115. int main()
  116. {
  117.     CHexEditing* monHun = new CHexEditing;
  118.     string fileName = "mhr_game";
  119.     int fileNumber;
  120.     cout << "Please enter your file number (top file = 0, middle = 1, bottom = 2): ";
  121.     cin >> fileNumber;
  122.     fileName = fileName + to_string(fileNumber) + ".sav";
  123.  
  124.     if (monHun->LoadFile(fileName) == 1) return 0;                                      // If unable to load a file, exit app
  125.     monHun->WriteToOffset(kMaxMoney.offset, kMaxMoney.value);
  126.     monHun->WriteToOffset(kMaxMegaPotions.offset, kMaxMegaPotions.value);
  127.     monHun->CloseFile();
  128.  
  129.     cout << "Yo dawg, we done here. You should have max money and Mega Potions.";
  130.     cout << endl;
  131.     system("pause");        // Fight me.
  132.     return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement