Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
VersionConverter128To129.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
4using XmlUtilities;
5
6namespace Game {
8 public override string SourceVersion => "1.28";
9
10 public override string TargetVersion => "1.29";
11
12 public override void ConvertProjectXml(XElement projectNode) {
13 XmlUtils.SetAttributeValue(projectNode, "Version", TargetVersion);
14 foreach (XElement item in from e in projectNode.Element("Subsystems").Elements()
15 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Pickables"
16 select e) {
17 foreach (XElement item2 in from e in item.Elements("Values")
18 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Pickables"
19 select e) {
20 foreach (XElement item3 in item2.Elements("Values")) {
21 foreach (XElement item4 in from e in item3.Elements("Value")
22 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Value"
23 select e) {
24 int num = ConvertValue(XmlUtils.GetAttributeValue<int>(item4, "Value"));
25 XmlUtils.SetAttributeValue(item4, "Value", num);
26 }
27 }
28 }
29 }
30 foreach (XElement item5 in from e in projectNode.Element("Subsystems").Elements()
31 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Projectiles"
32 select e) {
33 foreach (XElement item6 in from e in item5.Elements("Values")
34 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Projectiles"
35 select e) {
36 foreach (XElement item7 in item6.Elements("Values")) {
37 foreach (XElement item8 in from e in item7.Elements("Value")
38 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Value"
39 select e) {
40 int num2 = ConvertValue(XmlUtils.GetAttributeValue<int>(item8, "Value"));
41 XmlUtils.SetAttributeValue(item8, "Value", num2);
42 }
43 }
44 }
45 }
46 foreach (XElement item9 in from e in projectNode.Element("Subsystems").Elements()
47 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "CollapsingBlockBehavior"
48 select e) {
49 foreach (XElement item10 in from e in item9.Elements("Values")
50 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "CollapsingBlocks"
51 select e) {
52 foreach (XElement item11 in item10.Elements("Values")) {
53 foreach (XElement item12 in from e in item11.Elements("Value")
54 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Value"
55 select e) {
56 int num3 = ConvertValue(XmlUtils.GetAttributeValue<int>(item12, "Value"));
57 XmlUtils.SetAttributeValue(item12, "Value", num3);
58 }
59 }
60 }
61 }
62 foreach (XElement item13 in projectNode.Element("Entities").Elements()) {
63 foreach (XElement item14 in from e in item13.Elements("Values")
64 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Clothing"
65 select e) {
66 foreach (XElement item15 in from e in item14.Elements("Values")
67 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Clothes"
68 select e) {
69 foreach (XElement item16 in item15.Elements()) {
70 string attributeValue = XmlUtils.GetAttributeValue<string>(item16, "Value");
71 int[] array = HumanReadableConverter.ValuesListFromString<int>(';', attributeValue);
72 for (int i = 0; i < array.Length; i++) {
73 array[i] = ConvertValue(array[i]);
74 }
75 string value = HumanReadableConverter.ValuesListToString(';', array);
76 XmlUtils.SetAttributeValue(item16, "Value", value);
77 }
78 }
79 }
80 }
81 string[] inventoryNames = ["Inventory", "CreativeInventory", "CraftingTable", "Chest", "Furnace", "Dispenser"];
82 foreach (XElement item17 in projectNode.Element("Entities").Elements()) {
83 foreach (XElement item18 in from e in item17.Elements("Values")
84 where inventoryNames.Contains(XmlUtils.GetAttributeValue(e, "Name", string.Empty))
85 select e) {
86 foreach (XElement item19 in from e in item18.Elements("Values")
87 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Slots"
88 select e) {
89 foreach (XElement item20 in item19.Elements()) {
90 foreach (XElement item21 in from e in item20.Elements("Value")
91 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "Contents"
92 select e) {
93 int num4 = ConvertValue(XmlUtils.GetAttributeValue<int>(item21, "Value"));
94 XmlUtils.SetAttributeValue(item21, "Value", num4);
95 }
96 }
97 }
98 }
99 }
100 }
101
102 public override void ConvertWorld(string directoryName) {
103 ConvertProject(directoryName);
104 ConvertChunks(directoryName);
105 }
106
107 public void ConvertProject(string directoryName) {
108 string path = Storage.CombinePaths(directoryName, "Project.xml");
109 XElement xElement;
110 using (Stream stream = Storage.OpenFile(path, OpenFileMode.Read)) {
111 xElement = XmlUtils.LoadXmlFromStream(stream, null, true);
112 }
113 ConvertProjectXml(xElement);
114 using (Stream stream2 = Storage.OpenFile(path, OpenFileMode.Create)) {
115 XmlUtils.SaveXmlToStream(xElement, stream2, null, true);
116 }
117 }
118
119 public void ConvertChunks(string directoryName) {
120 string path = Storage.CombinePaths(directoryName, "Chunks.dat");
121 string path2 = Storage.CombinePaths(directoryName, "Chunks32.dat");
122 using (Stream stream2 = Storage.OpenFile(path, OpenFileMode.Read)) {
123 using (Stream stream = Storage.OpenFile(path2, OpenFileMode.Create)) {
124 byte[] array = new byte[65536];
125 byte[] array2 = new byte[131072];
126 for (int i = 0; i < 65537; i++) {
127 TerrainSerializer129.WriteTOCEntry(stream, 0, 0, -1);
128 }
129 int num = 0;
130 while (true) {
131 stream2.Position = 12 * num;
132 TerrainSerializer14.ReadTOCEntry(stream2, out int cx, out int cz, out int offset);
133 if (offset == 0) {
134 break;
135 }
136 stream.Position = 12 * num;
137 TerrainSerializer129.WriteTOCEntry(stream, cx, cz, num);
138 stream2.Position = offset;
139 stream.Position = stream.Length;
142 stream2.ReadExactly(array, 0, 65536);
143 int num2 = 0;
144 for (int j = 0; j < 16; j++) {
145 for (int k = 0; k < 16; k++) {
146 for (int l = 0; l < 128; l++) {
147 int num3 = array[2 * num2] | (array[2 * num2 + 1] << 8);
148 int num4 = ConvertValue(num3);
149 if (l < 127) {
150 int num5 = num3 & 0xFF;
151 if (num5 == 18
152 || num5 == 92) {
153 int num6 = (array[2 * num2 + 2] | (array[2 * num2 + 3] << 8)) & 0xFF;
154 if (num5 != num6) {
155 num4 |= 0x40000;
156 }
157 }
158 }
159 array2[4 * num2] = (byte)num4;
160 array2[4 * num2 + 1] = (byte)(num4 >> 8);
161 array2[4 * num2 + 2] = (byte)(num4 >> 16);
162 array2[4 * num2 + 3] = (byte)(num4 >> 24);
163 num2++;
164 }
165 }
166 }
167 stream.Write(array2, 0, 131072);
168 stream2.ReadExactly(array, 0, 1024);
169 stream.Write(array, 0, 1024);
170 num++;
171 }
172 }
173 }
174 Storage.DeleteFile(path);
175 }
176
177 public static int ConvertValue(int value) {
178 int contents = value & 0xFF;
179 int light = (value >> 8) & 0xF;
180 int data = value >> 12;
181 ConvertContentsLightData(ref contents, ref light, ref data);
182 return contents | (light << 10) | (data << 14);
183 }
184
185 public static void ConvertContentsLightData(ref int contents, ref int light, ref int data) {
186 if (contents >= 133
187 && contents <= 136) {
188 data |= (contents - 133) << 4;
189 contents = 133;
190 return;
191 }
192 if (contents == 152) {
193 int num = data & 1;
194 int num2 = (data >> 1) & 7;
195 int num3 = num == 0 ? 2 : 5;
196 data = num2 | (num3 << 3);
197 return;
198 }
199 if (contents == 182) {
200 int num4 = data & 1;
201 int num5 = (data >> 1) & 7;
202 int num6 = num4 == 0 ? 3 : 0;
203 data = num5 | (num6 << 3);
204 return;
205 }
206 if (contents == 185) {
207 int num7 = data & 3;
208 int num8 = (data >> 2) & 3;
209 int num9 = 0;
210 if (num7 == 0) {
211 num9 = 2;
212 }
213 if (num7 == 1) {
214 num9 = 5;
215 }
216 if (num7 == 2) {
217 num9 = 3;
218 }
219 data = num8 | (num9 << 3);
220 return;
221 }
222 if (contents == 139) {
223 int num10 = data & 1;
224 int num11 = (data >> 1) & 7;
225 int num12 = num10 * 15;
226 data = num11 | (num12 << 3);
227 return;
228 }
229 if (contents == 128) {
230 contents = 21;
231 data = (data << 1) | 1;
232 }
233 if (contents == 163) {
234 contents = 3;
235 data = (data << 1) | 1;
236 }
237 if (contents == 164) {
238 contents = 73;
239 data = (data << 1) | 1;
240 }
241 if (contents == 165) {
242 contents = 67;
243 data = (data << 1) | 1;
244 }
245 }
246 }
247}
static Stream OpenFile(string path, OpenFileMode openFileMode)
static void DeleteFile(string path)
static string CombinePaths(params string[] paths)
static void WriteTOCEntry(Stream stream, int cx, int cz, int index)
static void WriteChunkHeader(Stream stream, int cx, int cz)
static void ReadChunkHeader(Stream stream)
static void ReadTOCEntry(Stream stream, out int cx, out int cz, out int offset)
override void ConvertWorld(string directoryName)
static void ConvertContentsLightData(ref int contents, ref int light, ref int data)
override void ConvertProjectXml(XElement projectNode)
static void SetAttributeValue(XElement node, string attributeName, object value)
static object GetAttributeValue(XElement node, string attributeName, Type type)
static XElement LoadXmlFromStream(Stream stream, Encoding encoding, bool throwOnError)
static void SaveXmlToStream(XElement node, Stream stream, Encoding encoding, bool throwOnError)