Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Little lazy with this, but people seem to have been asking so hey, it's better than nothing.
- // Little to no error checking, should probably make that clear.
- // Anyway, this'll give you max money and max Mega Potions... Or Potions... It's one or the other.
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- struct SEditValues
- {
- int offset;
- int value;
- };
- const SEditValues kMaxMoney = { 0x5B404, 9999999 };
- const SEditValues kMaxMegaPotions = { 0x1A, 999 };
- class CHexEditing
- {
- private:
- fstream file;
- public:
- int LoadFile(string fileName);
- void CloseFile();
- void WriteToOffset(int offset, int value);
- };
- int CHexEditing::LoadFile(string fileName)
- {
- file.open(fileName, ios::in | ios::out | ios::binary);
- if (file.is_open())
- {
- cout << "File Opened";
- return 0;
- }
- else
- {
- cout << "Unable to open file, is it in the same directory?" << endl;
- system("pause"); // Fight me.
- return 1;
- }
- }
- void CHexEditing::CloseFile()
- {
- file.close();
- #ifdef _DEBUG
- if (!file.is_open()) cout << "File Closed";
- else cout << "File Not Closed";
- cout << endl;
- system("pause");
- #endif
- }
- void CHexEditing::WriteToOffset(int offset, int value)
- {
- unsigned int valueToWrite = (unsigned int)value;
- file.seekp(offset);
- if (valueToWrite <= 0xFF)
- {
- file.put(valueToWrite);
- return;
- }
- else if (valueToWrite <= 0xFFFF)
- {
- unsigned short bytes[2];
- bytes[0] = (valueToWrite) & 0xFF;
- bytes[1] = (valueToWrite >> 8) & 0xFF;
- file.put(bytes[0]);
- file.seekp(offset + 1);
- file.put(bytes[1]);
- }
- else if (valueToWrite <= 0xFFFFFFFF)
- {
- unsigned short bytes[4];
- bytes[0] = (valueToWrite) & 0xFF;
- bytes[1] = (valueToWrite >> 8) & 0xFF;
- bytes[2] = (valueToWrite >> 16) & 0xFF;
- bytes[3] = (valueToWrite >> 24) & 0xFF;
- file.put(bytes[0]);
- file.seekp(offset + 1);
- file.put(bytes[1]);
- file.seekp(offset + 2);
- file.put(bytes[2]);
- file.seekp(offset + 3);
- file.put(bytes[3]);
- }
- else cout << "Look mango, that number is real big. Too big.";
- #ifdef _DEBUG
- cout << valueToWrite << " written to file." << endl;
- system("pause");
- #endif
- }
- int main()
- {
- CHexEditing* monHun = new CHexEditing;
- string fileName = "mhr_game";
- int fileNumber;
- cout << "Please enter your file number (top file = 0, middle = 1, bottom = 2): ";
- cin >> fileNumber;
- fileName = fileName + to_string(fileNumber) + ".sav";
- if (monHun->LoadFile(fileName) == 1) return 0; // If unable to load a file, exit app
- monHun->WriteToOffset(kMaxMoney.offset, kMaxMoney.value);
- monHun->WriteToOffset(kMaxMegaPotions.offset, kMaxMegaPotions.value);
- monHun->CloseFile();
- cout << "Yo dawg, we done here. You should have max money and Mega Potions.";
- cout << endl;
- system("pause"); // Fight me.
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement