- Home /
Write to XML-file within Assets\Resources
Hello!
I have a question regarding XML-files within the Assets\Resources-Folder:
I am able to load a XML-file from the Assets\Resources-Folder with
Resources.Load("xmlfile", typeof(TextAsset)) as TextAsset;
and converting this TextAsset with this line of code:
xmlDoc.Load(new MemoryStream(textAsset.bytes));
to a XmlDocument.
Now, I want to change attributes within this XML-file, but I do not want to save the changes to a new XML-file. I want to save the changes to the XML-file in the Assets\Resources-Folder, because files within the Build of the game cannot be changed with Text-Editors, and to prevent cheating my XML-file must not be altered by the user.
using Unity 3.5.1f2, MonoDevelop 2.8.2, Windows 7 64-bit
Thank you Bunny83 for your quick answer!
Now, is there any workaround to achieve what I want to have? (A possibility to save data which cannot be changes by the user. PlayerPrefs are not acceptable, because those are saved in the Registry under Windows, which can be changes by the user)
Well there's not much you can do about that. Well you can try to make it harder but it will never be save ;)
All your source code can easily be viewed with a .NET reflector so it doesn't matter what encryption you use, a cheater can always figure it out. The best bet is usually to save such data on your server, but you need some sanity checks on your server since a client can also send fake updates.
If you just want prevent the "usual" user from altering your saved data, just encrypt it with any encryption and additionally store a hash value of all saved data to check the integrity.
If you have Unity pro you could create a native code plugin for encryption so it's a bit harder to decompile it. Of course native code plugins doesn't work in the webplayer ;)
Again, thank you very much for your quick answer, Bunny83.
Do you have more hints for me how to make a Unity game as secure and save as possible?
Answer by Bunny83 · May 01, 2012 at 04:09 AM
That isn't possible since the whole assetdatabase is created in the Unity editor and is readonly at runtime. There's no build-in way to save altered assets at runtime.
Your answer
Follow this Question
Related Questions
"Access to path denied" 0 Answers
Editing an XML File 1 Answer
Saving My World 1 Answer
can xml be used in anrdoid?? 1 Answer