示例#1
0
 public void writeToSave(KnyttSave save)
 {
     for (int i = 0; i < Powers.Length; i++)
     {
         save.setPower(i, Powers[i]);
     }
     for (int i = 0; i < Flags.Length; i++)
     {
         save.setFlag(i, Flags[i]);
     }
     save.setCollectables(Collectables, CoinsSpent);
     save.VisitedAreas = VisitedAreas;
     save.Attachment   = Attachment;
     save.Cutscenes    = Cutscenes;
     save.Endings      = Endings;
 }
示例#2
0
 public void readFromSave(KnyttSave save)
 {
     for (int i = 0; i < Powers.Length; i++)
     {
         Powers[i] = save.getPower(i);
     }
     for (int i = 0; i < Flags.Length; i++)
     {
         Flags[i] = save.getFlag(i);
     }
     save.getCollectables(out var collectables, out var coins_spent);
     Collectables = collectables;
     CoinsSpent   = coins_spent;
     VisitedAreas = save.VisitedAreas;
     Attachment   = save.Attachment;
     Cutscenes    = save.Cutscenes;
     Endings      = save.Endings;
 }
示例#3
0
        public static KnyttSave FromBinary(KnyttWorld world, byte[] data, bool slim = false)
        {
            var save = new KnyttSave(world);

            int bposition = 0;

            if (!slim)
            {
                var y = data[bposition++];
                var k = data[bposition++];
                if (y != 'Y' || k != 'K')
                {
                    throw new SystemException("Magic number YK not present");
                }
            }

            using (SHA1Managed sha1 = new SHA1Managed())
            {
                var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(save.getWorldDirectory()));
                for (int i = 0; i < (slim ? SLIM_HASH_BYTES : HASH_BYTES); i++)
                {
                    if (!(hash[i] == data[bposition++]))
                    {
                        throw new SystemException("World name hash doesn't match.");
                    }
                }
            }

            save.setArea(new KnyttPoint((int)new VarInt(data, ref bposition).Value + 1000,
                                        (int)new VarInt(data, ref bposition).Value + 1000));

            int bitpack = (int)new VarInt(data, ref bposition).Value;

            save.setAreaPosition(new KnyttPoint(bitpack & 0x1F, (bitpack & (0xF << 5)) >> 5));

            JuniValues values = new JuniValues();

            BinaryTools.readBoolArray(bitpack, values.Powers, 9);
            BinaryTools.readBoolArray(bitpack, values.Flags, 21);
            values.writeToSave(save);

            return(save);
        }
示例#4
0
 public JuniValues(KnyttSave save) : this()
 {
     readFromSave(save);
 }