Example #1
0
        private static int HandleIW4Stats(byte[] data, byte[] fileData, out string backupName)
        {
            var newData = new StructuredData("data/playerdata.xml");

            newData.SetData(data);

            backupName = null;

            if (true)
            {
                // TODO: more extensive checks than just experience
                var oldData = new StructuredData("data/playerdata.xml");

                oldData.SetData(fileData);

                var oldExperience = oldData.Get("experience").Get <int>();
                var newExperience = newData.Get("experience").Get <int>();

                var difference = newExperience - oldExperience;

                if (difference > 200000)
                {
                    //return 1;
                }

                var oldPrestige = oldData.Get("prestige").Get <int>();
                var newPrestige = newData.Get("prestige").Get <int>();

                difference = newPrestige - oldPrestige;

                if (newPrestige > 10)
                {
                    return(1);
                }

                //backupName = string.Format("{2}/iw4_{0}_{1}.stat", newPrestige, DateTime.UtcNow.ToString("yyyyMMdd"), Path.GetDirectoryName(fileName));
            }

            var has10th = newData.Get("iconUnlocked.cardicon_prestige10_02").Get <bool>();

            if (has10th)
            {
                return(1);
            }

            return(0);
        }
Example #2
0
        private void Handle(UpdateRequest request)
        {
            Log.Info("Handling profile update request for " + request.UserID.ToString("X16"));

            var filename = StorageUtils.GetFilename("iw4.stat", request.UserID);

            if (!File.Exists(filename))
            {
                return;
            }

            _structuredData.IW5 = true;
            _structuredData.SetData(File.ReadAllBytes(filename));

            var prestige   = _structuredData.Get("prestige").Get <int>();
            var experience = _structuredData.Get("experience").Get <int>();
            var cardicon   = _structuredData.Get("cardIcon").Get <string>();
            var cardtitle  = _structuredData.Get("cardTitle").Get <string>();

            var shortUserID = (int)(request.UserID & 0xFFFFFFFF);
            var profileData = new IW4Profiles();
            var isNew       = true;

            var query = from profile in Database.IW4Profiles
                        where profile.UserID == shortUserID
                        select profile;

            if (query.Count() > 0)
            {
                profileData = query.First();
                isNew       = false;
            }

            profileData.UserID     = shortUserID;
            profileData.Prestige   = (sbyte)prestige;
            profileData.Experience = experience;
            profileData.CardIcon   = cardicon;
            profileData.CardTitle  = cardtitle;

            if (isNew)
            {
                Database.IW4Profiles.InsertOnSubmit(profileData);
            }

            Database.SubmitChanges();
        }
Example #3
0
        private static int HandleIW5Stats(byte[] data, byte[] fileData, out string backupName)
        {
            var newData = new StructuredData("data/playerdata_iw5.xml");

            newData.SetData(data);

            backupName = null;

            if (true)
            {
                // TODO: more extensive checks than just experience
                var oldData = new StructuredData("data/playerdata_iw5.xml");

                oldData.SetData(fileData);

                var oldExperience = oldData.Get("experience").Get <int>();
                var newExperience = newData.Get("experience").Get <int>();

                var difference = newExperience - oldExperience;

                if (difference > 200000)
                {
                    return(1);
                }

                var oldPrestige = oldData.Get("prestige").Get <int>();
                var newPrestige = newData.Get("prestige").Get <int>();

                difference = newPrestige - oldPrestige;

                if (difference > 1 || newPrestige > 20)
                {
                    return(1);
                }

                if (difference == 1 && oldExperience < 1695700)
                {
                    return(1);
                }

                //backupName = string.Format("{2}/mpdata_{0}_{1}", newPrestige, DateTime.UtcNow.ToString("yyyyMMdd"), Path.GetDirectoryName(fileName));
            }

            var element = newData.Trace(new[] { "extraCustomClassesEntitlement" });

            data[element.Offset + 4] = 10;

            new[] { "weaponXPMultiplier", "xpMultiplier" }.ToList().ForEach(key =>
            {
                for (int i = 0; i < 1; i++)
                {
                    var el = newData.Trace(new[] { key, i.ToString() });
                    Array.Copy(BitConverter.GetBytes(4), 0, data, el.Offset + 4, 4);

                    el = newData.Trace(new[] { key + "TimePlayed", i.ToString() });
                    Array.Copy(BitConverter.GetBytes(0), 0, data, el.Offset + 4, 4);

                    el = newData.Trace(new[] { key.Replace("Multiplier", "MaxMultiplier") + "TimePlayed", i.ToString() });
                    Array.Copy(BitConverter.GetBytes(int.MaxValue), 0, data, el.Offset + 4, 4);
                }
            });

            element = newData.Trace(new[] { "challengeXPMultiplier", "0" });
            Array.Copy(BitConverter.GetBytes(1), 0, data, element.Offset + 4, 4);

            element = newData.Trace(new[] { "xpMultiplier", "1" });
            Array.Copy(BitConverter.GetBytes(0), 0, data, element.Offset + 4, 4);

            element = newData.Trace(new[] { "xpMultiplier", "2" });
            Array.Copy(BitConverter.GetBytes(0), 0, data, element.Offset + 4, 4);

            //element = newData.Trace(new[] { "experience" });
            //Array.Copy(BitConverter.GetBytes(1000000), 0, data, element.Offset + 4, 4);

            var checksumBytes = new byte[data.Length - 4];

            Array.Copy(data, 4, checksumBytes, 0, checksumBytes.Length);
            var checksum = Crc32.Compute(checksumBytes);

            Array.Copy(BitConverter.GetBytes(checksum), 0, data, 0, 4);

            return(0);
        }