Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WorldFile.cs
Go to the documentation of this file.
1using System;
4using System.IO;
13using Terraria.ID;
15using Terraria.Social;
16using Terraria.UI;
19
20namespace Terraria.IO;
21
22public class WorldFile
23{
24 public static class TilePacker
25 {
26 public const int Header1_1 = 1;
27
28 public const int Header1_2 = 2;
29
30 public const int Header1_4 = 4;
31
32 public const int Header1_8 = 8;
33
34 public const int Header1_10 = 16;
35
36 public const int Header1_18 = 24;
37
38 public const int Header1_20 = 32;
39
40 public const int Header1_40 = 64;
41
42 public const int Header1_80 = 128;
43
44 public const int Header1_C0 = 192;
45
46 public const int Header2_1 = 1;
47
48 public const int Header2_2 = 2;
49
50 public const int Header2_4 = 4;
51
52 public const int Header2_8 = 8;
53
54 public const int Header2_10 = 16;
55
56 public const int Header2_20 = 32;
57
58 public const int Header2_40 = 64;
59
60 public const int Header2_70 = 112;
61
62 public const int Header2_80 = 128;
63
64 public const int Header3_1 = 1;
65
66 public const int Header3_2 = 2;
67
68 public const int Header3_4 = 4;
69
70 public const int Header3_8 = 8;
71
72 public const int Header3_10 = 16;
73
74 public const int Header3_20 = 32;
75
76 public const int Header3_40 = 64;
77
78 public const int Header3_80 = 128;
79
80 public const int Header4_1 = 1;
81
82 public const int Header4_2 = 2;
83
84 public const int Header4_4 = 4;
85
86 public const int Header4_8 = 8;
87
88 public const int Header4_10 = 16;
89
90 public const int Header4_20 = 32;
91
92 public const int Header4_40 = 64;
93
94 public const int Header4_80 = 128;
95 }
96
97 private static readonly object IOLock = new object();
98
99 private static double _tempTime = Main.time;
100
101 private static bool _tempRaining;
102
103 private static float _tempMaxRain;
104
105 private static int _tempRainTime;
106
107 private static bool _tempDayTime = Main.dayTime;
108
109 private static bool _tempBloodMoon = Main.bloodMoon;
110
111 private static bool _tempEclipse = Main.eclipse;
112
113 private static int _tempMoonPhase = Main.moonPhase;
114
116
117 private static int _versionNumber;
118
119 private static bool _isWorldOnCloud;
120
121 private static bool _tempPartyGenuine;
122
123 private static bool _tempPartyManual;
124
125 private static int _tempPartyCooldown;
126
127 private static readonly List<int> TempPartyCelebratingNPCs = new List<int>();
128
129 private static bool _hasCache;
130
131 private static bool? _cachedDayTime;
132
133 private static double? _cachedTime;
134
135 private static int? _cachedMoonPhase;
136
137 private static bool? _cachedBloodMoon;
138
139 private static bool? _cachedEclipse;
140
141 private static int? _cachedCultistDelay;
142
143 private static bool? _cachedPartyGenuine;
144
145 private static bool? _cachedPartyManual;
146
147 private static int? _cachedPartyDaysOnCooldown;
148
149 private static readonly List<int> CachedCelebratingNPCs = new List<int>();
150
151 private static bool? _cachedSandstormHappening;
152
153 private static bool _tempSandstormHappening;
154
155 private static int? _cachedSandstormTimeLeft;
156
157 private static int _tempSandstormTimeLeft;
158
159 private static float? _cachedSandstormSeverity;
160
161 private static float _tempSandstormSeverity;
162
163 private static float? _cachedSandstormIntendedSeverity;
164
165 private static float _tempSandstormIntendedSeverity;
166
167 private static bool _tempLanternNightGenuine;
168
169 private static bool _tempLanternNightManual;
170
172
173 private static int _tempLanternNightCooldown;
174
175 private static bool? _cachedLanternNightGenuine;
176
177 private static bool? _cachedLanternNightManual;
178
180
181 private static int? _cachedLanternNightCooldown;
182
184
185 public static event Action OnWorldLoad;
186
210
211 public static void SetOngoingToTemps()
212 {
213 Main.dayTime = _tempDayTime;
214 Main.time = _tempTime;
215 Main.moonPhase = _tempMoonPhase;
216 Main.bloodMoon = _tempBloodMoon;
217 Main.eclipse = _tempEclipse;
218 Main.raining = _tempRaining;
219 Main.rainTime = _tempRainTime;
220 Main.maxRaining = _tempMaxRain;
221 Main.cloudAlpha = _tempMaxRain;
222 CultistRitual.delay = _tempCultistDelay;
223 BirthdayParty.ManualParty = _tempPartyManual;
224 BirthdayParty.GenuineParty = _tempPartyGenuine;
225 BirthdayParty.PartyDaysOnCooldown = _tempPartyCooldown;
228 Sandstorm.Happening = _tempSandstormHappening;
229 Sandstorm.TimeLeft = _tempSandstormTimeLeft;
230 Sandstorm.Severity = _tempSandstormSeverity;
231 Sandstorm.IntendedSeverity = _tempSandstormIntendedSeverity;
232 LanternNight.GenuineLanterns = _tempLanternNightGenuine;
233 LanternNight.LanternNightsOnCooldown = _tempLanternNightCooldown;
234 LanternNight.ManualLanterns = _tempLanternNightManual;
235 LanternNight.NextNightIsLanternNight = _tempLanternNightNextNightIsGenuine;
236 }
237
238 public static bool IsValidWorld(string file, bool cloudSave)
239 {
240 return GetFileMetadata(file, cloudSave) != null;
241 }
242
243 public static WorldFileData GetAllMetadata(string file, bool cloudSave)
244 {
245 if (file == null || (cloudSave && SocialAPI.Cloud == null))
246 {
247 return null;
248 }
251 {
253 }
254 try
255 {
256 using Stream stream = (cloudSave ? ((Stream)new MemoryStream(SocialAPI.Cloud.Read(file))) : ((Stream)new FileStream(file, FileMode.Open)));
258 int num = binaryReader.ReadInt32();
259 if (num >= 135)
260 {
261 worldFileData.Metadata = FileMetadata.Read(binaryReader, FileType.World);
262 }
263 else
264 {
265 worldFileData.Metadata = FileMetadata.FromCurrentSettings(FileType.World);
266 }
267 if (num <= 279)
268 {
269 binaryReader.ReadInt16();
270 stream.Position = binaryReader.ReadInt32();
271 worldFileData.Name = binaryReader.ReadString();
272 if (num >= 179)
273 {
274 string seed = ((num != 179) ? binaryReader.ReadString() : binaryReader.ReadInt32().ToString());
275 worldFileData.SetSeed(seed);
276 worldFileData.WorldGeneratorVersion = binaryReader.ReadUInt64();
277 }
278 else
279 {
280 worldFileData.SetSeedToEmpty();
281 worldFileData.WorldGeneratorVersion = 0uL;
282 }
283 if (num >= 181)
284 {
285 worldFileData.UniqueId = new Guid(binaryReader.ReadBytes(16));
286 }
287 else
288 {
289 worldFileData.UniqueId = Guid.Empty;
290 }
291 binaryReader.ReadInt32();
292 binaryReader.ReadInt32();
293 binaryReader.ReadInt32();
294 binaryReader.ReadInt32();
295 binaryReader.ReadInt32();
296 int y = binaryReader.ReadInt32();
297 int x = binaryReader.ReadInt32();
298 worldFileData.SetWorldSize(x, y);
299 if (num >= 209)
300 {
301 worldFileData.GameMode = binaryReader.ReadInt32();
302 if (num >= 222)
303 {
304 worldFileData.DrunkWorld = binaryReader.ReadBoolean();
305 if (num >= 227)
306 {
307 worldFileData.ForTheWorthy = binaryReader.ReadBoolean();
308 }
309 if (num >= 238)
310 {
311 worldFileData.Anniversary = binaryReader.ReadBoolean();
312 }
313 if (num >= 239)
314 {
315 worldFileData.DontStarve = binaryReader.ReadBoolean();
316 }
317 if (num >= 241)
318 {
319 worldFileData.NotTheBees = binaryReader.ReadBoolean();
320 }
321 if (num >= 249)
322 {
323 worldFileData.RemixWorld = binaryReader.ReadBoolean();
324 }
325 if (num >= 266)
326 {
327 worldFileData.NoTrapsWorld = binaryReader.ReadBoolean();
328 }
329 if (num >= 267)
330 {
331 worldFileData.ZenithWorld = binaryReader.ReadBoolean();
332 }
333 else
334 {
335 worldFileData.ZenithWorld = worldFileData.DrunkWorld && worldFileData.RemixWorld;
336 }
337 }
338 }
339 else if (num >= 112)
340 {
341 if (binaryReader.ReadBoolean())
342 {
343 worldFileData.GameMode = 1;
344 }
345 else
346 {
347 worldFileData.GameMode = 0;
348 }
349 }
350 if (num >= 141)
351 {
352 worldFileData.CreationTime = DateTime.FromBinary(binaryReader.ReadInt64());
353 }
354 else if (!cloudSave)
355 {
356 worldFileData.CreationTime = File.GetCreationTime(file);
357 }
358 else
359 {
360 worldFileData.CreationTime = DateTime.Now;
361 }
362 binaryReader.ReadByte();
363 binaryReader.ReadInt32();
364 binaryReader.ReadInt32();
365 binaryReader.ReadInt32();
366 binaryReader.ReadInt32();
367 binaryReader.ReadInt32();
368 binaryReader.ReadInt32();
369 binaryReader.ReadInt32();
370 binaryReader.ReadInt32();
371 binaryReader.ReadInt32();
372 binaryReader.ReadInt32();
373 binaryReader.ReadInt32();
374 binaryReader.ReadInt32();
375 binaryReader.ReadInt32();
376 binaryReader.ReadInt32();
377 binaryReader.ReadInt32();
378 binaryReader.ReadInt32();
379 binaryReader.ReadInt32();
380 binaryReader.ReadInt32();
381 binaryReader.ReadInt32();
382 binaryReader.ReadDouble();
383 binaryReader.ReadDouble();
384 binaryReader.ReadDouble();
385 binaryReader.ReadBoolean();
386 binaryReader.ReadInt32();
387 binaryReader.ReadBoolean();
388 binaryReader.ReadBoolean();
389 binaryReader.ReadInt32();
390 binaryReader.ReadInt32();
391 worldFileData.HasCrimson = binaryReader.ReadBoolean();
392 binaryReader.ReadBoolean();
393 binaryReader.ReadBoolean();
394 binaryReader.ReadBoolean();
395 binaryReader.ReadBoolean();
396 binaryReader.ReadBoolean();
397 binaryReader.ReadBoolean();
398 binaryReader.ReadBoolean();
399 binaryReader.ReadBoolean();
400 binaryReader.ReadBoolean();
401 binaryReader.ReadBoolean();
402 if (num >= 118)
403 {
404 binaryReader.ReadBoolean();
405 }
406 else
407 _ = 0;
408 binaryReader.ReadBoolean();
409 binaryReader.ReadBoolean();
410 binaryReader.ReadBoolean();
411 binaryReader.ReadBoolean();
412 binaryReader.ReadBoolean();
413 binaryReader.ReadBoolean();
414 binaryReader.ReadBoolean();
415 binaryReader.ReadBoolean();
416 binaryReader.ReadBoolean();
417 binaryReader.ReadByte();
418 binaryReader.ReadInt32();
419 worldFileData.IsHardMode = binaryReader.ReadBoolean();
420 if (num >= 257)
421 {
422 binaryReader.ReadBoolean();
423 }
424 binaryReader.ReadInt32();
425 binaryReader.ReadInt32();
426 binaryReader.ReadInt32();
427 binaryReader.ReadDouble();
428 if (num >= 118)
429 {
430 binaryReader.ReadDouble();
431 }
432 if (num >= 113)
433 {
434 binaryReader.ReadByte();
435 }
436 binaryReader.ReadBoolean();
437 binaryReader.ReadInt32();
438 binaryReader.ReadSingle();
439 binaryReader.ReadInt32();
440 binaryReader.ReadInt32();
441 binaryReader.ReadInt32();
442 binaryReader.ReadByte();
443 binaryReader.ReadByte();
444 binaryReader.ReadByte();
445 binaryReader.ReadByte();
446 binaryReader.ReadByte();
447 binaryReader.ReadByte();
448 binaryReader.ReadByte();
449 binaryReader.ReadByte();
450 binaryReader.ReadInt32();
451 binaryReader.ReadInt16();
452 binaryReader.ReadSingle();
453 if (num < 95)
454 {
455 return worldFileData;
456 }
457 for (int num2 = binaryReader.ReadInt32(); num2 > 0; num2--)
458 {
459 binaryReader.ReadString();
460 }
461 if (num < 99)
462 {
463 return worldFileData;
464 }
465 binaryReader.ReadBoolean();
466 if (num < 101)
467 {
468 return worldFileData;
469 }
470 binaryReader.ReadInt32();
471 if (num < 104)
472 {
473 return worldFileData;
474 }
475 binaryReader.ReadBoolean();
476 if (num >= 129)
477 {
478 binaryReader.ReadBoolean();
479 }
480 if (num >= 201)
481 {
482 binaryReader.ReadBoolean();
483 }
484 if (num >= 107)
485 {
486 binaryReader.ReadInt32();
487 }
488 if (num >= 108)
489 {
490 binaryReader.ReadInt32();
491 }
492 if (num < 109)
493 {
494 return worldFileData;
495 }
496 int num3 = binaryReader.ReadInt16();
497 for (int i = 0; i < num3; i++)
498 {
499 binaryReader.ReadInt32();
500 }
501 if (num < 128)
502 {
503 return worldFileData;
504 }
505 binaryReader.ReadBoolean();
506 if (num < 131)
507 {
508 return worldFileData;
509 }
510 binaryReader.ReadBoolean();
511 binaryReader.ReadBoolean();
512 binaryReader.ReadBoolean();
513 worldFileData.DefeatedMoonlord = binaryReader.ReadBoolean();
514 return worldFileData;
515 }
516 }
517 catch (Exception)
518 {
519 }
520 return null;
521 }
522
523 public static WorldFileData CreateMetadata(string name, bool cloudSave, int GameMode)
524 {
527 {
529 Main.autoGenFileLocation = null;
530 }
531 worldFileData.Name = name;
532 worldFileData.GameMode = GameMode;
533 worldFileData.CreationTime = DateTime.Now;
534 worldFileData.Metadata = FileMetadata.FromCurrentSettings(FileType.World);
535 worldFileData.SetFavorite(favorite: false);
536 worldFileData.WorldGeneratorVersion = 1198295875585uL;
537 worldFileData.UniqueId = Guid.NewGuid();
538 if (Main.DefaultSeed == "")
539 {
540 worldFileData.SetSeedToRandom();
541 }
542 else
543 {
545 }
546 return worldFileData;
547 }
548
549 public static void ResetTemps()
550 {
551 _tempRaining = false;
552 _tempMaxRain = 0f;
553 _tempRainTime = 0;
554 _tempDayTime = true;
555 _tempBloodMoon = false;
556 _tempEclipse = false;
557 _tempMoonPhase = 0;
559 Main.anglerQuestFinished = false;
560 }
561
562 public static void ClearTempTiles()
563 {
564 for (int i = 0; i < Main.maxTilesX; i++)
565 {
566 for (int j = 0; j < Main.maxTilesY; j++)
567 {
568 if (Main.tile[i, j].type == 127 || Main.tile[i, j].type == 504)
569 {
570 WorldGen.KillTile(i, j);
571 }
572 }
573 }
574 }
575
576 public static void LoadWorld(bool loadFromCloud)
577 {
578 Main.lockMenuBGChange = true;
580 Main.checkXMas();
582 bool flag = loadFromCloud && SocialAPI.Cloud != null;
584 {
585 if (!flag)
586 {
587 for (int num = Main.worldPathName.Length - 1; num >= 0; num--)
588 {
589 if (Main.worldPathName.Substring(num, 1) == (Path.DirectorySeparatorChar.ToString() ?? ""))
590 {
591 Utils.TryCreatingDirectory(Main.worldPathName.Substring(0, num));
592 break;
593 }
594 }
595 }
597 Main.ActiveWorldFileData = CreateMetadata((Main.worldName == "") ? "World" : Main.worldName, flag, Main.GameMode);
598 string text = (Main.AutogenSeedName ?? "").Trim();
599 if (text.Length == 0)
600 {
601 Main.ActiveWorldFileData.SetSeedToRandom();
602 }
603 else
604 {
606 }
609 SaveWorld();
610 }
611 try
612 {
615 try
616 {
617 WorldGen.loadFailed = false;
618 WorldGen.loadSuccess = false;
619 int num2 = (_versionNumber = binaryReader.ReadInt32());
621 {
622 WorldGen.loadFailed = true;
623 return;
624 }
626 if (num2 < 141)
627 {
628 if (!loadFromCloud)
629 {
630 Main.ActiveWorldFileData.CreationTime = File.GetCreationTime(Main.worldPathName);
631 }
632 else
633 {
634 Main.ActiveWorldFileData.CreationTime = DateTime.Now;
635 }
636 }
638 binaryReader.Close();
639 memoryStream.Close();
640 if (num3 != 0)
641 {
642 WorldGen.loadFailed = true;
643 }
644 else
645 {
646 WorldGen.loadSuccess = true;
647 }
649 {
650 return;
651 }
654 WorldGen.gen = true;
655 GenVars.waterLine = Main.maxTilesY;
658 int num4 = 0;
659 Liquid.quickSettle = true;
660 int num5 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
661 float num6 = 0f;
662 while (Liquid.numLiquid > 0 && num4 < 100000)
663 {
664 num4++;
665 float num7 = (float)(num5 - (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer)) / (float)num5;
667 {
668 num5 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
669 }
670 if (num7 > num6)
671 {
672 num6 = num7;
673 }
674 else
675 {
676 num7 = num6;
677 }
678 Main.statusText = Lang.gen[27].Value + " " + (int)(num7 * 100f / 2f + 50f) + "%";
680 }
681 Liquid.quickSettle = false;
682 Main.weatherCounter = WorldGen.genRand.Next(3600, 18000);
685 WorldGen.gen = false;
687 if (Main.slimeRainTime > 0.0)
688 {
690 }
692 }
694 {
696 WorldGen.loadFailed = true;
697 WorldGen.loadSuccess = false;
698 try
699 {
700 binaryReader.Close();
701 memoryStream.Close();
702 return;
703 }
704 catch
705 {
706 return;
707 }
708 }
709 }
711 {
713 WorldGen.loadFailed = true;
714 WorldGen.loadSuccess = false;
715 return;
716 }
717 if (WorldFile.OnWorldLoad != null)
718 {
720 }
721 }
722
723 public static void CheckSavedOreTiers()
724 {
726 {
727 return;
728 }
729 int[] array = WorldGen.CountTileTypesInWorld(7, 166, 6, 167, 9, 168, 8, 169);
730 for (int i = 0; i < array.Length; i += 2)
731 {
732 int num = array[i];
733 int num2 = array[i + 1];
734 switch (i)
735 {
736 case 0:
737 if (num > num2)
738 {
739 WorldGen.SavedOreTiers.Copper = 7;
740 }
741 else
742 {
743 WorldGen.SavedOreTiers.Copper = 166;
744 }
745 break;
746 case 2:
747 if (num > num2)
748 {
749 WorldGen.SavedOreTiers.Iron = 6;
750 }
751 else
752 {
753 WorldGen.SavedOreTiers.Iron = 167;
754 }
755 break;
756 case 4:
757 if (num > num2)
758 {
759 WorldGen.SavedOreTiers.Silver = 9;
760 }
761 else
762 {
763 WorldGen.SavedOreTiers.Silver = 168;
764 }
765 break;
766 case 6:
767 if (num > num2)
768 {
769 WorldGen.SavedOreTiers.Gold = 8;
770 }
771 else
772 {
773 WorldGen.SavedOreTiers.Gold = 169;
774 }
775 break;
776 }
777 }
778 }
779
780 public static void SaveWorld()
781 {
782 try
783 {
785 }
786 catch (Exception exception)
787 {
789 throw;
790 }
791 }
792
793 public static void SaveWorld(bool useCloudSaving, bool resetTime = false)
794 {
795 if (useCloudSaving && SocialAPI.Cloud == null)
796 {
797 return;
798 }
799 if (Main.worldName == "")
800 {
801 Main.worldName = "World";
802 }
804 {
805 Main.statusText = Lang.gen[48].Value;
806 }
807 if (!Monitor.TryEnter(IOLock))
808 {
809 return;
810 }
811 try
812 {
814 {
816 });
817 }
818 finally
819 {
821 }
822 }
823
824 private static void InternalSaveWorld(bool useCloudSaving, bool resetTime)
825 {
827 if (Main.skipMenu)
828 {
829 return;
830 }
831 if (_hasCache)
832 {
834 }
835 else
836 {
838 }
839 if (resetTime)
840 {
842 }
843 if (Main.worldPathName == null)
844 {
845 return;
846 }
847 new Stopwatch().Start();
848 int num;
849 byte[] array;
850 using (MemoryStream memoryStream = new MemoryStream(7000000))
851 {
853 {
855 }
856 array = memoryStream.ToArray();
857 num = array.Length;
858 }
859 byte[] array2 = null;
861 {
863 }
866 string text = null;
867 using (MemoryStream input = new MemoryStream(array, 0, num, writable: false))
868 {
871 {
872 if (array2 != null)
873 {
874 text = Main.worldPathName + ".bak";
875 Main.statusText = Lang.gen[50].Value;
876 }
878 }
879 else
880 {
882 }
883 }
884 if (text != null && array2 != null)
885 {
887 }
888 }
889
890 private static void DoRollingBackups(string backupWorldWritePath)
891 {
893 {
894 return;
895 }
897 if (num > 9)
898 {
899 num = 9;
900 }
901 int num2 = 1;
902 for (int i = 1; i < num; i++)
903 {
904 string path = backupWorldWritePath + i;
905 if (i == 1)
906 {
908 }
909 if (!FileUtilities.Exists(path, cloud: false))
910 {
911 break;
912 }
913 num2 = i + 1;
914 }
915 for (int num3 = num2 - 1; num3 > 0; num3--)
916 {
917 string text = backupWorldWritePath + num3;
918 if (num3 == 1)
919 {
921 }
922 string destination = backupWorldWritePath + (num3 + 1);
923 if (FileUtilities.Exists(text, cloud: false))
924 {
926 }
927 }
928 }
929
930 private static void ResetTempsToDayTime()
931 {
932 _tempDayTime = true;
933 _tempTime = 13500.0;
934 _tempMoonPhase = 0;
935 _tempBloodMoon = false;
936 _tempEclipse = false;
937 _tempCultistDelay = 86400;
938 _tempPartyManual = false;
939 _tempPartyGenuine = false;
941 {
942 _tempPartyGenuine = true;
943 }
954 }
955
981
1008
1009 private static void ConvertOldTileEntities()
1010 {
1013 for (int i = 0; i < Main.maxTilesX; i++)
1014 {
1015 for (int j = 0; j < Main.maxTilesY; j++)
1016 {
1017 Tile tile = Main.tile[i, j];
1018 if ((tile.type == 128 || tile.type == 269) && tile.frameY == 0 && (tile.frameX % 100 == 0 || tile.frameX % 100 == 36))
1019 {
1020 list.Add(new Point(i, j));
1021 }
1022 if (tile.type == 334 && tile.frameY == 0 && tile.frameX % 54 == 0)
1023 {
1024 list2.Add(new Point(i, j));
1025 }
1026 if (tile.type == 49 && (tile.frameX == -1 || tile.frameY == -1))
1027 {
1028 tile.frameX = 0;
1029 tile.frameY = 0;
1030 }
1031 }
1032 }
1033 foreach (Point item in list)
1034 {
1035 if (!WorldGen.InWorld(item.X, item.Y, 5))
1036 {
1037 continue;
1038 }
1039 int frameX = Main.tile[item.X, item.Y].frameX;
1040 int frameX2 = Main.tile[item.X, item.Y + 1].frameX;
1041 int frameX3 = Main.tile[item.X, item.Y + 2].frameX;
1042 for (int k = 0; k < 2; k++)
1043 {
1044 for (int l = 0; l < 3; l++)
1045 {
1046 Tile tile2 = Main.tile[item.X + k, item.Y + l];
1047 tile2.frameX %= 100;
1048 if (tile2.type == 269)
1049 {
1050 tile2.frameX += 72;
1051 }
1052 tile2.type = 470;
1053 }
1054 }
1055 int num = TEDisplayDoll.Place(item.X, item.Y);
1056 if (num != -1)
1057 {
1058 (TileEntity.ByID[num] as TEDisplayDoll).SetInventoryFromMannequin(frameX, frameX2, frameX3);
1059 }
1060 }
1061 foreach (Point item2 in list2)
1062 {
1063 if (!WorldGen.InWorld(item2.X, item2.Y, 5))
1064 {
1065 continue;
1066 }
1067 bool flag = Main.tile[item2.X, item2.Y].frameX >= 54;
1068 short frameX4 = Main.tile[item2.X, item2.Y + 1].frameX;
1069 int frameX5 = Main.tile[item2.X + 1, item2.Y + 1].frameX;
1070 bool flag2 = frameX4 >= 5000;
1071 int num2 = frameX4 % 5000;
1072 num2 -= 100;
1073 int prefix = frameX5 - ((frameX5 >= 25000) ? 25000 : 10000);
1074 for (int m = 0; m < 3; m++)
1075 {
1076 for (int n = 0; n < 3; n++)
1077 {
1078 Tile tile3 = Main.tile[item2.X + m, item2.Y + n];
1079 tile3.type = 471;
1080 tile3.frameX = (short)((flag ? 54 : 0) + m * 18);
1081 tile3.frameY = (short)(n * 18);
1082 }
1083 }
1084 if (TEWeaponsRack.Place(item2.X, item2.Y) != -1 && flag2)
1085 {
1087 }
1088 }
1089 }
1090
1110
1112 {
1113 ushort count = TileID.Count;
1114 short num = 11;
1115 writer.Write(279);
1116 Main.WorldFileMetadata.IncrementAndWrite(writer);
1117 writer.Write(num);
1118 for (int i = 0; i < num; i++)
1119 {
1120 writer.Write(0);
1121 }
1122 writer.Write(count);
1123 byte b = 0;
1124 byte b2 = 1;
1125 for (int i = 0; i < count; i++)
1126 {
1127 if (Main.tileFrameImportant[i])
1128 {
1129 b |= b2;
1130 }
1131 if (b2 == 128)
1132 {
1133 writer.Write(b);
1134 b = 0;
1135 b2 = 1;
1136 }
1137 else
1138 {
1139 b2 <<= 1;
1140 }
1141 }
1142 if (b2 != 1)
1143 {
1144 writer.Write(b);
1145 }
1146 return (int)writer.BaseStream.Position;
1147 }
1148
1150 {
1151 writer.BaseStream.Position = 0L;
1152 writer.Write(279);
1153 writer.BaseStream.Position += 20L;
1154 writer.Write((short)pointers.Length);
1155 for (int i = 0; i < pointers.Length; i++)
1156 {
1157 writer.Write(pointers[i]);
1158 }
1159 return (int)writer.BaseStream.Position;
1160 }
1161
1163 {
1164 writer.Write(Main.worldName);
1165 writer.Write(Main.ActiveWorldFileData.SeedText);
1166 writer.Write(Main.ActiveWorldFileData.WorldGeneratorVersion);
1167 writer.Write(Main.ActiveWorldFileData.UniqueId.ToByteArray());
1168 writer.Write(Main.worldID);
1169 writer.Write((int)Main.leftWorld);
1170 writer.Write((int)Main.rightWorld);
1171 writer.Write((int)Main.topWorld);
1172 writer.Write((int)Main.bottomWorld);
1173 writer.Write(Main.maxTilesY);
1174 writer.Write(Main.maxTilesX);
1175 writer.Write(Main.GameMode);
1176 writer.Write(Main.drunkWorld);
1177 writer.Write(Main.getGoodWorld);
1181 writer.Write(Main.remixWorld);
1182 writer.Write(Main.noTrapsWorld);
1183 writer.Write(Main.zenithWorld);
1184 writer.Write(Main.ActiveWorldFileData.CreationTime.ToBinary());
1185 writer.Write((byte)Main.moonType);
1186 writer.Write(Main.treeX[0]);
1187 writer.Write(Main.treeX[1]);
1188 writer.Write(Main.treeX[2]);
1189 writer.Write(Main.treeStyle[0]);
1190 writer.Write(Main.treeStyle[1]);
1191 writer.Write(Main.treeStyle[2]);
1192 writer.Write(Main.treeStyle[3]);
1193 writer.Write(Main.caveBackX[0]);
1194 writer.Write(Main.caveBackX[1]);
1195 writer.Write(Main.caveBackX[2]);
1196 writer.Write(Main.caveBackStyle[0]);
1197 writer.Write(Main.caveBackStyle[1]);
1198 writer.Write(Main.caveBackStyle[2]);
1199 writer.Write(Main.caveBackStyle[3]);
1200 writer.Write(Main.iceBackStyle);
1202 writer.Write(Main.hellBackStyle);
1203 writer.Write(Main.spawnTileX);
1204 writer.Write(Main.spawnTileY);
1205 writer.Write(Main.worldSurface);
1206 writer.Write(Main.rockLayer);
1207 writer.Write(_tempTime);
1208 writer.Write(_tempDayTime);
1209 writer.Write(_tempMoonPhase);
1210 writer.Write(_tempBloodMoon);
1211 writer.Write(_tempEclipse);
1212 writer.Write(Main.dungeonX);
1213 writer.Write(Main.dungeonY);
1214 writer.Write(WorldGen.crimson);
1215 writer.Write(NPC.downedBoss1);
1216 writer.Write(NPC.downedBoss2);
1217 writer.Write(NPC.downedBoss3);
1218 writer.Write(NPC.downedQueenBee);
1219 writer.Write(NPC.downedMechBoss1);
1220 writer.Write(NPC.downedMechBoss2);
1221 writer.Write(NPC.downedMechBoss3);
1223 writer.Write(NPC.downedPlantBoss);
1224 writer.Write(NPC.downedGolemBoss);
1225 writer.Write(NPC.downedSlimeKing);
1226 writer.Write(NPC.savedGoblin);
1227 writer.Write(NPC.savedWizard);
1228 writer.Write(NPC.savedMech);
1229 writer.Write(NPC.downedGoblins);
1230 writer.Write(NPC.downedClown);
1231 writer.Write(NPC.downedFrost);
1232 writer.Write(NPC.downedPirates);
1235 writer.Write((byte)WorldGen.shadowOrbCount);
1236 writer.Write(WorldGen.altarCount);
1237 writer.Write(Main.hardMode);
1239 writer.Write(Main.invasionDelay);
1240 writer.Write(Main.invasionSize);
1241 writer.Write(Main.invasionType);
1242 writer.Write(Main.invasionX);
1243 writer.Write(Main.slimeRainTime);
1244 writer.Write((byte)Main.sundialCooldown);
1245 writer.Write(_tempRaining);
1246 writer.Write(_tempRainTime);
1247 writer.Write(_tempMaxRain);
1251 writer.Write((byte)WorldGen.treeBG1);
1252 writer.Write((byte)WorldGen.corruptBG);
1253 writer.Write((byte)WorldGen.jungleBG);
1254 writer.Write((byte)WorldGen.snowBG);
1255 writer.Write((byte)WorldGen.hallowBG);
1256 writer.Write((byte)WorldGen.crimsonBG);
1257 writer.Write((byte)WorldGen.desertBG);
1258 writer.Write((byte)WorldGen.oceanBG);
1259 writer.Write((int)Main.cloudBGActive);
1260 writer.Write((short)Main.numClouds);
1262 writer.Write(Main.anglerWhoFinishedToday.Count);
1263 for (int i = 0; i < Main.anglerWhoFinishedToday.Count; i++)
1264 {
1266 }
1267 writer.Write(NPC.savedAngler);
1268 writer.Write(Main.anglerQuest);
1269 writer.Write(NPC.savedStylist);
1271 writer.Write(NPC.savedGolfer);
1274 writer.Write(NPCID.Count);
1275 for (int j = 0; j < NPCID.Count; j++)
1276 {
1277 writer.Write(NPC.killCount[j]);
1278 }
1280 writer.Write(NPC.downedFishron);
1281 writer.Write(NPC.downedMartians);
1283 writer.Write(NPC.downedMoonlord);
1298 writer.Write(_tempPartyManual);
1301 writer.Write(TempPartyCelebratingNPCs.Count);
1302 for (int k = 0; k < TempPartyCelebratingNPCs.Count; k++)
1303 {
1305 }
1310 writer.Write(NPC.savedBartender);
1312 writer.Write((byte)WorldGen.mushroomBG);
1313 writer.Write((byte)WorldGen.underworldBG);
1314 writer.Write((byte)WorldGen.treeBG2);
1315 writer.Write((byte)WorldGen.treeBG3);
1316 writer.Write((byte)WorldGen.treeBG4);
1322 WorldGen.TreeTops.Save(writer);
1329 writer.Write(NPC.boughtCat);
1330 writer.Write(NPC.boughtDog);
1331 writer.Write(NPC.boughtBunny);
1334 writer.Write(NPC.downedDeerclops);
1354 writer.Write((byte)Main.moondialCooldown);
1355 return (int)writer.BaseStream.Position;
1356 }
1357
1359 {
1360 byte[] array = new byte[16];
1361 for (int i = 0; i < Main.maxTilesX; i++)
1362 {
1363 float num = (float)i / (float)Main.maxTilesX;
1364 Main.statusText = Lang.gen[49].Value + " " + (int)(num * 100f + 1f) + "%";
1365 int num2;
1366 for (num2 = 0; num2 < Main.maxTilesY; num2++)
1367 {
1368 Tile tile = Main.tile[i, num2];
1369 int num3 = 4;
1370 byte b2;
1371 byte b;
1372 byte b3;
1373 byte b4 = (b3 = (b2 = (b = 0)));
1374 bool flag = false;
1375 if (tile.active())
1376 {
1377 flag = true;
1378 }
1379 if (flag)
1380 {
1381 b4 = (byte)(b4 | 2u);
1382 array[num3] = (byte)tile.type;
1383 num3++;
1384 if (tile.type > 255)
1385 {
1386 array[num3] = (byte)(tile.type >> 8);
1387 num3++;
1388 b4 = (byte)(b4 | 0x20u);
1389 }
1390 if (Main.tileFrameImportant[tile.type])
1391 {
1392 array[num3] = (byte)((uint)tile.frameX & 0xFFu);
1393 num3++;
1394 array[num3] = (byte)((tile.frameX & 0xFF00) >> 8);
1395 num3++;
1396 array[num3] = (byte)((uint)tile.frameY & 0xFFu);
1397 num3++;
1398 array[num3] = (byte)((tile.frameY & 0xFF00) >> 8);
1399 num3++;
1400 }
1401 if (tile.color() != 0)
1402 {
1403 b2 = (byte)(b2 | 8u);
1404 array[num3] = tile.color();
1405 num3++;
1406 }
1407 }
1408 if (tile.wall != 0)
1409 {
1410 b4 = (byte)(b4 | 4u);
1411 array[num3] = (byte)tile.wall;
1412 num3++;
1413 if (tile.wallColor() != 0)
1414 {
1415 b2 = (byte)(b2 | 0x10u);
1416 array[num3] = tile.wallColor();
1417 num3++;
1418 }
1419 }
1420 if (tile.liquid != 0)
1421 {
1422 if (!tile.shimmer())
1423 {
1424 b4 = (tile.lava() ? ((byte)(b4 | 0x10u)) : ((!tile.honey()) ? ((byte)(b4 | 8u)) : ((byte)(b4 | 0x18u))));
1425 }
1426 else
1427 {
1428 b2 = (byte)(b2 | 0x80u);
1429 b4 = (byte)(b4 | 8u);
1430 }
1431 array[num3] = tile.liquid;
1432 num3++;
1433 }
1434 if (tile.wire())
1435 {
1436 b3 = (byte)(b3 | 2u);
1437 }
1438 if (tile.wire2())
1439 {
1440 b3 = (byte)(b3 | 4u);
1441 }
1442 if (tile.wire3())
1443 {
1444 b3 = (byte)(b3 | 8u);
1445 }
1446 int num4 = (tile.halfBrick() ? 16 : ((tile.slope() != 0) ? (tile.slope() + 1 << 4) : 0));
1447 b3 |= (byte)num4;
1448 if (tile.actuator())
1449 {
1450 b2 = (byte)(b2 | 2u);
1451 }
1452 if (tile.inActive())
1453 {
1454 b2 = (byte)(b2 | 4u);
1455 }
1456 if (tile.wire4())
1457 {
1458 b2 = (byte)(b2 | 0x20u);
1459 }
1460 if (tile.wall > 255)
1461 {
1462 array[num3] = (byte)(tile.wall >> 8);
1463 num3++;
1464 b2 = (byte)(b2 | 0x40u);
1465 }
1466 if (tile.invisibleBlock())
1467 {
1468 b = (byte)(b | 2u);
1469 }
1470 if (tile.invisibleWall())
1471 {
1472 b = (byte)(b | 4u);
1473 }
1474 if (tile.fullbrightBlock())
1475 {
1476 b = (byte)(b | 8u);
1477 }
1478 if (tile.fullbrightWall())
1479 {
1480 b = (byte)(b | 0x10u);
1481 }
1482 int num5 = 3;
1483 if (b != 0)
1484 {
1485 b2 = (byte)(b2 | 1u);
1486 array[num5] = b;
1487 num5--;
1488 }
1489 if (b2 != 0)
1490 {
1491 b3 = (byte)(b3 | 1u);
1492 array[num5] = b2;
1493 num5--;
1494 }
1495 if (b3 != 0)
1496 {
1497 b4 = (byte)(b4 | 1u);
1498 array[num5] = b3;
1499 num5--;
1500 }
1501 short num6 = 0;
1502 int num7 = num2 + 1;
1503 int num8 = Main.maxTilesY - num2 - 1;
1504 while (num8 > 0 && tile.isTheSameAs(Main.tile[i, num7]) && TileID.Sets.AllowsSaveCompressionBatching[tile.type])
1505 {
1506 num6++;
1507 num8--;
1508 num7++;
1509 }
1510 num2 += num6;
1511 if (num6 > 0)
1512 {
1513 array[num3] = (byte)((uint)num6 & 0xFFu);
1514 num3++;
1515 if (num6 > 255)
1516 {
1517 b4 = (byte)(b4 | 0x80u);
1518 array[num3] = (byte)((num6 & 0xFF00) >> 8);
1519 num3++;
1520 }
1521 else
1522 {
1523 b4 = (byte)(b4 | 0x40u);
1524 }
1525 }
1526 array[num5] = b4;
1527 writer.Write(array, num5, num3 - num5);
1528 }
1529 }
1530 return (int)writer.BaseStream.Position;
1531 }
1532
1533 public static int SaveChests(BinaryWriter writer)
1534 {
1535 short num = 0;
1536 for (int i = 0; i < 8000; i++)
1537 {
1538 Chest chest = Main.chest[i];
1539 if (chest == null)
1540 {
1541 continue;
1542 }
1543 bool flag = false;
1544 for (int j = chest.x; j <= chest.x + 1; j++)
1545 {
1546 for (int k = chest.y; k <= chest.y + 1; k++)
1547 {
1548 if (j < 0 || k < 0 || j >= Main.maxTilesX || k >= Main.maxTilesY)
1549 {
1550 flag = true;
1551 break;
1552 }
1553 Tile tile = Main.tile[j, k];
1554 if (!tile.active() || !Main.tileContainer[tile.type])
1555 {
1556 flag = true;
1557 break;
1558 }
1559 }
1560 }
1561 if (flag)
1562 {
1563 Main.chest[i] = null;
1564 }
1565 else
1566 {
1567 num++;
1568 }
1569 }
1570 writer.Write(num);
1571 writer.Write((short)40);
1572 for (int i = 0; i < 8000; i++)
1573 {
1574 Chest chest = Main.chest[i];
1575 if (chest == null)
1576 {
1577 continue;
1578 }
1579 writer.Write(chest.x);
1580 writer.Write(chest.y);
1581 writer.Write(chest.name);
1582 for (int l = 0; l < 40; l++)
1583 {
1584 Item item = chest.item[l];
1586 {
1587 writer.Write((short)0);
1588 continue;
1589 }
1590 if (item.stack < 0)
1591 {
1592 item.stack = 1;
1593 }
1594 writer.Write((short)item.stack);
1595 if (item.stack > 0)
1596 {
1597 writer.Write(item.netID);
1598 writer.Write(item.prefix);
1599 }
1600 }
1601 }
1602 return (int)writer.BaseStream.Position;
1603 }
1604
1605 public static int SaveSigns(BinaryWriter writer)
1606 {
1607 short num = 0;
1608 for (int i = 0; i < 1000; i++)
1609 {
1610 Sign sign = Main.sign[i];
1611 if (sign != null && sign.text != null)
1612 {
1613 num++;
1614 }
1615 }
1616 writer.Write(num);
1617 for (int j = 0; j < 1000; j++)
1618 {
1619 Sign sign = Main.sign[j];
1620 if (sign != null && sign.text != null)
1621 {
1622 writer.Write(sign.text);
1623 writer.Write(sign.x);
1624 writer.Write(sign.y);
1625 }
1626 }
1627 return (int)writer.BaseStream.Position;
1628 }
1629
1630 public static int SaveNPCs(BinaryWriter writer)
1631 {
1632 bool[] array = (bool[])NPC.ShimmeredTownNPCs.Clone();
1633 writer.Write(array.Count(value: true));
1634 for (int i = 0; i < array.Length; i++)
1635 {
1636 if (array[i])
1637 {
1638 writer.Write(i);
1639 }
1640 }
1641 for (int j = 0; j < Main.npc.Length; j++)
1642 {
1643 NPC nPC = Main.npc[j];
1644 if (nPC.active && nPC.townNPC && nPC.type != 368)
1645 {
1646 writer.Write(nPC.active);
1647 writer.Write(nPC.netID);
1648 writer.Write(nPC.GivenName);
1649 writer.Write(nPC.position.X);
1650 writer.Write(nPC.position.Y);
1651 writer.Write(nPC.homeless);
1652 writer.Write(nPC.homeTileX);
1653 writer.Write(nPC.homeTileY);
1654 BitsByte bitsByte = (byte)0;
1655 bitsByte[0] = nPC.townNPC;
1656 writer.Write(bitsByte);
1657 if (bitsByte[0])
1658 {
1659 writer.Write(nPC.townNpcVariationIndex);
1660 }
1661 }
1662 }
1663 writer.Write(value: false);
1664 for (int k = 0; k < Main.npc.Length; k++)
1665 {
1666 NPC nPC2 = Main.npc[k];
1667 if (nPC2.active && NPCID.Sets.SavesAndLoads[nPC2.type])
1668 {
1669 writer.Write(nPC2.active);
1670 writer.Write(nPC2.netID);
1671 writer.WriteVector2(nPC2.position);
1672 }
1673 }
1674 writer.Write(value: false);
1675 return (int)writer.BaseStream.Position;
1676 }
1677
1678 public static int SaveFooter(BinaryWriter writer)
1679 {
1680 writer.Write(value: true);
1681 writer.Write(Main.worldName);
1682 writer.Write(Main.worldID);
1683 return (int)writer.BaseStream.Position;
1684 }
1685
1686 public static int LoadWorld_Version2(BinaryReader reader)
1687 {
1688 reader.BaseStream.Position = 0L;
1690 {
1691 return 5;
1692 }
1693 if (reader.BaseStream.Position != positions[0])
1694 {
1695 return 5;
1696 }
1697 LoadHeader(reader);
1698 if (reader.BaseStream.Position != positions[1])
1699 {
1700 return 5;
1701 }
1702 LoadWorldTiles(reader, importance);
1703 if (reader.BaseStream.Position != positions[2])
1704 {
1705 return 5;
1706 }
1707 LoadChests(reader);
1708 if (reader.BaseStream.Position != positions[3])
1709 {
1710 return 5;
1711 }
1712 LoadSigns(reader);
1713 if (reader.BaseStream.Position != positions[4])
1714 {
1715 return 5;
1716 }
1717 LoadNPCs(reader);
1718 if (reader.BaseStream.Position != positions[5])
1719 {
1720 return 5;
1721 }
1722 if (_versionNumber >= 116)
1723 {
1724 if (_versionNumber < 122)
1725 {
1726 LoadDummies(reader);
1727 if (reader.BaseStream.Position != positions[6])
1728 {
1729 return 5;
1730 }
1731 }
1732 else
1733 {
1734 LoadTileEntities(reader);
1735 if (reader.BaseStream.Position != positions[6])
1736 {
1737 return 5;
1738 }
1739 }
1740 }
1741 if (_versionNumber >= 170)
1742 {
1744 if (reader.BaseStream.Position != positions[7])
1745 {
1746 return 5;
1747 }
1748 }
1749 if (_versionNumber >= 189)
1750 {
1751 LoadTownManager(reader);
1752 if (reader.BaseStream.Position != positions[8])
1753 {
1754 return 5;
1755 }
1756 }
1757 if (_versionNumber >= 210)
1758 {
1760 if (reader.BaseStream.Position != positions[9])
1761 {
1762 return 5;
1763 }
1764 }
1765 else
1766 {
1768 }
1769 if (_versionNumber >= 220)
1770 {
1772 if (reader.BaseStream.Position != positions[10])
1773 {
1774 return 5;
1775 }
1776 }
1778 return LoadFooter(reader);
1779 }
1780
1781 private static void LoadWorld_LastMinuteFixes()
1782 {
1783 if (_versionNumber < 258)
1784 {
1786 }
1788 }
1789
1790 private static void FixAgainstExploits()
1791 {
1792 for (int i = 0; i < 8000; i++)
1793 {
1794 Main.chest[i]?.FixLoadedData();
1795 }
1796 foreach (TileEntity value in TileEntity.ByID.Values)
1797 {
1799 {
1800 fixLoadedData.FixLoadedData();
1801 }
1802 }
1803 }
1804
1805 public static bool LoadFileFormatHeader(BinaryReader reader, out bool[] importance, out int[] positions)
1806 {
1807 importance = null;
1808 positions = null;
1809 if ((_versionNumber = reader.ReadInt32()) >= 135)
1810 {
1811 try
1812 {
1813 Main.WorldFileMetadata = FileMetadata.Read(reader, FileType.World);
1814 }
1815 catch (FormatException value)
1816 {
1817 Console.WriteLine(Language.GetTextValue("Error.UnableToLoadWorld"));
1819 return false;
1820 }
1821 }
1822 else
1823 {
1824 Main.WorldFileMetadata = FileMetadata.FromCurrentSettings(FileType.World);
1825 }
1826 short num = reader.ReadInt16();
1827 positions = new int[num];
1828 for (int i = 0; i < num; i++)
1829 {
1830 positions[i] = reader.ReadInt32();
1831 }
1832 ushort num2 = reader.ReadUInt16();
1833 importance = new bool[num2];
1834 byte b = 0;
1835 byte b2 = 128;
1836 for (int i = 0; i < num2; i++)
1837 {
1838 if (b2 == 128)
1839 {
1840 b = reader.ReadByte();
1841 b2 = 1;
1842 }
1843 else
1844 {
1845 b2 <<= 1;
1846 }
1847 if ((b & b2) == b2)
1848 {
1849 importance[i] = true;
1850 }
1851 }
1852 return true;
1853 }
1854
1855 public static void LoadHeader(BinaryReader reader)
1856 {
1857 int versionNumber = _versionNumber;
1858 Main.worldName = reader.ReadString();
1859 if (versionNumber >= 179)
1860 {
1861 string seed = ((versionNumber != 179) ? reader.ReadString() : reader.ReadInt32().ToString());
1862 Main.ActiveWorldFileData.SetSeed(seed);
1863 Main.ActiveWorldFileData.WorldGeneratorVersion = reader.ReadUInt64();
1864 }
1865 if (versionNumber >= 181)
1866 {
1867 Main.ActiveWorldFileData.UniqueId = new Guid(reader.ReadBytes(16));
1868 }
1869 else
1870 {
1871 Main.ActiveWorldFileData.UniqueId = Guid.NewGuid();
1872 }
1873 Main.worldID = reader.ReadInt32();
1874 Main.leftWorld = reader.ReadInt32();
1875 Main.rightWorld = reader.ReadInt32();
1876 Main.topWorld = reader.ReadInt32();
1877 Main.bottomWorld = reader.ReadInt32();
1878 Main.maxTilesY = reader.ReadInt32();
1879 Main.maxTilesX = reader.ReadInt32();
1881 if (versionNumber >= 209)
1882 {
1883 Main.GameMode = reader.ReadInt32();
1884 if (versionNumber >= 222)
1885 {
1886 Main.drunkWorld = reader.ReadBoolean();
1887 }
1888 if (versionNumber >= 227)
1889 {
1890 Main.getGoodWorld = reader.ReadBoolean();
1891 }
1892 if (versionNumber >= 238)
1893 {
1894 Main.tenthAnniversaryWorld = reader.ReadBoolean();
1895 }
1896 if (versionNumber >= 239)
1897 {
1898 Main.dontStarveWorld = reader.ReadBoolean();
1899 }
1900 if (versionNumber >= 241)
1901 {
1902 Main.notTheBeesWorld = reader.ReadBoolean();
1903 }
1904 if (versionNumber >= 249)
1905 {
1906 Main.remixWorld = reader.ReadBoolean();
1907 }
1908 if (versionNumber >= 266)
1909 {
1910 Main.noTrapsWorld = reader.ReadBoolean();
1911 }
1912 if (versionNumber >= 267)
1913 {
1914 Main.zenithWorld = reader.ReadBoolean();
1915 }
1916 else
1917 {
1918 Main.zenithWorld = Main.remixWorld && Main.drunkWorld;
1919 }
1920 }
1921 else
1922 {
1923 if (versionNumber >= 112)
1924 {
1925 Main.GameMode = (reader.ReadBoolean() ? 1 : 0);
1926 }
1927 else
1928 {
1929 Main.GameMode = 0;
1930 }
1931 if (versionNumber == 208 && reader.ReadBoolean())
1932 {
1933 Main.GameMode = 2;
1934 }
1935 }
1936 if (versionNumber >= 141)
1937 {
1938 Main.ActiveWorldFileData.CreationTime = DateTime.FromBinary(reader.ReadInt64());
1939 }
1940 Main.moonType = reader.ReadByte();
1941 Main.treeX[0] = reader.ReadInt32();
1942 Main.treeX[1] = reader.ReadInt32();
1943 Main.treeX[2] = reader.ReadInt32();
1944 Main.treeStyle[0] = reader.ReadInt32();
1945 Main.treeStyle[1] = reader.ReadInt32();
1946 Main.treeStyle[2] = reader.ReadInt32();
1947 Main.treeStyle[3] = reader.ReadInt32();
1948 Main.caveBackX[0] = reader.ReadInt32();
1949 Main.caveBackX[1] = reader.ReadInt32();
1950 Main.caveBackX[2] = reader.ReadInt32();
1951 Main.caveBackStyle[0] = reader.ReadInt32();
1952 Main.caveBackStyle[1] = reader.ReadInt32();
1953 Main.caveBackStyle[2] = reader.ReadInt32();
1954 Main.caveBackStyle[3] = reader.ReadInt32();
1955 Main.iceBackStyle = reader.ReadInt32();
1956 Main.jungleBackStyle = reader.ReadInt32();
1957 Main.hellBackStyle = reader.ReadInt32();
1958 Main.spawnTileX = reader.ReadInt32();
1959 Main.spawnTileY = reader.ReadInt32();
1960 Main.worldSurface = reader.ReadDouble();
1961 Main.rockLayer = reader.ReadDouble();
1962 _tempTime = reader.ReadDouble();
1963 _tempDayTime = reader.ReadBoolean();
1964 _tempMoonPhase = reader.ReadInt32();
1965 _tempBloodMoon = reader.ReadBoolean();
1966 _tempEclipse = reader.ReadBoolean();
1967 Main.eclipse = _tempEclipse;
1968 Main.dungeonX = reader.ReadInt32();
1969 Main.dungeonY = reader.ReadInt32();
1970 WorldGen.crimson = reader.ReadBoolean();
1971 NPC.downedBoss1 = reader.ReadBoolean();
1972 NPC.downedBoss2 = reader.ReadBoolean();
1973 NPC.downedBoss3 = reader.ReadBoolean();
1974 NPC.downedQueenBee = reader.ReadBoolean();
1975 NPC.downedMechBoss1 = reader.ReadBoolean();
1976 NPC.downedMechBoss2 = reader.ReadBoolean();
1977 NPC.downedMechBoss3 = reader.ReadBoolean();
1978 NPC.downedMechBossAny = reader.ReadBoolean();
1979 NPC.downedPlantBoss = reader.ReadBoolean();
1980 NPC.downedGolemBoss = reader.ReadBoolean();
1981 if (versionNumber >= 118)
1982 {
1983 NPC.downedSlimeKing = reader.ReadBoolean();
1984 }
1985 NPC.savedGoblin = reader.ReadBoolean();
1986 NPC.savedWizard = reader.ReadBoolean();
1987 NPC.savedMech = reader.ReadBoolean();
1988 NPC.downedGoblins = reader.ReadBoolean();
1989 NPC.downedClown = reader.ReadBoolean();
1990 NPC.downedFrost = reader.ReadBoolean();
1991 NPC.downedPirates = reader.ReadBoolean();
1992 WorldGen.shadowOrbSmashed = reader.ReadBoolean();
1993 WorldGen.spawnMeteor = reader.ReadBoolean();
1994 WorldGen.shadowOrbCount = reader.ReadByte();
1995 WorldGen.altarCount = reader.ReadInt32();
1996 Main.hardMode = reader.ReadBoolean();
1997 if (versionNumber >= 257)
1998 {
1999 Main.afterPartyOfDoom = reader.ReadBoolean();
2000 }
2001 else
2002 {
2003 Main.afterPartyOfDoom = false;
2004 }
2005 Main.invasionDelay = reader.ReadInt32();
2006 Main.invasionSize = reader.ReadInt32();
2007 Main.invasionType = reader.ReadInt32();
2008 Main.invasionX = reader.ReadDouble();
2009 if (versionNumber >= 118)
2010 {
2011 Main.slimeRainTime = reader.ReadDouble();
2012 }
2013 if (versionNumber >= 113)
2014 {
2015 Main.sundialCooldown = reader.ReadByte();
2016 }
2017 _tempRaining = reader.ReadBoolean();
2018 _tempRainTime = reader.ReadInt32();
2019 _tempMaxRain = reader.ReadSingle();
2020 WorldGen.SavedOreTiers.Cobalt = reader.ReadInt32();
2021 WorldGen.SavedOreTiers.Mythril = reader.ReadInt32();
2022 WorldGen.SavedOreTiers.Adamantite = reader.ReadInt32();
2023 WorldGen.setBG(0, reader.ReadByte());
2024 WorldGen.setBG(1, reader.ReadByte());
2025 WorldGen.setBG(2, reader.ReadByte());
2026 WorldGen.setBG(3, reader.ReadByte());
2027 WorldGen.setBG(4, reader.ReadByte());
2028 WorldGen.setBG(5, reader.ReadByte());
2029 WorldGen.setBG(6, reader.ReadByte());
2030 WorldGen.setBG(7, reader.ReadByte());
2031 Main.cloudBGActive = reader.ReadInt32();
2032 Main.cloudBGAlpha = (((double)Main.cloudBGActive < 1.0) ? 0f : 1f);
2033 Main.cloudBGActive = -WorldGen.genRand.Next(8640, 86400);
2034 Main.numClouds = reader.ReadInt16();
2035 Main.windSpeedTarget = reader.ReadSingle();
2036 Main.windSpeedCurrent = Main.windSpeedTarget;
2037 if (versionNumber < 95)
2038 {
2039 return;
2040 }
2042 for (int num = reader.ReadInt32(); num > 0; num--)
2043 {
2045 }
2046 if (versionNumber < 99)
2047 {
2048 return;
2049 }
2050 NPC.savedAngler = reader.ReadBoolean();
2051 if (versionNumber < 101)
2052 {
2053 return;
2054 }
2055 Main.anglerQuest = reader.ReadInt32();
2056 if (versionNumber < 104)
2057 {
2058 return;
2059 }
2060 NPC.savedStylist = reader.ReadBoolean();
2061 if (versionNumber >= 129)
2062 {
2063 NPC.savedTaxCollector = reader.ReadBoolean();
2064 }
2065 if (versionNumber >= 201)
2066 {
2067 NPC.savedGolfer = reader.ReadBoolean();
2068 }
2069 if (versionNumber < 107)
2070 {
2071 if (Main.invasionType > 0 && Main.invasionSize > 0)
2072 {
2074 }
2075 }
2076 else
2077 {
2078 Main.invasionSizeStart = reader.ReadInt32();
2079 }
2080 if (versionNumber < 108)
2081 {
2082 _tempCultistDelay = 86400;
2083 }
2084 else
2085 {
2086 _tempCultistDelay = reader.ReadInt32();
2087 }
2088 if (versionNumber < 109)
2089 {
2090 return;
2091 }
2092 int num2 = reader.ReadInt16();
2093 for (int i = 0; i < num2; i++)
2094 {
2095 if (i < NPCID.Count)
2096 {
2097 NPC.killCount[i] = reader.ReadInt32();
2098 }
2099 else
2100 {
2101 reader.ReadInt32();
2102 }
2103 }
2104 if (versionNumber < 128)
2105 {
2106 return;
2107 }
2108 Main.fastForwardTimeToDawn = reader.ReadBoolean();
2109 if (versionNumber < 131)
2110 {
2111 return;
2112 }
2113 NPC.downedFishron = reader.ReadBoolean();
2114 NPC.downedMartians = reader.ReadBoolean();
2115 NPC.downedAncientCultist = reader.ReadBoolean();
2116 NPC.downedMoonlord = reader.ReadBoolean();
2117 NPC.downedHalloweenKing = reader.ReadBoolean();
2118 NPC.downedHalloweenTree = reader.ReadBoolean();
2119 NPC.downedChristmasIceQueen = reader.ReadBoolean();
2120 NPC.downedChristmasSantank = reader.ReadBoolean();
2121 NPC.downedChristmasTree = reader.ReadBoolean();
2122 if (versionNumber < 140)
2123 {
2124 return;
2125 }
2126 NPC.downedTowerSolar = reader.ReadBoolean();
2127 NPC.downedTowerVortex = reader.ReadBoolean();
2128 NPC.downedTowerNebula = reader.ReadBoolean();
2129 NPC.downedTowerStardust = reader.ReadBoolean();
2130 NPC.TowerActiveSolar = reader.ReadBoolean();
2131 NPC.TowerActiveVortex = reader.ReadBoolean();
2132 NPC.TowerActiveNebula = reader.ReadBoolean();
2133 NPC.TowerActiveStardust = reader.ReadBoolean();
2134 NPC.LunarApocalypseIsUp = reader.ReadBoolean();
2136 {
2137 NPC.ShieldStrengthTowerSolar = NPC.ShieldStrengthTowerMax;
2138 }
2140 {
2141 NPC.ShieldStrengthTowerVortex = NPC.ShieldStrengthTowerMax;
2142 }
2144 {
2145 NPC.ShieldStrengthTowerNebula = NPC.ShieldStrengthTowerMax;
2146 }
2148 {
2149 NPC.ShieldStrengthTowerStardust = NPC.ShieldStrengthTowerMax;
2150 }
2151 if (versionNumber < 170)
2152 {
2153 _tempPartyManual = false;
2154 _tempPartyGenuine = false;
2157 }
2158 else
2159 {
2160 _tempPartyManual = reader.ReadBoolean();
2161 _tempPartyGenuine = reader.ReadBoolean();
2162 _tempPartyCooldown = reader.ReadInt32();
2163 int num3 = reader.ReadInt32();
2165 for (int j = 0; j < num3; j++)
2166 {
2167 TempPartyCelebratingNPCs.Add(reader.ReadInt32());
2168 }
2169 }
2170 if (versionNumber < 174)
2171 {
2176 }
2177 else
2178 {
2183 }
2184 DD2Event.Load(reader, versionNumber);
2185 if (versionNumber > 194)
2186 {
2187 WorldGen.setBG(8, reader.ReadByte());
2188 }
2189 else
2190 {
2191 WorldGen.setBG(8, 0);
2192 }
2193 if (versionNumber >= 215)
2194 {
2195 WorldGen.setBG(9, reader.ReadByte());
2196 }
2197 else
2198 {
2199 WorldGen.setBG(9, 0);
2200 }
2201 if (versionNumber > 195)
2202 {
2203 WorldGen.setBG(10, reader.ReadByte());
2204 WorldGen.setBG(11, reader.ReadByte());
2205 WorldGen.setBG(12, reader.ReadByte());
2206 }
2207 else
2208 {
2212 }
2213 if (versionNumber >= 204)
2214 {
2215 NPC.combatBookWasUsed = reader.ReadBoolean();
2216 }
2217 if (versionNumber < 207)
2218 {
2223 }
2224 else
2225 {
2230 }
2231 WorldGen.TreeTops.Load(reader, versionNumber);
2232 if (versionNumber >= 212)
2233 {
2234 Main.forceHalloweenForToday = reader.ReadBoolean();
2235 Main.forceXMasForToday = reader.ReadBoolean();
2236 }
2237 else
2238 {
2239 Main.forceHalloweenForToday = false;
2240 Main.forceXMasForToday = false;
2241 }
2242 if (versionNumber >= 216)
2243 {
2244 WorldGen.SavedOreTiers.Copper = reader.ReadInt32();
2245 WorldGen.SavedOreTiers.Iron = reader.ReadInt32();
2246 WorldGen.SavedOreTiers.Silver = reader.ReadInt32();
2247 WorldGen.SavedOreTiers.Gold = reader.ReadInt32();
2248 }
2249 else
2250 {
2251 WorldGen.SavedOreTiers.Copper = -1;
2252 WorldGen.SavedOreTiers.Iron = -1;
2253 WorldGen.SavedOreTiers.Silver = -1;
2254 WorldGen.SavedOreTiers.Gold = -1;
2255 }
2256 if (versionNumber >= 217)
2257 {
2258 NPC.boughtCat = reader.ReadBoolean();
2259 NPC.boughtDog = reader.ReadBoolean();
2260 NPC.boughtBunny = reader.ReadBoolean();
2261 }
2262 else
2263 {
2264 NPC.boughtCat = false;
2265 NPC.boughtDog = false;
2266 NPC.boughtBunny = false;
2267 }
2268 if (versionNumber >= 223)
2269 {
2270 NPC.downedEmpressOfLight = reader.ReadBoolean();
2271 NPC.downedQueenSlime = reader.ReadBoolean();
2272 }
2273 else
2274 {
2275 NPC.downedEmpressOfLight = false;
2276 NPC.downedQueenSlime = false;
2277 }
2278 if (versionNumber >= 240)
2279 {
2280 NPC.downedDeerclops = reader.ReadBoolean();
2281 }
2282 else
2283 {
2284 NPC.downedDeerclops = false;
2285 }
2286 if (versionNumber >= 250)
2287 {
2288 NPC.unlockedSlimeBlueSpawn = reader.ReadBoolean();
2289 }
2290 else
2291 {
2292 NPC.unlockedSlimeBlueSpawn = false;
2293 }
2294 if (versionNumber >= 251)
2295 {
2296 NPC.unlockedMerchantSpawn = reader.ReadBoolean();
2297 NPC.unlockedDemolitionistSpawn = reader.ReadBoolean();
2298 NPC.unlockedPartyGirlSpawn = reader.ReadBoolean();
2299 NPC.unlockedDyeTraderSpawn = reader.ReadBoolean();
2300 NPC.unlockedTruffleSpawn = reader.ReadBoolean();
2301 NPC.unlockedArmsDealerSpawn = reader.ReadBoolean();
2302 NPC.unlockedNurseSpawn = reader.ReadBoolean();
2303 NPC.unlockedPrincessSpawn = reader.ReadBoolean();
2304 }
2305 else
2306 {
2307 NPC.unlockedMerchantSpawn = false;
2308 NPC.unlockedDemolitionistSpawn = false;
2309 NPC.unlockedPartyGirlSpawn = false;
2310 NPC.unlockedDyeTraderSpawn = false;
2311 NPC.unlockedTruffleSpawn = false;
2312 NPC.unlockedArmsDealerSpawn = false;
2313 NPC.unlockedNurseSpawn = false;
2314 NPC.unlockedPrincessSpawn = false;
2315 }
2316 if (versionNumber >= 259)
2317 {
2318 NPC.combatBookVolumeTwoWasUsed = reader.ReadBoolean();
2319 }
2320 else
2321 {
2322 NPC.combatBookVolumeTwoWasUsed = false;
2323 }
2324 if (versionNumber >= 260)
2325 {
2326 NPC.peddlersSatchelWasUsed = reader.ReadBoolean();
2327 }
2328 else
2329 {
2330 NPC.peddlersSatchelWasUsed = false;
2331 }
2332 if (versionNumber >= 261)
2333 {
2334 NPC.unlockedSlimeGreenSpawn = reader.ReadBoolean();
2335 NPC.unlockedSlimeOldSpawn = reader.ReadBoolean();
2336 NPC.unlockedSlimePurpleSpawn = reader.ReadBoolean();
2337 NPC.unlockedSlimeRainbowSpawn = reader.ReadBoolean();
2338 NPC.unlockedSlimeRedSpawn = reader.ReadBoolean();
2339 NPC.unlockedSlimeYellowSpawn = reader.ReadBoolean();
2340 NPC.unlockedSlimeCopperSpawn = reader.ReadBoolean();
2341 }
2342 else
2343 {
2344 NPC.unlockedSlimeGreenSpawn = false;
2345 NPC.unlockedSlimeOldSpawn = false;
2346 NPC.unlockedSlimePurpleSpawn = false;
2347 NPC.unlockedSlimeRainbowSpawn = false;
2348 NPC.unlockedSlimeRedSpawn = false;
2349 NPC.unlockedSlimeYellowSpawn = false;
2350 NPC.unlockedSlimeCopperSpawn = false;
2351 }
2352 if (versionNumber >= 264)
2353 {
2354 Main.fastForwardTimeToDusk = reader.ReadBoolean();
2355 Main.moondialCooldown = reader.ReadByte();
2356 }
2357 else
2358 {
2359 Main.fastForwardTimeToDusk = false;
2360 Main.moondialCooldown = 0;
2361 }
2363 }
2364
2365 public static void LoadWorldTiles(BinaryReader reader, bool[] importance)
2366 {
2367 for (int i = 0; i < Main.maxTilesX; i++)
2368 {
2369 float num = (float)i / (float)Main.maxTilesX;
2370 Main.statusText = Lang.gen[51].Value + " " + (int)((double)num * 100.0 + 1.0) + "%";
2371 for (int j = 0; j < Main.maxTilesY; j++)
2372 {
2373 int num2 = -1;
2374 byte b2;
2375 byte b;
2376 byte b3 = (b2 = (b = 0));
2377 Tile tile = Main.tile[i, j];
2378 byte b4 = reader.ReadByte();
2379 bool flag = false;
2380 if ((b4 & 1) == 1)
2381 {
2382 flag = true;
2383 b3 = reader.ReadByte();
2384 }
2385 bool flag2 = false;
2386 if (flag && (b3 & 1) == 1)
2387 {
2388 flag2 = true;
2389 b2 = reader.ReadByte();
2390 }
2391 if (flag2 && (b2 & 1) == 1)
2392 {
2393 b = reader.ReadByte();
2394 }
2395 byte b5;
2396 if ((b4 & 2) == 2)
2397 {
2398 tile.active(active: true);
2399 if ((b4 & 0x20) == 32)
2400 {
2401 b5 = reader.ReadByte();
2402 num2 = reader.ReadByte();
2403 num2 = (num2 << 8) | b5;
2404 }
2405 else
2406 {
2407 num2 = reader.ReadByte();
2408 }
2409 tile.type = (ushort)num2;
2410 if (importance[num2])
2411 {
2412 tile.frameX = reader.ReadInt16();
2413 tile.frameY = reader.ReadInt16();
2414 if (tile.type == 144)
2415 {
2416 tile.frameY = 0;
2417 }
2418 }
2419 else
2420 {
2421 tile.frameX = -1;
2422 tile.frameY = -1;
2423 }
2424 if ((b2 & 8) == 8)
2425 {
2426 tile.color(reader.ReadByte());
2427 }
2428 }
2429 if ((b4 & 4) == 4)
2430 {
2431 tile.wall = reader.ReadByte();
2432 if (tile.wall >= WallID.Count)
2433 {
2434 tile.wall = 0;
2435 }
2436 if ((b2 & 0x10) == 16)
2437 {
2438 tile.wallColor(reader.ReadByte());
2439 }
2440 }
2441 b5 = (byte)((b4 & 0x18) >> 3);
2442 if (b5 != 0)
2443 {
2444 tile.liquid = reader.ReadByte();
2445 if ((b2 & 0x80) == 128)
2446 {
2447 tile.shimmer(shimmer: true);
2448 }
2449 else if (b5 > 1)
2450 {
2451 if (b5 == 2)
2452 {
2453 tile.lava(lava: true);
2454 }
2455 else
2456 {
2457 tile.honey(honey: true);
2458 }
2459 }
2460 }
2461 if (b3 > 1)
2462 {
2463 if ((b3 & 2) == 2)
2464 {
2465 tile.wire(wire: true);
2466 }
2467 if ((b3 & 4) == 4)
2468 {
2469 tile.wire2(wire2: true);
2470 }
2471 if ((b3 & 8) == 8)
2472 {
2473 tile.wire3(wire3: true);
2474 }
2475 b5 = (byte)((b3 & 0x70) >> 4);
2476 if (b5 != 0 && (Main.tileSolid[tile.type] || TileID.Sets.NonSolidSaveSlopes[tile.type]))
2477 {
2478 if (b5 == 1)
2479 {
2480 tile.halfBrick(halfBrick: true);
2481 }
2482 else
2483 {
2484 tile.slope((byte)(b5 - 1));
2485 }
2486 }
2487 }
2488 if (b2 > 1)
2489 {
2490 if ((b2 & 2) == 2)
2491 {
2492 tile.actuator(actuator: true);
2493 }
2494 if ((b2 & 4) == 4)
2495 {
2496 tile.inActive(inActive: true);
2497 }
2498 if ((b2 & 0x20) == 32)
2499 {
2500 tile.wire4(wire4: true);
2501 }
2502 if ((b2 & 0x40) == 64)
2503 {
2504 b5 = reader.ReadByte();
2505 tile.wall = (ushort)((b5 << 8) | tile.wall);
2506 if (tile.wall >= WallID.Count)
2507 {
2508 tile.wall = 0;
2509 }
2510 }
2511 }
2512 if (b > 1)
2513 {
2514 if ((b & 2) == 2)
2515 {
2516 tile.invisibleBlock(invisibleBlock: true);
2517 }
2518 if ((b & 4) == 4)
2519 {
2520 tile.invisibleWall(invisibleWall: true);
2521 }
2522 if ((b & 8) == 8)
2523 {
2524 tile.fullbrightBlock(fullbrightBlock: true);
2525 }
2526 if ((b & 0x10) == 16)
2527 {
2528 tile.fullbrightWall(fullbrightWall: true);
2529 }
2530 }
2531 int num3 = (byte)((b4 & 0xC0) >> 6) switch
2532 {
2533 0 => 0,
2534 1 => reader.ReadByte(),
2535 _ => reader.ReadInt16(),
2536 };
2537 if (num2 != -1)
2538 {
2539 if ((double)j <= Main.worldSurface)
2540 {
2541 if ((double)(j + num3) <= Main.worldSurface)
2542 {
2543 WorldGen.tileCounts[num2] += (num3 + 1) * 5;
2544 }
2545 else
2546 {
2547 int num4 = (int)(Main.worldSurface - (double)j + 1.0);
2548 int num5 = num3 + 1 - num4;
2549 WorldGen.tileCounts[num2] += num4 * 5 + num5;
2550 }
2551 }
2552 else
2553 {
2554 WorldGen.tileCounts[num2] += num3 + 1;
2555 }
2556 }
2557 while (num3 > 0)
2558 {
2559 j++;
2560 Main.tile[i, j].CopyFrom(tile);
2561 num3--;
2562 }
2563 }
2564 }
2566 if (_versionNumber < 105)
2567 {
2569 }
2570 }
2571
2572 public static void LoadChests(BinaryReader reader)
2573 {
2574 int num = reader.ReadInt16();
2575 int num2 = reader.ReadInt16();
2576 int num3;
2577 int num4;
2578 if (num2 < 40)
2579 {
2580 num3 = num2;
2581 num4 = 0;
2582 }
2583 else
2584 {
2585 num3 = 40;
2586 num4 = num2 - 40;
2587 }
2588 int i;
2589 for (i = 0; i < num; i++)
2590 {
2591 Chest chest = new Chest();
2592 chest.x = reader.ReadInt32();
2593 chest.y = reader.ReadInt32();
2594 chest.name = reader.ReadString();
2595 for (int j = 0; j < num3; j++)
2596 {
2597 short num5 = reader.ReadInt16();
2598 Item item = new Item();
2599 if (num5 > 0)
2600 {
2601 item.netDefaults(reader.ReadInt32());
2602 item.stack = num5;
2603 item.Prefix(reader.ReadByte());
2604 }
2605 else if (num5 < 0)
2606 {
2607 item.netDefaults(reader.ReadInt32());
2608 item.Prefix(reader.ReadByte());
2609 item.stack = 1;
2610 }
2611 chest.item[j] = item;
2612 }
2613 for (int k = 0; k < num4; k++)
2614 {
2615 short num5 = reader.ReadInt16();
2616 if (num5 > 0)
2617 {
2618 reader.ReadInt32();
2619 reader.ReadByte();
2620 }
2621 }
2622 Main.chest[i] = chest;
2623 }
2625 for (int l = 0; l < i; l++)
2626 {
2627 if (Main.chest[l] != null)
2628 {
2629 Point16 item2 = new Point16(Main.chest[l].x, Main.chest[l].y);
2630 if (list.Contains(item2))
2631 {
2632 Main.chest[l] = null;
2633 }
2634 else
2635 {
2636 list.Add(item2);
2637 }
2638 }
2639 }
2640 for (; i < 8000; i++)
2641 {
2642 Main.chest[i] = null;
2643 }
2644 if (_versionNumber < 115)
2645 {
2647 }
2648 }
2649
2651 {
2652 for (int i = 0; i < Main.maxTilesX; i++)
2653 {
2654 for (int j = 0; j < Main.maxTilesY; j++)
2655 {
2656 Tile tile = Main.tile[i, j];
2657 if (tile.active() && tile.color() == 31)
2658 {
2659 tile.color(0);
2660 tile.fullbrightBlock(fullbrightBlock: true);
2661 }
2662 if (tile.wallColor() == 31)
2663 {
2664 tile.wallColor(0);
2665 tile.fullbrightWall(fullbrightWall: true);
2666 }
2667 }
2668 }
2669 }
2670
2671 public static void LoadSigns(BinaryReader reader)
2672 {
2673 short num = reader.ReadInt16();
2674 int i;
2675 for (i = 0; i < num; i++)
2676 {
2677 string text = reader.ReadString();
2678 int num2 = reader.ReadInt32();
2679 int num3 = reader.ReadInt32();
2680 Tile tile = Main.tile[num2, num3];
2681 Sign sign;
2682 if (tile.active() && Main.tileSign[tile.type])
2683 {
2684 sign = new Sign();
2685 sign.text = text;
2686 sign.x = num2;
2687 sign.y = num3;
2688 }
2689 else
2690 {
2691 sign = null;
2692 }
2693 Main.sign[i] = sign;
2694 }
2696 for (int j = 0; j < 1000; j++)
2697 {
2698 if (Main.sign[j] != null)
2699 {
2700 Point16 item = new Point16(Main.sign[j].x, Main.sign[j].y);
2701 if (list.Contains(item))
2702 {
2703 Main.sign[j] = null;
2704 }
2705 else
2706 {
2707 list.Add(item);
2708 }
2709 }
2710 }
2711 for (; i < 1000; i++)
2712 {
2713 Main.sign[i] = null;
2714 }
2715 }
2716
2717 public static void LoadDummies(BinaryReader reader)
2718 {
2719 int num = reader.ReadInt32();
2720 for (int i = 0; i < num; i++)
2721 {
2722 reader.ReadInt16();
2723 reader.ReadInt16();
2724 }
2725 }
2726
2727 public static void LoadNPCs(BinaryReader reader)
2728 {
2729 if (_versionNumber >= 268)
2730 {
2731 int num = reader.ReadInt32();
2732 while (num-- > 0)
2733 {
2734 NPC.ShimmeredTownNPCs[reader.ReadInt32()] = true;
2735 }
2736 }
2737 int num2 = 0;
2738 bool flag = reader.ReadBoolean();
2739 while (flag)
2740 {
2741 NPC nPC = Main.npc[num2];
2742 if (_versionNumber >= 190)
2743 {
2744 nPC.SetDefaults(reader.ReadInt32());
2745 }
2746 else
2747 {
2748 nPC.SetDefaults(NPCID.FromLegacyName(reader.ReadString()));
2749 }
2750 nPC.GivenName = reader.ReadString();
2751 nPC.position.X = reader.ReadSingle();
2752 nPC.position.Y = reader.ReadSingle();
2753 nPC.homeless = reader.ReadBoolean();
2754 nPC.homeTileX = reader.ReadInt32();
2755 nPC.homeTileY = reader.ReadInt32();
2756 if (_versionNumber >= 213 && ((BitsByte)reader.ReadByte())[0])
2757 {
2758 nPC.townNpcVariationIndex = reader.ReadInt32();
2759 }
2760 num2++;
2761 flag = reader.ReadBoolean();
2762 }
2763 if (_versionNumber < 140)
2764 {
2765 return;
2766 }
2767 flag = reader.ReadBoolean();
2768 while (flag)
2769 {
2770 NPC nPC = Main.npc[num2];
2771 if (_versionNumber >= 190)
2772 {
2773 nPC.SetDefaults(reader.ReadInt32());
2774 }
2775 else
2776 {
2777 nPC.SetDefaults(NPCID.FromLegacyName(reader.ReadString()));
2778 }
2779 nPC.position = reader.ReadVector2();
2780 num2++;
2781 flag = reader.ReadBoolean();
2782 }
2783 if (_versionNumber < 251)
2784 {
2785 NPC.unlockedMerchantSpawn = NPC.AnyNPCs(17);
2786 NPC.unlockedDemolitionistSpawn = NPC.AnyNPCs(38);
2787 NPC.unlockedPartyGirlSpawn = NPC.AnyNPCs(208);
2788 NPC.unlockedDyeTraderSpawn = NPC.AnyNPCs(207);
2789 NPC.unlockedTruffleSpawn = NPC.AnyNPCs(160);
2790 NPC.unlockedArmsDealerSpawn = NPC.AnyNPCs(19);
2791 NPC.unlockedNurseSpawn = NPC.AnyNPCs(18);
2792 NPC.unlockedPrincessSpawn = NPC.AnyNPCs(663);
2793 }
2794 }
2795
2797 {
2798 int num = fileIO.ReadInt32();
2799 while (num-- > 0)
2800 {
2801 fileIO.ReadInt32();
2802 }
2803 bool flag = fileIO.ReadBoolean();
2804 while (flag)
2805 {
2806 fileIO.ReadInt32();
2807 fileIO.ReadString();
2808 fileIO.ReadSingle();
2809 fileIO.ReadSingle();
2810 fileIO.ReadBoolean();
2811 fileIO.ReadInt32();
2812 fileIO.ReadInt32();
2813 if (((BitsByte)fileIO.ReadByte())[0])
2814 {
2815 fileIO.ReadInt32();
2816 }
2817 flag = fileIO.ReadBoolean();
2818 }
2819 flag = fileIO.ReadBoolean();
2820 while (flag)
2821 {
2822 fileIO.ReadInt32();
2823 fileIO.ReadSingle();
2824 fileIO.ReadSingle();
2825 flag = fileIO.ReadBoolean();
2826 }
2827 }
2828
2829 public static int LoadFooter(BinaryReader reader)
2830 {
2831 if (!reader.ReadBoolean())
2832 {
2833 return 6;
2834 }
2835 if (reader.ReadString() != Main.worldName)
2836 {
2837 return 6;
2838 }
2839 if (reader.ReadInt32() != Main.worldID)
2840 {
2841 return 6;
2842 }
2843 return 0;
2844 }
2845
2847 {
2848 new Stopwatch().Start();
2849 try
2850 {
2851 Stream baseStream = fileIO.BaseStream;
2852 int num = fileIO.ReadInt32();
2853 if (num == 0 || num > 279)
2854 {
2855 return false;
2856 }
2857 baseStream.Position = 0L;
2859 {
2860 return false;
2861 }
2862 string text = fileIO.ReadString();
2863 if (num >= 179)
2864 {
2865 if (num == 179)
2866 {
2867 fileIO.ReadInt32();
2868 }
2869 else
2870 {
2871 fileIO.ReadString();
2872 }
2873 fileIO.ReadUInt64();
2874 }
2875 if (num >= 181)
2876 {
2877 fileIO.ReadBytes(16);
2878 }
2879 int num2 = fileIO.ReadInt32();
2880 fileIO.ReadInt32();
2881 fileIO.ReadInt32();
2882 fileIO.ReadInt32();
2883 fileIO.ReadInt32();
2884 int num3 = fileIO.ReadInt32();
2885 int num4 = fileIO.ReadInt32();
2886 baseStream.Position = positions[1];
2887 for (int i = 0; i < num4; i++)
2888 {
2889 float num5 = (float)i / (float)Main.maxTilesX;
2890 Main.statusText = Lang.gen[73].Value + " " + (int)(num5 * 100f + 1f) + "%";
2891 int num6;
2892 for (num6 = 0; num6 < num3; num6++)
2893 {
2894 byte b;
2895 byte b2 = (b = 0);
2896 byte b3 = fileIO.ReadByte();
2897 bool flag = false;
2898 if ((b3 & 1) == 1)
2899 {
2900 flag = true;
2901 b2 = fileIO.ReadByte();
2902 }
2903 bool flag2 = false;
2904 if (flag && (b2 & 1) == 1)
2905 {
2906 flag2 = true;
2907 b = fileIO.ReadByte();
2908 }
2909 if (flag2 && (b & 1) == 1)
2910 {
2911 fileIO.ReadByte();
2912 }
2913 if ((b3 & 2) == 2)
2914 {
2915 int num7;
2916 if ((b3 & 0x20) == 32)
2917 {
2918 byte b4 = fileIO.ReadByte();
2919 num7 = fileIO.ReadByte();
2920 num7 = (num7 << 8) | b4;
2921 }
2922 else
2923 {
2924 num7 = fileIO.ReadByte();
2925 }
2926 if (importance[num7])
2927 {
2928 fileIO.ReadInt16();
2929 fileIO.ReadInt16();
2930 }
2931 if ((b & 8) == 8)
2932 {
2933 fileIO.ReadByte();
2934 }
2935 }
2936 if ((b3 & 4) == 4)
2937 {
2938 fileIO.ReadByte();
2939 if ((b & 0x10) == 16)
2940 {
2941 fileIO.ReadByte();
2942 }
2943 }
2944 if ((b3 & 0x18) >> 3 != 0)
2945 {
2946 fileIO.ReadByte();
2947 }
2948 if ((b & 0x40) == 64)
2949 {
2950 fileIO.ReadByte();
2951 }
2952 num6 += (byte)((b3 & 0xC0) >> 6) switch
2953 {
2954 0 => 0,
2955 1 => fileIO.ReadByte(),
2956 _ => fileIO.ReadInt16(),
2957 };
2958 }
2959 }
2960 if (baseStream.Position != positions[2])
2961 {
2962 return false;
2963 }
2964 int num8 = fileIO.ReadInt16();
2965 int num9 = fileIO.ReadInt16();
2966 for (int j = 0; j < num8; j++)
2967 {
2968 fileIO.ReadInt32();
2969 fileIO.ReadInt32();
2970 fileIO.ReadString();
2971 for (int k = 0; k < num9; k++)
2972 {
2973 if (fileIO.ReadInt16() > 0)
2974 {
2975 fileIO.ReadInt32();
2976 fileIO.ReadByte();
2977 }
2978 }
2979 }
2980 if (baseStream.Position != positions[3])
2981 {
2982 return false;
2983 }
2984 int num10 = fileIO.ReadInt16();
2985 for (int l = 0; l < num10; l++)
2986 {
2987 fileIO.ReadString();
2988 fileIO.ReadInt32();
2989 fileIO.ReadInt32();
2990 }
2991 if (baseStream.Position != positions[4])
2992 {
2993 return false;
2994 }
2996 if (baseStream.Position != positions[5])
2997 {
2998 return false;
2999 }
3000 if (_versionNumber >= 116 && _versionNumber <= 121)
3001 {
3002 int num11 = fileIO.ReadInt32();
3003 for (int m = 0; m < num11; m++)
3004 {
3005 fileIO.ReadInt16();
3006 fileIO.ReadInt16();
3007 }
3008 if (baseStream.Position != positions[6])
3009 {
3010 return false;
3011 }
3012 }
3013 if (_versionNumber >= 122)
3014 {
3015 int num12 = fileIO.ReadInt32();
3016 for (int n = 0; n < num12; n++)
3017 {
3019 }
3020 }
3021 if (_versionNumber >= 170)
3022 {
3023 int num13 = fileIO.ReadInt32();
3024 for (int num14 = 0; num14 < num13; num14++)
3025 {
3026 fileIO.ReadInt64();
3027 }
3028 }
3029 if (_versionNumber >= 189)
3030 {
3031 int num15 = fileIO.ReadInt32();
3032 fileIO.ReadBytes(12 * num15);
3033 }
3034 if (_versionNumber >= 210)
3035 {
3036 Main.BestiaryTracker.ValidateWorld(fileIO, _versionNumber);
3037 }
3038 if (_versionNumber >= 220)
3039 {
3041 }
3042 bool num16 = fileIO.ReadBoolean();
3043 string text2 = fileIO.ReadString();
3044 int num17 = fileIO.ReadInt32();
3045 bool result = false;
3046 if (num16 && (text2 == text || num17 == num2))
3047 {
3048 result = true;
3049 }
3050 return result;
3051 }
3052 catch (Exception value)
3053 {
3054 using (StreamWriter streamWriter = new StreamWriter("client-crashlog.txt", append: true))
3055 {
3056 streamWriter.WriteLine(DateTime.Now);
3057 streamWriter.WriteLine(value);
3058 streamWriter.WriteLine("");
3059 }
3060 return false;
3061 }
3062 }
3063
3064 public static FileMetadata GetFileMetadata(string file, bool cloudSave)
3065 {
3066 if (file == null)
3067 {
3068 return null;
3069 }
3070 try
3071 {
3072 byte[] buffer = null;
3073 int num;
3074 if (cloudSave)
3075 {
3076 num = ((SocialAPI.Cloud != null) ? 1 : 0);
3077 if (num != 0)
3078 {
3079 int num2 = 24;
3080 buffer = new byte[num2];
3081 SocialAPI.Cloud.Read(file, buffer, num2);
3082 }
3083 }
3084 else
3085 {
3086 num = 0;
3087 }
3088 using Stream input = ((num != 0) ? ((Stream)new MemoryStream(buffer)) : ((Stream)new FileStream(file, FileMode.Open)));
3090 if (binaryReader.ReadInt32() >= 135)
3091 {
3092 return FileMetadata.Read(binaryReader, FileType.World);
3093 }
3095 }
3096 catch
3097 {
3098 }
3099 return null;
3100 }
3101
3102 private static void FixDresserChests()
3103 {
3104 for (int i = 0; i < Main.maxTilesX; i++)
3105 {
3106 for (int j = 0; j < Main.maxTilesY; j++)
3107 {
3108 Tile tile = Main.tile[i, j];
3109 if (tile.active() && tile.type == 88 && tile.frameX % 54 == 0 && tile.frameY % 36 == 0)
3110 {
3111 Chest.CreateChest(i, j);
3112 }
3113 }
3114 }
3115 }
3116
3118 {
3120 {
3121 writer.Write(TileEntity.ByID.Count);
3123 {
3124 TileEntity.Write(writer, item.Value);
3125 }
3126 }
3127 return (int)writer.BaseStream.Position;
3128 }
3129
3130 public static void LoadTileEntities(BinaryReader reader)
3131 {
3132 TileEntity.ByID.Clear();
3133 TileEntity.ByPosition.Clear();
3134 int num = reader.ReadInt32();
3135 int num2 = 0;
3136 for (int i = 0; i < num; i++)
3137 {
3139 tileEntity.ID = num2++;
3141 if (TileEntity.ByPosition.TryGetValue(tileEntity.Position, out var value))
3142 {
3143 TileEntity.ByID.Remove(value.ID);
3144 }
3146 }
3147 TileEntity.TileEntitiesNextID = num;
3150 {
3151 if (!WorldGen.InWorld(item.Value.Position.X, item.Value.Position.Y, 1))
3152 {
3153 list.Add(item.Value.Position);
3154 }
3155 else if (!TileEntity.manager.CheckValidTile(item.Value.type, item.Value.Position.X, item.Value.Position.Y))
3156 {
3157 list.Add(item.Value.Position);
3158 }
3159 }
3160 try
3161 {
3162 foreach (Point16 item2 in list)
3163 {
3165 if (TileEntity.ByID.ContainsKey(tileEntity2.ID))
3166 {
3167 TileEntity.ByID.Remove(tileEntity2.ID);
3168 }
3169 if (TileEntity.ByPosition.ContainsKey(item2))
3170 {
3171 TileEntity.ByPosition.Remove(item2);
3172 }
3173 }
3174 }
3175 catch
3176 {
3177 }
3178 }
3179
3181 {
3183 {
3186 {
3187 writer.Write(item.Key.X);
3188 writer.Write(item.Key.Y);
3189 }
3190 }
3191 return (int)writer.BaseStream.Position;
3192 }
3193
3194 public static void LoadWeightedPressurePlates(BinaryReader reader)
3195 {
3197 PressurePlateHelper.NeedsFirstUpdate = true;
3198 int num = reader.ReadInt32();
3199 for (int i = 0; i < num; i++)
3200 {
3201 Point key = new Point(reader.ReadInt32(), reader.ReadInt32());
3202 PressurePlateHelper.PressurePlatesPressed.Add(key, new bool[255]);
3203 }
3204 }
3205
3207 {
3209 return (int)writer.BaseStream.Position;
3210 }
3211
3212 public static void LoadTownManager(BinaryReader reader)
3213 {
3214 WorldGen.TownManager.Load(reader);
3215 }
3216
3218 {
3220 return (int)writer.BaseStream.Position;
3221 }
3222
3223 public static void LoadBestiary(BinaryReader reader, int loadVersionNumber)
3224 {
3226 }
3227
3229 {
3230 Main.BestiaryTracker.FillBasedOnVersionBefore210();
3231 }
3232
3234 {
3236 return (int)writer.BaseStream.Position;
3237 }
3238
3239 public static void LoadCreativePowers(BinaryReader reader, int loadVersionNumber)
3240 {
3241 CreativePowerManager.Instance.LoadFromWorld(reader, loadVersionNumber);
3242 }
3243
3245 {
3246 Main.WorldFileMetadata = FileMetadata.FromCurrentSettings(FileType.World);
3247 int versionNumber = _versionNumber;
3248 if (versionNumber > 279)
3249 {
3250 return 1;
3251 }
3252 Main.worldName = fileIO.ReadString();
3253 Main.worldID = fileIO.ReadInt32();
3254 Main.leftWorld = fileIO.ReadInt32();
3255 Main.rightWorld = fileIO.ReadInt32();
3256 Main.topWorld = fileIO.ReadInt32();
3257 Main.bottomWorld = fileIO.ReadInt32();
3258 Main.maxTilesY = fileIO.ReadInt32();
3259 Main.maxTilesX = fileIO.ReadInt32();
3260 if (versionNumber >= 112)
3261 {
3262 Main.GameMode = (fileIO.ReadBoolean() ? 1 : 0);
3263 }
3264 else
3265 {
3266 Main.GameMode = 0;
3267 }
3268 if (versionNumber >= 63)
3269 {
3270 Main.moonType = fileIO.ReadByte();
3271 }
3272 else
3273 {
3275 }
3277 if (versionNumber >= 44)
3278 {
3279 Main.treeX[0] = fileIO.ReadInt32();
3280 Main.treeX[1] = fileIO.ReadInt32();
3281 Main.treeX[2] = fileIO.ReadInt32();
3282 Main.treeStyle[0] = fileIO.ReadInt32();
3283 Main.treeStyle[1] = fileIO.ReadInt32();
3284 Main.treeStyle[2] = fileIO.ReadInt32();
3285 Main.treeStyle[3] = fileIO.ReadInt32();
3286 }
3287 if (versionNumber >= 60)
3288 {
3289 Main.caveBackX[0] = fileIO.ReadInt32();
3290 Main.caveBackX[1] = fileIO.ReadInt32();
3291 Main.caveBackX[2] = fileIO.ReadInt32();
3292 Main.caveBackStyle[0] = fileIO.ReadInt32();
3293 Main.caveBackStyle[1] = fileIO.ReadInt32();
3294 Main.caveBackStyle[2] = fileIO.ReadInt32();
3295 Main.caveBackStyle[3] = fileIO.ReadInt32();
3296 Main.iceBackStyle = fileIO.ReadInt32();
3297 if (versionNumber >= 61)
3298 {
3299 Main.jungleBackStyle = fileIO.ReadInt32();
3300 Main.hellBackStyle = fileIO.ReadInt32();
3301 }
3302 }
3303 else
3304 {
3306 }
3307 Main.spawnTileX = fileIO.ReadInt32();
3308 Main.spawnTileY = fileIO.ReadInt32();
3309 Main.worldSurface = fileIO.ReadDouble();
3310 Main.rockLayer = fileIO.ReadDouble();
3311 _tempTime = fileIO.ReadDouble();
3312 _tempDayTime = fileIO.ReadBoolean();
3313 _tempMoonPhase = fileIO.ReadInt32();
3314 _tempBloodMoon = fileIO.ReadBoolean();
3315 if (versionNumber >= 70)
3316 {
3317 _tempEclipse = fileIO.ReadBoolean();
3318 Main.eclipse = _tempEclipse;
3319 }
3320 Main.dungeonX = fileIO.ReadInt32();
3321 Main.dungeonY = fileIO.ReadInt32();
3322 if (versionNumber >= 56)
3323 {
3324 WorldGen.crimson = fileIO.ReadBoolean();
3325 }
3326 else
3327 {
3328 WorldGen.crimson = false;
3329 }
3330 NPC.downedBoss1 = fileIO.ReadBoolean();
3331 NPC.downedBoss2 = fileIO.ReadBoolean();
3332 NPC.downedBoss3 = fileIO.ReadBoolean();
3333 if (versionNumber >= 66)
3334 {
3335 NPC.downedQueenBee = fileIO.ReadBoolean();
3336 }
3337 if (versionNumber >= 44)
3338 {
3339 NPC.downedMechBoss1 = fileIO.ReadBoolean();
3340 NPC.downedMechBoss2 = fileIO.ReadBoolean();
3341 NPC.downedMechBoss3 = fileIO.ReadBoolean();
3342 NPC.downedMechBossAny = fileIO.ReadBoolean();
3343 }
3344 if (versionNumber >= 64)
3345 {
3346 NPC.downedPlantBoss = fileIO.ReadBoolean();
3347 NPC.downedGolemBoss = fileIO.ReadBoolean();
3348 }
3349 if (versionNumber >= 29)
3350 {
3351 NPC.savedGoblin = fileIO.ReadBoolean();
3352 NPC.savedWizard = fileIO.ReadBoolean();
3353 if (versionNumber >= 34)
3354 {
3355 NPC.savedMech = fileIO.ReadBoolean();
3356 if (versionNumber >= 80)
3357 {
3358 NPC.savedStylist = fileIO.ReadBoolean();
3359 }
3360 }
3361 if (versionNumber >= 129)
3362 {
3363 NPC.savedTaxCollector = fileIO.ReadBoolean();
3364 }
3365 if (versionNumber >= 201)
3366 {
3367 NPC.savedGolfer = fileIO.ReadBoolean();
3368 }
3369 NPC.downedGoblins = fileIO.ReadBoolean();
3370 }
3371 if (versionNumber >= 32)
3372 {
3373 NPC.downedClown = fileIO.ReadBoolean();
3374 }
3375 if (versionNumber >= 37)
3376 {
3377 NPC.downedFrost = fileIO.ReadBoolean();
3378 }
3379 if (versionNumber >= 56)
3380 {
3381 NPC.downedPirates = fileIO.ReadBoolean();
3382 }
3383 WorldGen.shadowOrbSmashed = fileIO.ReadBoolean();
3384 WorldGen.spawnMeteor = fileIO.ReadBoolean();
3385 WorldGen.shadowOrbCount = fileIO.ReadByte();
3386 if (versionNumber >= 23)
3387 {
3388 WorldGen.altarCount = fileIO.ReadInt32();
3389 Main.hardMode = fileIO.ReadBoolean();
3390 }
3391 Main.invasionDelay = fileIO.ReadInt32();
3392 Main.invasionSize = fileIO.ReadInt32();
3393 Main.invasionType = fileIO.ReadInt32();
3394 Main.invasionX = fileIO.ReadDouble();
3395 if (versionNumber >= 113)
3396 {
3397 Main.sundialCooldown = fileIO.ReadByte();
3398 }
3399 if (versionNumber >= 53)
3400 {
3401 _tempRaining = fileIO.ReadBoolean();
3402 _tempRainTime = fileIO.ReadInt32();
3403 _tempMaxRain = fileIO.ReadSingle();
3404 }
3405 if (versionNumber >= 54)
3406 {
3407 WorldGen.SavedOreTiers.Cobalt = fileIO.ReadInt32();
3408 WorldGen.SavedOreTiers.Mythril = fileIO.ReadInt32();
3409 WorldGen.SavedOreTiers.Adamantite = fileIO.ReadInt32();
3410 }
3411 else if (versionNumber >= 23 && WorldGen.altarCount == 0)
3412 {
3413 WorldGen.SavedOreTiers.Cobalt = -1;
3414 WorldGen.SavedOreTiers.Mythril = -1;
3415 WorldGen.SavedOreTiers.Adamantite = -1;
3416 }
3417 else
3418 {
3419 WorldGen.SavedOreTiers.Cobalt = 107;
3420 WorldGen.SavedOreTiers.Mythril = 108;
3421 WorldGen.SavedOreTiers.Adamantite = 111;
3422 }
3423 int style = 0;
3424 int style2 = 0;
3425 int style3 = 0;
3426 int style4 = 0;
3427 int style5 = 0;
3428 int style6 = 0;
3429 int style7 = 0;
3430 int style8 = 0;
3431 int style9 = 0;
3432 int style10 = 0;
3433 if (versionNumber >= 55)
3434 {
3435 style = fileIO.ReadByte();
3436 style2 = fileIO.ReadByte();
3437 style3 = fileIO.ReadByte();
3438 }
3439 if (versionNumber >= 60)
3440 {
3441 style4 = fileIO.ReadByte();
3442 style5 = fileIO.ReadByte();
3443 style6 = fileIO.ReadByte();
3444 style7 = fileIO.ReadByte();
3445 style8 = fileIO.ReadByte();
3446 }
3447 WorldGen.setBG(0, style);
3448 WorldGen.setBG(1, style2);
3449 WorldGen.setBG(2, style3);
3450 WorldGen.setBG(3, style4);
3451 WorldGen.setBG(4, style5);
3452 WorldGen.setBG(5, style6);
3453 WorldGen.setBG(6, style7);
3454 WorldGen.setBG(7, style8);
3455 WorldGen.setBG(8, style9);
3457 WorldGen.setBG(10, style);
3458 WorldGen.setBG(11, style);
3459 WorldGen.setBG(12, style);
3460 if (versionNumber >= 60)
3461 {
3462 Main.cloudBGActive = fileIO.ReadInt32();
3463 if (Main.cloudBGActive >= 1f)
3464 {
3465 Main.cloudBGAlpha = 1f;
3466 }
3467 else
3468 {
3469 Main.cloudBGAlpha = 0f;
3470 }
3471 }
3472 else
3473 {
3474 Main.cloudBGActive = -WorldGen.genRand.Next(8640, 86400);
3475 }
3476 if (versionNumber >= 62)
3477 {
3478 Main.numClouds = fileIO.ReadInt16();
3479 Main.windSpeedTarget = fileIO.ReadSingle();
3480 Main.windSpeedCurrent = Main.windSpeedTarget;
3481 }
3482 else
3483 {
3485 }
3486 for (int i = 0; i < Main.maxTilesX; i++)
3487 {
3488 float num = (float)i / (float)Main.maxTilesX;
3489 Main.statusText = Lang.gen[51].Value + " " + (int)(num * 100f + 1f) + "%";
3490 for (int j = 0; j < Main.maxTilesY; j++)
3491 {
3492 Tile tile = Main.tile[i, j];
3493 int num2 = -1;
3494 tile.active(fileIO.ReadBoolean());
3495 if (tile.active())
3496 {
3497 num2 = ((versionNumber <= 77) ? fileIO.ReadByte() : fileIO.ReadUInt16());
3498 tile.type = (ushort)num2;
3499 if (tile.type == 127 || tile.type == 504)
3500 {
3501 tile.active(active: false);
3502 }
3503 if (versionNumber < 72 && (tile.type == 35 || tile.type == 36 || tile.type == 170 || tile.type == 171 || tile.type == 172))
3504 {
3505 tile.frameX = fileIO.ReadInt16();
3506 tile.frameY = fileIO.ReadInt16();
3507 }
3508 else if (Main.tileFrameImportant[num2])
3509 {
3510 if (versionNumber < 28 && num2 == 4)
3511 {
3512 tile.frameX = 0;
3513 tile.frameY = 0;
3514 }
3515 else if (versionNumber < 40 && tile.type == 19)
3516 {
3517 tile.frameX = 0;
3518 tile.frameY = 0;
3519 }
3520 else if (versionNumber < 195 && tile.type == 49)
3521 {
3522 tile.frameX = 0;
3523 tile.frameY = 0;
3524 }
3525 else
3526 {
3527 tile.frameX = fileIO.ReadInt16();
3528 tile.frameY = fileIO.ReadInt16();
3529 if (tile.type == 144)
3530 {
3531 tile.frameY = 0;
3532 }
3533 }
3534 }
3535 else
3536 {
3537 tile.frameX = -1;
3538 tile.frameY = -1;
3539 }
3540 if (versionNumber >= 48 && fileIO.ReadBoolean())
3541 {
3542 tile.color(fileIO.ReadByte());
3543 }
3544 }
3545 if (versionNumber <= 25)
3546 {
3547 fileIO.ReadBoolean();
3548 }
3549 if (fileIO.ReadBoolean())
3550 {
3551 tile.wall = fileIO.ReadByte();
3552 if (tile.wall >= WallID.Count)
3553 {
3554 tile.wall = 0;
3555 }
3556 if (versionNumber >= 48 && fileIO.ReadBoolean())
3557 {
3558 tile.wallColor(fileIO.ReadByte());
3559 }
3560 }
3561 if (fileIO.ReadBoolean())
3562 {
3563 tile.liquid = fileIO.ReadByte();
3564 tile.lava(fileIO.ReadBoolean());
3565 if (versionNumber >= 51)
3566 {
3567 tile.honey(fileIO.ReadBoolean());
3568 }
3569 }
3570 if (versionNumber >= 33)
3571 {
3572 tile.wire(fileIO.ReadBoolean());
3573 }
3574 if (versionNumber >= 43)
3575 {
3576 tile.wire2(fileIO.ReadBoolean());
3577 tile.wire3(fileIO.ReadBoolean());
3578 }
3579 if (versionNumber >= 41)
3580 {
3581 tile.halfBrick(fileIO.ReadBoolean());
3582 if (!Main.tileSolid[tile.type] && !TileID.Sets.NonSolidSaveSlopes[tile.type])
3583 {
3584 tile.halfBrick(halfBrick: false);
3585 }
3586 if (versionNumber >= 49)
3587 {
3588 tile.slope(fileIO.ReadByte());
3589 if (!Main.tileSolid[tile.type] && !TileID.Sets.NonSolidSaveSlopes[tile.type])
3590 {
3591 tile.slope(0);
3592 }
3593 }
3594 }
3595 if (versionNumber >= 42)
3596 {
3597 tile.actuator(fileIO.ReadBoolean());
3598 tile.inActive(fileIO.ReadBoolean());
3599 }
3600 int num3 = 0;
3601 if (versionNumber >= 25)
3602 {
3603 num3 = fileIO.ReadInt16();
3604 }
3605 if (num2 != -1)
3606 {
3607 if ((double)j <= Main.worldSurface)
3608 {
3609 if ((double)(j + num3) <= Main.worldSurface)
3610 {
3611 WorldGen.tileCounts[num2] += (num3 + 1) * 5;
3612 }
3613 else
3614 {
3615 int num4 = (int)(Main.worldSurface - (double)j + 1.0);
3616 int num5 = num3 + 1 - num4;
3617 WorldGen.tileCounts[num2] += num4 * 5 + num5;
3618 }
3619 }
3620 else
3621 {
3622 WorldGen.tileCounts[num2] += num3 + 1;
3623 }
3624 }
3625 if (num3 > 0)
3626 {
3627 for (int k = j + 1; k < j + num3 + 1; k++)
3628 {
3629 Main.tile[i, k].CopyFrom(Main.tile[i, j]);
3630 }
3631 j += num3;
3632 }
3633 }
3634 }
3636 if (versionNumber < 67)
3637 {
3639 }
3640 if (versionNumber < 72)
3641 {
3643 }
3644 int num6 = 40;
3645 if (versionNumber < 58)
3646 {
3647 num6 = 20;
3648 }
3649 int num7 = 1000;
3650 for (int l = 0; l < num7; l++)
3651 {
3652 if (!fileIO.ReadBoolean())
3653 {
3654 continue;
3655 }
3656 Main.chest[l] = new Chest();
3657 Main.chest[l].x = fileIO.ReadInt32();
3658 Main.chest[l].y = fileIO.ReadInt32();
3659 if (versionNumber >= 85)
3660 {
3661 string text = fileIO.ReadString();
3662 if (text.Length > 20)
3663 {
3664 text = text.Substring(0, 20);
3665 }
3666 Main.chest[l].name = text;
3667 }
3668 for (int m = 0; m < 40; m++)
3669 {
3670 Main.chest[l].item[m] = new Item();
3671 if (m >= num6)
3672 {
3673 continue;
3674 }
3675 int num8 = 0;
3676 num8 = ((versionNumber < 59) ? fileIO.ReadByte() : fileIO.ReadInt16());
3677 if (num8 > 0)
3678 {
3679 if (versionNumber >= 38)
3680 {
3681 Main.chest[l].item[m].netDefaults(fileIO.ReadInt32());
3682 }
3683 else
3684 {
3685 short defaults = ItemID.FromLegacyName(fileIO.ReadString(), versionNumber);
3686 Main.chest[l].item[m].SetDefaults(defaults);
3687 }
3688 Main.chest[l].item[m].stack = num8;
3689 if (versionNumber >= 36)
3690 {
3691 Main.chest[l].item[m].Prefix(fileIO.ReadByte());
3692 }
3693 }
3694 }
3695 }
3696 for (int n = 0; n < 1000; n++)
3697 {
3698 if (fileIO.ReadBoolean())
3699 {
3700 string text2 = fileIO.ReadString();
3701 int num9 = fileIO.ReadInt32();
3702 int num10 = fileIO.ReadInt32();
3703 if (Main.tile[num9, num10].active() && (Main.tile[num9, num10].type == 55 || Main.tile[num9, num10].type == 85))
3704 {
3705 Main.sign[n] = new Sign();
3706 Main.sign[n].x = num9;
3707 Main.sign[n].y = num10;
3708 Main.sign[n].text = text2;
3709 }
3710 }
3711 }
3712 bool flag = fileIO.ReadBoolean();
3713 int num11 = 0;
3714 while (flag)
3715 {
3716 if (versionNumber >= 190)
3717 {
3718 Main.npc[num11].SetDefaults(fileIO.ReadInt32());
3719 }
3720 else
3721 {
3722 Main.npc[num11].SetDefaults(NPCID.FromLegacyName(fileIO.ReadString()));
3723 }
3724 if (versionNumber >= 83)
3725 {
3726 Main.npc[num11].GivenName = fileIO.ReadString();
3727 }
3728 Main.npc[num11].position.X = fileIO.ReadSingle();
3729 Main.npc[num11].position.Y = fileIO.ReadSingle();
3730 Main.npc[num11].homeless = fileIO.ReadBoolean();
3731 Main.npc[num11].homeTileX = fileIO.ReadInt32();
3732 Main.npc[num11].homeTileY = fileIO.ReadInt32();
3733 flag = fileIO.ReadBoolean();
3734 num11++;
3735 }
3736 if (versionNumber >= 31 && versionNumber <= 83)
3737 {
3738 NPC.setNPCName(fileIO.ReadString(), 17, resetExtras: true);
3739 NPC.setNPCName(fileIO.ReadString(), 18, resetExtras: true);
3740 NPC.setNPCName(fileIO.ReadString(), 19, resetExtras: true);
3741 NPC.setNPCName(fileIO.ReadString(), 20, resetExtras: true);
3742 NPC.setNPCName(fileIO.ReadString(), 22, resetExtras: true);
3743 NPC.setNPCName(fileIO.ReadString(), 54, resetExtras: true);
3744 NPC.setNPCName(fileIO.ReadString(), 38, resetExtras: true);
3745 NPC.setNPCName(fileIO.ReadString(), 107, resetExtras: true);
3746 NPC.setNPCName(fileIO.ReadString(), 108, resetExtras: true);
3747 if (versionNumber >= 35)
3748 {
3749 NPC.setNPCName(fileIO.ReadString(), 124, resetExtras: true);
3750 if (versionNumber >= 65)
3751 {
3752 NPC.setNPCName(fileIO.ReadString(), 160, resetExtras: true);
3753 NPC.setNPCName(fileIO.ReadString(), 178, resetExtras: true);
3754 NPC.setNPCName(fileIO.ReadString(), 207, resetExtras: true);
3755 NPC.setNPCName(fileIO.ReadString(), 208, resetExtras: true);
3756 NPC.setNPCName(fileIO.ReadString(), 209, resetExtras: true);
3757 NPC.setNPCName(fileIO.ReadString(), 227, resetExtras: true);
3758 NPC.setNPCName(fileIO.ReadString(), 228, resetExtras: true);
3759 NPC.setNPCName(fileIO.ReadString(), 229, resetExtras: true);
3760 if (versionNumber >= 79)
3761 {
3762 NPC.setNPCName(fileIO.ReadString(), 353, resetExtras: true);
3763 }
3764 }
3765 }
3766 }
3767 if (Main.invasionType > 0 && Main.invasionSize > 0)
3768 {
3770 }
3771 if (versionNumber >= 7)
3772 {
3773 bool num12 = fileIO.ReadBoolean();
3774 string text3 = fileIO.ReadString();
3775 int num13 = fileIO.ReadInt32();
3776 if (num12 && (text3 == Main.worldName || num13 == Main.worldID))
3777 {
3778 return 0;
3779 }
3780 return 2;
3781 }
3782 return 0;
3783 }
3784}
void Add(TKey key, TValue value)
static void WriteLine()
Definition Console.cs:733
virtual bool ReadBoolean()
virtual double ReadDouble()
virtual byte ReadByte()
virtual string ReadString()
virtual ulong ReadUInt64()
virtual float ReadSingle()
virtual ushort ReadUInt16()
virtual int ReadInt32()
virtual Stream BaseStream
virtual short ReadInt16()
virtual byte[] ReadBytes(int count)
virtual long ReadInt64()
static DateTime GetCreationTime(string path)
Definition File.cs:164
static readonly char DirectorySeparatorChar
Definition Path.cs:71
static void Exit(object obj)
static bool TryEnter(object obj)
Definition Monitor.cs:36
static int CreateChest(int X, int Y, int id=-1)
Definition Chest.cs:645
Item[] item
Definition Chest.cs:41
string name
Definition Chest.cs:49
static void resetClouds()
Definition Cloud.cs:36
static Dictionary< int, TileEntity > ByID
Definition TileEntity.cs:18
static TileEntitiesManager manager
Definition TileEntity.cs:12
static Dictionary< Point16, TileEntity > ByPosition
Definition TileEntity.cs:20
static void Write(BinaryWriter writer, TileEntity ent, bool networkSend=false)
Definition TileEntity.cs:80
static TileEntity Read(BinaryReader reader, bool networkSend=false)
Definition TileEntity.cs:86
static void Load(BinaryReader reader, int gameVersionNumber)
Definition DD2Event.cs:132
static void Save(BinaryWriter writer)
Definition DD2Event.cs:125
static Dictionary< Point, bool[]> PressurePlatesPressed
static void TryPlacing(int x, int y, int netid, int prefix, int stack)
static void ProcessSpecialWorldSeeds(string processedSeed)
static bool[] ItemsThatShouldNotBeInInventory
Definition ItemID.cs:57
static short FromLegacyName(string name, int release)
Definition ItemID.cs:12856
static bool[] SavesAndLoads
Definition NPCID.cs:4188
static readonly short Count
Definition NPCID.cs:11744
static int FromLegacyName(string name)
Definition NPCID.cs:11748
static bool[] NonSolidSaveSlopes
Definition TileID.cs:109
static bool[] AllowsSaveCompressionBatching
Definition TileID.cs:87
static readonly ushort Count
Definition TileID.cs:1698
static readonly ushort Count
Definition WallID.cs:753
static FileMetadata Read(BinaryReader reader, FileType expectedType)
static FileMetadata FromCurrentSettings(FileType type)
static WorldFileData FromInvalidWorld(string path, bool cloudSave)
static ? float _cachedSandstormIntendedSeverity
Definition WorldFile.cs:163
static void LoadWorldTiles(BinaryReader reader, bool[] importance)
static ? bool _cachedLanternNightGenuine
Definition WorldFile.cs:175
static int SaveFileFormatHeader(BinaryWriter writer)
static void LoadNPCs(BinaryReader reader)
static bool LoadFileFormatHeader(BinaryReader reader, out bool[] importance, out int[] positions)
static void LoadTileEntities(BinaryReader reader)
static bool _tempSandstormHappening
Definition WorldFile.cs:153
static readonly object IOLock
Definition WorldFile.cs:97
static void InternalSaveWorld(bool useCloudSaving, bool resetTime)
Definition WorldFile.cs:824
static bool _tempLanternNightManual
Definition WorldFile.cs:169
static void LoadWorld(bool loadFromCloud)
Definition WorldFile.cs:576
static int SaveCreativePowers(BinaryWriter writer)
static ? bool _cachedLanternNightNextNightIsGenuine
Definition WorldFile.cs:179
static void ConvertIlluminantPaintToNewField()
static void LoadBestiary(BinaryReader reader, int loadVersionNumber)
static void ResetTemps()
Definition WorldFile.cs:549
static void FixAgainstExploits()
static void CheckSavedOreTiers()
Definition WorldFile.cs:723
static float _tempSandstormSeverity
Definition WorldFile.cs:161
static int SaveFooter(BinaryWriter writer)
static int LoadWorld_Version2(BinaryReader reader)
static bool _tempRaining
Definition WorldFile.cs:101
static void LoadCreativePowers(BinaryReader reader, int loadVersionNumber)
static int _tempCultistDelay
Definition WorldFile.cs:115
static bool _tempLanternNightGenuine
Definition WorldFile.cs:167
static int SaveWeightedPressurePlates(BinaryWriter writer)
static void LoadTownManager(BinaryReader reader)
static int SaveBestiary(BinaryWriter writer)
static void SetTempToCache()
Definition WorldFile.cs:982
static int SaveTownManager(BinaryWriter writer)
static int SaveChests(BinaryWriter writer)
static Action OnWorldLoad
Definition WorldFile.cs:185
static FileMetadata GetFileMetadata(string file, bool cloudSave)
static void ClearTempTiles()
Definition WorldFile.cs:562
static ? bool _cachedLanternNightManual
Definition WorldFile.cs:177
static ? bool _cachedSandstormHappening
Definition WorldFile.cs:151
static int _tempPartyCooldown
Definition WorldFile.cs:125
static void LoadDummies(BinaryReader reader)
static bool ValidateWorld(BinaryReader fileIO)
static float _tempSandstormIntendedSeverity
Definition WorldFile.cs:165
static void FixDresserChests()
static void SaveWorld_Version2(BinaryWriter writer)
static bool _hasCache
Definition WorldFile.cs:129
static readonly List< int > CachedCelebratingNPCs
Definition WorldFile.cs:149
static ? bool _cachedBloodMoon
Definition WorldFile.cs:137
static void SaveWorld(bool useCloudSaving, bool resetTime=false)
Definition WorldFile.cs:793
static int SaveHeaderPointers(BinaryWriter writer, int[] pointers)
static void CacheSaveTime()
Definition WorldFile.cs:187
static bool _tempPartyGenuine
Definition WorldFile.cs:121
static bool _tempDayTime
Definition WorldFile.cs:107
static WorldFileData CreateMetadata(string name, bool cloudSave, int GameMode)
Definition WorldFile.cs:523
static void SaveWorld()
Definition WorldFile.cs:780
static void ConvertOldTileEntities()
static readonly List< int > TempPartyCelebratingNPCs
Definition WorldFile.cs:127
static ? int _cachedPartyDaysOnCooldown
Definition WorldFile.cs:147
static bool IsValidWorld(string file, bool cloudSave)
Definition WorldFile.cs:238
static int _tempRainTime
Definition WorldFile.cs:105
static ? bool _cachedPartyManual
Definition WorldFile.cs:145
static int _tempSandstormTimeLeft
Definition WorldFile.cs:157
static ? float _cachedSandstormSeverity
Definition WorldFile.cs:159
static float _tempMaxRain
Definition WorldFile.cs:103
static bool _isWorldOnCloud
Definition WorldFile.cs:119
static ? int _cachedMoonPhase
Definition WorldFile.cs:135
static ? int _cachedLanternNightCooldown
Definition WorldFile.cs:181
static int SaveWorldTiles(BinaryWriter writer)
static bool _tempBloodMoon
Definition WorldFile.cs:109
static void LoadBestiaryForVersionsBefore210()
static int SaveSigns(BinaryWriter writer)
static void LoadSigns(BinaryReader reader)
static WorldFileData GetAllMetadata(string file, bool cloudSave)
Definition WorldFile.cs:243
static void ResetTempsToDayTime()
Definition WorldFile.cs:930
static ? bool _cachedEclipse
Definition WorldFile.cs:139
static bool _tempPartyManual
Definition WorldFile.cs:123
static int LoadWorld_Version1_Old_BeforeRelease88(BinaryReader fileIO)
static bool _tempLanternNightNextNightIsGenuine
Definition WorldFile.cs:171
static int SaveWorldHeader(BinaryWriter writer)
static int SaveTileEntities(BinaryWriter writer)
static void ValidateLoadNPCs(BinaryReader fileIO)
static int _versionNumber
Definition WorldFile.cs:117
static int LoadFooter(BinaryReader reader)
static ? int _cachedCultistDelay
Definition WorldFile.cs:141
static void SetOngoingToTemps()
Definition WorldFile.cs:211
static void LoadWorld_LastMinuteFixes()
static void LoadChests(BinaryReader reader)
static ? int _cachedSandstormTimeLeft
Definition WorldFile.cs:155
static void SetTempToOngoing()
Definition WorldFile.cs:956
static bool _tempEclipse
Definition WorldFile.cs:111
static int _tempMoonPhase
Definition WorldFile.cs:113
static int _tempLanternNightCooldown
Definition WorldFile.cs:173
static ? bool _cachedPartyGenuine
Definition WorldFile.cs:143
static ? bool _cachedDayTime
Definition WorldFile.cs:131
static void LoadHeader(BinaryReader reader)
static void DoRollingBackups(string backupWorldWritePath)
Definition WorldFile.cs:890
static double _tempTime
Definition WorldFile.cs:99
static int SaveNPCs(BinaryWriter writer)
static ? double _cachedTime
Definition WorldFile.cs:133
static Exception LastThrownLoadException
Definition WorldFile.cs:183
static void LoadWeightedPressurePlates(BinaryReader reader)
static LocalizedText[] gen
Definition Lang.cs:22
static int numLiquidBuffer
static void UpdateLiquid()
Definition Liquid.cs:983
static int numLiquid
Definition Liquid.cs:27
static void QuickWater(int verbose=0, int minY=-1, int maxY=-1)
Definition Liquid.cs:103
static string GetTextValue(string key)
Definition Language.cs:15
static string GetWorldPathFromName(string worldName, bool cloudSave)
Definition Main.cs:4488
static int rainTime
Definition Main.cs:1308
static bool raining
Definition Main.cs:1310
static double time
Definition Main.cs:1284
static float bottomWorld
Definition Main.cs:1112
static int maxTilesY
Definition Main.cs:1116
static int spawnTileY
Definition Main.cs:1811
static float windSpeedTarget
Definition Main.cs:1362
static double invasionX
Definition Main.cs:1972
static bool forceXMasForToday
Definition Main.cs:690
static Chest[] chest
Definition Main.cs:1699
static WorldFileData ActiveWorldFileData
Definition Main.cs:1946
static int invasionSizeStart
Definition Main.cs:1980
static double worldSurface
Definition Main.cs:1272
static int numClouds
Definition Main.cs:1356
static bool forceHalloweenForToday
Definition Main.cs:692
static bool[] tileContainer
Definition Main.cs:1503
static int[] treeX
Definition Main.cs:668
static bool skipMenu
Definition Main.cs:560
static double rockLayer
Definition Main.cs:1274
static bool dayTime
Definition Main.cs:1282
static bool[] tileSign
Definition Main.cs:1505
static int[] caveBackStyle
Definition Main.cs:674
static bool bloodMoon
Definition Main.cs:1296
static void checkHalloween()
Definition Main.cs:12188
static bool zenithWorld
Definition Main.cs:353
static string DefaultSeed
Definition Main.cs:1413
static string worldPathName
Definition Main.cs:2837
static int moonPhase
Definition Main.cs:1288
static string worldName
Definition Main.cs:1260
static int maxTilesX
Definition Main.cs:1114
static int dungeonX
Definition Main.cs:1218
static int GameMode
Definition Main.cs:2685
static bool getGoodWorld
Definition Main.cs:341
static bool validateSaves
Definition Main.cs:1242
static float topWorld
Definition Main.cs:1110
static bool[] tileSolid
Definition Main.cs:1471
static List< string > anglerWhoFinishedToday
Definition Main.cs:1845
static Tile[,] tile
Definition Main.cs:1675
static BestiaryUnlocksTracker BestiaryTracker
Definition Main.cs:1868
static int hellBackStyle
Definition Main.cs:678
static int spawnTileX
Definition Main.cs:1809
static int WorldRollingBackupsCountToKeep
Definition Main.cs:1210
static int dungeonY
Definition Main.cs:1220
static int moondialCooldown
Definition Main.cs:2287
static bool fastForwardTimeToDawn
Definition Main.cs:2281
static int jungleBackStyle
Definition Main.cs:680
static bool eclipse
Definition Main.cs:1312
static int invasionType
Definition Main.cs:1970
static int moonType
Definition Main.cs:1397
static int invasionDelay
Definition Main.cs:1976
static bool notTheBeesWorld
Definition Main.cs:347
static int worldID
Definition Main.cs:1262
static float rightWorld
Definition Main.cs:1108
static NPC[] npc
Definition Main.cs:1685
static bool noTrapsWorld
Definition Main.cs:351
static void UpdateTimeRate()
Definition Main.cs:5760
static bool afterPartyOfDoom
Definition Main.cs:1020
static void FakeLoadInvasionStart()
Definition Main.cs:61293
static bool dontStarveWorld
Definition Main.cs:345
static GenerationProgress AutogenProgress
Definition Main.cs:982
static float maxRaining
Definition Main.cs:1304
static bool tenthAnniversaryWorld
Definition Main.cs:343
static string WorldPath
Definition Main.cs:1948
static int[] treeStyle
Definition Main.cs:670
static double slimeRainTime
Definition Main.cs:1164
static int sundialCooldown
Definition Main.cs:2283
static float cloudBGActive
Definition Main.cs:628
static bool drunkWorld
Definition Main.cs:339
static string autoGenFileLocation
Definition Main.cs:2275
static int iceBackStyle
Definition Main.cs:676
static float leftWorld
Definition Main.cs:1106
static bool[] tileFrameImportant
Definition Main.cs:1495
static bool autoGen
Definition Main.cs:1322
static int[] caveBackX
Definition Main.cs:672
static bool hardMode
Definition Main.cs:1022
static void checkXMas()
Definition Main.cs:12169
static Sign[] sign
Definition Main.cs:1701
static FileMetadata WorldFileMetadata
Definition Main.cs:361
static void StartSlimeRain(bool announce=true)
Definition Main.cs:61505
static int anglerQuest
Definition Main.cs:1849
static int invasionSize
Definition Main.cs:1974
static bool fastForwardTimeToDusk
Definition Main.cs:2285
static bool remixWorld
Definition Main.cs:349
static bool downedChristmasSantank
Definition NPC.cs:379
static bool downedTowerSolar
Definition NPC.cs:385
static bool downedFrost
Definition NPC.cs:357
static bool savedAngler
Definition NPC.cs:293
static bool boughtCat
Definition NPC.cs:301
static bool unlockedSlimeRainbowSpawn
Definition NPC.cs:315
static bool unlockedSlimeGreenSpawn
Definition NPC.cs:309
static bool downedTowerVortex
Definition NPC.cs:387
static bool downedMechBoss2
Definition NPC.cs:425
static bool downedFishron
Definition NPC.cs:369
static bool unlockedSlimePurpleSpawn
Definition NPC.cs:313
static bool savedTaxCollector
Definition NPC.cs:285
static bool downedBoss2
Definition NPC.cs:347
static void setFireFlyChance()
Definition NPC.cs:90049
static bool savedGolfer
Definition NPC.cs:299
static int ShieldStrengthTowerMax
Definition NPC.cs:785
static bool TowerActiveStardust
Definition NPC.cs:417
static int[] killCount
Definition NPC.cs:71
static bool savedMech
Definition NPC.cs:291
static bool unlockedMerchantSpawn
Definition NPC.cs:323
static bool unlockedSlimeBlueSpawn
Definition NPC.cs:307
static bool downedMechBossAny
Definition NPC.cs:421
static bool downedEmpressOfLight
Definition NPC.cs:393
static bool unlockedDyeTraderSpawn
Definition NPC.cs:329
static bool savedWizard
Definition NPC.cs:289
static bool downedHalloweenKing
Definition NPC.cs:373
static bool boughtDog
Definition NPC.cs:303
static bool downedBoss1
Definition NPC.cs:345
static bool downedSlimeKing
Definition NPC.cs:353
static bool unlockedPrincessSpawn
Definition NPC.cs:337
static bool savedGoblin
Definition NPC.cs:287
static bool TowerActiveVortex
Definition NPC.cs:413
static bool unlockedTruffleSpawn
Definition NPC.cs:331
static bool combatBookWasUsed
Definition NPC.cs:339
static bool[] ShimmeredTownNPCs
Definition NPC.cs:97
static bool downedTowerStardust
Definition NPC.cs:391
static bool unlockedSlimeRedSpawn
Definition NPC.cs:317
static bool downedMechBoss3
Definition NPC.cs:427
static bool downedPirates
Definition NPC.cs:359
static bool downedMoonlord
Definition NPC.cs:383
static bool unlockedPartyGirlSpawn
Definition NPC.cs:327
static bool TowerActiveSolar
Definition NPC.cs:411
static bool AnyNPCs(int Type)
Definition NPC.cs:86689
static bool downedQueenBee
Definition NPC.cs:351
static bool downedHalloweenTree
Definition NPC.cs:371
static bool downedChristmasTree
Definition NPC.cs:377
static bool unlockedSlimeOldSpawn
Definition NPC.cs:311
static bool downedGoblins
Definition NPC.cs:355
static bool downedClown
Definition NPC.cs:361
static bool peddlersSatchelWasUsed
Definition NPC.cs:343
static bool combatBookVolumeTwoWasUsed
Definition NPC.cs:341
static bool unlockedNurseSpawn
Definition NPC.cs:335
static bool downedGolemBoss
Definition NPC.cs:365
static bool LunarApocalypseIsUp
Definition NPC.cs:419
static bool downedMartians
Definition NPC.cs:367
static bool boughtBunny
Definition NPC.cs:305
static bool downedChristmasIceQueen
Definition NPC.cs:375
static bool downedAncientCultist
Definition NPC.cs:381
static bool downedBoss3
Definition NPC.cs:349
static void SetWorldSpecificMonstersByWorldID()
Definition NPC.cs:12106
static bool unlockedSlimeYellowSpawn
Definition NPC.cs:319
static bool downedPlantBoss
Definition NPC.cs:363
static bool savedBartender
Definition NPC.cs:297
static bool unlockedDemolitionistSpawn
Definition NPC.cs:325
static bool TowerActiveNebula
Definition NPC.cs:415
static bool downedMechBoss1
Definition NPC.cs:423
static bool downedDeerclops
Definition NPC.cs:397
static bool unlockedSlimeCopperSpawn
Definition NPC.cs:321
static bool unlockedArmsDealerSpawn
Definition NPC.cs:333
static bool downedTowerNebula
Definition NPC.cs:389
static bool downedQueenSlime
Definition NPC.cs:395
static void setNPCName(string newName, int npcType, bool resetExtras=false)
Definition NPC.cs:1513
static bool savedStylist
Definition NPC.cs:295
int y
Definition Sign.cs:9
string text
Definition Sign.cs:11
int x
Definition Sign.cs:7
static Terraria.Social.Base.CloudSocialModule Cloud
Definition SocialAPI.cs:18
byte color()
Definition Tile.cs:555
bool wire4()
Definition Tile.cs:413
bool wire3()
Definition Tile.cs:633
bool fullbrightWall()
Definition Tile.cs:694
bool invisibleWall()
Definition Tile.cs:521
byte liquid
Definition Tile.cs:12
bool inActive()
Definition Tile.cs:582
bool fullbrightBlock()
Definition Tile.cs:538
short frameY
Definition Tile.cs:24
ushort type
Definition Tile.cs:8
short frameX
Definition Tile.cs:22
bool invisibleBlock()
Definition Tile.cs:504
bool active()
Definition Tile.cs:565
byte slope()
Definition Tile.cs:684
bool honey()
Definition Tile.cs:379
bool lava()
Definition Tile.cs:362
bool shimmer()
Definition Tile.cs:396
ushort wall
Definition Tile.cs:10
bool wire2()
Definition Tile.cs:616
byte wallColor()
Definition Tile.cs:352
bool actuator()
Definition Tile.cs:667
bool wire()
Definition Tile.cs:599
bool halfBrick()
Definition Tile.cs:650
bool isTheSameAs(Tile compTile)
Definition Tile.cs:172
static void ShowFileSavingFailError(Exception exception, string filePath)
static bool Exists(string path, bool cloud)
static void ProtectedInvoke(Action action)
static void Write(string path, byte[] data, int length, bool cloud)
static byte[] ReadAllBytes(string path, bool cloud)
static void Move(string source, string destination, bool cloud, bool overwrite=true, bool forceDeleteSourceFile=false)
static void WriteAllBytes(string path, byte[] data, bool cloud)
static bool TryCreatingDirectory(string folderPath)
Definition Utils.cs:754
static int hallowBG
Definition WorldGen.cs:914
static bool loadFailed
Definition WorldGen.cs:982
static int mushroomBG
Definition WorldGen.cs:922
static int jungleBG
Definition WorldGen.cs:910
static void FixHearts()
static void GenerateWorld(int seed, GenerationProgress customProgressObject=null)
Definition WorldGen.cs:7175
static int treeBG2
Definition WorldGen.cs:902
static int treeBG3
Definition WorldGen.cs:904
static int shadowOrbCount
Definition WorldGen.cs:976
static TownRoomManager TownManager
Definition WorldGen.cs:892
static int treeBG4
Definition WorldGen.cs:906
static void KillTile(int i, int j, bool fail=false, bool effectOnly=false, bool noItem=false)
static void setBG(int bg, int style)
Definition WorldGen.cs:3660
static int underworldBG
Definition WorldGen.cs:924
static UnifiedRandom genRand
Definition WorldGen.cs:1215
static TreeTopsInfo TreeTops
Definition WorldGen.cs:1178
static int corruptBG
Definition WorldGen.cs:908
static bool loadSuccess
Definition WorldGen.cs:984
static void RandomizeWeather()
Definition WorldGen.cs:4140
static bool crimson
Definition WorldGen.cs:932
static void FixSunflowers()
static int[] CountTileTypesInWorld(params int[] oreTypes)
static void clearWorld()
Definition WorldGen.cs:3373
static int altarCount
Definition WorldGen.cs:978
static int desertBG
Definition WorldGen.cs:918
static void AddUpAlignmentCounts(bool clearCounts=false)
static int crimsonBG
Definition WorldGen.cs:916
static void RandomizeMoonState(UnifiedRandom random, bool garenteeNewStyle=false)
Definition WorldGen.cs:4152
static int treeBG1
Definition WorldGen.cs:900
static void RandomizeCaveBackgrounds()
Definition WorldGen.cs:4515
static int snowBG
Definition WorldGen.cs:912
static void FixChands()
static int oceanBG
Definition WorldGen.cs:920
static bool InWorld(int x, int y, int fluff=0)
Definition WorldGen.cs:5816
static bool shadowOrbSmashed
Definition WorldGen.cs:974
static void WaterCheck()
static bool spawnMeteor
Definition WorldGen.cs:980
static int[] tileCounts
Definition WorldGen.cs:934
static bool IsGeneratingHardMode
Definition WorldGen.cs:964
static DateTime Now
Definition DateTime.cs:103
static DateTime FromBinary(long dateData)
Definition DateTime.cs:671
static Guid NewGuid()
Definition Guid.cs:1283
static readonly Guid Empty
Definition Guid.cs:86