Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal void WriteFourCC(string fourCC)
- {
- byte[] arr = Encoding.ASCII.GetBytes(fourCC);
- Array.Reverse(arr);
- if (arr.Length < 4)
- {
- byte[] backup = arr;
- arr = new byte[arr.Length + 1];
- backup.CopyTo(arr, 0);
- }
- int test = BitConverter.ToInt32(arr, 0);
- WriteInt32(BitConverter.ToInt32(arr,0));
- }
- internal void WriteInt32( int intVal )
- {
- WriteBits(intVal, 32);
- }
- // passing 5730135 into function, which is equal to 'WoW' (WoW + chr(0) to make 4 chars)
- internal void WriteBits<T>(T valz, int numBits)
- {
- if (numBits > 0)
- {
- // becomes 43 (+ 32 to old result)
- _numBits += numBits;
- while (true)
- {
- // WritePos = 11, pos7 becomes 3
- // second run, WritePos = 16, pos7 = 0
- // 3rd run, WritePos = 32, pos7 = 0
- // 4th run, WritePos = 40, pos7 = 0
- // 5th run, WritePos = 40, pos7 = 0
- int pos7 = (WritePos & 7);
- // unk = 5
- // second run, unk = 8
- // 3rd + 4th + 5th, unk = 8
- int unk = 8 - pos7;
- // lShift = 32
- // second run, 256
- // 3rd, 4th, 5th = 256
- var lShift = (char) (1 << unk);
- int subNum;
- if (unk < numBits)
- // = 5
- // second run, 8
- // 3rd = 8
- // 4th = 8
- subNum = unk;
- else
- {
- // 5th run
- // lshift = 8
- lShift = (char) (1 << numBits);
- // subnum = 3
- subNum = numBits;
- }
- // numbits = 27 now
- // second run, 19
- // 4th = 3
- // 5th = 0
- numBits -= subNum;
- // 65287
- // 65280 second run & 3rd & 4th
- // 65528 = 5th
- var firstHalf = (char) (~((lShift - 1) << pos7));
- // both 0
- // second run, both 10
- // 3rd run = 2797
- // 4th run = 60906
- // 5th run = 28503
- var shifted = (char) Shift(valz, numBits);
- // 3rd run = 237
- // 4th run = 234
- // 5th run = 7
- var secondHalf = (char) (((lShift - 1) & shifted) << pos7);
- Buffer[WritePos >> 3] = (byte) (Buffer[WritePos >> 3] & firstHalf | secondHalf);
- // writepos = 16
- // second run, writepos = 24
- // 3rd run, = 32
- // 4th run = 40
- // 5th run = 43
- WritePos += subNum;
- // 5th run = 0
- if (numBits == 0)
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement