public BackwardsScanner(FileStream str, WorldHeader head)
		{
			stream = str;
			MaxX = head.MaxTiles.X;
			MaxY = head.MaxTiles.Y;
			header = head;
			backReader = new BackwardsBinaryReader(stream);
		}
Beispiel #2
0
		private void ReadHeader()
		{

			int version = reader.ReadInt32();
			if (version < 94)
				throw new Exception("Must use version 1.2.3.1 or higher!");

			ulong fileFormat = reader.ReadUInt64();

			byte fileTypeValue = (byte)(fileFormat >> 56 & (ulong)byte.MaxValue);
			//Revision
			uint revision = reader.ReadUInt32();

			//Favorite
			ulong favorite = reader.ReadUInt64();

			short sectionCount = reader.ReadInt16();
			sectionPointers = new int[sectionCount];
			for (int j = 0; j < sectionCount; j++)
			{
				sectionPointers[j] = reader.ReadInt32();
			}

			short tiletypeCount = reader.ReadInt16();
			tileImportant = new bool[tiletypeCount];
			byte flags = 0;
			byte mask = 0x80;

			for (int k = 0; k < tiletypeCount; k++)
			{
				if (mask == 0x80)
				{
					flags = reader.ReadByte();
					mask = 0x01;
				}
				else
				{
					mask <<= 1;
				}

				if ((flags & mask) == mask)
					tileImportant[k] = true;


			}

			Int32 x, y, w, h;
			Int32 i;

			if (bw != null)
				bw.ReportProgress((Int32)(((Single)progressPosition / stream.Length) * readWorldPerc)
					, "Reading Header");

			header = new WorldHeader();
			header.sectionPointers = sectionPointers;
			header.ReleaseNumber = version;
			header.Name = reader.ReadString();
			header.Id = reader.ReadInt32();
			x = reader.ReadInt32();
			w = reader.ReadInt32();
			y = reader.ReadInt32();
			h = reader.ReadInt32();

			header.WorldCoords = new Rect(x, w, y, h);


			MaxY = reader.ReadInt32();
			MaxX = reader.ReadInt32();

			header.MaxTiles = new Point(MaxX, MaxY);

			//Expert Mode
			bool expertMode;
			if (version >= 112)
				expertMode = reader.ReadBoolean();

			//Creation Time
			DateTime creationTime;
			if (version >= 141)
				creationTime = DateTime.FromBinary(reader.ReadInt64());



			header.TreeX = new int[3];
			header.TreeStyle = new int[4];
			header.CaveBackX = new int[3];
			header.CaveBackStyle = new int[4];
			header.MoonType = reader.ReadByte();

			for (i = 0; i < 3; i++)
			{
				header.TreeX[i] = reader.ReadInt32();
			}
			for (i = 0; i < 4; i++)
			{
				header.TreeStyle[i] = reader.ReadInt32();
			}
			for (i = 0; i < 3; i++)
			{
				header.CaveBackX[i] = reader.ReadInt32();
			}
			for (i = 0; i < 4; i++)
			{
				header.CaveBackStyle[i] = reader.ReadInt32();
			}
			header.IceBackStyle = reader.ReadInt32();
			header.JungleBackStyle = reader.ReadInt32();
			header.HellBackStyle = reader.ReadInt32();

			header.SpawnPoint = new Point(reader.ReadInt32(), reader.ReadInt32());
			header.SurfaceLevel = reader.ReadDouble();
			header.RockLayer = reader.ReadDouble();
			header.TemporaryTime = reader.ReadDouble();
			header.IsDayTime = reader.ReadBoolean();
			header.MoonPhase = reader.ReadInt32();
			header.IsBloodMoon = reader.ReadBoolean();
			header.IsEclipse = reader.ReadBoolean();

			header.DungeonPoint = new Point(reader.ReadInt32(), reader.ReadInt32());
			header.Crimson = reader.ReadBoolean();
			header.IsBoss1Dead = reader.ReadBoolean();
			header.IsBoss2Dead = reader.ReadBoolean();
			header.IsBoss3Dead = reader.ReadBoolean();

			header.IsQueenBeeDead = reader.ReadBoolean();
			header.IsMechBoss1Dead = reader.ReadBoolean();
			header.IsMechBoss2Dead = reader.ReadBoolean();
			header.IsMechBoss3Dead = reader.ReadBoolean();
			header.IsMechBossAnyDead = reader.ReadBoolean();
			header.IsPlantBossDead = reader.ReadBoolean();
			header.IsGolemBossDead = reader.ReadBoolean();

			if (version >= 118)
				header.IsSlimeKingDead = reader.ReadBoolean();

			header.IsGoblinSaved = reader.ReadBoolean();
			header.IsWizardSaved = reader.ReadBoolean();
			header.IsMechanicSaved = reader.ReadBoolean();
			header.IsGoblinArmyDefeated = reader.ReadBoolean();
			header.IsClownDefeated = reader.ReadBoolean();
			header.IsFrostDefeated = reader.ReadBoolean();
			header.IsPiratesDefeated = reader.ReadBoolean();
			header.IsShadowOrbSmashed = reader.ReadBoolean();
			header.IsMeteorSpawned = reader.ReadBoolean();
			header.ShadowOrbsSmashed = reader.ReadByte();

			header.AltarsDestroyed = reader.ReadInt32();
			header.HardMode = reader.ReadBoolean();

			header.InvasionDelay = reader.ReadInt32();
			header.InvasionSize = reader.ReadInt32();
			header.InvasionType = reader.ReadInt32();
			header.InvasionPointX = reader.ReadDouble();

			if (version >= 118)
				header.SlimeRainTime = reader.ReadDouble();
			if (version >= 113)
				header.SundialCooldown = (int)reader.ReadByte();

			header.OreTiers = new int[3];
			header.Styles = new byte[8];
			if (version >= 66)
			{
				header.IsRaining = reader.ReadBoolean();
				header.RainTime = reader.ReadInt32();
				header.MaxRain = reader.ReadSingle();

				for (i = 0; i < 3; i++)
				{
					header.OreTiers[i] = reader.ReadInt32();
				}

				for (i = 0; i < 8; i++)
				{
					header.Styles[i] = reader.ReadByte();
				}

				header.CloudsActive = reader.ReadInt32();
				header.NumClouds = reader.ReadInt16();
				header.WindSpeed = reader.ReadSingle();
				List<string> anglerWhoFinishedToday = new List<string>();
				for (int index = reader.ReadInt32(); index > 0; --index)
					anglerWhoFinishedToday.Add(reader.ReadString());
				if (version < 99)
					return;
				var savedAngler = reader.ReadBoolean();
				if (version < 101)
					return;
				var anglerQuest = reader.ReadInt32();

				//Saved Stylist
				reader.ReadBoolean();
				//Saved Tax Collector
				reader.ReadBoolean();

				//Inavsion Size Start
				reader.ReadInt32();

				//temp cultist delay
				reader.ReadInt32();

				int killCountTotal = (int)reader.ReadInt16();
				for (int killIndex = 0; killIndex < killCountTotal; killIndex++)
				{
					reader.ReadInt32();
				}

				//fast forward time
				reader.ReadBoolean();


				//downed fishron
				reader.ReadBoolean();

				// Martians
				reader.ReadBoolean();

				// Cultists
				reader.ReadBoolean();

				// Moonlord
				reader.ReadBoolean();

				// Halloween King
				reader.ReadBoolean();

				// Halloween Tree
				reader.ReadBoolean();

				// Christmas Ice Queen
				reader.ReadBoolean();

				// Christmas Santank
				reader.ReadBoolean();

				// Christmas Tree
				reader.ReadBoolean();

				// Tower Solar
				reader.ReadBoolean();

				// Tower Vortex
				reader.ReadBoolean();

				// Tower Nebula
				reader.ReadBoolean();

				// Tower Stardust
				reader.ReadBoolean();

				// Tower Active Solar
				reader.ReadBoolean();

				// Tower Active Vortex
				reader.ReadBoolean();

				// Tower Active Nebula
				reader.ReadBoolean();

				// Tower Active Stardust
				reader.ReadBoolean();

				// Lunar Apolocyplse is up
				reader.ReadBoolean();

			}


			posTiles = stream.Position;
			progressPosition = stream.Position;


		}
