x


Write to XML-file within Assets\Resources

Hello!

I have a question regarding XML-files within the AssetsResources-Folder:

I am able to load a XML-file from the AssetsResources-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 AssetsResources-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

more ▼

asked May 01 '12 at 04:05 AM

Nutzer gravatar image

Nutzer
2 1 1 2

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)

May 01 '12 at 10:48 AM Nutzer

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 ;)

May 01 '12 at 11:31 AM Bunny83

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?

May 02 '12 at 06:45 AM Nutzer
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered May 01 '12 at 04:09 AM

Bunny83 gravatar image

Bunny83
45.3k 11 49 207

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x437
x280
x255
x218
x52

asked: May 01 '12 at 04:05 AM

Seen: 1251 times

Last Updated: May 02 '12 at 06:45 AM