Elin Modding Docs Doc
Loading...
Searching...
No Matches
PartialMap.cs
1using System;
2using System.Collections.Generic;
3using System.IO;
4using Ionic.Zip;
5using Newtonsoft.Json;
6using SFB;
7using UnityEngine;
8
9// Token: 0x02000698 RID: 1688
10public class PartialMap : EClass
11{
12 // Token: 0x17000E25 RID: 3621
13 // (get) Token: 0x0600310B RID: 12555 RVA: 0x0011239C File Offset: 0x0011059C
14 public static string PathTemp
15 {
16 get
17 {
18 return CorePath.MapPieceSave + "_temp.mp";
19 }
20 }
21
22 // Token: 0x17000E26 RID: 3622
23 // (get) Token: 0x0600310C RID: 12556 RVA: 0x001123AD File Offset: 0x001105AD
24 public bool altDirPosition
25 {
26 get
27 {
28 return true;
29 }
30 }
31
32 // Token: 0x17000E27 RID: 3623
33 // (get) Token: 0x0600310D RID: 12557 RVA: 0x001123B0 File Offset: 0x001105B0
34 public string ID
35 {
36 get
37 {
38 return new FileInfo(this.path).Name.Replace(".mp", "");
39 }
40 }
41
42 // Token: 0x0600310E RID: 12558 RVA: 0x001123D4 File Offset: 0x001105D4
43 public void Rotate()
44 {
45 this.dir++;
46 if (this.dir > 3)
47 {
48 this.dir = 0;
49 }
50 SE.Rotate();
51 this.localOffsetX = (this.localOffsetZ = 0);
52 }
53
54 // Token: 0x0600310F RID: 12559 RVA: 0x00112414 File Offset: 0x00110614
55 public void ClearMarkedCells()
56 {
57 foreach (Cell cell in this.cellsMarked)
58 {
59 cell.skipRender = false;
60 }
61 this.cellsMarked.Clear();
62 }
63
64 // Token: 0x06003110 RID: 12560 RVA: 0x00112470 File Offset: 0x00110670
65 public unsafe void Apply(Point _point, PartialMap.ApplyMode mode)
66 {
67 PartialMap.<>c__DisplayClass35_0 CS$<>8__locals1 = new PartialMap.<>c__DisplayClass35_0();
68 CS$<>8__locals1.<>4__this = this;
69 byte height = _point.cell.height;
70 int num = _point.cell.IsFloorWater ? this.baseHeightWater : this.baseHeight;
71 Point point = new Point(_point);
72 point.x += this.localOffsetX;
73 point.z += this.localOffsetZ;
74 if (this.altDirPosition)
75 {
76 switch (this.dir)
77 {
78 case 1:
79 point.z += this.w - 1;
80 break;
81 case 2:
82 point.x += this.w - 1;
83 point.z += this.h - 1;
84 break;
85 case 3:
86 point.x += this.h - 1;
87 break;
88 }
89 }
90 this.destX = point.x;
91 this.destZ = point.z;
92 CS$<>8__locals1.p = new Point();
93 if (mode == PartialMap.ApplyMode.Render)
94 {
95 this.ClearMarkedCells();
96 }
97 if (mode == PartialMap.ApplyMode.Evaluate)
98 {
99 this.value = 0;
100 }
101 int num2 = 0;
102 int num3 = 0;
103 CS$<>8__locals1.minX = point.x;
104 CS$<>8__locals1.minZ = point.z;
105 CS$<>8__locals1.maxX = point.x + this.w;
106 CS$<>8__locals1.maxZ = point.z + this.h;
107 switch (this.dir)
108 {
109 case 1:
110 CS$<>8__locals1.minX = point.x;
111 CS$<>8__locals1.maxX = point.x + this.h;
112 CS$<>8__locals1.minZ = point.z - this.w + 1;
113 CS$<>8__locals1.maxZ = point.z + 1;
114 break;
115 case 2:
116 CS$<>8__locals1.minX = point.x - this.w + 1;
117 CS$<>8__locals1.maxX = point.x + 1;
118 CS$<>8__locals1.minZ = point.z - this.h + 1;
119 CS$<>8__locals1.maxZ = point.z + 1;
120 break;
121 case 3:
122 CS$<>8__locals1.minX = point.x - this.h + 1;
123 CS$<>8__locals1.maxX = point.x + 1;
124 CS$<>8__locals1.minZ = point.z;
125 CS$<>8__locals1.maxZ = point.z + this.w;
126 break;
127 }
128 EClass.pc.GetCurrency("money");
129 BiomeProfile.TileGroup interior = EClass._zone.biome.interior;
130 BiomeProfile.TileGroup exterior = EClass._zone.biome.exterior;
131 this.result.ruined.Clear();
132 for (int i = 0; i < this.w; i++)
133 {
134 for (int j = 0; j < this.h; j++)
135 {
136 Cell cell = this.map.cells[i, j];
137 CS$<>8__locals1.p.Set(point.x + num2, point.z + num3);
138 if (EClass._map.Contains(CS$<>8__locals1.p))
139 {
140 PartialMap.<>c__DisplayClass35_1 CS$<>8__locals2;
141 CS$<>8__locals2.c1 = EClass._map.cells[CS$<>8__locals1.p.x, CS$<>8__locals1.p.z];
142 CS$<>8__locals2.result = HitResult.Valid;
143 if (CS$<>8__locals2.c1.isFloating)
144 {
145 CS$<>8__locals2.result = HitResult.Invalid;
146 }
147 if (CS$<>8__locals2.result == HitResult.Valid)
148 {
149 this.validPoints.Add(CS$<>8__locals1.p.index);
150 }
151 if (mode == PartialMap.ApplyMode.Render)
152 {
153 CS$<>8__locals2.c1.skipRender = true;
154 this.cellsMarked.Add(CS$<>8__locals2.c1);
155 if (CS$<>8__locals2.result != HitResult.Valid)
156 {
157 MeshPass guidePass = ActionMode.Copy.GetGuidePass(point);
158 int num4 = (int)CS$<>8__locals2.result;
159 Vector3 vector = *CS$<>8__locals1.p.Position();
160 guidePass.Add(vector.x, vector.y, vector.z - 0.01f, (float)num4, 0.3f);
161 }
162 else
163 {
164 CS$<>8__locals1.<Apply>g__Render|1(cell.sourceFloor, cell.floorDir, 0, ref CS$<>8__locals2);
165 CS$<>8__locals1.<Apply>g__Render|1(cell.sourceBlock, cell.HasWall ? this.FixWall(cell) : cell.blockDir, 0, ref CS$<>8__locals2);
166 CS$<>8__locals1.<Apply>g__Render|1(cell.sourceObj, cell.objDir, 0, ref CS$<>8__locals2);
167 CS$<>8__locals1.<Apply>g__Render|1(cell.sourceBridge, cell.floorDir, (int)((cell.bridgeHeight == 0) ? 0 : (cell.bridgeHeight - cell.height)), ref CS$<>8__locals2);
168 foreach (SerializedCards.Data data in this.exportData.serializedCards.cards)
169 {
170 Recipe orCreate = Recipe.GetOrCreate(EClass.sources.cards.map[data.id].RecipeID);
171 if (data.x - this.offsetX == i && data.z - this.offsetZ == j)
172 {
173 if (PartialMap.relative)
174 {
175 if (orCreate != null)
176 {
177 orCreate.OnRenderMarker(CS$<>8__locals1.p, true, CS$<>8__locals2.result, true, data.dir, (int)(height + cell.height) - num);
178 }
179 }
180 else if (orCreate != null)
181 {
182 orCreate.OnRenderMarker(CS$<>8__locals1.p, true, CS$<>8__locals2.result, true, data.dir, (int)cell.height);
183 }
184 }
185 }
186 Critter.RebuildCritter(CS$<>8__locals2.c1);
187 }
188 }
189 if (mode == PartialMap.ApplyMode.Apply && CS$<>8__locals2.result == HitResult.Valid)
190 {
191 if (Rand.Range(0f, 1f) < this.ruinChance)
192 {
193 this.result.ruined.Add(CS$<>8__locals1.p.index);
194 }
195 else if (cell._floor != 77 || this.editMode)
196 {
197 if (cell._block == 149 && !this.editMode)
198 {
199 CS$<>8__locals2.c1._block = (byte)interior.block.id;
200 CS$<>8__locals2.c1._blockMat = (byte)interior.block.mat;
201 }
202 else if (cell._block == 150 && !this.editMode)
203 {
204 CS$<>8__locals2.c1._block = (byte)exterior.block.id;
205 CS$<>8__locals2.c1._blockMat = (byte)exterior.block.mat;
206 }
207 else
208 {
209 CS$<>8__locals2.c1._block = cell._block;
210 CS$<>8__locals2.c1._blockMat = cell._blockMat;
211 }
212 if (cell._floor == 2 && !this.editMode)
213 {
214 CS$<>8__locals2.c1._floor = (byte)interior.floor.id;
215 CS$<>8__locals2.c1._floorMat = (byte)interior.floor.mat;
216 }
217 else if (cell._floor == 3 && !this.editMode)
218 {
219 CS$<>8__locals2.c1._floor = (byte)exterior.floor.id;
220 CS$<>8__locals2.c1._floorMat = (byte)exterior.floor.mat;
221 }
222 else
223 {
224 CS$<>8__locals2.c1._floor = cell._floor;
225 CS$<>8__locals2.c1._floorMat = cell._floorMat;
226 }
227 CS$<>8__locals2.c1._roofBlock = cell._roofBlock;
228 CS$<>8__locals2.c1._roofBlockMat = cell._roofBlockMat;
229 CS$<>8__locals2.c1.obj = cell.obj;
230 CS$<>8__locals2.c1.objMat = cell.objMat;
231 CS$<>8__locals2.c1.objVal = cell.objVal;
232 CS$<>8__locals2.c1.decal = cell.decal;
233 CS$<>8__locals2.c1._dirs = cell._dirs;
234 CS$<>8__locals2.c1._bridge = cell._bridge;
235 CS$<>8__locals2.c1._bridgeMat = cell._bridgeMat;
236 CS$<>8__locals2.c1.bridgePillar = cell.bridgePillar;
237 CS$<>8__locals2.c1.isModified = true;
238 if (CS$<>8__locals2.c1.HasWall)
239 {
240 CS$<>8__locals2.c1.blockDir = this.FixWall(CS$<>8__locals2.c1);
241 }
242 if (PartialMap.relative || this.procedural)
243 {
244 CS$<>8__locals2.c1.height = (byte)Mathf.Clamp((int)(height + cell.height) - num, 0, 255);
245 CS$<>8__locals2.c1.bridgeHeight = (byte)Mathf.Clamp((int)((cell.bridgeHeight == 0) ? 0 : (CS$<>8__locals2.c1.height + (cell.bridgeHeight - cell.height))), 0, 255);
246 }
247 else
248 {
249 CS$<>8__locals2.c1.height = cell.height;
250 CS$<>8__locals2.c1.bridgeHeight = cell.bridgeHeight;
251 }
252 }
253 }
254 }
255 switch (this.dir)
256 {
257 case 0:
258 num3++;
259 if (num3 >= this.h)
260 {
261 num3 = 0;
262 num2++;
263 }
264 break;
265 case 1:
266 num2++;
267 if (num2 >= this.h)
268 {
269 num2 = 0;
270 num3--;
271 }
272 break;
273 case 2:
274 num3--;
275 if (num3 <= -this.h)
276 {
277 num3 = 0;
278 num2--;
279 }
280 break;
281 case 3:
282 num2--;
283 if (num2 <= -this.h)
284 {
285 num2 = 0;
286 num3++;
287 }
288 break;
289 }
290 }
291 }
292 if (mode != PartialMap.ApplyMode.Apply)
293 {
294 return;
295 }
296 CS$<>8__locals1.p.Set(point.x, point.z);
297 EClass._map.SetReference();
298 EClass._map.things.ForeachReverse(delegate(Thing t)
299 {
300 if (CS$<>8__locals1.<>4__this.validPoints.Contains(t.pos.index) && t.pos.x >= CS$<>8__locals1.minX && t.pos.z >= CS$<>8__locals1.minZ && t.pos.x < CS$<>8__locals1.maxX && t.pos.z < CS$<>8__locals1.maxZ && t.trait.CanBeDestroyed)
301 {
302 t.Destroy();
303 }
304 });
305 if (this.exportData != null)
306 {
307 this.exportData.serializedCards.Restore(EClass._map, null, true, this);
308 }
309 EClass._map.RefreshAllTiles();
310 EClass._map.RefreshAllTiles();
311 }
312
313 // Token: 0x06003111 RID: 12561 RVA: 0x00112E64 File Offset: 0x00111064
314 public int FixWall(Cell c)
315 {
316 switch (this.dir)
317 {
318 case 1:
319 if (c.blockDir == 0)
320 {
321 return 1;
322 }
323 if (c.blockDir == 1)
324 {
325 return 0;
326 }
327 break;
328 case 3:
329 if (c.blockDir == 0)
330 {
331 return 1;
332 }
333 if (c.blockDir == 1)
334 {
335 return 0;
336 }
337 if (c.blockDir == 2)
338 {
339 return 0;
340 }
341 break;
342 }
343 return c.blockDir;
344 }
345
346 // Token: 0x06003112 RID: 12562 RVA: 0x00112ECB File Offset: 0x001110CB
347 public void Update()
348 {
349 if (this.path.IsEmpty())
350 {
351 return;
352 }
353 Map.UpdateMetaData(this.path, this);
354 }
355
356 // Token: 0x06003113 RID: 12563 RVA: 0x00112EE8 File Offset: 0x001110E8
357 public void Save(int _x, int _z, int _w, int _h)
358 {
359 this.offsetX = _x;
360 this.offsetZ = _z;
361 this.w = _w;
362 this.h = _h;
363 this.value = 0;
364 for (int i = _x; i < _x + this.w; i++)
365 {
366 for (int j = _z; j < _z + this.h; j++)
367 {
368 Cell cell = EClass._map.cells[i, j];
369 this.value += Card.GetTilePrice(cell.sourceBlock, cell.matBlock);
370 this.value += Card.GetTilePrice(cell.sourceFloor, cell.matFloor);
371 this.value += Card.GetTilePrice(cell.sourceObj, cell.matObj);
372 this.value += Card.GetTilePrice(cell.sourceBridge, cell.matBridge);
373 this.value += Card.GetTilePrice(cell.sourceRoofBlock, cell.matRoofBlock);
374 }
375 }
376 foreach (Thing thing in EClass._map.things)
377 {
378 if (thing.trait.CanCopyInBlueprint && thing.pos.Within(_x, _z, _w, _h) && thing.IsInstalled)
379 {
380 this.value += thing.GetPrice(CurrencyType.Money, false, PriceType.Default, null) * thing.Num;
381 }
382 }
383 EClass._zone.Export(PartialMap.PathTemp, this, false);
384 }
385
386 // Token: 0x06003114 RID: 12564 RVA: 0x00113094 File Offset: 0x00111294
387 public static PartialMap Apply(string path, Point pos)
388 {
389 PartialMap partialMap = PartialMap.Load(CorePath.MapPieceSave + path);
390 partialMap.ruinChance = 0f;
391 partialMap.Apply(pos, PartialMap.ApplyMode.Apply);
392 return partialMap;
393 }
394
395 // Token: 0x06003115 RID: 12565 RVA: 0x001130BC File Offset: 0x001112BC
396 public static PartialMap Load(string path = null)
397 {
398 bool flag = path.IsEmpty();
399 if (flag)
400 {
401 path = PartialMap.PathTemp;
402 }
403 if (!File.Exists(path))
404 {
405 return null;
406 }
407 MapMetaData metaData = Map.GetMetaData(path);
408 if (metaData == null || metaData.partial == null)
409 {
410 return null;
411 }
412 PartialMap partial = metaData.partial;
413 if (!flag)
414 {
415 partial.path = path;
416 }
417 partial.exportData = EClass._zone.Import(path);
418 partial._Load();
419 return partial;
420 }
421
422 // Token: 0x06003116 RID: 12566 RVA: 0x00113124 File Offset: 0x00111324
423 public void _Load()
424 {
425 this.map = GameIO.LoadFile<Map>(EClass._zone.pathTemp + "map");
426 this.map.Load(EClass._zone.pathTemp, false, this);
427 if (this.map == null)
428 {
429 Debug.Log("Map is null:" + this.name + "/" + PartialMap.PathTemp);
430 return;
431 }
432 EClass._map.SetReference();
433 this.baseHeight = 255;
434 this.baseHeightWater = 255;
435 for (int i = 0; i < this.w; i++)
436 {
437 for (int j = 0; j < this.h; j++)
438 {
439 Cell cell = this.map.cells[i, j];
440 if ((int)cell.height < this.baseHeight)
441 {
442 this.baseHeightWater = (int)cell.height;
443 }
444 if ((int)cell.height < this.baseHeight && !cell.IsFloorWater)
445 {
446 this.baseHeight = (int)cell.height;
447 }
448 }
449 }
450 if (this.baseHeight == 255)
451 {
452 this.baseHeight = 0;
453 }
454 }
455
456 // Token: 0x06003117 RID: 12567 RVA: 0x00113234 File Offset: 0x00111434
457 public static void Delete(string path)
458 {
459 string fullFileNameWithoutExtension = path.GetFullFileNameWithoutExtension();
460 IO.DeleteFile(path);
461 IO.DeleteFile(fullFileNameWithoutExtension + ".jpg");
462 IO.DeleteFile(fullFileNameWithoutExtension + ".txt");
463 }
464
465 // Token: 0x06003118 RID: 12568 RVA: 0x00113264 File Offset: 0x00111464
466 public static void ExportDialog(string dir = null)
467 {
468 EClass.core.WaitForEndOfFrame(delegate
469 {
470 string pathDest = StandaloneFileBrowser.SaveFilePanel("Export Map Piece", dir ?? CorePath.MapPieceSaveUser, "new map piece", "mp");
471 if (!string.IsNullOrEmpty(pathDest))
472 {
473 PartialMap.SavePreview(PartialMap.PathTemp, pathDest);
474 Msg.SayRaw("Exported Zone");
475 }
476 });
477 }
478
479 // Token: 0x06003119 RID: 12569 RVA: 0x00113294 File Offset: 0x00111494
480 public static void SavePreview(string path, string pathDest)
481 {
482 EClass.core.actionsNextFrame.Add(delegate
483 {
484 string fileName = CorePath.Temp + "preview.jpg";
485 Texture2D texture2D = ScreenCapture.CaptureScreenshotAsTexture();
486 int num = 200;
487 int num2 = 100;
488 RenderTexture renderTexture = new RenderTexture(num, num2, 0);
489 renderTexture.Create();
490 RenderTexture active = RenderTexture.active;
491 RenderTexture.active = renderTexture;
492 Graphics.Blit(texture2D, renderTexture);
493 Texture2D texture2D2 = new Texture2D(num, num2, texture2D.format, false);
494 texture2D2.ReadPixels(new Rect(0f, 0f, (float)num, (float)num2), 0, 0);
495 texture2D2.Apply();
496 RenderTexture.active = active;
497 renderTexture.Release();
498 File.WriteAllBytes(fileName, texture2D2.EncodeToJPG());
499 ZipFile zipFile = ZipFile.Read(path);
500 zipFile.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
501 zipFile.AddFile(fileName, "");
502 zipFile.Save(pathDest);
503 zipFile.Dispose();
504 IO.DeleteFile(fileName);
505 UnityEngine.Object.Destroy(texture2D2);
506 UnityEngine.Object.Destroy(texture2D);
507 UnityEngine.Object.Destroy(renderTexture);
508 });
509 }
510
511 // Token: 0x04001B1A RID: 6938
512 public static bool relative;
513
514 // Token: 0x04001B1B RID: 6939
515 [JsonProperty]
516 public string name;
517
518 // Token: 0x04001B1C RID: 6940
519 [JsonProperty]
520 public int offsetX;
521
522 // Token: 0x04001B1D RID: 6941
523 [JsonProperty]
524 public int offsetZ;
525
526 // Token: 0x04001B1E RID: 6942
527 [JsonProperty]
528 public int w;
529
530 // Token: 0x04001B1F RID: 6943
531 [JsonProperty]
532 public int h;
533
534 // Token: 0x04001B20 RID: 6944
535 [JsonProperty]
536 public int dir;
537
538 // Token: 0x04001B21 RID: 6945
539 [JsonProperty]
540 public int baseHeight;
541
542 // Token: 0x04001B22 RID: 6946
543 [JsonProperty]
544 public int baseHeightWater;
545
546 // Token: 0x04001B23 RID: 6947
547 [JsonProperty]
548 public int value;
549
550 // Token: 0x04001B24 RID: 6948
551 [JsonProperty]
552 public bool allowRotate;
553
554 // Token: 0x04001B25 RID: 6949
555 [JsonProperty]
556 public bool ignoreBlock;
557
558 // Token: 0x04001B26 RID: 6950
559 public int localOffsetX;
560
561 // Token: 0x04001B27 RID: 6951
562 public int localOffsetZ;
563
564 // Token: 0x04001B28 RID: 6952
565 public int destX;
566
567 // Token: 0x04001B29 RID: 6953
568 public int destZ;
569
570 // Token: 0x04001B2A RID: 6954
571 public string path;
572
573 // Token: 0x04001B2B RID: 6955
574 public bool editMode;
575
576 // Token: 0x04001B2C RID: 6956
577 public bool procedural;
578
579 // Token: 0x04001B2D RID: 6957
580 public float ruinChance;
581
582 // Token: 0x04001B2E RID: 6958
583 public Map map;
584
585 // Token: 0x04001B2F RID: 6959
586 public ZoneExportData exportData;
587
588 // Token: 0x04001B30 RID: 6960
589 public List<Cell> cellsMarked = new List<Cell>();
590
591 // Token: 0x04001B31 RID: 6961
592 public HashSet<int> validPoints = new HashSet<int>();
593
594 // Token: 0x04001B32 RID: 6962
595 public PartialMap.Result result = new PartialMap.Result();
596
597 // Token: 0x02000BFE RID: 3070
598 public enum ApplyMode
599 {
600 // Token: 0x04002FC7 RID: 12231
601 Render,
602 // Token: 0x04002FC8 RID: 12232
603 HitTest,
604 // Token: 0x04002FC9 RID: 12233
605 Apply,
606 // Token: 0x04002FCA RID: 12234
607 Evaluate
608 }
609
610 // Token: 0x02000BFF RID: 3071
611 public class Result
612 {
613 // Token: 0x04002FCB RID: 12235
614 public bool hasLight;
615
616 // Token: 0x04002FCC RID: 12236
617 public List<int> ruined = new List<int>();
618 }
619}
Definition Card.cs:13
Definition Cell.cs:10
Definition Map.cs:15
Definition Msg.cs:7
Definition Point.cs:11
Definition Thing.cs:10