Beispiel #1
0
    public static string EncodeShareCode(MatchSignature signature)
    {
        var bytes = new byte[19];

        Array.Copy(BitConverter.GetBytes(signature.matchId), 0, bytes, 1, 8);
        Array.Copy(BitConverter.GetBytes(signature.outcomeId), 0, bytes, 9, 8);
        Array.Copy(BitConverter.GetBytes((ushort)(signature.token & ((1 << 16) - 1))), 0, bytes, 17, 2);

        string output           = "";
        var    aVeryLargeNumber = new BigInteger(bytes.Reverse().ToArray());

        for (int i = 0; i < 25; i++)
        {
            int currentIndex = (int)(aVeryLargeNumber % DICTIONARY.Length);
            output           += DICTIONARY[currentIndex];
            aVeryLargeNumber /= DICTIONARY.Length;
        }

        output = "CSGO-" + output.Substring(0, 5) + "-" + output.Substring(5, 5) + "-" + output.Substring(10, 5) + "-" + output.Substring(15, 5) + "-" + output.Substring(20, 5);
        return(output);
    }
Beispiel #2
0
    public static MatchSignature DecodeShareCode(string sharecode)
    {
        MatchSignature decodedSignature = new MatchSignature();

        if (CheckShareCode(sharecode))
        {
            sharecode = sharecode.Replace("CSGO-", "");
            sharecode = sharecode.Replace("-", "");
            var aVeryLargeNumber = BigInteger.Zero;
            for (int i = sharecode.Length - 1; i >= 0; i--)
            {
                aVeryLargeNumber = aVeryLargeNumber * DICTIONARY.Length + DICTIONARY.IndexOf(sharecode[i]);
            }

            var bytes = aVeryLargeNumber.ToByteArray();
            // sometimes the number isn't unsigned, add a 00 byte at the end (the array is reversed later) of the array to make sure it is
            if (bytes.Length == 18)
            {
                bytes = bytes.Concat(new byte[] { 0 }).ToArray();
            }
            bytes = bytes.Reverse().ToArray();

            byte[] longContainer = new byte[8];
            Array.Copy(bytes, 1, longContainer, 0, 8);
            decodedSignature.matchId = BitConverter.ToUInt64(longContainer, 0);
            Array.Copy(bytes, 9, longContainer, 0, 8);
            decodedSignature.outcomeId = BitConverter.ToUInt64(longContainer, 0);
            Array.Copy(bytes, 17, longContainer, 0, 2);
            longContainer[2]       = 0;
            longContainer[3]       = 0;
            decodedSignature.token = BitConverter.ToUInt32(longContainer, 0);
        }
        else
        {
            Debug.LogError("MatchInfo: Error decoding sharecode, unknown format");
        }

        return(decodedSignature);
    }