Esempio n. 1
0
 /// <summary>
 /// Runescape Font. Doesn't work!
 /// </summary>
 public RSFont(bool flag, string fontName, ArchiveParser titleArchive)
 {
     glyphPixels = new List<byte[]>();
     glyphWidth = new int[256];
     glyphHeight = new int[256];
     horizontalKerning = new int[256];
     verticalKerning = new int[256];
     charEffectiveWidth = new int[256];
     random = new Random();
     isStrikethrough = false;
     byte[] data = titleArchive.getFile(fontName + ".dat");
     byte[] index = titleArchive.getFile("index.dat");
     dataReader = new BigEndianBinaryReader(new MemoryStream(data));
     indexReader = new BigEndianBinaryReader(new MemoryStream(index));
     int pos = dataReader.ReadInt16() + 4;
     int k = indexReader.ReadByte();
     if (k > 0)
         pos += 3 * (k - 1);
     indexReader.BaseStream.Position = pos;
     for (int l = 0; l < 256; l++)
     {
         horizontalKerning[l] = indexReader.ReadChar();
         verticalKerning[l] = indexReader.ReadChar();
         int width = glyphWidth[l] = indexReader.ReadInt16();
         int height = glyphWidth[l] = indexReader.ReadInt16();
         int k1 = indexReader.ReadByte();
         int l1 = width * height;
         glyphPixels.Add(new byte[l1]);
         if (k1 == 0)
             for (int i = 0; i < l1; i++)
                 glyphPixels[l][i] = dataReader.ReadByte();
         else
             if (k1 == 1)
                 for (int j = 0; j < width; j++)
                     for (int l2 = 0; l2 < height; l2++)
                         glyphPixels[l][j + l2 * width] = dataReader.ReadByte();
         if (height > charHeight && l < 128)
             charHeight = height;
         horizontalKerning[l] = 1;
         charEffectiveWidth[l] = width + 2;
         int k2 = 0;
         for (int i = height / 7; i < height; i++)
             k2 += glyphPixels[l][i * width];
         if (k2 <= height / 7)
         {
             charEffectiveWidth[l]--;
             horizontalKerning[l] = 0;
         }
         k2 = 0;
         for (int j = height / 7; j < height; j++)
             k2 += glyphPixels[l][(width - 1) + j * width];
         if (k2 <= height / 7)
             charEffectiveWidth[l]--;
     }
     if (flag)
         charEffectiveWidth[32] = charEffectiveWidth[73];
     else
         charEffectiveWidth[32] = charEffectiveWidth[105];
 }
Esempio n. 2
0
 //Parses flo.dat from config.jag
 //Yup it's fixed
 public static FloorConfig[] ParseFloorConfig(byte[] floorData)
 {
     int floorCount;
     FloorConfig[] floors;
     BigEndianBinaryReader floorReader = new BigEndianBinaryReader(new MemoryStream(floorData));
     floorCount = floorReader.ReadUInt16();
     floors = new FloorConfig[floorCount];
     bool finishFloor = false;
     for (int i = 0; i < floorCount; i++)
     {
         floors[i] = new FloorConfig();
         finishFloor = false;
         do
         {
             int type = floorReader.ReadByte();
             switch (type)
             {
                 case 0:
                     finishFloor = true;
                     break;
                 case 1:
                     floors[i].actualColor = toRGB(floorReader.ReadUInt24());
                     break;
                 case 2:
                     floors[i].texture = floorReader.ReadByte();
                     break;
                 case 3:
                     floors[i].unknown = true;
                     break;
                 case 5:
                     floors[i].occlude = false;
                     break;
                 case 6:
                     floors[i].floorName = floorReader.ReadString().TrimEnd('\n');
                     break;
                 case 7:
                     floors[i].mapColor = toRGB(floorReader.ReadUInt24());
                     break;
                 default:
                     Logger.Log("Unrecognized floor type: " + type, LogType.Error);
                     break;
             }
         } while (!finishFloor);
         Logger.Log(floors[i].ToString(), LogType.Success);
     }
     return floors;
 }
