def encode(self, fields, player):
    ownedBrawlersCount = len(player.OwnedBrawlers)
    ownedPinsCount = len(player.OwnedPins)
    ownedThumbnailCount = len(player.OwnedThumbnails)
    ownedSkins = []
    for brawlerInfo in player.OwnedBrawlers.values():
        try:
            ownedSkins.extend(brawlerInfo['Skins'])
        except KeyError:
            continue
    self.writeVint(int(time.time()))
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(player.Trophies)
    self.writeVint(player.HighestTrophies)
    self.writeVint(player.HighestTrophies)
    self.writeVint(player.TrophyRoadTier)
    self.writeVint(player.Experience)
    self.writeDataReference(28, player.Thumbnail)
    self.writeDataReference(43, player.Namecolor)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(len(ownedSkins))
    for skinID in ownedSkins:
        self.writeDataReference(29, skinID)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(player.HighestTrophies)
    self.writeVint(0)
    self.writeVint(1)
    self.writeBoolean(True)
    self.writeVint(player.TokensDoubler)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(141)
    self.writeVint(135)
    self.writeVint(5)
    self.writeVint(93)
    self.writeVint(206)
    self.writeVint(456)
    self.writeVint(792)
    self.writeVint(729)
    self.writeBoolean(False)
    self.writeBoolean(False)
    self.writeBoolean(True)
    self.writeVint(2)
    self.writeVint(2)
    self.writeVint(2)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(1)
    self.writeVint(1)
    for i in range(1):
        self.writeVint(6)
        self.writeVint(0)
        self.writeDataReference(0)
        self.writeVint(0)
    self.writeVint(0)
    self.writeVint(666)
    self.writeVint(950400)
    self.writeVint(2)
    self.writeVint(0)
    self.writeBoolean(False)
    self.writeVint(3917)
    self.writeVint(0)
    self.writeBoolean(False)
    self.writeVint(49)
    self.writeInt(0)
    self.writeString('Unlock all skins')
    self.writeBoolean(False)
    self.writeString()
    self.writeVint((- 1))
    self.writeBoolean(False)
    self.writeVint(0)
    self.writeVint(0)
    self.writeString()
    self.writeBoolean(False)
    self.writeBoolean(False)
    self.writeVint(0)
    self.writeVint(player.Tokens)
    self.writeVint((- 1))
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(len(player.SelectedBrawlers))
    for i in player.SelectedBrawlers:
        self.writeDataReference(16, i)
    self.writeString(player.Region)
    self.writeString(player.ContentCreator)
    self.writeVint(19)
    self.writeLong(2, 1)
    self.writeLong(3, 0)
    self.writeLong(4, 0)
    self.writeLong(6, 0)
    self.writeLong(7, 0)
    self.writeLong(8, 0)
    self.writeLong(9, 1)
    self.writeLong(10, 0)
    self.writeLong(12, 1)
    self.writeLong(14, 0)
    self.writeLong(15, 0)
    self.writeLong(16, 1)
    self.writeLong(17, 1)
    self.writeLong(18, 1)
    self.writeLong(19, 1)
    self.writeLong(20, 0)
    self.writeLong(21, 1)
    self.writeLong(22, 1)
    self.writeLong(24, 1)
    self.writeVint(0)
    self.writeVint(2)
    for i in range(8, 10):
        self.writeVint(i)
        self.writeVint(34500)
        self.writeBoolean(True)
        self.writeVint(0)
        self.writeUInt8(2)
        self.writeUInt(4294967292)
        self.writeUInt(4294967295)
        self.writeUInt(511)
        self.writeUInt(0)
        self.writeUInt8(1)
        self.writeUInt(4294967292)
        self.writeUInt(4294967295)
        self.writeUInt(511)
        self.writeUInt(0)
    self.writeVint(0)
    self.writeBoolean(True)
    self.writeVint(0)
    self.writeBoolean(True)
    self.writeVint((ownedPinsCount + ownedThumbnailCount))
    for i in player.OwnedPins:
        self.writeDataReference(52, i)
        self.writeVint(1)
        for i in range(1):
            self.writeVint(1)
            self.writeVint(1)
    for i in player.OwnedThumbnails:
        self.writeDataReference(28, i)
        self.writeVint(1)
        for i in range(1):
            self.writeVint(1)
            self.writeVint(1)
    self.writeBoolean(False)
    self.writeInt(0)
    self.writeVint(0)
    self.writeVint(25)
    self.writeVint(1)
    self.writeVint(2)
    self.writeVint(3)
    self.writeVint(4)
    self.writeVint(5)
    self.writeVint(6)
    self.writeVint(7)
    self.writeVint(8)
    self.writeVint(9)
    self.writeVint(10)
    self.writeVint(11)
    self.writeVint(12)
    self.writeVint(13)
    self.writeVint(14)
    self.writeVint(15)
    self.writeVint(16)
    self.writeVint(17)
    self.writeVint(20)
    self.writeVint(21)
    self.writeVint(22)
    self.writeVint(23)
    self.writeVint(24)
    self.writeVint(30)
    self.writeVint(31)
    self.writeVint(32)
    self.writeVint(3)
    eventIndex = 1
    for i in [5, 7, 24]:
        self.writeVint((- 1))
        self.writeVint(eventIndex)
        self.writeVint(0)
        self.writeVint(51208)
        self.writeVint(0)
        self.writeDataReference(15, i)
        self.writeVint((- 1))
        self.writeVint(2)
        self.writeString()
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeBoolean(False)
        self.writeVint(0)
        self.writeBoolean(False)
        self.writeVint(0)
        self.writeVint(0)
        self.writeBoolean(False)
        self.writeBoolean(False)
        self.writeBoolean(False)
        self.writeVint((- 1))
        self.writeBoolean(False)
        self.writeBoolean(False)
        eventIndex += 1
    self.writeVint(0)
    self.writeVint(10)
    self.writeVint(20)
    self.writeVint(35)
    self.writeVint(75)
    self.writeVint(140)
    self.writeVint(290)
    self.writeVint(480)
    self.writeVint(800)
    self.writeVint(1250)
    self.writeVint(1875)
    self.writeVint(2800)
    self.writeVint(4)
    self.writeVint(20)
    self.writeVint(50)
    self.writeVint(140)
    self.writeVint(280)
    self.writeVint(4)
    self.writeVint(150)
    self.writeVint(400)
    self.writeVint(1200)
    self.writeVint(2600)
    self.writeBoolean(True)
    self.writeVint(0)
    self.writeVint(23)
    self.writeLong(10008, 501)
    self.writeLong(65, 2)
    self.writeLong(1, 41000036)
    self.writeLong(60, 36270)
    self.writeLong(66, 1)
    self.writeLong(61, 36270)
    self.writeLong(47, 41381)
    self.writeLong(29, 0)
    self.writeLong(48, 41381)
    self.writeLong(50, 0)
    self.writeLong(1100, 500)
    self.writeLong(1101, 500)
    self.writeLong(1003, 1)
    self.writeLong(36, 0)
    self.writeLong(14, 0)
    self.writeLong(31, 0)
    self.writeLong(79, 149999)
    self.writeLong(80, 160000)
    self.writeLong(28, 4)
    self.writeLong(74, 1)
    self.writeLong(78, 1)
    self.writeLong(17, 4)
    self.writeLong(10046, 1)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeLong(player.ID[0], player.ID[1])
    self.writeVint(0)
    self.writeVint((- 1))
    self.writeBoolean(False)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVLong(player.ID[0], player.ID[1])
    self.writeVLong(0, 0)
    self.writeVLong(0, 0)
    self.writeString(player.Name)
    self.writeBoolean(player.Registered)
    self.writeInt(0)
    self.writeVint(15)
    self.writeVint((3 + ownedBrawlersCount))
    for brawlerInfo in player.OwnedBrawlers.values():
        self.writeDataReference(23, brawlerInfo['CardID'])
        self.writeVint(1)
    self.writeDataReference(5, 8)
    self.writeVint(player.Coins)
    self.writeDataReference(5, 10)
    self.writeVint(player.StarPoints)
    self.writeDataReference(5, 13)
    self.writeVint(99999)
    self.writeVint(ownedBrawlersCount)
    for (brawlerID, brawlerInfo) in player.OwnedBrawlers.items():
        self.writeDataReference(16, brawlerID)
        self.writeVint(brawlerInfo['Trophies'])
    self.writeVint(ownedBrawlersCount)
    for (brawlerID, brawlerInfo) in player.OwnedBrawlers.items():
        self.writeDataReference(16, brawlerID)
        self.writeVint(brawlerInfo['HighestTrophies'])
    self.writeVint(0)
    self.writeVint(ownedBrawlersCount)
    for (brawlerID, brawlerInfo) in player.OwnedBrawlers.items():
        self.writeDataReference(16, brawlerID)
        self.writeVint(brawlerInfo['PowerPoints'])
    self.writeVint(ownedBrawlersCount)
    for (brawlerID, brawlerInfo) in player.OwnedBrawlers.items():
        self.writeDataReference(16, brawlerID)
        self.writeVint((brawlerInfo['PowerLevel'] - 1))
    self.writeVint(0)
    self.writeVint(ownedBrawlersCount)
    for (brawlerID, brawlerInfo) in player.OwnedBrawlers.items():
        self.writeDataReference(16, brawlerID)
        self.writeVint(brawlerInfo['State'])
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(player.Gems)
    self.writeVint(player.Gems)
    self.writeVint(player.Level)
    self.writeVint(100)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(2)
    self.writeVint(0)
