/[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 17:39:39	19
+++ trunk/libTES3FileFormat/PlugingClothing.cs	2011/07/29 18:22:20	20
@@ -23,9 +23,93 @@
         Amulet,
     }
 
-    public interface IPlugingClothing : IParse, ICommit, IAsBytes, ISizeOffset
+    public interface IClothingEntry : IOffset
     {
+        byte[] CLOT_MAGIC { get; } // 4bytes, CLOT
+        byte[] CLOT_SIZE { get; set; } // 12 bytes
+
+        byte[] CLOT_NAME_MAGIC { get; } // 4bytes, NAME
+        int CLOT_NAME_LENGTH { get; }//4 bytes, name length
+        string CLOT_NAME { get; set; } // variable length, null terminated
+
+        byte[] CLOT_MODL_MAGIC { get; } // 4bytes, MODL
+        int CLOT_MODL_LENGTH { get; }//4 bytes, MODL length
+        string CLOT_MODL { get; set; } // variable length, null terminated
+
+        byte[] CLOT_FULLNAME_MAGIC { get; } // 4bytes, FNAM
+        int CLOT_FULLNAME_LENGTH { get; }//4 bytes, FNAM length
+        string CLOT_FULLNAME { get; set; } // variable length, null terminated
+
+        byte[] CLOT_CTDT_MAGIC { get; } // 4bytes, CTDT
+        int CLOT_CTDT_TYPE { get; set; }//4 bytes
+        float CLOT_CTDT_WEIGHT { get; set; }//4 bytes
+        short CLOT_CTDT_VALUE { get; set; }//2 bytes
+        short CLOT_CTDT_ENCHANTPTS { get; set; }//2 bytes
 
+        byte[] CLOT_OTHER_DATA { get; set; } // the rest of the clothing data entry
+    }
+    public class ClothingEntry : IClothingEntry
+    {
+        public ClothingEntry()
+        {
+            this.Offset = 0;
+            this.CLOT_SIZE = new byte[12];
+            this.CLOT_NAME = "";
+            this.CLOT_MODL = "";
+            this.CLOT_FULLNAME = "";
+            this.CLOT_CTDT_TYPE = (int)ClothingType.Amulet;
+            this.CLOT_CTDT_WEIGHT = 0;
+            this.CLOT_CTDT_VALUE = 0;
+            this.CLOT_CTDT_ENCHANTPTS = 0;
+            this.CLOT_OTHER_DATA = new byte[0];
+        }
+        #region IOffset Members
+        private int _Offset;
+        public int Offset { get { return _Offset; } set { _Offset = value; } }
+        #endregion
+        #region IClothingEntry Members
+        public byte[] CLOT_MAGIC { get { return ASCIIEncoding.ASCII.GetBytes("CLOT"); } } // 4bytes, CLOT
+        private byte[] _CLOT_SIZE;
+        public byte[] CLOT_SIZE { get { return _CLOT_SIZE; } set { _CLOT_SIZE = value; Debug.Assert(value.Length == 12, "Excepted CLOT_SIZE of 12 bytes. Found: " + value.Length + " bytes"); } }// 12 bytes
+
+        public byte[] CLOT_NAME_MAGIC { get { return ASCIIEncoding.ASCII.GetBytes("NAME"); } } // 4bytes, NAME
+        public int CLOT_NAME_LENGTH { get { return CLOT_NAME.Length; } }//4 bytes, name length
+        private string _CLOT_NAME;
+        public string CLOT_NAME { get { return _CLOT_NAME; } set { _CLOT_NAME = value; } } // variable length, null terminated
+
+        public byte[] CLOT_MODL_MAGIC { get { return ASCIIEncoding.ASCII.GetBytes("MODL"); } } // 4bytes, MODL
+        public int CLOT_MODL_LENGTH { get { return CLOT_MODL.Length; } }//4 bytes, MODL length
+        private string _CLOT_MODL;
+        public string CLOT_MODL { get { return _CLOT_MODL; } set { _CLOT_MODL = value; } } // variable length, null terminated
+
+        public byte[] CLOT_FULLNAME_MAGIC { get { return ASCIIEncoding.ASCII.GetBytes("FNAM"); } } // 4bytes, FNAM
+        public int CLOT_FULLNAME_LENGTH { get { return CLOT_FULLNAME.Length; } }//4 bytes, FNAM length
+        private string _CLOT_FULLNAME;
+        public string CLOT_FULLNAME { get { return _CLOT_FULLNAME; } set { _CLOT_FULLNAME = value; } } // variable length, null terminated
+
+        public byte[] CLOT_CTDT_MAGIC { get { return ASCIIEncoding.ASCII.GetBytes("CTDT"); } } // 4bytes, CTDT
+
+        private int _CLOT_CTDT_SIZE;
+        private int _CLOT_CTDT_TYPE;
+        private float _CLOT_CTDT_WEIGHT;
+        private short _CLOT_CTDT_VALUE;
+        private short _CLOT_CTDT_ENCHANTPTS;
+
+        public int CLOT_CTDT_SIZE { get { return _CLOT_CTDT_SIZE; } set { _CLOT_CTDT_SIZE = value; } }//4 bytes
+
+        public int CLOT_CTDT_TYPE { get { return _CLOT_CTDT_TYPE; } set { _CLOT_CTDT_TYPE = value; } }//4 bytes
+        public float CLOT_CTDT_WEIGHT { get { return _CLOT_CTDT_WEIGHT; } set { _CLOT_CTDT_WEIGHT = value; } }//4 bytes
+        public short CLOT_CTDT_VALUE { get { return _CLOT_CTDT_VALUE; } set { _CLOT_CTDT_VALUE = value; } }//2 bytes
+        public short CLOT_CTDT_ENCHANTPTS { get { return _CLOT_CTDT_ENCHANTPTS; } set { _CLOT_CTDT_ENCHANTPTS = value; } }//2 bytes
+
+        private byte[] _CLOT_OTHER_DATA;
+        public byte[] CLOT_OTHER_DATA { get { return _CLOT_OTHER_DATA; } set { _CLOT_OTHER_DATA = value; } } // the rest of the clothing data entry
+        #endregion
+    }
+
+    public interface IPlugingClothing : IParse, ICommit, IAsBytes, ISizeOffset
+    {
+        List<ClothingEntry> ClothingEntries { get; }
     }
     public class PlugingClothing : IPlugingClothing, ICommitParseAsBytes
     {
@@ -40,6 +124,7 @@
             this.Offset = 0;
             this.Size = 0;
             this.SectionOffsets = new List<int>();
+            this.ClothingEntries = new List<ClothingEntry>();
         }
         public PlugingClothing(BinaryReader br, List<int> SectionOffsets, bool ReadOnly, ConsoleLog Log)
             : this()
