コード例 #1
0
        /// <summary>
        /// Loads in data from the raw secret data provided
        /// </summary>
        /// <param name="secret">The raw secret data</param>
        /// <example>
        /// This example demonstrates loading a <see cref="GameSecret"/> from a
        /// a byte array containing an encoded secret.
        /// <code language="C#">
        /// // H~2:@ ←2♦yq GB3●( 6♥?↑6
        /// byte[] rawSecret = new byte[]
        /// {
        ///      4, 37, 51, 36, 63,
        ///     61, 51, 10, 44, 39,
        ///      3,  0, 52, 21, 48,
        ///     55,  9, 45, 59, 55
        /// };
        /// Secret secret = new GameSecret();
        /// secret.Load(rawSecret);
        /// </code>
        /// </example>
        public override void Load(byte[] secret)
        {
            if (secret == null || secret.Length != Length)
            {
                throw new InvalidSecretException("Secret must contatin exactly 20 bytes");
            }

            byte[] decodedBytes  = DecodeBytes(secret);
            string decodedSecret = ByteArrayToBinaryString(decodedBytes);

            byte[] clonedBytes = (byte[])decodedBytes.Clone();
            clonedBytes[19] = 0;
            var checksum = CalculateChecksum(clonedBytes);

            if ((decodedBytes[19] & 7) != (checksum & 7))
            {
                throw new InvalidSecretException("Checksum does not match expected value");
            }

            GameID = Convert.ToInt16(decodedSecret.ReversedSubstring(5, 15), 2);

            if (decodedSecret[3] != '0' && decodedSecret[4] != '0')
            {
                throw new ArgumentException("The specified data is not a game code", "secret");
            }

            TargetGame   = (Game)(byte)(decodedSecret[21] == '1' ? 1 : 0);
            IsHeroQuest  = decodedSecret[20] == '1';
            IsLinkedGame = decodedSecret[105] == '1';


            Hero = System.Text.Encoding.ASCII.GetString(new byte[] {
                Convert.ToByte(decodedSecret.ReversedSubstring(22, 8), 2),
                Convert.ToByte(decodedSecret.ReversedSubstring(38, 8), 2),
                Convert.ToByte(decodedSecret.ReversedSubstring(60, 8), 2),
                Convert.ToByte(decodedSecret.ReversedSubstring(77, 8), 2),
                Convert.ToByte(decodedSecret.ReversedSubstring(89, 8), 2)
            });

            Child = System.Text.Encoding.ASCII.GetString(new byte[] {
                Convert.ToByte(decodedSecret.ReversedSubstring(30, 8), 2),
                Convert.ToByte(decodedSecret.ReversedSubstring(46, 8), 2),
                Convert.ToByte(decodedSecret.ReversedSubstring(68, 8), 2),
                Convert.ToByte(decodedSecret.ReversedSubstring(97, 8), 2),
                Convert.ToByte(decodedSecret.ReversedSubstring(106, 8), 2)
            });

            // It should be noted that if we include the unknown bit at location 88 with the
            // animal bytes, then the values will match those in the game's save file.
            // Perhaps they are the actual values.
            Animal   = (Animal)Convert.ToByte(decodedSecret.ReversedSubstring(85, 3), 2);
            Behavior = (ChildBehavior)Convert.ToByte(decodedSecret.ReversedSubstring(54, 4), 2);


            // TODO: Figure out what all the unknown values are for.
            bool unknown1 = decodedSecret[58] == '1';
            bool unknown2 = decodedSecret[59] == '1';
            bool unknown3 = decodedSecret[76] == '1';
            bool unknown4 = decodedSecret[88] == '1';
        }
コード例 #2
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
 /// };
 /// 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;
 }
コード例 #3
0
        private void CalculateBehavior()
        {
            RupeesGiven   rupeesGiven   = 0;
            SleepMethod   method        = 0;
            KindOfChild   kindOfChild   = 0;
            ChildQuestion childQuestion = 0;

            RadioButton radioButton = ugRupeesGiven.Children.OfType <RadioButton>().FirstOrDefault(r => r.IsChecked ?? false);

            if (radioButton != null)
            {
                Enum.TryParse(radioButton.Tag.ToString(), out rupeesGiven);
            }

            radioButton = ugSleepMethod.Children.OfType <RadioButton>().FirstOrDefault(r => r.IsChecked ?? false);
            if (radioButton != null)
            {
                Enum.TryParse(radioButton.Tag.ToString(), out method);
            }

            radioButton = ugKindOfChild.Children.OfType <RadioButton>().FirstOrDefault(r => r.IsChecked ?? false);
            if (radioButton != null)
            {
                Enum.TryParse(radioButton.Tag.ToString(), out kindOfChild);
            }

            radioButton = ugChildQuestion.Children.OfType <RadioButton>().FirstOrDefault(r => r.IsChecked ?? false);
            if (radioButton != null)
            {
                Enum.TryParse(radioButton.Tag.ToString(), out childQuestion);
            }

            CalculatedTotal    = ChildBehaviorHelper.GetValue(_gameInfo?.Region ?? GameRegion.US, txtChildName.Text, rupeesGiven, method, childQuestion, kindOfChild);
            CalculatedBehavior = ChildBehaviorHelper.GetBehavior(CalculatedTotal);

            if (_gameInfo != null)
            {
                _gameInfo.Child    = txtChildName.Text;
                _gameInfo.Behavior = CalculatedTotal;
            }
        }
コード例 #4
0
    // Use this for initialization
    void Start()
    {
        if (prefab == null)
        {
            // end early
            Debug.Log("Please assign a drone prefab.");
            return;
        }

        // instantiate the drones
        GameObject    droneTemp;
        ChildBehavior db = null;

        drones = new List <GameObject>();

        for (int i = 0; i < droneCount; i++)
        {
            droneTemp      = (GameObject)GameObject.Instantiate(prefab);
            droneTemp.name = "Child " + i;
            db             = droneTemp.GetComponent <ChildBehavior>();
            db.drones      = this.drones;
            db.swarm       = this;

            // spawn inside circle
            Vector2 pos = new Vector2(transform.position.x, transform.position.z) + Random.insideUnitCircle * spawnRadius;
            droneTemp.transform.position = new Vector3(pos.x, transform.position.y, pos.y);
            droneTemp.transform.parent   = transform;
            drones.Add(droneTemp);

            db.maxRunSpeed = 3.0f + 1.5f * Random.value * Random.value;
            db.baseSpeed   = db.maxRunSpeed * 0.75f;
        }

        /*
         *      droneTemp = drones[(int)(Random.value * drones.Count)];
         *      ChildBehavior.hunter = droneTemp;
         *      droneTemp.GetComponent<Renderer>().material.SetColor("_Color", Color.red);*/
    }