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

Diff of /trunk/libTES3FileFormat/PlugingClothing.cs

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

revision 19 by william, Fri Jul 29 17:39:39 2011 UTC revision 20 by william, Fri Jul 29 18:22:20 2011 UTC
# Line 23  namespace libTES3FileFormat Line 23  namespace libTES3FileFormat
23          Amulet,          Amulet,
24      }      }
25    
26      public interface IPlugingClothing : IParse, ICommit, IAsBytes, ISizeOffset      public interface IClothingEntry : IOffset
27      {      {
28            byte[] CLOT_MAGIC { get; } // 4bytes, CLOT
29            byte[] CLOT_SIZE { get; set; } // 12 bytes
30    
31            byte[] CLOT_NAME_MAGIC { get; } // 4bytes, NAME
32            int CLOT_NAME_LENGTH { get; }//4 bytes, name length
33            string CLOT_NAME { get; set; } // variable length, null terminated
34    
35            byte[] CLOT_MODL_MAGIC { get; } // 4bytes, MODL
36            int CLOT_MODL_LENGTH { get; }//4 bytes, MODL length
37            string CLOT_MODL { get; set; } // variable length, null terminated
38    
39            byte[] CLOT_FULLNAME_MAGIC { get; } // 4bytes, FNAM
40            int CLOT_FULLNAME_LENGTH { get; }//4 bytes, FNAM length
41            string CLOT_FULLNAME { get; set; } // variable length, null terminated
42    
43            byte[] CLOT_CTDT_MAGIC { get; } // 4bytes, CTDT
44            int CLOT_CTDT_TYPE { get; set; }//4 bytes
45            float CLOT_CTDT_WEIGHT { get; set; }//4 bytes
46            short CLOT_CTDT_VALUE { get; set; }//2 bytes
47            short CLOT_CTDT_ENCHANTPTS { get; set; }//2 bytes
48    
49            byte[] CLOT_OTHER_DATA { get; set; } // the rest of the clothing data entry
50        }
51        public class ClothingEntry : IClothingEntry
52        {
53            public ClothingEntry()
54            {
55                this.Offset = 0;
56                this.CLOT_SIZE = new byte[12];
57                this.CLOT_NAME = "";
58                this.CLOT_MODL = "";
59                this.CLOT_FULLNAME = "";
60                this.CLOT_CTDT_TYPE = (int)ClothingType.Amulet;
61                this.CLOT_CTDT_WEIGHT = 0;
62                this.CLOT_CTDT_VALUE = 0;
63                this.CLOT_CTDT_ENCHANTPTS = 0;
64                this.CLOT_OTHER_DATA = new byte[0];
65            }
66            #region IOffset Members
67            private int _Offset;
68            public int Offset { get { return _Offset; } set { _Offset = value; } }
69            #endregion
70            #region IClothingEntry Members
71            public byte[] CLOT_MAGIC { get { return ASCIIEncoding.ASCII.GetBytes("CLOT"); } } // 4bytes, CLOT
72            private byte[] _CLOT_SIZE;
73            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
74    
75            public byte[] CLOT_NAME_MAGIC { get { return ASCIIEncoding.ASCII.GetBytes("NAME"); } } // 4bytes, NAME
76            public int CLOT_NAME_LENGTH { get { return CLOT_NAME.Length; } }//4 bytes, name length
77            private string _CLOT_NAME;
78            public string CLOT_NAME { get { return _CLOT_NAME; } set { _CLOT_NAME = value; } } // variable length, null terminated
79    
80            public byte[] CLOT_MODL_MAGIC { get { return ASCIIEncoding.ASCII.GetBytes("MODL"); } } // 4bytes, MODL
81            public int CLOT_MODL_LENGTH { get { return CLOT_MODL.Length; } }//4 bytes, MODL length
82            private string _CLOT_MODL;
83            public string CLOT_MODL { get { return _CLOT_MODL; } set { _CLOT_MODL = value; } } // variable length, null terminated
84    
85            public byte[] CLOT_FULLNAME_MAGIC { get { return ASCIIEncoding.ASCII.GetBytes("FNAM"); } } // 4bytes, FNAM
86            public int CLOT_FULLNAME_LENGTH { get { return CLOT_FULLNAME.Length; } }//4 bytes, FNAM length
87            private string _CLOT_FULLNAME;
88            public string CLOT_FULLNAME { get { return _CLOT_FULLNAME; } set { _CLOT_FULLNAME = value; } } // variable length, null terminated
89    
90            public byte[] CLOT_CTDT_MAGIC { get { return ASCIIEncoding.ASCII.GetBytes("CTDT"); } } // 4bytes, CTDT
91    
92            private int _CLOT_CTDT_SIZE;
93            private int _CLOT_CTDT_TYPE;
94            private float _CLOT_CTDT_WEIGHT;
95            private short _CLOT_CTDT_VALUE;
96            private short _CLOT_CTDT_ENCHANTPTS;
97    
98            public int CLOT_CTDT_SIZE { get { return _CLOT_CTDT_SIZE; } set { _CLOT_CTDT_SIZE = value; } }//4 bytes
99    
100            public int CLOT_CTDT_TYPE { get { return _CLOT_CTDT_TYPE; } set { _CLOT_CTDT_TYPE = value; } }//4 bytes
101            public float CLOT_CTDT_WEIGHT { get { return _CLOT_CTDT_WEIGHT; } set { _CLOT_CTDT_WEIGHT = value; } }//4 bytes
102            public short CLOT_CTDT_VALUE { get { return _CLOT_CTDT_VALUE; } set { _CLOT_CTDT_VALUE = value; } }//2 bytes
103            public short CLOT_CTDT_ENCHANTPTS { get { return _CLOT_CTDT_ENCHANTPTS; } set { _CLOT_CTDT_ENCHANTPTS = value; } }//2 bytes
104    
105            private byte[] _CLOT_OTHER_DATA;
106            public byte[] CLOT_OTHER_DATA { get { return _CLOT_OTHER_DATA; } set { _CLOT_OTHER_DATA = value; } } // the rest of the clothing data entry
107            #endregion
108        }
109    
110        public interface IPlugingClothing : IParse, ICommit, IAsBytes, ISizeOffset
111        {
112            List<ClothingEntry> ClothingEntries { get; }
113      }      }
114      public class PlugingClothing : IPlugingClothing, ICommitParseAsBytes      public class PlugingClothing : IPlugingClothing, ICommitParseAsBytes
115      {      {
# Line 40  namespace libTES3FileFormat Line 124  namespace libTES3FileFormat
124              this.Offset = 0;              this.Offset = 0;
125              this.Size = 0;              this.Size = 0;
126              this.SectionOffsets = new List<int>();              this.SectionOffsets = new List<int>();
127                this.ClothingEntries = new List<ClothingEntry>();
128          }          }
129          public PlugingClothing(BinaryReader br, List<int> SectionOffsets, bool ReadOnly, ConsoleLog Log)          public PlugingClothing(BinaryReader br, List<int> SectionOffsets, bool ReadOnly, ConsoleLog Log)
130              : this()              : this()
# Line 52  namespace libTES3FileFormat Line 137  namespace libTES3FileFormat
137              this.reader = new MemoryStream(br.ReadBytes((int)br.BaseStream.Length), 0, (int)br.BaseStream.Length);              this.reader = new MemoryStream(br.ReadBytes((int)br.BaseStream.Length), 0, (int)br.BaseStream.Length);
138              this.Parse(this.reader);              this.Parse(this.reader);
139          }          }
140            #region IPlugingClothing Members
141            private List<ClothingEntry> _ClothingEntries;
142            public List<ClothingEntry> ClothingEntries
143            {
144                get { return _ClothingEntries; }
145                private set { _ClothingEntries = value; }
146            }
147    
148            #endregion
149          #region IParse Members          #region IParse Members
150    
151          public bool Parse(MemoryStream stream)          public bool Parse(MemoryStream stream)
# Line 63  namespace libTES3FileFormat Line 156  namespace libTES3FileFormat
156    
157              for (int i = 0; i < this.SectionOffsets.Count; i++)              for (int i = 0; i < this.SectionOffsets.Count; i++)
158              {              {
159                    ClothingEntry entry = new ClothingEntry();
160                    
161                    entry.Offset = this.SectionOffsets[i]; // set the offset for this entry
162    
163                  br.BaseStream.Seek(this.SectionOffsets[i], SeekOrigin.Begin);                  br.BaseStream.Seek(this.SectionOffsets[i], SeekOrigin.Begin);
164                  this.Log.WriteLine(string.Format("Clothing Section: Index=0x{0:x8} Offset=0x{1:x8}", i,(int)br.BaseStream.Position));                  this.Log.WriteLine(string.Format("Clothing Section: Index=0x{0:x8} Offset=0x{1:x8}", i,(int)br.BaseStream.Position));
165    
# Line 71  namespace libTES3FileFormat Line 168  namespace libTES3FileFormat
168                  Debug.Assert(str_magic == "CLOT", string.Format("Excepted: {0} found: {1}", "CLOT", str_magic));                  Debug.Assert(str_magic == "CLOT", string.Format("Excepted: {0} found: {1}", "CLOT", str_magic));
169    
170                  // Clothing Name                  // Clothing Name
171                  int section_size = BitConverter.ToInt32(br.ReadBytes(12), 0);                  byte[] section_size_bytes = br.ReadBytes(12);
172                    int section_size = BitConverter.ToInt32(section_size_bytes, 0);
173                    
174                    entry.CLOT_SIZE = section_size_bytes; // set the clot size
175    
176                  int name_offset = (int)br.BaseStream.Position;                  int name_offset = (int)br.BaseStream.Position;
177                  magic = br.ReadBytes(4);                  magic = br.ReadBytes(4);
178                  str_magic = ASCIIEncoding.ASCII.GetString(magic);                  str_magic = ASCIIEncoding.ASCII.GetString(magic);
179                  Debug.Assert(str_magic == "NAME", string.Format("Excepted: {0} found: {1}", "NAME", str_magic));                  Debug.Assert(str_magic == "NAME", string.Format("Excepted: {0} found: {1}", "NAME", str_magic));
180                                    
181                  int name_size = br.ReadInt32();                  int name_size = br.ReadInt32();
182                    
183                  this.Log.WriteLine("\t\tClothing Name Size: " + name_size.ToString());                  this.Log.WriteLine("\t\tClothing Name Size: " + name_size.ToString());
184                  byte[] name_bytes = br.ReadBytes(name_size);                  byte[] name_bytes = br.ReadBytes(name_size);
185                  string ClothingName = ASCIIEncoding.ASCII.GetString(name_bytes);                  string ClothingName = ASCIIEncoding.ASCII.GetString(name_bytes);
186                    
187                    entry.CLOT_NAME = ClothingName; // set the NAME
188    
189                  this.Log.WriteLine("\t\tClothing Name : " + ClothingName);                  this.Log.WriteLine("\t\tClothing Name : " + ClothingName);
190    
191    
# Line 93  namespace libTES3FileFormat Line 198  namespace libTES3FileFormat
198                  this.Log.WriteLine("\t\tClothing Model Name Size: " + modl_name_size.ToString());                  this.Log.WriteLine("\t\tClothing Model Name Size: " + modl_name_size.ToString());
199                  byte[] modl_name_bytes = br.ReadBytes(modl_name_size);                  byte[] modl_name_bytes = br.ReadBytes(modl_name_size);
200                  string ClothingModelName = ASCIIEncoding.ASCII.GetString(modl_name_bytes);                  string ClothingModelName = ASCIIEncoding.ASCII.GetString(modl_name_bytes);
201    
202                    entry.CLOT_MODL = ClothingModelName; // set the MODL
203    
204                  this.Log.WriteLine("\t\tClothing Model Name: " + ClothingModelName);                  this.Log.WriteLine("\t\tClothing Model Name: " + ClothingModelName);
205    
206                  // Clothing Full Name                  // Clothing Full Name
# Line 104  namespace libTES3FileFormat Line 212  namespace libTES3FileFormat
212                  this.Log.WriteLine("\t\tClothing FullName Size: " + fname_size.ToString());                  this.Log.WriteLine("\t\tClothing FullName Size: " + fname_size.ToString());
213                  byte[] fname_bytes = br.ReadBytes(fname_size);                  byte[] fname_bytes = br.ReadBytes(fname_size);
214                  string ClothingFullName = ASCIIEncoding.ASCII.GetString(fname_bytes);                  string ClothingFullName = ASCIIEncoding.ASCII.GetString(fname_bytes);
215                    entry.CLOT_FULLNAME = ClothingFullName; // set the full name
216                  this.Log.WriteLine("\t\tClothing FullName: " + ClothingFullName);                  this.Log.WriteLine("\t\tClothing FullName: " + ClothingFullName);
217    
218                  // Clothing Data                  // Clothing Data
# Line 112  namespace libTES3FileFormat Line 221  namespace libTES3FileFormat
221                  Debug.Assert(str_magic == "CTDT", string.Format("Excepted: {0} found: {1}", "CTDT", str_magic));                  Debug.Assert(str_magic == "CTDT", string.Format("Excepted: {0} found: {1}", "CTDT", str_magic));
222    
223                  int ctdt_size = br.ReadInt32();                  int ctdt_size = br.ReadInt32();
224                    
225                  int ctdt_type = br.ReadInt32();                  int ctdt_type = br.ReadInt32();
226                  string ctdt_type_string = "";                  string ctdt_type_string = "";
227    
# Line 127  namespace libTES3FileFormat Line 236  namespace libTES3FileFormat
236                  short ctdt_value = br.ReadInt16();                  short ctdt_value = br.ReadInt16();
237                  short ctdt_echant_pts = br.ReadInt16();                  short ctdt_echant_pts = br.ReadInt16();
238    
239    
240                    entry.CLOT_CTDT_SIZE = ctdt_size; // set the size
241                    entry.CLOT_CTDT_TYPE = ctdt_type; // set the type
242                    entry.CLOT_CTDT_WEIGHT = ctdt_weight; // set the weight
243                    entry.CLOT_CTDT_VALUE = ctdt_value; // set the value
244                    entry.CLOT_CTDT_ENCHANTPTS = ctdt_echant_pts; // set the enchant pts
245    
246                  this.Log.WriteLine("\t\tClothing Data: ");                  this.Log.WriteLine("\t\tClothing Data: ");
247                  this.Log.WriteLine("\t\t\tType: " + ctdt_type + " (" + ctdt_type_string +")");                  this.Log.WriteLine("\t\t\tType: " + ctdt_type + " (" + ctdt_type_string +")");
248                  this.Log.WriteLine("\t\t\tWeight: " + ctdt_weight);                  this.Log.WriteLine("\t\t\tWeight: " + ctdt_weight);
# Line 143  namespace libTES3FileFormat Line 259  namespace libTES3FileFormat
259                  int length_till_end_of_section = (name_offset + section_size) - (int)br.BaseStream.Position;                  int length_till_end_of_section = (name_offset + section_size) - (int)br.BaseStream.Position;
260    
261    
262                  try                  //try
263                  {                  //{
264                      byte[] extra_clothing_data = br.ReadBytes(length_till_end_of_section);                  byte[] extra_clothing_data = br.ReadBytes(length_till_end_of_section);
265                  }                  entry.CLOT_OTHER_DATA = extra_clothing_data; // set the extra data
266                  catch { break; }                  //}
267                    //catch { break; }
268    
269                  //break;                  //break;
270                    this.ClothingEntries.Add(entry);
271              }              }
272                                        
273    
# Line 202  namespace libTES3FileFormat Line 319  namespace libTES3FileFormat
319                  this.reader = new MemoryStream();                  this.reader = new MemoryStream();
320                  this.Log = new ConsoleLog();                  this.Log = new ConsoleLog();
321                  this.ClothingSectionOffsets = new List<int>();                  this.ClothingSectionOffsets = new List<int>();
322                    
323              }              }
324              public SectionLocater(BinaryReader br, int CurrentOffset, ConsoleLog Log) : this()              public SectionLocater(BinaryReader br, int CurrentOffset, ConsoleLog Log) : this()
325              {              {
# Line 267  namespace libTES3FileFormat Line 385  namespace libTES3FileFormat
385              #endregion              #endregion
386          }          }
387          #endregion          #endregion
388    
389    
390      }      }
391  }  }

Legend:
Removed from v.19  
changed lines
  Added in v.20

  ViewVC Help
Powered by ViewVC 1.1.22