@@ -52,7 +137,15 @@
             this.reader = new MemoryStream(br.ReadBytes((int)br.BaseStream.Length), 0, (int)br.BaseStream.Length);
             this.Parse(this.reader);
         }
+        #region IPlugingClothing Members
+        private List<ClothingEntry> _ClothingEntries;
+        public List<ClothingEntry> ClothingEntries
+        {
+            get { return _ClothingEntries; }
+            private set { _ClothingEntries = value; }
+        }
 
+        #endregion
         #region IParse Members
 
         public bool Parse(MemoryStream stream)
@@ -63,6 +156,10 @@
 
             for (int i = 0; i < this.SectionOffsets.Count; i++)
             {
+                ClothingEntry entry = new ClothingEntry();
+                
+                entry.Offset = this.SectionOffsets[i]; // set the offset for this entry
+
                 br.BaseStream.Seek(this.SectionOffsets[i], SeekOrigin.Begin);
                 this.Log.WriteLine(string.Format("Clothing Section: Index=0x{0:x8} Offset=0x{1:x8}", i,(int)br.BaseStream.Position));
 
@@ -71,16 +168,24 @@
                 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);
+                byte[] section_size_bytes = br.ReadBytes(12);
+                int section_size = BitConverter.ToInt32(section_size_bytes, 0);
+                
+                entry.CLOT_SIZE = section_size_bytes; // set the clot size
+
                 int name_offset = (int)br.BaseStream.Position;
                 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);
+                
+                entry.CLOT_NAME = ClothingName; // set the NAME
+
                 this.Log.WriteLine("\t\tClothing Name : " + ClothingName);
 
 
@@ -93,6 +198,9 @@
                 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);
+
+                entry.CLOT_MODL = ClothingModelName; // set the MODL
+
                 this.Log.WriteLine("\t\tClothing Model Name: " + ClothingModelName);
 
                 // Clothing Full Name
@@ -104,6 +212,7 @@
                 this.Log.WriteLine("\t\tClothing FullName Size: " + fname_size.ToString());
                 byte[] fname_bytes = br.ReadBytes(fname_size);
                 string ClothingFullName = ASCIIEncoding.ASCII.GetString(fname_bytes);
+                entry.CLOT_FULLNAME = ClothingFullName; // set the full name
                 this.Log.WriteLine("\t\tClothing FullName: " + ClothingFullName);
 
                 // Clothing Data
@@ -112,7 +221,7 @@
                 Debug.Assert(str_magic == "CTDT", string.Format("Excepted: {0} found: {1}", "CTDT", str_magic));
 
                 int ctdt_size = br.ReadInt32();
-
+                
                 int ctdt_type = br.ReadInt32();
                 string ctdt_type_string = "";
 
@@ -127,6 +236,13 @@
                 short ctdt_value = br.ReadInt16();
                 short ctdt_echant_pts = br.ReadInt16();
 
+
+                entry.CLOT_CTDT_SIZE = ctdt_size; // set the size
+                entry.CLOT_CTDT_TYPE = ctdt_type; // set the type
+                entry.CLOT_CTDT_WEIGHT = ctdt_weight; // set the weight
+                entry.CLOT_CTDT_VALUE = ctdt_value; // set the value
+                entry.CLOT_CTDT_ENCHANTPTS = ctdt_echant_pts; // set the enchant pts
+
                 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);
@@ -143,14 +259,15 @@
                 int length_till_end_of_section = (name_offset + section_size) - (int)br.BaseStream.Position;
 
 
-                try
-                {
-                    byte[] extra_clothing_data = br.ReadBytes(length_till_end_of_section);
-                }
-                catch { break; }
+                //try
+                //{
+                byte[] extra_clothing_data = br.ReadBytes(length_till_end_of_section);
+                entry.CLOT_OTHER_DATA = extra_clothing_data; // set the extra data
+                //}
+                //catch { break; }
 
                 //break;
-
+                this.ClothingEntries.Add(entry);
             }
                   
 
@@ -202,6 +319,7 @@
                 this.reader = new MemoryStream();
                 this.Log = new ConsoleLog();
                 this.ClothingSectionOffsets = new List<int>();
+                
             }
             public SectionLocater(BinaryReader br, int CurrentOffset, ConsoleLog Log) : this()
             {
@@ -267,5 +385,7 @@
             #endregion
         }
         #endregion
+
+
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22