三国卡牌客户端基础资源仓库
yyl
2025-08-25 214fe94eaf7f09741a7857775dfffe8c3b83c75c
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
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using System.Text;
 
namespace UnityFS
{
    public static class UnityBinUtils
    {
        public static void SwapUInt(ref uint val)
        {
            val = (val >> 24) | ((val >> 8) & 0x0000ff00) | ((val << 8) & 0x00ff0000) | (val << 24);
        }
 
        public static string ReadRawString(this BinaryReader br)
        {
            long startPos = br.BaseStream.Position;
            while (true)
            {
                byte val = br.ReadByte();
                if(val == 0)
                    break;
            }
            int size = (int)(br.BaseStream.Position - startPos);
            br.BaseStream.Position = startPos;
 
            byte[] buffer = br.ReadBytes(size);
            string ret = Encoding.UTF8.GetString(buffer, 0, size - 1);
 
            return ret;
        }
 
        public static void WriteRawString(this BinaryWriter bw, string str)
        {
            byte[] buffer = Encoding.UTF8.GetBytes(str);
            bw.Write(buffer, 0, buffer.Length);
            bw.Write((byte)0);
        }
 
        public static string ReadSizeString(this BinaryReader br)
        {
            int size = br.ReadInt32();
            byte[] buff = br.ReadBytes(size);
            br.BaseStream.AlignOffset4();
 
            string ret = Encoding.UTF8.GetString(buff);
            return ret;
        }
 
        public static void WriteSizeString(this BinaryWriter bw, string str)
        {
            byte[] buff = Encoding.UTF8.GetBytes(str);
            bw.Write(buff.Length);
            bw.Write(buff, 0, buff.Length);
            bw.BaseStream.AlignOffset4();
        }
 
        public static void AlignOffset4(this Stream stream)
        {
            int offset = (((int)stream.Position + 3) >> 2) << 2;
            stream.Position = offset;
        }
 
        public static long AlignedReadInt64(this BinaryReader br)
        {
            br.BaseStream.AlignOffset4();
            return br.ReadInt64();
        }
 
        public static void AlignedWriteInt64(this BinaryWriter bw, long val)
        {
            bw.BaseStream.AlignOffset4();
            bw.Write(val);
        }
    }
}