2

So basically, I'm working on a console based game in C#. I'm to the point where I'm ready to save the data. I want all the data saved into one file, if possible. I don't wan't something like XML Serialization, where the player can just go in and give himself a million gold.

What should I use? Here's the things I need to serialize:

    GameWorld
    Inventory
    Player
    List<Item>

    Point
    List<String>

Here's the variables that are in the classes:

    public class GameWorld
    {
        Dictionary<Point, Room>
    }

    public class Item
    {
        String Creator
        String Verb
        String RequiredItem
        Action OnActivate
        int Difficulty
        Action OnDefeatEnemy
        Action OnDefeatedByEnemy 
    }

    public class Room
    {
        String Title
        String Description
        List<Item> Items
        List<String> ItemNames
        String Creator
    }

    public class Inventory
    {
        List<Items>
    }

    public enum ActionType
    {
        ACQUIRE_GOLD, DECREASE_HEALTH, INCREASE_HEALTH, DECREASE_STRENGTH, INCREASE_STRENGTH, GET_ITEM, PRINT_MESSAGE
    }

    public class Action
    {
        ActionType actionType
        int Amount
        String GiveItem
        String Message
        String Creator
        bool SingleActivation
        bool HasActivated
    }
3
  • This may seems like a stupid question, but why do you care if a player edits the XML file or not? Seems like a small thing to be concerned about when the time could be better spent working on the game itself. Commented Jan 20, 2011 at 2:07
  • 2
    Remember back in Transport Tycoon, when you could hexedit the save game file to give yourself billions of dollars? Remember how it wasn't any fun after you did it as the challenge was taken away? Commented Jan 20, 2011 at 2:09
  • @dotalchemy: Remember how this is a hobby project console game and not a shipping commercial product? If implemented correctly, persistance should be something that can easily be changed out at a much later stage without effecting gameplay. Commented Jan 20, 2011 at 2:13

5 Answers 5

3

Using Binary serialization would obfuscate slightly.

[It won't stop someone with Reflector and a bit of a poke around your code and data files though]

Sign up to request clarification or add additional context in comments.

Comments

2

You could pretty easily serialize to xml then encrypt it before saving it to a file.

Comments

1

http://www.codeproject.com/KB/cs/objserial.aspx

Would that work for you?

2 Comments

This looks promising... I'll check it out :)
whoops, forgot to set as answer.
1

Its easier to manage stored object, programmatically, using embedded object database like Db4o or Eloquera.

Comments

0

If you're not worried about disclosure, you could just add a hash of [ your serialized data concatenated with some magic constant ]. A hacker would then have to disassemble your program to find the constant if they wanted to manipulate your serialized data.

If disclosure is a problem, then I would recommend "encryption" with a magic constant. This is really just a form of content scrambling, since the magic constant is "known" (although, perhaps a nuisance to find).

By the way, your problem is analogous to the DRM problem, which really is unsolvable unless you have complete control over the client platform. http://www.schneier.com/crypto-gram-0105.html#3

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.