少年修仙传客户端代码仓库
client_Zxw
2019-03-04 6beea42305d7bae180f5ec6769f3e9daca3d849c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
namespace NSpeex
{
    using System;
 
    internal class Bits
    {
        private int bitPtr = 0;
        private int bytePtr = 0;
        private byte[] bytes = new byte[0x400];
        public const int DefaultBufferSize = 0x400;
        private int nbBits;
 
        public void Advance(int n)
        {
            this.bytePtr += n >> 3;
            this.bitPtr += n & 7;
            if (this.bitPtr > 7)
            {
                this.bitPtr -= 8;
                this.bytePtr++;
            }
        }
 
        public int BitsRemaining {  get { return (this.nbBits - ((this.bytePtr * 8) + this.bitPtr)); } }
 
        public void InsertTerminator()
        {
            if (this.bitPtr > 0)
            {
                this.Pack(0, 1);
            }
            while (this.bitPtr != 0)
            {
                this.Pack(1, 1);
            }
        }
 
        public void Pack(int data, int nbBits)
        {
            int num = data;
            while ((this.bytePtr + ((nbBits + this.bitPtr) >> 3)) >= this.bytes.Length)
            {
                int num2 = this.bytes.Length * 2;
                byte[] destinationArray = new byte[num2];
                Array.Copy(this.bytes, 0, destinationArray, 0, this.bytes.Length);
                this.bytes = destinationArray;
            }
            while (nbBits > 0)
            {
                int num3 = (num >> (nbBits - 1)) & 1;
                this.bytes[this.bytePtr] = (byte)(this.bytes[this.bytePtr] | ((byte)(num3 << (7 - this.bitPtr))));
                this.bitPtr++;
                if (this.bitPtr == 8)
                {
                    this.bitPtr = 0;
                    this.bytePtr++;
                }
                nbBits--;
            }
        }
 
        public int Peek { get { return (((this.bytes[this.bytePtr] & 0xff) >> (7 - this.bitPtr)) & 1); } }
 
        public void ReadFrom(byte[] newbytes, int offset, int len)
        {
            for (int i = 0; i < len; i++)
            {
                this.bytes[i] = newbytes[offset + i];
            }
            this.bytePtr = 0;
            this.bitPtr = 0;
            this.nbBits = len * 8;
        }
 
        public void Reset()
        {
            Array.Clear(this.bytes, 0, this.bytes.Length);
            this.bytePtr = 0;
            this.bitPtr = 0;
        }
 
        public int Unpack(int nbBits)
        {
            int num = 0;
            while (nbBits != 0)
            {
                num = num << 1;
                num |= ((this.bytes[this.bytePtr] & 0xff) >> (7 - this.bitPtr)) & 1;
                this.bitPtr++;
                if (this.bitPtr == 8)
                {
                    this.bitPtr = 0;
                    this.bytePtr++;
                }
                nbBits--;
            }
            return num;
        }
 
        public int Write(byte[] buffer, int offset, int maxBytes)
        {
            int bitPtr = this.bitPtr;
            int bytePtr = this.bytePtr;
            byte[] bytes = this.bytes;
            this.InsertTerminator();
            this.bitPtr = bitPtr;
            this.bytePtr = bytePtr;
            this.bytes = bytes;
            if (maxBytes > this.BufferSize)
            {
                maxBytes = this.BufferSize;
            }
            Array.Copy(this.bytes, 0, buffer, offset, maxBytes);
            return maxBytes;
        }
 
        public int BufferSize { get { return (this.bytePtr + ((this.bitPtr > 0) ? 1 : 0)); } }
    }
}