Inheritance: INotifyPropertyChanged
        /// <summary>
        /// Loads a game info from the stream at the specified offset
        /// </summary>
        /// <param name="stream">Stream.</param>
        /// <param name="offset">Offset.</param>
        /// <returns>The game information at the specified offset</returns>
        /// <remarks>This method has only been tested with the US version of the games</remarks>
        public static GameInfo Load(Stream stream, int offset)
        {
            GameInfo info = new GameInfo();

            byte[] versionBytes = new byte[1];
            byte[] gameIdBytes = new byte[2];
            byte[] heroBytes = new byte[5];
            byte[] kidBytes = new byte[5];
            byte[] behaviorBytes = new byte[1];
            byte[] animalBytes = new byte[1];
            byte[] linkedBytes = new byte[1];
            byte[] heroQuestBytes = new byte[1];
            byte[] freeRingBytes = new byte[1];
            byte[] ringBytes = new byte[8];

            stream.Seek(offset, SeekOrigin.Begin);

            stream.Read(versionBytes, 0, 1);

            // The version is represented by the char values '1' or '2'
            if (versionBytes[0] != 49 && versionBytes[0] != 50)
                return null;

            stream.Seek(76, SeekOrigin.Current);
            stream.Read(gameIdBytes, 0, 2);
            stream.Read(heroBytes, 0, 5);

            stream.Seek(2, SeekOrigin.Current);
            stream.Read(kidBytes, 0, 5);

            stream.Seek(1, SeekOrigin.Current);
            stream.Read(behaviorBytes, 0, 1);
            stream.Read(animalBytes, 0, 1);

            stream.Seek(1, SeekOrigin.Current);

            stream.Read(linkedBytes, 0, 1);
            stream.Read(heroQuestBytes, 0, 1);

            stream.Seek(1, SeekOrigin.Current);
            stream.Read(freeRingBytes, 0, 1);
            stream.Read(ringBytes, 0, 8);

            info.Game = versionBytes[0] == 49 ? Game.Seasons : Game.Ages;
            info.GameID = BitConverter.ToInt16(gameIdBytes, 0);
            info.Hero = System.Text.Encoding.ASCII.GetString(heroBytes);
            info.Child = System.Text.Encoding.ASCII.GetString(kidBytes);
            info.Behavior = (ChildBehavior)(behaviorBytes[0] & 15);
            info.Animal = (Animal)(animalBytes[0] & 7);
            info.IsLinkedGame = linkedBytes[0] == 1;
            info.IsHeroQuest = heroQuestBytes[0] == 1;
            info.Rings = (Rings)BitConverter.ToUInt64(ringBytes, 0);

            info.Unknown58 = (behaviorBytes[0] >> 4 & 1) == 1;
            info.Unknown59 = (behaviorBytes[0] >> 5 & 1) == 1;
            info.WasGivenFreeRing = freeRingBytes[0] == 1;
            info.Unknown88 = animalBytes[0] >> 3 == 1;

            return info;
        }
        /// <summary>
        /// Builds a dictionary of name/value pairs.
        /// </summary>
        /// <param name="obj">The object to serialize.</param>
        /// <returns>
        /// An object that contains key/value pairs that represent the object’s data.
        /// </returns>
        /// <exception cref="ArgumentException">Invalid type;obj</exception>
        public IDictionary<string, object> Serialize(GameInfo info)
        {
            if (info == null)
                throw new ArgumentNullException("info cannot be null");

            var dict = new Dictionary<string, object>();

            dict["Hero"] = info.Hero;
            dict["Child"] = info.Child;
            dict["GameID"] = info.GameID;
            dict["Game"] = info.Game.ToString();
            dict["Animal"] = info.Animal.ToString();
            dict["Behavior"] = info.Behavior.ToString();
            dict["IsLinkedGame"] = info.IsLinkedGame;
            dict["IsHeroQuest"] = info.IsHeroQuest;
            dict["WasGivenFreeRing"] = info.WasGivenFreeRing;
            dict["Rings"] = (long)info.Rings;

            return dict;
        }
        /// <summary>
        /// Converts the provided dictionary into an object of the specified type.
        /// </summary>
        /// <param name="dictionary">An <see cref="T:System.Collections.Generic.IDictionary`2" /> instance of property data stored as name/value pairs.</param>
        /// <returns>
        /// The deserialized object.
        /// </returns>
        /// <exception cref="ArgumentNullException">dictionary</exception>
        public GameInfo Deserialize(IDictionary<string, object> dictionary)
        {
            if (dictionary == null)
                throw new ArgumentNullException("dictionary");

            GameInfo info = new GameInfo();

            info.Hero = dictionary.ReadValue<string>("Hero");
            info.Child = dictionary.ReadValue<string>("Child");
            info.IsHeroQuest = dictionary.ReadValue<bool>("IsHeroQuest");
            info.IsLinkedGame = dictionary.ReadValue<bool>("IsLinkedGame");
            info.WasGivenFreeRing = dictionary.ReadValue<bool>("WasGivenFreeRing");
            info.GameID = dictionary.ReadValue<short>("GameID");
            info.Rings = (Rings)dictionary.ReadValue<long>("Rings");
            info.Game = dictionary.ReadValue<Game>("Game");
            info.Animal = dictionary.ReadValue<Animal>("Animal");
            info.Behavior = dictionary.ReadValue<ChildBehavior>("Behavior");

            return info;
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MemorySecret"/> class.
 /// </summary>
 /// <param name="info">The game information.</param>
 /// <param name="memory">The memory.</param>
 /// <param name="isReturnSecret">if set to <c>true</c> [is return secret].</param>
 public MemorySecret(GameInfo info, Memory memory, bool isReturnSecret)
     : this(info.Game, info.GameID, memory, isReturnSecret)
 {
 }
Exemple #5
0
 /// <summary>
 /// Loads in data from the specified game info
 /// </summary>
 /// <param name="info">The game info</param>
 /// <remarks>
 /// Because <see cref="GameInfo"/> does not contain information about
 /// memories, only the properties <see cref="TargetGame"/> and
 /// <see cref="Secret.GameID"/> will be populated by this method.
 /// </remarks>
 /// <example>
 /// <code language="C#">
 /// GameInfo info = new GameInfo()
 /// {
 ///     Game = Game.Ages,
 ///     GameID = 14129
 /// };
 /// MemorySecret secret = new MemorySecret();
 /// secret.Load(info);
 /// </code>
 /// </example>
 public override void Load(GameInfo info)
 {
     TargetGame = info.Game;
     GameID = info.GameID;
 }
Exemple #6
0
 /// <summary>
 /// Loads in data from the specified game info
 /// </summary>
 /// <param name="info">The game info</param>
 public abstract void Load(GameInfo info);
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RingSecret"/> class from the
 /// specified game <paramref name="info"/>.
 /// </summary>
 /// <param name="info">The game information.</param>
 public RingSecret(GameInfo info)
 {
     Load(info);
 }
Exemple #8
0
        /// <summary>
        /// Updates the <see cref="GameInfo.Rings"/> property with the rings in this secret
        /// </summary>
        /// <param name="info">The information.</param>
        /// <param name="appendRings">
        /// If true, this will add the rings contained in the secret to the
        /// existings Rings. If false, it will overwrite them.
        /// </param>
        /// <exception cref="InvalidSecretException">
        /// The Game IDs of the secret and game info do not match.
        /// </exception>
        /// <example>
        /// <code language="C#">
        /// RingSecret secret = new RingSecret()
        /// {
        ///     GameID = 14129,
        ///     Rings = Rings.PowerRingL1 | Rings.DoubleEdgeRing | Rings.ProtectionRing
        /// };
        /// GameInfo info = new GameInfo() { GameID = 14129 };
        /// bool appendRings = true;
        /// secret.UpdateGameInfo(info, appendRings);
        /// </code>
        /// </example>
        public void UpdateGameInfo(GameInfo info, bool appendRings)
        {
            if(info.GameID != GameID)
                throw new InvalidSecretException("The Game IDs of the secret and game info do not match.");

            info.Rings = Rings | (appendRings ? info.Rings : Rings.None);
        }
Exemple #9
0
 /// <summary>
 /// Loads in data from the specified game info
 /// </summary>
 /// <param name="info">The game info</param>
 /// <example>
 /// <code language="C#">
 /// GameInfo info = new GameInfo()
 /// {
 ///     GameID = 14129,
 ///     Rings = Rings.PowerRingL1 | Rings.DoubleEdgeRing | Rings.ProtectionRing
 /// };
 /// RingSecret secret = new RingSecret();
 /// secret.Load(info);
 /// </code>
 /// </example>
 public override void Load(GameInfo info)
 {
     GameID = info.GameID;
     Rings = info.Rings;
 }
Exemple #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GameSecret"/> class from the
 /// specified game <paramref name="info"/>.
 /// </summary>
 /// <param name="info">The game information.</param>
 public GameSecret(GameInfo info)
     : base()
 {
     Load(info);
 }
Exemple #11
0
 /// <summary>
 /// Updates the game information.
 /// </summary>
 /// <param name="info">The information.</param>
 /// <example>
 /// <code language="C#">
 /// GameSecret secret = new GameSecret()
 /// {
 ///     TargetGame = Game.Ages,
 ///     GameID = 14129,
 ///     Hero = "Link",
 ///     Child = "Pip",
 ///     Animal = Animal.Dimitri,
 ///     Behavior = ChildBehavior.BouncyD,
 ///     IsLinkedGame = true,
 ///     IsHeroQuest = false,
 ///     WasGivenFreeRing = true
 /// };
 /// GameInfo info = new GameInfo();
 /// secret.UpdateGameInfo(info);
 /// </code>
 /// </example>
 public void UpdateGameInfo(GameInfo info)
 {
     info.GameID = GameID;
     info.Game = TargetGame;
     info.Hero = Hero;
     info.Child = Child;
     info.Animal = Animal;
     info.Behavior = Behavior;
     info.IsLinkedGame = IsLinkedGame;
     info.IsHeroQuest = IsHeroQuest;
     info.WasGivenFreeRing = WasGivenFreeRing;
     info.Unknown58 = Unknown58;
     info.Unknown59 = Unknown59;
     info.Unknown88 = Unknown88;
 }
Exemple #12
0
 /// <summary>
 /// Loads in data from the specified game info
 /// </summary>
 /// <param name="info">The game info</param>
 /// <example>
 /// <code language="C#">
 /// GameInfo info = new GameInfo()
 /// {
 ///     Game = Game.Ages,
 ///     GameID = 14129,
 ///     Hero = "Link",
 ///     Child = "Pip",
 ///     Animal = Animal.Dimitri,
 ///     Behavior = ChildBehavior.BouncyD,
 ///     IsLinkedGame = true,
 ///     IsHeroQuest = false,
 ///     WasGivenFreeRing = true
 /// };
 /// GameSecret secret = new GameSecret();
 /// secret.Load(info);
 /// </code>
 /// </example>
 public override void Load(GameInfo info)
 {
     GameID = info.GameID;
     TargetGame = info.Game;
     Hero = info.Hero;
     Child = info.Child;
     Animal = info.Animal;
     Behavior = info.Behavior;
     IsLinkedGame = info.IsLinkedGame;
     IsHeroQuest = info.IsHeroQuest;
     WasGivenFreeRing = info.WasGivenFreeRing;
     Unknown58 = info.Unknown58;
     Unknown59 = info.Unknown59;
     Unknown88 = info.Unknown88;
 }