少年修仙传客户端基础资源
dabaoji
2025-06-09 8ee0256378cbf5dbc9d76ed10b60b65a844ef4dd
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
//----------------------------------------------
//            NGUI: Next-Gen UI kit
// Copyright © 2011-2014 Tasharen Entertainment
//----------------------------------------------
 
using UnityEngine;
using System.Text;
using System.Collections.Generic;
 
/// <summary>
/// MemoryStream.ReadLine has an interesting oddity: it doesn't always advance the stream's position by the correct amount:
/// http://social.msdn.microsoft.com/Forums/en-AU/Vsexpressvcs/thread/b8f7837b-e396-494e-88e1-30547fcf385f
/// Solution? Custom line reader with the added benefit of not having to use streams at all.
/// </summary>
 
public class ByteReader
{
    byte[] mBuffer;
    int mOffset = 0;
 
    public ByteReader (byte[] bytes) { mBuffer = bytes; }
    public ByteReader (TextAsset asset) { mBuffer = asset.bytes; }
 
    /// <summary>
    /// Whether the buffer is readable.
    /// </summary>
 
    public bool canRead { get { return (mBuffer != null && mOffset < mBuffer.Length); } }
 
    /// <summary>
    /// Read a single line from the buffer.
    /// </summary>
 
    static string ReadLine (byte[] buffer, int start, int count)
    {
#if UNITY_FLASH
        // Encoding.UTF8 is not supported in Flash :(
        StringBuilder sb = new StringBuilder();
 
        int max = start + count;
 
        for (int i = start; i < max; ++i)
        {
            byte byte0 = buffer[i];
 
            if ((byte0 & 128) == 0)
            {
                // If an UCS fits 7 bits, its coded as 0xxxxxxx. This makes ASCII character represented by themselves
                sb.Append((char)byte0);
            }
            else if ((byte0 & 224) == 192)
            {
                // If an UCS fits 11 bits, it is coded as 110xxxxx 10xxxxxx
                if (++i == count) break;
                byte byte1 = buffer[i];
                int ch = (byte0 & 31) << 6;
                ch |= (byte1 & 63);
                sb.Append((char)ch);
            }
            else if ((byte0 & 240) == 224)
            {
                // If an UCS fits 16 bits, it is coded as 1110xxxx 10xxxxxx 10xxxxxx
                if (++i == count) break;
                byte byte1 = buffer[i];
                if (++i == count) break;
                byte byte2 = buffer[i];
 
                if (byte0 == 0xEF && byte1 == 0xBB && byte2 == 0xBF)
                {
                    // Byte Order Mark -- generally the first 3 bytes in a Windows-saved UTF-8 file. Skip it.
                }
                else
                {
                    int ch = (byte0 & 15) << 12;
                    ch |= (byte1 & 63) << 6;
                    ch |= (byte2 & 63);
                    sb.Append((char)ch);
                }
            }
            else if ((byte0 & 248) == 240)
            {
                // If an UCS fits 21 bits, it is coded as 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 
                if (++i == count) break;
                byte byte1 = buffer[i];
                if (++i == count) break;
                byte byte2 = buffer[i];
                if (++i == count) break;
                byte byte3 = buffer[i];
 
                int ch = (byte0 & 7) << 18;
                ch |= (byte1 & 63) << 12;
                ch |= (byte2 & 63) << 6;
                ch |= (byte3 & 63);
                sb.Append((char)ch);
            }
        }
        return sb.ToString();
#else
        return Encoding.UTF8.GetString(buffer, start, count);
#endif
    }
 
    /// <summary>
    /// Read a single line from the buffer.
    /// </summary>
 
    public string ReadLine () { return ReadLine(true); }
 
    /// <summary>
    /// Read a single line from the buffer.
    /// </summary>
 
    public string ReadLine (bool skipEmptyLines)
    {
        int max = mBuffer.Length;
 
        // Skip empty characters
        if (skipEmptyLines)
        {
            while (mOffset < max && mBuffer[mOffset] < 32) ++mOffset;
        }
 
        int end = mOffset;
 
        if (end < max)
        {
            for (; ; )
            {
                if (end < max)
                {
                    int ch = mBuffer[end++];
                    if (ch != '\n' && ch != '\r') continue;
                }
                else ++end;
 
                string line = ReadLine(mBuffer, mOffset, end - mOffset - 1);
                mOffset = end;
                return line;
            }
        }
        mOffset = max;
        return null;
    }
 
    /// <summary>
    /// Assume that the entire file is a collection of key/value pairs.
    /// </summary>
 
    public Dictionary<string, string> ReadDictionary ()
    {
        Dictionary<string, string> dict = new Dictionary<string, string>();
        char[] separator = new char[] { '=' };
 
        while (canRead)
        {
            string line = ReadLine();
            if (line == null) break;
            if (line.StartsWith("//")) continue;
 
#if UNITY_FLASH
            string[] split = line.Split(separator, System.StringSplitOptions.RemoveEmptyEntries);
#else
            string[] split = line.Split(separator, 2, System.StringSplitOptions.RemoveEmptyEntries);
#endif
 
            if (split.Length == 2)
            {
                string key = split[0].Trim();
                string val = split[1].Trim().Replace("\\n", "\n");
                dict[key] = val;
            }
        }
        return dict;
    }
 
    static BetterList<string> mTemp = new BetterList<string>();
 
    /// <summary>
    /// Read a single line of Comma-Separated Values from the file.
    /// </summary>
 
    public BetterList<string> ReadCSV ()
    {
        mTemp.Clear();
        string line = "";
        bool insideQuotes = false;
        int wordStart = 0;
 
        while (canRead)
        {
            if (insideQuotes)
            {
                string s = ReadLine(false);
                if (s == null) return null;
                s = s.Replace("\\n", "\n");
                line += "\n" + s;
                ++wordStart;
            }
            else
            {
                line = ReadLine(true);
                if (line == null) return null;
                line = line.Replace("\\n", "\n");
                wordStart = 0;
            }
 
            for (int i = wordStart, imax = line.Length; i < imax; ++i)
            {
                char ch = line[i];
 
                if (ch == ',')
                {
                    if (!insideQuotes)
                    {
                        mTemp.Add(line.Substring(wordStart, i - wordStart));
                        wordStart = i + 1;
                    }
                }
                else if (ch == '"')
                {
                    if (insideQuotes)
                    {
                        if (i + 1 >= imax)
                        {
                            mTemp.Add(line.Substring(wordStart, i - wordStart).Replace("\"\"", "\""));
                            return mTemp;
                        }
 
                        if (line[i + 1] != '"')
                        {
                            mTemp.Add(line.Substring(wordStart, i - wordStart));
                            insideQuotes = false;
 
                            if (line[i + 1] == ',')
                            {
                                ++i;
                                wordStart = i + 1;
                            }
                        }
                        else ++i;
                    }
                    else
                    {
                        wordStart = i + 1;
                        insideQuotes = true;
                    }
                }
            }
 
            if (wordStart < line.Length)
            {
                if (insideQuotes) continue;
                mTemp.Add(line.Substring(wordStart, line.Length - wordStart));
            }
            return mTemp;
        }
        return null;
    }
}