Exemplo n.º 1
0
 private void ParseFileForCells(BinaryReader br, string PluginName, Dictionary<string, bool> IgnoreList, Dictionary<string, bool> CellList) {
     List<string> Masters = new List<string>() { PluginName.ToLower(Statics.Culture) };
     if (DEBUG) allWarnings.Add("PLUGIN=" + Masters[0]);
     int DEBUG_cells = 0;
     int DEBUG_refs = 0;
     int DEBUG_added = 0;
     int DEBUG_moved = 0;
     int DEBUG_deleted = 0;
     while (br.BaseStream.Position < br.BaseStream.Length) {
         string s = ReadString(br);
         int size = br.ReadInt32();
         br.BaseStream.Position += 8;
         switch (s) {
             case "TES3":
                 int read = 0;
                 while (read < size) {
                     s = ReadString(br);
                     int size2 = br.ReadInt32();
                     read += size2 + 8;
                     long pos = br.BaseStream.Position;
                     switch (s) {
                         case "MAST":
                             Masters.Add(ReadCString(br, size2).ToLower(Statics.Culture));
                             if (DEBUG) allWarnings.Add("MASTER[" + (Masters.Count - 1) + "]=" + Masters[Masters.Count-1]);
                             break;
                     }
                     br.BaseStream.Position = pos + size2;
                 }
                 break;
             case "CELL":
                 if (DEBUG) DEBUG_cells++;
                 string CellName = "";
                 bool IsValidCell = false;
                 bool InReference = false;
                 bool ReferenceHasScale = false;
                 bool ReferenceDeleted = false;
                 bool ReadData = false;
                 bool Interior = false;
                 uint RefID = 0;
                 int MastID = 0;
                 int CellX = 0;
                 int CellY = 0;
                 StaticReference sr = new StaticReference();
                 read = 0;
                 while (read < size) {
                     s = ReadString(br);
                     int size2 = br.ReadInt32();
                     read += size2 + 8;
                     long pos = br.BaseStream.Position;
                     switch (s) {
                         case "DATA":
                             if (!InReference) {
                                 if (ReadData) break;
                                 uint flags = br.ReadUInt32();
                                 if ((flags & 0x01) == 0 || (cbStatIntExt.Checked && (flags & 0x81) == 0x81) || (cbStatIntWater.Checked && (flags & 0x83) == 0x03)) IsValidCell = true;
                                 if ((flags & 0x01) != 0) {
                                     Interior = true;
                                     if (CellList.ContainsKey(CellName.ToLower(Statics.Culture))) IsValidCell = CellList[CellName.ToLower(Statics.Culture)];
                                 }
                                 else Interior = false;
                                 CellX = br.ReadInt32();
                                 CellY = br.ReadInt32();
                                 ReadData = true;
                             } else {
                                 sr.x = br.ReadSingle();
                                 sr.y = br.ReadSingle();
                                 sr.z = br.ReadSingle();
                                 sr.yaw = br.ReadSingle();
                                 sr.pitch = br.ReadSingle();
                                 sr.roll = br.ReadSingle();
                             }
                             break;
                         case "FRMR":
                             if (DEBUG) DEBUG_refs++;
                             if (!IsValidCell) break;
                             if (InReference) {
                                 if (!ReferenceHasScale) sr.scale = 1;
                                 if (StaticsList.ContainsKey(sr.name) && (!IgnoreList.ContainsKey(sr.name) || !IgnoreList[sr.name])) {
                                     sr.SetID(StaticsList, StaticMap);
                                     string Worldspace = Interior ? CellName : "";
                                     string Reference = Masters[MastID] + "\u0001" + (Interior ? "" : CellX + "\u0002" + CellY + "\u0001") + RefID;
                                     if (ReferenceDeleted) {
                                         if (UsedStaticsList.ContainsKey(Worldspace) && UsedStaticsList[Worldspace].ContainsKey(Reference)) UsedStaticsList[Worldspace].Remove(Reference);
                                     }
                                     else {
                                         if (!UsedStaticsList.ContainsKey(Worldspace)) UsedStaticsList.Add(Worldspace, new Dictionary<string, StaticReference>());
                                         UsedStaticsList[Worldspace][Reference] = sr;
                                     }
                                     if (DEBUG) {
                                         if (ReferenceDeleted) ++DEBUG_deleted;
                                         else if (MastID > 0) ++DEBUG_moved;
                                         else ++DEBUG_added;
                                     }
                                 }
                             }
                             RefID = br.ReadUInt32();
                             MastID = (int)(RefID >> 24);
                             RefID &= 0x00FFFFFF;
                             sr = new StaticReference();
                             InReference = true;
                             ReferenceHasScale = false;
                             ReferenceDeleted = false;
                             break;
                         case "DELE":
                             ReferenceDeleted = true;
                             break;
                         case "NAME":
                             if (InReference) sr.name = ReadCString(br, size2).ToLower(Statics.Culture);
                             else CellName = ReadCString(br, size2);
                             break;
                         case "XSCL":
                             if (!InReference) break;
                             sr.scale = br.ReadSingle();
                             ReferenceHasScale = true;
                             break;
                     }
                     br.BaseStream.Position = pos + size2;
                 }
                 if (InReference) {
                     if (!ReferenceHasScale) sr.scale = 1;
                     if (StaticsList.ContainsKey(sr.name) && (!IgnoreList.ContainsKey(sr.name) || !IgnoreList[sr.name])) {
                         sr.SetID(StaticsList, StaticMap);
                         string Worldspace = Interior ? CellName : "";
                         string Reference = Masters[MastID] + "\u0001" + (Interior ? "" : CellX + "\u0002" + CellY + "\u0001") + RefID;
                         if (ReferenceDeleted) {
                             if (UsedStaticsList.ContainsKey(Worldspace) && UsedStaticsList[Worldspace].ContainsKey(Reference)) UsedStaticsList[Worldspace].Remove(Reference);
                         }
                         else {
                             if (!UsedStaticsList.ContainsKey(Worldspace)) UsedStaticsList.Add(Worldspace, new Dictionary<string, StaticReference>());
                             UsedStaticsList[Worldspace][Reference] = sr;
                         }
                         if (DEBUG) {
                             if (ReferenceDeleted) ++DEBUG_deleted;
                             else if (MastID > 0) ++DEBUG_moved;
                             else ++DEBUG_added;
                         }
                     }
                 }
                 break;
             default:
                 br.BaseStream.Position += size;
                 break;
         }
     }
     if (DEBUG) allWarnings.Add("Scanning summary for: " + PluginName + " : " + DEBUG_cells + " cells : " + DEBUG_refs + " refs : " + DEBUG_added + " added : " + DEBUG_moved + " moved : " + DEBUG_deleted + " deleted");
 }