|
3 | 3 |
|
4 | 4 | namespace BlastCorpsEditor |
5 | 5 | { |
6 | | - // helper class for converting arrays of bytes in big endian to native integer types |
7 | | - class BE |
8 | | - { |
9 | | - public static UInt32 U32(byte[] buf, uint i) |
10 | | - { |
11 | | - byte[] u32bytes = new byte[4]; |
12 | | - Array.Copy(buf, i, u32bytes, 0, u32bytes.Length); |
13 | | - if (BitConverter.IsLittleEndian) |
14 | | - { |
15 | | - Array.Reverse(u32bytes); |
16 | | - } |
17 | | - return BitConverter.ToUInt32(u32bytes, 0); |
18 | | - } |
19 | | - |
20 | | - public static Int32 I32(byte[] buf, uint i) |
21 | | - { |
22 | | - byte[] i32bytes = new byte[4]; |
23 | | - Array.Copy(buf, i, i32bytes, 0, i32bytes.Length); |
24 | | - if (BitConverter.IsLittleEndian) |
25 | | - { |
26 | | - Array.Reverse(i32bytes); |
27 | | - } |
28 | | - return BitConverter.ToInt32(i32bytes, 0); |
29 | | - } |
30 | | - |
31 | | - public static UInt16 U16(byte[] buf, uint i) |
32 | | - { |
33 | | - byte[] u16bytes = new byte[2]; |
34 | | - Array.Copy(buf, i, u16bytes, 0, u16bytes.Length); |
35 | | - if (BitConverter.IsLittleEndian) |
36 | | - { |
37 | | - Array.Reverse(u16bytes); |
38 | | - } |
39 | | - return BitConverter.ToUInt16(u16bytes, 0); |
40 | | - } |
41 | | - |
42 | | - public static Int16 I16(byte[] buf, uint i) |
43 | | - { |
44 | | - byte[] i16bytes = new byte[2]; |
45 | | - Array.Copy(buf, i, i16bytes, 0, i16bytes.Length); |
46 | | - if (BitConverter.IsLittleEndian) |
47 | | - { |
48 | | - Array.Reverse(i16bytes); |
49 | | - } |
50 | | - return BitConverter.ToInt16(i16bytes, 0); |
51 | | - } |
52 | | - |
53 | | - public static int ToBytes(Int16 val, byte[] buf, int i) |
54 | | - { |
55 | | - byte[] data = BitConverter.GetBytes(val); |
56 | | - if (BitConverter.IsLittleEndian) |
57 | | - { |
58 | | - Array.Reverse(data); |
59 | | - } |
60 | | - Array.Copy(data, 0, buf, i, data.Length); |
61 | | - return data.Length; |
62 | | - } |
63 | | - |
64 | | - public static int ToBytes(UInt16 val, byte[] buf, int i) |
65 | | - { |
66 | | - byte[] data = BitConverter.GetBytes(val); |
67 | | - if (BitConverter.IsLittleEndian) |
68 | | - { |
69 | | - Array.Reverse(data); |
70 | | - } |
71 | | - Array.Copy(data, 0, buf, i, data.Length); |
72 | | - return data.Length; |
73 | | - } |
74 | | - |
75 | | - public static int ToBytes(Int32 val, byte[] buf, int i) |
76 | | - { |
77 | | - byte[] data = BitConverter.GetBytes(val); |
78 | | - if (BitConverter.IsLittleEndian) |
79 | | - { |
80 | | - Array.Reverse(data); |
81 | | - } |
82 | | - Array.Copy(data, 0, buf, i, data.Length); |
83 | | - return data.Length; |
84 | | - } |
85 | | - |
86 | | - public static int ToBytes(UInt32 val, byte[] buf, int i) |
87 | | - { |
88 | | - byte[] data = BitConverter.GetBytes(val); |
89 | | - if (BitConverter.IsLittleEndian) |
90 | | - { |
91 | | - Array.Reverse(data); |
92 | | - } |
93 | | - Array.Copy(data, 0, buf, i, data.Length); |
94 | | - return data.Length; |
95 | | - } |
96 | | - } |
97 | | - |
98 | 6 | public class BlastCorpsLevelMeta |
99 | 7 | { |
100 | 8 | public uint id { get; set; } |
@@ -750,7 +658,7 @@ private static int AppendArray(byte[] dest, int offset, byte[] src) |
750 | 658 |
|
751 | 659 | public byte[] ToBytes() |
752 | 660 | { |
753 | | - // TODO: better estimate of size |
| 661 | + // TODO: convert to MemoryStream |
754 | 662 | byte[] data = new byte[400 * 1024]; |
755 | 663 | int offset = 0x0; |
756 | 664 |
|
|
0 commit comments