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); }
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; }