Esempio n. 3
0
 public ImageGroup(byte[] index, byte[] data, bool unpack)
 {
     indexReader = new BigEndianBinaryReader(new MemoryStream(index));
     dataReader = new BigEndianBinaryReader(new MemoryStream(data));
     indexReader.BaseStream.Position = dataReader.ReadUInt16();
     indexOffset = (int)indexReader.BaseStream.Position;
     maxWidth = indexReader.ReadUInt16();
     maxHeight = indexReader.ReadUInt16();
     colorCount = indexReader.ReadByte();
     colorMap = new int[colorCount];
     for (int x = 0; x < colorCount - 1; x++)
     {
         colorMap[x + 1] = indexReader.ReadUInt24();
         if (colorMap[x + 1] == 0)
             colorMap[x + 1] = 1;
     }
     if(unpack)
         unpackImages();
 }
Esempio n. 4
0
 public static ItemConfig[] ParseItemConfig(byte[] data, byte[] index)
 {
     BigEndianBinaryReader dataReader = new BigEndianBinaryReader(new MemoryStream(data));
     BigEndianBinaryReader indexReader = new BigEndianBinaryReader(new MemoryStream(index));
     int totalItems = indexReader.ReadUInt16();
     int[] streamIndices = new int[totalItems];
     ItemConfig[] itemConfig = new ItemConfig[totalItems];
     int i = 2;
     for (int j = 0; j < totalItems; j++)
     {
         streamIndices[j] = i;
         i += indexReader.ReadUInt16();
     }
     for (int x = 0; x < totalItems; x++)
     {
         dataReader.BaseStream.Position = streamIndices[x];
         ItemConfig item = new ItemConfig();
         do
         {
             int opCode = dataReader.ReadByte();
             if (opCode == 0)
                 break;
             if (opCode == 1)
                 item.modelID = dataReader.ReadUInt16();
             else if (opCode == 2)
                 item.name = dataReader.ReadString().TrimEnd('\n');
             else if (opCode == 3)
                 item.description = dataReader.ReadString().TrimEnd('\n');
             else if (opCode == 4)
                 item.modelInvZoom = dataReader.ReadUInt16();
             else if (opCode == 5)
                 item.modelInvRotationY = dataReader.ReadUInt16();
             else if (opCode == 6)
                 item.modelInvRotationX = dataReader.ReadUInt16();
             else if (opCode == 7)
             {
                 item.modelInvPosOffsetX = dataReader.ReadUInt16();
                 if (item.modelInvPosOffsetX > 32767)
                     item.modelInvPosOffsetX -= 0x10000;
             }
             else if (opCode == 8)
             {
                 item.modelInvPosOffsetY = dataReader.ReadUInt16();
                 if (item.modelInvPosOffsetY > 32767)
                     item.modelInvPosOffsetY -= 0x10000;
             }
             else if (opCode == 10)
                 dataReader.ReadUInt16();
             else if (opCode == 11)
                 item.stackable = true;
             else if (opCode == 12)
                 item.value = dataReader.ReadInt32();
             else if (opCode == 16)
                 item.membersObject = true;
             else if (opCode == 23)
             {
                 item.maleWornModelID = dataReader.ReadUInt16();
                 item.maleYOffset = dataReader.ReadByte();
             }
             else if (opCode == 24)
                 item.maleArmsID = dataReader.ReadUInt16();
             else if (opCode == 25)
             {
                 item.femaleWornModelID = dataReader.ReadUInt16();
                 item.femaleYOffset = dataReader.ReadByte();
             }
             else if (opCode == 26)
                 item.femaleArmsID = dataReader.ReadUInt16();
             else if (opCode >= 30 && opCode < 35)
             {
                 if (item.groundActions == null)
                     item.groundActions = new string[5];
                 item.groundActions[opCode - 30] = dataReader.ReadString().TrimEnd('\n');
                 if (item.groundActions[opCode - 30].ToLower() == "hidden")
                     item.groundActions[opCode - 30] = null;
             }
             else if (opCode >= 35 && opCode < 40)
             {
                 if (item.actions == null)
                     item.actions = new string[5];
                 item.actions[opCode - 35] = dataReader.ReadString().TrimEnd('\n');
             }
             else if (opCode == 40)
             {
                 int colors = dataReader.ReadByte();
                 item.originalModelColors = new int[colors];
                 item.modifiedModelColors = new int[colors];
                 for (int colorPtr = 0; colorPtr < colors; colorPtr++)
                 {
                     item.originalModelColors[colorPtr] = dataReader.ReadUInt16();
                     item.modifiedModelColors[colorPtr] = dataReader.ReadUInt16();
                 }
             }
             else if (opCode == 78)
                 item.maleEmblem = dataReader.ReadUInt16();
             else if (opCode == 79)
                 item.femaleEmblem = dataReader.ReadUInt16();
             else if (opCode == 90)
                 item.maleDialog = dataReader.ReadUInt16();
             else if (opCode == 91)
                 item.femaleDialog = dataReader.ReadUInt16();
             else if (opCode == 92)
                 item.maleDialogHat = dataReader.ReadUInt16();
             else if (opCode == 93)
                 item.femaleDialogHat = dataReader.ReadUInt16();
             else if (opCode == 95)
                 item.diagonalRotation = dataReader.ReadUInt16();
             else if (opCode == 97)
                 item.certID = dataReader.ReadUInt16();
             else if (opCode == 98)
                 item.certTemplateID = dataReader.ReadUInt16();
             else if (opCode >= 100 && opCode < 110)
             {
                 if (item.stackIDs == null)
                 {
                     item.stackIDs = new int[10];
                     item.stackAmounts = new int[10];
                 }
                 item.stackIDs[opCode - 100] = dataReader.ReadUInt16();
                 item.stackAmounts[opCode - 100] = dataReader.ReadUInt16();
             }
             else if (opCode == 110)
                 item.modelSizeX = dataReader.ReadUInt16();
             else if (opCode == 111)
                 item.modelSizeY = dataReader.ReadUInt16();
             else if (opCode == 112)
                 item.modelSizeZ = dataReader.ReadUInt16();
             else if (opCode == 113)
                 item.lightModifier = dataReader.ReadUInt16();
             else if (opCode == 114)
                 item.shadowModifier = dataReader.ReadByte() * 5;
             else if (opCode == 115)
                 item.team = dataReader.ReadByte();
             else if (opCode == 116)
                 item.lendID = dataReader.ReadUInt16();
             else if (opCode == 117)
                 item.lentItemID = dataReader.ReadUInt16();
             else
                 Logger.Log("Unknown Item Opcode: " + opCode, LogType.Error);
         } while (true);
         itemConfig[x] = item;
     }
     return itemConfig;
 }
Esempio n. 5
0
 public static ObjectConfig[] ParseObjectConfig(byte[] data, byte[] index)
 {
     BigEndianBinaryReader indexReader = new BigEndianBinaryReader(new MemoryStream(index));
     BigEndianBinaryReader dataReader = new BigEndianBinaryReader(new MemoryStream(data));
     ObjectConfig[] obj = new ObjectConfig[indexReader.ReadUInt16()];
     int sIndex = 2;
     int[] streamIndices = new int[obj.Length];
     for (int i = 0; i < streamIndices.Length; i++)
     {
         streamIndices[i] = sIndex;
         sIndex += indexReader.ReadUInt16();
     }
     for (int j = 0; j < obj.Length; j++)
     {
         if (obj[j] == null) obj[j] = new ObjectConfig();
         dataReader.BaseStream.Position = streamIndices[j];
         bool breakTop = false;
         bool continueTop = false;
         int t = 0;
         do
         {
             continueTop = false;
             int k;
             do
             {
                 k = dataReader.ReadByte();
                 if (k == 0)
                     breakTop = true;
                 else if (k == 1)
                 {
                     int l = dataReader.ReadByte();
                     if (l > 0)
                         if (obj[j].objectModelIDs == null)
                         {
                             obj[j].types = new int[l];
                             obj[j].objectModelIDs = new int[l];
                             for (int k1 = 0; k1 < l; k1++)
                             {
                                 obj[j].objectModelIDs[k1] = dataReader.ReadUInt16();
                                 obj[j].types[k1] = dataReader.ReadByte();
                             }
                         }
                         else
                             dataReader.BaseStream.Position += l * 3;
                 }
                 else if (k == 2)
                     obj[j].name = dataReader.ReadString();
                 else if (k == 3)
                     obj[j].description = dataReader.ReadString();
                 else if (k == 5)
                 {
                     int l = dataReader.ReadByte();
                     if (l > 0)
                         if (obj[j].objectModelIDs == null)
                         {
                             obj[j].types = null;
                             obj[j].objectModelIDs = new int[l];
                             for (int l1 = 0; l1 < l; l1++)
                                 obj[j].objectModelIDs[l1] = dataReader.ReadUInt16();
                         }
                         else dataReader.BaseStream.Position += l * 2;
                 }
                 else if (k == 14)
                     obj[j].sizeX = dataReader.ReadByte();
                 else if (k == 15)
                     obj[j].sizeY = dataReader.ReadByte();
                 else if (k == 17)
                     obj[j].isUnwalkable = false;
                 else if (k == 18)
                     obj[j].aBoolean757 = false;
                 else if (k == 19)
                 {
                     t = dataReader.ReadByte();
                     if (t == 1)
                         obj[j].hasActions = true;
                 }
                 else if (k == 21)
                     obj[j].adjustToTerrain = true;
                 else if (k == 22)
                     obj[j].nonFlatShading = true;
                 else if (k == 23)
                     obj[j].aBoolean764 = true;
                 else if (k == 24)
                 {
                     obj[j].animationID = dataReader.ReadUInt16();
                     if (obj[j].animationID == 65535) obj[j].animationID = -1;
                 }
                 else if (k == 28)
                     obj[j].anInt775 = dataReader.ReadByte();
                 else if (k == 29)
                     obj[j].brightness = dataReader.ReadByte();
                 else if (k == 39)
                     obj[j].contrast = dataReader.ReadByte();
                 else if (k >= 30 && k < 39)
                 {
                     if (obj[j].actions == null)
                         obj[j].actions = new string[10];
                     obj[j].actions[k - 30] = dataReader.ReadString();
                     if (obj[j].actions[k - 30].ToLower() == "hidden")
                         obj[j].actions[k - 30] = null;
                 }
                 else if (k == 40)
                 {
                     int i1 = dataReader.ReadByte();
                     obj[j].modifiedModelColors = new int[i1];
                     obj[j].originalModelColors = new int[i1];
                     for (int i2 = 0; i2 < i1; i2++)
                     {
                         obj[j].modifiedModelColors[i2] = dataReader.ReadUInt16();
                         obj[j].originalModelColors[i2] = dataReader.ReadUInt16();
                     }
                 }
                 else if (k == 60)
                     obj[j].mapFunctionID = dataReader.ReadUInt16();
                 else if (k == 62)
                     obj[j].aBoolean751 = true;
                 else if (k == 64)
                     obj[j].aBoolean779 = false;
                 else if (k == 65)
                     obj[j].modelSizeX = dataReader.ReadUInt16();
                 else if (k == 66)
                     obj[j].modelSizeH = dataReader.ReadUInt16();
                 else if (k == 67)
                     obj[j].modelSizeY = dataReader.ReadUInt16();
                 else if (k == 68)
                     obj[j].mapSceneID = dataReader.ReadUInt16();
                 else if (k == 69)
                     obj[j].anInt768 = dataReader.ReadByte();
                 else if (k == 70)
                     obj[j].offsetX = dataReader.ReadUInt16();
                 else if (k == 71)
                     obj[j].offsetH = dataReader.ReadUInt16();
                 else if (k == 72)
                     obj[j].offsetY = dataReader.ReadUInt16();
                 else if (k == 73)
                     obj[j].aBoolean736 = true;
                 else if (k == 74)
                     obj[j].isSolidObject = true;
                 else
                 {
                     if (k != 75)
                         continue;
                     obj[j].anInt760 = dataReader.ReadByte();
                 }
                 continueTop = true;
             } while (k != 77 && !breakTop);
             if (breakTop) break;
             if (continueTop) continue;
             obj[j].configId_1 = dataReader.ReadUInt16();
             if (obj[j].configId_1 == 65535)
                 obj[j].configId_1 = -1;
             obj[j].configId_1 = dataReader.ReadUInt16();
             if (obj[j].configID == 65535)
                 obj[j].configID = -1;
             int j1 = dataReader.ReadByte();
             obj[j].configObjectIDs = new int[j1 + 1];
             for (int j2 = 0; j2 <= j1; j2++)
             {
                 obj[j].configObjectIDs[j2] = dataReader.ReadUInt16();
                 if (obj[j].configObjectIDs[j2] == 65535)
                     obj[j].configObjectIDs[j2] = -1;
             }
         } while (!breakTop);
         if (t == -1)
         {
             obj[j].hasActions = obj[j].objectModelIDs != null;
             if (obj[j].actions != null)
                 obj[j].hasActions = true;
         }
         if (obj[j].isSolidObject)
             obj[j].isUnwalkable = obj[j].aBoolean757 = false;
         if (obj[j].anInt760 == -1)
             obj[j].anInt760 = obj[j].isUnwalkable ? 1 : 0;
     }
     return obj;
 }
