Cacoon
Cacoon

Reputation: 2538

Modify bytes (Hex?) of a save file with C++

Sorry, I have read a lot of Q&A on this site that are kind of related by due to me essentially just starting C++, only previously coding in C# and Java I have a save file, and with a hex edit program I have found a value that modifys the campaigns save difficulty; enter image description here

the '00' highlighted value is what I wish to change, I have seen examples but nothing that I fully understand enough to manipulate

    std::ofstream ofs ("/text.txt", std::ofstream::out);//("/JKSV/Saves/Fire_Emblem__Awakening/hack/", std::ofstream::out);
    //Edit item at 0000000D '00' to '01'
    ofs.close();

I know my question, put to people with proper knowledge of C++ is extremely trivial, but its still quite new to me

Upvotes: 0

Views: 2324

Answers (1)

bashrc
bashrc

Reputation: 4835

You will need to open the file in binary mode so that i/o libraries restrict interpretation of the special characters.

fstream binaryFile("txt.txt", ios::in | ios::out | ios::binary);

You may want to check the available functions in fstream

seek to the position where you want to modify the byte value:

binaryFile.seekp(0x0D/*offsetToWrite*);

Write the byte value:

binaryFile << char(0x01/*ValueToReplace*/);  

Upvotes: 4

Related Questions