public static void WritePatch(Patch patch, IWriter writer)
		{
			var container = new ContainerWriter(writer);
			container.StartBlock("asmp", 0);
			WriteBlocks(patch, container, writer);
			container.EndBlock();
		}
Beispiel #2
0
        public static void WriteTagContainer(TagContainer tags, IWriter writer)
        {
            var container = new ContainerWriter(writer);
            container.StartBlock("tagc", 0);

            WriteDataBlocks(tags, container, writer);
            WriteTags(tags, container, writer);
            WriteResourcePages(tags, container, writer);
            WriteResources(tags, container, writer);

            container.EndBlock();
        }
Beispiel #3
0
        private static void WriteDataBlocks(TagContainer tags, ContainerWriter container, IWriter writer)
        {
            foreach (DataBlock dataBlock in tags.DataBlocks)
            {
                container.StartBlock("data", 2);

                // Main data
                writer.WriteUInt32(dataBlock.OriginalAddress);
                writer.WriteInt32(dataBlock.EntryCount);
                WriteByteArray(dataBlock.Data, writer);

                // Address fixups
                writer.WriteInt32(dataBlock.AddressFixups.Count);
                foreach (DataBlockAddressFixup blockRef in dataBlock.AddressFixups)
                {
                    writer.WriteUInt32(blockRef.OriginalAddress);
                    writer.WriteInt32(blockRef.WriteOffset);
                }

                // Tagref fixups
                writer.WriteInt32(dataBlock.TagFixups.Count);
                foreach (DataBlockTagFixup tagRef in dataBlock.TagFixups)
                {
                    writer.WriteUInt32(tagRef.OriginalIndex.Value);
                    writer.WriteInt32(tagRef.WriteOffset);
                }

                // Resource reference fixups
                writer.WriteInt32(dataBlock.ResourceFixups.Count);
                foreach (DataBlockResourceFixup resourceRef in dataBlock.ResourceFixups)
                {
                    writer.WriteUInt32(resourceRef.OriginalIndex.Value);
                    writer.WriteInt32(resourceRef.WriteOffset);
                }

                // StringID fixups
                writer.WriteInt32(dataBlock.StringIDFixups.Count);
                foreach (DataBlockStringIDFixup sid in dataBlock.StringIDFixups)
                {
                    writer.WriteAscii(sid.OriginalString);
                    writer.WriteInt32(sid.WriteOffset);
                }

                container.EndBlock();
            }
        }
		private static void WritePatchInfo(Patch patch, ContainerWriter container, IWriter writer)
		{
			container.StartBlock("titl", 2); // Version 2

			// Write target map info
			writer.WriteInt32(patch.MapID);
			if (patch.MapInternalName != null)
				writer.WriteAscii(patch.MapInternalName);
			else
				writer.WriteByte(0);

			// Write patch info
			writer.WriteUTF16(patch.Name);
			writer.WriteUTF16(patch.Description);
			writer.WriteUTF16(patch.Author);

			// Write screenshot
			if (patch.Screenshot != null)
			{
				writer.WriteInt32(patch.Screenshot.Length);
				writer.WriteBlock(patch.Screenshot);
			}
			else
			{
				writer.WriteInt32(0);
			}

			// Write meta info
			writer.WriteUInt32(patch.MetaPokeBase);
			writer.WriteSByte((sbyte) patch.MetaChangesIndex);

			// Write output name
			if (patch.OutputName != null)
				writer.WriteAscii(patch.OutputName);
			else
				writer.WriteByte(0);

			container.EndBlock();
		}
        private static void WriteBlfInfo(Patch patch, ContainerWriter container, IWriter writer)
        {
            if (patch.CustomBlfContent == null)
                return;

            container.StartBlock("blfc", 0); // Version 0

            writer.WriteByte((byte) patch.CustomBlfContent.TargetGame);

            // Write mapinfo filename
            if (patch.CustomBlfContent.MapInfoFileName != null)
                writer.WriteAscii(patch.CustomBlfContent.MapInfoFileName);
            else
                writer.WriteByte(0);

            // Write mapinfo data
            if (patch.CustomBlfContent.MapInfo != null)
            {
                writer.WriteUInt32((uint) patch.CustomBlfContent.MapInfo.Length);
                writer.WriteBlock(patch.CustomBlfContent.MapInfo);
            }
            else
            {
                writer.WriteUInt32(0);
            }

            // Write BLF containers
            writer.WriteInt16((short) patch.CustomBlfContent.BlfContainerEntries.Count);
            foreach (BlfContainerEntry blfContainerEntry in patch.CustomBlfContent.BlfContainerEntries)
            {
                writer.WriteAscii(blfContainerEntry.FileName);
                writer.WriteUInt32((uint) blfContainerEntry.BlfContainer.Length);
                writer.WriteBlock(blfContainerEntry.BlfContainer);
            }

            container.EndBlock();
        }