Esempio n. 6
0
 public static NPCConfig[] ParseNPCConfig(byte[] data, byte[] index)
 {
     BigEndianBinaryReader dataReader = new BigEndianBinaryReader(new MemoryStream(data));
     BigEndianBinaryReader indexReader = new BigEndianBinaryReader(new MemoryStream(index));
     int totalNPCs = indexReader.ReadUInt16();
     NPCConfig[] NPCList = new NPCConfig[totalNPCs];
     int[] streamIndices = new int[totalNPCs];
     int offset = 2;
     for (int npcPtr = 0; npcPtr < totalNPCs; npcPtr++)
     {
         streamIndices[npcPtr] = offset;
         offset += indexReader.ReadUInt16();
     }
     for (int j = 0; j < totalNPCs; j++)
     {
         NPCConfig npc = new NPCConfig();
         dataReader.BaseStream.Position = streamIndices[j];
         do
         {
             byte i = dataReader.ReadByte();
             if (i == 0)
                 break;
             else if (i == 1)
             {
                 int modelCount = dataReader.ReadByte();
                 npc.npcModels = new int[modelCount];
                 for (int k = 0; k < modelCount; k++)
                     npc.npcModels[k] = dataReader.ReadUInt16();
             }
             else if (i == 2)
                 npc.name = dataReader.ReadString();
             else if (i == 3)
                 npc.description = dataReader.ReadString();
             else if (i == 12)
                 npc.boundDim = dataReader.ReadByte();
             else if (i == 13)
                 npc.idleAnimation = dataReader.ReadUInt16();
             else if (i == 14)
                 npc.walkAnimIndex = dataReader.ReadUInt16();
             else if (i == 17)
             {
                 npc.walkAnimIndex = dataReader.ReadUInt16();
                 npc.turn180AnimIndex = dataReader.ReadUInt16();
                 npc.turn90CWAnimIndex = dataReader.ReadUInt16();
                 npc.turn90CCWAnimIndex = dataReader.ReadUInt16();
             }
             else if (i >= 30 && i < 40)
             {
                 if (npc.actions == null)
                     npc.actions = new string[5];
                 npc.actions[i - 30] = dataReader.ReadString();
                 if (npc.actions[i - 30] == "hidden")
                     npc.actions[i - 30] = null;
             }
             else if (i == 40)
             {
                 int colors = dataReader.ReadByte();
                 npc.recolorOriginal = new int[colors];
                 npc.recolorTarget = new int[colors];
                 for (int l = 0; l < colors; l++)
                 {
                     npc.recolorOriginal[l] = dataReader.ReadUInt16();
                     npc.recolorTarget[l] = dataReader.ReadUInt16();
                 }
             }
             else if (i == 60)
             {
                 int additionalModelCount = dataReader.ReadByte();
                 npc.additionalModels = new int[additionalModelCount];
                 for (int l = 0; l < additionalModelCount; l++)
                     npc.additionalModels[l] = dataReader.ReadUInt16();
             }
             else if (i >= 90 && i < 93)
                 dataReader.ReadUInt16();
             else if (i == 93)
                 npc.drawMinimapDot = false;
             else if (i == 95)
                 npc.combatLevel = dataReader.ReadUInt16();
             else if (i == 97)
                 npc.scaleXZ = dataReader.ReadUInt16();
             else if (i == 98)
                 npc.scaleY = dataReader.ReadUInt16();
             else if (i == 99)
                 npc.invisible = true;
             else if (i == 100)
                 npc.lightModifier = dataReader.ReadByte();
             else if (i == 101)
                 npc.shadowModifier = dataReader.ReadByte() * 5;
             else if (i == 102)
                 npc.headIcon = dataReader.ReadUInt16();
             else if (i == 103)
                 npc.degreesToTurn = dataReader.ReadUInt16();
             else if (i == 106)
             {
                 npc.varBitID = dataReader.ReadUInt16();
                 if (npc.varBitID == 65535)
                     npc.varBitID = -1;
                 npc.sessionSettingID = dataReader.ReadUInt16();
                 if (npc.sessionSettingID == 65535)
                     npc.sessionSettingID = -1;
                 int childrensCount = dataReader.ReadByte();
                 npc.childrenIDs = new int[childrensCount + 1];
                 for (int c = 0; c <= childrensCount; c++)
                 {
                     npc.childrenIDs[c] = dataReader.ReadUInt16();
                     if (npc.childrenIDs[c] == 65535)
                         npc.childrenIDs[c] = -1;
                 }
             }
             else if (i == 107)
                 npc.clickable = false;
         }
         while (true);
         NPCList[j] = npc;
     }
     return NPCList;
 }
