I'm working on a small app (script editor) for a game called "The Outforce". This game has a .opf file that contains some kind of cfg files, pictures, .3d model files, and plenty of different extensions such as: .cbaseclass,.unknown,.cweaponunit, cgridmember etc...
but this file (packedproject.opf) also has readable parts, that I can edit with notepad++
I decided to make a form to make file editing faster. Each "strings" in the file have one-two values. For example: "onlysingleplayerunit" "0".
Do you have any idea how to do that? Any suggestions?
read the whole thing in in binary, parse out the things you care about, let the user edit them, and put them back in. Do not increase the size of the text, it can only be the same or less, unless very, very careful (youll have to experiment). C-string it, they are likely zero terminated strings in binary. I advise you to do what you want to do with a hex editor, carefully and fully test what you did, and once happy, use the notes you took in this process to write an editor. If you change the file size, there may be things that lost the hard coded position, and it breaks. If you had a zero terminal followed by junk, you may be able to extend but you can't know where the string really ended and data really started after, so that is high risk. Keeping same size or less, these risks go away.
Its unclear what you want to do. do you want to get a list of the variables so you can change values?
edit them: the strings, the values, or both?
it is a BINARY file.
if you change that to
it may work, it may break. because you made the string bigger. if it breaks, shifting it 2 bytes may fix it, or it may not. Depends on how the reader works.
if you change it to
"Cheats" "5" it will likely work, odds are far better than 100: the file bytes did not move around, so if the thing supports having a 5 there, and does not validate the value and reject it, it will probably work.
if you break something, it may be subtle, and take a lot of testing to even see that it was damaged.
you can do it however you want, but what I said initially holds true... if you can locate these entries, you can change them, sure. you need to read the file (into a binary byte buffer), locate the string data, and use that to populate your gui widget, then allow user to modify in the clean interface, then back feed the changes to the file data, and write the file back out in binary mode. So far, that is fairly simple, but the trick is, again, you need to be careful about breaking the file, which means that if you make a string's size bigger than it was when you edit it, you are at risk, and need to test and play with the program to see what you can and cannot do there. That part isn't tied to c++, its tied to how the consumer of the file reacts to hackery.
In other words if I want not just edit the values but add new lines the game will crash at start :(
I can't say for sure. Odds are against careless hackery working, but sometimes it does. That was part of my original point... take a hex editor, hack the way you want to, and then run your game to see if you broke it. Once you are comfortable with what you can do to your file, then you can make a tool to do the changes. Making the tool first is possible but you will be chasing your tail a bit.
--it shouldn't have to be said, but I will... keep a copy of the original file before you take the axe to it.
There's no such thing as "lines" in a binary file. So, no, you can't add a "line".
To add new strings then, at a minimum, you'd need to also enter the string sizes that I mentioned.
I don't know what you mean by "I tried to add FFNULCanBuildUnit...".
Obviously you can't type the characters "FFNUL" for [FF][NUL].
Those are binary values that are being displayed as ascii control character names.
You might be able to copy/paste one of the actual values that's already in the file.
That might be easy for [FF][NUL]CanBuildUnit.
You would need to add the correct one for the second string, too.
It's 6 chars long, so it would need [ACK][NUL] before the string "M_RD72".
So you would need to find an [ACK] in the file somewhere and copy that.
But this is madness! We would never do it this way. You should be using a hex editor.
Additionally, there could be section offsets that need to be adjusted. This might be a little complicated.
Finally, it's possible that there is a checksum (e.g., CRC32) that would need to be recalculated. (You can test this by changing a single number, like 0 to 1, and see if it breaks.)
But obviously you don't want to upload the file, so there's not much I can do.