//public int InsertAndCombine(int StartingValue, int AddingValue, out uint Mask, out byte ShiftVal) //{ // Mask = 0; // ShiftVal = 0; // BitArray StartingBits = new BitArray(new int[] { StartingValue }); // BitArray AddingBits = new BitArray(new int[] { AddingValue }); // int MinAddBitSize = GetMinLength(AddingValue); // bool success = false; // for (int i = 0; i < StartingBits.Count - MinAddBitSize; i++) // { // if (StartingBits[i] == AddingBits[0]) // { // bool CanFit = true; // for (int j = 0; j < MinAddBitSize; j++) // { // if (StartingBits[i + j] != AddingBits[j]) // { // CanFit = false; // break; // } // } // if (CanFit) // { // success = true; // BitArray BitMask = new BitArray(new int[1]); // for (int j = 0; j < MinAddBitSize; j++) // { // BitMask[i + j] = true; // } // Mask = (uint)BitMask.ToInt32(); // ShiftVal = (byte)i; // break; // } // } // } // if (!success) // { // int NumberInsertLocation = GetMinLength(StartingValue); // int BackwardsOffset = 0; // bool HasFoundFit = false; // int BestFitOffset = 0; // while (NumberInsertLocation - BackwardsOffset > 0) // { // if (StartingBits[NumberInsertLocation - BackwardsOffset] == AddingBits[0]) // { // bool CanFit = true; // for (int i = 0; i < MinAddBitSize; i++) // { // if (AddingBits[i] && StartingBits[(NumberInsertLocation - BackwardsOffset) + i] != AddingBits[i]) // { // if ((NumberInsertLocation - BackwardsOffset) + i < NumberInsertLocation) // { // CanFit = false; // break; // } // } // } // if (CanFit) // { // HasFoundFit = true; // BestFitOffset = NumberInsertLocation - BackwardsOffset; // break; // } // } // BackwardsOffset++; // } // for (int j = 0; j < MinAddBitSize; j++) // { // StartingBits[HasFoundFit ? BestFitOffset + j : NumberInsertLocation] = AddingBits[j]; // } // BitArray BitMask = new BitArray(new int[1]); // for (int j = 0; j < MinAddBitSize; j++) // { // BitMask[HasFoundFit ? BestFitOffset + j : NumberInsertLocation] = true; // } // Mask = (uint)BitMask.ToInt32(); // ShiftVal = (byte)(HasFoundFit ? BestFitOffset : NumberInsertLocation); // } // return StartingBits.ToInt32(); //} //private int GetMinLength(int val) //{ // for (int i = 28; i >= 0; i -= 4) // if ((val >> i) > 0) // return i + 4; // return 0; //} internal void Read(Stream BCSV) { Fields = new Dictionary <uint, BCSVField>(); Entries = new List <BCSVEntry>(); int entrycount = BitConverter.ToInt32(BCSV.ReadReverse(0, 4), 0); //Console.Write($"{entrycount} Entries "); int fieldcount = BitConverter.ToInt32(BCSV.ReadReverse(0, 4), 0); //Console.WriteLine($"done with {fieldcount} fields"); uint dataoffset = BitConverter.ToUInt32(BCSV.ReadReverse(0, 4), 0); uint entrysize = BitConverter.ToUInt32(BCSV.ReadReverse(0, 4), 0); //Console.WriteLine("Loading Fields:"); for (int i = 0; i < fieldcount; i++) { BCSVField currentfield = new BCSVField(BCSV); Fields.Add(currentfield.HashName, currentfield); //Console.Write($"\r{Math.Min(((float)(i + 1) / (float)fieldcount) * 100.0f, 100.0f)}% "); } //Console.WriteLine("Complete!"); //Console.WriteLine("Loading Entries:"); for (int i = 0; i < entrycount; i++) { BCSVEntry currententry = new BCSVEntry(BCSV, Fields, dataoffset + (entrycount * entrysize)); Entries.Add(currententry); BCSV.Position += entrysize; //Console.Write($"\r{Math.Min(((float)(i + 1) / (float)entrycount) * 100.0f, 100.0f)}% "); } //Console.WriteLine("Complete!"); }
/// <summary> /// Removes a specific BCSVEntry /// </summary> /// <param name="entry">The entry to remove</param> public void Remove(BCSVEntry entry) => Entries.Remove(entry);
/// <summary> /// Add a BCSVEntry to the Entry List /// </summary> /// <param name="entry">Entry to add</param> public void Add(BCSVEntry entry) => Entries.Add(entry);