Esempio n. 7
0
 public static string[] ParseTldList(byte[] tldenc)
 {
     BigEndianBinaryReader br = new BigEndianBinaryReader(new MemoryStream(tldenc));
     int length = br.ReadInt32();
     List<char[]> tldList = new List<char[]>();
     int[] tldArray = new int[length];
     for(int id = 0; id < length; id++)
     {
         tldArray[id] = br.ReadByte();
         char[] tld = new char[br.ReadByte()];
         for (int charID = 0; charID < tld.Length; charID++)
             tld[charID] = (char)br.ReadByte();
         tldList.Add(tld);
     }
     string[] s = new string[tldList.Count];
     for (int c = 0; c < s.Length; c++)
         s[c] = new string(tldList[c]);
     return s;
 }
Esempio n. 8
0
 public static string[] ParseDomainEnc(byte[] domainenc)
 {
     BigEndianBinaryReader br = new BigEndianBinaryReader(new MemoryStream(domainenc));
     int length = br.ReadInt32();
     List<char[]> domains = new List<char[]>();
     for (int j = 0; j < length; j++)
     {
         char[] val = new char[br.ReadByte()];
         for (int k = 0; k < val.GetLength(0); k++)
             val[k] = (char)br.ReadChar();
         domains.Add(val);
     }
     string[] s = new string[domains.Count];
     for (int c = 0; c < s.Length; c++)
         s[c] = new string(domains[c]);
     return s;
 }
Esempio n. 9
0
 public static string[] ParseBadEnc(byte[] badenc)
 {
     BigEndianBinaryReader br = new BigEndianBinaryReader(new MemoryStream(badenc));
     int length = br.ReadInt32();
     List<char[]> bads = new List<char[]>();
     for (int i = 0; i < length; i++)
     {
         char[] val = new char[br.ReadChar()];
         for (int charid = 0; charid < val.Length; charid++)
             val[charid] = (char)br.ReadChar();
         bads.Add(val);
         byte[,] b1 = new byte[br.ReadByte(), 2];
         for (int l = 0; l < b1.Length/2; l++)
         {
             b1[l, 0] = (byte)br.ReadByte();
             b1[l, 1] = (byte)br.ReadByte();
         }
     }
     string[] s = new string[bads.Count];
     for(int c=0;c<s.Length;c++)
         s[c] = new string(bads[c]);
     return s;
 }