/[MorrowindCustomClothingSlotCreator]/trunk/libTES3FileFormat/PlugingClothing.cs
ViewVC logotype

Diff of /trunk/libTES3FileFormat/PlugingClothing.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/libTES3FileFormat/PlugingClothing.cs	2011/07/29 16:09:53	17
+++ trunk/libTES3FileFormat/PlugingClothing.cs	2011/07/29 16:54:40	18
@@ -9,7 +9,19 @@
 namespace libTES3FileFormat
 {
 
-   
+    public enum ClothingType
+    {
+        Pants,
+        Shoes,
+        Shirt,
+        Belt,
+        Robe,
+        RightGlove,
+        LeftGlove,
+        Skirt,
+        Ring,
+        Amulet,
+    }
 
     public interface IPlugingClothing : IParse, ICommit, IAsBytes, ISizeOffset
     {
@@ -21,19 +33,21 @@
         private const string CLOTHING_MAGIC = "CLOT";
         private const string CLOTHING_NAME_MAGIC = "NAME";
         MemoryStream reader = new MemoryStream();
+        private int SectionCount = 0;
         public PlugingClothing()
         {
             this.reader = new MemoryStream();
             this.Offset = 0;
             this.Size = 0;
         }
-        public PlugingClothing(BinaryReader br, int offset, int size, bool ReadOnly, ConsoleLog Log)
+        public PlugingClothing(BinaryReader br, int offset, int size, int SectionCount, bool ReadOnly, ConsoleLog Log)
             : this()
         {
             this.Log = Log;
             br.BaseStream.Seek(offset, SeekOrigin.Begin);
             this.Offset = offset;
             this.Size = size;
+            this.SectionCount = SectionCount;
             this.reader = new MemoryStream(br.ReadBytes((int)br.BaseStream.Length), 0, size);
             this.Parse(this.reader);
         }
@@ -46,41 +60,85 @@
             this.Log.WriteLine();
             // read header section magic
 
+            for (int i = 0; i < this.SectionCount; i++)
+            {
+
+                this.Log.WriteLine(string.Format("Clothing Section: Index=0x{0:x8} Offset=0x{1:x8}", i,(int)br.BaseStream.Position));
+
+                byte[] magic = br.ReadBytes(4);
+                string str_magic = ASCIIEncoding.ASCII.GetString(magic);
+                Debug.Assert(str_magic == "CLOT", string.Format("Excepted: {0} found: {1}", "CLOT", str_magic));
+
+                // Clothing Name
+                int section_size = BitConverter.ToInt32(br.ReadBytes(12), 0);
+                magic = br.ReadBytes(4);
+                str_magic = ASCIIEncoding.ASCII.GetString(magic);
+                Debug.Assert(str_magic == "NAME", string.Format("Excepted: {0} found: {1}", "NAME", str_magic));
+                
+                int name_size = br.ReadInt32();
+                this.Log.WriteLine("\t\tClothing Name Size: " + name_size.ToString());
+                byte[] name_bytes = br.ReadBytes(name_size);
+                string ClothingName = ASCIIEncoding.ASCII.GetString(name_bytes);
+                this.Log.WriteLine("\t\tClothing Name : " + ClothingName);
+
+
+                // Clothing Model
+                magic = br.ReadBytes(4);
+                str_magic = ASCIIEncoding.ASCII.GetString(magic);
+                Debug.Assert(str_magic == "MODL", string.Format("Excepted: {0} found: {1}", "MODL", str_magic));
+                
+                int modl_name_size = br.ReadInt32();
+                this.Log.WriteLine("\t\tClothing Model Name Size: " + modl_name_size.ToString());
+                byte[] modl_name_bytes = br.ReadBytes(modl_name_size);
+                string ClothingModelName = ASCIIEncoding.ASCII.GetString(modl_name_bytes);
+                this.Log.WriteLine("\t\tClothing Model Name: " + ClothingModelName);
+
+                // Clothing Full Name
+                magic = br.ReadBytes(4);
+                str_magic = ASCIIEncoding.ASCII.GetString(magic);
+                Debug.Assert(str_magic == "FNAM", string.Format("Excepted: {0} found: {1}", "FNAM", str_magic));
+
+                int fname_size = br.ReadInt32();
+                this.Log.WriteLine("\t\tClothing FullName Size: " + fname_size.ToString());
+                byte[] fname_bytes = br.ReadBytes(fname_size);
+                string ClothingFullName = ASCIIEncoding.ASCII.GetString(fname_bytes);
+                this.Log.WriteLine("\t\tClothing FullName: " + ClothingFullName);
+
+                // Clothing Data
+                magic = br.ReadBytes(4);
+                str_magic = ASCIIEncoding.ASCII.GetString(magic);
+                Debug.Assert(str_magic == "CTDT", string.Format("Excepted: {0} found: {1}", "CTDT", str_magic));
 
-            //bool NoMoreClothingEntries = false;
+                int ctdt_size = br.ReadInt32();
+
+                int ctdt_type = br.ReadInt32();
+                string ctdt_type_string = "";
+
+                try
+                {
+                    ctdt_type_string = Enum.GetName(typeof(ClothingType), ctdt_type);
+                }
+                catch { ctdt_type_string = "unknown"; }
 
-            //while (NoMoreClothingEntries != true)
-            //{
-            //    // read the MAST tag
-            //    byte[] magic = br.ReadBytes(4);
-            //    string str_magic = ASCIIEncoding.ASCII.GetString(magic);
-            //    StringBuilder magic_info_message = new StringBuilder();
-            //    magic_info_message.Append("\tDetected Master Section: ");
-            //    magic_info_message.Append(magic.ToStr());
-            //    magic_info_message.Append(" : " + str_magic);
-
-            //    if (str_magic != PlugingClothing.CLOTHING_MAGIC)
-            //    {
-            //        NoMoreClothingEntries = true;
-            //        br.BaseStream.Seek(br.BaseStream.Position - 4, SeekOrigin.Begin); // seek back 4 bytes in the stream
-            //        break;
-            //    }
-            //    // throw assert if not true
-            //    Debug.Assert(str_magic == PlugingClothing.CLOTHING_MAGIC, string.Format("Excepted: {0} found: {1}", PlugingClothing.CLOTHING_MAGIC, str_magic));
-
-            //    this.Log.WriteLine(magic_info_message.ToString());
-            //    int MasterFileNameLength = br.ReadInt32();
-            //    byte[] MasterFileName = br.ReadBytes(MasterFileNameLength);
-            //    this.Log.WriteLine("\t\tFileName: " + MasterFileName.ToAscii());
-            //    // read this master's data section
-            //    magic = br.ReadBytes(4);
-            //    str_magic = ASCIIEncoding.ASCII.GetString(magic);
-            //    Debug.Assert(str_magic == PlugingClothing.CLOTHING_NAME_MAGIC, string.Format("Excepted: {0} found: {1}", PlugingClothing.CLOTHING_NAME_MAGIC, str_magic));
-            //    int DataSectionLength = br.ReadInt32();
-            //    byte[] Data = br.ReadBytes(DataSectionLength);
-            //    this.Log.WriteLine("\t\tData: " + Data.ToStr());
-            //}
-            
+
+                float ctdt_weight = br.ReadSingle();
+                short ctdt_value = br.ReadInt16();
+                short ctdt_echant_pts = br.ReadInt16();
+
+                this.Log.WriteLine("\t\tClothing Data: ");
+                this.Log.WriteLine("\t\t\tType: " + ctdt_type + " (" + ctdt_type_string +")");
+                this.Log.WriteLine("\t\t\tWeight: " + ctdt_weight);
+                this.Log.WriteLine("\t\t\tValue: " + ctdt_value);
+                this.Log.WriteLine("\t\t\tEnchant Points: " + ctdt_echant_pts);
+
+                magic = br.ReadBytes(4);
+                str_magic = ASCIIEncoding.ASCII.GetString(magic);
+                Debug.Assert(str_magic == "SCRI", string.Format("Excepted: {0} found: {1}", "SCRI", str_magic));
+
+                break;
+
+            }
+                  
 
             return true;
         }
@@ -192,9 +250,10 @@
                     int b = (CLOTH_LENGTH + (int)br.BaseStream.Position) - PlugingClothing.CLOTHING_NAME_MAGIC.Length;
 
                     this.Size = b - this.Offset;
+                    this.SectionCount = ClothingSectionCount;
                     this.Log.WriteLine("\t\tSize of All Clothing Sections (from first entry): 0x" + this.Size.ToString("x8"));
                     this.Log.WriteLine("\t\tCloting Section: Start=0x" + this.Offset.ToString("x8") + " End=0x" + (this.Offset + this.Size).ToString("x8"));
-                    this.Log.WriteLine("\t\tTotal Clothing Sections: " + ClothingSectionCount.ToString());
+                    this.Log.WriteLine("\t\tTotal Clothing Sections: " + this.SectionCount.ToString());
                 }
 
                 return true;
@@ -217,6 +276,12 @@
                 get { return _Size; }
                 private set { _Size = value; }
             }
+            private int _SectionCount;
+            public int SectionCount
+            {
+                get { return _SectionCount; }
+                private set { _SectionCount = value; }
+            }
             #endregion
         }
         #endregion

 

  ViewVC Help
Powered by ViewVC 1.1.22