Beispiel #3
0
		public void Clear()
		{
			header = new WorldHeader();
			tiles = null;
			chests = null;
			signs = null;
			footer = null;

			posChests = 0;
			posEnd = 0;
			posFooter = 0;
			posNpcs = 0;
			posSigns = 0;
			posTiles = 0;

			MaxX = 0;
			MaxY = 0;
			progress = 0;

			if (reader != null)
			{
				reader.Close();
				reader = null;
			}

			if (stream != null)
				stream = null;

			if (buffReader != null)
				buffReader = null;

			if (bw != null)
				bw = null;
		}
Beispiel #4
0
        private void ReadHeader(World world)
        {
            version = reader.ReadInt32();
            sectionCount = reader.ReadInt16();
            sectionPointers = new int[sectionCount];
            for(int i = 0; i < sectionCount; i++)
            {
                sectionPointers[i] = reader.ReadInt32();
            }
            tiletypeCount = reader.ReadInt16();
            tileImportance = new bool[tiletypeCount];
            byte mask = 0x80;
            byte flags = 0;
            for (int i = 0; i < tiletypeCount; i++)
            {
                if (mask == 0x80)
                {
                    flags = reader.ReadByte();
                    mask = 0x01;
                }
                else
                {
                    mask <<= 1;
                }

                if ((flags & mask) == mask)
                    tileImportance[i] = true;

                
            }
            int x, y, w, h;
            
            var header = new WorldHeader();

           // header.ReleaseNumber = version;
            header.Name = reader.ReadString();
            header.Id = reader.ReadInt32();
            x = reader.ReadInt32();
            w = reader.ReadInt32();
            y = reader.ReadInt32();
            h = reader.ReadInt32();

            header.WorldCoords = new Rect(x, w, y, h);

            y = reader.ReadInt32();
            x = reader.ReadInt32();
            header.MaxTiles = new Point(x, y);

            header.TreeX = new int[3];
            header.TreeStyle = new int[4];
            header.CaveBackX = new int[3];
            header.CaveBackStyle = new int[4];

            if (version >= 0x3F)
            {
                header.MoonType = reader.ReadByte();
                for (int i = 0; i < 3; i++)
                {
                    header.TreeX[i] = reader.ReadInt32();
                }
                for (int i = 0; i < 4; i++)
                {
                    header.TreeStyle[i] = reader.ReadInt32();
                }
                for (int i = 0; i < 3; i++)
                {
                    header.CaveBackX[i] = reader.ReadInt32();
                }
                for (int i = 0; i < 4; i++)
                {
                    header.CaveBackStyle[i] = reader.ReadInt32();
                }
                header.IceBackStyle = reader.ReadInt32();
                header.JungleBackStyle = reader.ReadInt32();
                header.HellBackStyle = reader.ReadInt32();
            }


            header.SpawnPoint = new Point(reader.ReadInt32(), reader.ReadInt32());
            header.SurfaceLevel = reader.ReadDouble();
            header.RockLayer = reader.ReadDouble();
            header.TemporaryTime = reader.ReadDouble();
            header.IsDayTime = reader.ReadBoolean();
            header.MoonPhase = reader.ReadInt32();
            header.IsBloodMoon = reader.ReadBoolean();
            if (version >= 70)
                header.IsEclipse = reader.ReadBoolean();
            header.DungeonPoint = new Point(reader.ReadInt32(), reader.ReadInt32());
            if (version >= 66)
			    header.Crimson = reader.ReadBoolean();
            header.IsBoss1Dead = reader.ReadBoolean();
            header.IsBoss2Dead = reader.ReadBoolean();
            header.IsBoss3Dead = reader.ReadBoolean();
            if (version >= 66)
            {
                header.IsQueenBeeDead = reader.ReadBoolean();
                header.IsMechBoss1Dead = reader.ReadBoolean();
                header.IsMechBoss2Dead = reader.ReadBoolean();
                header.IsMechBoss3Dead = reader.ReadBoolean();
                header.IsMechBossAnyDead = reader.ReadBoolean();
                header.IsPlantBossDead = reader.ReadBoolean();
                header.IsGolemBossDead = reader.ReadBoolean();
            }
            if (version >= 0x24)
            {
                header.IsGoblinSaved = reader.ReadBoolean();
                header.IsWizardSaved = reader.ReadBoolean();
                header.IsMechanicSaved = reader.ReadBoolean();
                header.IsGoblinArmyDefeated = reader.ReadBoolean();
                header.IsClownDefeated = reader.ReadBoolean();
            }
            if (version >= 0x25)
            {
                header.IsFrostDefeated = reader.ReadBoolean();
            }
            if (version >= 66)
                header.IsPiratesDefeated = reader.ReadBoolean();

            header.IsShadowOrbSmashed = reader.ReadBoolean();
            header.IsMeteorSpawned = reader.ReadBoolean();
            header.ShadowOrbsSmashed = reader.ReadByte();

            if (version >= 0x24)
            {
                header.AltarsDestroyed = reader.ReadInt32();
                header.HardMode = reader.ReadBoolean();
            }

            header.InvasionDelay = reader.ReadInt32();
            header.InvasionSize = reader.ReadInt32();
            header.InvasionType = reader.ReadInt32();
            header.InvasionPointX = reader.ReadDouble();

            header.OreTiers = new int[3];
            header.Styles = new byte[8];
            if (version >= 66)
            {
                header.IsRaining = reader.ReadBoolean();
                header.RainTime = reader.ReadInt32();
                header.MaxRain = reader.ReadSingle();

                for (int i = 0; i < 3; i++)
                {
                    header.OreTiers[i] = reader.ReadInt32();
                }

                for (int i = 0; i < 8; i++)
                {
                    header.Styles[i] = reader.ReadByte();
                }

                header.CloudsActive = reader.ReadInt32();
                header.NumClouds = reader.ReadInt16();
                header.WindSpeed = reader.ReadSingle();
            }
            else if (version >= 24)
            {
                if (header.AltarsDestroyed == 0)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        header.OreTiers[i] = -1;
                    }
                }
                else
                {
                    header.OreTiers[1] = 107;
                    header.OreTiers[1] = 108;
                    header.OreTiers[1] = 111;
                }
            }

            world.Header = header;
        }