changeset 0:82db9430c2e4 default tip

Initial commit under GPLv3
author IBBoard <dev@ibboard.co.uk>
date Sat, 06 Oct 2018 19:49:25 +0100
parents
children
files .hgignore AssemblyInfo.cs COPYING ChunkyChunk.cs ChunkyData.cs ChunkyDataATTR.cs ChunkyDataCHAN.cs ChunkyDataDATA.cs ChunkyDataDATAIMAG.cs ChunkyDataFBIF.cs ChunkyDataHEAD.cs ChunkyDataINFO.cs ChunkyDataINFOGeneric.cs ChunkyDataINFOSHDR.cs ChunkyDataINFOTPAT.cs ChunkyDataINFOTXTR.cs ChunkyDataLayer.cs ChunkyDataPTBD.cs ChunkyDataPTBN.cs ChunkyDataPTLD.cs ChunkyDataSSHR.cs ChunkyDataUnknown.cs ChunkyFolder.cs ChunkyRawData.cs ChunkyValidator.cs Collections/ChunkyCollection.cs Collections/ChunkyStructureCollection.cs Collections/SgaFileCollection.cs Collections/SgaFolderCollection.cs Compression/ICSharpCode.SharpZipLib.dll Exceptions/Exception.cs Exceptions/FileExistsException.cs Exceptions/FileNotFoundException.cs Exceptions/FileNotZippedException.cs Exceptions/InvalidChunkException.cs Exceptions/InvalidChunkValueException.cs Exceptions/InvalidFileException.cs Exceptions/InvalidSourceFileException.cs Exceptions/InvalidUseException.cs FileFormats.cs LayerCollection.cs RECFile.cs RSHFile.cs RTXFile.cs RelicBinaryReader.cs RelicChunkReader.cs RelicChunkyFile.cs RelicChunkyReader.cs RelicChunkyStructure.cs RelicTools.csproj RelicTools.csproj.user SgaArchive.cs SgaFile.cs SgaFolder.cs SgaReader.cs WTPFile.cs
diffstat 56 files changed, 8592 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,2 @@
+bin/
+obj/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AssemblyInfo.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,61 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+//
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+//
+[assembly: AssemblyTitle("Relic Tools")]
+[assembly: AssemblyDescription("Assorted utility classes for handling Relic's Dawn of War file formats")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("IBBoard, 2006-2007")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]		
+
+//
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers 
+// by using the '*' as shown below:
+
+[assembly: AssemblyVersion("1.0.*")]
+
+//
+// In order to sign your assembly you must specify a key to use. Refer to the 
+// Microsoft .NET Framework documentation for more information on assembly signing.
+//
+// Use the attributes below to control which key is used for signing. 
+//
+// Notes: 
+//   (*) If no key is specified, the assembly is not signed.
+//   (*) KeyName refers to a key that has been installed in the Crypto Service
+//       Provider (CSP) on your machine. KeyFile refers to a file which contains
+//       a key.
+//   (*) If the KeyFile and the KeyName values are both specified, the 
+//       following processing occurs:
+//       (1) If the KeyName can be found in the CSP, that key is used.
+//       (2) If the KeyName does not exist and the KeyFile does exist, the key 
+//           in the KeyFile is installed into the CSP and used.
+//   (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
+//       When specifying the KeyFile, the location of the KeyFile should be
+//       relative to the project output directory which is
+//       %Project Directory%\obj\<configuration>. For example, if your KeyFile is
+//       located in the project directory, you would specify the AssemblyKeyFile 
+//       attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
+//   (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
+//       documentation for more information on this.
+//
+[assembly: AssemblyDelaySign(false)]
+[assembly: AssemblyKeyFile("")]
+[assembly: AssemblyKeyName("")]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/COPYING	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyChunk.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,243 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.Text;
+using System.IO;
+
+namespace IBBoard.Relic.RelicTools
+{
+	public enum ChunkyChunkType {Data, Folder, RawData}
+	/// <summary>
+	/// Summary description for ChunkyChunk.
+	/// </summary>
+	public abstract class ChunkyChunk
+	{
+		protected string id;
+		protected int version;
+		protected string name;
+		//protected int dataLength;
+		protected ChunkyChunkType type;
+		protected ChunkyFolder parent;
+		private RelicChunkyFile parentFile;
+
+		public ChunkyChunk(ChunkyChunkType type_in, string ID_in, int version_in, string name_in)
+		{
+			type = type_in;
+			id = ID_in;
+			version = version_in;
+			name = name_in;
+			parentFile = null;
+		}
+
+		public ChunkyFolder Parent
+		{
+			get{return parent;}
+			set{parent = value;}
+		}
+
+		public RelicChunkyFile ParentFile
+		{
+			get
+			{
+				if (parentFile!=null)
+				{
+					return parentFile;
+				}
+				else if (parent!=null)
+				{
+					return parent.ParentFile;
+				}
+				else
+				{
+					return null;
+				}
+			}
+			set
+			{
+				if (parent==null)
+				{
+					parentFile = value;
+				}
+				else
+				{
+					throw new InvalidOperationException("Unable to set parent file - parent file must only be set on root nodes.");
+				}
+			}
+		}
+
+		public virtual int Length
+		{
+			get {
+				return 20 + NameDataLength + DataLength;
+			}
+		}
+
+		public int NameLength
+		{
+			get
+			{
+				return name.Length;
+			}
+		}
+
+		public int NameDataLength
+		{
+			get
+			{
+				if (name=="")
+				{
+					return 0;
+				}
+				else
+				{
+					return NameLength+1; //names are padded with a single null if they exist
+				}
+			}
+		}
+
+		public abstract int DataLength{get;}
+
+		public string ID
+		{
+			get{return id;}
+		}
+
+		public string Name
+		{
+			get{return name;}
+			set
+			{
+				if (name!=null)
+				{
+					name = value;
+				}
+				else
+				{
+					name = ""; 
+				}
+			}
+		}
+
+		public abstract string GetValidationString();
+
+		public virtual string GetDisplayDetails()
+		{
+			return "Type:\t\t"+ type.ToString() + Environment.NewLine +
+					"ID:\t\t"+ id + Environment.NewLine +
+					"Version:\t"+version+Environment.NewLine +
+					"Data Size:\t"+DataLength+Environment.NewLine +
+					"Chunk Size:\t"+Length+Environment.NewLine +
+					"Name Length:\t"+name.Length+Environment.NewLine +
+					"Name:\t\t"+name;
+		}
+
+		public static string ByteArrayToString(byte[] arr)
+		{
+			StringBuilder sb = new StringBuilder(arr.Length);
+
+			for (int i = 0; i<arr.Length && i<512; i++)
+			{
+				if ((i%4)==0 && i!=0)
+				{
+					sb.Append(" ");
+				}
+
+				sb.Append(String.Format("{0:x2}", arr[i])+" ");
+			}
+
+			if (arr.Length>511)
+			{
+				sb.Append(Environment.NewLine+"...Truncated...");
+			}
+
+			return sb.ToString();
+		}
+
+		public static string ByteArrayToString(byte[] arr, int start)
+		{
+
+			return ByteArrayToString(arr, start, (arr.Length-start));
+		}
+
+		public static string ByteArrayToString(byte[] arr, int start, int length)
+		{
+			byte[] temp = new byte[length];
+
+			for (int i = 0; i<length; i++)
+			{
+				temp[i] = arr[start+i];
+			}
+
+			return ByteArrayToString(temp);
+		}
+
+		public static float ByteArrayToSingle(byte[] arr)
+		{
+			return BitConverter.ToSingle(arr, 0);;
+		}
+
+		public static float ByteArrayToSingle(byte[] arr, int start)
+		{
+			return BitConverter.ToSingle(arr, start);
+		}
+
+		public static string ByteArrayToTextString(byte[] arr)
+		{
+			StringBuilder sb = new StringBuilder(arr.Length);
+
+			for (int i = 0; i<arr.Length; i++)
+			{
+				sb.Append((char)arr[i]);
+			}
+
+			return sb.ToString();
+		}
+
+		public static string ByteArrayToTextString(byte[] arr, int start)
+		{
+
+			return ByteArrayToTextString(arr, start, (arr.Length-start));
+		}
+
+		public static string ByteArrayToTextString(byte[] arr, int start, int length)
+		{
+			byte[] temp = new byte[length];
+
+			for (int i = 0; i<length; i++)
+			{
+				temp[i] = arr[start+i];
+			}
+
+			return ByteArrayToTextString(temp);
+		}
+
+		protected byte[] GetNameBytes()
+		{
+			if (name=="")
+			{
+				return new byte[0];
+			}
+			else
+			{
+				byte[] bytes = new byte[name.Length+1];
+				System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
+				enc.GetBytes(name).CopyTo(bytes,0);
+				return bytes;
+			}
+		}
+
+		public bool Export(String destination)
+		{
+			FileStream str = new FileStream(destination, FileMode.Create);
+			BinaryWriter bw = new BinaryWriter(str);
+			bw.Write(this.GetBytes());
+			bw.Flush();
+			bw.Close();
+			return true;
+		}
+
+		public abstract byte [] GetBytes();
+		public abstract bool Savable { get; }
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyData.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,134 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyData.
+	/// </summary>
+	public abstract class ChunkyData : ChunkyChunk
+	{
+		public static readonly byte[] TGA_Greyscale_Header_a = new byte[]{0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+		public static readonly byte[] TGA_Greyscale_Header_b = new byte[]{0x08, 0x00}; //Adobe Photoshop sets the second byte (the ImageDescriptor) as 0x08 but that means alpha transparency, which only 16/32-bit images should have, which confuses The GIMP and is technically against the standards
+		public static readonly byte[] TGA_Colour_Header_a = new byte[]{0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+		public static readonly byte[] TGA_Colour_Header_b = new byte[]{0x20, 0x08};
+		public static readonly byte[] DTX_Header_a = new byte[]{0x44, 0x44, 0x53, 0x20,//"DDS "
+																   0x7C, 0x00, 0x00, 0x00,//size - fixed to 124
+																   //0x07, 0x10, 0x02, 0x00};//valid field flags - DDSD_CAPS, DDSD_PIXELFORMAT, DDSD_WIDTH, DDSD_HEIGHT
+																   0x07, 0x10, 0x0A, 0x00};
+		public static readonly byte[] DXT1_Header_b = new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//11 DWords of unspecified 'reserved'
+																	0x20, 0x00, 0x00, 0x00, //size - apparently fixed to 32
+																	0x04, 0x00, 0x00, 0x00,//DDPF_FOURCC
+																	0x44, 0x58, 0x54, 0x31,//DTX1
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //RGB and Alpha bit masks - not used in DoW DDS files
+																	0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, //DDS Caps - always the same in DoW
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//two more reserved DWords
+																	0x00, 0x00, 0x00, 0x00};//and a final reserved DWord for good measure!
+
+		public static readonly byte[] DXT3_Header_b = new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//11 DWords of unspecified 'reserved'
+																	0x20, 0x00, 0x00, 0x00, //size - apparently fixed to 32
+																	0x04, 0x00, 0x00, 0x00,//DDPF_FOURCC
+																	0x44, 0x58, 0x54, 0x33,//DTX5
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //RGB and Alpha bit masks - not used in DoW DDS files
+																	0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, //DDS Caps - always the same in DoW
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//two more reserved DWords
+																	0x00, 0x00, 0x00, 0x00};//and a final reserved DWord for good measure!
+		
+		public static readonly byte[] DXT5_Header_b = new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//11 DWords of unspecified 'reserved'
+																	0x20, 0x00, 0x00, 0x00, //size - apparently fixed to 32
+																	0x04, 0x00, 0x00, 0x00,//DDPF_FOURCC
+																	0x44, 0x58, 0x54, 0x35,//DTX5
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //RGB and Alpha bit masks - not used in DoW DDS files
+																	0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, //DDS Caps - always the same in DoW
+																	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//two more reserved DWords
+																	0x00, 0x00, 0x00, 0x00};//and a final reserved DWord for good measure!
+
+		public ChunkyData(string ID_in, int version_in, string name_in):base(ChunkyChunkType.Data, ID_in, version_in, name_in)
+		{}
+
+		protected string GetBaseDisplayDetails()
+		{
+			return base.GetDisplayDetails();
+		}
+
+		public override byte[] GetBytes()
+		{
+			
+			byte[] file = new byte[Length];
+			byte[] temp;
+			int pos = 0;
+			System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
+			
+			enc.GetBytes("DATA"+id).CopyTo(file,0);
+			pos=id.Length+4;
+
+			BitConverter.GetBytes(version).CopyTo(file, pos);
+			pos+=4;
+			BitConverter.GetBytes(DataLength).CopyTo(file, pos);
+			pos+=4;
+			BitConverter.GetBytes(NameDataLength).CopyTo(file, pos);
+			pos+=4;
+			temp = GetNameBytes();
+			temp.CopyTo(file, pos);
+			pos+=temp.Length;
+			GetDataBytes().CopyTo(file, pos);
+
+			return file;
+		}
+
+		public abstract byte[] GetDataBytes();
+
+		protected byte[] GetStartBytes()
+		{
+			byte[] file = new byte[NameDataLength+20];
+			int pos = 0;
+			System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
+			
+			enc.GetBytes("DATA"+id).CopyTo(file,0);
+			pos=id.Length+4;
+
+			BitConverter.GetBytes(version).CopyTo(file, pos);
+			pos+=4;
+			BitConverter.GetBytes(DataLength).CopyTo(file, pos);
+			pos+=4;
+			BitConverter.GetBytes(NameDataLength).CopyTo(file, pos);
+			pos+=4;
+			GetNameBytes().CopyTo(file, pos);
+
+			return file;
+		}
+
+		public virtual bool Save(string path)
+		{			
+			string name = this.ParentFile.Name.Substring(0, this.ParentFile.Name.LastIndexOf('.'));
+			this.Save(new DirectoryInfo(path), name);
+			return true;
+		}
+
+		public virtual void Save(DirectoryInfo dir, string fileBaseName)
+		{
+		}
+
+		public override bool Savable
+		{
+			get{return false;}
+		}
+
+		public override string GetValidationString()
+		{
+			return "DATA"+ID;
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataATTR.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,132 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataDATA.
+	/// </summary>
+	public class ChunkyDataATTR : ChunkyData
+	{
+
+		int width = 0;
+		int height = 0;
+		int mipmaps = 0;
+		int imagetype = 0;
+
+		public ChunkyDataATTR(int version_in, string name_in, byte[] innerData_in):base("ATTR", version_in, name_in)
+		{
+			imagetype = innerData_in[0]+(innerData_in[1]<<8)+(innerData_in[2]<<16)+(innerData_in[3]<<24);
+			width = innerData_in[4]+(innerData_in[5]<<8)+(innerData_in[6]<<16)+(innerData_in[7]<<24);
+			height = innerData_in[8]+(innerData_in[9]<<8)+(innerData_in[10]<<16)+(innerData_in[11]<<24);
+
+			if (innerData_in.Length>12)
+			{
+				mipmaps = innerData_in[12]+(innerData_in[13]<<8)+(innerData_in[14]<<16)+(innerData_in[15]<<24);
+			}
+			else
+			{
+				mipmaps = 0;
+			}
+		}
+
+		public int Width
+		{
+			get
+			{
+				return width;
+			}
+		}
+
+		public int Height
+		{
+			get
+			{
+				return height;
+			}
+		}
+
+		public int MipMaps
+		{
+			get
+			{
+				return mipmaps;
+			}
+		}
+
+		public int ImageType
+		{
+			get
+			{
+				return imagetype;
+			}
+		}
+
+		public string ImageTypeString
+		{
+			get
+			{
+				switch(imagetype)
+				{
+					case 0: return "TGA";
+					case 8: return "DXT1 DDS";
+					case 10: return "DXT3 DDS";
+					case 11: return "DXT5 DDS";
+					default: return "Unknown";
+				}
+			}
+		}
+
+		public override string GetDisplayDetails()
+		{
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				"Image Type:\t"+ImageTypeString+Environment.NewLine+
+				"Width:\t\t"+width+Environment.NewLine+
+				"Height:\t\t"+height+Environment.NewLine+
+				(ImageType!=0?"Mip Maps:\t"+mipmaps:"Unknown:\t"+mipmaps);
+		}
+
+		public override int DataLength
+		{
+			get
+			{
+				return (imagetype == 0 && mipmaps==0)?12:16;
+			}
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			byte[] data = new byte[DataLength];
+			int pos = 0;
+
+			data[pos++] = (byte)imagetype;
+			data[pos++] = (byte)(imagetype>>8);
+			data[pos++] = (byte)(imagetype>>16);
+			data[pos++] = (byte)(imagetype>>24);
+			data[pos++] = (byte)width;
+			data[pos++] = (byte)(width>>8);
+			data[pos++] = (byte)(width>>16);
+			data[pos++] = (byte)(width>>24);
+			data[pos++] = (byte)width;
+			data[pos++] = (byte)(width>>8);
+			data[pos++] = (byte)(width>>16);
+			data[pos++] = (byte)(width>>24);
+
+			if (DataLength>12)
+			{
+				data[pos++] = (byte)imagetype;
+				data[pos++] = (byte)(imagetype>>8);
+				data[pos++] = (byte)(imagetype>>16);
+				data[pos++] = (byte)(imagetype>>24);
+			}
+
+			return data;
+		}
+
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataCHAN.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,246 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataCHAN.
+	/// </summary>
+	public class ChunkyDataCHAN : ChunkyData
+	{
+		public enum ChannelType{Texture, Specularity, Reflection, SelfIllum, Opacity, Unknown}
+		public enum ChannelMethod{Texture = 1, Add = 2, Blend = 3, None = 0}
+
+		private struct Coordinate
+		{
+			float x;
+			float y;
+
+			public Coordinate(float x_in, float y_in)
+			{
+				this.x = x_in;
+				this.y = y_in;
+			}
+
+			public float X
+			{
+				get { return x; }
+			}
+
+			public float Y
+			{
+				get { return y; }
+			}
+
+			public override string ToString()
+			{
+				return x+","+y;
+			}
+
+		}
+
+		int stringLength;
+		ChannelType channel;
+		ChannelMethod method;
+		string channelName;
+		byte[] colourMask;
+		int numCoords;
+		byte[] unknown, unknown2;
+		Coordinate[,] coords;
+
+
+		public ChunkyDataCHAN(int version_in, string name_in, byte[] innerData):base("CHAN", version_in, name_in)
+		{
+			stringLength = innerData[12]+(innerData[13]<<8)+(innerData[14]<<16)+(innerData[15]<<24);
+
+			colourMask = new byte[4];
+			colourMask[0] = innerData[8];
+			colourMask[1] = innerData[9];
+			colourMask[2] = innerData[10];
+			colourMask[3] = innerData[11];
+
+			if (innerData[4]==1)
+			{
+				method = ChannelMethod.Texture;
+			}
+			else if (innerData[4]==2)
+			{
+				method = ChannelMethod.Add;
+			}
+			else if (innerData[4]==3)
+			{
+				method = ChannelMethod.Blend;
+			}
+			else if (innerData[4]>3 || innerData[4] == 0)
+			{
+				method = ChannelMethod.None;
+			}
+			else 
+			{
+				throw new InvalidChunkValueException("Invalid value found for CHAN method", "Channel Method", innerData[4]);
+			}
+
+			channel = (ChannelType)innerData[0];
+			channelName = ByteArrayToTextString(innerData, 16, stringLength);
+			unknown = new byte[4];
+			unknown[0] = innerData[stringLength+16];
+			unknown[1] = innerData[stringLength+17];
+			unknown[2] = innerData[stringLength+18];
+			unknown[3] = innerData[stringLength+19];
+			int coordPos = stringLength+20;
+			numCoords = innerData[coordPos]+(innerData[coordPos+1]<<8)+(innerData[coordPos+2]<<16)+(innerData[coordPos+3]<<24);
+			unknown2 = new byte[4];
+			unknown2[0] = innerData[coordPos+4];
+			unknown2[1] = innerData[coordPos+5];
+			unknown2[2] = innerData[coordPos+6];
+			unknown2[3] = innerData[coordPos+7];
+
+			coords = new Coordinate[numCoords, 4];
+
+			int pos = coordPos+8;
+
+			for (int i = 0; i < numCoords && pos < innerData.Length; i++)
+			{
+				coords[i, 0] = new Coordinate(ByteArrayToSingle(innerData, pos), ByteArrayToSingle(innerData, pos+4));
+				coords[i, 1] = new Coordinate(ByteArrayToSingle(innerData, pos+8), ByteArrayToSingle(innerData, pos+12));
+				coords[i, 2] = new Coordinate(ByteArrayToSingle(innerData, pos+16), ByteArrayToSingle(innerData, pos+20));
+				coords[i, 3] = new Coordinate(ByteArrayToSingle(innerData, pos+24), ByteArrayToSingle(innerData, pos+28));
+				i++;
+				pos = coordPos+8+(i*32);
+			}
+		}
+
+		public ChannelType Channel
+		{
+			get{ return channel;}
+		}
+
+		public ChannelMethod Method
+		{
+			get
+			{
+				return method;
+			}
+		}
+
+		public string ChannelName
+		{
+			get{ return channelName; }
+			set
+			{
+				if (value!=null)
+				{
+					channelName = value;
+				}
+				else
+				{
+					channelName = "";
+				}
+			}
+		}
+		
+		public override string GetDisplayDetails()
+		{
+			string coordString = "";
+			
+			for (int i = 0; i<coords.GetLength(0); i++)
+			{
+				coordString+="Coordinates "+(i+1)+":\t"+coords[i,0].ToString()+" "+coords[i,1].ToString()+" "+coords[i,2].ToString()+" "+coords[i,3].ToString()+" "+Environment.NewLine;
+			}
+
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				"Channel:\t"+channel.ToString()+Environment.NewLine+
+				"Blend method:\t"+Method.ToString()+Environment.NewLine+
+				"Colour Mask(?):\t"+ByteArrayToString(colourMask)+Environment.NewLine+
+				"Name length:\t"+stringLength+Environment.NewLine+
+				"Name:\t\t"+channelName+Environment.NewLine+
+				"Channel used(?):"+(unknown[0]==1).ToString()+Environment.NewLine+
+				"Num Coords:\t"+numCoords+Environment.NewLine+
+				"Unknown:\t"+ByteArrayToString(unknown2)+Environment.NewLine+
+				coordString;
+		}
+
+		public override int DataLength
+		{
+			get
+			{
+				return 156+ChannelName.Length;
+			}
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			byte[] data = new byte[DataLength];
+			int pos = 0;
+			int temp = 0;
+	
+			temp = (int)channel;
+			data[pos++] = (byte)temp;
+			data[pos++] = (byte)(temp>>8);
+			data[pos++] = (byte)(temp>>16);
+			data[pos++] = (byte)(temp>>24);
+
+			temp = (int)Method;
+			if (temp>4)
+			{
+				temp = 0;
+			}
+			data[pos++] = (byte)temp;
+			data[pos++] = (byte)(temp>>8);
+			data[pos++] = (byte)(temp>>16);
+			data[pos++] = (byte)(temp>>24);
+
+			colourMask.CopyTo(data, pos);
+			pos+=4;
+
+			temp = channelName.Length;
+			data[pos++] = (byte)temp;
+			data[pos++] = (byte)(temp>>8);
+			data[pos++] = (byte)(temp>>16);
+			data[pos++] = (byte)(temp>>24);
+
+			System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
+			
+			enc.GetBytes(channelName).CopyTo(data,pos);
+			pos+= temp;
+
+			unknown.CopyTo(data, pos);		
+			pos+= 4;
+			
+			data[pos++] = (byte)numCoords;
+			data[pos++] = (byte)(numCoords>>8);
+			data[pos++] = (byte)(numCoords>>16);
+			data[pos++] = (byte)(numCoords>>24);
+
+			unknown2.CopyTo(data, pos);
+			pos+=4;
+
+			for (int i = 0; i<coords.GetLength(0); i++)
+			{
+				BitConverter.GetBytes(coords[i, 0].X).CopyTo(data, pos);
+				pos+=4;
+				BitConverter.GetBytes(coords[i, 0].Y).CopyTo(data, pos);
+				pos+=4;
+				BitConverter.GetBytes(coords[i, 1].X).CopyTo(data, pos);
+				pos+=4;
+				BitConverter.GetBytes(coords[i, 1].Y).CopyTo(data, pos);
+				pos+=4;
+				BitConverter.GetBytes(coords[i, 2].X).CopyTo(data, pos);
+				pos+=4;
+				BitConverter.GetBytes(coords[i, 2].Y).CopyTo(data, pos);
+				pos+=4;
+				BitConverter.GetBytes(coords[i, 3].X).CopyTo(data, pos);
+				pos+=4;
+				BitConverter.GetBytes(coords[i, 3].Y).CopyTo(data, pos);
+				pos+=4;
+			}			
+
+			return data;
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataDATA.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,48 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataDATA.
+	/// </summary>
+	public class ChunkyDataDATA : ChunkyData
+	{
+		private ChunkyDataATTR attr;
+		private byte[] data;
+
+		public ChunkyDataDATA(int version_in, string name_in, byte[] innerData_in):base("DATA", version_in, name_in)
+		{
+			data = innerData_in;
+		}
+
+		public ChunkyDataATTR Attributes{
+			get{ return attr; }
+			set{ attr = value; }
+		}
+
+		public override int DataLength
+		{
+			get
+			{
+				return data.Length;
+			}
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			return data;
+		}
+
+		public override string GetDisplayDetails()
+		{		
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				ByteArrayToString(GetDataBytes());
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataDATAIMAG.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,173 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataDATA.
+	/// </summary>
+	public class ChunkyDataDATAIMAG : ChunkyDataDATA
+	{
+		public ChunkyDataDATAIMAG(int version_in, string name_in, byte[] innerData_in):base(version_in, name_in, innerData_in)
+		{
+		}
+
+		private void SaveTGA(DirectoryInfo dir, string fileBaseName)
+		{
+			FileStream str = new FileStream(dir.FullName.TrimEnd(Path.DirectorySeparatorChar)+Path.DirectorySeparatorChar+fileBaseName+".tga", FileMode.Create);
+			BinaryWriter bw = new BinaryWriter(str);
+			bw.Write(TGA_Colour_Header_a);
+			bw.Write((ushort)Attributes.Width);
+			bw.Write((ushort)Attributes.Height);
+			bw.Write(TGA_Colour_Header_b);
+			bw.Write(base.GetDataBytes());
+			bw.Flush();
+			bw.Close();
+		}
+
+		public override bool Savable
+		{
+			get
+			{
+				return true;
+			}
+		}
+
+		public override void Save(DirectoryInfo dir, string fileBaseName)
+		{
+			if (Attributes.ImageType == 0)
+			{
+				this.SaveTGA(dir, fileBaseName);
+			}
+			else if (Attributes.ImageType == 8 || Attributes.ImageType == 10 || Attributes.ImageType == 11)
+			{
+				this.SaveDDS(dir, fileBaseName);
+			}
+			else
+			{
+				throw new InvalidOperationException("Unexpected image type for DATA chunk: "+Attributes.ImageType);
+			}
+		}
+
+		public static ChunkyDataDATA CreateFromTGA(int version, string name, byte[] tgaData)
+		{
+			//check image type code
+			if (tgaData[2]!=0x02)
+			{
+				throw new InvalidFileException("Base layer must be a valid 32-bit Targa image");
+			}
+
+			//check colour depth
+			if (tgaData[16]!=0x20)
+			{
+				throw new InvalidFileException("Base layer must be a valid 32-bit Targa image (pixel depth reads as "+tgaData[16].ToString()+"-bit)");
+			}
+
+			int width = tgaData[12]+(tgaData[13]<<8);
+			int height = tgaData[14]+(tgaData[15]<<8);
+			byte[] data = new byte[width*height*4]; //only take the correct number of bytes so that we don't include comments
+			int offset = 18+tgaData[0];
+						
+			for (int i = 0; i<data.Length; i++)
+			{
+				data[i] = tgaData[i+offset];
+			}
+
+			return new ChunkyDataDATAIMAG(version, name, data);
+		}
+
+		public static ChunkyDataDATA CreateFromDDS(int version, string name, byte[] ddsData)
+		{
+			//check image type code
+			if (ddsData[0]!=0x44 || ddsData[1]!=0x44 ||ddsData[2]!=0x53 || ddsData[3]!=0x20)
+			{
+				throw new InvalidFileException("Source image must be a valid DDS image");
+			}
+
+			//check colour depth
+			if (ddsData[84] != 0x44 || ddsData[85] != 0x58 || ddsData[86] !=0x54 || (ddsData[87] != 0x31 && ddsData[87] != 0x33 && ddsData[87] != 0x35))
+			{
+				throw new InvalidFileException("Source image must be a valid DXT1 , DXT3 or DXT5 DDS image");
+			}
+
+
+
+			byte[] data = new byte[ddsData.Length-128];
+						
+			int max = data.Length;
+			for (int i = 0; i<max; i++)
+			{
+				data[i] = ddsData[i+128];
+			}
+
+			return new ChunkyDataDATAIMAG(version, name, data);
+		}
+
+		private void SaveDDS(DirectoryInfo dir, string fileBaseName)//, int type)
+		{
+			if (Attributes == null)
+			{
+				throw new InvalidOperationException("DATA chunk must have a related ATTR chunk before it can be saved");
+			}
+
+			int mipmaps = (int)Math.Log(Attributes.Width, 2)+1;
+			int type = Attributes.ImageType;
+
+			FileStream str = new FileStream(dir.FullName.TrimEnd(Path.DirectorySeparatorChar)+Path.DirectorySeparatorChar+fileBaseName+".dds", FileMode.Create);
+			BinaryWriter bw = new BinaryWriter(str);
+			bw.Write(DTX_Header_a);
+			bw.Write(Attributes.Height);
+			bw.Write(Attributes.Width);
+
+			if (type == 0x8)
+			{
+				bw.Write(DataLength);
+			}
+			else
+			{
+				bw.Write(Attributes.Width*Attributes.Height);
+			}
+
+			bw.Write(new byte[]{0x00, 0x00, 0x00, 0x00});//volume depth - always 0
+			bw.Write(mipmaps);
+			
+			if (type == 0x8)
+			{
+				bw.Write(DXT1_Header_b);
+			}
+			else if (type == 0xA)
+			{
+				bw.Write(DXT3_Header_b);
+			}
+			else
+			{
+				bw.Write(DXT5_Header_b);
+			}
+
+			bw.Write(base.GetDataBytes());
+			bw.Flush();
+			bw.Close();
+		}
+
+		/*
+		public void SaveDDS(DirectoryInfo dir, string fileBaseName, int width, int height, byte id)
+		{
+			FileStream str = new FileStream(dir.FullName.TrimEnd(Path.DirectorySeparatorChar)+Path.DirectorySeparatorChar+fileBaseName+".dds", FileMode.Create);
+			BinaryWriter bw = new BinaryWriter(str);
+			bw.Write(DTX1_Header_a);
+			bw.Write(width);
+			bw.Write(height);
+			bw.Write(DataLength);
+			bw.Write(new byte[]{0x00, 0x00, 0x00, 0x00});//volume depth - always 0
+			bw.Write((int)Math.Log(width, 2)+1);//calculate the number of MIP Maps
+			bw.Write(DXT1_Header_b);
+			bw.Write(innerData);
+			bw.Flush();
+			bw.Close();
+		}*/
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataFBIF.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,99 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataDATA.
+	/// </summary>
+	public class ChunkyDataFBIF : ChunkyData
+	{
+		string pluginName, username, burntime;
+		int pluginVer;
+
+		public ChunkyDataFBIF(int version_in, string name_in, byte[] innerData):base("FBIF", version_in, name_in)
+		{
+			int pos = 0;
+			int length = innerData[0]+(innerData[1]<<8)+(innerData[2]<<16)+(innerData[3]<<24);
+			pos = 4;
+			pluginName = ByteArrayToTextString(innerData, 4, length);
+			pos += length;
+			pluginVer = innerData[pos]+(innerData[pos+1]<<8)+(innerData[pos+2]<<16)+(innerData[pos+3]<<24);
+			pos+=4;
+			length = innerData[pos]+(innerData[pos+1]<<8)+(innerData[pos+2]<<16)+(innerData[pos+3]<<24);
+			pos+=4;
+			username = ByteArrayToTextString(innerData, pos, length);
+			pos += length;
+			length = innerData[pos]+(innerData[pos+1]<<8)+(innerData[pos+2]<<16)+(innerData[pos+3]<<24);
+			pos+=4;
+			burntime = ByteArrayToTextString(innerData, pos, length);
+		}
+
+		public override string GetDisplayDetails()
+		{		
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				"Plugin name:\t\t"+pluginName+Environment.NewLine+
+				"Plugin version:\t\t"+pluginVer+Environment.NewLine+
+				"Username:\t\t"+username+Environment.NewLine+
+				"Burn time:\t\t"+burntime;
+		}
+
+		public override int DataLength
+		{
+			get
+			{
+				return 16+pluginName.Length+username.Length+burntime.Length;
+			}
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			byte[] data = new byte[DataLength];
+			int pos = 0;
+			int temp;
+
+			temp = pluginName.Length;
+			data[pos++] = (byte)temp;
+			data[pos++] = (byte)(temp>>8);
+			data[pos++] = (byte)(temp>>16);
+			data[pos++] = (byte)(temp>>24);
+
+			System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
+			
+			enc.GetBytes(pluginName).CopyTo(data,pos);
+			pos += temp;
+
+			data[pos++] = (byte)pluginVer;
+			data[pos++] = (byte)(pluginVer>>8);
+			data[pos++] = (byte)(pluginVer>>16);
+			data[pos++] = (byte)(pluginVer>>24);
+
+			temp = username.Length;
+			data[pos++] = (byte)temp;
+			data[pos++] = (byte)(temp>>8);
+			data[pos++] = (byte)(temp>>16);
+			data[pos++] = (byte)(temp>>24);
+			
+			enc.GetBytes(username).CopyTo(data,pos);
+			pos += temp;
+
+			temp = burntime.Length;
+			data[pos++] = (byte)temp;
+			data[pos++] = (byte)(temp>>8);
+			data[pos++] = (byte)(temp>>16);
+			data[pos++] = (byte)(temp>>24);
+			
+			enc.GetBytes(burntime).CopyTo(data,pos);
+			pos += temp;
+
+			return data;
+		}
+
+        
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataHEAD.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,83 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataHEAD.
+	/// </summary>
+	public class ChunkyDataHEAD :ChunkyData
+	{
+		int imageType = 0;
+		int numImages = 0;
+
+		public ChunkyDataHEAD(int version_in, string name_in, byte[] innerData_in):base("HEAD", version_in, name_in)
+		{
+			imageType = innerData_in[0]+(innerData_in[1]<<8)+(innerData_in[2]<<16)+(innerData_in[3]<<24);
+			numImages = innerData_in[4]+(innerData_in[5]<<8)+(innerData_in[6]<<16)+(innerData_in[7]<<24);
+		}
+
+		public FileFormats.ImgType ImageType
+		{
+			get
+			{
+				if (imageType==5)
+				{
+					return FileFormats.ImgType.DXT1DDS;
+				}
+				else if (imageType == 6)
+				{
+					return FileFormats.ImgType.DXT3DDS;
+				}
+				else if (imageType == 7)
+				{
+					return FileFormats.ImgType.DXT5DDS;
+				}
+				else if (imageType == 0 || imageType == 2)
+				{
+					return FileFormats.ImgType.TGA;
+				}
+				else
+				{
+					return FileFormats.ImgType.Unknown;
+				}
+			}
+		}
+
+		public override string GetDisplayDetails()
+		{		
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				"Image Type:\t\t"+ImageType.ToString()+Environment.NewLine+
+				"Number Images(?):\t"+numImages;
+		}
+
+		public override int DataLength
+		{
+			get
+			{
+				return 8;
+			}
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			byte[] data = new byte[8];
+			int pos = 0;
+
+			data[pos++] = (byte)imageType;
+			data[pos++] = (byte)(imageType>>8);
+			data[pos++] = (byte)(imageType>>16);
+			data[pos++] = (byte)(imageType>>24);
+			data[pos++] = (byte)numImages;
+			data[pos++] = (byte)(numImages>>8);
+			data[pos++] = (byte)(numImages>>16);
+			data[pos++] = (byte)(numImages>>24);
+			return data;
+		}
+
+
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataINFO.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,15 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyChunkINFO.
+	/// </summary>
+	public abstract class ChunkyDataINFO : ChunkyData
+	{
+		public ChunkyDataINFO(int version_in, string name_in):base("INFO", version_in, name_in){}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataINFOGeneric.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,40 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataINFOGeneric.
+	/// </summary>
+	public class ChunkyDataINFOGeneric : ChunkyDataINFO
+	{
+		byte[] data;
+
+		public ChunkyDataINFOGeneric(int version_in, string name_in, byte[] innerData_in):base(version_in, name_in)
+		{
+			data = innerData_in;
+		}
+
+		public override int DataLength
+		{
+			get
+			{
+				return data.Length;
+			}
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			return data;
+		}
+
+		public override string GetDisplayDetails()
+		{		
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				ByteArrayToString(GetDataBytes());
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataINFOSHDR.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,88 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataINFOSHDR.
+	/// </summary>
+	public class ChunkyDataINFOSHDR :ChunkyDataINFO
+	{
+		int numChannels = 0;
+		byte[] unknown1 = new byte[4];
+		byte[] unknown2 = new byte[4];
+		byte[] unknown3 = new byte[5];
+
+		public ChunkyDataINFOSHDR(int version_in, string name_in, byte[] innerData_in):base(version_in, name_in)
+		{
+			numChannels = innerData_in[0]+(innerData_in[1]<<8)+(innerData_in[2]<<16)+(innerData_in[3]<<24);
+			unknown1[0] = innerData_in[4];
+			unknown1[1] = innerData_in[5];
+			unknown1[2] = innerData_in[6];
+			unknown1[3] = innerData_in[7];
+			unknown2[0] = innerData_in[8];
+			unknown2[1] = innerData_in[9];
+			unknown2[2] = innerData_in[10];
+			unknown2[3] = innerData_in[11];
+			unknown3[0] = innerData_in[12];
+			unknown3[1] = innerData_in[13];
+			unknown3[2] = innerData_in[14];
+			unknown3[3] = innerData_in[15];
+			unknown3[4] = innerData_in[16];
+		}
+
+		public bool AdditionalShaders
+		{
+			get
+			{
+				return (unknown2[0]==0xcd);
+			}
+		}
+
+		public override string GetDisplayDetails()
+		{		
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				"Channels:\t"+numChannels+Environment.NewLine+
+				"Unknown 1:\t"+ChunkyChunk.ByteArrayToString(unknown1)+Environment.NewLine+
+				//"Additional Shaders(?):\t"+AdditionalShaders+Environment.NewLine+
+				"Unknown 2:\t"+ChunkyChunk.ByteArrayToString(unknown2)+Environment.NewLine+
+				"Unknown 3:\t"+ChunkyChunk.ByteArrayToString(unknown3);
+		}
+
+		public override int DataLength
+		{
+			get
+			{
+				return 17;
+			}
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			byte[] data = new byte[17];
+			data[0] = (byte)numChannels;
+			data[1] = (byte)(numChannels>>8);
+			data[2] = (byte)(numChannels>>16);
+			data[3] = (byte)(numChannels>>24);
+			data[4] = unknown1[0];
+			data[5] = unknown1[1];
+			data[6] = unknown1[2];
+			data[7] = unknown1[3];
+			data[8] = unknown2[0];
+			data[9] = unknown2[1];
+			data[10] = unknown2[2];
+			data[11] = unknown2[3];
+			data[12] = unknown3[0];
+			data[13] = unknown3[1];
+			data[14] = unknown3[2];
+			data[15] = unknown3[3];
+			data[16] = unknown3[4];
+			return data;
+		}
+
+
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataINFOTPAT.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,68 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataINFOTPAT.
+	/// </summary>
+	public class ChunkyDataINFOTPAT : ChunkyDataINFO
+	{
+		int width = 0;
+		int height = 0;
+
+		public ChunkyDataINFOTPAT(int version_in, string name_in, byte[] innerData_in):base(version_in, name_in)
+		{
+			width = innerData_in[0]+(innerData_in[1]<<8)+(innerData_in[2]<<16)+(innerData_in[3]<<24);
+			height= innerData_in[4]+(innerData_in[5]<<8)+(innerData_in[6]<<16)+(innerData_in[7]<<24);
+		}
+
+		public int Width
+		{
+			get
+			{
+				return width;
+			}
+		}
+
+		public int Height
+		{
+			get
+			{
+				return height;
+			}
+		}
+
+		public override string GetDisplayDetails()
+		{		
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				"Width:\t\t"+width+Environment.NewLine+
+				"Height:\t\t"+height;
+		}
+
+		public override int DataLength
+		{
+			get
+			{
+				return 8;
+			}
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			byte[] data = new byte[8];
+			data[0] = (byte)width;
+			data[1] = (byte)(width>>8);
+			data[2] = (byte)(width>>16);
+			data[3] = (byte)(width>>24);
+			data[4] = (byte)height;
+			data[5] = (byte)(height>>8);
+			data[6] = (byte)(height>>16);
+			data[7] = (byte)(height>>24);
+			return data;
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataINFOTXTR.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,105 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataINFOTXTR.
+	/// </summary>
+	public class ChunkyDataINFOTXTR :ChunkyDataINFO
+	{
+		int imageType = 0;
+		int width = 0;
+		int height = 0;
+		int images = 0;
+
+		public ChunkyDataINFOTXTR(int version_in, string name_in, byte[] innerData_in):base(version_in, name_in)
+		{
+			imageType = innerData_in[0]+(innerData_in[1]<<8)+(innerData_in[2]<<16)+(innerData_in[3]<<24);
+			width = innerData_in[4]+(innerData_in[5]<<8)+(innerData_in[6]<<16)+(innerData_in[7]<<24);
+			height = innerData_in[8]+(innerData_in[9]<<8)+(innerData_in[10]<<16)+(innerData_in[11]<<24);
+			images = innerData_in[12]+(innerData_in[13]<<8)+(innerData_in[14]<<16)+(innerData_in[15]<<24);
+		}
+
+		public FileFormats.ImgType ImageType
+		{
+			get
+			{
+				if (imageType==5)
+				{
+					return FileFormats.ImgType.DXT1DDS;
+				}
+				else if (imageType == 7)
+				{
+					return FileFormats.ImgType.DXT1DDS;
+				}
+				else if (imageType == 0)
+				{
+					return FileFormats.ImgType.TGA;
+				}
+				else
+				{
+					return FileFormats.ImgType.Unknown;
+				}
+			}
+		}
+
+		public int Width
+		{
+			get
+			{
+				return width;
+			}
+		}
+
+		public int Height
+		{
+			get
+			{
+				return height;
+			}
+		}
+
+		public override string GetDisplayDetails()
+		{		
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				"Image Type:\t"+this.ImageType.ToString()+Environment.NewLine+
+				"Width:\t\t"+width+Environment.NewLine+
+				"Height:\t\t"+height+Environment.NewLine+
+				"Number images(?):\t"+images;
+		}
+
+		public override int DataLength
+		{
+			get
+			{
+				return 16;
+			}
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			byte[] data = new byte[16];
+			data[0] = (byte)imageType;
+			data[1] = (byte)(imageType>>8);
+			data[2] = (byte)(imageType>>16);
+			data[3] = (byte)(imageType>>24);
+			data[4] = (byte)width;
+			data[5] = (byte)(width>>8);
+			data[6] = (byte)(width>>16);
+			data[7] = (byte)(width>>24);
+			data[8] = (byte)height;
+			data[9] = (byte)(height>>8);
+			data[10] = (byte)(height>>16);
+			data[11] = (byte)(height>>24);
+			data[12] = (byte)images;
+			data[13] = (byte)(images>>8);
+			data[14] = (byte)(images>>16);
+			data[15] = (byte)(images>>24);
+			return data;
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataLayer.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,25 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataLayer.
+	/// </summary>
+	public abstract class ChunkyDataLayer : ChunkyData
+	{
+		private ChunkyDataINFOTPAT attr;
+
+		public ChunkyDataLayer(string id, int version_in, string name_in):base(id, version_in, name_in)
+		{
+		}
+
+		public ChunkyDataINFOTPAT Info
+		{
+			get{ return attr; }
+			set{ attr = value; }
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataPTBD.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,227 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using IBBoard.Graphics;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataPTBD.
+	/// </summary>
+	public class ChunkyDataPTBD : ChunkyDataLayer
+	{
+		const float size_x = 64;
+		const float size_y = 64;
+		float x;
+		float y;
+
+		public ChunkyDataPTBD(int version_in, string name_in, byte[] innerData):base("PTBD", version_in, name_in)
+		{
+			x = BitConverter.ToSingle(innerData,0);
+			y = BitConverter.ToSingle(innerData,4);
+		}
+
+		public float Pos_x
+		{
+			get{ return x; }
+		}
+
+		public float Pos_y
+		{
+			get{ return y; }
+		}
+
+		public float Height
+		{
+			get{ return size_y; }
+		}
+
+		public float Width
+		{
+			get{ return size_x; }
+		}
+
+		public override void Save(DirectoryInfo dir, string fileBaseName)
+		{
+			int width = Info.Width;
+			int height = Info.Height;
+
+			float right = x+size_x;
+			float top = y+size_y;
+
+			if (((int)right)>width || ((int)top)>height)
+			{
+				throw new InvalidChunkException("Badge layer contains an invalid badge position");
+			}
+
+			//create the TGA
+			int fileLength = width*height;
+			byte [] file = new byte[fileLength];
+
+			int pos = 0;
+
+			for (int i = 0; i<height; i++)
+			{
+				for (int j = 0; j<width; j++)
+				{
+					if (x<=j && j<right && y<=i && i<top)
+					{
+						file[pos] = byte.MaxValue;
+					}
+					else
+					{
+						file[pos] = byte.MinValue;
+					}
+
+					pos++;
+				}
+			}
+
+			//save the TGA
+			FileStream str = new FileStream(dir.FullName.TrimEnd(Path.DirectorySeparatorChar)+Path.DirectorySeparatorChar+fileBaseName+"_Badge.tga", FileMode.Create);
+			BinaryWriter bw = new BinaryWriter(str);
+			bw.Write(TGA_Greyscale_Header_a);				
+			bw.Write((ushort)width);
+			bw.Write((ushort)height);
+			bw.Write(TGA_Greyscale_Header_b);
+			bw.Write(file);
+			bw.Flush();
+			bw.Close();
+		}
+
+		public static ChunkyDataPTBD CreateFromTGA(int version, string name, byte[] tgaData)
+		{
+			//check image type code
+			if (tgaData[2]!=0x03)
+			{
+				bool worked = false;
+
+				if (tgaData[1] == 0x01 && tgaData[2] == 0x01)
+				{
+					tgaData = ImageConverter.ColourMapToGreyscale(tgaData);
+					worked = true;
+				}
+
+
+				if (!worked)
+				{
+					ImageConverter.MapEncStruct format = ImageConverter.getMapEncStruct(tgaData[2]);
+					throw new InvalidFileException("_badge.tga must be an unencoded unmapped monochrome Targa image.\r\n"+
+						"  Image type: "+format.formatType+"\r\n"+
+						"  Image encoded: "+((format.isEncoded)?"yes":"no")+"\r\n"+
+						"  Colour mapped: "+((format.isMapped)?"yes":"no"));
+				}
+			}
+
+			//check colour depth
+			if (tgaData[16]!=0x08)
+			{
+				throw new InvalidFileException("_badge.tga must be an 8-bit Targa image. Image was "+tgaData[16]+"-bit.");
+			}
+
+			float pos_x = float.MinValue;
+			float pos_y = float.MinValue;
+			int width = (int)tgaData[12]+(((int)tgaData[13])<<8);
+			int height = (int)tgaData[14]+(((int)tgaData[15])<<8);
+			int currPos = 0;
+			int size_x_int = (int)size_x;
+
+			for (currPos = 18; currPos<tgaData.Length; currPos+=size_x_int)
+			{
+				//try to find our badge;
+				if (tgaData[currPos]==byte.MaxValue)
+				{
+					pos_y = (float)((currPos-18)/width);
+					pos_x = (float)(currPos-18-(pos_y*width));
+					break;
+				}
+			}
+
+			if (pos_y!=float.MinValue)
+			{
+				int maxPossibleEnd = currPos+width;
+				int extra = 0;
+
+				while (currPos<maxPossibleEnd && tgaData[currPos]==byte.MaxValue)
+				{
+					currPos++;
+					extra++;
+				}
+
+				//check where the left hand side should start
+				if (pos_x>0 && (tgaData[currPos-size_x_int]!=byte.MaxValue || tgaData[currPos-size_x_int-1]!=byte.MinValue))
+				{
+					throw new InvalidFileException("Badge is is not the correct width or is not a solid white square");
+				}
+				else
+				{
+					pos_x = pos_x+extra-size_x;
+				}
+
+				//and check for the top - not all of the block, just assume a left and bottom side are OK
+				int aboveTop = currPos-size_x_int+(width*(int)size_y);
+				for (int i = currPos-size_x_int; i<=aboveTop && i<tgaData.Length; i+= width)
+				{
+					if (tgaData[i]!=byte.MaxValue && i!=aboveTop)
+					{
+						throw new InvalidFileException("Badge area is too small. Badge must be 64px by 64px");
+					}
+				}
+
+				//if we got here, it's all OK
+
+				byte[] data = new byte[16];
+			
+				BitConverter.GetBytes(pos_x).CopyTo(data, 0);
+				BitConverter.GetBytes(pos_y).CopyTo(data, 4);
+				BitConverter.GetBytes(size_x).CopyTo(data, 8);
+				BitConverter.GetBytes(size_y).CopyTo(data, 12);
+			
+				return new ChunkyDataPTBD(version, name, data);
+			}
+			else
+			{
+				return null;
+			}
+		}
+
+		public override bool Savable
+		{
+			get
+			{
+				return true;
+			}
+		}
+
+		public override int DataLength
+		{
+			get
+			{
+				return 16;
+			}
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			byte[] data = new byte[16];
+			BitConverter.GetBytes(x).CopyTo(data, 0);
+			BitConverter.GetBytes(y).CopyTo(data, 4);
+			BitConverter.GetBytes(size_x).CopyTo(data, 8);
+			BitConverter.GetBytes(size_y).CopyTo(data, 12);
+			return data;
+		}
+
+		public override string GetDisplayDetails()
+		{
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				"X:\t\t"+x+Environment.NewLine+
+				"Y:\t\t"+y+Environment.NewLine+
+				"Width:\t\t"+size_x+Environment.NewLine+
+				"Height:\t\t"+size_y;
+		}
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataPTBN.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,240 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using IBBoard.Graphics;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataPTBN.
+	/// </summary>
+	public class ChunkyDataPTBN : ChunkyDataLayer
+	{
+		private static readonly byte[] PTBN_TGA_Header = new byte[]{0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x08, 0x08};
+
+		const float size_x = 64;
+		const float size_y = 96;
+		float x;
+		float y;
+
+		public ChunkyDataPTBN(int version_in, string name_in, byte[] innerData):base("PTBN", version_in, name_in)
+		{
+			x = BitConverter.ToSingle(innerData,0);
+			y = BitConverter.ToSingle(innerData,4);
+		}
+
+		public float Pos_x
+		{
+			get{ return x; }
+		}
+
+		public float Pos_y
+		{
+			get{ return y; }
+		}
+
+		public float Height
+		{
+			get{ return size_y; }
+		}
+
+		public float Width
+		{
+			get{ return size_x; }
+		}
+
+		/*public override bool Save(string path)
+		{
+			string name = this.ParentFile.Name.Substring(0, this.ParentFile.Name.LastIndexOf('.'));
+			return Save(path, name);
+		}
+
+		public bool Save(string path, string name){
+			this.Save(new DirectoryInfo(path), name);
+			return true;
+		}*/
+
+		public override void Save(DirectoryInfo dir, string fileBaseName)
+		{
+			int width = Info.Width;
+			int height = Info.Height;
+
+			float right = x+size_x;
+			float top = y+size_y;
+
+			if (((int)right)>width || ((int)top)>height)
+			{
+				throw new InvalidChunkException("Banner layer contains an invalid banner position");
+			}
+
+			//create the TGA
+			int fileLength = width*height;
+			byte [] file = new byte[fileLength];
+
+			int pos = 0;
+
+			for (int i = 0; i<height; i++)
+			{
+				for (int j = 0; j<width; j++)
+				{
+					if (x<=j && j<right && y<=i && i<top)
+					{
+						file[pos] = byte.MaxValue;
+					}
+					else
+					{
+						file[pos] = byte.MinValue;
+					}
+
+					pos++;
+				}
+			}
+
+			//save the TGA
+			FileStream str = new FileStream(dir.FullName.TrimEnd(Path.DirectorySeparatorChar)+Path.DirectorySeparatorChar+fileBaseName+"_Banner.tga", FileMode.Create);
+			BinaryWriter bw = new BinaryWriter(str);
+			bw.Write(TGA_Greyscale_Header_a);				
+			bw.Write((ushort)width);
+			bw.Write((ushort)height);
+			bw.Write(TGA_Greyscale_Header_b);
+			bw.Write(file);
+			bw.Flush();
+			bw.Close();
+		}
+
+		public static ChunkyDataPTBN CreateFromTGA(int version, string name, byte[] tgaData)
+		{
+			//check image type code
+			if (tgaData[2]!=0x03)
+			{
+				bool worked = false;
+
+				if (tgaData[1] == 0x01 && tgaData[2] == 0x01)
+				{
+					tgaData = ImageConverter.ColourMapToGreyscale(tgaData);
+					worked = true;
+				}
+
+
+				if (!worked)
+				{
+					ImageConverter.MapEncStruct format = ImageConverter.getMapEncStruct(tgaData[2]);
+					throw new InvalidFileException("_banner.tga must be an unencoded unmapped monochrome Targa image.\r\n"+
+						"  Image type: "+format.formatType+"\r\n"+
+						"  Image encoded: "+((format.isEncoded)?"yes":"no")+"\r\n"+
+						"  Colour mapped: "+((format.isMapped)?"yes":"no"));
+				}
+			}
+
+			//check colour depth
+			if (tgaData[16]!=0x08)
+			{
+				throw new InvalidFileException("_banner.tga must be an 8-bit Targa image. Image was "+tgaData[16]+"-bit.");
+			}
+
+			float pos_x = float.MinValue;
+			float pos_y = float.MinValue;
+			int width = (int)tgaData[12]+(((int)tgaData[13])<<8);
+			int height = (int)tgaData[14]+(((int)tgaData[15])<<8);
+			int currPos = 0;
+			int size_x_int = (int)size_x;
+
+			for (currPos = 18; currPos<tgaData.Length; currPos+=size_x_int)
+			{
+				//try to find out badge;
+				if (tgaData[currPos]==byte.MaxValue)
+				{
+					pos_y = (float)((currPos-18)/width);
+					pos_x = (float)(currPos-18-(pos_y*height));
+					break;
+				}
+			}
+
+			if (pos_y!=float.MinValue)
+			{
+				int maxPossibleEnd = currPos+width;
+				int extra = 0;
+
+				while (currPos<maxPossibleEnd && tgaData[currPos]==byte.MaxValue)
+				{
+					currPos++;
+					extra++;
+				}
+
+				//check where the left hand side should start
+				if (pos_x>0 && (tgaData[currPos-size_x_int]!=byte.MaxValue || tgaData[currPos-size_x_int-1]!=byte.MinValue))
+				{
+					throw new InvalidFileException("Banner is positioned beyond the edge of the texture");
+				}
+				else
+				{
+					pos_x = pos_x+extra-size_x;
+				}
+
+				//and check for the top - not all of the block, just assume a left and bottom side are OK
+				int aboveTop = currPos-size_x_int+(width*(int)size_y);
+				for (int i = currPos-size_x_int; i<=aboveTop && i<tgaData.Length; i+= width)
+				{
+					if (tgaData[i]!=byte.MaxValue && i!=aboveTop)
+					{
+						throw new InvalidFileException("Banner area is too small. Banner must be 64px by 96px");
+					}
+				}
+
+				//if we got here, it's all OK
+
+				byte[] data = new byte[16];
+			
+				BitConverter.GetBytes(pos_x).CopyTo(data, 0);
+				BitConverter.GetBytes(pos_y).CopyTo(data, 4);
+				BitConverter.GetBytes((float)size_x).CopyTo(data, 8);
+				BitConverter.GetBytes((float)size_y).CopyTo(data, 12);
+			
+				return new ChunkyDataPTBN(version, name, data);
+			}
+			else
+			{
+				return null;
+			}
+		}
+
+		public override bool Savable
+		{
+			get
+			{
+				return true;
+			}
+		}
+		
+		public override int DataLength
+		{
+			get
+			{
+				return 16;
+			}
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			byte[] data = new byte[16];
+			BitConverter.GetBytes(x).CopyTo(data, 0);
+			BitConverter.GetBytes(y).CopyTo(data, 4);
+			BitConverter.GetBytes(size_x).CopyTo(data, 8);
+			BitConverter.GetBytes(size_y).CopyTo(data, 12);
+			return data;
+		}
+
+		public override string GetDisplayDetails()
+		{
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				"Pos X:\t\t"+x+Environment.NewLine+
+				"Pos Y:\t\t"+y+Environment.NewLine+
+				"Width:\t\t"+size_x+Environment.NewLine+
+				"Height:\t\t"+size_y;
+		}
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataPTLD.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,166 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using System.Collections;
+using IBBoard.Graphics;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	public enum PTLD_Layers {Primary = 0, Secondary = 1, Trim = 2, Weapon = 3, Eyes = 4, Dirt = 5}
+
+	/// <summary>
+	/// Summary description for ChunkyDataPTLD
+	/// </summary>
+	public class ChunkyDataPTLD : ChunkyDataLayer
+	{
+		private PTLD_Layers layerType;
+		byte[] image;
+
+		public ChunkyDataPTLD(int version_in, string name_in, byte[] innerData_in):base("PTLD", version_in, name_in)
+		{
+			layerType = (PTLD_Layers)(int)innerData_in[0];
+			int layerSize = (innerData_in[4])+(innerData_in[5]<<8)+(innerData_in[6]<<16)+(innerData_in[7]<<24);
+			image = new byte[layerSize];
+
+			for (int i = 0; i<layerSize; i++)
+			{
+				image[i] = innerData_in[i+8];
+			}
+		}
+
+		public override void Save(DirectoryInfo dir, string fileBaseName)
+		{
+			FileStream str = new FileStream(dir.FullName.TrimEnd(Path.DirectorySeparatorChar)+Path.DirectorySeparatorChar+fileBaseName+"_"+layerType.ToString()+".tga", FileMode.Create);
+			BinaryWriter bw = new BinaryWriter(str);
+			bw.Write(TGA_Greyscale_Header_a);			
+			bw.Write((ushort)Info.Width);
+			bw.Write((ushort)Info.Height);
+			bw.Write(TGA_Greyscale_Header_b);
+			bw.Write(image);
+			bw.Flush();
+			bw.Close();
+		}
+
+		public PTLD_Layers Layer
+		{
+			get{ return layerType; }
+		}
+
+		public int LayerSize
+		{
+			get{ return image.Length; }
+		}
+
+		public byte[] GetColourBytes()
+		{
+			return image;
+		}
+
+		public static ChunkyDataPTLD CreateFromTGA(PTLD_Layers layer_in, int version, string name, byte[] tgaData)
+		{
+			//check image type code
+			if (tgaData[2]!=0x03)
+			{
+				bool worked = false;
+
+				if (tgaData[1] == 0x01 && tgaData[2] == 0x01)
+				{
+					tgaData = ImageConverter.ColourMapToGreyscale(tgaData);
+					worked = true;
+				}
+
+
+				if (!worked)
+				{
+					ImageConverter.MapEncStruct format = ImageConverter.getMapEncStruct(tgaData[2]);
+					throw new InvalidFileException("_"+layer_in.ToString()+".tga must be an unencoded unmapped monochrome Targa image.\r\n"+
+						"  Image type: "+format.formatType+"\r\n"+
+						"  Image encoded: "+((format.isEncoded)?"yes":"no")+"\r\n"+
+						"  Colour mapped: "+((format.isMapped)?"yes":"no"));
+				}
+			}
+
+			//check colour depth
+			if (tgaData[16]!=0x08)
+			{
+				throw new InvalidFileException("_"+layer_in.ToString()+".tga must be an 8-bit Targa image. Image was "+tgaData[16]+"-bit.");
+			}
+
+			int width = tgaData[12]+(tgaData[13]<<8);
+			int height = tgaData[14]+(tgaData[15]<<8);
+			byte[] data = new byte[width*height+8]; //only take the correct number of bytes so that we don't include comments
+			
+			int layerDataLength = data.Length-8; 
+			int layer = (int)layer_in;
+			data[0] = (byte)(layer);
+			data[1] = (byte)(layer >> 8);
+			data[2] = (byte)(layer >> 16);
+			data[3] = (byte)(layer >> 24);
+			data[4] = (byte)layerDataLength;
+			data[5] = (byte)(layerDataLength>>8);
+			data[6] = (byte)(layerDataLength>>16);
+			data[7] = (byte)(layerDataLength>>24);
+			
+			int offset = 10+tgaData[0];//should be 18, but we're starting at i=8 so remove 8 here as well
+			bool nonBlack = false; //boolean to check whether they actually included any data in the layer
+
+			for (int i = 8; i<data.Length; i++)
+			{
+				data[i] = tgaData[i+offset];//take in to account any possible image ID
+
+				if (data[i]>5)
+				{
+					nonBlack = true;
+				}
+			}
+
+			//make sure we always return a dirt layer, even if they made it all black (all teamcolourable)
+			if (nonBlack || layer_in == PTLD_Layers.Dirt)
+			{
+				return new ChunkyDataPTLD(version, name, data);
+			}
+			else
+			{
+				return null;
+			}
+		}
+
+		public override bool Savable
+		{
+			get
+			{
+				return true;
+			}
+		}
+
+		public override string GetDisplayDetails()
+		{
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				"Layer:\t\t"+this.Layer+Environment.NewLine+
+				"Layer size:\t"+this.LayerSize+Environment.NewLine+
+				"Image data:\t"+Environment.NewLine+
+				ByteArrayToString(image, 8);
+		}
+		
+		public override int DataLength
+		{
+			get
+			{
+				return image.Length+8;
+			}
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			byte[] data = new byte[DataLength];
+			BitConverter.GetBytes((int)layerType).CopyTo(data, 0);
+			BitConverter.GetBytes(image.Length).CopyTo(data, 4);
+			image.CopyTo(data, 8);
+			return data;
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataSSHR.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,66 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataDATA.
+	/// </summary>
+	public class ChunkyDataSSHR : ChunkyData
+	{
+		string filepath;
+
+		public ChunkyDataSSHR(int version_in, string name_in, byte[] innerData_in):base("SSHR", version_in, name_in)
+		{
+			filepath = ByteArrayToTextString(innerData_in, 4);
+		}
+
+		public string ShaderPath
+		{
+			get{ return filepath; }
+			set
+			{
+				if (value!=null)
+				{
+					filepath = value;
+				}
+				else
+				{
+					filepath = "";
+				}
+			}
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			byte[] bytes = new byte[4+filepath.Length];
+			bytes[0] = (byte)filepath.Length;
+			bytes[1] = (byte)(filepath.Length>>8);
+			bytes[2] = (byte)(filepath.Length>>16);
+			bytes[3] = (byte)(filepath.Length>>24);
+			System.Text.ASCIIEncoding.ASCII.GetBytes(filepath).CopyTo(bytes, 4);
+			return bytes;
+		}
+
+		public override int DataLength
+		{
+			get
+			{
+				return filepath.Length+4;
+			}
+		}
+
+
+		
+		public override string GetDisplayDetails()
+		{
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				"Shader path:\t"+filepath;
+		}
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyDataUnknown.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,36 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyDataUnknown.
+	/// </summary>
+	public class ChunkyDataUnknown : ChunkyData
+	{
+		byte[] innerData;
+		public ChunkyDataUnknown(string id, int version_in, string name_in, byte[] innerData_in):base(id, version_in, name_in)
+		{
+			innerData = innerData_in;
+		}
+
+		public override byte[] GetDataBytes()
+		{
+			return innerData;
+		}
+
+		public override int DataLength
+		{
+			get { return innerData.Length; }
+		}
+
+		public override string GetDisplayDetails()
+		{		
+			return base.GetBaseDisplayDetails()+Environment.NewLine+
+				"------------"+Environment.NewLine+
+				ByteArrayToString(GetDataBytes());
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyFolder.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,203 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using System.Text;
+using IBBoard.Relic.RelicTools.Collections;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyFolder.
+	/// </summary>
+	public class ChunkyFolder : ChunkyChunk
+	{
+		ChunkyCollection children;
+
+		public ChunkyFolder(string ID_in, int version_in, string name_in, byte[] innerData):base(ChunkyChunkType.Folder, ID_in, version_in, name_in)
+		{
+			children = new ChunkyCollection(this);
+			MemoryStream ms = new MemoryStream(innerData, false);
+			BinaryReader br = new BinaryReader(ms);
+			
+			ChunkyChunk chunk = null;
+			ChunkyDataATTR attr = null;
+			ChunkyDataINFOTPAT info = null;
+
+			int pos = 0;
+
+			while (pos<innerData.Length)
+			{
+				br.BaseStream.Seek(pos, SeekOrigin.Begin);
+				chunk = RelicChunkReader.ReadChunkyChunk(br.ReadBytes(innerData.Length-pos), ID_in);
+				children.Add(chunk);
+
+				if (chunk is ChunkyDataATTR)
+				{
+					attr = (ChunkyDataATTR)chunk;
+				}
+				else if (chunk is ChunkyDataINFOTPAT)
+				{
+					info = (ChunkyDataINFOTPAT)chunk;
+				}
+				else if (attr!=null && chunk is ChunkyDataDATA)
+				{
+					((ChunkyDataDATA)chunk).Attributes = attr;
+				}
+				else if  (info!=null && chunk is ChunkyDataLayer)
+				{
+					((ChunkyDataLayer)chunk).Info = info;
+				}
+
+				pos+=chunk.Length;
+			}
+
+		}
+
+		public ChunkyFolder(string ID_in, int version_in, string name_in):base(ChunkyChunkType.Folder, ID_in, version_in, name_in)
+		{
+			children = new ChunkyCollection(this);
+		}
+
+		public ChunkyCollection Children
+		{
+			get { return children; }
+		}
+
+		public override byte[] GetBytes()
+		{
+			byte[] file = new byte[this.Length];
+			byte[] temp;
+			int pos = 0;
+
+			System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
+
+			enc.GetBytes("FOLD"+id).CopyTo(file,0);
+			pos+= 8;
+
+			BitConverter.GetBytes(version).CopyTo(file, pos);
+			pos+=4;
+			BitConverter.GetBytes(DataLength).CopyTo(file, pos);
+			pos+=4;
+			BitConverter.GetBytes(NameDataLength).CopyTo(file, pos);
+			pos+=4;
+			temp = this.GetNameBytes();
+			temp.CopyTo(file,pos);
+			pos+=temp.Length;
+
+			int childCount = this.children.Count;
+
+			for (int i = 0; i<childCount; i++)
+			{
+				temp = children[i].GetBytes();
+				temp.CopyTo(file, pos);
+				pos+= temp.Length;
+			}
+
+			return file;
+		}
+
+		public override int DataLength
+		{
+			get
+			{
+				int length = 0;
+
+				int childCount = this.children.Count;
+
+				for (int i = 0; i<childCount; i++)
+				{
+					length+= children[i].Length;
+				}
+
+				return length;
+			}
+		}
+
+		public override int Length
+		{
+			get 
+			{
+				int length = 20;
+
+				if (name!="")
+				{
+					 //names are padded with a single null if they exist
+					length += name.Length + 1;
+				}
+
+				length+= DataLength;
+
+				return length;
+			}
+		}
+
+		public int Save(string path)
+		{
+			int saves = 0;
+			ChunkyData data;
+
+			foreach (ChunkyChunk child in children)
+			{
+				if (child is ChunkyFolder)
+				{
+					saves+= ((ChunkyFolder)child).Save(path);
+				}
+				else if (child is ChunkyData)
+				{
+					data = (ChunkyData)child;
+					if (data.Savable && data.Save(path))
+					{
+						saves++;
+					}
+				}
+			}
+
+			return saves;
+		}
+
+		public override bool Savable
+		{
+			get
+			{
+				foreach (ChunkyChunk chunk in children)
+				{
+					if (chunk.Savable)
+					{
+						return true;
+					}
+				}
+
+				return false;
+			}
+		}
+
+		public override string GetValidationString()
+		{
+			int childCount = Children.Count;
+
+			if (childCount>0)
+			{
+				StringBuilder sb = new StringBuilder("FOLD"+ID+"[ ");
+
+				childCount--;
+
+				for (int i = 0; i<childCount; i++)
+				{
+					sb.Append(Children[i].GetValidationString()+" ");
+				}
+
+				sb.Append(Children[childCount].GetValidationString());
+
+				sb.Append(" ]");
+
+				return sb.ToString();
+			}
+			else
+			{
+				return "FOLD"+ID+"[ ]";
+			}
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyRawData.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,51 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyRawData.
+	/// </summary>
+	public class ChunkyRawData : ChunkyChunk
+	{
+		byte[] innerData;
+
+		public ChunkyRawData(byte[] bytes):base(ChunkyChunkType.RawData, "", 0, "")
+		{
+			innerData = bytes;
+		}
+
+		protected string GetBaseDisplayDetails()
+		{
+			return base.GetDisplayDetails();
+		}
+
+		public override byte[] GetBytes()
+		{
+			return innerData;
+		}
+
+		public override int DataLength
+		{
+			get { return innerData.Length; }
+		}
+
+		public byte[] GetDataBytes()
+		{
+			return innerData;
+		}
+
+		public override bool Savable
+		{
+			get{return false;}
+		}
+
+		public override string GetValidationString()
+		{
+			return "";
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ChunkyValidator.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,308 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using System.Collections;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for ChunkyValidator.
+	/// </summary>
+	public class ChunkyValidator
+	{
+		private class ValidatorToken
+		{
+			string tkn;
+			int min, max;
+			ValidatorToken[] children;
+
+			public ValidatorToken(string token, int minOccurances, int maxOccurances, ValidatorToken[] childTokens)
+			{
+				tkn = token;
+				min = minOccurances;
+				max = maxOccurances;
+				children = childTokens;
+			}
+
+			public ValidatorToken(string token, int minOccurances, int maxOccurances)
+				:this(token, minOccurances, maxOccurances, new ValidatorToken[0]){}
+			public ValidatorToken(string token, ValidatorToken[] childTokens):this(token, 1, 1, childTokens){}
+			public ValidatorToken(string token):this(token, 1, 1){}
+
+			public string Token
+			{
+				get{ return tkn; }
+			}
+
+			public int MinOccurances
+			{
+				get{ return min; }
+			}
+
+			public int MaxOccurances
+			{
+				get{ return max; }
+			}
+
+			public ValidatorToken[] SubTokens
+			{
+				get{ return children; }
+				set{ children = value; }
+			}
+		}
+		string type;
+		ValidatorToken[] tokens;
+		int part;
+
+		public ChunkyValidator(FileInfo file)
+		{
+			type = file.Name.Substring(0, file.Name.IndexOf('.')).ToUpper();
+
+			StreamReader sr = file.OpenText();
+			//char[] chars = new char[file.Length];
+			char prev = ' ';
+			string chars = sr.ReadLine();
+			
+			while (chars!=null && chars.StartsWith("#"))
+			{
+				chars = sr.ReadLine();
+			}
+
+			sr.Close();
+
+			if (chars == null)
+			{
+				throw new InvalidOperationException("Could not find validator string in file");
+			}
+			
+			chars = chars.Trim();
+
+			if (chars == "")
+			{
+				throw new InvalidOperationException("Could not find validator string in file");
+			}
+
+			string temp = "";
+			int val = 0, min = -1, max = -1;
+			ArrayList currTokens = new ArrayList();
+			Stack items = new Stack();
+
+			for (int i = 0; i<chars.Length; i++)
+			{
+				if (chars[i]==' ')
+				{
+					if (temp!="")
+					{
+						currTokens.Add(new ValidatorToken(temp, (min>-1?min:1), (max>-1?max:1)));
+					}
+
+					temp = "";					
+					min = -1; max = -1; val = 0;
+				}
+				else if (chars[i]=='[')
+				{
+					currTokens.Add(new ValidatorToken(temp, (min>-1?min:1), (max>-1?max:1)));//create a token for a FOLD
+					items.Push(currTokens);//store our current tokens
+					currTokens = new ArrayList();//and clear the list
+					temp = "";
+				}
+				else if (chars[i]==']')
+				{
+					ValidatorToken[] childTokens = (ValidatorToken[])currTokens.ToArray(typeof(ValidatorToken));
+					currTokens = (ArrayList)items.Pop();
+					((ValidatorToken)currTokens[currTokens.Count-1]).SubTokens = childTokens;
+					temp = "";
+				}
+				//else if (chars[i]=='(')
+				//{
+					//min = 1; max = 1;
+				//}
+				else if (chars[i]==')')
+				{
+					if (min>-1)
+					{
+						max = (val > min ? val : min);
+					}
+					else
+					{
+						min = val;
+						max = val;
+					}
+				}
+				else if (Char.IsDigit(chars[i]))
+				{
+					if (prev=='(')
+					{
+						val = int.Parse(chars[i].ToString());
+					}
+					else if (prev=='-')
+					{
+						min = val;
+						val = int.Parse(chars[i].ToString());
+					}
+					else if (Char.IsDigit(prev))
+					{
+						val*=10;
+						val+= int.Parse(chars[i].ToString());
+					}
+					//else it's something it shouldn't be
+				}
+				else if (Char.IsLetter(chars[i]))
+				{
+					temp+=chars[i];
+				}
+
+				prev = chars[i];
+			}
+
+			if (prev!=']')
+			{
+			/*	ValidatorToken[] childTokens = (ValidatorToken[])currTokens.ToArray(typeof(ValidatorToken));
+				currTokens = (ArrayList)items.Pop();
+				((ValidatorToken)currTokens[currTokens.Count-1]).SubTokens = childTokens;
+			}
+			else
+			{*/
+				currTokens.Add(new ValidatorToken(temp, (min>-1?min:1), (max>-1?max:1)));
+			}
+
+			tokens = (ValidatorToken[])currTokens.ToArray(typeof(ValidatorToken));
+		}
+
+		public string FileType
+		{
+			get{ return type; }
+		}
+
+		public bool Validate(string validationString)
+		{
+			lock(this)
+			{
+
+				string[] parts = validationString.Split(' ');
+				part = 0;
+				int pos = 0;
+				Stack layers = new Stack();
+				Stack layerPositions = new Stack();
+
+				try
+				{
+					while (pos < tokens.Length)
+					{
+						if (!validate(parts, tokens[pos]))
+						{
+							return false;
+						}
+						pos++;
+					}
+				}
+				catch (IndexOutOfRangeException)
+				{
+					return false;
+				}
+
+				return true;
+			}
+		}
+
+		private bool validate(string[] parts, ValidatorToken token)
+		{
+			int diff = 0;
+
+			if (token.SubTokens.Length>0)
+			{
+				for (int j = 0; j<token.MinOccurances; j++)
+				{
+					if (parts[part]!=token.Token+"[")
+					{
+						return false;
+					}
+			
+					part++;
+
+					for (int k = 0; k<token.SubTokens.Length; k++)
+					{
+						if (!validate(parts, token.SubTokens[k]))
+						{
+							return false;
+						}
+					}
+
+					if (parts[part]!="]")
+					{
+						return false;
+					}
+
+					part++;
+				}
+
+				diff = token.MaxOccurances - token.MinOccurances;
+
+				for (int j = 0; j < diff; j++)
+				{
+					if (parts[part]!=token.Token+"[")
+					{
+						break;
+					}	
+
+					part++;				
+
+					for (int k = 0; k<token.SubTokens.Length; k++)
+					{
+						if (!validate(parts, token.SubTokens[k]))
+						{
+							return false;
+						}
+					}
+
+					if (parts[part]!="]")
+					{
+						return false;
+					}
+					
+					part++;	
+				}
+
+				if (part<parts.Length && parts[part]==token.Token)
+				{
+					return false;
+				}
+			}
+			else
+			{
+				for (int j = 0; j<token.MinOccurances; j++)
+				{
+					if (parts[part]!=token.Token)
+					{
+						return false;
+					}
+
+					part++;
+				}
+
+				diff = token.MaxOccurances - token.MinOccurances;
+
+				for (int j = 0; j < diff; j++)
+				{
+					if (parts[part]!=token.Token)
+					{
+						break;
+					}
+					else
+					{
+						part++;
+					}
+				}
+
+				if (part<parts.Length && parts[part]==token.Token)
+				{
+					return false;
+				}
+			}
+
+			return true;
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Collections/ChunkyCollection.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,57 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.Collections;
+
+namespace IBBoard.Relic.RelicTools.Collections
+{
+	/// <summary>
+	/// Summary description for ChunkyCollection.
+	/// </summary>
+	public class ChunkyCollection
+	{
+		private ArrayList arr;
+		private ChunkyFolder parent;
+
+		public ChunkyCollection()
+		{
+			arr = new ArrayList();
+		}
+
+		public ChunkyCollection(ChunkyFolder parentFolder):this()
+		{			
+			parent = parentFolder;
+		}
+
+		public void Add(ChunkyChunk chunk)
+		{
+			if (chunk!=null)
+			{
+				arr.Add(chunk);
+				chunk.Parent = parent;
+			}
+		}
+
+		public ChunkyChunk this[int key]
+		{
+			get{return (ChunkyChunk)arr[key];}
+			set{ if (value!=null){arr[key] = value;}}
+		}
+
+		public void Remove(ChunkyChunk chunk)
+		{
+			arr.Remove(chunk);
+		}
+
+		public int Count
+		{
+			get{return arr.Count;}
+		}
+
+		public IEnumerator GetEnumerator()
+		{
+			return arr.GetEnumerator();
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Collections/ChunkyStructureCollection.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,62 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.Collections;
+
+namespace IBBoard.Relic.RelicTools.Collections
+{
+	/// <summary>
+	/// Summary description for ChunkyStructureCollection.
+	/// </summary>
+	public class ChunkyStructureCollection
+	{		
+		private ArrayList arr;
+		private RelicChunkyFile parent;
+
+		public ChunkyStructureCollection()
+		{
+			arr = new ArrayList();
+		}
+
+		public ChunkyStructureCollection(RelicChunkyFile parentFile):this()
+		{			
+			parent = parentFile;
+		}
+
+		public ChunkyStructureCollection(RelicChunkyStructure strct):this()
+		{
+			arr.Add(strct);
+		}
+
+		public void Add(RelicChunkyStructure chunk)
+		{
+			if (chunk!=null)
+			{
+				arr.Add(chunk);
+				chunk.ParentFile = parent;
+			}
+		}
+
+		public RelicChunkyStructure this[int key]
+		{
+			get{return (RelicChunkyStructure)arr[key];}
+			set{ if (value!=null){arr[key] = value;}}
+		}
+
+		public void Remove(RelicChunkyStructure chunk)
+		{
+			arr.Remove(chunk);
+		}
+
+		public int Count
+		{
+			get{return arr.Count;}
+		}
+
+		public IEnumerator GetEnumerator()
+		{
+			return arr.GetEnumerator();
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Collections/SgaFileCollection.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,105 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.Collections;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools.Collections
+{
+	/// <summary>
+	/// Summary description for SgaFileCollection.
+	/// </summary>
+	public class SgaFileCollection: IEnumerable, ICollection
+	{
+		private SortedList col = null;
+
+		/// <summary>
+		/// 
+		/// </summary>
+		public SgaFileCollection()
+		{
+			col = new SortedList();
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="toAdd"></param>
+		public void Add(SgaFile toAdd)
+		{
+			if (!col.ContainsKey(toAdd.Name))
+			{
+				col.Add(toAdd.Name, toAdd);
+			}
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		public SgaFile this[string name]
+		{
+			get
+			{
+				if (col.ContainsKey(name))
+				{
+					return (SgaFile)col[name];
+				}
+				else
+				{
+					throw new FileNotFoundException();
+				}
+			}
+		}
+
+		#region ICollection Members
+
+		public bool IsSynchronized
+		{
+			get
+			{
+				return col.IsSynchronized;
+			}
+		}
+
+		public int Count
+		{
+			get
+			{
+				return col.Count;
+			}
+		}
+
+		public void CopyTo(Array array, int index)
+		{
+			col.CopyTo(array, index);
+		}
+
+		public object SyncRoot
+		{
+			get
+			{
+				return col.SyncRoot;
+			}
+		}
+
+		#endregion
+
+		/// <summary>
+		/// 
+		/// </summary>
+		public ICollection Values
+		{
+			get{ return col.Values;}
+		}
+
+		#region IEnumerable Members
+
+		public IEnumerator GetEnumerator()
+		{
+			return col.GetEnumerator();
+		}
+
+		#endregion
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Collections/SgaFolderCollection.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,86 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.Collections;
+
+namespace IBBoard.Relic.RelicTools.Collections
+{
+	/// <summary>
+	/// Summary description for SgaFolderCollection.
+	/// </summary>
+	public class SgaFolderCollection: IEnumerable, ICollection
+	{
+		private SortedList col = null;
+
+		/// <summary>
+		/// 
+		/// </summary>
+		public SgaFolderCollection()
+		{
+			col = new SortedList();
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="toAdd"></param>
+		public void Add(SgaFolder toAdd)
+		{
+			if (!col.ContainsKey(toAdd.ID))
+			{
+				col.Add(toAdd.ID, toAdd);
+			}
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		public ICollection Values
+		{
+			get{ return col.Values;}
+		}
+
+		#region IEnumerable Members
+
+		public IEnumerator GetEnumerator()
+		{
+			return col.GetEnumerator();
+		}
+
+		#endregion
+
+		#region ICollection Members
+
+		public bool IsSynchronized
+		{
+			get
+			{
+				return col.IsSynchronized;
+			}
+		}
+
+		public int Count
+		{
+			get
+			{
+				return col.Count;
+			}
+		}
+
+		public void CopyTo(Array array, int index)
+		{
+			col.CopyTo(array, index);
+		}
+
+		public object SyncRoot
+		{
+			get
+			{
+				return col.SyncRoot;
+			}
+		}
+
+		#endregion
+	}
+}
Binary file Compression/ICSharpCode.SharpZipLib.dll has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Exceptions/Exception.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,29 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools.Exceptions
+{
+	/// <summary>
+	/// Summary description for Exception.
+	/// </summary>
+	public class Exception:System.Exception
+	{
+		private static readonly string DefaultMessage = "An unknown error has occured";
+
+		public Exception():base(DefaultMessage)
+		{
+		}
+
+		public Exception(string message):base(message)
+		{}
+
+		public Exception(Exception ex):base(DefaultMessage, ex)
+		{
+		}
+
+		public Exception(string message, Exception ex):base(message, ex)
+		{}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Exceptions/FileExistsException.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,29 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools.Exceptions
+{
+	/// <summary>
+	/// Summary description for FileExistsException.
+	/// </summary>
+	public class FileExistsException:Exception
+	{
+		private static readonly string DefaultMessage = "The file to be extracted already existed at the specified location and \"no overwrite\" was specified.";
+		private static readonly string DefaultMessageStart = "The file to be extracted (";
+		private static readonly string DefaultMessageEnd = ") already existed at the specified location and \"no overwrite\" was specified.";
+
+		public FileExistsException():base(DefaultMessage)
+		{
+		}
+
+		public FileExistsException(Exception ex):base(DefaultMessage, ex)
+		{
+		}
+
+		public FileExistsException(string filename):base(DefaultMessageStart+filename+DefaultMessageEnd)
+		{
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Exceptions/FileNotFoundException.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,21 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools.Exceptions
+{
+	/// <summary>
+	/// Summary description for FileNotFoundException.
+	/// </summary>
+	public class FileNotFoundException:Exception
+	{
+		private static readonly string DefaultMessage = "The file requested was not found in the folder specified.";
+
+		public FileNotFoundException():base(DefaultMessage){}
+
+		public FileNotFoundException(string message):base(message){}
+
+		public FileNotFoundException(Exception innerException):base(DefaultMessage,innerException){}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Exceptions/FileNotZippedException.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,23 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools.Exceptions
+{
+	/// <summary>
+	/// Summary description for FileNotZippedException.
+	/// </summary>
+	public class FileNotZippedException:Exception
+	{
+		private static readonly string DefaultMessage = "Unzipping was attempted on a file that does not appear to be compressed.";
+
+		public FileNotZippedException():base(DefaultMessage)
+		{
+		}
+
+		public FileNotZippedException(Exception ex):base(DefaultMessage, ex)
+		{
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Exceptions/InvalidChunkException.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,17 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools.Exceptions
+{
+	/// <summary>
+	/// Summary description for InvalidChunkException.
+	/// </summary>
+	public class InvalidChunkException: Exception
+	{
+		public InvalidChunkException(string message):base(message)
+		{
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Exceptions/InvalidChunkValueException.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,32 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools.Exceptions
+{
+	/// <summary>
+	/// Summary description for InvalidChunkValueException.
+	/// </summary>
+	public class InvalidChunkValueException : InvalidChunkException
+	{
+		string field;
+		object val;
+
+		public InvalidChunkValueException(string message, string fieldName, object valueFound): base(message)
+		{
+			field = fieldName;
+			val = (valueFound==null ? "" : valueFound);
+		}
+
+		public string FieldName
+		{
+			get { return field; }
+		}
+
+		public object Value
+		{
+			get { return val; }
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Exceptions/InvalidFileException.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,17 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools.Exceptions
+{
+	/// <summary>
+	/// Summary description for InvalidFileException.
+	/// </summary>
+	public class InvalidFileException : Exception
+	{
+		public InvalidFileException(string message):base(message)
+		{
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Exceptions/InvalidSourceFileException.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,20 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools.Exceptions
+{
+	/// <summary>
+	/// Summary description for InvalidSourceFileException.
+	/// </summary>
+	public class InvalidSourceFileException
+	{
+		public InvalidSourceFileException()
+		{
+			//
+			// TODO: Add constructor logic here
+			//
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Exceptions/InvalidUseException.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,27 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools.Exceptions
+{
+	/// <summary>
+	/// Summary description for InvalidUseException.
+	/// </summary>
+	public class InvalidUseException:Exception
+	{
+		private static readonly string DefaultMessage = "One of the methods or classes was used incorrectly or instantiated in a non-standard way.";
+
+		public InvalidUseException():base(DefaultMessage)
+		{
+		}
+
+		public InvalidUseException(Exception ex):base(DefaultMessage, ex)
+		{
+		}
+
+		public InvalidUseException(string message):base(message){}
+
+		public InvalidUseException(string message, Exception innerException):base(message, innerException){}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FileFormats.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,55 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for FileFormats.
+	/// </summary>
+	public class FileFormats
+	{
+		public enum ImgType {DXT1DDS, DXT3DDS, DXT5DDS, TGA, Unknown}
+
+		public static string FormatAsString(string extension)
+		{
+			switch(extension)
+			{
+				//http://www.relic.com/rdn/wiki/DOWFileFormats&v=17ol
+				case "rtx": return "Relic TeXture";
+				case "rsh": return "Relic SHader";
+				case "wtp": return "Team Coloured Texture";
+				case "ai": return "Artificial Intelligence";
+				case "scar": return "SCripting At Relic";
+				case "rgd": return "Compiled game data";
+				case "lua": return "Generic game data";
+				case "nil": return "Inheritance game data";
+				case "tga": return "Targa Image";
+				case "dds": return "DirectDraw Surface";
+				case "screen": return "Screen layout";
+				case "nis": return "Non-Interactive Sequence";
+				case "rat": return "Relic Audio Tool";
+				case "sgb": return "Game map";
+				case "camp": return "Campaign file";
+				case "turn": return "Turning behaviour";
+				case "events": return "Game Event";
+				case "fda": return "Fast Digital Audio";
+				case "con": return "Fake file";
+				case "teamcolour": return "Team colour";
+				case "whm": return "Game model";
+				case "whe": return "Game model animations";
+				case "bmp": return "Bitmap image";
+				case "jpg": return "JPEG image";
+				case "jpeg": return "JPEG image";
+				case "sgm": return "OE-ready model";
+				case "colours": return "Named colour list";
+				case "styles": return "Style sheet";
+				case "fnt": return "Font file";
+				case "ttf": return "True Type Font";
+				case "txt": return "Plain text";
+				default: return "Unknown";
+			}
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LayerCollection.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,65 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.Collections;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for LayerCollection.
+	/// </summary>
+	public class LayerCollection
+	{
+		private byte[][] layers;
+		private int layerSize;
+		public LayerCollection(int layerSize_in)
+		{
+			layers = new byte[6][];
+			layerSize = layerSize_in;
+
+			layers[0] = new byte[layerSize];
+			layers[1] = new byte[layerSize];
+			layers[2] = new byte[layerSize];
+			layers[3] = new byte[layerSize];
+			layers[4] = new byte[layerSize];
+			layers[5] = new byte[layerSize];
+		}
+
+		public byte[] this[int key]
+		{
+			get
+			{
+				return layers[key];
+			}
+
+			set
+			{
+				if (value.Length!=layerSize)
+				{
+					throw new InvalidOperationException("Data in layer collection must be the same size: "+layerSize.ToString()+" bytes");
+				}
+
+				layers[key] = value;
+			}
+		}
+
+		public byte[] this[PTLD_Layers key]
+		{
+			get
+			{
+				return layers[(int)key];
+			}
+
+			set
+			{
+				if (value.Length!=layerSize)
+				{
+					throw new InvalidOperationException("Data in layer collection must be the same size: "+layerSize.ToString()+" bytes");
+				}
+
+				layers[(int)key] = value;
+			}
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RECFile.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,35 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using IBBoard.Relic.RelicTools.Collections;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for WTPFile.
+	/// </summary>
+	public class RECFile:RelicChunkyFile
+	{
+		int version;
+		string recType;
+
+		public RECFile(string filename, ChunkyStructureCollection chunkyStructs, int ver, string type): base(filename, chunkyStructs)
+		{	
+			version = ver;
+			recType = type;
+		}
+
+		public string RecordingType
+		{
+			get { return recType; }
+		}
+
+		public int RecordingVersion
+		{
+			get { return version; }
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RSHFile.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,491 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using IBBoard.Relic.RelicTools.Exceptions;
+using IBBoard.Relic.RelicTools.Collections;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for WTPFile.
+	/// </summary>
+	public class RSHFile:RelicChunkyFile
+	{
+		public enum ShaderLayers {None=1, SpecMap=2, SelfIllum=4, Opacity = 8}
+
+		public RSHFile(string filename, ChunkyStructureCollection col): base(filename, col){}
+
+		public RSHFile(string filename, ChunkyFolder folder): base(filename, folder){}
+		
+		public RSHFile(string filename, ChunkyCollection col): base(filename, col){}
+
+		public ChunkyFolder GetBaseImageFolder()
+		{
+			return (ChunkyFolder)((ChunkyFolder)this.ChunkyStructures[0].RootChunks[0]).Children[0];
+		}
+
+		public ChunkyDataCHAN GetBaseImageDataCHAN()
+		{
+			return (ChunkyDataCHAN)GetSHDRFolder().Children[1];
+		}
+
+		public ChunkyFolder GetSHDRFolder()
+		{
+			ChunkyCollection col = ((ChunkyFolder)this.ChunkyStructures[0].RootChunks[0]).Children;
+			return (ChunkyFolder)col[col.Count-1];
+		}
+
+		public void SaveParts(DirectoryInfo destination)
+		{
+			string filenamebase = filename.Substring(0, filename.LastIndexOf('.'));
+
+			saveFolder((ChunkyFolder)this.ChunkyStructures[0].RootChunks[0], destination, filenamebase);
+		}
+
+		private void saveFolder(ChunkyFolder folder, DirectoryInfo destination, string filenamebase)
+		{
+			int children = folder.Children.Count;
+			ChunkyChunk chunk = null;
+
+			for (int i = 0; i<children; i++)
+			{
+				chunk = folder.Children[i];
+
+				if (chunk is ChunkyFolder)
+				{
+					this.saveFolder((ChunkyFolder)chunk, destination, filenamebase);
+				}
+				else if (chunk is ChunkyDataDATAIMAG)
+				{
+					((ChunkyDataDATAIMAG)chunk).Save(destination, folder.Parent.Name.Substring(folder.Parent.Name.LastIndexOf('/')+1));
+				}
+			}
+		}
+
+		public static RSHFile Create(string filepath)
+		{
+			return Create(new string[]{filepath, "", "", "", "", ""}, filepath);
+		}
+
+		public static RSHFile Create(string[] filepaths, string mainfilepath)
+		{
+			if (filepaths.Length!=6)
+			{
+				throw new InvalidOperationException("RSH file must contain six file path entries");
+			}
+
+			string baseFileName = mainfilepath.Substring(mainfilepath.LastIndexOf(Path.DirectorySeparatorChar)+1);
+			string baseFileNameLower = baseFileName.ToLower();
+
+			string directory = "";
+
+			if (mainfilepath.IndexOf(Path.DirectorySeparatorChar)!=-1)
+			{
+				directory = mainfilepath.Substring(0, mainfilepath.LastIndexOf(Path.DirectorySeparatorChar))+Path.DirectorySeparatorChar;
+			}
+			
+			if(baseFileNameLower.EndsWith(".dds"))
+			{
+				baseFileName = baseFileName.Substring(0, baseFileName.Length-4);
+			}
+			else
+			{
+				throw new InvalidFileException("File specified cannot be converted to a RSH file");
+			}
+
+			string texturePath = "";
+			
+			DirectoryInfo dir = new DirectoryInfo(directory);
+			
+			while(dir.Parent!=null)
+			{
+				texturePath = dir.Name+"/"+texturePath;
+
+				if (dir.Name.ToLower()!="art")
+				{
+					dir = dir.Parent;
+				}
+				else
+				{
+					break;
+				}
+			}
+
+			if (dir.Parent==null)
+			{
+				throw new InvalidFileException("RSH Files must be built within the 'data\\art' path to ensure correct WTP loading");
+			}
+
+			ChunkyDataDATA defaultData = null;
+			ChunkyData attr = null;
+			byte [] data;
+
+			int width = 0;
+			int height = 0;
+			int mipmaps = 0;
+			int size = 0;
+			byte type;
+			byte byte1;
+			FileInfo file;
+			BinaryReader br;
+			ChunkyFolder defaultFolder;
+			ChunkyData head;
+			ChunkyFolder txtr;
+			string filename;
+			string mainTexturePath = texturePath+baseFileName;
+			string[] texturePaths = new string[filepaths.Length];
+
+			int layers = 0;
+
+			if (filepaths[1]!="" && filepaths[1]!=null && filepaths[2]!="" && filepaths[2]!=null)
+			{
+				layers = (int)ShaderLayers.SpecMap;
+			}
+			
+			if (filepaths[3]!="" && filepaths[3]!=null)
+			{
+				layers+= (int)ShaderLayers.SelfIllum;
+			}
+
+			if (filepaths[4]!="" && filepaths[4]!=null)
+			{
+				layers+= (int)ShaderLayers.Opacity;
+			}
+
+			ChunkyFolder shrf = new ChunkyFolder("SHRF", 1, mainTexturePath);
+
+			CompilationEvent("Compiling RSH Texture...");
+
+			for (int i = 0; i<filepaths.Length; i++)
+			{
+				if (filepaths[i]=="" || filepaths[i]==null)
+				{
+					continue;
+				}
+
+				filename = filepaths[i].Substring(filepaths[i].LastIndexOf(Path.DirectorySeparatorChar)+1);
+				filename = filename.Substring(0, filename.Length-4);
+
+				if (File.Exists(filepaths[i]))
+				{
+					CompilationEvent("Reading "+filename+".dds");
+					file = new FileInfo(directory+filename+".dds");
+					br = new BinaryReader(file.OpenRead());
+					br.BaseStream.Seek(0, SeekOrigin.Begin);
+					data = br.ReadBytes((int)file.Length);
+
+					defaultData = ChunkyDataDATAIMAG.CreateFromDDS(2, "", data);
+				
+					br.BaseStream.Seek(12,SeekOrigin.Begin);
+					height = br.ReadInt32();
+					width = br.ReadInt32();
+					size = br.ReadInt32();
+					br.BaseStream.Seek(4, SeekOrigin.Current);
+					mipmaps = br.ReadInt32();
+					br.BaseStream.Seek(87, SeekOrigin.Begin);
+					type = br.ReadByte();
+					br.Close();
+
+					if ((char)type=='1')
+					{
+						type = 0x8;
+						byte1 = 0x5;
+					}
+                    else if ((char)type == '3')
+                    {
+                        type = 0xA;
+                        byte1 = 0x6;
+                    }
+                    else if ((char)type == '5')
+                    {
+                        type = 0xB;
+                        byte1 = 0x7;
+                    }
+                    else
+                    {
+                        throw new RelicTools.Exceptions.FileNotFoundException("RSH files must be made from DXT1, DXT3 or DXT5 DDS files");
+                    }
+
+					data = new byte[]{type, 0x0, 0x0, 0x0, (byte)width, (byte)(width>>8), (byte)(width>>16), (byte)(width>>24), (byte)(height), (byte)(height>>8), (byte)(height>>16), (byte)(height>>24), (byte)mipmaps, (byte)(mipmaps>>8), (byte)(mipmaps>>16), (byte)(mipmaps>>24)};
+					attr = new ChunkyDataUnknown("ATTR", 2, "", data);
+				}
+				else
+				{
+					throw new RelicTools.Exceptions.FileNotFoundException("RSH files must be made from a DDS file");
+				}
+
+				defaultFolder = new ChunkyFolder("IMAG", 1, "");
+
+				defaultFolder.Children.Add(attr);
+				defaultFolder.Children.Add(defaultData);
+
+				head = new ChunkyDataUnknown("HEAD", 1, "", new byte[]{byte1, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00});
+
+				texturePaths[i] = texturePath+filename;
+				txtr = new ChunkyFolder("TXTR", 1, texturePath+filename);
+				txtr.Children.Add(head);
+				txtr.Children.Add(defaultFolder);
+				shrf.Children.Add(txtr);
+			}
+
+			CompilationEvent("Compiling Texture Shaders");
+
+			ChunkyDataINFO info = new ChunkyDataINFOGeneric(1, "", new byte[]{0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, (byte)((layers<=1)?0xcc:0xcd), 0xcc, 0xcc, 0x3d, 0x01, 0x00, 0x00, 0x00, 0x00 });
+
+			data = new byte[156+mainTexturePath.Length];
+			data[0] = 0x00;
+			data[1] = 0x00;
+			data[2] = 0x00;
+			data[3] = 0x00;
+			data[4] = 0x01;
+			data[5] = 0x00;
+			data[6] = 0x00;
+			data[7] = 0x00;
+
+			if (layers<=1)
+			{
+				data[8] = 0x96;
+				data[9] = 0x96;
+				data[10] = 0x96;
+				data[11] = 0xff;
+			}
+			else
+			{
+				data[8] = 0x0;
+				data[9] = 0x0;
+				data[10] = 0x0;
+				data[11] = 0xff;
+			}
+
+			data[12] = (byte)mainTexturePath.Length;
+			data[13] = (byte)(mainTexturePath.Length>>8);
+			data[14] = (byte)(mainTexturePath.Length>>16);
+			data[15] = (byte)(mainTexturePath.Length>>24);
+
+			System.Text.ASCIIEncoding.ASCII.GetBytes(mainTexturePath).CopyTo(data, 16);
+			byte[] temp = new byte[]{0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f};
+			temp.CopyTo(data, 16+mainTexturePath.Length);
+			
+			ChunkyData chan0 = new ChunkyDataUnknown("CHAN", 3, "", data);
+
+			ChunkyData chan1, chan2, chan3, chan4, chan5;
+			
+			//fill out the defaults
+			if ((layers & (int)ShaderLayers.SpecMap)!=(int)ShaderLayers.SpecMap)
+			{
+				//they're not using a spec map
+				data = new byte[]{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)((layers<=1)?0xe5:0x00), (byte)((layers<=1)?0xe5:0x00), (byte)((layers<=1)?0xe5:0x00), 0xff, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f};
+				chan1 = new ChunkyDataUnknown("CHAN", 3, "", data);
+
+				data = new byte[]{0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f};
+				chan2 = new ChunkyDataUnknown("CHAN", 3, "", data);
+			}
+			else
+			{
+				//they are using a spec map				
+				data = new byte[156+texturePaths[1].Length];
+				data[0] = 0x01;//ID
+				data[1] = 0x00;
+				data[2] = 0x00;
+				data[3] = 0x00;
+				data[4] = 0x01;//format - 1 = Texture, 2 = Add, 3 = Blend, 4+ = blank
+				data[5] = 0x00;
+				data[6] = 0x00;
+				data[7] = 0x00;
+				data[8] = 0x00;
+				data[9] = 0x00;
+				data[10] = 0x00;
+				data[11] = 0xff;
+				data[12] = (byte)texturePaths[1].Length;
+				data[13] = (byte)(texturePaths[1].Length>>8);
+				data[14] = (byte)(texturePaths[1].Length>>16);
+				data[15] = (byte)(texturePaths[1].Length>>24);
+
+				System.Text.ASCIIEncoding.ASCII.GetBytes(texturePaths[1]).CopyTo(data, 16);
+				temp = new byte[]{0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f};
+				temp.CopyTo(data, 16+texturePaths[1].Length);
+				chan1 = new ChunkyDataUnknown("CHAN", 3, "", data);
+
+				data = new byte[156+texturePaths[2].Length];
+				data[0] = 0x02;
+				data[1] = 0x00;
+				data[2] = 0x00;
+				data[3] = 0x00;
+				data[4] = 0x01;
+				data[5] = 0x00;
+				data[6] = 0x00;
+				data[7] = 0x00;
+				data[8] = 0x00;
+				data[9] = 0x00;
+				data[10] = 0x00;
+				data[11] = 0xff;
+				data[12] = (byte)texturePaths[2].Length;
+				data[13] = (byte)(texturePaths[2].Length>>8);
+				data[14] = (byte)(texturePaths[2].Length>>16);
+				data[15] = (byte)(texturePaths[2].Length>>24);
+
+				System.Text.ASCIIEncoding.ASCII.GetBytes(texturePaths[2]).CopyTo(data, 16);
+				temp = new byte[]{0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f};
+				temp.CopyTo(data, 16+texturePaths[2].Length);
+				chan2 = new ChunkyDataUnknown("CHAN", 3, "", data);
+			}
+			
+
+			if ((layers & (int)ShaderLayers.SelfIllum)!=(int)ShaderLayers.SelfIllum)
+			{
+				data = new byte[]{0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f};
+			}
+			else
+			{
+				data = new byte[156+texturePaths[3].Length];
+				data[0] = 0x03;
+				data[1] = 0x00;
+				data[2] = 0x00;
+				data[3] = 0x00;
+				data[4] = 0x01;
+				data[5] = 0x00;
+				data[6] = 0x00;
+				data[7] = 0x00;
+				data[8] = 0x00;
+				data[9] = 0x00;
+				data[10] = 0x00;
+				data[11] = 0xff;
+				data[12] = (byte)texturePaths[3].Length;
+				data[13] = (byte)(texturePaths[3].Length>>8);
+				data[14] = (byte)(texturePaths[3].Length>>16);
+				data[15] = (byte)(texturePaths[3].Length>>24);
+
+				System.Text.ASCIIEncoding.ASCII.GetBytes(texturePaths[3]).CopyTo(data, 16);
+				temp = new byte[]{0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f};
+				temp.CopyTo(data, 16+texturePaths[3].Length);
+			}
+			chan3 = new ChunkyDataUnknown("CHAN", 3, "", data);
+
+			if ((layers & (int)ShaderLayers.Opacity)!=(int)ShaderLayers.Opacity)
+			{
+				data = new byte[]{0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f};
+			}
+			else
+			{
+				data = new byte[156+texturePaths[4].Length];
+				data[0] = 0x04;
+				data[1] = 0x00;
+				data[2] = 0x00;
+				data[3] = 0x00;
+				data[4] = 0x01;
+				data[5] = 0x00;
+				data[6] = 0x00;
+				data[7] = 0x00;
+				data[8] = 0x00;//0x00;
+				data[9] = 0x00;//0x00;
+				data[10] = 0x00;//0x00;
+				data[11] = 0xff;
+				data[12] = (byte)texturePaths[4].Length;
+				data[13] = (byte)(texturePaths[4].Length>>8);
+				data[14] = (byte)(texturePaths[4].Length>>16);
+				data[15] = (byte)(texturePaths[4].Length>>24);
+
+				System.Text.ASCIIEncoding.ASCII.GetBytes(texturePaths[4]).CopyTo(data, 16);
+				temp = new byte[]{0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f};
+				temp.CopyTo(data, 16+texturePaths[4].Length);
+			}
+			chan4 = new ChunkyDataUnknown("CHAN", 3, "", data);
+
+			//if (filepaths.Length<6)
+			//{
+				data = new byte[]{0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+									 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f};
+			/*}
+			else
+			{
+				data = new byte[156+texturePaths[1].Length];
+				data[0] = 0x05;
+				data[1] = 0x00;
+				data[2] = 0x00;
+				data[3] = 0x00;
+				data[4] = 0x01;
+				data[5] = 0x00;
+				data[6] = 0x00;
+				data[7] = 0x00;
+				data[8] = 0x00;
+				data[9] = 0x00;
+				data[10] = 0x00;
+				data[11] = 0xff;
+				data[12] = (byte)texturePaths[1].Length;
+				data[13] = (byte)(texturePaths[1].Length>>8);
+				data[14] = (byte)(texturePaths[1].Length>>16);
+				data[15] = (byte)(texturePaths[1].Length>>24);
+
+				System.Text.ASCIIEncoding.ASCII.GetBytes(texturePaths[1]).CopyTo(data, 16);
+				temp = new byte[]{0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f};
+				temp.CopyTo(data, 16+texturePaths[1].Length);
+			}*/
+			chan5 = new ChunkyDataUnknown("CHAN", 3, "", data);
+			
+
+			ChunkyFolder shdr = new ChunkyFolder("SHDR", 1, mainTexturePath);
+			shdr.Children.Add(info);
+			shdr.Children.Add(chan0);
+			shdr.Children.Add(chan1);
+			shdr.Children.Add(chan2);
+			shdr.Children.Add(chan3);
+			shdr.Children.Add(chan4);
+			shdr.Children.Add(chan5);
+
+
+			CompilationEvent("Compiling RSH File");
+
+			shrf.Children.Add(shdr);
+
+			return new RSHFile(baseFileName+".rsh", shrf);//new ChunkyStructureCollection(new RelicChunkyStructure(
+			
+			//RelicChunkyFile.SaveChunky(directory+baseFileName+".rsh", shrf.GetBytes());
+		}
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTXFile.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,216 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using IBBoard.Relic.RelicTools.Exceptions;
+using IBBoard.Relic.RelicTools.Collections;
+
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for WTPFile.
+	/// </summary>
+	public class RTXFile:RelicChunkyFile
+	{
+		int width = 0;
+		int height = 0;
+		int id = 0;
+
+		public RTXFile(string filename, ChunkyFolder folder)
+			:this(filename, new ChunkyStructureCollection(new RelicChunkyStructure(folder))){}
+		
+		public RTXFile(string filename, ChunkyCollection col)
+			:this(filename, new ChunkyStructureCollection(new RelicChunkyStructure(col))){}
+
+		public RTXFile(string filename, ChunkyStructureCollection col): base(filename, col)
+		{	
+			int lastIndex = filename.LastIndexOf('_');
+			
+			if (lastIndex == -1 ||  filename.IndexOf('_')==lastIndex)
+			{
+				throw new InvalidFileException("RTX file name specified must end with a skin name and number e.g. _default_0.rtx");
+			}
+
+			try
+			{
+				int dot = filename.LastIndexOf('.');
+				lastIndex++;
+				id = int.Parse(filename.Substring(lastIndex, dot - lastIndex));
+			}
+			catch(FormatException)
+			{
+				throw new InvalidFileException("RTX file name specified must end with a skin name and number e.g. _default_0.rtx");
+			}
+
+			FindAttributes((ChunkyFolder)this.ChunkyStructures[0].RootChunks[0]);			
+		}
+
+		private void FindAttributes(ChunkyFolder folder)
+		{
+			int children = folder.Children.Count;
+			ChunkyChunk chunk = null;
+			ChunkyDataATTR attr = null;
+
+			for (int i = 0; i<children; i++)
+			{
+				chunk = folder.Children[i];
+
+				if (chunk is ChunkyDataATTR)
+				{
+					attr = (ChunkyDataATTR)chunk;
+					width = attr.Width;
+					height = attr.Height;
+					break;
+				}
+				else if (chunk is ChunkyFolder)
+				{
+					FindAttributes((ChunkyFolder)chunk);
+				}
+			}
+		}
+
+		public void SaveParts(DirectoryInfo destination)
+		{
+			string filenamebase = filename.Substring(0, filename.LastIndexOf('.'));
+
+			saveFolder((ChunkyFolder)this.ChunkyStructures[0].RootChunks[0], destination, filenamebase);
+		}
+
+		private void saveFolder(ChunkyFolder folder, DirectoryInfo destination, string filenamebase)
+		{
+			int children = folder.Children.Count;
+			ChunkyChunk chunk = null;
+
+			for (int i = 0; i<children; i++)
+			{
+				chunk = folder.Children[i];
+
+				if (chunk is ChunkyFolder)
+				{
+					this.saveFolder((ChunkyFolder)chunk, destination, filenamebase);
+				}
+				/*else if (chunk is ChunkyDataATTR)
+				{
+					attr = (ChunkyDataATTR)chunk;
+					imagetype = attr.ImageType;
+					mipmaps = attr.MipMaps;
+				}*/
+				else if (chunk is ChunkyDataDATAIMAG)
+				{
+					((ChunkyDataDATAIMAG)chunk).Save(destination, filenamebase);
+				}
+			}
+		}
+
+		public static RTXFile Create(string filepath)
+		{
+			string baseFileName = filepath.Substring(filepath.LastIndexOf(Path.DirectorySeparatorChar)+1);
+			string baseFileNameLower = baseFileName.ToLower();
+
+			string directory = "";
+
+			if (filepath.IndexOf(Path.DirectorySeparatorChar)!=-1)
+			{
+				directory = filepath.Substring(0, filepath.LastIndexOf(Path.DirectorySeparatorChar))+Path.DirectorySeparatorChar;
+			}
+			
+			if(baseFileNameLower.EndsWith(".dds"))
+			{
+				baseFileName = baseFileName.Substring(0, baseFileName.Length-4);
+			}
+			else
+			{
+				throw new InvalidFileException("File path specified is not valid for a RTX file");
+			}
+
+			string unit_name = "";
+			int lastUnderscore = baseFileName.LastIndexOf('_');
+
+			if (lastUnderscore!=-1)
+			{
+				unit_name = baseFileName.Substring(0, lastUnderscore);//trim the number
+
+				try
+				{
+					int id = int.Parse(baseFileName.Substring(lastUnderscore+1));
+				}
+				catch
+				{
+					throw new InvalidFileException("DDS file name specified must end with a number to identify RTX e.g. _default_0.dds");
+				}
+
+				lastUnderscore = unit_name.LastIndexOf('_');
+				if (lastUnderscore!=-1)
+				{
+					unit_name = unit_name.Substring(0, lastUnderscore);
+				}
+				else
+				{
+					throw new InvalidFileException("DDS file name specified must end with a skin name followed by a number e.g. _default_0.dds");
+				}
+			}
+			else
+			{
+				throw new InvalidFileException("DDS file name specified must end with a skin name and number e.g. _default_0.dds");
+			}
+
+			ChunkyDataDATA defaultData = null;
+			ChunkyData attr = null;
+			byte [] data;
+
+			int width = 0;
+			int height = 0;
+			int mipmaps = 0;
+
+			if (File.Exists(directory+baseFileName+".dds"))
+			{
+				CompilationEvent("Reading "+baseFileName+".dds");
+				FileInfo file = new FileInfo(directory+baseFileName+".dds");
+				BinaryReader br = new BinaryReader(file.OpenRead());
+				br.BaseStream.Seek(0, SeekOrigin.Begin);
+				data = br.ReadBytes((int)file.Length);
+
+				defaultData = ChunkyDataDATAIMAG.CreateFromDDS(2, "", data);
+				
+				br.BaseStream.Seek(12,SeekOrigin.Begin);
+				height = br.ReadInt32();
+				width = br.ReadInt32();
+				int size = br.ReadInt32();
+				br.BaseStream.Seek(4, SeekOrigin.Current);
+				mipmaps = br.ReadInt32();
+				br.Close();
+
+				byte type = 0x8;
+
+				if (size==width*height)
+				{
+					type = 0xb;
+				}
+
+				data = new byte[]{type, 0x0, 0x0, 0x0, (byte)width, (byte)(width>>8), (byte)(width>>16), (byte)(width>>24), (byte)(height), (byte)(height>>8), (byte)(height>>16), (byte)(height>>24), (byte)mipmaps, (byte)(mipmaps>>8), (byte)(mipmaps>>16), (byte)(mipmaps>>24)};
+				attr = new ChunkyDataUnknown("ATTR", 2, "", data);
+			}
+			else
+			{
+				throw new RelicTools.Exceptions.FileNotFoundException("RTX files must be made from a DDS file");
+			}
+
+			ChunkyFolder defaultFolder = new ChunkyFolder("IMAG", 1, "");
+
+			defaultFolder.Children.Add(attr);
+			defaultFolder.Children.Add(defaultData);
+
+			ChunkyData head = new ChunkyDataUnknown("HEAD", 1, "", new byte[]{0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00});
+
+
+			CompilationEvent("Compiling RTX File");
+			ChunkyFolder txtr = new ChunkyFolder("TXTR", 1, unit_name);
+			txtr.Children.Add(head);
+			txtr.Children.Add(defaultFolder);
+			return new RTXFile(baseFileName+".rtx", txtr);
+			//RelicChunkyFile.SaveChunky(directory+baseFileName+".rtx", txtr.GetBytes());
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RelicBinaryReader.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,99 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using System.Text;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for RelicBinaryReader.
+	/// </summary>
+	public class RelicBinaryReader:BinaryReader
+	{
+		public RelicBinaryReader(Stream input):base(input)
+		{
+		}
+
+		public override string ReadString()
+		{
+			return base.ReadString();
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="start"></param>
+		/// <param name="bytes"></param>
+		/// <returns></returns>
+		public string ReadString(int start, int length)
+		{
+			return ReadString(start, length, false);
+		}
+
+		public string ReadString(int length)
+		{
+			return ReadString(-1, length, false);
+		}
+
+		public string ReadString(int length, bool unicode)
+		{
+			return ReadString(-1, length, unicode);
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="start"></param>
+		/// <param name="bytes"></param>
+		/// <param name="unicode"></param>
+		/// <returns></returns>
+		public string ReadString(int start, int length, bool unicode)
+		{
+			if (length <= 0)
+			{
+				return "";
+			}
+
+			StringBuilder str = new StringBuilder();
+			byte tempByte = 0;
+			if (start>=0)
+			{
+				this.BaseStream.Seek(start, SeekOrigin.Begin);
+			}
+			//else read from where we are
+
+			if (length>0)
+			{
+				for (long i = 0; i<length; i++)
+				{
+					tempByte = this.ReadByte();
+
+					if (tempByte>=30)
+						str.Append((char)tempByte);
+				
+					if (unicode)
+						i++;
+				}
+			}
+			else
+			{
+				try
+				{
+					do 
+					{
+						tempByte = this.ReadByte();
+
+						if (tempByte>=30)
+							str.Append((char)tempByte);
+
+					} while (tempByte!=0);
+				}
+				catch{}
+			}
+
+			return str.ToString();
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RelicChunkReader.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,182 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using IBBoard.Relic.RelicTools.Collections;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for RelicChunkReader.
+	/// </summary>
+	public class RelicChunkReader
+	{
+		static byte[] remaining;
+
+		public static bool HasRemainingBytes()
+		{
+			return (remaining!=null && remaining.Length>20);
+		}
+
+		public static byte[] GetRemainingBytes()
+		{
+			return remaining;
+		}
+
+		public static ChunkyCollection ReadChunkyChunks(byte[] chunkBytes)
+		{
+			MemoryStream ms = new MemoryStream(chunkBytes, false);
+			RelicBinaryReader br = new RelicBinaryReader(ms);
+
+			remaining = new byte[0];
+
+			int pos = 0;
+
+			int fileLength = chunkBytes.Length;
+			ChunkyCollection col = new ChunkyCollection();
+
+			while (pos<fileLength && (fileLength-pos)>20)
+				//check that there's a reasonable amount remaining so that the app doesn't choke on the extra bytes
+				//added to the end of files like Relic's Chunky Viewer does on SpookyRAT extracted files
+			{
+				string type = br.ReadString(4);
+
+				if (type == "FOLD" || type=="DATA")
+				{
+					string id = br.ReadString(4);
+					int version = br.ReadInt32();
+					int dataLength = br.ReadInt32();
+					int nameLength = br.ReadInt32();
+					string name = br.ReadString(nameLength);
+					byte[] innerData = br.ReadBytes(dataLength);
+
+					if (type == "FOLD")
+					{
+						col.Add(new ChunkyFolder(id, version, name, innerData));
+					}
+					else
+					{
+						col.Add(CreateChunkyChunk(id, "", version, name, innerData));
+					}
+
+					pos+= dataLength+nameLength+20;
+				}
+				else if (type == "Reli")
+				{
+					br.BaseStream.Seek(-4, SeekOrigin.Current);
+					remaining = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));
+					//we've hit another chunk, so stop the reading
+					break;
+				}
+				else if (type=="")
+				{
+					//HACK: drop out with REC files rather than exceptioning, as the trailing info doesn't seem to be Chunkified
+					remaining = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));
+					break;
+				}
+				else
+				{
+					throw new InvalidChunkException("Chunk was not of type FOLD or DATA");
+				}
+			}
+
+			return col;
+		}
+
+		public static ChunkyChunk ReadChunkyChunk(byte[] chunkBytes)
+		{
+			return ReadChunkyChunk(chunkBytes, "");
+		}
+
+		public static ChunkyChunk ReadChunkyChunk(byte[] chunkBytes, string parentID)
+		{
+			MemoryStream ms = new MemoryStream(chunkBytes, false);
+			RelicBinaryReader br = new RelicBinaryReader(ms);
+
+			string type = br.ReadString(0,4);
+			string id = br.ReadString(4);
+			int version = br.ReadInt32();
+			int dataLength = br.ReadInt32();
+			int nameLength = br.ReadInt32();
+			string name = br.ReadString(nameLength);
+			byte[] innerData = br.ReadBytes(dataLength);
+
+			if (type=="FOLD")
+			{
+				return new ChunkyFolder(id, version, name, innerData);
+			}
+			else if (type=="DATA")
+			{
+				return CreateChunkyChunk(id, parentID, version, name, innerData);
+			}
+			else
+			{
+				throw new InvalidChunkException("Chunk was not of type FOLD or DATA");
+			}
+		}
+
+		private static ChunkyData CreateChunkyChunk(string id, string parentID, int version, string name, byte[] innerData)
+		{
+			try
+			{
+				switch(id)
+				{
+					case "PTLD":
+						return new ChunkyDataPTLD(version, name, innerData);
+					case "DATA":
+						if (parentID=="IMAG")
+						{
+							return new ChunkyDataDATAIMAG(version, name, innerData);
+						}
+						else
+						{
+							return new ChunkyDataDATA(version, name, innerData);
+						}
+					case "PTBN":
+						return new ChunkyDataPTBN(version, name, innerData);
+					case "PTBD":
+						return new ChunkyDataPTBD(version, name, innerData);
+					case "INFO":
+						if (parentID == "")
+						{
+							return new ChunkyDataINFOGeneric(version, name, innerData);
+						}
+						else if (parentID == "SHDR")
+						{
+							return new ChunkyDataINFOSHDR(version, name, innerData);
+						}
+						else if (parentID == "TPAT")
+						{						
+							return new ChunkyDataINFOTPAT(version, name, innerData);
+						}
+						else if (parentID == "TXTR")
+						{
+							return new ChunkyDataINFOTXTR(version, name, innerData);
+						}
+						else
+						{
+							return new ChunkyDataINFOGeneric(version, name, innerData);
+						}
+					case "ATTR":
+						return new ChunkyDataATTR(version, name, innerData);
+					case "CHAN":
+						return new ChunkyDataCHAN(version, name, innerData);
+					case "HEAD":
+						return new ChunkyDataHEAD(version, name, innerData);
+					case "FBIF":
+						return new ChunkyDataFBIF(version, name, innerData);
+					case "SSHR":
+						return new ChunkyDataSSHR(version, name, innerData);
+					default:
+						return new ChunkyDataUnknown(id, version, name, innerData);
+				}
+			}
+			catch (IndexOutOfRangeException)
+			{
+				throw new InvalidChunkException("Data chunk of type "+id+" contained less data than expected");
+			}
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RelicChunkyFile.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,126 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using System.Text;
+using IBBoard.Relic.RelicTools.Collections;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for RelicChunkyFile.
+	/// </summary>
+	public class RelicChunkyFile
+	{
+		ChunkyStructureCollection structCol;
+		protected string filename;
+
+		public RelicChunkyFile(string name, ChunkyFolder folder)
+			:this(name, new RelicChunkyStructure(folder))
+		{}
+
+		public RelicChunkyFile(string name, ChunkyCollection col)
+			:this(name, new RelicChunkyStructure(col))
+		{}
+
+		public RelicChunkyFile(string name, RelicChunkyStructure chunkyRoot)
+			:this(name, new ChunkyStructureCollection(chunkyRoot))
+		{}
+        
+		public RelicChunkyFile(string name, ChunkyStructureCollection col)
+		{
+			structCol = col;
+			filename = name;
+
+			foreach (RelicChunkyStructure strct in structCol)
+			{
+				strct.ParentFile = this;
+			}
+		}
+
+		public ChunkyStructureCollection ChunkyStructures
+		{
+			get{return structCol;}
+		}
+
+		public delegate void CompilationEventDelegate(string message, bool error);
+
+		public static event CompilationEventDelegate OnCompilationEvent;
+
+		public static void CompilationEvent(string message, bool error)
+		{
+			if (OnCompilationEvent!=null)
+			{
+				OnCompilationEvent(message, error);
+			}
+			//else no-one cares
+		}
+
+		public string Name
+		{
+			get{return filename;}
+		}
+
+		public static void CompilationEvent(string message)
+		{
+			CompilationEvent(message, false);
+		}
+		
+		public void Save(DirectoryInfo destination)
+		{
+			FileStream fs = null;
+			BinaryWriter bw = null;
+
+			fs = new FileInfo(destination.FullName+"/"+filename).Open(FileMode.Create, FileAccess.Write);
+
+			try
+			{
+				bw = new BinaryWriter(fs);
+
+				foreach (RelicChunkyStructure strct in ChunkyStructures)
+				{
+					strct.Save(bw);
+				}
+				bw.Close();
+				CompilationEvent("Saved.\r\n");
+			}
+			finally
+			{
+				if (fs!=null)
+				{
+					fs.Close();
+				}
+
+				if (bw!=null)
+				{
+					bw.Close();
+				}
+			}
+		}
+
+		public string GetValidationString()
+		{
+			int childCount = this.ChunkyStructures.Count;
+
+			if (childCount>1)
+			{
+				StringBuilder sb = new StringBuilder();
+				childCount--;
+
+				for (int i = 0; i<childCount; i++)
+				{
+					sb.Append(ChunkyStructures[i].GetValidationString()+" ");
+				}
+
+				sb.Append(ChunkyStructures[childCount].GetValidationString());
+
+				return sb.ToString();
+			}
+			else
+			{
+				return ChunkyStructures[0].GetValidationString();
+			}
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RelicChunkyReader.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,176 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.Collections;
+using System.IO;
+using System.Text;
+using IBBoard.Relic.RelicTools.Collections;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for RelicChunkyReader.
+	/// </summary>
+	public class RelicChunkyReader
+	{
+		public static RelicChunkyFile ReadChunkyFile(string filepath)
+		{
+			if (!File.Exists(filepath))
+			{
+				throw new RelicTools.Exceptions.FileNotFoundException("No 'RelicChunky' file found at "+filepath);
+			}
+
+			FileInfo chunkyFile = new FileInfo(filepath);
+			BinaryReader br = new BinaryReader(chunkyFile.OpenRead());
+
+			byte[] start = br.ReadBytes(4);
+			int version = 0;
+			string fileType = "";
+
+			if (start[1] == 0 && start[2] == 0 && start[3] == 0)
+			{
+				version = start[0];
+				fileType = ReadString(br, 4, 8);
+			}
+			else
+			{
+				br.BaseStream.Seek(0, SeekOrigin.Begin);
+			}
+
+			ChunkyStructureCollection structCol = ReadChunkyFileStructure(br);
+			
+			br.Close();
+
+			string filename = filepath.Substring(filepath.LastIndexOf(Path.DirectorySeparatorChar)+1);
+
+			if (filepath.EndsWith(".rec"))
+			{
+				return new RECFile(filename, structCol, version, fileType);
+			}
+			else if (structCol.Count==1 && structCol[0].RootChunks[0].ID=="TPAT")
+			{
+				return new WTPFile(filename, structCol);
+			}
+			else if (structCol.Count==1 && structCol[0].RootChunks[0].ID=="SHRF")
+			{
+				return new RSHFile(filename, structCol);
+			}
+			else if (structCol.Count==1 && structCol[0].RootChunks[0].ID=="TXTR")
+			{
+				return new RTXFile(filename, structCol);
+			}
+			else
+			{
+				return new RelicChunkyFile(filename, structCol);
+			}
+		}
+
+		private static ChunkyStructureCollection ReadChunkyFileStructure(BinaryReader br)
+		{			
+			string name = "";
+
+			name = ReadString(br, (int)br.BaseStream.Position, 12);
+
+			if (name!="Relic Chunky")
+			{
+				/*if (name == "Relic Chunky")
+				{
+					//handle REC files which are chunkys with data at the start
+					br.BaseStream.Seek(0, SeekOrigin.Begin);
+					//version = br.ReadInt32();
+					//fileType = ReadString(br, 4, 8);
+					br.BaseStream.Seek(12, SeekOrigin.Current); //skip the name string we just read
+					
+				}
+				else
+				{*/
+				throw new InvalidFileException("File was not recognised as a valid RelicChunky File");//"File '"+filepath+"' was not recognised as a valid RelicChunky File");
+			}
+			//}
+
+			return ReadChunkyStructure(br, br.BaseStream.Length);
+		}
+
+		private static ChunkyStructureCollection ReadChunkyStructure(BinaryReader br, long fileLength)
+		{
+
+			//long end = fileLength - 20;
+			ChunkyStructureCollection structCol = new ChunkyStructureCollection();
+			int unknown1 = br.ReadInt32();
+			int unknown2 = br.ReadInt32();
+			int unknown3 = br.ReadInt32();
+
+			byte[] bytes = br.ReadBytes((int)(fileLength-br.BaseStream.Position));
+
+			structCol.Add(new RelicChunkyStructure(RelicChunkReader.ReadChunkyChunks(bytes), unknown1, unknown2, unknown3));
+			
+			if (RelicChunkReader.HasRemainingBytes())
+			{
+				byte[] remainingData = RelicChunkReader.GetRemainingBytes();
+
+				if (remainingData[0]==0x52 && remainingData[1]==0x65 && remainingData[2]==0x6C && remainingData[3]==0x69)
+				{
+					MemoryStream ms = new MemoryStream(remainingData);
+					BinaryReader br2 = new BinaryReader(ms);
+					ChunkyStructureCollection col = ReadChunkyFileStructure(br2);
+
+					foreach (RelicChunkyStructure strct in col)
+					{
+						structCol.Add(strct);
+					}
+				}
+				else
+				{
+					ChunkyCollection col = new ChunkyCollection();
+					col.Add(new ChunkyRawData(remainingData));
+					structCol.Add(new RelicChunkyStructure(col));
+				}
+			}
+
+			return structCol;
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="start"></param>
+		/// <param name="length"></param>
+		/// <returns></returns>
+		private static string ReadString(BinaryReader br, int start, int length)
+		{
+			StringBuilder str = new StringBuilder();
+			byte tempByte = 0;
+			br.BaseStream.Seek(start, SeekOrigin.Begin);
+
+			if (length>0)
+			{
+				for (int i = 0; i<length; i++)
+				{
+					tempByte = br.ReadByte();
+
+					if (tempByte>=30)
+						str.Append((char)tempByte);
+				}
+			}
+			else
+			{
+				try
+				{
+					do 
+					{
+						tempByte = br.ReadByte();
+
+						if (tempByte>=30)
+							str.Append((char)tempByte);
+
+					} while (tempByte!=0);
+				}
+				catch{}
+			}
+
+			return str.ToString();
+		}
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RelicChunkyStructure.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,95 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using System.Text;
+using IBBoard.Relic.RelicTools;
+using IBBoard.Relic.RelicTools.Collections;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for RelicChunkyStructure.
+	/// </summary>
+	public class RelicChunkyStructure
+	{
+		protected ChunkyCollection chunkCol;
+		int unknownInt1;
+		int unknownInt2;
+		int unknownInt3;
+		
+		public static readonly byte[] ChunkyHeader = new byte[]{0x52, 0x65, 0x6C, 0x69, 0x63, 0x20, 0x43, 0x68, 0x75, 0x6E, 0x6B, 0x79, 0x0D, 0x0A, 0x1A, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
+
+		public RelicChunkyStructure(ChunkyFolder chunkyRoot):this(chunkyRoot, 0, 0, 0){}
+
+		public RelicChunkyStructure(ChunkyFolder chunkyRoot, int unknown1, int unknown2, int unknown3)
+		{
+			chunkCol = new ChunkyCollection();
+			chunkCol.Add(chunkyRoot);
+			unknownInt1 = unknown1;
+			unknownInt2 = unknown2;
+			unknownInt3 = unknown3;
+		}
+
+		public RelicChunkyStructure(ChunkyCollection col):this(col, 0, 0, 0){}
+
+		public RelicChunkyStructure(ChunkyCollection col, int unknown1, int unknown2, int unknown3)
+		{
+			chunkCol = col;
+			unknownInt1 = unknown1;
+			unknownInt2 = unknown2;
+			unknownInt3 = unknown3;
+		}
+
+		public RelicChunkyFile ParentFile
+		{
+			get{ return (chunkCol.Count>0)?chunkCol[0].ParentFile:null;  }
+			set{
+				for (int i = 0; i<chunkCol.Count; i++)
+				{
+					chunkCol[i].ParentFile = value;
+				}
+			}
+		}
+
+		public ChunkyCollection RootChunks
+		{
+			get{ return chunkCol; }
+		}
+
+		public void Save(BinaryWriter bw)
+		{			
+			bw.Write(ChunkyHeader);
+
+			foreach(ChunkyChunk chunk in RootChunks)
+			{
+				bw.Write(chunk.GetBytes());
+			}
+		}
+		
+		public string GetValidationString()
+		{
+			int childCount = this.RootChunks.Count;
+
+			if (childCount>1)
+			{
+				StringBuilder sb = new StringBuilder();
+				childCount--;
+
+				for (int i = 0; i<childCount; i++)
+				{
+					sb.Append(RootChunks[i].GetValidationString()+" ");
+				}
+
+				sb.Append(RootChunks[childCount].GetValidationString());
+
+				return sb.ToString();
+			}
+			else
+			{
+				return RootChunks[0].GetValidationString();
+			}
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RelicTools.csproj	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,239 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <ProjectType>Local</ProjectType>
+    <ProductVersion>8.0.50727</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{D3B2F94E-ADE9-45E1-829F-698C0F4F1CFC}</ProjectGuid>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyKeyContainerName>
+    </AssemblyKeyContainerName>
+    <AssemblyName>IBBoard.Relic.RelicTools</AssemblyName>
+    <DefaultClientScript>JScript</DefaultClientScript>
+    <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
+    <DefaultTargetSchema>IE50</DefaultTargetSchema>
+    <DelaySign>false</DelaySign>
+    <OutputType>Library</OutputType>
+    <RootNamespace>IBBoard.Relic.RelicTools</RootNamespace>
+    <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
+    <FileUpgradeFlags>
+    </FileUpgradeFlags>
+    <UpgradeBackupLocation>
+    </UpgradeBackupLocation>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <OutputPath>bin\Debug\</OutputPath>
+    <BaseAddress>285212672</BaseAddress>
+    <ConfigurationOverrideFile>
+    </ConfigurationOverrideFile>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DocumentationFile>
+    </DocumentationFile>
+    <DebugSymbols>true</DebugSymbols>
+    <FileAlignment>4096</FileAlignment>
+    <Optimize>false</Optimize>
+    <RegisterForComInterop>false</RegisterForComInterop>
+    <RemoveIntegerChecks>false</RemoveIntegerChecks>
+    <WarningLevel>4</WarningLevel>
+    <DebugType>full</DebugType>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <OutputPath>bin\Release\</OutputPath>
+    <BaseAddress>285212672</BaseAddress>
+    <ConfigurationOverrideFile>
+    </ConfigurationOverrideFile>
+    <DefineConstants>TRACE</DefineConstants>
+    <DocumentationFile>
+    </DocumentationFile>
+    <FileAlignment>4096</FileAlignment>
+    <Optimize>true</Optimize>
+    <RegisterForComInterop>false</RegisterForComInterop>
+    <RemoveIntegerChecks>false</RemoveIntegerChecks>
+    <WarningLevel>4</WarningLevel>
+    <DebugType>none</DebugType>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="ICSharpCode.SharpZipLib, Version=0.84.0.0, Culture=neutral, PublicKeyToken=1b03e6acf1164f73">
+      <HintPath>Compression\ICSharpCode.SharpZipLib.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="AssemblyInfo.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyChunk.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyData.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataATTR.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataCHAN.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataDATA.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataDATAIMAG.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataFBIF.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataHEAD.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataINFO.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataINFOGeneric.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataINFOSHDR.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataINFOTPAT.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataINFOTXTR.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataLayer.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataPTBD.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataPTBN.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataPTLD.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataSSHR.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyDataUnknown.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyFolder.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyRawData.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="ChunkyValidator.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Collections\ChunkyCollection.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Collections\ChunkyStructureCollection.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Collections\SgaFileCollection.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Collections\SgaFolderCollection.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Exceptions\Exception.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Exceptions\FileExistsException.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Exceptions\FileNotFoundException.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Exceptions\FileNotZippedException.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Exceptions\InvalidChunkException.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Exceptions\InvalidChunkValueException.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Exceptions\InvalidFileException.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Exceptions\InvalidSourceFileException.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Exceptions\InvalidUseException.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="FileFormats.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="LayerCollection.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="RECFile.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="RelicBinaryReader.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="RelicChunkReader.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="RelicChunkyFile.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="RelicChunkyReader.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="RelicChunkyStructure.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="RSHFile.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="RTXFile.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="SgaArchive.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="SgaFile.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="SgaFolder.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="SgaReader.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="WTPFile.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Content Include="Compression\ICSharpCode.SharpZipLib.dll" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+  <PropertyGroup>
+    <PreBuildEvent>
+    </PreBuildEvent>
+    <PostBuildEvent>
+    </PostBuildEvent>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\dev\IBBoard\IBBoard.csproj">
+      <Project>{5DFD64F6-FC2B-4B4F-B92E-483BAC468105}</Project>
+      <Name>IBBoard</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\dev\IBBoard.Graphics\IBBoard.Graphics.csproj">
+      <Project>{7CCF5C77-6038-45DE-BFA7-1A5378B3E08B}</Project>
+      <Name>IBBoard.Graphics</Name>
+    </ProjectReference>
+  </ItemGroup>
+</Project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RelicTools.csproj.user	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,58 @@
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <LastOpenVersion>7.10.3077</LastOpenVersion>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ReferencePath>
+    </ReferencePath>
+    <CopyProjectDestinationFolder>
+    </CopyProjectDestinationFolder>
+    <CopyProjectUncPath>
+    </CopyProjectUncPath>
+    <CopyProjectOption>0</CopyProjectOption>
+    <ProjectView>ProjectFiles</ProjectView>
+    <ProjectTrust>0</ProjectTrust>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <EnableASPDebugging>false</EnableASPDebugging>
+    <EnableASPXDebugging>false</EnableASPXDebugging>
+    <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
+    <EnableSQLServerDebugging>false</EnableSQLServerDebugging>
+    <RemoteDebugEnabled>false</RemoteDebugEnabled>
+    <RemoteDebugMachine>
+    </RemoteDebugMachine>
+    <StartAction>Project</StartAction>
+    <StartArguments>
+    </StartArguments>
+    <StartPage>
+    </StartPage>
+    <StartProgram>
+    </StartProgram>
+    <StartURL>
+    </StartURL>
+    <StartWorkingDirectory>
+    </StartWorkingDirectory>
+    <StartWithIE>false</StartWithIE>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <EnableASPDebugging>false</EnableASPDebugging>
+    <EnableASPXDebugging>false</EnableASPXDebugging>
+    <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
+    <EnableSQLServerDebugging>false</EnableSQLServerDebugging>
+    <RemoteDebugEnabled>false</RemoteDebugEnabled>
+    <RemoteDebugMachine>
+    </RemoteDebugMachine>
+    <StartAction>Project</StartAction>
+    <StartArguments>
+    </StartArguments>
+    <StartPage>
+    </StartPage>
+    <StartProgram>
+    </StartProgram>
+    <StartURL>
+    </StartURL>
+    <StartWorkingDirectory>
+    </StartWorkingDirectory>
+    <StartWithIE>false</StartWithIE>
+  </PropertyGroup>
+</Project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SgaArchive.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,669 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+
+using System;
+using System.IO;
+using System.Collections;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for SgaArchive.
+	/// </summary>
+	public class SgaArchive
+	{
+		private string path = "";
+		private readonly Hashtable attrib;
+		private SgaReader sr = null;
+		private SgaFolder root = null;
+		private FileInfo file = null;
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="pathIn"></param>
+		public SgaArchive(string pathIn)
+		{
+			path = pathIn;
+			file = new FileInfo(this.path);
+			sr = new SgaReader(path);
+			sr.Archive = this;
+			attrib = sr.ReadHeaders();
+			root = sr.ReadFolders((long)attrib["DirOffset"], (long)attrib["ItemOffset"], attrib["TocAlias"].ToString());
+			root.ParentArchive = this;
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		public SgaReader ArchiveReader
+		{
+			get{ return sr; }
+		}
+
+		public string Name
+		{
+			get{ return file.Name; }
+		}
+
+		public SgaFolder Root
+		{
+			get{return root;}
+		}
+
+		public int Version
+		{
+			get { return (int)(long)attrib["Version"]; }
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		public Hashtable Attributes
+		{
+			get{ return attrib; }
+		}
+
+		public string DefaultPath
+		{
+			get{ return file.DirectoryName+Path.DirectorySeparatorChar+attrib["TocAlias"]; }
+		}
+
+		public string BasePath
+		{
+			get{ return file.DirectoryName; }
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		public bool ExtractAll()
+		{
+			return ExtractAll(this.DefaultPath);
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="overwrite"></param>
+		public bool ExtractAll(bool overwrite)
+		{
+			return ExtractAll(this.DefaultPath, overwrite);
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="destination"></param>
+		public bool ExtractAll(string destination)
+		{
+			return ExtractAll(destination, false);
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="desintation"></param>
+		/// <param name="overwrite"></param>
+		public bool ExtractAll(string desintation, bool overwrite)
+		{
+			return ExtractFolder("",desintation, true, overwrite);
+		}
+
+		/// <summary>
+		/// Extracts the specified folder to it's default location
+		/// </summary>
+		/// <param name="folderPath">The path of the folder to extract</param>
+		public bool ExtractFolder(string folderPath)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractFolder(folderPath, this.DefaultPath+"\\"+folderPath);
+		}
+
+		public bool ExtractFolder(string folderPath, string dest)
+		{
+			return ExtractFolder(folderPath, dest, false);
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="folderPath"></param>
+		/// <param name="recursive"></param>
+		public bool ExtractFolder(string folderPath, bool recursive)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractFolder(folderPath, this.DefaultPath+"\\"+folderPath, recursive);
+		}
+
+		public bool ExtractFolder(string folderPath, bool recursive, bool overwrite)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractFolder(folderPath, this.DefaultPath+"\\"+folderPath, recursive, overwrite);
+		}
+
+		
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="folderPath"></param>
+		/// <param name="destination"></param>
+		public bool ExtractFolder(string folderPath, string find, string replace)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractFolder(folderPath, this.DefaultPath+"\\"+folderPath, find, replace);
+		}
+
+		public bool ExtractFolder(string folderPath, string find, string replace, bool recursive)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractFolder(folderPath, this.DefaultPath+"\\"+folderPath, recursive, false);
+		}
+
+		public bool ExtractFolder(string folderPath, string find, string replace, bool recursive, bool overwrite)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractFolder(folderPath, this.DefaultPath+"\\"+folderPath, "", "", recursive, overwrite);
+		}
+
+		public bool ExtractFolder(string folderPath, string[] find, string[] replace)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractFolder(folderPath, this.DefaultPath+"\\"+folderPath, find, replace, false);
+		}
+
+		public bool ExtractFolder(string folderPath, string[] find, string[] replace, bool recursive)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractFolder(folderPath, this.DefaultPath+"\\"+folderPath, find, replace, recursive, false);
+		}
+
+		public bool ExtractFolder(string folderPath, string[] find, string[] replace, bool recursive, bool overwrite)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractFolder(folderPath, this.DefaultPath+"\\"+folderPath, find, replace, recursive, overwrite);
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="folderPath"></param>
+		/// <param name="destination"></param>
+		/// <param name="recursive"></param>
+		public bool ExtractFolder(string folderPath, string destination, bool recursive)
+		{
+			return ExtractFolder(folderPath, destination, recursive, false);
+		}
+
+		public bool ExtractFolder(string folderPath, string destination, bool recursive, bool overwrite)
+		{
+			return ExtractFolder(folderPath, destination, "", "", recursive, overwrite);
+		}
+
+		public bool ExtractFolder(string folderPath, string destination, string find, string replace)
+		{
+			return ExtractFolder(folderPath, destination, find, replace, false);
+		}
+
+		public bool ExtractFolder(string folderPath, string destination, string[] find, string[] replace)
+		{
+			return ExtractFolder(folderPath, destination, find, replace, false);
+		}
+
+		public bool ExtractFolder(string folderPath, string destination, string find, string replace, bool recursive)
+		{
+			return ExtractFolder(folderPath, destination, find, replace, recursive, false);
+		}
+
+		public bool ExtractFolder(string folderPath, string destination, string[] find, string[] replace, bool recursive)
+		{
+			return ExtractFolder(folderPath, destination, find, replace, recursive, false);
+		}
+
+		public bool ExtractFolder(string folderPath, string destination, string find, string replace, bool recursive, bool overwrite)
+		{
+			return ExtractFolder(folderPath, destination, new string[]{find}, new string[]{replace}, recursive, overwrite);
+		}
+
+		public bool ExtractFolder(string folderPath, string destination, string[] find, string[] replace, bool recursive, bool overwrite)
+		{
+			destination = destination.Replace('\\', Constants.DirectoryChar);
+			folderPath = folderPath.TrimEnd(Constants.DirectoryChar);
+			folderPath = TrimPath(folderPath);
+
+			SgaFolder container = root.DigFor(folderPath);
+			if (container!=null)
+			{
+				return container.ExtractAll(destination, find, replace, recursive, overwrite);
+			}
+			else
+			{
+				ExtractFolderFail(container, "path not found");
+				return false;
+			}
+		}
+
+		public bool ExtractType(string ext)
+		{
+			FileInfo file = new FileInfo(this.path);
+			return ExtractType(ext, "", this.DefaultPath, true);
+		}
+
+		public bool ExtractType(string ext, bool overwrite)
+		{
+			FileInfo file = new FileInfo(this.path);
+			return ExtractType(ext, "", this.DefaultPath, true, overwrite);
+		}
+
+		public bool ExtractType(string ext, string folderPath)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractType(ext, folderPath, this.DefaultPath+"\\"+folderPath);
+		}
+
+		public bool ExtractType(string ext, string folderPath, bool recursive)
+		{
+			folderPath = this.TrimPath(folderPath);
+			
+			return ExtractType(ext, folderPath, this.DefaultPath+"\\"+folderPath, recursive);
+		}
+
+		public bool ExtractType(string ext, string folderPath, bool recursive, bool overwrite)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractType(ext, folderPath, this.DefaultPath+"\\"+folderPath, recursive, overwrite);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string destination)
+		{
+			return ExtractType(ext, folderPath, destination, false);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string destination, bool recursive)
+		{
+			return ExtractType(ext, folderPath, destination, recursive, false);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string destination, bool recursive, bool overwrite)
+		{
+			return ExtractType(ext, folderPath, destination, "", "", recursive, overwrite);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string find, string replace)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractType(ext, folderPath, this.DefaultPath+"\\"+folderPath, find, replace,  false);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string find, string replace, bool recursive)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractType(ext, folderPath, this.DefaultPath+"\\"+folderPath, find, replace, recursive, false);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string find, string replace, bool recursive, bool overwrite)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractType(ext, folderPath, this.DefaultPath+"\\"+folderPath, find, replace, recursive, overwrite);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string[] find, string[] replace)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractType(ext, folderPath, this.DefaultPath+"\\"+folderPath, find, replace,  false);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string[] find, string[] replace, bool recursive)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractType(ext, folderPath, this.DefaultPath+"\\"+folderPath, find, replace, recursive, false);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string[] find, string[] replace, bool recursive, bool overwrite)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			return ExtractType(ext, folderPath, this.DefaultPath+"\\"+folderPath, find, replace, recursive, overwrite);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string destination, string[] find, string[] replace)
+		{
+			return ExtractType(ext, folderPath, destination, find, replace, false, false);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string destination, string find, string replace)
+		{
+			return ExtractType(ext, folderPath, destination, find, replace, false, false);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string destination, string[] find, string[] replace, bool recursive)
+		{
+			return ExtractType(ext, folderPath, destination, find, replace, recursive, false);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string destination, string find, string replace, bool recursive)
+		{
+			return ExtractType(ext, folderPath, destination, find, replace, recursive, false);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string destination, string find, string replace, bool recursive, bool overwrite)
+		{
+			return ExtractType(ext, folderPath, destination, new string[]{find}, new string[]{replace}, recursive, overwrite);
+		}
+
+		public bool ExtractType(string ext, string folderPath, string destination, string[] find, string[] replace, bool recursive, bool overwrite)
+		{
+			folderPath = this.TrimPath(folderPath);
+
+			SgaFolder container = root.DigFor(folderPath);
+			
+			if (container!=null)
+			{
+				return container.ExtractType(ext,destination, find, replace, recursive, overwrite);
+			}
+			else
+			{
+				ExtractFolderFail(null, "path not found");
+				return false;
+			}
+		}
+
+
+		public bool Extract(string filePath)
+		{
+			filePath = this.TrimPath(filePath);
+			
+			int lastSlash = filePath.LastIndexOf("\\");
+			int lastDot = filePath.LastIndexOf('.');
+			string folderPath = "";
+
+			if (lastDot==-1)
+			{
+				//Someone stole our dot!
+				ExtractFileFail(null, "Filename '"+filePath+"'did not contain an extension");
+				return false;
+			}
+			else
+			{
+				folderPath = filePath.Substring(0,lastSlash);
+			}
+
+			return Extract(filePath, this.DefaultPath+"\\"+folderPath, false);
+		}
+
+		public bool Extract(string filePath, bool overwrite)
+		{
+			filePath = this.TrimPath(filePath);
+			
+			int lastSlash = filePath.LastIndexOf("\\");
+			int lastDot = filePath.LastIndexOf('.');
+			string folderPath = "";
+
+			if (lastDot==-1)
+			{
+				//Someone stole our dot!
+				ExtractFileFail(null, "Filename '"+filePath+"'did not contain an extension");
+				return false;
+			}
+			else if (lastSlash>=0)
+			{
+				folderPath = filePath.Substring(0,lastSlash);
+			}
+
+			return Extract(filePath, this.DefaultPath+"\\"+folderPath, overwrite);
+		}
+
+		public bool Extract(string filePath, string find, string replace)
+		{
+			filePath = this.TrimPath(filePath);
+			
+			int lastSlash = filePath.LastIndexOf("\\");
+			int lastDot = filePath.LastIndexOf('.');
+			string folderPath = "";
+
+			if (lastDot==-1)
+			{
+				//Someone stole our dot!
+				ExtractFileFail(null, "Filename '"+filePath+"'did not contain an extension");
+				return false;
+			}
+			else
+			{
+				folderPath = filePath.Substring(0,lastSlash);
+			}
+
+			return Extract(filePath, this.DefaultPath+"\\"+folderPath, find, replace);
+		}
+
+		public bool Extract(string filePath, string find, string replace, bool overwrite)
+		{
+			filePath = this.TrimPath(filePath);
+			
+			int lastSlash = filePath.LastIndexOf("\\");
+			int lastDot = filePath.LastIndexOf('.');
+			string folderPath = "";
+
+			if (lastDot==-1)
+			{
+				//Someone stole our dot!
+				ExtractFileFail(null, "Filename '"+filePath+"'did not contain an extension");
+				return false;
+			}
+			else
+			{
+				folderPath = filePath.Substring(0,lastSlash);
+			}
+
+			return Extract(filePath, this.DefaultPath+"\\"+folderPath, find, replace, overwrite);
+		}
+
+		public bool Extract(string filePath, string[] find, string[] replace)
+		{
+			filePath = this.TrimPath(filePath);
+			
+			int lastSlash = filePath.LastIndexOf("\\");
+			int lastDot = filePath.LastIndexOf('.');
+			string folderPath = "";
+
+			if (lastDot==-1)
+			{
+				//Someone stole our dot!
+				ExtractFileFail(null, "Filename '"+filePath+"'did not contain an extension");
+				return false;
+			}
+			else
+			{
+				folderPath = filePath.Substring(0,lastSlash);
+			}
+
+			return Extract(filePath, this.DefaultPath+"\\"+folderPath, find, replace, false);
+		}
+
+		public bool Extract(string filePath, string[] find, string[] replace, bool overwrite)
+		{
+			filePath = this.TrimPath(filePath);
+			
+			int lastSlash = filePath.LastIndexOf("\\");
+			int lastDot = filePath.LastIndexOf('.');
+			string folderPath = "";
+
+			if (lastDot==-1)
+			{
+				//Someone stole our dot!
+				ExtractFileFail(null, "Filename '"+filePath+"' did not contain an extension");
+				return false;
+			}
+			else
+			{
+				folderPath = filePath.Substring(0,lastSlash);
+			}
+
+			return Extract(filePath, this.DefaultPath+"\\"+folderPath, find, replace, overwrite);
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="filePath"></param>
+		/// <param name="destination"></param>
+		public bool Extract(string filePath, string destination)
+		{
+			return Extract(filePath, destination,"","", false);
+		}
+
+		public bool Extract(string filePath, string destination, bool overwrite)
+		{
+			return Extract(filePath, destination,"","", overwrite);
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="filePath"></param>
+		/// <param name="destination"></param>
+		/// <param name="find"></param>
+		/// <param name="replace"></param>
+		public bool Extract(string filePath, string destination, string find, string replace)
+		{
+			return Extract(filePath, destination, new string[]{find}, new string[]{replace});
+		}
+
+		public bool Extract(string filePath, string destination, string find, string replace, bool overwrite)
+		{
+			return Extract(filePath, destination, new string[]{find}, new string[]{replace}, overwrite);
+		}
+
+		public bool Extract(string filePath, string destination, string[] find, string[] replace)
+		{
+			return Extract(filePath, destination, find, replace, false);
+		}
+		public bool Extract(string filePath, string destination, string[] find, string[] replace, bool overwrite)
+		{
+			
+			if (destination.EndsWith("\\"))
+			{
+				destination = destination.TrimEnd('\\');
+			}
+
+			filePath = this.TrimPath(filePath);
+
+			int lastSlash = filePath.LastIndexOf('\\');
+			string folderPath = "";
+
+			if (lastSlash>-1)
+			{
+				folderPath = filePath.Substring(0, lastSlash);
+			}
+			
+			destination = destination.Replace('\\', Constants.DirectoryChar);
+			
+			SgaFolder container = root.DigFor(folderPath);
+
+			if (container!=null)
+			{
+				string fileName = filePath.Substring(filePath.LastIndexOf('\\')+1);
+				return container.Extract(fileName, destination, find, replace, overwrite);
+			}
+			else
+			{
+				ExtractFileFail(null, "path not found");
+				return false;
+				//throw exception
+			}
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="folderPath"></param>
+		/// <returns></returns>
+		public string TrimPath(string folderPath)
+		{
+			string temp = folderPath.ToLower();
+			string start = "\\"+(string)attrib["TocAlias"];
+
+			if (temp==start)
+			{
+				return "";
+			}
+			else if (temp.StartsWith(start))
+			{
+				return folderPath.Substring(start.Length+1);
+			}
+			else
+			{
+				return folderPath;
+			}
+		}
+
+		public delegate void ExtractionNotification(string type, string name, string message);
+
+		public event ExtractionNotification OnExtractFileFail;
+		public event ExtractionNotification OnExtractFileSuccess;
+		public event ExtractionNotification OnExtractFolderFail;
+		public event ExtractionNotification OnExtractFolderSuccess;
+		
+		public void ExtractFileFail(SgaFile file, string reason)
+		{
+			if (OnExtractFileFail!=null)
+			{
+				if (file==null)
+				{
+					OnExtractFileFail("File", "unknown", reason);
+				}
+				else
+				{
+					OnExtractFileFail("File", file.Name, reason);
+				}
+			}
+		}
+
+		public void ExtractFileSuccess(SgaFile file)
+		{
+			if (OnExtractFileSuccess!=null)
+			{
+				OnExtractFileSuccess("File", file.Name, "");
+			}
+		}
+
+		public void ExtractFolderFail(SgaFolder folder, string reason)
+		{
+			if (OnExtractFolderFail!=null)
+			{
+				if (folder==null)
+				{
+					OnExtractFolderFail("Folder", "unknown", reason);
+				}
+				else
+				{
+					OnExtractFolderFail("Folder", folder.Path, reason);
+				}
+			}
+		}
+
+		public void ExtractFolderSuccess(SgaFolder folder)
+		{
+			if (OnExtractFolderSuccess!=null)
+			{
+				OnExtractFolderSuccess("Folder", folder.Path, "");
+			}
+		}
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SgaFile.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,341 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.Collections;
+using System.IO;
+using System.Text;
+using ICSharpCode.SharpZipLib.GZip;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for SgaFile.
+	/// </summary>
+	public class SgaFile
+	{
+		public enum FileFormat {Unknown, LUA, WTP, RSH, RTX, WHM, WHE, RGD, EVENTS, AI, SCAR, NIL, TGA, DDS, SCREEN, NIS, RAT, SGB, CAMP, TURN, FDA, CON, TEAMCOLOUR, JPG, JPEG, BMP, SGM, STYLES, COLOURS, FNT, TTF, TXT}
+		public enum CompressionType{None, ZLibLarge, ZLibSmall, ZLib, UnknownCompression}
+
+		private Hashtable attrib = null;
+		private long id;
+		private SgaFolder parent = null;
+		private string name;
+		private string extension;
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="idNum"></param>
+		/// <param name="nameIn"></param>
+		/// <param name="attr"></param>
+		public SgaFile(long idNum, string nameIn, Hashtable attr)
+		{
+			attrib = attr;
+			id = idNum;
+			parent = null;
+			name = nameIn;
+			extension = name.Substring(name.LastIndexOf('.')+1).ToLower();
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		public SgaFolder Parent
+		{
+			get{ return parent; }
+			set
+			{
+				parent = value;  
+				parent.Files.Add(this);
+			}
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		public long ID 
+		{
+			get{ return id; }
+		}
+
+		public string Path
+		{
+			get
+			{
+				return parent.Path+this.Name;
+			}
+		}
+
+		public long Size
+		{
+			get	{ return (long)attrib["DataLength"];}
+		}
+
+		public long SizeUncompressed
+		{
+			get{ return (long)attrib["DataLengthCompressed"];}
+		}
+
+		public string Type
+		{
+			get{return extension;}
+		}
+
+		public string TypeDesc
+		{
+			get{return FileFormats.FormatAsString(extension);}
+		}
+
+		public FileFormat Format
+		{
+			get
+			{
+				try
+				{
+					return (FileFormat)Enum.Parse(typeof(FileFormat), this.Extension, true);
+				}
+				catch
+				{
+					return FileFormat.Unknown;
+				}
+			}
+		}
+
+		public CompressionType Compression
+		{
+			get
+			{
+				switch((long)attrib["Compression"])
+				{
+					case 0x00: return CompressionType.None;
+					case 0x10: return CompressionType.ZLibLarge;
+					case 0x20: return CompressionType.ZLibSmall;
+					case 0x30: return CompressionType.ZLib;
+					default: return CompressionType.UnknownCompression; //HACK: temporarily stop the exception
+						//throw new InvalidFileException("Invalid compression value found in SGA file");
+				}
+			}
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		public string Name
+		{
+			get{ return name;}
+		}
+
+		public string Extension
+		{
+			get { return extension; }
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="destination"></param>
+		public bool Save(string destination)
+		{
+			return Save(destination, false);
+		}
+
+		public bool Save(string destination, bool overwrite)
+		{
+			return Save(destination, "", "", overwrite);
+		}
+
+		public bool Save(string destination, string find, string replace)
+		{
+			return Save(destination, find, replace, false);
+		}
+
+		public bool Save(string destination, string[] find, string[] replace)
+		{
+			return Save(destination, find, replace, false);
+		}
+
+		public bool Save(string destination, string find, string replace, bool overwrite)
+		{
+			return Save(destination, new string[]{find}, new string[]{replace},overwrite);
+		}
+
+		public bool Save(string destination, string[] find, string[] replace, bool overwrite)
+		{
+			string outputFileName = "";
+
+			//if there is a dot before the last slash (or no dot, which returns -1)
+			//then we've been passed a folder to extract to, so the output file name is the current file name			
+			int lastSlash = destination.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
+			
+			if (destination.LastIndexOf('.') <= lastSlash)
+			{
+				outputFileName = name;
+			}
+			else
+			{
+				//if we can't find one of the slashes that Windows uses then look
+				//for a real folder slash
+				if (lastSlash==-1)
+				{
+					lastSlash = destination.LastIndexOf('/');
+				}
+
+				//if we didn't find one of those slashes either, then all we were given was a file name and no folder
+				if (lastSlash==-1)
+				{
+					outputFileName = destination;
+					destination = Environment.CurrentDirectory;
+				}
+				else
+				{					
+					outputFileName = destination.Substring(lastSlash+1);
+					destination = destination.Substring(0, lastSlash);
+				}
+				//otherwise we've been passed a file name to save to
+			}
+
+			DirectoryInfo dir = null;
+
+			if (!Directory.Exists(destination))
+			{
+				dir = Directory.CreateDirectory(destination);
+			}
+			else
+			{
+				dir = new DirectoryInfo(destination);
+
+				if (File.Exists(dir.FullName+System.IO.Path.DirectorySeparatorChar+outputFileName) && !overwrite)
+				{
+					//throw new FileExistsException(dir.FullName+Path.DirectorySeparatorChar+outputFileName);
+					//change the behaviour if a file exists so that it just fails and returns false instead of
+					//exceptioning and stopping further execution
+					this.Parent.ParentArchive.ExtractFileFail(this, "file already exists");
+					return false;
+				}
+			}
+
+			FileInfo file = new FileInfo(dir.FullName+System.IO.Path.DirectorySeparatorChar+outputFileName);
+			long dataOffset = (long)parent.ParentArchive.Attributes["DataOffest"];
+			long fileDataOffset = (long)attrib["DataOffset"];
+			long dataLength = (long)attrib["DataLength"];
+			long dataLengthCompressed = (long)attrib["DataLengthCompressed"];
+			byte[] bytes = null;
+			
+			if (dataLengthCompressed!=dataLength)
+			{
+				bytes = parent.ParentArchive.ArchiveReader.ReadFileDataZipped(dataOffset, fileDataOffset, dataLengthCompressed);
+			}
+			else
+			{
+				bytes = parent.ParentArchive.ArchiveReader.ReadFileData(dataOffset, fileDataOffset, dataLength);
+			}
+
+			if (find!=null && replace!=null)
+			{
+				for (int i = 0; i<find.Length; i++)
+				{
+					if (replace[i]!=null && find[i]!=null)
+					{
+						if (find[i]!="" && replace[i]!="" && find[i].Length==replace[i].Length)
+						{
+							//string tempString = Encoding.UTF8.GetString(bytes);
+							//tempString = tempString.Replace(find, replace);
+							//bytes = Encoding.UTF8.GetBytes(tempString);
+							bytes = Replace(bytes, find[i], replace[i]);
+						}
+						else if (find[i].Length!=replace[i].Length)
+						{
+//TODO: throw error here
+						}
+					}
+				}
+			}
+
+			BinaryWriter bw = new BinaryWriter(file.OpenWrite());
+			bw.Write(bytes);
+			bw.Flush();
+			bw.Close();		
+
+			this.Parent.ParentArchive.ExtractFileSuccess(this);
+
+			return true;
+		}
+
+		private byte[] Replace(byte[] data, string find, string replace)
+		{
+			if (replace!=null && find!=null && find!=replace)
+			{
+				byte[] findByte = new byte[find.Length];
+				for (int i = 0; i<find.Length; i++)
+				{
+					findByte[i] = Convert.ToByte(find[i]);
+				}
+
+				byte[] replaceByte = new byte[replace.Length];
+				for (int i = 0; i<replace.Length; i++)
+				{
+					replaceByte[i] = Convert.ToByte(replace[i]);
+				}
+
+
+				if (find!="" && replace!="" && find.Length==replace.Length)
+				{
+					int lastPos = data.Length - find.Length;
+					int matchPos = -1;
+					bool match = false;
+
+					for (int i =0; i<data.Length; i++)
+					{
+						if (data[i] == findByte[0])
+						{
+							matchPos = i;
+							match = true;
+
+							int j = 1;
+
+							for (j = 1; j < findByte.Length; j++)
+							{
+								if (data[i+j]==findByte[j])
+								{
+									continue;
+								}
+								else if (data[i+j]==findByte[0])
+								{
+									//if the data matches the start of the Find again
+									//then reduce J by one to make sure that the next pass
+									//doesn't skip over it
+									j--;
+									match = false;
+									break;
+								}
+								else
+								{
+									match = false;
+									break;
+								}
+							}
+
+							if (match)
+							{
+								for (int k = 0; k < replaceByte.Length; k++)
+								{
+									data[matchPos+k] = replaceByte[k];
+								}
+							}
+
+							i+= j;
+						}
+					}
+				}
+				else if (find.Length!=replace.Length)
+				{
+//TODO: throw error here
+				}
+			}
+
+			return data;
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SgaFolder.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,510 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+using System.Collections;
+
+using IBBoard.Relic.RelicTools.Collections;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for Class1.
+	/// </summary>
+	public class SgaFolder
+	{
+		private Hashtable attrib = null;
+		private long id;
+		private SgaFolder parent;
+		private SgaFolderCollection children;
+		private string name = "";
+		//private string path = "";
+		private SgaFileCollection files = null;
+		private SgaArchive archive = null;
+
+		/// <summary>
+		/// Initialises a new instance of a Folder within an SGA file with the specified ID and attributes
+		/// </summary>
+		/// <param name="idNum">A Long specifying the ID of the archive, as determined by the position in the Table of Contents</param>
+		/// <param name="attr">A Hashtable of attributes of the folder</param>
+		public SgaFolder(long idNum, Hashtable attr):this(idNum, "", attr){}
+
+		/// <summary>
+		/// Initialises a new instance of a Folder within an SGA file with the specified ID, path and attributes
+		/// </summary>
+		/// <param name="idNum">A Long specifying the ID of the archive, as determined by the position in the Table of Contents</param>
+		/// <param name="nameIn">A String specifying the path of the folder below the archive root</param>
+		/// <param name="attr">A Hashtable of attributes of the folder</param>
+		public SgaFolder(long idNum, string nameIn, Hashtable attr)
+		{
+			attrib = attr;
+			id = idNum;
+			children = new SgaFolderCollection();
+			files = null;
+			name = nameIn;
+
+			//path = pathIn;
+			//if (path.IndexOf(Path.DirectorySeparatorChar)>0)
+			//{
+				//name = path.Substring(path.LastIndexOf(Path.DirectorySeparatorChar)+1);
+			//}
+			//else
+			//{
+				//name = path;
+			//}
+		}
+
+		/// <summary>
+		/// Gets or sets the parent SgaFolder of this folder. Setting the parent also adds this folder as the child of the parent.
+		/// </summary>
+		public SgaFolder Parent
+		{
+			get{ return parent; }
+			set{
+				parent = value;
+				value.SubFolders.Add(this);
+			}
+		}
+
+		/// <summary>
+		/// Gets an SgaFolderCollection containing all of the SgaFolder objects that are children of this folder
+		/// </summary>
+		public SgaFolderCollection SubFolders
+		{
+			get{ return children; }
+		}
+
+		/// <summary>
+		/// Gets the ID of the folder, as specified by it's position in the Table of Contents of the archive
+		/// </summary>
+		public long ID 
+		{
+			get{ return id; }
+		}
+
+		/// <summary>
+		/// Gets an SgaFileCollection of the files within this folder.
+		/// </summary>
+		public SgaFileCollection Files
+		{
+			get
+			{
+				//use some simple caching so we don't need to load all of the files if we don't want to use them
+				if (files==null)
+				{
+					files = new SgaFileCollection();
+					FillFiles();
+				}
+				
+				return files;				
+			}
+		}
+
+		public string PathDisplayString
+		{
+			get
+			{
+				if (parent==null)
+				{
+					return name;
+				}
+				else
+				{
+					return parent.PathDisplayString + ">" + name;
+				}
+			}
+		}
+
+			/// <summary>
+			/// Gets or sets a reference to the SgaArchive that this folder is contained in. If no reference exists, then it is taken from the parent folder of this folder
+			/// </summary>
+		public SgaArchive ParentArchive
+		{
+			get
+			{
+				SgaArchive tempArchive;
+
+				if (this.archive!=null)
+				{
+					return this.archive;
+				}
+				else if ((tempArchive = this.Parent.ParentArchive)!=null)
+				{
+					return tempArchive;
+				}
+				else
+				{
+					throw new InvalidUseException("No Parent Archive found. SgaFolders should only be instantiated automatically through the creation of an SgaArchive object");
+				}
+			}
+			set
+			{
+				if (this.parent==null)
+				{
+					this.archive = value;
+
+					//if (this.Name==this.archive.Attributes["TocAlias"].ToString())
+					//{
+						//this.path = "";
+					//}
+				}
+			}
+		}
+
+		/// <summary>
+		/// Gets the name of the folder
+		/// </summary>
+		public string Name
+		{
+			get{ return name; } 
+		}
+
+		/// <summary>
+		/// Gets the full path of the folder within the archive
+		/// </summary>
+		public string InternalPath
+		{
+			get
+			{
+				if (this.Parent!=null)
+				{
+					return this.Parent.InternalPath+Name+"\\"; 
+				}
+				else
+				{
+					return "";
+				}
+			}
+		}
+
+		public string Path
+		{
+			get 
+			{
+				if (this.Parent!=null)
+				{
+					return "\\"+ParentArchive.Attributes["TocAlias"].ToString()+"\\"+this.InternalPath; 
+				}
+				else
+				{
+					return "\\"+ParentArchive.Attributes["TocAlias"].ToString()+"\\";
+				}
+			}
+		}
+
+		/// <summary>
+		/// Works down the folder hierarchy of the archive to retrieve the SgaFolder that matches the path requested.
+		/// </summary>
+		/// <param name="digPath">A string of the path to dig for (not including the root folder e.g. 'data')</param>
+		/// <returns>The SgaFolder object that represents the folder within the archive with the path specified</returns>
+		public SgaFolder DigFor(string digPath)
+		{
+			if (digPath!="" && !digPath.EndsWith("\\"))
+			{
+				digPath = digPath + "\\";
+			}
+
+			string path = this.InternalPath;
+
+			if (digPath == path)
+			{
+				return this;
+			}
+			else
+			{
+				if (SubFolders.Count>0)
+				{
+					foreach(SgaFolder subfolder in SubFolders.Values)
+					{
+						if (digPath==subfolder.InternalPath)
+						{
+							return subfolder;
+						}
+						else if (digPath.StartsWith(subfolder.InternalPath))
+						{
+							return subfolder.DigFor(digPath);
+						}
+					}
+
+					return null;
+				}
+				else
+				{
+					return null;
+				}
+			}
+		}
+
+		/// <summary>
+		/// Extracts a single file from within the folder to the destination specified
+		/// </summary>
+		/// <param name="fileName">A string representing the file name to extract</param>
+		/// <param name="destination">A string representing the destination folder to save the file to</param>
+		public bool Extract(string fileName, string destination)
+		{
+			return Extract(fileName, destination,"","");
+		}
+
+		/// <summary>
+		/// Extracts a single file from within the folder to the destination specified, with the ability to force an overwrite of the file
+		/// </summary>
+		/// <param name="fileName">A string representing the file name to extract</param>
+		/// <param name="destination">A string representing the destination folder to save the file to</param>
+		/// <param name="overwrite">A boolean to specify whether to overwrite the file if it exists in the destination. This function will Exception if false is specified and the file exists.</param>
+		public bool Extract(string fileName, string destination, bool overwrite)
+		{
+			return Extract(fileName, destination,"","", overwrite);
+		}
+
+		/// <summary>
+		/// Extracts a single file from within the folder to the destination specified, with the ability to find and replace a string within the file.  This is useful for replacing race names when RSH or WHM files are being used for cloned races
+		/// </summary>
+		/// <param name="fileName">A string representing the file name to extract</param>
+		/// <param name="destination">A string representing the destination folder to save the file to</param>
+		/// <param name="find">A string representing the string to find in the code</param>
+		/// <param name="replace">A string, which must be the same length as find, representing the string to replace the found matches with</param>
+		public bool Extract(string fileName, string destination, string find, string replace)
+		{
+			return Extract(fileName, destination, find, replace, false);
+		}
+
+		public bool Extract(string fileName, string destination, string[] find, string[] replace)
+		{
+			return Extract(fileName, destination, find, replace, false);
+		}
+
+		/// <summary>
+		/// Extracts a single file from within the folder to the destination specified, with the ability to find and replace a string within the file and force an overwrite of the file.  Find and Replace is useful for replacing race names when RSH or WHM files are being used for cloned races
+		/// </summary>
+		/// <param name="fileName">A string representing the file name to extract</param>
+		/// <param name="destination">A string representing the destination folder to save the file to</param>
+		/// <param name="find">A string representing the string to find in the code</param>
+		/// <param name="replace">A string, which must be the same length as find, representing the string to replace the found matches with</param>
+		/// <param name="overwrite">A boolean to specify whether to overwrite the file if it exists in the destination. This function will Exception if false is specified and the file exists.</param>
+		public bool Extract(string fileName, string destination, string find, string replace, bool overwrite)
+		{
+			return Extract(fileName, destination, new string[]{find}, new string[]{replace}, overwrite);
+		}
+
+		public bool Extract(string fileName, string destination, string[] find, string[] replace, bool overwrite)
+		{
+			SgaFile file = this.Files[fileName];
+			return file.Save(destination, find, replace, overwrite);
+		}
+
+		public bool ExtractType(string ext, string destination)
+		{
+			return ExtractType(ext, destination, false);
+		}
+
+		public bool ExtractType(string ext, string destination, bool recursive)
+		{
+			return ExtractType(ext, destination, recursive, false);
+		}
+
+		/// <summary>
+		/// Extracts all of the files that have the specified extention within the folder to the destination specified. 
+		/// </summary>
+		/// <param name="ext">A string representing the extension to extract (does not include preceeding ".")</param>
+		/// <param name="destination">A string representing the destination folder to save the file to</param>
+		/// <param name="recursive">A boolean to define whether sub-folders should also be extracted</param>
+		/// <param name="overwrite">A boolean to specify whether to overwrite the file if it exists in the destination. This function will Exception if false is specified and the file exists.</param>
+		public bool ExtractType(string ext, string destination, bool recursive, bool overwrite)
+		{
+			return ExtractType(ext, destination, "","", recursive, overwrite);
+		}
+
+		public bool ExtractType(string ext, string destination, string find, string replace)
+		{
+			return ExtractType(ext, destination, find, replace, false);
+		}
+
+		public bool ExtractType(string ext, string destination, string find, string replace, bool recursive)
+		{
+			return ExtractType(ext, destination, find, replace, recursive, false);
+		}
+
+		public bool ExtractType(string ext, string destination, string[] find, string[] replace)
+		{
+			return ExtractType(ext, destination, find, replace, false);
+		}
+
+		public bool ExtractType(string ext, string destination, string[] find, string[] replace, bool recursive)
+		{
+			return ExtractType(ext, destination, find, replace, recursive, false);
+		}
+
+		public bool ExtractType(string ext, string destination, string find, string replace, bool recursive, bool overwrite)
+		{
+			return ExtractType(ext, destination, new string[]{find}, new string[]{replace}, recursive, overwrite);
+		}
+
+		public bool ExtractType(string ext, string destination, string[] find, string[] replace, bool recursive, bool overwrite)
+		{
+			if (destination.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
+			{
+				destination = destination.TrimEnd(System.IO.Path.DirectorySeparatorChar);
+			}
+
+			bool success = true;
+			bool temp = false;
+
+			if (recursive && this.SubFolders.Count>0)
+			{
+				foreach (SgaFolder subfolder in this.SubFolders.Values)
+				{
+					temp = subfolder.ExtractType(ext, destination+System.IO.Path.DirectorySeparatorChar+subfolder.Name, find, replace, recursive, overwrite);
+					success = success && temp;
+				}
+			}
+
+			ext = ext.ToLower();
+
+			//trim the dot if someone ignored us and included it anyway
+			if (ext[0]=='.')
+			{
+				ext = ext.Substring(1);
+			}
+
+
+			foreach (SgaFile file in this.Files.Values)
+			{
+				if (file.Extension==ext)
+				{
+					//separate the return and the anding out, because .Net doesn't go into the other files
+					//once it hits the first "false" because it knows "false && anything" = false and so isn't
+					//worth evaluating
+					temp = file.Save(destination, find, replace, overwrite);
+					success = success && temp;
+				}
+			}
+
+			if (success)
+			{
+				this.ParentArchive.ExtractFolderSuccess(this);
+			}
+			else
+			{
+				this.ParentArchive.ExtractFolderFail(this, "one or more files failed to extract");
+			}
+
+			return success;
+		}
+
+		/// <summary>
+		/// Extracts all of the files within the folder to the destination specified, but not from sub-folders. 
+		/// </summary>
+		/// <param name="destination">A string representing the path that the files should be extracted in to</param>
+		public bool ExtractAll(string destination)
+		{
+			return ExtractAll(destination, false);
+		}
+
+		/// <summary>
+		/// Extracts all of the files within the folder to the destination specified. When called recursively, it
+		/// creates the folder structure of all folders below the current folder and extracts the files within them.
+		/// </summary>
+		/// <param name="destination">A string representing the path that the files should be extracted in to</param>
+		/// <param name="recursive">A boolean to define whether sub-folders should also be extracted</param>
+		public bool ExtractAll(string destination, bool recursive)
+		{
+			return ExtractAll(destination, recursive, false);
+		}
+
+		/// <summary>
+		/// Extracts all of the files within the folder to the destination specified. When called recursively, it
+		/// creates the folder structure of all folders below the current folder and extracts the files within them.
+		/// </summary>
+		/// <param name="destination"></param>
+		/// <param name="recursive"></param>
+		public bool ExtractAll(string destination, bool recursive, bool overwrite)
+		{
+			return ExtractAll(destination, "", "", recursive, overwrite);
+		}
+
+		public bool ExtractAll(string destination, string find, string replace)
+		{
+			return ExtractAll(destination, find, replace, false, false);
+		}
+
+		public bool ExtractAll(string destination, string[] find, string[] replace)
+		{
+			return ExtractAll(destination, find, replace, false, false);
+		}
+
+		public bool ExtractAll(string destination, string find, string replace, bool recursive)
+		{
+			return ExtractAll(destination, find, replace, recursive, false);
+		}
+
+		public bool ExtractAll(string destination, string[] find, string[] replace, bool recursive)
+		{
+			return ExtractAll(destination, find, replace, recursive, false);
+		}
+
+		public bool ExtractAll(string destination, string find, string replace, bool recursive, bool overwrite)
+		{
+			return ExtractAll(destination, new string[] {find}, new string[]{replace}, recursive, overwrite);
+		}
+
+		public bool ExtractAll(string destination, string[] find, string[] replace, bool recursive, bool overwrite)
+		{
+			if (destination.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
+			{
+				destination = destination.TrimEnd(System.IO.Path.DirectorySeparatorChar);
+			}
+
+			
+			bool success = true;
+			bool temp = false;
+
+			if (recursive && this.SubFolders.Count>0)
+			{
+				foreach (SgaFolder subfolder in this.SubFolders.Values)
+				{
+					temp = subfolder.ExtractAll(destination+System.IO.Path.DirectorySeparatorChar+subfolder.Name, find, replace, recursive, overwrite);
+					success = temp && success;
+				}
+			}
+
+
+			foreach (SgaFile file in this.Files.Values)
+			{
+				//separate the return and the anding out, because .Net doesn't go into the other files
+				//once it hits the first "false" because it knows "false && anything" = false and so isn't
+				//worth evaluating
+                temp = file.Save(destination, find, replace, overwrite);
+				success = success && temp;
+			}
+
+			if (success)
+			{
+				this.ParentArchive.ExtractFolderSuccess(this);
+			}
+			else
+			{
+				this.ParentArchive.ExtractFolderFail(this, "one or more files failed to extract");
+			}
+
+			return success;
+		}
+
+		private void FillFiles()
+		{
+			long startID = (long)attrib["FileIDBegin"];
+			long endID = (long)attrib["FileIDEnd"];
+			SgaArchive parentArchive = this.ParentArchive;
+			long itemOffset = (long)parentArchive.Attributes["ItemOffset"];
+			long fileOffset = (long)parentArchive.Attributes["FileOffset"];
+			SgaFile tempFile = null;
+
+			for (long i = startID; i<endID; i++)
+			{
+				tempFile = parentArchive.ArchiveReader.ReadFile(fileOffset, itemOffset,i);
+				tempFile.Parent = this;
+			}
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SgaReader.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,494 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.Collections;
+using System.IO;
+using System.Text;
+using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
+using IBBoard.Relic.RelicTools.Exceptions;
+
+/*
+ * struct _SgaHeader
+	{
+		char* sIdentifier; // 8 bytes
+		long iVersion;
+		long* iToolMD5; // 16 bytes
+		wchar_t* sArchiveType; // unicode (128 bytes - 64 * wchar)
+		long* iMD5; // MD5
+		long iDataHeaderSize;
+		long iDataOffset;
+
+		long iToCOffset;
+		short int iToCCount;
+		long iDirOffset;
+		short int iDirCount;
+		long iFileOffset;
+		short int iFileCount;
+		long iItemOffset;
+		short int iItemCount;
+	};
+
+	struct _SgaToC
+	{
+		char* sAlias; // 64 bytes
+		char* sBaseDirName; // 64 bytes
+		short int iStartDir;
+		short int iEndDir;
+		short int iStartFile;
+		short int iEndFile;
+		long iFolderOffset;
+	};
+
+	struct _SgaDirInfo
+	{
+		long iNameOffset;
+		short int iSubDirBegin;
+		short int iSubDirEnd;
+		short int iFileBegin;
+		short int iFileEnd;
+	};
+
+	struct _SgaFileInfo
+	{
+		long iNameOffset;
+		long iFlags; // 0x00 = uncompressed, 0x10 = zlib large file, 0x20 = zlib small file (< 4kb)
+		long iDataOffset;
+		long iDataLengthCompressed; //actually uncompressed size
+		long iDataLength;//actually compressed size
+	};
+	*/
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for SgaReader.
+	/// </summary>
+	public class SgaReader
+	{
+		private BinaryReader br = null;
+		private string path = "";
+		private FileInfo sga = null;
+		
+		public static readonly int FolderInfoLength = 12;
+		public static int FileInfoLength
+		{
+			get{ return fileInfoLength; }
+		}
+		public static int BaseOffset
+		{
+			get{ return baseOffset; }
+		}
+
+		private static int baseOffset;
+		private static int fileInfoLength;
+		private static SgaArchive archive;
+
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="pathIn"></param>
+		public SgaReader(string pathIn)
+		{
+			path = pathIn;
+
+			if (!File.Exists(path))
+			{
+				throw new RelicTools.Exceptions.FileNotFoundException();
+			}
+
+			sga = new FileInfo(path);
+		}
+
+		public SgaArchive Archive
+		{
+			get{ return archive; }
+			set{ archive = value; }
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <returns></returns>
+		public Hashtable ReadHeaders()
+		{
+			Hashtable ht = new Hashtable();
+
+			try
+			{
+				
+				FileStream input = sga.OpenRead();
+				br = new BinaryReader(input);
+
+				int pos = 0;
+
+				ht["AsciiIdent"] = ReadString(0, 8);
+				pos+=8;
+				ht["Version"] = ReadLong(pos,4);
+				pos+=4;
+				ht["ToolMD5"] = ReadString(pos,16);
+				pos+=16;
+				ht["UnicodeString"] = ReadString(pos,128);
+				pos+=128;
+				ht["MD5"] = ReadString(pos,16);
+				pos+=16;
+				ht["DataHeaderSize"] = ReadLong(pos,4);
+				pos+=4;
+				ht["DataOffest"] =  ReadLong(pos,4);
+				pos+=4;
+				ht["TocOffset"] = ReadLong(pos,4);
+				pos+=4;
+				ht["TocCount"] = ReadLong(pos,2);
+				pos+=2;
+
+				if ((long)ht["Version"]==4)
+				{
+					ht["Unknown"] = ReadLong(pos, 4);
+					pos+=4;
+					baseOffset = 184;
+					fileInfoLength = 22;
+				}
+				else
+				{
+					baseOffset = 180;
+					fileInfoLength = 20;
+				}
+
+				ht["DirOffset"] = ReadLong(pos,4);
+				pos+=4;
+				ht["DirCount"] = ReadLong(pos,2);
+				pos+=2;
+				ht["FileOffset"] = ReadLong(pos,4);
+				pos+=4;
+				ht["FileCount"] = ReadLong(pos,2);
+				pos+=2;
+				ht["ItemOffset"] = ReadLong(pos,4);
+				pos+=4;
+				ht["ItemCount"] = ReadLong(pos,2);
+				pos+=2;
+				ht["TocAlias"] = ReadString(pos,64);
+				pos+=64;
+				ht["TocStartName"] = ReadString(pos,64);
+				pos+=64;
+				ht["TocStartDir"] = ReadLong(pos,2);
+				pos+=2;
+				ht["TocEndDir"] = ReadLong(pos,2);
+				pos+=2;
+				ht["TocStartFile"] = ReadLong(pos,2);
+				pos+=2;
+				ht["TocEndFile"] = ReadLong(pos,2);
+				pos+=2;
+				ht["TocFolderOffset"] = ReadLong(pos,2);
+			}
+			finally
+			{
+				if (br!=null)
+				{
+					br.Close();
+				}
+			}
+			return ht;
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="dirOffset"></param>
+		/// <param name="itemOffset"></param>
+		/// <returns></returns>
+		public SgaFolder ReadFolders(long dirOffset, long itemOffset, string rootName)
+		{
+			SgaFolder root = null;
+			try
+			{
+				FileStream input = sga.OpenRead();
+				br = new BinaryReader(input);
+				Hashtable ht = new Hashtable();
+
+				ht["FolderNameOffset"] = ReadLong(dirOffset+BaseOffset, 4);
+				ht["SubDirIDBegin"] = ReadLong(dirOffset+BaseOffset+4, 2);
+				ht["SubDirIDEnd"] = ReadLong(dirOffset+BaseOffset+6, 2);
+				ht["FileIDBegin"] = ReadLong(dirOffset+BaseOffset+8, 2);
+				ht["FileIDEnd"] = ReadLong(dirOffset+BaseOffset+10, 2);
+
+				root = new SgaFolder(0, rootName, ht);
+				long startID = (long)ht["SubDirIDBegin"];
+				long endID = (long)ht["SubDirIDEnd"];
+
+				if (startID<endID)
+				{
+					SgaFolder tempFolder = null;
+					for (long i = startID; i < endID; i++)
+					{
+						tempFolder = ReadFolder(dirOffset, itemOffset, i);
+						tempFolder.Parent = root;
+					}
+				}
+			}
+			finally
+			{
+				br.Close();
+			}
+
+			return root;
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="dirOffset"></param>
+		/// <param name="itemOffset"></param>
+		/// <param name="folderID"></param>
+		/// <returns></returns>
+		public SgaFolder ReadFolder(long dirOffset, long itemOffset, long folderID)
+		{
+			SgaFolder folder = null;
+
+			Hashtable ht = new Hashtable();
+
+			ht["FolderNameOffset"] = ReadLong(dirOffset+BaseOffset+(FolderInfoLength*folderID), 4);
+			ht["SubDirIDBegin"] = ReadLong(dirOffset+BaseOffset+4+(FolderInfoLength*folderID), 2);
+			ht["SubDirIDEnd"] = ReadLong(dirOffset+BaseOffset+6+(FolderInfoLength*folderID), 2);
+			ht["FileIDBegin"] = ReadLong(dirOffset+BaseOffset+8+(FolderInfoLength*folderID), 2);
+			ht["FileIDEnd"] = ReadLong(dirOffset+BaseOffset+10+(FolderInfoLength*folderID), 2);
+
+			string tmpName = ReadString(itemOffset+BaseOffset+(long)ht["FolderNameOffset"], -1);
+			tmpName = tmpName.Substring(tmpName.LastIndexOf('\\')+1);
+
+			folder = new SgaFolder(folderID, tmpName, ht);
+			long startID = (long)ht["SubDirIDBegin"];
+			long endID = (long)ht["SubDirIDEnd"];
+
+			if (startID<endID)
+			{
+				SgaFolder tempFolder = null;
+				for (long i = startID; i < endID; i++)
+				{
+					tempFolder = ReadFolder(dirOffset, itemOffset, i);
+					tempFolder.Parent = folder;
+				}
+			}
+
+			return folder;
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="fileOffset"></param>
+		/// <param name="itemOffset"></param>
+		/// <param name="id"></param>
+		/// <returns></returns>
+		public SgaFile ReadFile(long fileOffset, long itemOffset, long id)
+		{
+			Hashtable ht = new Hashtable();
+			SgaFile file = null;
+			try
+			{
+				FileStream input = sga.OpenRead();
+				br = new BinaryReader(input);
+				long begin = fileOffset+BaseOffset+(id*FileInfoLength);
+				int pos = 0;
+
+				ht["FileNameOffset"] = ReadLong(begin,4);
+				pos+=4;
+
+				if (archive.Version==2)
+				{
+					ht["Compression"] = ReadLong(begin+pos,4);
+					pos+=4;
+				}
+				else
+				{
+					ht["Compression"] = 0L;
+				}
+
+				ht["DataOffset"] = ReadLong(begin+pos,4);
+				pos+=4;
+				ht["DataLength"] = ReadLong(begin+pos,4);
+				pos+=4;
+				ht["DataLengthCompressed"] = ReadLong(begin+pos,4);
+				pos+=4;
+
+				if (archive.Version==4)
+				{
+					ht["CRC"] = ReadLong(begin+pos,4);
+					pos+=4;
+					ht["Unknown"] = ReadLong(begin+pos, 2);
+					ht["Compression"] = ((long)ht["DataLength"] == (long)ht["DataLengthCompressed"] ? 0L : 0x30L);
+				}
+				else
+				{
+					ht["CRC"] = 0L;
+					ht["Unknown"] = 0L;
+				}
+
+				string tmpName = ReadString(BaseOffset+itemOffset+(long)ht["FileNameOffset"], -1);
+				file = new SgaFile(id, tmpName, ht);
+			}
+			finally
+			{
+				br.Close();
+			}
+			return file;
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="start"></param>
+		/// <param name="bytes"></param>
+		/// <returns></returns>
+		private string ReadString(long start, long bytes)
+		{
+			return ReadString(start, bytes, false);
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="start"></param>
+		/// <param name="bytes"></param>
+		/// <param name="unicode"></param>
+		/// <returns></returns>
+		private string ReadString(long start, long bytes, bool unicode)
+		{
+			StringBuilder str = new StringBuilder();
+			byte tempByte = 0;
+			br.BaseStream.Seek(start, SeekOrigin.Begin);
+
+			if (bytes>0)
+			{
+				for (long i = 0; i<bytes; i++)
+				{
+					tempByte = br.ReadByte();
+
+					if (tempByte>=30)
+						str.Append((char)tempByte);
+				
+					if (unicode)
+						i++;
+				}
+			}
+			else
+			{
+				try
+				{
+					do 
+					{
+						tempByte = br.ReadByte();
+
+						if (tempByte>=30)
+							str.Append((char)tempByte);
+
+					} while (tempByte!=0);
+				}
+				catch{}
+			}
+
+			return str.ToString();
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="start"></param>
+		/// <param name="bytes"></param>
+		/// <returns></returns>
+		private long ReadLong(long start, long bytes)
+		{
+
+			long tempLong = 0;
+			byte tempByte = 0;			
+			br.BaseStream.Seek(start, SeekOrigin.Begin);
+
+			for (long i = 0; i<bytes; i++)
+			{
+				tempByte = br.ReadByte();
+
+				tempLong = tempLong+(long)(tempByte*Math.Pow(256,i));
+			}
+
+			return tempLong;
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="dataOffset"></param>
+		/// <param name="fileDataOffset"></param>
+		/// <param name="bytes"></param>
+		/// <returns></returns>
+		public byte[] ReadFileData(long dataOffset, long fileDataOffset, long bytes)
+		{
+			try
+			{
+				FileStream input = sga.OpenRead();
+				br = new BinaryReader(input);
+				br.BaseStream.Seek(dataOffset+fileDataOffset, SeekOrigin.Begin);
+
+				if (bytes<=int.MaxValue)
+				{
+					return br.ReadBytes((int)bytes);
+				}
+				else
+				{
+					throw new RelicTools.Exceptions.Exception("File larger than 2GB!");
+				}
+			}
+			finally
+			{
+				br.Close();
+			}
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="dataOffset"></param>
+		/// <param name="fileDataOffset"></param>
+		/// <param name="bytes"></param>
+		/// <returns></returns>
+		public byte[] ReadFileDataZipped(long dataOffset, long fileDataOffset, long bytes)
+		{
+			InflaterInputStream zipped = null;
+			try
+			{
+				byte [] compressed = ReadFileData(dataOffset, fileDataOffset, bytes);
+				MemoryStream ms = new MemoryStream(compressed, 0, compressed.Length);
+				ms.Seek(0, SeekOrigin.Begin);
+				zipped = new InflaterInputStream(ms);
+				
+				if (bytes<=int.MaxValue)
+				{
+					byte[] byteArr = new byte[bytes];
+					int size = 0;
+					int offset = 0;
+
+					try
+					{
+						do
+						{
+							size = zipped.Read(byteArr, offset, byteArr.Length);
+							offset+= size;
+						} while (size > 0);
+					}
+					catch(RelicTools.Exceptions.Exception ex)
+					{
+						throw new FileNotZippedException(ex);
+					}
+
+					return byteArr;
+				}
+				else
+				{
+					throw new RelicTools.Exceptions.Exception("File larger than 2GB!");
+				}
+			}
+			finally
+			{
+				zipped.Close();
+			}
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WTPFile.cs	Sat Oct 06 19:49:25 2018 +0100
@@ -0,0 +1,683 @@
+// This file is a part of the Relic Tools and is copyright 2006-2018 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.Collections;
+using System.IO;
+using IBBoard.Graphics;
+using IBBoard.Relic.RelicTools.Exceptions;
+using IBBoard.Relic.RelicTools.Collections;
+
+namespace IBBoard.Relic.RelicTools
+{
+	/// <summary>
+	/// Summary description for WTPFile.
+	/// </summary>
+	public class WTPFile:RelicChunkyFile
+	{
+		int width = 0;
+		int height = 0;
+		ChunkyDataATTR attr = null;
+		
+		public WTPFile(string filename, ChunkyFolder folder)
+			:this(filename, new ChunkyStructureCollection(new RelicChunkyStructure(folder))){}
+		
+		public WTPFile(string filename, ChunkyCollection col)
+			:this(filename, new ChunkyStructureCollection(new RelicChunkyStructure(col))){}
+
+		public WTPFile(string filename, ChunkyStructureCollection col): base(filename, col)
+		{
+			ChunkyFolder folder = (ChunkyFolder)col[0].RootChunks[0];
+			int children = folder.Children.Count;
+			ChunkyChunk chunk = null;
+			ChunkyDataINFOTPAT info = null;
+
+			for (int i = 0; i<children; i++)
+			{
+				chunk = folder.Children[i];
+
+				if (chunk is ChunkyDataINFOTPAT)
+				{
+					info = (ChunkyDataINFOTPAT)chunk;
+					width = info.Width;
+					height = info.Height;
+				}
+			}
+		}
+
+		public void SaveParts(DirectoryInfo destination)
+		{
+			string filenamebase = filename.Substring(0, filename.LastIndexOf('.'));
+
+			saveFolder((ChunkyFolder)this.ChunkyStructures[0].RootChunks[0], destination, filenamebase);
+		}
+
+		private void saveFolder(ChunkyFolder folder, DirectoryInfo destination, string filenamebase)
+		{
+			int children = folder.Children.Count;
+			ChunkyChunk chunk = null;
+
+			for (int i = 0; i<children; i++)
+			{
+				chunk = folder.Children[i];
+
+				if (chunk is ChunkyData)
+				{
+					((ChunkyData)chunk).Save(destination, filenamebase);
+				}
+				else if (chunk is ChunkyFolder)
+				{
+					this.saveFolder((ChunkyFolder)chunk, destination, filenamebase);
+				}
+				//else something is wrong!
+
+				/*else if (chunk is ChunkyDataDATAIMAG)
+				{
+					((ChunkyDataDATAIMAG)chunk).Save(destination, filenamebase);
+				}
+				else if (chunk is ChunkyDataPTBD)
+				{
+					((ChunkyDataPTBD)chunk).Save(destination, filenamebase);
+				}
+				else if (chunk is ChunkyDataPTBN)
+				{
+					((ChunkyDataPTBN)chunk).Save(destination, filenamebase);
+				}*/
+			}
+		}
+
+		public static WTPFile Create(string filepath)
+		{
+			string baseFileName = filepath.Substring(filepath.LastIndexOf(Path.DirectorySeparatorChar)+1);
+			string baseFileNameLower = baseFileName.ToLower();
+
+			string directory = "";
+
+			if (filepath.IndexOf(Path.DirectorySeparatorChar)!=-1)
+			{
+				directory = filepath.Substring(0, filepath.LastIndexOf(Path.DirectorySeparatorChar))+Path.DirectorySeparatorChar;
+			}
+
+			if (baseFileNameLower.EndsWith(".wtp"))
+			{
+				baseFileName = baseFileName.Substring(0, baseFileName.Length-4);
+			}
+			else if(baseFileNameLower.EndsWith(".tga"))
+			{
+
+				if (baseFileNameLower.EndsWith("_primary.tga"))
+				{
+					baseFileName = baseFileName.Substring(0, baseFileName.Length-12);
+				}
+				else if (baseFileNameLower.EndsWith("_secondary.tga"))
+				{
+					baseFileName = baseFileName.Substring(0, baseFileName.Length-14);
+				}
+				else if (baseFileNameLower.EndsWith("_weapon.tga")||baseFileNameLower.EndsWith("_banner.tga"))
+				{
+					baseFileName = baseFileName.Substring(0, baseFileName.Length-11);
+				}
+				else if (baseFileNameLower.EndsWith("_badge.tga"))
+				{
+					baseFileName = baseFileName.Substring(0, baseFileName.Length-10);
+				}
+				else if (baseFileNameLower.EndsWith("_eyes.tga") || baseFileNameLower.EndsWith("_trim.tga") || baseFileNameLower.EndsWith("_dirt.tga"))
+				{
+					baseFileName = baseFileName.Substring(0, baseFileName.Length-9);
+				}
+				else
+				{					
+					baseFileName = baseFileName.Substring(0, baseFileName.Length-4);
+				}
+			}
+			else
+			{
+				throw new InvalidFileException("File path specified is not valid for a WTP file or one of its components");
+			}
+
+			string skinName = baseFileName.Substring(baseFileName.LastIndexOf('_')+1);//make it forwards compatible on the off-chance Relic introduce multiple textures
+
+			ChunkyDataDATA defaultData = null;
+			ChunkyData attr = null;
+			FileStream fs = null;
+			BinaryReader br = null;
+			FileInfo file = null;
+			byte [] data;
+
+			int width = 0;
+			int height = 0;
+
+			if (File.Exists(directory+baseFileName+".tga"))
+			{
+				CompilationEvent("Reading "+baseFileName+".tga");
+				file = new FileInfo(directory+baseFileName+".tga");
+				fs = file.OpenRead();
+				br = new BinaryReader(fs);
+				br.BaseStream.Seek(12,SeekOrigin.Begin);
+				width = br.ReadInt16();
+				height = br.ReadInt16();
+				br.BaseStream.Seek(0, SeekOrigin.Begin);
+				data = br.ReadBytes((int)br.BaseStream.Length);
+
+				defaultData = ChunkyDataDATAIMAG.CreateFromTGA(2, "", data);				
+				
+				br.Close();
+				data = new byte[]{0x0, 0x0, 0x0, 0x0, (byte)width, (byte)(width>>8), (byte)(width>>16), (byte)(width>>24), (byte)(height), (byte)(height>>8), (byte)(height>>16), (byte)(height>>24), 0x1, 0x0, 0x0, 0x0};
+				attr = new ChunkyDataUnknown("ATTR", 2, "", data);
+			}
+			else
+			{
+				throw new RelicTools.Exceptions.FileNotFoundException("WTP files must have a 32bit layer e.g. _default.tga layer");
+			}
+
+			string dirt_name = directory+baseFileName+"_Dirt.tga";
+
+			ChunkyFolder defaultFolder = new ChunkyFolder("IMAG", 1, "TOOL:"+dirt_name);
+
+			defaultFolder.Children.Add(attr);
+			defaultFolder.Children.Add(defaultData);
+
+			ChunkyDataPTLD primary = null;
+			ChunkyDataPTLD secondary = null;
+			ChunkyDataPTLD trim = null;
+			ChunkyDataPTLD weapon = null;
+			ChunkyDataPTLD eyes = null;
+			ChunkyDataPTLD dirt = null;
+			ChunkyDataPTBD badge = null;
+			ChunkyDataPTBN banner = null;
+			string primaryname = directory+baseFileName+"_Primary.tga";
+			string secondaryname = directory+baseFileName+"_Secondary.tga";
+			string trimname = directory+baseFileName+"_Trim.tga";
+			string weaponname = directory+baseFileName+"_Weapon.tga";
+			string eyesname = directory+baseFileName+"_Eyes.tga";
+			string badgename = directory+baseFileName+"_Badge.tga";
+			string bannername = directory+baseFileName+"_Banner.tga";
+
+			//int byteRead = width*height+18;//length of TGA data plus header
+			
+			if (File.Exists(dirt_name))
+			{
+				CompilationEvent("Reading "+baseFileName+"_Dirt.tga");
+				file = new FileInfo(dirt_name);
+				fs = file.OpenRead();
+				br = new BinaryReader(fs);
+				br.BaseStream.Seek(0, SeekOrigin.Begin);
+				
+				data = br.ReadBytes((int)br.BaseStream.Length);
+				br.Close();
+
+				dirt = ChunkyDataPTLD.CreateFromTGA(PTLD_Layers.Dirt, 1, "", data);
+			}
+			else
+			{
+				throw new RelicTools.Exceptions.FileNotFoundException("WTP Files must contain a dirt layer");
+			}
+
+			data = new byte[8];
+			data[0] = (byte)(width);
+			data[1] = (byte)(width >> 8);
+			data[2] = (byte)(width >> 16);
+			data[3] = (byte)(width >> 24);
+			data[4] = (byte)(height);
+			data[5] = (byte)(height >> 8);
+			data[6] = (byte)(height >> 16);
+			data[7] = (byte)(height >> 24);
+
+			ChunkyData info = new ChunkyDataUnknown("INFO", 1, "", data);
+
+			if (File.Exists(primaryname))
+			{
+				CompilationEvent("Reading "+baseFileName+"_Primary.tga");
+				file = new FileInfo(primaryname);
+				fs = file.OpenRead();
+				br = new BinaryReader(fs);
+				br.BaseStream.Seek(0, SeekOrigin.Begin);
+				
+				data = br.ReadBytes((int)br.BaseStream.Length);
+				br.Close();
+
+				primary = ChunkyDataPTLD.CreateFromTGA(PTLD_Layers.Primary, 1, "", data);
+
+				if (primary==null)
+				{
+					CompilationEvent("Skipped "+baseFileName+"_Primary.tga - no team colour data");
+				}
+			}
+
+			if (File.Exists(secondaryname))
+			{
+				CompilationEvent("Reading "+baseFileName+"_Secondary.tga");
+				file = new FileInfo(secondaryname);
+				fs = file.OpenRead();
+				br = new BinaryReader(fs);
+				br.BaseStream.Seek(0, SeekOrigin.Begin);
+				
+				data = br.ReadBytes((int)br.BaseStream.Length);
+				br.Close();
+
+				secondary = ChunkyDataPTLD.CreateFromTGA(PTLD_Layers.Secondary, 1, "", data);
+
+				if (secondary==null)
+				{
+					CompilationEvent("Skipped "+baseFileName+"_Secondary.tga - no team colour data");
+				}
+			}
+
+			if (File.Exists(trimname))
+			{
+				CompilationEvent("Reading "+baseFileName+"_Trim.tga");
+				file = new FileInfo(trimname);
+				fs = file.OpenRead();
+				br = new BinaryReader(fs);
+				br.BaseStream.Seek(0, SeekOrigin.Begin);
+				
+				data = br.ReadBytes((int)br.BaseStream.Length);
+				br.Close();
+
+				trim = ChunkyDataPTLD.CreateFromTGA(PTLD_Layers.Trim, 1, "", data);
+
+				if (trim==null)
+				{
+					CompilationEvent("Skipped "+baseFileName+"_Trim.tga - no team colour data");
+				}
+			}
+
+			if (File.Exists(weaponname))
+			{
+				CompilationEvent("Reading "+baseFileName+"_Weapon.tga");
+				file = new FileInfo(weaponname);
+				fs = file.OpenRead();
+				br = new BinaryReader(fs);
+				br.BaseStream.Seek(0, SeekOrigin.Begin);
+				
+				data = br.ReadBytes((int)br.BaseStream.Length);
+				br.Close();
+
+				weapon = ChunkyDataPTLD.CreateFromTGA(PTLD_Layers.Weapon, 1, "", data);
+
+				if (weapon==null)
+				{
+					CompilationEvent("Skipped "+baseFileName+"_Weapon.tga - no team colour data");
+				}
+			}
+
+			if (File.Exists(eyesname))
+			{
+				CompilationEvent("Reading "+baseFileName+"_Eyes.tga");
+				file = new FileInfo(eyesname);
+				fs = file.OpenRead();
+				br = new BinaryReader(fs);
+				br.BaseStream.Seek(0, SeekOrigin.Begin);
+				
+				data = br.ReadBytes((int)br.BaseStream.Length);
+				br.Close();
+
+				eyes = ChunkyDataPTLD.CreateFromTGA(PTLD_Layers.Eyes, 1, "", data);
+
+				if (eyes==null)
+				{
+					CompilationEvent("Skipped "+baseFileName+"_Eyes.tga - no team colour data");
+				}
+			}
+
+			if (File.Exists(badgename))
+			{
+				CompilationEvent("Reading "+baseFileName+"_Badge.tga");
+				file = new FileInfo(badgename);
+				fs = file.OpenRead();
+				br = new BinaryReader(fs);
+				br.BaseStream.Seek(0, SeekOrigin.Begin);
+				
+				data = br.ReadBytes((int)br.BaseStream.Length);
+				br.Close();
+
+				badge = ChunkyDataPTBD.CreateFromTGA(1, "", data);
+			}
+
+			if (File.Exists(bannername))
+			{
+				CompilationEvent("Reading "+baseFileName+"_Banner.tga");
+				file = new FileInfo(bannername);
+				fs = file.OpenRead();
+				br = new BinaryReader(fs);
+				br.BaseStream.Seek(0, SeekOrigin.Begin);
+				
+				data = br.ReadBytes((int)br.BaseStream.Length);
+				br.Close();
+
+				banner = ChunkyDataPTBN.CreateFromTGA(1, "", data);
+			}
+
+			if (badge!=null && banner!=null)
+			{
+				if (((badge.Pos_x<=banner.Pos_x && (badge.Pos_x+badge.Width)>=banner.Pos_x)||
+					(badge.Pos_x<=(banner.Pos_x+banner.Width) && (badge.Pos_x+badge.Width)>=(banner.Pos_x+banner.Width)))&&
+					((badge.Pos_y<=banner.Pos_y && (badge.Pos_y+badge.Height)>=banner.Pos_y)||
+					(badge.Pos_y<=(banner.Pos_y+banner.Height) && (badge.Pos_y+badge.Height)>=(banner.Pos_y+banner.Height))))
+				{
+					throw new InvalidFileException("Badge and banner position overlap");
+				}
+			}
+
+
+			CompilationEvent("Compiling WTP File");
+			ChunkyFolder tpat = new ChunkyFolder("TPAT", 3, skinName);
+			tpat.Children.Add(info);
+			tpat.Children.Add(primary);
+			tpat.Children.Add(secondary);
+			tpat.Children.Add(trim);
+			tpat.Children.Add(weapon);
+			tpat.Children.Add(eyes);
+			tpat.Children.Add(dirt);
+			tpat.Children.Add(defaultFolder);
+			tpat.Children.Add(banner);
+			tpat.Children.Add(badge);
+
+			return new WTPFile(baseFileName+".wtp", tpat);
+
+			//RelicChunkyFile.SaveChunky(directory+baseFileName+".wtp", tpat.GetBytes());
+		}
+
+		public byte[] CreateCompositeTGABytes(LayerCollection colours, string badgePath, string bannerPath)
+		{
+			if (colours[PTLD_Layers.Dirt].Length!=3)
+			{
+				throw new InvalidOperationException("LayerCollection 'colours' must contain RGB colour data in a 3-byte array");
+			}
+
+			FileInfo file = null;
+			BinaryReader br = null;
+			byte[] badge = new byte[64*64*4];
+			byte[] banner = new byte[64*96*4];
+			byte[] temp;
+
+			CompilationEvent("Loading badge");
+			if (File.Exists(badgePath))
+			{
+				file = new FileInfo(badgePath);
+				br = new BinaryReader(file.OpenRead());
+				temp = br.ReadBytes((int)file.Length);
+				br.Close();
+
+				if ((temp[12]+(temp[13]<<8))!=64 ||(temp[14]+(temp[15]<<8))!=64)
+				{
+					CompilationEvent("Invalid badge image - badge must be a 64x64 pixel 24/32-bit TGA image", true);
+				}
+				else if (!((temp[16]==32 || temp[16]==24) && temp[2]==2))
+				{
+					CompilationEvent("Invalid badge image - badge must be a 64x64 pixel 24/32-bit TGA image", true);
+				}
+				else
+				{
+					Buffer.BlockCopy(ImageConverter.TGAto32bitTGA(temp), 18, badge, 0, badge.Length);
+				}
+			}
+			else
+			{
+				CompilationEvent("Invalid badge path - file must exist. Using blank badge.", true);
+			}
+
+			CompilationEvent("Loading banner");
+			if (File.Exists(bannerPath))
+			{
+				file = new FileInfo(bannerPath);
+				br = new BinaryReader(file.OpenRead());
+				temp = br.ReadBytes((int)file.Length);
+				br.Close();
+
+
+				if ((temp[12]+(temp[13]<<8))!=64 ||(temp[14]+(temp[15]<<8))!=96)
+				{
+					CompilationEvent("Invalid banner image - banner must be a 64x96 pixel 24/32-bit TGA image", true);
+				}
+				else if (!((temp[16]==32 || temp[16]==24) && temp[2]==2))
+				{
+					CompilationEvent("Invalid banner image - banner must be a 64x64 pixel 24/32-bit TGA image", true);
+				}
+				else
+				{
+					Buffer.BlockCopy(ImageConverter.TGAto32bitTGA(temp), 18, banner, 0, banner.Length);
+				}
+			}
+			else
+			{
+				CompilationEvent("Invalid banner path - file must exist. Using blank badge.", true);
+			}
+
+			ChunkyFolder root = (ChunkyFolder)this.ChunkyStructures[0].RootChunks[0];
+
+			ChunkyChunk chunk = null;
+			ChunkyDataPTLD ptld = null;
+			ChunkyDataPTBN bannerLayer = null;
+			ChunkyDataPTBD badgeLayer = null;
+			ChunkyDataINFOTPAT info = (ChunkyDataINFOTPAT)root.Children[0];
+			LayerCollection layers = new LayerCollection(info.Width*info.Height);
+			byte[] mainImage = new byte[info.Width*info.Height];
+
+			int badge_bottom = int.MaxValue;
+			int badge_top = int.MaxValue;
+			int badge_left = int.MaxValue;
+			int badge_right = int.MaxValue;
+
+			int banner_bottom = int.MaxValue;
+			int banner_top = int.MaxValue;
+			int banner_left = int.MaxValue;
+			int banner_right = int.MaxValue;
+
+			CompilationEvent("Loading colour layers");
+			for (int i = 0; i<root.Children.Count; i++)
+			{
+				chunk = root.Children[i];
+
+				if (chunk is ChunkyDataPTLD)
+				{
+					ptld = (ChunkyDataPTLD)root.Children[i];
+					layers[(int)ptld.Layer] = ptld.GetColourBytes();
+				}
+				else if (chunk is ChunkyDataPTBD)
+				{
+					badgeLayer = (ChunkyDataPTBD)chunk;
+					badge_bottom = (int)badgeLayer.Pos_y;
+					badge_top = badge_bottom+(int)badgeLayer.Height;
+					badge_left = (int)badgeLayer.Pos_x;
+					badge_right = badge_left+(int)badgeLayer.Width;
+				}
+				else if (chunk is ChunkyDataPTBN)
+				{
+					bannerLayer = (ChunkyDataPTBN)chunk;
+					banner_bottom = (int)bannerLayer.Pos_y;
+					banner_top = banner_bottom+(int)bannerLayer.Height;
+					banner_left = (int)bannerLayer.Pos_x;
+					banner_right = banner_left+(int)bannerLayer.Width;
+				}
+				else if (chunk is ChunkyFolder)
+				{
+					mainImage = ((ChunkyData)((ChunkyFolder)chunk).Children[1]).GetDataBytes();
+				}
+			}
+
+			int bytePos = 0;
+			int bytePos32bit = 0;
+			int bytePosBadge = 0;
+			int bytePosBanner = 0;
+			byte[] badgeByte;
+			byte[] bannerByte;
+			double ratio;
+			double ratio2;
+			double ratio3;
+			double ratioTC;
+			double tempByte = 0;
+			double extra = 0;
+			int badge_width = 0;
+			
+			if (badgeLayer != null)
+			{
+				badge_width = (int)badgeLayer.Width;
+			}
+
+			int banner_width = 0;
+			
+			if (bannerLayer!=null)
+			{
+				banner_width = (int)bannerLayer.Width;
+			}
+
+			CompilationEvent("Compiling TGA");
+			for (int i = 0; i<info.Height; i++)
+			{
+				for (int j = 0; j<info.Width; j++)
+				{
+					bytePos = (i*info.Width)+j;
+					bytePos32bit = bytePos*4;
+					ratio = layers[PTLD_Layers.Dirt][bytePos]/255.0;
+
+					if (badge_left<=j && badge_right>j && badge_bottom<=i && badge_top>i)
+					{
+						bytePosBadge = ((i-badge_bottom)*badge_width+(j-badge_left))*4;
+
+						ratio2 = (badge[bytePosBadge+3]/255.0);
+						badgeByte = new byte[]{badge[bytePosBadge], badge[bytePosBadge+1], badge[bytePosBadge+2]};
+					}
+					else
+					{
+						ratio2 = 0;
+						badgeByte = new byte[3];
+					}
+
+					if (banner_left<=j && banner_right>j && banner_bottom<=i && banner_top>i)
+					{
+						bytePosBanner = ((i-banner_bottom)*banner_width+(j-banner_left))*4;
+
+						ratio3 = (banner[bytePosBanner+3]/255.0);
+						bannerByte = new byte[]{banner[bytePosBanner], banner[bytePosBanner+1], banner[bytePosBanner+2]};
+					}
+					else
+					{
+						ratio3 = 0;
+						bannerByte = new byte[3];
+					}
+
+					ratioTC = 1-ratio;
+
+					ratio2 = ratioTC*ratio2;
+					ratio3 = ratioTC*ratio3;
+					ratioTC = (ratioTC-ratio2-ratio3)*2;
+					extra = 0;
+
+					//TGA files run in reverse - little-endian ARGB, which ends up as BGRA in the file
+
+					//red
+					tempByte = (ratio*mainImage[bytePos32bit+2]) + (ratioTC)*((colours[PTLD_Layers.Primary][0]*layers[PTLD_Layers.Primary][bytePos]/255.0) + 
+						(colours[PTLD_Layers.Secondary][0]*layers[PTLD_Layers.Secondary][bytePos]/255.0) + 
+						(colours[PTLD_Layers.Weapon][0]*layers[PTLD_Layers.Weapon][bytePos]/255.0) + 
+						(colours[PTLD_Layers.Trim][0]*layers[PTLD_Layers.Trim][bytePos]/255.0) + 
+						(colours[PTLD_Layers.Eyes][0]*layers[PTLD_Layers.Eyes][bytePos]/255.0)) + ratio2*badgeByte[2] + ratio3*bannerByte[2];
+
+					if (tempByte>byte.MaxValue)
+					{
+						//CompilationEvent("Colour overflow at X:"+j.ToString()+", Y:"+i.ToString()+". Colour will show as Magenta or other bright colour with some colour schemes.", true);
+						mainImage[bytePos32bit+2] = byte.MaxValue;
+						extra = (tempByte-byte.MaxValue);
+					}
+					else
+					{
+						mainImage[bytePos32bit+2] = (byte)tempByte;
+					}
+
+					//green
+					tempByte = (ratio*mainImage[bytePos32bit+1]) + (ratioTC)*((colours[PTLD_Layers.Primary][1]*layers[PTLD_Layers.Primary][bytePos]/255.0) + 
+						(colours[PTLD_Layers.Secondary][1]*layers[PTLD_Layers.Secondary][bytePos]/255.0) + 
+						(colours[PTLD_Layers.Weapon][1]*layers[PTLD_Layers.Weapon][bytePos]/255.0) + 
+						(colours[PTLD_Layers.Trim][1]*layers[PTLD_Layers.Trim][bytePos]/255.0) + 
+						(colours[PTLD_Layers.Eyes][1]*layers[PTLD_Layers.Eyes][bytePos]/255.0)) + extra + ratio2*badgeByte[1] + ratio3*bannerByte[1];
+
+					if (tempByte>byte.MaxValue)
+					{
+						//CompilationEvent("Colour overflow at X:"+j.ToString()+", Y:"+i.ToString()+". Colour will show as Magenta or other bright colour with some colour schemes.", true);
+						mainImage[bytePos32bit+1] = byte.MaxValue;
+						extra = extra + tempByte-byte.MaxValue;
+						tempByte = mainImage[bytePos32bit+2]+extra;
+						if (tempByte>byte.MaxValue)
+						{
+							tempByte = byte.MaxValue;
+						}
+						mainImage[bytePos32bit+2] = (byte)tempByte;
+					}
+					else
+					{
+						mainImage[bytePos32bit+1] = (byte)tempByte;
+					}
+
+					//blue
+					tempByte = (ratio*mainImage[bytePos32bit]) + (ratioTC)*((colours[PTLD_Layers.Primary][2]*layers[PTLD_Layers.Primary][bytePos]/255.0) + 
+						(colours[PTLD_Layers.Secondary][2]*layers[PTLD_Layers.Secondary][bytePos]/255.0) + 
+						(colours[PTLD_Layers.Weapon][2]*layers[PTLD_Layers.Weapon][bytePos]/255.0) + 
+						(colours[PTLD_Layers.Trim][2]*layers[PTLD_Layers.Trim][bytePos]/255.0) + 
+						(colours[PTLD_Layers.Eyes][2]*layers[PTLD_Layers.Eyes][bytePos]/255.0)) + extra + ratio2*badgeByte[0] + ratio3*bannerByte[0];
+
+					if (tempByte>byte.MaxValue)
+					{
+						//CompilationEvent("Colour overflow at X:"+j.ToString()+", Y:"+i.ToString()+". Colour will show as Magenta or other bright colour with some colour schemes.", true);
+						mainImage[bytePos32bit] = byte.MaxValue;
+						extra = extra + tempByte - byte.MaxValue;
+						tempByte = mainImage[bytePos32bit+2]+extra;
+						if (tempByte>byte.MaxValue)
+						{
+							tempByte = byte.MaxValue;
+						}
+						mainImage[bytePos32bit+2] = (byte)tempByte;
+						tempByte = mainImage[bytePos32bit+1]+extra;
+						if (tempByte>byte.MaxValue)
+						{
+							tempByte = byte.MaxValue;
+						}
+						mainImage[bytePos32bit+1] = (byte)tempByte;
+					}
+					else
+					{
+						mainImage[bytePos32bit] = (byte)tempByte;
+					}
+				}
+			}
+
+			return mainImage;
+		}
+
+		public void SaveCompositeTGA(DirectoryInfo destination, LayerCollection colours, string badgePath, string bannerPath)
+		{
+			byte[] tga = this.CreateCompositeTGABytes(colours, badgePath, bannerPath);
+			
+			ChunkyDataATTR attr = findFirstDataAttributes();
+			
+			ChunkyDataDATAIMAG data = new ChunkyDataDATAIMAG(2, "", tga);
+			data.Attributes = attr;
+			CompilationEvent("Saving compiled TGA");
+			data.Save(destination, filename.Substring(0, filename.LastIndexOf('_')));
+			CompilationEvent("Compilation Complete\r\n");
+		}
+
+		private ChunkyDataATTR findFirstDataAttributes()
+		{
+			if (attr == null)
+			{
+				ChunkyFolder root = (ChunkyFolder)this.ChunkyStructures[0].RootChunks[0];
+
+				for (int i = 0; i<root.Children.Count; i++)
+				{
+					if (root.Children[i] is ChunkyFolder)
+					{
+						root = (ChunkyFolder)root.Children[i];
+						break;
+					}
+				}
+
+				if (root.Children[0] is ChunkyDataATTR)
+				{
+					attr = (ChunkyDataATTR)root.Children[0];
+				}
+			}
+			
+			return attr;
+		}
+	}
+}
\ No newline at end of file