def encode(self, fields, player):
    ownedBrawlersCount = len(player.OwnedBrawlers)
    ownedPinsCount = len(player.OwnedPins)
    ownedThumbnailCount = len(player.OwnedThumbnails)
    ownedSkins = []
    for brawlerInfo in player.OwnedBrawlers.values():
        try:
            ownedSkins.extend(brawlerInfo['Skins'])
        except KeyError:
            continue
    self.writeVint(int(time.time()))
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(player.Trophies)
    self.writeVint(player.HighestTrophies)
    self.writeVint(player.HighestTrophies)
    self.writeVint(player.TrophyRoadTier)
    self.writeVint(player.Experience)
    self.writeDataReference(28, player.Thumbnail)
    self.writeDataReference(43, player.Namecolor)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(len(ownedSkins))
    for skinID in ownedSkins:
        self.writeDataReference(29, skinID)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(player.HighestTrophies)
    self.writeVint(0)
    self.writeVint(1)
    self.writeBoolean(True)
    self.writeVint(player.TokensDoubler)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(141)
    self.writeVint(135)
    self.writeVint(5)
    self.writeVint(93)
    self.writeVint(206)
    self.writeVint(456)
    self.writeVint(792)
    self.writeVint(729)
    self.writeBoolean(False)
    self.writeBoolean(False)
    self.writeBoolean(True)
    self.writeVint(2)
    self.writeVint(2)
    self.writeVint(2)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(1)
    self.writeVint(1)
    for i in range(1):
        self.writeVint(6)
        self.writeVint(0)
        self.writeDataReference(0)
        self.writeVint(0)
    self.writeVint(0)
    self.writeVint(666)
    self.writeVint(950400)
    self.writeVint(2)
    self.writeVint(0)
    self.writeBoolean(False)
    self.writeVint(3917)
    self.writeVint(0)
    self.writeBoolean(False)
    self.writeVint(49)
    self.writeInt(0)
    self.writeString('Unlock all skins')
    self.writeBoolean(False)
    self.writeString()
    self.writeVint((- 1))
    self.writeBoolean(False)
    self.writeVint(0)
    self.writeVint(0)
    self.writeString()
    self.writeBoolean(False)
    self.writeBoolean(False)
    self.writeVint(0)
    self.writeVint(player.Tokens)
    self.writeVint((- 1))
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(len(player.SelectedBrawlers))
    for i in player.SelectedBrawlers:
        self.writeDataReference(16, i)
    self.writeString(player.Region)
    self.writeString(player.ContentCreator)
    self.writeVint(19)
    self.writeLong(2, 1)
    self.writeLong(3, 0)
    self.writeLong(4, 0)
    self.writeLong(6, 0)
    self.writeLong(7, 0)
    self.writeLong(8, 0)
    self.writeLong(9, 1)
    self.writeLong(10, 0)
    self.writeLong(12, 1)
    self.writeLong(14, 0)
    self.writeLong(15, 0)
    self.writeLong(16, 1)
    self.writeLong(17, 1)
    self.writeLong(18, 1)
    self.writeLong(19, 1)
    self.writeLong(20, 0)
    self.writeLong(21, 1)
    self.writeLong(22, 1)
    self.writeLong(24, 1)
    self.writeVint(0)
    self.writeVint(2)
    for i in range(8, 10):
        self.writeVint(i)
        self.writeVint(34500)
        self.writeBoolean(True)
        self.writeVint(0)
        self.writeUInt8(2)
        self.writeUInt(4294967292)
        self.writeUInt(4294967295)
        self.writeUInt(511)
        self.writeUInt(0)
        self.writeUInt8(1)
        self.writeUInt(4294967292)
        self.writeUInt(4294967295)
        self.writeUInt(511)
        self.writeUInt(0)
    self.writeVint(0)
    self.writeBoolean(True)
    self.writeVint(0)
    self.writeBoolean(True)
    self.writeVint((ownedPinsCount + ownedThumbnailCount))
    for i in player.OwnedPins:
        self.writeDataReference(52, i)
        self.writeVint(1)
        for i in range(1):
            self.writeVint(1)
            self.writeVint(1)
    for i in player.OwnedThumbnails:
        self.writeDataReference(28, i)
        self.writeVint(1)
        for i in range(1):
            self.writeVint(1)
            self.writeVint(1)
    self.writeBoolean(False)
    self.writeInt(0)
    self.writeVint(0)
    self.writeVint(25)
    self.writeVint(1)
    self.writeVint(2)
    self.writeVint(3)
    self.writeVint(4)
    self.writeVint(5)
    self.writeVint(6)
    self.writeVint(7)
    self.writeVint(8)
    self.writeVint(9)
    self.writeVint(10)
    self.writeVint(11)
    self.writeVint(12)
    self.writeVint(13)
    self.writeVint(14)
    self.writeVint(15)
    self.writeVint(16)
    self.writeVint(17)
    self.writeVint(20)
    self.writeVint(21)
    self.writeVint(22)
    self.writeVint(23)
    self.writeVint(24)
    self.writeVint(30)
    self.writeVint(31)
    self.writeVint(32)
    self.writeVint(3)
    eventIndex = 1
    for i in [5, 7, 24]:
        self.writeVint((- 1))
        self.writeVint(eventIndex)
        self.writeVint(0)
        self.writeVint(51208)
        self.writeVint(0)
        self.writeDataReference(15, i)
        self.writeVint((- 1))
        self.writeVint(2)
        self.writeString()
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeBoolean(False)
        self.writeVint(0)
        self.writeBoolean(False)
        self.writeVint(0)
        self.writeVint(0)
        self.writeBoolean(False)
        self.writeBoolean(False)
        self.writeBoolean(False)
        self.writeVint((- 1))
        self.writeBoolean(False)
        self.writeBoolean(False)
        eventIndex += 1
    self.writeVint(0)
    self.writeVint(10)
    self.writeVint(20)
    self.writeVint(35)
    self.writeVint(75)
    self.writeVint(140)
    self.writeVint(290)
    self.writeVint(480)
    self.writeVint(800)
    self.writeVint(1250)
    self.writeVint(1875)
    self.writeVint(2800)
    self.writeVint(4)
    self.writeVint(20)
    self.writeVint(50)
    self.writeVint(140)
    self.writeVint(280)
    self.writeVint(4)
    self.writeVint(150)
    self.writeVint(400)
    self.writeVint(1200)
    self.writeVint(2600)
    self.writeBoolean(True)
    self.writeVint(0)
    self.writeVint(23)
    self.writeLong(10008, 501)
    self.writeLong(65, 2)
    self.writeLong(1, 41000036)
    self.writeLong(60, 36270)
    self.writeLong(66, 1)
    self.writeLong(61, 36270)
    self.writeLong(47, 41381)
    self.writeLong(29, 0)
    self.writeLong(48, 41381)
    self.writeLong(50, 0)
    self.writeLong(1100, 500)
    self.writeLong(1101, 500)
    self.writeLong(1003, 1)
    self.writeLong(36, 0)
    self.writeLong(14, 0)
    self.writeLong(31, 0)
    self.writeLong(79, 149999)
    self.writeLong(80, 160000)
    self.writeLong(28, 4)
    self.writeLong(74, 1)
    self.writeLong(78, 1)
    self.writeLong(17, 4)
    self.writeLong(10046, 1)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeLong(player.ID[0], player.ID[1])
    self.writeVint(0)
    self.writeVint((- 1))
    self.writeBoolean(False)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVLong(player.ID[0], player.ID[1])
    self.writeVLong(0, 0)
    self.writeVLong(0, 0)
    self.writeString(player.Name)
    self.writeBoolean(player.Registered)
    self.writeInt(0)
    self.writeVint(15)
    self.writeVint((3 + ownedBrawlersCount))
    for brawlerInfo in player.OwnedBrawlers.values():
        self.writeDataReference(23, brawlerInfo['CardID'])
        self.writeVint(1)
    self.writeDataReference(5, 8)
    self.writeVint(player.Coins)
    self.writeDataReference(5, 10)
    self.writeVint(player.StarPoints)
    self.writeDataReference(5, 13)
    self.writeVint(99999)
    self.writeVint(ownedBrawlersCount)
    for (brawlerID, brawlerInfo) in player.OwnedBrawlers.items():
        self.writeDataReference(16, brawlerID)
        self.writeVint(brawlerInfo['Trophies'])
    self.writeVint(ownedBrawlersCount)
    for (brawlerID, brawlerInfo) in player.OwnedBrawlers.items():
        self.writeDataReference(16, brawlerID)
        self.writeVint(brawlerInfo['HighestTrophies'])
    self.writeVint(0)
    self.writeVint(ownedBrawlersCount)
    for (brawlerID, brawlerInfo) in player.OwnedBrawlers.items():
        self.writeDataReference(16, brawlerID)
        self.writeVint(brawlerInfo['PowerPoints'])
    self.writeVint(ownedBrawlersCount)
    for (brawlerID, brawlerInfo) in player.OwnedBrawlers.items():
        self.writeDataReference(16, brawlerID)
        self.writeVint((brawlerInfo['PowerLevel'] - 1))
    self.writeVint(0)
    self.writeVint(ownedBrawlersCount)
    for (brawlerID, brawlerInfo) in player.OwnedBrawlers.items():
        self.writeDataReference(16, brawlerID)
        self.writeVint(brawlerInfo['State'])
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(player.Gems)
    self.writeVint(player.Gems)
    self.writeVint(player.Level)
    self.writeVint(100)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(0)
    self.writeVint(2)
    self.writeVint(0)