Beispiel #6
0
        private static void WriteResourcePages(TagContainer tags, ContainerWriter container, IWriter writer)
        {
            foreach (ResourcePage page in tags.ResourcePages)
            {
                container.StartBlock("rspg", 1);

                writer.WriteInt32(page.Index);
                writer.WriteUInt16(page.Salt);
                writer.WriteByte(page.Flags);
                writer.WriteAscii(page.FilePath ?? "");
                writer.WriteInt32(page.Offset);
                writer.WriteInt32(page.UncompressedSize);
                writer.WriteByte((byte) page.CompressionMethod);
                writer.WriteInt32(page.CompressedSize);
                writer.WriteUInt32(page.Checksum);
                WriteByteArray(page.Hash1, writer);
                WriteByteArray(page.Hash2, writer);
                WriteByteArray(page.Hash3, writer);
                writer.WriteInt32(page.Unknown1);
                writer.WriteInt32(page.Unknown2);
                writer.WriteInt32(page.Unknown3);

                container.EndBlock();
            }
        }
Beispiel #7
0
        private static void WriteTags(TagContainer tags, ContainerWriter container, IWriter writer)
        {
            foreach (ExtractedTag tag in tags.Tags)
            {
                container.StartBlock("tag!", 0);

                writer.WriteUInt32(tag.OriginalIndex.Value);
                writer.WriteUInt32(tag.OriginalAddress);
                writer.WriteInt32(tag.Class);
                writer.WriteAscii(tag.Name);

                container.EndBlock();
            }
        }
Beispiel #8
0
        private static void WriteResources(TagContainer tags, ContainerWriter container, IWriter writer)
        {
            foreach (ExtractedResourceInfo resource in tags.Resources)
            {
                container.StartBlock("rsrc", 1);

                writer.WriteUInt32(resource.OriginalIndex.Value);
                writer.WriteUInt32(resource.Flags);
                if (resource.Type != null)
                    writer.WriteAscii(resource.Type);
                else
                    writer.WriteByte(0);
                WriteByteArray(resource.Info, writer);
                writer.WriteUInt32(resource.OriginalParentTagIndex.Value);
                if (resource.Location != null)
                {
                    writer.WriteByte(1);
                    writer.WriteInt32(resource.Location.OriginalPrimaryPageIndex);
                    writer.WriteInt32(resource.Location.PrimaryOffset);
                    writer.WriteInt32(resource.Location.PrimaryUnknown);
                    writer.WriteInt32(resource.Location.OriginalSecondaryPageIndex);
                    writer.WriteInt32(resource.Location.SecondaryOffset);
                    writer.WriteInt32(resource.Location.SecondaryUnknown);
                }
                else
                {
                    writer.WriteByte(0);
                }
                writer.WriteInt32(resource.Unknown1);
                writer.WriteInt32(resource.Unknown2);
                writer.WriteInt32(resource.Unknown3);

                writer.WriteInt32(resource.ResourceFixups.Count);
                foreach (ResourceFixup fixup in resource.ResourceFixups)
                {
                    writer.WriteInt32(fixup.Offset);
                    writer.WriteUInt32(fixup.Address);
                }

                writer.WriteInt32(resource.DefinitionFixups.Count);
                foreach (ResourceDefinitionFixup fixup in resource.DefinitionFixups)
                {
                    writer.WriteInt32(fixup.Offset);
                    writer.WriteInt32(fixup.Type);
                }

                container.EndBlock();
            }
        }
		private static void WriteSegmentChanges(Patch patch, ContainerWriter container, IWriter writer)
		{
			if (patch.SegmentChanges.Count == 0)
				return;

			container.StartBlock("segm", 0); // Version 0

			writer.WriteByte((byte) patch.SegmentChanges.Count);
			foreach (SegmentChange segment in patch.SegmentChanges)
			{
				writer.WriteUInt32(segment.OldOffset);
				writer.WriteInt32(segment.OldSize);
				writer.WriteUInt32(segment.NewOffset);
				writer.WriteInt32(segment.NewSize);
				writer.WriteByte(Convert.ToByte(segment.ResizeAtEnd));

				WriteDataChanges(segment.DataChanges, writer);
			}

			container.EndBlock();
		}
		private static void WriteLocaleChanges(Patch patch, ContainerWriter container, IWriter writer)
		{
			if (patch.LanguageChanges.Count == 0)
				return;

			container.StartBlock("locl", 0); // Version 0

			// Write change data for each language
			writer.WriteByte((byte) patch.LanguageChanges.Count);
			foreach (LanguageChange language in patch.LanguageChanges)
			{
				writer.WriteByte(language.LanguageIndex);

				// Write the change data for each string in the language
				writer.WriteInt32(language.LocaleChanges.Count);
				foreach (LocaleChange change in language.LocaleChanges)
				{
					writer.WriteInt32(change.Index);
					writer.WriteUTF8(change.NewValue);
				}
			}

			container.EndBlock();
		}
		private static void WriteMetaChanges(Patch patch, ContainerWriter container, IWriter writer)
		{
			if (patch.MetaChanges.Count == 0)
				return;

			container.StartBlock("meta", 0); // Version 0

			List<DataChange> fourByteChanges = patch.MetaChanges.Where(c => c.Data.Length == 4).ToList();
			List<DataChange> otherChanges = patch.MetaChanges.Where(c => c.Data.Length != 4).ToList();

			// Write 4-byte changes
			writer.WriteUInt32((uint) fourByteChanges.Count);
			foreach (DataChange change in fourByteChanges)
			{
				writer.WriteUInt32(change.Offset);
				writer.WriteBlock(change.Data);
			}

			// Write other changes
			writer.WriteUInt32((uint) otherChanges.Count);
			foreach (DataChange change in otherChanges)
			{
				writer.WriteUInt32(change.Offset);
				writer.WriteInt32(change.Data.Length);
				writer.WriteBlock(change.Data);
			}

			container.EndBlock();
		}
