示例#1
0
		private void ReadSigns()
		{
			Sign theSign;
			signs = new List<Sign>(1000);

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

			int maxSigns = reader.ReadInt16();

			for (Int32 i = 0; i < maxSigns; i++)
			{
				//isSign = reader.ReadBoolean();

				theSign = new Sign();
				theSign.Id = i;
				theSign.Active = true;

				theSign.Text = reader.ReadString();
				theSign.Position = new Point(reader.ReadInt32(), reader.ReadInt32());

				signs.Add(theSign);


				progressPosition = stream.Position;
			}

			posNpcs = stream.Position;
		}
		public Int64 SeekToChestsBackwards()
		{
			Footer useFooter;
			NPC useNPC;
			Sign useSign = new Sign();
			Item useItem = new Item();
			Chest useChest;
			Int32 signCount;
			Int32 chestCount;
			Int32 i, j;
			Int32 countByte;
			long beforeReads;

			stream.Seek(0, SeekOrigin.End);
			useFooter = tryReadFooterBackwards();

			// We'll fail if we don't have a good footer object.
			if (useFooter.Active == false)
				return 0;

			if (header.ReleaseNumber >= 0x24)
			{
				String NPCName;
				if (header.ReleaseNumber >= 68)
				{
					NPCName = backReader.ReadBackwardsString(false);
					if (NPCName == null)
						return 0;
					header.PiratesName = NPCName;

					NPCName = backReader.ReadBackwardsString(false);
					if (NPCName == null)
						return 0;
					header.WitchDoctorsName = NPCName;

					NPCName = backReader.ReadBackwardsString(false);
					if (NPCName == null)
						return 0;
					header.PaintersName = NPCName;

					NPCName = backReader.ReadBackwardsString(false);
					if (NPCName == null)
						return 0;
					header.CyborgsName = NPCName;

					NPCName = backReader.ReadBackwardsString(false);
					if (NPCName == null)
						return 0;
					header.PartyGirlsName = NPCName;

					NPCName = backReader.ReadBackwardsString(false);
					if (NPCName == null)
						return 0;
					header.DyeTradersName = NPCName;

					NPCName = backReader.ReadBackwardsString(false);
					if (NPCName == null)
						return 0;
					header.SteamPunkersName = NPCName;

					NPCName = backReader.ReadBackwardsString(false);
					if (NPCName == null)
						return 0;
					header.TrufflesName = NPCName;
				}

				NPCName = backReader.ReadBackwardsString(false);
				if (NPCName == null)
					return 0;
				header.MechanicsName = NPCName;

				NPCName = backReader.ReadBackwardsString(false);
				if (NPCName == null)
					return 0;
				header.WizardsName = NPCName;

				NPCName = backReader.ReadBackwardsString(false);
				if (NPCName == null)
					return 0;
				header.TinkerersName = NPCName;

				NPCName = backReader.ReadBackwardsString(false);
				if (NPCName == null)
					return 0;
				header.DemolitionistsName = NPCName;

				NPCName = backReader.ReadBackwardsString(false);
				if (NPCName == null)
					return 0;
				header.ClothiersName = NPCName;

				NPCName = backReader.ReadBackwardsString(false);
				if (NPCName == null)
					return 0;
				header.GuidesName = NPCName;

				NPCName = backReader.ReadBackwardsString(false);
				if (NPCName == null)
					return 0;
				header.DryadsName = NPCName;

				NPCName = backReader.ReadBackwardsString(false);
				if (NPCName == null)
					return 0;
				header.ArmsDealersName = NPCName;

				NPCName = backReader.ReadBackwardsString(false);
				if (NPCName == null)
					return 0;
				header.NursesName = NPCName;

				NPCName = backReader.ReadBackwardsString(false);
				if (NPCName == null)
					return 0;
				header.MerchantsName = NPCName;
			}

			// The NPC section always ends with 00 for "No more NPCs".  
			if (backReader.ReadBackwardsByte() != 00)
				return 0;

			do
			{
				useNPC = tryReadNPCBackwards();
			} while (useNPC.Active == true);

			// So now we need to find a way to read backwards through all the zeros and find our way to the
			// last sign.

			// So at first it looked like most zeros we could have was 9 and still get a
			// good sign but Terraria only allows you to go to within 22 of the edges.
			// This means it's actually three max.
			signCount = countBackwardZeros(1003);

			// Every sign item ends with at least two zeros.  If we have less then
			// reading backwards failed.
			if (signCount < 2)
				return 0;

			if (signCount == 2)
			{
				stream.Seek(2, SeekOrigin.Current);
				signCount = 0;
			}
			else
			{
				stream.Seek(3, SeekOrigin.Current);
				signCount -= 3;
			}

			// Simple loop.  We set it to the earliest we could have a good sign then
			// keep reading in as many signs as we can.  If we don't get a good sign see
			// if we have a zero at the very start.  If so we can call it an empty sign
			// and shift over and try again.
			for (i = signCount; i < 1000; i++)
			{
				useSign = tryReadSignBackwards();

				if (useSign.Active == true)
					continue;

				j = backReader.ReadBackwardsByte();

				if (j != 0)
					return 0;

			}

			// Time to read the chests.

			// So just like signs the longest 0 string we can get is a pure empty chest with
			// Y coord less then 256.  This is 23.
			chestCount = countBackwardZeros(1023);

			if (chestCount < 23)
			{
				stream.Seek(chestCount, SeekOrigin.Current);
				chestCount = 0;
			}
			else
			{
				stream.Seek(23, SeekOrigin.Current);
				chestCount -= (23);
			}

			int numChestItems;
			if (header.ReleaseNumber < 68)
				numChestItems = 20;
			else
				numChestItems = 40;

			for (i = chestCount; i < 1000; i++)
			{
				beforeReads = stream.Position;

				for (j = 0; j < numChestItems; j++)
				{
					countByte = backReader.PeekBackwardsByte();

					if (countByte != 00)
					{
						useItem = tryReadChestItemBackwards();

						if (useItem.Count == 0)
							return 0;
					}
					else
					{
						backReader.ReadBackwardsByte();
					}
				}

				useChest = tryReadChestHeaderBackwards();

				if (useChest.Active == false)
				{
					stream.Seek(beforeReads, SeekOrigin.Begin);

					countByte = backReader.ReadBackwardsByte();

					if (countByte != 00)
						return 0;
				}
			}

			return stream.Position;
		}
		/// <summary>
		/// Tries to make the next bytes backward in the stream fit into an Sign object.
		/// If it fails sets the position back to where it was.
		/// </summary>
		/// <returns>An Sign object.  activeSign will be true for a valid Sign.</returns>
		private Sign tryReadSignBackwards()
		{
			Int32 x, y;
			Int32 strictbool;
			Sign returnSign = new Sign();
			long oldPosition = stream.Position;
			Boolean validSign = false;

#if (DEBUG == false)
			try
			{
#endif
				y = backReader.ReadBackwardsInt32();
				x = backReader.ReadBackwardsInt32();

				returnSign.Position = new Point(x, y);

				// We're going to try to read in the string.  In a Sign the string should
				// always have a 0x01 before it to show it was an active Sign.
				returnSign.Text = backReader.ReadBackwardsString(true, 1500, 1);
				//returnSign.Text = backReader.ReadBackwardsString(true, 1500);

				if (returnSign.Text != null)
				{
					strictbool = backReader.ReadBackwardsByte();

					if (strictbool == 1)
						returnSign.Active = true;

					if (returnSign.Active == true && y != 0 && x != 0)
						validSign = true;
				}
#if (DEBUG == false)
			}
			catch (EndOfStreamException e)
			{
				e.GetType();
			}
#endif

			if (validSign == false)
			{
				stream.Seek(oldPosition, SeekOrigin.Begin);
				returnSign.Active = false;
			}

			return returnSign;
		}
示例#4
0
        private void ReadSigns(World world)
        {
            Boolean isSign;
            Sign theSign;
            var signs = new List<Sign>(1000);


            for (Int32 i = 0; i < 1000; i++)
            {
                isSign = reader.ReadBoolean();
                if (isSign == true)
                {
                    theSign = new Sign();
                    theSign.Id = i;
                    theSign.Active = isSign;

                    theSign.Text = reader.ReadString();
                    theSign.Position = new Point(reader.ReadInt32(), reader.ReadInt32());

                    signs.Add(theSign);
                }

               // progressPosition = stream.Position;
            }

            world.Signs = signs;

   
        }