Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static public byte[] decompText(byte[] src)
- { //, int srcInd) { // int srcPos) {
- //return decompTextOld2(src);
- int total = 0; int total2 = 0;
- DateTime c = DateTime.Now;
- //Scan char data to generate data for faster decompression than old method.
- int asmpchar = Bits.getInt32(src, 0x38578) - 0x8000000;
- int asmptext = Bits.getInt32(src, 0x385DC) - 0x8000000;
- int chardata = Bits.getInt32(src, asmpchar) - 0x08000000;
- int charpntrs = Bits.getInt32(src, asmpchar + 4) - 0x08000000;
- //Do a pre-scan of char tables to determine array sizes.
- int maxLetter = 0;
- int cTreeSize = 0;
- int maxDepth = 0;
- for (int char1 = 0; char1 <= maxLetter; char1++)
- {
- if ((char1 & 0xFF) == 0)
- {
- chardata = Bits.getInt32(src, asmpchar + (char1 >> 8) * 8) - 0x08000000;
- charpntrs = Bits.getInt32(src, asmpchar + (char1 >> 8) * 8 + 4) - 0x08000000;
- }
- //if (charpntrs == asmpchar) { break; }
- if (Bits.getInt16(src, charpntrs) == 0x8000) { charpntrs += 2; continue; }
- total2 += 1;
- int charTree = (chardata + Bits.getInt16(src, charpntrs)) << 3; charpntrs += 2;
- int charSlot = charTree - 12;
- int depth = 0;
- while (true)
- {
- while (((src[charTree >> 3] >> (charTree++ & 7)) & 1) == 0) { depth++; cTreeSize++; }
- int letter = ((Bits.getInt16(src, charSlot >> 3) >> (charSlot & 7)) & 0xFFF); charSlot -= 12; total += 1;
- cTreeSize++;
- if (letter > maxLetter) { maxLetter = letter; }
- if (depth > maxDepth) { maxDepth = depth; }
- //if ((char1 == 0) && (letter == 7))
- // Console.WriteLine("0-7 depth: " + depth);
- if (depth <= 0) break;
- --depth;
- } //while (depth > 0);
- }
- Console.WriteLine("Total letter combos: " + total + " \nTotal unique letters: " + total2 + "\nMax letter: " + maxLetter + "\nMax depth: " + maxDepth + "\ncTreeSize: " + cTreeSize);
- chardata = Bits.getInt32(src, asmpchar) - 0x08000000;
- charpntrs = Bits.getInt32(src, asmpchar + 4) - 0x08000000;
- int[] ctOffsets = new int[maxLetter + 1];// 0x1000];
- int[] cTree = new int[cTreeSize];// 0x10000];
- int[] nodeOffsets = new int[maxDepth]; //0x100]; //For temp use as we label leaves first, and iterate backwards.
- //int[] ctOffsets = new int[0x1000];
- //int[] cTree = new int[0x10000];
- //int[] nodeOffsets = new int[0x100]; //For temp use as we label leaves first, and iterate backwards.
- //int depth = 0;
- int pos = 0;
- for (int char1 = 0; char1 <= maxLetter; char1++)
- {
- if ((char1 & 0xFF) == 0)
- {
- chardata = Bits.getInt32(src, asmpchar + (char1 >> 8) * 8) - 0x08000000;
- charpntrs = Bits.getInt32(src, asmpchar + (char1 >> 8) * 8 + 4) - 0x08000000;
- }
- //if (charpntrs == asmpchar) { break; }
- if (Bits.getInt16(src, charpntrs) == 0x8000) { charpntrs += 2; continue; }
- //total2 += 1;
- int charTree = (chardata + Bits.getInt16(src, charpntrs)) << 3; charpntrs += 2;
- int charSlot = charTree - 12;
- int depth = 0;
- ctOffsets[char1] = pos;
- while (true)
- {
- while (((src[charTree >> 3] >> (charTree++ & 7)) & 1) == 0) { nodeOffsets[depth++] = pos++; }
- cTree[pos++] = -((Bits.getInt16(src, charSlot >> 3) >> (charSlot & 7)) & 0xFFF); charSlot -= 12; //total += 1;
- if (depth <= 0) break;
- cTree[nodeOffsets[--depth]] = pos;
- } //while (depth > 0);
- }
- //Console.WriteLine(DateTime.Now - c);
- //c = DateTime.Now;
- int textTree = 0, textLenAddr = 0;
- byte[] des = new byte[0x800000]; int desEntry = 0, desPos = 0xC300;
- for (int srcI = 0; srcI < 12461; srcI++)
- {
- Bits.setInt32(des, desEntry, desPos - 0xC300); desEntry += 4;
- int srcInd = srcI;
- if ((srcInd & 0xFF) == 0)
- {
- textTree = Bits.getInt32(src, asmptext + ((srcInd >> 8) << 3)) - 0x08000000;
- textLenAddr = Bits.getInt32(src, asmptext + ((srcInd >> 8) << 3) + 4) - 0x08000000;
- }
- else
- {
- int cLen;
- do
- {
- cLen = src[textLenAddr++];
- textTree += cLen;
- } while (cLen == 0xFF);
- }
- int initChar = 0, textTree2 = textTree << 3;//, bitnum = 1, val = 0;
- do
- {
- pos = ctOffsets[initChar];
- while (cTree[pos] > 0)
- {
- if ((src[textTree2 >> 3] >> (textTree2++ & 7) & 1) == 0) { pos++; }
- else { pos = cTree[pos]; }
- //--- if using textTree2 = textTree; ---
- //if (bitnum >= 0x100) { bitnum = 1; textTree2++; }
- //if ((src[textTree2] & bitnum) == 0) { pos++; }
- //else { pos = cTree[pos]; }
- //bitnum <<= 1;
- }
- initChar = -cTree[pos]; //bitChar[entry]; val >>= bitLen[entry]; bitnum -= bitLen[entry];
- des[desPos++] = (byte)initChar;
- if (srcI == 5468)
- Console.Write(initChar.ToString("X2")+" ");
- } while (initChar != 0);
- }
- Console.WriteLine(DateTime.Now - c + " (Text Decompression)");
- return des;
- }
Advertisement
Add Comment
Please, Sign In to add comment