Beispiel #12
0
		private static void WriteDataBlocks(TagContainer tags, ContainerWriter container, IWriter writer)
		{
			foreach (DataBlock dataBlock in tags.DataBlocks)
			{
				container.StartBlock("data", 6);

				// Main data
				writer.WriteUInt32(dataBlock.OriginalAddress);
				writer.WriteInt32(dataBlock.EntryCount);
				writer.WriteInt32(dataBlock.Alignment);
				WriteByteArray(dataBlock.Data, writer);

				// Address fixups
				writer.WriteInt32(dataBlock.AddressFixups.Count);
				foreach (DataBlockAddressFixup blockRef in dataBlock.AddressFixups)
				{
					writer.WriteUInt32(blockRef.OriginalAddress);
					writer.WriteInt32(blockRef.WriteOffset);
				}

				// Tagref fixups
				writer.WriteInt32(dataBlock.TagFixups.Count);
				foreach (DataBlockTagFixup tagRef in dataBlock.TagFixups)
				{
					writer.WriteUInt32(tagRef.OriginalIndex.Value);
					writer.WriteInt32(tagRef.WriteOffset);
				}

				// Resource reference fixups
				writer.WriteInt32(dataBlock.ResourceFixups.Count);
				foreach (DataBlockResourceFixup resourceRef in dataBlock.ResourceFixups)
				{
					writer.WriteUInt32(resourceRef.OriginalIndex.Value);
					writer.WriteInt32(resourceRef.WriteOffset);
				}

				// StringID fixups
				writer.WriteInt32(dataBlock.StringIDFixups.Count);
				foreach (DataBlockStringIDFixup sid in dataBlock.StringIDFixups)
				{
					writer.WriteAscii(sid.OriginalString);
					writer.WriteInt32(sid.WriteOffset);
				}

				// Shader fixups
				writer.WriteInt32(dataBlock.ShaderFixups.Count);
				foreach (DataBlockShaderFixup shaderRef in dataBlock.ShaderFixups)
				{
					writer.WriteInt32(shaderRef.WriteOffset);
					if (shaderRef.Data != null)
					{
						writer.WriteInt32(shaderRef.Data.Length);
						writer.WriteBlock(shaderRef.Data);
					}
					else
					{
						writer.WriteInt32(0);
					}
				}

				// Unicode string list fixups
				writer.WriteInt32(dataBlock.UnicListFixups.Count);
				foreach (DataBlockUnicListFixup unicList in dataBlock.UnicListFixups)
				{
					writer.WriteInt32(unicList.LanguageIndex);
					writer.WriteInt32(unicList.WriteOffset);
					writer.WriteInt32(unicList.Strings.Length);
					foreach (UnicListFixupString str in unicList.Strings)
					{
						writer.WriteAscii(str.StringID);
						writer.WriteUTF8(str.String);
					}
				}

				container.EndBlock();
			}
		}
Beispiel #13
0
		private static void WriteExtractedResourcePages(TagContainer tags, ContainerWriter container, IWriter writer)
		{
			foreach (var extractedPage in tags.ExtractedResourcePages)
			{
				container.StartBlock("ersp", 0);

				writer.WriteInt32(extractedPage.ResourcePageIndex);
				WriteByteArray(extractedPage.ExtractedPageData, writer);

				container.EndBlock();
			}
		}