A RuneTek3 client (377) that is deobfuscated, converted to Kotlin, and includes QoL improvements.
0

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'worktree-kotlin-cache-def' into 'master'

Convert cache/def/ to Kotlin (Phase 3)

See merge request high-level-alchemy/client!2

+3426 -3939
-300
src/main/java/com/jagex/runescape/cache/def/ActorDefinition.java
··· 1 - package com.jagex.runescape.cache.def; 2 - 3 - import com.jagex.runescape.cache.Archive; 4 - import com.jagex.runescape.net.Buffer; 5 - import com.jagex.runescape.Game; 6 - import com.jagex.runescape.cache.cfg.Varbit; 7 - import com.jagex.runescape.collection.Cache; 8 - import com.jagex.runescape.media.Animation; 9 - import com.jagex.runescape.media.renderable.Model; 10 - 11 - public class ActorDefinition { 12 - 13 - public int standAnimationId = -1; 14 - public int childrenIds[]; 15 - public int headModelIndexes[]; 16 - public int modelIds[]; 17 - public int anInt627 = -1; 18 - public long id = -1L; 19 - public static Game client; 20 - public int sizeY = 128; 21 - public boolean clickable = true; 22 - public int sizeXZ = 128; 23 - public int turnLeftAnimationId = -1; 24 - public int modifiedModelColors[]; 25 - public static Cache modelCache = new Cache(30); 26 - public boolean minimapVisible = true; 27 - public int anInt637 = -1; 28 - public int headIcon = -1; 29 - public int combatLevel = -1; 30 - public int turnRightAnimationId = -1; 31 - public byte boundaryDimension = 1; 32 - public int turnAroundAnimationId = -1; 33 - public boolean visible = false; 34 - public int walkAnimationId = -1; 35 - public String actions[]; 36 - public int anInt648 = -1; 37 - public static int size; 38 - public static int bufferOffsets[]; 39 - public int degreesToTurn = 32; 40 - public String name = "null"; 41 - public int varBitId = -1; 42 - public static ActorDefinition cache[]; 43 - public int originalModelColors[]; 44 - public static Buffer buffer; 45 - public int contrast; 46 - public int settingId = -1; 47 - public byte description[]; 48 - public static int bufferIndex; 49 - public int brightness; 50 - 51 - public static ActorDefinition getDefinition(int id) { 52 - for (int j = 0; j < 20; j++) 53 - if (cache[j].id == id) 54 - return cache[j]; 55 - 56 - bufferIndex = (bufferIndex + 1) % 20; 57 - ActorDefinition definition = cache[bufferIndex] = new ActorDefinition(); 58 - buffer.currentPosition = bufferOffsets[id]; 59 - definition.id = id; 60 - definition.loadDefinition(buffer); 61 - return definition; 62 - } 63 - 64 - 65 - public void loadDefinition(Buffer buffer) { 66 - do { 67 - int attributeId = buffer.getUnsignedByte(); 68 - if (attributeId == 0) 69 - return; 70 - if (attributeId == 1) { 71 - int modelCount = buffer.getUnsignedByte(); 72 - modelIds = new int[modelCount]; 73 - for (int model = 0; model < modelCount; model++) 74 - modelIds[model] = buffer.getUnsignedShortBE(); 75 - 76 - } else if (attributeId == 2) 77 - name = buffer.getString(); 78 - else if (attributeId == 3) 79 - description = buffer.getStringBytes(); 80 - else if (attributeId == 12) 81 - boundaryDimension = buffer.getByte(); 82 - else if (attributeId == 13) 83 - standAnimationId = buffer.getUnsignedShortBE(); 84 - else if (attributeId == 14) 85 - walkAnimationId = buffer.getUnsignedShortBE(); 86 - else if (attributeId == 17) { 87 - walkAnimationId = buffer.getUnsignedShortBE(); 88 - turnAroundAnimationId = buffer.getUnsignedShortBE(); 89 - turnRightAnimationId = buffer.getUnsignedShortBE(); 90 - turnLeftAnimationId = buffer.getUnsignedShortBE(); 91 - } else if (attributeId >= 30 && attributeId < 40) { 92 - if (actions == null) 93 - actions = new String[5]; 94 - actions[attributeId - 30] = buffer.getString(); 95 - if (actions[attributeId - 30].equalsIgnoreCase("hidden")) 96 - actions[attributeId - 30] = null; 97 - } else if (attributeId == 40) { 98 - int modelColorCount = buffer.getUnsignedByte(); 99 - modifiedModelColors = new int[modelColorCount]; 100 - originalModelColors = new int[modelColorCount]; 101 - for (int colour = 0; colour < modelColorCount; colour++) { 102 - modifiedModelColors[colour] = buffer.getUnsignedShortBE(); 103 - originalModelColors[colour] = buffer.getUnsignedShortBE(); 104 - } 105 - 106 - } else if (attributeId == 60) { 107 - int additionalModelCount = buffer.getUnsignedByte(); 108 - headModelIndexes = new int[additionalModelCount]; 109 - for (int model = 0; model < additionalModelCount; model++) 110 - headModelIndexes[model] = buffer.getUnsignedShortBE(); 111 - 112 - } else if (attributeId == 90) 113 - anInt648 = buffer.getUnsignedShortBE(); 114 - else if (attributeId == 91) 115 - anInt627 = buffer.getUnsignedShortBE(); 116 - else if (attributeId == 92) 117 - anInt637 = buffer.getUnsignedShortBE(); 118 - else if (attributeId == 93) 119 - minimapVisible = false; 120 - else if (attributeId == 95) 121 - combatLevel = buffer.getUnsignedShortBE(); 122 - else if (attributeId == 97) 123 - sizeXZ = buffer.getUnsignedShortBE(); 124 - else if (attributeId == 98) 125 - sizeY = buffer.getUnsignedShortBE(); 126 - else if (attributeId == 99) 127 - visible = true; 128 - else if (attributeId == 100) 129 - brightness = buffer.getByte(); 130 - else if (attributeId == 101) 131 - contrast = buffer.getByte() * 5; 132 - else if (attributeId == 102) 133 - headIcon = buffer.getUnsignedShortBE(); 134 - else if (attributeId == 103) 135 - degreesToTurn = buffer.getUnsignedShortBE(); 136 - else if (attributeId == 106) { 137 - varBitId = buffer.getUnsignedShortBE(); 138 - if (varBitId == 65535) 139 - varBitId = -1; 140 - settingId = buffer.getUnsignedShortBE(); 141 - if (settingId == 65535) 142 - settingId = -1; 143 - int childrenCount = buffer.getUnsignedByte(); 144 - childrenIds = new int[childrenCount + 1]; 145 - for (int child = 0; child <= childrenCount; child++) { 146 - childrenIds[child] = buffer.getUnsignedShortBE(); 147 - if (childrenIds[child] == 65535) 148 - childrenIds[child] = -1; 149 - } 150 - 151 - } else if (attributeId == 107) 152 - clickable = false; 153 - } while (true); 154 - } 155 - 156 - public static void reset() { 157 - modelCache = null; 158 - bufferOffsets = null; 159 - cache = null; 160 - buffer = null; 161 - } 162 - 163 - public Model getHeadModel() { 164 - if (childrenIds != null) { 165 - ActorDefinition definition = getChildDefinition(); 166 - if (definition == null) 167 - return null; 168 - else 169 - return definition.getHeadModel(); 170 - } 171 - if (headModelIndexes == null) 172 - return null; 173 - boolean cached = false; 174 - for (int headModel = 0; headModel < headModelIndexes.length; headModel++) 175 - if (!Model.loaded(headModelIndexes[headModel])) 176 - cached = true; 177 - 178 - if (cached) 179 - return null; 180 - Model[] headModels = new Model[headModelIndexes.length]; 181 - for (int model = 0; model < headModelIndexes.length; model++) 182 - headModels[model] = Model.getModel(headModelIndexes[model]); 183 - 184 - Model headModel; 185 - if (headModels.length == 1) 186 - headModel = headModels[0]; 187 - else 188 - headModel = new Model(headModels.length, 189 - headModels); 190 - if (modifiedModelColors != null) { 191 - for (int colour = 0; colour < modifiedModelColors.length; colour++) 192 - headModel.replaceColor(modifiedModelColors[colour], originalModelColors[colour]); 193 - 194 - } 195 - return headModel; 196 - } 197 - 198 - public boolean isVisible() { 199 - if (childrenIds == null) 200 - return true; 201 - int j = -1; 202 - if (varBitId != -1) { 203 - Varbit class49 = Varbit.cache[varBitId]; 204 - int k = class49.configId; 205 - int l = class49.leastSignificantBit; 206 - int i1 = class49.mostSignificantBit; 207 - int j1 = client.BITFIELD_MAX_VALUE[i1 - l]; 208 - j = client.widgetSettings[k] >> l & j1; 209 - } else if (settingId != -1) 210 - j = client.widgetSettings[settingId]; 211 - return j >= 0 && j < childrenIds.length && childrenIds[j] != -1; 212 - } 213 - 214 - public static void load(Archive archive) { 215 - buffer = new Buffer(archive.getFile("npc.dat")); 216 - Buffer buffer = new Buffer(archive.getFile("npc.idx")); 217 - size = buffer.getUnsignedShortBE(); 218 - bufferOffsets = new int[size]; 219 - int offset = 2; 220 - for (int bufferIndex = 0; bufferIndex < size; bufferIndex++) { 221 - bufferOffsets[bufferIndex] = offset; 222 - offset += buffer.getUnsignedShortBE(); 223 - } 224 - 225 - cache = new ActorDefinition[20]; 226 - for (int cacheIndex = 0; cacheIndex < 20; cacheIndex++) 227 - cache[cacheIndex] = new ActorDefinition(); 228 - 229 - } 230 - 231 - public Model getChildModel(int frameId2, int frameId, int[] framesFrom2) { 232 - if (childrenIds != null) { 233 - ActorDefinition childDefinition = getChildDefinition(); 234 - if (childDefinition == null) 235 - return null; 236 - else 237 - return childDefinition.getChildModel(frameId2, frameId, framesFrom2); 238 - } 239 - Model childIdModel = (Model) modelCache.get(id); 240 - if (childIdModel == null) { 241 - boolean cached = false; 242 - for (int modelId = 0; modelId < modelIds.length; modelId++) 243 - if (!Model.loaded(modelIds[modelId])) 244 - cached = true; 245 - 246 - if (cached) 247 - return null; 248 - Model[] childModels = new Model[modelIds.length]; 249 - for (int model = 0; model < modelIds.length; model++) 250 - childModels[model] = Model.getModel(modelIds[model]); 251 - 252 - if (childModels.length == 1) 253 - childIdModel = childModels[0]; 254 - else 255 - childIdModel = new Model(childModels.length, 256 - childModels); 257 - if (modifiedModelColors != null) { 258 - for (int colour = 0; colour < modifiedModelColors.length; colour++) 259 - childIdModel.replaceColor(modifiedModelColors[colour], originalModelColors[colour]); 260 - 261 - } 262 - childIdModel.createBones(); 263 - childIdModel.applyLighting(64 + brightness, 850 + contrast, -30, -50, -30, true); 264 - modelCache.put(childIdModel, id); 265 - } 266 - Model childModel = Model.EMPTY_MODEL; 267 - childModel.replaceWithModel(childIdModel, Animation.exists(frameId2) & Animation.exists(frameId) 268 - ); 269 - if (frameId2 != -1 && frameId != -1) 270 - childModel.mixAnimationFrames(frameId, 0, frameId2, framesFrom2); 271 - else if (frameId2 != -1) 272 - childModel.applyTransform(frameId2); 273 - if (sizeXZ != 128 || sizeY != 128) 274 - childModel.scaleT(sizeY, sizeXZ, 9, sizeXZ); 275 - childModel.calculateDiagonals(); 276 - childModel.triangleSkin = null; 277 - childModel.vectorSkin = null; 278 - if (boundaryDimension == 1) 279 - childModel.singleTile = true; 280 - return childModel; 281 - } 282 - 283 - public ActorDefinition getChildDefinition() { 284 - int childId = -1; 285 - if (varBitId != -1) { 286 - Varbit varbit = Varbit.cache[varBitId]; 287 - int configId = varbit.configId; 288 - int leastSignificantBit = varbit.leastSignificantBit; 289 - int mostSignificantBit = varbit.mostSignificantBit; 290 - int bit = client.BITFIELD_MAX_VALUE[mostSignificantBit - leastSignificantBit]; 291 - childId = client.widgetSettings[configId] >> leastSignificantBit & bit; 292 - } else if (settingId != -1) 293 - childId = client.widgetSettings[settingId]; 294 - if (childId < 0 || childId >= childrenIds.length || childrenIds[childId] == -1) 295 - return null; 296 - else 297 - return getDefinition(childrenIds[childId]); 298 - } 299 - 300 - }
+250
src/main/java/com/jagex/runescape/cache/def/ActorDefinition.kt
··· 1 + package com.jagex.runescape.cache.def 2 + 3 + import com.jagex.runescape.Game 4 + import com.jagex.runescape.cache.Archive 5 + import com.jagex.runescape.cache.cfg.Varbit 6 + import com.jagex.runescape.collection.Cache 7 + import com.jagex.runescape.media.Animation 8 + import com.jagex.runescape.media.renderable.Model 9 + import com.jagex.runescape.net.Buffer 10 + 11 + class ActorDefinition { 12 + 13 + @JvmField var standAnimationId: Int = -1 14 + @JvmField var childrenIds: IntArray? = null 15 + @JvmField var headModelIndexes: IntArray? = null 16 + @JvmField var modelIds: IntArray? = null 17 + @JvmField var anInt627: Int = -1 18 + @JvmField var id: Long = -1L 19 + @JvmField var sizeY: Int = 128 20 + @JvmField var clickable: Boolean = true 21 + @JvmField var sizeXZ: Int = 128 22 + @JvmField var turnLeftAnimationId: Int = -1 23 + @JvmField var modifiedModelColors: IntArray? = null 24 + @JvmField var minimapVisible: Boolean = true 25 + @JvmField var anInt637: Int = -1 26 + @JvmField var headIcon: Int = -1 27 + @JvmField var combatLevel: Int = -1 28 + @JvmField var turnRightAnimationId: Int = -1 29 + @JvmField var boundaryDimension: Byte = 1 30 + @JvmField var turnAroundAnimationId: Int = -1 31 + @JvmField var visible: Boolean = false 32 + @JvmField var walkAnimationId: Int = -1 33 + @JvmField var actions: Array<String?>? = null 34 + @JvmField var anInt648: Int = -1 35 + @JvmField var degreesToTurn: Int = 32 36 + @JvmField var name: String = "null" 37 + @JvmField var varBitId: Int = -1 38 + @JvmField var originalModelColors: IntArray? = null 39 + @JvmField var contrast: Int = 0 40 + @JvmField var settingId: Int = -1 41 + @JvmField var description: ByteArray? = null 42 + @JvmField var brightness: Int = 0 43 + 44 + fun loadDefinition(buffer: Buffer) { 45 + do { 46 + val attributeId = buffer.getUnsignedByte() 47 + if (attributeId == 0) return 48 + when { 49 + attributeId == 1 -> { 50 + val modelCount = buffer.getUnsignedByte() 51 + modelIds = IntArray(modelCount) { buffer.getUnsignedShortBE() } 52 + } 53 + attributeId == 2 -> name = buffer.getString() 54 + attributeId == 3 -> description = buffer.getStringBytes() 55 + attributeId == 12 -> boundaryDimension = buffer.getByte() 56 + attributeId == 13 -> standAnimationId = buffer.getUnsignedShortBE() 57 + attributeId == 14 -> walkAnimationId = buffer.getUnsignedShortBE() 58 + attributeId == 17 -> { 59 + walkAnimationId = buffer.getUnsignedShortBE() 60 + turnAroundAnimationId = buffer.getUnsignedShortBE() 61 + turnRightAnimationId = buffer.getUnsignedShortBE() 62 + turnLeftAnimationId = buffer.getUnsignedShortBE() 63 + } 64 + attributeId in 30..39 -> { 65 + if (actions == null) actions = arrayOfNulls(5) 66 + actions!![attributeId - 30] = buffer.getString() 67 + if (actions!![attributeId - 30].equals("hidden", ignoreCase = true)) 68 + actions!![attributeId - 30] = null 69 + } 70 + attributeId == 40 -> { 71 + val modelColorCount = buffer.getUnsignedByte() 72 + modifiedModelColors = IntArray(modelColorCount) 73 + originalModelColors = IntArray(modelColorCount) 74 + for (colour in 0 until modelColorCount) { 75 + modifiedModelColors!![colour] = buffer.getUnsignedShortBE() 76 + originalModelColors!![colour] = buffer.getUnsignedShortBE() 77 + } 78 + } 79 + attributeId == 60 -> { 80 + val additionalModelCount = buffer.getUnsignedByte() 81 + headModelIndexes = IntArray(additionalModelCount) { buffer.getUnsignedShortBE() } 82 + } 83 + attributeId == 90 -> anInt648 = buffer.getUnsignedShortBE() 84 + attributeId == 91 -> anInt627 = buffer.getUnsignedShortBE() 85 + attributeId == 92 -> anInt637 = buffer.getUnsignedShortBE() 86 + attributeId == 93 -> minimapVisible = false 87 + attributeId == 95 -> combatLevel = buffer.getUnsignedShortBE() 88 + attributeId == 97 -> sizeXZ = buffer.getUnsignedShortBE() 89 + attributeId == 98 -> sizeY = buffer.getUnsignedShortBE() 90 + attributeId == 99 -> visible = true 91 + attributeId == 100 -> brightness = buffer.getByte().toInt() 92 + attributeId == 101 -> contrast = buffer.getByte().toInt() * 5 93 + attributeId == 102 -> headIcon = buffer.getUnsignedShortBE() 94 + attributeId == 103 -> degreesToTurn = buffer.getUnsignedShortBE() 95 + attributeId == 106 -> { 96 + varBitId = buffer.getUnsignedShortBE() 97 + if (varBitId == 65535) varBitId = -1 98 + settingId = buffer.getUnsignedShortBE() 99 + if (settingId == 65535) settingId = -1 100 + val childrenCount = buffer.getUnsignedByte() 101 + childrenIds = IntArray(childrenCount + 1) { 102 + val v = buffer.getUnsignedShortBE() 103 + if (v == 65535) -1 else v 104 + } 105 + } 106 + attributeId == 107 -> clickable = false 107 + } 108 + } while (true) 109 + } 110 + 111 + fun getHeadModel(): Model? { 112 + if (childrenIds != null) { 113 + val definition = getChildDefinition() ?: return null 114 + return definition.getHeadModel() 115 + } 116 + val indexes = headModelIndexes ?: return null 117 + var cached = false 118 + for (headModel in indexes.indices) 119 + if (!Model.loaded(indexes[headModel])) cached = true 120 + if (cached) return null 121 + 122 + val headModels = Array(indexes.size) { Model.getModel(indexes[it]) } 123 + var headModel: Model = if (headModels.size == 1) headModels[0] 124 + else Model(headModels.size, headModels) 125 + 126 + if (modifiedModelColors != null) { 127 + for (colour in modifiedModelColors!!.indices) 128 + headModel.replaceColor(modifiedModelColors!![colour], originalModelColors!![colour]) 129 + } 130 + return headModel 131 + } 132 + 133 + fun isVisible(): Boolean { 134 + if (childrenIds == null) return true 135 + var j = -1 136 + if (varBitId != -1) { 137 + val varbit = Varbit.cache!![varBitId]!! 138 + val k = varbit.configId 139 + val l = varbit.leastSignificantBit 140 + val i1 = varbit.mostSignificantBit 141 + val j1 = Game.BITFIELD_MAX_VALUE[i1 - l] 142 + j = client!!.widgetSettings[k] shr l and j1 143 + } else if (settingId != -1) { 144 + j = client!!.widgetSettings[settingId] 145 + } 146 + return j >= 0 && j < childrenIds!!.size && childrenIds!![j] != -1 147 + } 148 + 149 + fun getChildModel(frameId2: Int, frameId: Int, framesFrom2: IntArray?): Model? { 150 + if (childrenIds != null) { 151 + val childDefinition = getChildDefinition() ?: return null 152 + return childDefinition.getChildModel(frameId2, frameId, framesFrom2) 153 + } 154 + var childIdModel = modelCache!!.get(id) as Model? 155 + if (childIdModel == null) { 156 + var cached = false 157 + for (modelId in modelIds!!.indices) 158 + if (!Model.loaded(modelIds!![modelId])) cached = true 159 + if (cached) return null 160 + 161 + val childModels = Array(modelIds!!.size) { Model.getModel(modelIds!![it]) } 162 + childIdModel = if (childModels.size == 1) childModels[0] 163 + else Model(childModels.size, childModels) 164 + 165 + if (modifiedModelColors != null) { 166 + for (colour in modifiedModelColors!!.indices) 167 + childIdModel.replaceColor(modifiedModelColors!![colour], originalModelColors!![colour]) 168 + } 169 + childIdModel.createBones() 170 + childIdModel.applyLighting(64 + brightness, 850 + contrast, -30, -50, -30, true) 171 + modelCache!!.put(childIdModel, id) 172 + } 173 + val childModel = Model.EMPTY_MODEL 174 + childModel.replaceWithModel(childIdModel, Animation.exists(frameId2) and Animation.exists(frameId)) 175 + if (frameId2 != -1 && frameId != -1) 176 + childModel.mixAnimationFrames(frameId, 0, frameId2, framesFrom2) 177 + else if (frameId2 != -1) 178 + childModel.applyTransform(frameId2) 179 + if (sizeXZ != 128 || sizeY != 128) 180 + childModel.scaleT(sizeY, sizeXZ, 9, sizeXZ) 181 + childModel.calculateDiagonals() 182 + childModel.triangleSkin = null 183 + childModel.vectorSkin = null 184 + if (boundaryDimension.toInt() == 1) 185 + childModel.singleTile = true 186 + return childModel 187 + } 188 + 189 + fun getChildDefinition(): ActorDefinition? { 190 + var childId = -1 191 + if (varBitId != -1) { 192 + val varbit = Varbit.cache!![varBitId]!! 193 + val configId = varbit.configId 194 + val leastSignificantBit = varbit.leastSignificantBit 195 + val mostSignificantBit = varbit.mostSignificantBit 196 + val bit = Game.BITFIELD_MAX_VALUE[mostSignificantBit - leastSignificantBit] 197 + childId = client!!.widgetSettings[configId] shr leastSignificantBit and bit 198 + } else if (settingId != -1) { 199 + childId = client!!.widgetSettings[settingId] 200 + } 201 + return if (childId < 0 || childId >= childrenIds!!.size || childrenIds!![childId] == -1) null 202 + else getDefinition(childrenIds!![childId]) 203 + } 204 + 205 + companion object { 206 + @JvmField var client: Game? = null 207 + @JvmField var modelCache: Cache? = Cache(30) 208 + @JvmField var size: Int = 0 209 + @JvmField var bufferOffsets: IntArray? = null 210 + @JvmField var cache: Array<ActorDefinition?>? = null 211 + @JvmField var buffer: Buffer? = null 212 + @JvmField var bufferIndex: Int = 0 213 + 214 + @JvmStatic 215 + fun getDefinition(id: Int): ActorDefinition { 216 + for (j in 0 until 20) 217 + if (cache!![j]!!.id == id.toLong()) return cache!![j]!! 218 + 219 + bufferIndex = (bufferIndex + 1) % 20 220 + val definition = ActorDefinition() 221 + cache!![bufferIndex] = definition 222 + buffer!!.currentPosition = bufferOffsets!![id] 223 + definition.id = id.toLong() 224 + definition.loadDefinition(buffer!!) 225 + return definition 226 + } 227 + 228 + @JvmStatic 229 + fun reset() { 230 + modelCache = null 231 + bufferOffsets = null 232 + cache = null 233 + buffer = null 234 + } 235 + 236 + @JvmStatic 237 + fun load(archive: Archive) { 238 + buffer = Buffer(archive.getFile("npc.dat")!!) 239 + val idxBuffer = Buffer(archive.getFile("npc.idx")!!) 240 + size = idxBuffer.getUnsignedShortBE() 241 + bufferOffsets = IntArray(size) 242 + var offset = 2 243 + for (i in 0 until size) { 244 + bufferOffsets!![i] = offset 245 + offset += idxBuffer.getUnsignedShortBE() 246 + } 247 + cache = Array(20) { ActorDefinition() } 248 + } 249 + } 250 + }
-160
src/main/java/com/jagex/runescape/cache/def/FloorDefinition.java
··· 1 - package com.jagex.runescape.cache.def; 2 - 3 - import com.jagex.runescape.cache.Archive; 4 - import com.jagex.runescape.net.Buffer; 5 - 6 - public class FloorDefinition { 7 - 8 - public static byte aByte310 = 6; 9 - public int anInt311; 10 - public boolean aBoolean312 = true; 11 - public static int count; 12 - public static FloorDefinition cache[]; 13 - public String name; 14 - public int rgbColor; 15 - public int textureId = -1; 16 - public boolean aBoolean318 = false; 17 - public boolean occlude = true; 18 - public int hue2; 19 - public int saturation; 20 - public int lightness; 21 - public int hue; 22 - public int hueDivisor; 23 - public int hslColor2; 24 - 25 - public static void load(Archive archive) { 26 - Buffer buffer = new Buffer(archive.getFile("flo.dat")); 27 - count = buffer.getUnsignedShortBE(); 28 - if (cache == null) 29 - cache = new FloorDefinition[count]; 30 - for (int floor = 0; floor < count; floor++) { 31 - if (cache[floor] == null) 32 - cache[floor] = new FloorDefinition(); 33 - cache[floor].loadDefinition(buffer); 34 - } 35 - 36 - } 37 - 38 - public void loadDefinition(Buffer buffer) { 39 - while (true) { 40 - int attributeId = buffer.getUnsignedByte(); 41 - if (attributeId == 0) 42 - return; 43 - switch (attributeId) { 44 - case 1: 45 - rgbColor = buffer.getMediumBE(); 46 - shiftRGBColors(rgbColor); 47 - break; 48 - case 2: 49 - textureId = buffer.getUnsignedByte(); 50 - break; 51 - case 3: 52 - aBoolean318 = true; 53 - break; 54 - case 5: 55 - occlude = false; 56 - break; 57 - case 6: 58 - name = buffer.getString(); 59 - break; 60 - case 7: 61 - int oldHue2 = hue2; 62 - int oldSaturation = saturation; 63 - int oldLightness = lightness; 64 - int oldHue = hue; 65 - shiftRGBColors(buffer.getMediumBE()); 66 - hue2 = oldHue2; 67 - saturation = oldSaturation; 68 - lightness = oldLightness; 69 - hue = oldHue; 70 - hueDivisor = oldHue; 71 - break; 72 - default: 73 - System.out.println("Error unrecognised config code: " + attributeId); 74 - break; 75 - } 76 - } 77 - } 78 - 79 - public void shiftRGBColors(int color) { 80 - double r = (color >> 16 & 0xff) / 256D; 81 - double b = (color >> 8 & 0xff) / 256D; 82 - double g = (color & 0xff) / 256D; 83 - double cmin = r; 84 - if (b < cmin) 85 - cmin = b; 86 - if (g < cmin) 87 - cmin = g; 88 - double cmax = r; 89 - if (b > cmax) 90 - cmax = b; 91 - if (g > cmax) 92 - cmax = g; 93 - double d5 = 0.0D; 94 - double d6 = 0.0D; 95 - double d7 = (cmin + cmax) / 2D; 96 - if (cmin != cmax) { 97 - if (d7 < 0.5D) 98 - d6 = (cmax - cmin) / (cmax + cmin); 99 - if (d7 >= 0.5D) 100 - d6 = (cmax - cmin) / (2D - cmax - cmin); 101 - if (r == cmax) 102 - d5 = (b - g) / (cmax - cmin); 103 - else if (b == cmax) 104 - d5 = 2D + (g - r) / (cmax - cmin); 105 - else if (g == cmax) 106 - d5 = 4D + (r - b) / (cmax - cmin); 107 - } 108 - d5 /= 6D; 109 - hue2 = (int) (d5 * 256D); 110 - saturation = (int) (d6 * 256D); 111 - lightness = (int) (d7 * 256D); 112 - if (saturation < 0) 113 - saturation = 0; 114 - else if (saturation > 255) 115 - saturation = 255; 116 - if (lightness < 0) 117 - lightness = 0; 118 - else if (lightness > 255) 119 - lightness = 255; 120 - if (d7 > 0.5D) 121 - hueDivisor = (int) ((1.0D - d7) * d6 * 512D); 122 - else 123 - hueDivisor = (int) (d7 * d6 * 512D); 124 - if (hueDivisor < 1) 125 - hueDivisor = 1; 126 - hue = (int) (d5 * hueDivisor); 127 - int huerand = (hue2 + (int) (Math.random() * 16D)) - 8; 128 - if (huerand < 0) 129 - huerand = 0; 130 - else if (huerand > 255) 131 - huerand = 255; 132 - int satrand = (saturation + (int) (Math.random() * 48D)) - 24; 133 - if (satrand < 0) 134 - satrand = 0; 135 - else if (satrand > 255) 136 - satrand = 255; 137 - int lightrand = (lightness + (int) (Math.random() * 48D)) - 24; 138 - if (lightrand < 0) 139 - lightrand = 0; 140 - else if (lightrand > 255) 141 - lightrand = 255; 142 - hslColor2 = shiftHSLColors(huerand, satrand, lightrand); 143 - } 144 - 145 - public int shiftHSLColors(int i, int j, int k) { 146 - if (k > 179) 147 - j /= 2; 148 - if (k > 192) 149 - j /= 2; 150 - if (k > 217) 151 - j /= 2; 152 - if (k > 243) 153 - j /= 2; 154 - int l = (i / 4 << 10) + (j / 32 << 7) + k / 2; 155 - return l; 156 - } 157 - 158 - 159 - 160 - }
+123
src/main/java/com/jagex/runescape/cache/def/FloorDefinition.kt
··· 1 + package com.jagex.runescape.cache.def 2 + 3 + import com.jagex.runescape.cache.Archive 4 + import com.jagex.runescape.net.Buffer 5 + 6 + class FloorDefinition { 7 + 8 + @JvmField var anInt311: Int = 0 9 + @JvmField var aBoolean312: Boolean = true 10 + @JvmField var name: String? = null 11 + @JvmField var rgbColor: Int = 0 12 + @JvmField var textureId: Int = -1 13 + @JvmField var aBoolean318: Boolean = false 14 + @JvmField var occlude: Boolean = true 15 + @JvmField var hue2: Int = 0 16 + @JvmField var saturation: Int = 0 17 + @JvmField var lightness: Int = 0 18 + @JvmField var hue: Int = 0 19 + @JvmField var hueDivisor: Int = 0 20 + @JvmField var hslColor2: Int = 0 21 + 22 + fun loadDefinition(buffer: Buffer) { 23 + while (true) { 24 + val attributeId = buffer.getUnsignedByte() 25 + if (attributeId == 0) return 26 + when (attributeId) { 27 + 1 -> { 28 + rgbColor = buffer.getMediumBE() 29 + shiftRGBColors(rgbColor) 30 + } 31 + 2 -> textureId = buffer.getUnsignedByte() 32 + 3 -> aBoolean318 = true 33 + 5 -> occlude = false 34 + 6 -> name = buffer.getString() 35 + 7 -> { 36 + val oldHue2 = hue2 37 + val oldSaturation = saturation 38 + val oldLightness = lightness 39 + val oldHue = hue 40 + shiftRGBColors(buffer.getMediumBE()) 41 + hue2 = oldHue2 42 + saturation = oldSaturation 43 + lightness = oldLightness 44 + hue = oldHue 45 + hueDivisor = oldHue 46 + } 47 + else -> println("Error unrecognised config code: $attributeId") 48 + } 49 + } 50 + } 51 + 52 + fun shiftRGBColors(color: Int) { 53 + val r = (color shr 16 and 0xff) / 256.0 54 + val b = (color shr 8 and 0xff) / 256.0 55 + val g = (color and 0xff) / 256.0 56 + var cmin = r 57 + if (b < cmin) cmin = b 58 + if (g < cmin) cmin = g 59 + var cmax = r 60 + if (b > cmax) cmax = b 61 + if (g > cmax) cmax = g 62 + var d5 = 0.0 63 + var d6 = 0.0 64 + val d7 = (cmin + cmax) / 2.0 65 + if (cmin != cmax) { 66 + if (d7 < 0.5) d6 = (cmax - cmin) / (cmax + cmin) 67 + if (d7 >= 0.5) d6 = (cmax - cmin) / (2.0 - cmax - cmin) 68 + if (r == cmax) d5 = (b - g) / (cmax - cmin) 69 + else if (b == cmax) d5 = 2.0 + (g - r) / (cmax - cmin) 70 + else if (g == cmax) d5 = 4.0 + (r - b) / (cmax - cmin) 71 + } 72 + d5 /= 6.0 73 + hue2 = (d5 * 256.0).toInt() 74 + saturation = (d6 * 256.0).toInt() 75 + lightness = (d7 * 256.0).toInt() 76 + if (saturation < 0) saturation = 0 77 + else if (saturation > 255) saturation = 255 78 + if (lightness < 0) lightness = 0 79 + else if (lightness > 255) lightness = 255 80 + hueDivisor = if (d7 > 0.5) ((1.0 - d7) * d6 * 512.0).toInt() 81 + else (d7 * d6 * 512.0).toInt() 82 + if (hueDivisor < 1) hueDivisor = 1 83 + hue = (d5 * hueDivisor).toInt() 84 + var huerand = (hue2 + (Math.random() * 16.0).toInt()) - 8 85 + if (huerand < 0) huerand = 0 86 + else if (huerand > 255) huerand = 255 87 + var satrand = (saturation + (Math.random() * 48.0).toInt()) - 24 88 + if (satrand < 0) satrand = 0 89 + else if (satrand > 255) satrand = 255 90 + var lightrand = (lightness + (Math.random() * 48.0).toInt()) - 24 91 + if (lightrand < 0) lightrand = 0 92 + else if (lightrand > 255) lightrand = 255 93 + hslColor2 = shiftHSLColors(huerand, satrand, lightrand) 94 + } 95 + 96 + fun shiftHSLColors(i: Int, j: Int, k: Int): Int { 97 + var saturation = j 98 + if (k > 179) saturation /= 2 99 + if (k > 192) saturation /= 2 100 + if (k > 217) saturation /= 2 101 + if (k > 243) saturation /= 2 102 + return (i / 4 shl 10) + (saturation / 32 shl 7) + k / 2 103 + } 104 + 105 + companion object { 106 + @JvmField var aByte310: Byte = 6 107 + @JvmField var count: Int = 0 108 + @JvmField var cache: Array<FloorDefinition?>? = null 109 + 110 + @JvmStatic 111 + fun load(archive: Archive) { 112 + val buffer = Buffer(archive.getFile("flo.dat")!!) 113 + count = buffer.getUnsignedShortBE() 114 + if (cache == null) 115 + cache = arrayOfNulls(count) 116 + for (floor in 0 until count) { 117 + if (cache!![floor] == null) 118 + cache!![floor] = FloorDefinition() 119 + cache!![floor]!!.loadDefinition(buffer) 120 + } 121 + } 122 + } 123 + }
-506
src/main/java/com/jagex/runescape/cache/def/GameObjectDefinition.java
··· 1 - package com.jagex.runescape.cache.def; 2 - 3 - import com.jagex.runescape.cache.Archive; 4 - import com.jagex.runescape.cache.FileOperations; 5 - import com.jagex.runescape.net.Buffer; 6 - import com.jagex.runescape.Game; 7 - import com.jagex.runescape.net.requester.OnDemandRequester; 8 - import com.jagex.runescape.cache.cfg.Varbit; 9 - import com.jagex.runescape.collection.Cache; 10 - import com.jagex.runescape.media.Animation; 11 - import com.jagex.runescape.media.renderable.Model; 12 - 13 - public class GameObjectDefinition { 14 - 15 - public static int bufferOffsets[]; 16 - public boolean hasActions; 17 - public int modelSizeY; 18 - public int translateX; 19 - public static Cache animatedModelCache = new Cache(40); 20 - public int modelIds[]; 21 - public int anInt764; 22 - public boolean unknown; 23 - public int translateZ; 24 - public static Buffer buffer; 25 - public boolean adjustToTerrain; 26 - public static Game client; 27 - public static Model models[] = new Model[4]; 28 - public static boolean lowMemory; 29 - public int id = -1; 30 - public int sizeY; 31 - public String name = "null"; 32 - public static int cacheIndex; 33 - public int varbitId; 34 - public static Cache modelCache = new Cache(500); 35 - public int modelSizeX; 36 - public int configId; 37 - public static GameObjectDefinition cache[]; 38 - public byte description[]; 39 - public byte modelLightFalloff; 40 - public int translateY; 41 - public boolean aBoolean786 = true; 42 - public byte modelLightAmbient; 43 - public int modelTypes[]; 44 - public String options[]; 45 - public boolean aBoolean791; 46 - public int anIntArray792[]; 47 - public int anInt794; 48 - public int anInt795; 49 - public int modelSizeZ; 50 - public boolean wall; 51 - public boolean unknown3; 52 - public int modifiedModelColors[]; 53 - public int sizeX; 54 - public int offsetAmplifier; 55 - public int animationId; 56 - public boolean nonFlatShading; 57 - public int childrenIds[]; 58 - public int icon; 59 - public boolean castsShadow; 60 - public static int definitionCount; 61 - public boolean walkable; 62 - public boolean solid; 63 - 64 - public static GameObjectDefinition getDefinition(int id) { 65 - for (int index = 0; index < 20; index++) 66 - if (cache[index].id == id) 67 - return cache[index]; 68 - 69 - cacheIndex = (cacheIndex + 1) % 20; 70 - GameObjectDefinition definition = cache[cacheIndex]; 71 - buffer.currentPosition = bufferOffsets[id]; 72 - definition.id = id; 73 - definition.setDefaultValues(); 74 - definition.load(buffer); 75 - return definition; 76 - } 77 - 78 - public GameObjectDefinition getChildDefinition() { 79 - int child = -1; 80 - if (varbitId != -1) { 81 - Varbit varbit = Varbit.cache[varbitId]; 82 - int configId = varbit.configId; 83 - int leastSignificantBit = varbit.leastSignificantBit; 84 - int mostSignificantBit = varbit.mostSignificantBit; 85 - int bit = client.BITFIELD_MAX_VALUE[mostSignificantBit - leastSignificantBit]; 86 - child = client.widgetSettings[configId] >> leastSignificantBit & bit; 87 - } else if (configId != -1) 88 - child = client.widgetSettings[configId]; 89 - if (child < 0 || child >= childrenIds.length || childrenIds[child] == -1) 90 - return null; 91 - else 92 - return getDefinition(childrenIds[child]); 93 - } 94 - 95 - public void setDefaultValues() { 96 - modelIds = null; 97 - modelTypes = null; 98 - name = "null"; 99 - description = null; 100 - modifiedModelColors = null; 101 - anIntArray792 = null; 102 - sizeX = 1; 103 - sizeY = 1; 104 - solid = true; 105 - walkable = true; 106 - hasActions = false; 107 - adjustToTerrain = false; 108 - nonFlatShading = false; 109 - wall = false; 110 - animationId = -1; 111 - offsetAmplifier = 16; 112 - modelLightFalloff = 0; 113 - modelLightAmbient = 0; 114 - options = null; 115 - icon = -1; 116 - anInt795 = -1; 117 - unknown3 = false; 118 - castsShadow = true; 119 - modelSizeX = 128; 120 - modelSizeY = 128; 121 - modelSizeZ = 128; 122 - anInt764 = 0; 123 - translateX = 0; 124 - translateY = 0; 125 - translateZ = 0; 126 - unknown = false; 127 - aBoolean791 = false; 128 - anInt794 = -1; 129 - varbitId = -1; 130 - configId = -1; 131 - childrenIds = null; 132 - } 133 - 134 - public void passiveRequestModels(OnDemandRequester onDemandRequester) { 135 - if (modelIds != null) { 136 - for (int modelId : modelIds) { 137 - onDemandRequester.passiveRequest(modelId & 0xffff, 0); 138 - } 139 - } 140 - } 141 - 142 - public static void load(Archive archive) { 143 - buffer = new Buffer(archive.getFile("loc.dat")); 144 - Buffer buffer = new Buffer(archive.getFile("loc.idx")); 145 - FileOperations.WriteFile("DumpedData/377_OBJECTS.dat", archive.getFile("loc.dat")); 146 - FileOperations.WriteFile("DumpedData/377_OBJECTS.idx", archive.getFile("loc.idx")); 147 - definitionCount = buffer.getUnsignedShortBE(); 148 - bufferOffsets = new int[definitionCount]; 149 - int offset = 2; 150 - for (int index = 0; index < definitionCount; index++) { 151 - bufferOffsets[index] = offset; 152 - offset += buffer.getUnsignedShortBE(); 153 - } 154 - 155 - cache = new GameObjectDefinition[20]; 156 - for (int definition = 0; definition < 20; definition++) 157 - cache[definition] = new GameObjectDefinition(); 158 - 159 - } 160 - 161 - public Model getGameObjectAnimatedModel(int type, int animationId, int face) { 162 - Model subModel = null; 163 - long hash; 164 - if (modelTypes == null) { 165 - if (type != 10) 166 - return null; 167 - hash = ((id << 6) + face) + ((long) (animationId + 1) << 32); 168 - Model cachedModel = (Model) animatedModelCache.get(hash); 169 - if (cachedModel != null) 170 - return cachedModel; 171 - if (modelIds == null) 172 - return null; 173 - boolean mirror = unknown3 ^ (face > 3); 174 - int modelCount = modelIds.length; 175 - for (int modelId = 0; modelId < modelCount; modelId++) { 176 - int subModelId = modelIds[modelId]; 177 - if (mirror) 178 - subModelId += 0x10000; 179 - subModel = (Model) modelCache.get(subModelId); 180 - if (subModel == null) { 181 - subModel = Model.getModel(subModelId & 0xffff); 182 - if (subModel == null) 183 - return null; 184 - if (mirror) 185 - subModel.mirror(0); 186 - modelCache.put(subModel, subModelId); 187 - } 188 - if (modelCount > 1) 189 - models[modelId] = subModel; 190 - } 191 - 192 - if (modelCount > 1) 193 - subModel = new Model(modelCount, models); 194 - } else { 195 - int modelType = -1; 196 - for (int index = 0; index < modelTypes.length; index++) { 197 - if (modelTypes[index] != type) 198 - continue; 199 - modelType = index; 200 - break; 201 - } 202 - 203 - if (modelType == -1) 204 - return null; 205 - hash = ((id << 6) + (modelType << 3) + face) + ((long) (animationId + 1) << 32); 206 - Model model = (Model) animatedModelCache.get(hash); 207 - if (model != null) 208 - return model; 209 - int j2 = modelIds[modelType]; 210 - boolean mirror = unknown3 ^ (face > 3); 211 - if (mirror) 212 - j2 += 0x10000; 213 - subModel = (Model) modelCache.get(j2); 214 - if (subModel == null) { 215 - subModel = Model.getModel(j2 & 0xffff); 216 - if (subModel == null) 217 - return null; 218 - if (mirror) 219 - subModel.mirror(0); 220 - modelCache.put(subModel, j2); 221 - } 222 - } 223 - boolean scale; 224 - if (modelSizeX != 128 || modelSizeY != 128 || modelSizeZ != 128) 225 - scale = true; 226 - else 227 - scale = false; 228 - boolean needsTranslation; 229 - if (translateX != 0 || translateY != 0 || translateZ != 0) 230 - needsTranslation = true; 231 - else 232 - needsTranslation = false; 233 - Model animatedModel = new Model(modifiedModelColors == null, subModel, Animation.exists(animationId)); 234 - if (animationId != -1) { 235 - animatedModel.createBones(); 236 - animatedModel.applyTransform(animationId); 237 - animatedModel.triangleSkin = null; 238 - animatedModel.vectorSkin = null; 239 - } 240 - while (face-- > 0) 241 - animatedModel.rotate90Degrees(); 242 - if (modifiedModelColors != null) { 243 - for (int k2 = 0; k2 < modifiedModelColors.length; k2++) 244 - animatedModel.replaceColor(modifiedModelColors[k2], anIntArray792[k2]); 245 - 246 - } 247 - if (scale) 248 - animatedModel.scaleT(modelSizeY, modelSizeZ, 9, modelSizeX); 249 - if (needsTranslation) 250 - animatedModel.translate(translateX, translateZ, translateY); 251 - animatedModel.applyLighting(64 + modelLightFalloff, 768 + modelLightAmbient * 5, -50, -10, -50, !nonFlatShading); 252 - if (anInt794 == 1) 253 - animatedModel.anInt1675 = animatedModel.modelHeight; 254 - animatedModelCache.put(animatedModel, hash); 255 - return animatedModel; 256 - } 257 - 258 - public boolean isModelCached() { 259 - if (modelIds == null) 260 - return true; 261 - boolean cached = true; 262 - for (int modelId : modelIds) { 263 - cached &= Model.loaded(modelId & 0xffff); 264 - } 265 - return cached; 266 - } 267 - 268 - 269 - 270 - public void load(Buffer buf) { 271 - int i = -1; 272 - label0: 273 - while (true) { 274 - int attribute; 275 - do { 276 - attribute = buf.getUnsignedByte(); 277 - if (attribute == 0) 278 - break label0; 279 - switch (attribute) { 280 - case 1: 281 - int k = buf.getUnsignedByte(); 282 - if (k > 0) 283 - if (modelIds == null || lowMemory) { 284 - modelTypes = new int[k]; 285 - modelIds = new int[k]; 286 - for (int k1 = 0; k1 < k; k1++) { 287 - modelIds[k1] = buf.getUnsignedShortBE(); 288 - modelTypes[k1] = buf.getUnsignedByte(); 289 - } 290 - 291 - } else { 292 - buf.currentPosition += k * 3; 293 - } 294 - break; 295 - case 2: 296 - name = buf.getString(); 297 - break; 298 - case 3: 299 - description = buf.getStringBytes(); 300 - break; 301 - case 5: 302 - int l = buf.getUnsignedByte(); 303 - if (l > 0) 304 - if (modelIds == null || lowMemory) { 305 - modelTypes = null; 306 - modelIds = new int[l]; 307 - for (int l1 = 0; l1 < l; l1++) 308 - modelIds[l1] = buf.getUnsignedShortBE(); 309 - 310 - } else { 311 - buf.currentPosition += l * 2; 312 - } 313 - break; 314 - case 14: 315 - sizeX = buf.getUnsignedByte(); 316 - break; 317 - case 15: 318 - sizeY = buf.getUnsignedByte(); 319 - break; 320 - case 17: 321 - solid = false; 322 - break; 323 - case 18: 324 - walkable = false; 325 - break; 326 - case 19: 327 - i = buf.getUnsignedByte(); 328 - if (i == 1) 329 - hasActions = true; 330 - break; 331 - case 21: 332 - adjustToTerrain = true; 333 - break; 334 - case 22: 335 - nonFlatShading = true; 336 - break; 337 - case 23: 338 - wall = true; 339 - break; 340 - case 24: 341 - animationId = buf.getUnsignedShortBE(); 342 - if (animationId == 65535) 343 - animationId = -1; 344 - break; 345 - case 28: 346 - offsetAmplifier = buf.getUnsignedByte(); 347 - break; 348 - case 29: 349 - modelLightFalloff = buf.getByte(); 350 - break; 351 - case 39: 352 - modelLightAmbient = buf.getByte(); 353 - break; 354 - } 355 - if (attribute < 30 || attribute >= 39) { 356 - switch (attribute) { 357 - case 40: 358 - int i1 = buf.getUnsignedByte(); 359 - modifiedModelColors = new int[i1]; 360 - anIntArray792 = new int[i1]; 361 - for (int i2 = 0; i2 < i1; i2++) { 362 - modifiedModelColors[i2] = buf.getUnsignedShortBE(); 363 - anIntArray792[i2] = buf.getUnsignedShortBE(); 364 - } 365 - 366 - break; 367 - case 60: 368 - icon = buf.getUnsignedShortBE(); 369 - break; 370 - case 62: 371 - unknown3 = true; 372 - break; 373 - case 64: 374 - castsShadow = false; 375 - break; 376 - case 65: 377 - modelSizeX = buf.getUnsignedShortBE(); 378 - break; 379 - case 66: 380 - modelSizeY = buf.getUnsignedShortBE(); 381 - break; 382 - case 67: 383 - modelSizeZ = buf.getUnsignedShortBE(); 384 - break; 385 - case 68: 386 - anInt795 = buf.getUnsignedShortBE(); 387 - break; 388 - case 69: 389 - anInt764 = buf.getUnsignedByte(); 390 - break; 391 - case 70: 392 - translateX = buf.getShortBE(); 393 - break; 394 - case 71: 395 - translateY = buf.getShortBE(); 396 - break; 397 - case 72: 398 - translateZ = buf.getShortBE(); 399 - break; 400 - case 73: 401 - unknown = true; 402 - break; 403 - case 74: 404 - aBoolean791 = true; 405 - break; 406 - default: 407 - if (attribute != 75) 408 - continue; 409 - anInt794 = buf.getUnsignedByte(); 410 - break; 411 - } 412 - } else { 413 - if (options == null) 414 - options = new String[5]; 415 - options[attribute - 30] = buf.getString(); 416 - if (options[attribute - 30].equalsIgnoreCase("hidden")) 417 - options[attribute - 30] = null; 418 - } 419 - continue label0; 420 - } while (attribute != 77); 421 - varbitId = buf.getUnsignedShortBE(); 422 - if (varbitId == 65535) 423 - varbitId = -1; 424 - configId = buf.getUnsignedShortBE(); 425 - if (configId == 65535) 426 - configId = -1; 427 - int j1 = buf.getUnsignedByte(); 428 - childrenIds = new int[j1 + 1]; 429 - for (int j2 = 0; j2 <= j1; j2++) { 430 - childrenIds[j2] = buf.getUnsignedShortBE(); 431 - if (childrenIds[j2] == 65535) 432 - childrenIds[j2] = -1; 433 - } 434 - 435 - } 436 - if (i == -1) { 437 - hasActions = false; 438 - if (modelIds != null && (modelTypes == null || modelTypes[0] == 10)) 439 - hasActions = true; 440 - if (options != null) 441 - hasActions = true; 442 - } 443 - if (aBoolean791) { 444 - solid = false; 445 - walkable = false; 446 - } 447 - if (anInt794 == -1) 448 - anInt794 = solid ? 1 : 0; 449 - } 450 - 451 - public Model getGameObjectModel(int type, int face, int vertexHeight, int vertexHeightRight, int vertexHeightTopRight, int vertexHeightTop, int animationId) { 452 - Model model = getGameObjectAnimatedModel(type, animationId, face); 453 - if (model == null) 454 - return null; 455 - if (adjustToTerrain || nonFlatShading) 456 - model = new Model(adjustToTerrain, nonFlatShading, model); 457 - if (adjustToTerrain) { 458 - int l1 = (vertexHeight + vertexHeightRight + vertexHeightTopRight + vertexHeightTop) / 4; 459 - for (int i2 = 0; i2 < model.vertexCount; i2++) { 460 - int j2 = model.verticesX[i2]; 461 - int k2 = model.verticesZ[i2]; 462 - int l2 = vertexHeight + ((vertexHeightRight - vertexHeight) * (j2 + 64)) / 128; 463 - int i3 = vertexHeightTop + ((vertexHeightTopRight - vertexHeightTop) * (j2 + 64)) / 128; 464 - int j3 = l2 + ((i3 - l2) * (k2 + 64)) / 128; 465 - model.verticesY[i2] += j3 - l1; 466 - } 467 - 468 - model.normalise(); 469 - } 470 - return model; 471 - } 472 - 473 - public boolean method432(int i, int j) { 474 - if (i != 26261) 475 - aBoolean786 = !aBoolean786; 476 - if (modelTypes == null) { 477 - if (modelIds == null) 478 - return true; 479 - if (j != 10) 480 - return true; 481 - boolean flag = true; 482 - for (int l = 0; l < modelIds.length; l++) 483 - flag &= Model.loaded(modelIds[l] & 0xffff); 484 - 485 - return flag; 486 - } 487 - for (int k = 0; k < modelTypes.length; k++) 488 - if (modelTypes[k] == j) 489 - return Model.loaded(modelIds[k] & 0xffff); 490 - 491 - return true; 492 - } 493 - 494 - public static void method433(boolean flag) { 495 - modelCache = null; 496 - animatedModelCache = null; 497 - bufferOffsets = null; 498 - if (flag) { 499 - for (int i = 1; i > 0; i++) ; 500 - } 501 - cache = null; 502 - buffer = null; 503 - } 504 - 505 - 506 - }
+403
src/main/java/com/jagex/runescape/cache/def/GameObjectDefinition.kt
··· 1 + package com.jagex.runescape.cache.def 2 + 3 + import com.jagex.runescape.Game 4 + import com.jagex.runescape.cache.Archive 5 + import com.jagex.runescape.cache.FileOperations 6 + import com.jagex.runescape.cache.cfg.Varbit 7 + import com.jagex.runescape.collection.Cache 8 + import com.jagex.runescape.media.Animation 9 + import com.jagex.runescape.media.renderable.Model 10 + import com.jagex.runescape.net.Buffer 11 + import com.jagex.runescape.net.requester.OnDemandRequester 12 + 13 + class GameObjectDefinition { 14 + 15 + @JvmField var hasActions: Boolean = false 16 + @JvmField var modelSizeY: Int = 0 17 + @JvmField var translateX: Int = 0 18 + @JvmField var modelIds: IntArray? = null 19 + @JvmField var anInt764: Int = 0 20 + @JvmField var unknown: Boolean = false 21 + @JvmField var translateZ: Int = 0 22 + @JvmField var adjustToTerrain: Boolean = false 23 + @JvmField var id: Int = -1 24 + @JvmField var sizeY: Int = 0 25 + @JvmField var name: String = "null" 26 + @JvmField var varbitId: Int = 0 27 + @JvmField var modelSizeX: Int = 0 28 + @JvmField var configId: Int = 0 29 + @JvmField var description: ByteArray? = null 30 + @JvmField var modelLightFalloff: Byte = 0 31 + @JvmField var translateY: Int = 0 32 + @JvmField var aBoolean786: Boolean = true 33 + @JvmField var modelLightAmbient: Byte = 0 34 + @JvmField var modelTypes: IntArray? = null 35 + @JvmField var options: Array<String?>? = null 36 + @JvmField var aBoolean791: Boolean = false 37 + @JvmField var anIntArray792: IntArray? = null 38 + @JvmField var anInt794: Int = 0 39 + @JvmField var anInt795: Int = 0 40 + @JvmField var modelSizeZ: Int = 0 41 + @JvmField var wall: Boolean = false 42 + @JvmField var unknown3: Boolean = false 43 + @JvmField var modifiedModelColors: IntArray? = null 44 + @JvmField var sizeX: Int = 0 45 + @JvmField var offsetAmplifier: Int = 0 46 + @JvmField var animationId: Int = 0 47 + @JvmField var nonFlatShading: Boolean = false 48 + @JvmField var childrenIds: IntArray? = null 49 + @JvmField var icon: Int = 0 50 + @JvmField var castsShadow: Boolean = false 51 + @JvmField var walkable: Boolean = false 52 + @JvmField var solid: Boolean = false 53 + 54 + fun setDefaultValues() { 55 + modelIds = null 56 + modelTypes = null 57 + name = "null" 58 + description = null 59 + modifiedModelColors = null 60 + anIntArray792 = null 61 + sizeX = 1 62 + sizeY = 1 63 + solid = true 64 + walkable = true 65 + hasActions = false 66 + adjustToTerrain = false 67 + nonFlatShading = false 68 + wall = false 69 + animationId = -1 70 + offsetAmplifier = 16 71 + modelLightFalloff = 0 72 + modelLightAmbient = 0 73 + options = null 74 + icon = -1 75 + anInt795 = -1 76 + unknown3 = false 77 + castsShadow = true 78 + modelSizeX = 128 79 + modelSizeY = 128 80 + modelSizeZ = 128 81 + anInt764 = 0 82 + translateX = 0 83 + translateY = 0 84 + translateZ = 0 85 + unknown = false 86 + aBoolean791 = false 87 + anInt794 = -1 88 + varbitId = -1 89 + configId = -1 90 + childrenIds = null 91 + } 92 + 93 + fun passiveRequestModels(onDemandRequester: OnDemandRequester) { 94 + if (modelIds != null) { 95 + for (modelId in modelIds!!) 96 + onDemandRequester.passiveRequest(modelId and 0xffff, 0) 97 + } 98 + } 99 + 100 + fun load(buf: Buffer) { 101 + var i = -1 102 + while (true) { 103 + val attribute = buf.getUnsignedByte() 104 + if (attribute == 0) break 105 + 106 + if (attribute == 77) { 107 + varbitId = buf.getUnsignedShortBE() 108 + if (varbitId == 65535) varbitId = -1 109 + configId = buf.getUnsignedShortBE() 110 + if (configId == 65535) configId = -1 111 + val j1 = buf.getUnsignedByte() 112 + childrenIds = IntArray(j1 + 1) { 113 + val v = buf.getUnsignedShortBE() 114 + if (v == 65535) -1 else v 115 + } 116 + continue 117 + } 118 + 119 + when (attribute) { 120 + 1 -> { 121 + val k = buf.getUnsignedByte() 122 + if (k > 0) { 123 + if (modelIds == null || lowMemory) { 124 + modelTypes = IntArray(k) 125 + modelIds = IntArray(k) 126 + for (k1 in 0 until k) { 127 + modelIds!![k1] = buf.getUnsignedShortBE() 128 + modelTypes!![k1] = buf.getUnsignedByte() 129 + } 130 + } else { 131 + buf.currentPosition += k * 3 132 + } 133 + } 134 + } 135 + 2 -> name = buf.getString() 136 + 3 -> description = buf.getStringBytes() 137 + 5 -> { 138 + val l = buf.getUnsignedByte() 139 + if (l > 0) { 140 + if (modelIds == null || lowMemory) { 141 + modelTypes = null 142 + modelIds = IntArray(l) { buf.getUnsignedShortBE() } 143 + } else { 144 + buf.currentPosition += l * 2 145 + } 146 + } 147 + } 148 + 14 -> sizeX = buf.getUnsignedByte() 149 + 15 -> sizeY = buf.getUnsignedByte() 150 + 17 -> solid = false 151 + 18 -> walkable = false 152 + 19 -> { 153 + i = buf.getUnsignedByte() 154 + if (i == 1) hasActions = true 155 + } 156 + 21 -> adjustToTerrain = true 157 + 22 -> nonFlatShading = true 158 + 23 -> wall = true 159 + 24 -> { 160 + animationId = buf.getUnsignedShortBE() 161 + if (animationId == 65535) animationId = -1 162 + } 163 + 28 -> offsetAmplifier = buf.getUnsignedByte() 164 + 29 -> modelLightFalloff = buf.getByte() 165 + in 30..38 -> { 166 + if (options == null) options = arrayOfNulls(5) 167 + options!![attribute - 30] = buf.getString() 168 + if (options!![attribute - 30].equals("hidden", ignoreCase = true)) 169 + options!![attribute - 30] = null 170 + } 171 + 39 -> modelLightAmbient = buf.getByte() 172 + 40 -> { 173 + val i1 = buf.getUnsignedByte() 174 + modifiedModelColors = IntArray(i1) 175 + anIntArray792 = IntArray(i1) 176 + for (i2 in 0 until i1) { 177 + modifiedModelColors!![i2] = buf.getUnsignedShortBE() 178 + anIntArray792!![i2] = buf.getUnsignedShortBE() 179 + } 180 + } 181 + 60 -> icon = buf.getUnsignedShortBE() 182 + 62 -> unknown3 = true 183 + 64 -> castsShadow = false 184 + 65 -> modelSizeX = buf.getUnsignedShortBE() 185 + 66 -> modelSizeY = buf.getUnsignedShortBE() 186 + 67 -> modelSizeZ = buf.getUnsignedShortBE() 187 + 68 -> anInt795 = buf.getUnsignedShortBE() 188 + 69 -> anInt764 = buf.getUnsignedByte() 189 + 70 -> translateX = buf.getShortBE() 190 + 71 -> translateY = buf.getShortBE() 191 + 72 -> translateZ = buf.getShortBE() 192 + 73 -> unknown = true 193 + 74 -> aBoolean791 = true 194 + 75 -> anInt794 = buf.getUnsignedByte() 195 + } 196 + } 197 + if (i == -1) { 198 + hasActions = false 199 + if (modelIds != null && (modelTypes == null || modelTypes!![0] == 10)) 200 + hasActions = true 201 + if (options != null) 202 + hasActions = true 203 + } 204 + if (aBoolean791) { 205 + solid = false 206 + walkable = false 207 + } 208 + if (anInt794 == -1) 209 + anInt794 = if (solid) 1 else 0 210 + } 211 + 212 + fun getGameObjectAnimatedModel(type: Int, animationId: Int, face: Int): Model? { 213 + var subModel: Model? = null 214 + val hash: Long 215 + if (modelTypes == null) { 216 + if (type != 10) return null 217 + hash = ((id shl 6) + face).toLong() + ((animationId + 1).toLong() shl 32) 218 + val cachedModel = animatedModelCache!!.get(hash) as Model? 219 + if (cachedModel != null) return cachedModel 220 + if (modelIds == null) return null 221 + val mirror = unknown3 xor (face > 3) 222 + val modelCount = modelIds!!.size 223 + for (modelId in 0 until modelCount) { 224 + var subModelId = modelIds!![modelId] 225 + if (mirror) subModelId += 0x10000 226 + subModel = modelCache!!.get(subModelId.toLong()) as Model? 227 + if (subModel == null) { 228 + subModel = Model.getModel(subModelId and 0xffff) 229 + if (subModel == null) return null 230 + if (mirror) subModel.mirror(0) 231 + modelCache!!.put(subModel, subModelId.toLong()) 232 + } 233 + if (modelCount > 1) models[modelId] = subModel 234 + } 235 + if (modelCount > 1) subModel = Model(modelCount, models) 236 + } else { 237 + var modelType = -1 238 + for (index in modelTypes!!.indices) { 239 + if (modelTypes!![index] != type) continue 240 + modelType = index 241 + break 242 + } 243 + if (modelType == -1) return null 244 + hash = ((id shl 6) + (modelType shl 3) + face).toLong() + ((animationId + 1).toLong() shl 32) 245 + val model = animatedModelCache!!.get(hash) as Model? 246 + if (model != null) return model 247 + var j2 = modelIds!![modelType] 248 + val mirror = unknown3 xor (face > 3) 249 + if (mirror) j2 += 0x10000 250 + subModel = modelCache!!.get(j2.toLong()) as Model? 251 + if (subModel == null) { 252 + subModel = Model.getModel(j2 and 0xffff) 253 + if (subModel == null) return null 254 + if (mirror) subModel.mirror(0) 255 + modelCache!!.put(subModel, j2.toLong()) 256 + } 257 + } 258 + val scale = modelSizeX != 128 || modelSizeY != 128 || modelSizeZ != 128 259 + val needsTranslation = translateX != 0 || translateY != 0 || translateZ != 0 260 + val animatedModel = Model(modifiedModelColors == null, subModel, Animation.exists(animationId)) 261 + if (animationId != -1) { 262 + animatedModel.createBones() 263 + animatedModel.applyTransform(animationId) 264 + animatedModel.triangleSkin = null 265 + animatedModel.vectorSkin = null 266 + } 267 + var remainingFace = face 268 + while (remainingFace-- > 0) animatedModel.rotate90Degrees() 269 + if (modifiedModelColors != null) { 270 + for (k2 in modifiedModelColors!!.indices) 271 + animatedModel.replaceColor(modifiedModelColors!![k2], anIntArray792!![k2]) 272 + } 273 + if (scale) 274 + animatedModel.scaleT(modelSizeY, modelSizeZ, 9, modelSizeX) 275 + if (needsTranslation) 276 + animatedModel.translate(translateX, translateZ, translateY) 277 + animatedModel.applyLighting( 278 + 64 + modelLightFalloff, 768 + modelLightAmbient * 5, -50, -10, -50, !nonFlatShading 279 + ) 280 + if (anInt794 == 1) 281 + animatedModel.anInt1675 = animatedModel.modelHeight 282 + animatedModelCache!!.put(animatedModel, hash) 283 + return animatedModel 284 + } 285 + 286 + fun isModelCached(): Boolean { 287 + if (modelIds == null) return true 288 + var cached = true 289 + for (modelId in modelIds!!) 290 + cached = cached and Model.loaded(modelId and 0xffff) 291 + return cached 292 + } 293 + 294 + fun getGameObjectModel( 295 + type: Int, face: Int, vertexHeight: Int, vertexHeightRight: Int, 296 + vertexHeightTopRight: Int, vertexHeightTop: Int, animationId: Int 297 + ): Model? { 298 + var model = getGameObjectAnimatedModel(type, animationId, face) ?: return null 299 + if (adjustToTerrain || nonFlatShading) 300 + model = Model(adjustToTerrain, nonFlatShading, model) 301 + if (adjustToTerrain) { 302 + val l1 = (vertexHeight + vertexHeightRight + vertexHeightTopRight + vertexHeightTop) / 4 303 + for (i2 in 0 until model.vertexCount) { 304 + val j2 = model.verticesX[i2] 305 + val k2 = model.verticesZ[i2] 306 + val l2 = vertexHeight + ((vertexHeightRight - vertexHeight) * (j2 + 64)) / 128 307 + val i3 = vertexHeightTop + ((vertexHeightTopRight - vertexHeightTop) * (j2 + 64)) / 128 308 + val j3 = l2 + ((i3 - l2) * (k2 + 64)) / 128 309 + model.verticesY[i2] += j3 - l1 310 + } 311 + model.normalise() 312 + } 313 + return model 314 + } 315 + 316 + fun method432(i: Int, j: Int): Boolean { 317 + if (i != 26261) aBoolean786 = !aBoolean786 318 + if (modelTypes == null) { 319 + if (modelIds == null) return true 320 + if (j != 10) return true 321 + var flag = true 322 + for (l in modelIds!!.indices) 323 + flag = flag and Model.loaded(modelIds!![l] and 0xffff) 324 + return flag 325 + } 326 + for (k in modelTypes!!.indices) 327 + if (modelTypes!![k] == j) return Model.loaded(modelIds!![k] and 0xffff) 328 + return true 329 + } 330 + 331 + fun getChildDefinition(): GameObjectDefinition? { 332 + var child = -1 333 + if (varbitId != -1) { 334 + val varbit = Varbit.cache!![varbitId]!! 335 + val configId = varbit.configId 336 + val leastSignificantBit = varbit.leastSignificantBit 337 + val mostSignificantBit = varbit.mostSignificantBit 338 + val bit = Game.BITFIELD_MAX_VALUE[mostSignificantBit - leastSignificantBit] 339 + child = client!!.widgetSettings[configId] shr leastSignificantBit and bit 340 + } else if (configId != -1) { 341 + child = client!!.widgetSettings[configId] 342 + } 343 + return if (child < 0 || child >= childrenIds!!.size || childrenIds!![child] == -1) null 344 + else getDefinition(childrenIds!![child]) 345 + } 346 + 347 + companion object { 348 + @JvmField var bufferOffsets: IntArray? = null 349 + @JvmField var animatedModelCache: Cache? = Cache(40) 350 + @JvmField var buffer: Buffer? = null 351 + @JvmField var client: Game? = null 352 + @JvmField var models: Array<Model?> = arrayOfNulls(4) 353 + @JvmField var lowMemory: Boolean = false 354 + @JvmField var cacheIndex: Int = 0 355 + @JvmField var modelCache: Cache? = Cache(500) 356 + @JvmField var cache: Array<GameObjectDefinition?>? = null 357 + @JvmField var definitionCount: Int = 0 358 + 359 + @JvmStatic 360 + fun getDefinition(id: Int): GameObjectDefinition { 361 + for (index in 0 until 20) 362 + if (cache!![index]!!.id == id) return cache!![index]!! 363 + 364 + cacheIndex = (cacheIndex + 1) % 20 365 + val definition = cache!![cacheIndex]!! 366 + buffer!!.currentPosition = bufferOffsets!![id] 367 + definition.id = id 368 + definition.setDefaultValues() 369 + definition.load(buffer!!) 370 + return definition 371 + } 372 + 373 + @JvmStatic 374 + fun load(archive: Archive) { 375 + buffer = Buffer(archive.getFile("loc.dat")!!) 376 + val idxBuffer = Buffer(archive.getFile("loc.idx")!!) 377 + FileOperations.WriteFile("DumpedData/377_OBJECTS.dat", archive.getFile("loc.dat")!!) 378 + FileOperations.WriteFile("DumpedData/377_OBJECTS.idx", archive.getFile("loc.idx")!!) 379 + definitionCount = idxBuffer.getUnsignedShortBE() 380 + bufferOffsets = IntArray(definitionCount) 381 + var offset = 2 382 + for (index in 0 until definitionCount) { 383 + bufferOffsets!![index] = offset 384 + offset += idxBuffer.getUnsignedShortBE() 385 + } 386 + cache = Array(20) { GameObjectDefinition() } 387 + } 388 + 389 + @JvmStatic 390 + fun method433(flag: Boolean) { 391 + modelCache = null 392 + animatedModelCache = null 393 + bufferOffsets = null 394 + if (flag) { 395 + @Suppress("ControlFlowWithEmptyBody") 396 + var i = 1 397 + while (i > 0) i++ 398 + } 399 + cache = null 400 + buffer = null 401 + } 402 + } 403 + }
-549
src/main/java/com/jagex/runescape/cache/def/ItemDefinition.java
··· 1 - package com.jagex.runescape.cache.def; 2 - 3 - import com.jagex.runescape.cache.media.ImageRGB; 4 - import com.jagex.runescape.cache.Archive; 5 - import com.jagex.runescape.collection.Cache; 6 - import com.jagex.runescape.media.Rasterizer; 7 - import com.jagex.runescape.media.Rasterizer3D; 8 - import com.jagex.runescape.media.renderable.Model; 9 - import com.jagex.runescape.media.renderable.Renderable; 10 - import com.jagex.runescape.net.Buffer; 11 - 12 - public class ItemDefinition { 13 - 14 - public int primaryFemaleModel; 15 - public int modelOffsetX; 16 - public byte description[]; 17 - public String name; 18 - public byte femaleTranslation; 19 - public int secondaryMaleModel; 20 - public int team; 21 - public int notedInfoId; 22 - public int primaryMaleHeadPiece; 23 - public static int count; 24 - public static ItemDefinition cache[]; 25 - public static Cache modelCache = new Cache(50); 26 - public String groundActions[]; 27 - public int anInt339; 28 - public int modelOffsetY; 29 - public int destColors[]; 30 - public static int offsets[]; 31 - public int notedTemplateId; 32 - public static boolean memberServer = true; 33 - public int value; 34 - public static Cache rgbImageCache = new Cache(100); 35 - public String inventoryActions[]; 36 - public static boolean aBoolean350 = true; 37 - public static int cacheIndex; 38 - public int primaryMaleModel; 39 - public int ambience; 40 - public int secondaryFemaleModel; 41 - public int modelRotationY; 42 - public int groundScaleY; 43 - public int diffusion; 44 - public int modelRotationX; 45 - public int modelId; 46 - public int secondaryMaleHeadPiece; 47 - public int secondaryFemaleHeadPiece; 48 - public int id = -1; 49 - public int originalColours[]; 50 - public int stackIds[]; 51 - public int groundScaleX; 52 - public int tertiaryFemaleEquipmentModel; 53 - public int groundScaleZ; 54 - public int modelScale; 55 - public int tertiaryMaleEquipmentModel; 56 - public boolean stackable; 57 - public int anInt372; 58 - public static Buffer buffer; 59 - public int primaryFemaleHeadPiece; 60 - public int stackAmounts[]; 61 - public boolean members; 62 - public byte maleTranslation; 63 - 64 - 65 - public void reset() { 66 - modelId = 0; 67 - name = null; 68 - description = null; 69 - originalColours = null; 70 - destColors = null; 71 - modelScale = 2000; 72 - modelRotationX = 0; 73 - modelRotationY = 0; 74 - anInt339 = 0; 75 - modelOffsetX = 0; 76 - modelOffsetY = 0; 77 - anInt372 = -1; 78 - stackable = false; 79 - value = 1; 80 - members = false; 81 - groundActions = null; 82 - inventoryActions = null; 83 - primaryMaleModel = -1; 84 - secondaryMaleModel = -1; 85 - maleTranslation = 0; 86 - primaryFemaleModel = -1; 87 - secondaryFemaleModel = -1; 88 - femaleTranslation = 0; 89 - tertiaryMaleEquipmentModel = -1; 90 - tertiaryFemaleEquipmentModel = -1; 91 - primaryMaleHeadPiece = -1; 92 - secondaryMaleHeadPiece = -1; 93 - primaryFemaleHeadPiece = -1; 94 - secondaryFemaleHeadPiece = -1; 95 - stackIds = null; 96 - stackAmounts = null; 97 - notedInfoId = -1; 98 - notedTemplateId = -1; 99 - groundScaleX = 128; 100 - groundScaleY = 128; 101 - groundScaleZ = 128; 102 - ambience = 0; 103 - diffusion = 0; 104 - team = 0; 105 - } 106 - 107 - public static void dispose() { 108 - modelCache = null; 109 - rgbImageCache = null; 110 - offsets = null; 111 - cache = null; 112 - buffer = null; 113 - } 114 - 115 - public boolean headPieceReady(int gender) { 116 - int primary = primaryMaleHeadPiece; 117 - int secondary = secondaryMaleHeadPiece; 118 - if (gender == 1) { 119 - primary = primaryFemaleHeadPiece; 120 - secondary = secondaryFemaleHeadPiece; 121 - } 122 - if (primary == -1) 123 - return true; 124 - boolean ready = true; 125 - if (!Model.loaded(primary)) 126 - ready = false; 127 - if (secondary != -1 && !Model.loaded(secondary)) 128 - ready = false; 129 - return ready; 130 - } 131 - 132 - public static ItemDefinition lookup(int id) { 133 - for (int i = 0; i < 10; i++) 134 - if (cache[i].id == id) 135 - return cache[i]; 136 - 137 - cacheIndex = (cacheIndex + 1) % 10; 138 - ItemDefinition definition = cache[cacheIndex]; 139 - buffer.currentPosition = offsets[id]; 140 - definition.id = id; 141 - definition.reset(); 142 - definition.decode(buffer); 143 - if (definition.notedTemplateId != -1) 144 - definition.toNote(); 145 - if (!memberServer && definition.members) { 146 - definition.name = "Members Object"; 147 - definition.description = "Login to a members' server to use this object.".getBytes(); 148 - definition.groundActions = null; 149 - definition.inventoryActions = null; 150 - definition.team = 0; 151 - } 152 - return definition; 153 - } 154 - 155 - public Model asEquipment(int gender) { 156 - int primaryId = primaryMaleModel; 157 - int secondaryId = secondaryMaleModel; 158 - int tertiaryId = tertiaryMaleEquipmentModel; 159 - if (gender == 1) { 160 - primaryId = primaryFemaleModel; 161 - secondaryId = secondaryFemaleModel; 162 - tertiaryId = tertiaryFemaleEquipmentModel; 163 - } 164 - if (primaryId == -1) 165 - return null; 166 - Model primary = Model.getModel(primaryId); 167 - if (secondaryId != -1) 168 - if (tertiaryId == -1) { 169 - Model secondary = Model.getModel(secondaryId); 170 - Model parts[] = { primary, secondary }; 171 - primary = new Model(2, parts); 172 - } else { 173 - Model secondary = Model.getModel(secondaryId); 174 - Model tertiary = Model.getModel(tertiaryId); 175 - Model parts[] = { primary, 176 - secondary, tertiary }; 177 - primary = new Model(3, parts); 178 - } 179 - if (gender == 0 && maleTranslation != 0) 180 - primary.translate(0, 0, maleTranslation); 181 - if (gender == 1 && femaleTranslation != 0) 182 - primary.translate(0, 0, femaleTranslation); 183 - if (originalColours != null) { 184 - for (int color = 0; color < originalColours.length; color++) 185 - primary.replaceColor(originalColours[color], destColors[color]); 186 - 187 - } 188 - return primary; 189 - } 190 - 191 - public static void load(Archive archive) { 192 - buffer = new Buffer(archive.getFile("obj.dat")); 193 - Buffer buffer = new Buffer(archive.getFile("obj.idx")); 194 - count = buffer.getUnsignedShortBE(); 195 - offsets = new int[count]; 196 - int index = 2; 197 - for (int i = 0; i < count; i++) { 198 - offsets[i] = index; 199 - index += buffer.getUnsignedShortBE(); 200 - } 201 - 202 - cache = new ItemDefinition[10]; 203 - for (int i = 0; i < 10; i++) 204 - cache[i] = new ItemDefinition(); 205 - 206 - } 207 - 208 - public void toNote() { 209 - ItemDefinition graphics = lookup(notedTemplateId); 210 - modelId = graphics.modelId; 211 - modelScale = graphics.modelScale; 212 - modelRotationX = graphics.modelRotationX; 213 - modelRotationY = graphics.modelRotationY; 214 - anInt339 = graphics.anInt339; 215 - modelOffsetX = graphics.modelOffsetX; 216 - modelOffsetY = graphics.modelOffsetY; 217 - originalColours = graphics.originalColours; 218 - destColors = graphics.destColors; 219 - ItemDefinition info = lookup(notedInfoId); 220 - name = info.name; 221 - members = info.members; 222 - value = info.value; 223 - String prefix = "a"; 224 - char firstChar = info.name.charAt(0); 225 - if (firstChar == 'A' || firstChar == 'E' || firstChar == 'I' || firstChar == 'O' || firstChar == 'U') 226 - prefix = "an"; 227 - description = ("Swap this note at any bank for " + prefix + " " + info.name + ".").getBytes(); 228 - stackable = true; 229 - } 230 - 231 - public boolean equipmentReady(int gender) { 232 - int primary = primaryMaleModel; 233 - int secondary = secondaryMaleModel; 234 - int tertiary = tertiaryMaleEquipmentModel; 235 - if (gender == 1) { 236 - primary = primaryFemaleModel; 237 - secondary = secondaryFemaleModel; 238 - tertiary = tertiaryFemaleEquipmentModel; 239 - } 240 - if (primary == -1) 241 - return true; 242 - boolean ready = true; 243 - if (!Model.loaded(primary)) 244 - ready = false; 245 - if (secondary != -1 && !Model.loaded(secondary)) 246 - ready = false; 247 - if (tertiary != -1 && !Model.loaded(tertiary)) 248 - ready = false; 249 - return ready; 250 - } 251 - 252 - public Model asStack(int stackSize) { 253 - if (stackIds != null && stackSize > 1) { 254 - int id = -1; 255 - for (int i = 0; i < 10; i++) 256 - if (stackSize >= stackAmounts[i] && stackAmounts[i] != 0) 257 - id = stackIds[i]; 258 - 259 - if (id != -1) 260 - return lookup(id).asStack(1); 261 - } 262 - Model model = Model.getModel(modelId); 263 - if (model == null) 264 - return null; 265 - if (originalColours != null) { 266 - for (int i = 0; i < originalColours.length; i++) 267 - model.replaceColor(originalColours[i], destColors[i]); 268 - 269 - } 270 - return model; 271 - } 272 - 273 - public void decode(Buffer buffer) { 274 - while (true) { 275 - int opcode = buffer.getUnsignedByte(); 276 - if (opcode == 0) 277 - return; 278 - if (opcode == 1) 279 - modelId = buffer.getUnsignedShortBE(); 280 - else if (opcode == 2) 281 - name = buffer.getString(); 282 - else if (opcode == 3) 283 - description = buffer.getStringBytes(); 284 - else if (opcode == 4) 285 - modelScale = buffer.getUnsignedShortBE(); 286 - else if (opcode == 5) 287 - modelRotationX = buffer.getUnsignedShortBE(); 288 - else if (opcode == 6) 289 - modelRotationY = buffer.getUnsignedShortBE(); 290 - else if (opcode == 7) { 291 - modelOffsetX = buffer.getUnsignedShortBE(); 292 - if (modelOffsetX > 32767) 293 - modelOffsetX -= 0x10000; 294 - } else if (opcode == 8) { 295 - modelOffsetY = buffer.getUnsignedShortBE(); 296 - if (modelOffsetY > 32767) 297 - modelOffsetY -= 0x10000; 298 - } else if (opcode == 10) 299 - buffer.getUnsignedShortBE(); // Dummy 300 - else if (opcode == 11) 301 - stackable = true; 302 - else if (opcode == 12) 303 - value = buffer.getIntBE(); 304 - else if (opcode == 16) 305 - members = true; 306 - else if (opcode == 23) { 307 - primaryMaleModel = buffer.getUnsignedShortBE(); 308 - maleTranslation = buffer.getByte(); 309 - } else if (opcode == 24) 310 - secondaryMaleModel = buffer.getUnsignedShortBE(); 311 - else if (opcode == 25) { 312 - primaryFemaleModel = buffer.getUnsignedShortBE(); 313 - femaleTranslation = buffer.getByte(); 314 - } else if (opcode == 26) 315 - secondaryFemaleModel = buffer.getUnsignedShortBE(); 316 - else if (opcode >= 30 && opcode < 35) { 317 - if (groundActions == null) 318 - groundActions = new String[5]; 319 - groundActions[opcode - 30] = buffer.getString(); 320 - if (groundActions[opcode - 30].equalsIgnoreCase("hidden")) 321 - groundActions[opcode - 30] = null; 322 - } else if (opcode >= 35 && opcode < 40) { 323 - if (inventoryActions == null) 324 - inventoryActions = new String[5]; 325 - inventoryActions[opcode - 35] = buffer.getString(); 326 - } else if (opcode == 40) { 327 - int colorCount = buffer.getUnsignedByte(); 328 - originalColours = new int[colorCount]; 329 - destColors = new int[colorCount]; 330 - for (int k = 0; k < colorCount; k++) { 331 - originalColours[k] = buffer.getUnsignedShortBE(); 332 - destColors[k] = buffer.getUnsignedShortBE(); 333 - } 334 - 335 - } else if (opcode == 78) 336 - tertiaryMaleEquipmentModel = buffer.getUnsignedShortBE(); 337 - else if (opcode == 79) 338 - tertiaryFemaleEquipmentModel = buffer.getUnsignedShortBE(); 339 - else if (opcode == 90) 340 - primaryMaleHeadPiece = buffer.getUnsignedShortBE(); 341 - else if (opcode == 91) 342 - primaryFemaleHeadPiece = buffer.getUnsignedShortBE(); 343 - else if (opcode == 92) 344 - secondaryMaleHeadPiece = buffer.getUnsignedShortBE(); 345 - else if (opcode == 93) 346 - secondaryFemaleHeadPiece = buffer.getUnsignedShortBE(); 347 - else if (opcode == 95) 348 - anInt339 = buffer.getUnsignedShortBE(); 349 - else if (opcode == 97) 350 - notedInfoId = buffer.getUnsignedShortBE(); 351 - else if (opcode == 98) 352 - notedTemplateId = buffer.getUnsignedShortBE(); 353 - else if (opcode >= 100 && opcode < 110) { 354 - if (stackIds == null) { 355 - stackIds = new int[10]; 356 - stackAmounts = new int[10]; 357 - } 358 - stackIds[opcode - 100] = buffer.getUnsignedShortBE(); 359 - stackAmounts[opcode - 100] = buffer.getUnsignedShortBE(); 360 - } else if (opcode == 110) 361 - groundScaleX = buffer.getUnsignedShortBE(); 362 - else if (opcode == 111) 363 - groundScaleY = buffer.getUnsignedShortBE(); 364 - else if (opcode == 112) 365 - groundScaleZ = buffer.getUnsignedShortBE(); 366 - else if (opcode == 113) 367 - ambience = buffer.getByte(); 368 - else if (opcode == 114) 369 - diffusion = buffer.getByte() * 5; 370 - else if (opcode == 115) 371 - team = buffer.getUnsignedByte(); 372 - } 373 - } 374 - 375 - public Model asHeadPiece(int gender) { 376 - int primaryId = primaryMaleHeadPiece; 377 - int secondaryId = secondaryMaleHeadPiece; 378 - if (gender == 1) { 379 - primaryId = primaryFemaleHeadPiece; 380 - secondaryId = secondaryFemaleHeadPiece; 381 - } 382 - if (primaryId == -1) 383 - return null; 384 - Model primary = Model.getModel(primaryId); 385 - if (secondaryId != -1) { 386 - Model secondary = Model.getModel(secondaryId); 387 - primary = new Model(2, new Model[] { primary, secondary }); 388 - } 389 - if (originalColours != null) { 390 - for (int index = 0; index < originalColours.length; index++) 391 - primary.replaceColor(originalColours[index], destColors[index]); 392 - 393 - } 394 - return primary; 395 - } 396 - 397 - public Model asGroundStack(int amount) { 398 - if (stackIds != null && amount > 1) { 399 - int id = -1; 400 - for (int i = 0; i < 10; i++) 401 - if (amount >= stackAmounts[i] && stackAmounts[i] != 0) 402 - id = stackIds[i]; 403 - 404 - if (id != -1) 405 - return lookup(id).asGroundStack(1); 406 - } 407 - Model model = (Model) modelCache.get(id); 408 - if (model != null) 409 - return model; 410 - model = Model.getModel(modelId); 411 - if (model == null) 412 - return null; 413 - if (groundScaleX != 128 || groundScaleY != 128 || groundScaleZ != 128) 414 - model.scaleT(groundScaleY, groundScaleZ, 9, groundScaleX); 415 - if (originalColours != null) { 416 - for (int l = 0; l < originalColours.length; l++) 417 - model.replaceColor(originalColours[l], destColors[l]); 418 - 419 - } 420 - model.applyLighting(64 + ambience, 768 + diffusion, -50, -10, -50, true); 421 - model.singleTile = true; 422 - modelCache.put(model, id); 423 - return model; 424 - } 425 - 426 - public static ImageRGB sprite(int id, int stackSize, int backColour) { 427 - if (backColour == 0) { 428 - ImageRGB sprite = (ImageRGB) rgbImageCache.get(id); 429 - if (sprite != null && sprite.maxHeight != stackSize 430 - && sprite.maxHeight != -1) { 431 - sprite.remove(); 432 - sprite = null; 433 - } 434 - if (sprite != null) 435 - return sprite; 436 - } 437 - ItemDefinition definition = lookup(id); 438 - if (definition.stackIds == null) 439 - stackSize = -1; 440 - if (stackSize > 1) { 441 - int stackId = -1; 442 - for (int i = 0; i < 10; i++) 443 - if (stackSize >= definition.stackAmounts[i] && definition.stackAmounts[i] != 0) 444 - stackId = definition.stackIds[i]; 445 - 446 - if (stackId != -1) 447 - definition = lookup(stackId); 448 - } 449 - Model model = definition.asGroundStack(1); 450 - if (model == null) 451 - return null; 452 - ImageRGB notedSprite = null; 453 - if (definition.notedTemplateId != -1) { 454 - notedSprite = sprite(definition.notedInfoId, 10, -1); 455 - if (notedSprite == null) 456 - return null; 457 - } 458 - ImageRGB rendered = new ImageRGB(32, 32); 459 - int centreX = Rasterizer3D.center_x; 460 - int centerY = Rasterizer3D.center_y; 461 - int lineOffsets[] = Rasterizer3D.lineOffsets; 462 - int pixels[] = Rasterizer.pixels; 463 - int width = Rasterizer.width; 464 - int height = Rasterizer.height; 465 - int topX = Rasterizer.topX; 466 - int bottomX = Rasterizer.bottomX; 467 - int topY = Rasterizer.topY; 468 - int bottomY = Rasterizer.bottomY; 469 - Rasterizer3D.notTextured = false; 470 - Rasterizer.createRasterizer(rendered.pixels, 32, 32); 471 - Rasterizer.drawFilledRectangle(0, 0, 32, 32, 0); 472 - Rasterizer3D.setDefaultBounds(); 473 - int scale = definition.modelScale; 474 - if (backColour == -1) 475 - scale = (int) (scale * 1.5D); 476 - if (backColour > 0) 477 - scale = (int) (scale * 1.04D); 478 - int sin = Rasterizer3D.SINE[definition.modelRotationX] * scale >> 16; 479 - int cos = Rasterizer3D.COSINE[definition.modelRotationX] * scale >> 16; 480 - model.render(0, definition.modelRotationY, definition.anInt339, definition.modelRotationX, definition.modelOffsetX, sin 481 - + ((Renderable) (model)).modelHeight / 2 + definition.modelOffsetY, cos 482 - + definition.modelOffsetY); 483 - for (int x = 31; x >= 0; x--) { 484 - for (int y = 31; y >= 0; y--) 485 - if (rendered.pixels[x + y * 32] == 0) 486 - if (x > 0 && rendered.pixels[(x - 1) + y * 32] > 1) 487 - rendered.pixels[x + y * 32] = 1; 488 - else if (y > 0 && rendered.pixels[x + (y - 1) * 32] > 1) 489 - rendered.pixels[x + y * 32] = 1; 490 - else if (x < 31 && rendered.pixels[x + 1 + y * 32] > 1) 491 - rendered.pixels[x + y * 32] = 1; 492 - else if (y < 31 && rendered.pixels[x + (y + 1) * 32] > 1) 493 - rendered.pixels[x + y * 32] = 1; 494 - 495 - } 496 - 497 - if (backColour > 0) { 498 - for (int x = 31; x >= 0; x--) { 499 - for (int y = 31; y >= 0; y--) 500 - if (rendered.pixels[x + y * 32] == 0) 501 - if (x > 0 && rendered.pixels[(x - 1) + y * 32] == 1) 502 - rendered.pixels[x + y * 32] = backColour; 503 - else if (y > 0 && rendered.pixels[x + (y - 1) * 32] == 1) 504 - rendered.pixels[x + y * 32] = backColour; 505 - else if (x < 31 && rendered.pixels[x + 1 + y * 32] == 1) 506 - rendered.pixels[x + y * 32] = backColour; 507 - else if (y < 31 && rendered.pixels[x + (y + 1) * 32] == 1) 508 - rendered.pixels[x + y * 32] = backColour; 509 - 510 - } 511 - 512 - } else if (backColour == 0) { 513 - for (int x = 31; x >= 0; x--) { 514 - for (int y = 31; y >= 0; y--) 515 - if (rendered.pixels[x + y * 32] == 0 && x > 0 && y > 0 516 - && rendered.pixels[(x - 1) + (y - 1) * 32] > 0) 517 - rendered.pixels[x + y * 32] = 0x302020; 518 - 519 - } 520 - 521 - } 522 - if (definition.notedTemplateId != -1) { 523 - int resizeWidth = notedSprite.maxWidth; 524 - int resizeHeight = notedSprite.maxHeight; 525 - notedSprite.maxWidth = 32; 526 - notedSprite.maxHeight = 32; 527 - notedSprite.drawImage(0, 0); 528 - notedSprite.maxWidth = resizeWidth; 529 - notedSprite.maxHeight = resizeHeight; 530 - } 531 - if (backColour == 0) 532 - rgbImageCache.put(rendered, id); 533 - Rasterizer.createRasterizer(pixels, width, height); 534 - Rasterizer.setCoordinates(topY, topX, bottomY, bottomX); 535 - Rasterizer3D.center_x = centreX; 536 - Rasterizer3D.center_y = centerY; 537 - Rasterizer3D.lineOffsets = lineOffsets; 538 - Rasterizer3D.notTextured = true; 539 - if (definition.stackable) 540 - rendered.maxWidth = 33; 541 - else 542 - rendered.maxWidth = 32; 543 - rendered.maxHeight = stackSize; 544 - return rendered; 545 - } 546 - 547 - 548 - 549 - }
+490
src/main/java/com/jagex/runescape/cache/def/ItemDefinition.kt
··· 1 + package com.jagex.runescape.cache.def 2 + 3 + import com.jagex.runescape.cache.Archive 4 + import com.jagex.runescape.cache.media.ImageRGB 5 + import com.jagex.runescape.collection.Cache 6 + import com.jagex.runescape.media.Rasterizer 7 + import com.jagex.runescape.media.Rasterizer3D 8 + import com.jagex.runescape.media.renderable.Model 9 + import com.jagex.runescape.media.renderable.Renderable 10 + import com.jagex.runescape.net.Buffer 11 + 12 + class ItemDefinition { 13 + 14 + @JvmField var primaryFemaleModel: Int = 0 15 + @JvmField var modelOffsetX: Int = 0 16 + @JvmField var description: ByteArray? = null 17 + @JvmField var name: String? = null 18 + @JvmField var femaleTranslation: Byte = 0 19 + @JvmField var secondaryMaleModel: Int = 0 20 + @JvmField var team: Int = 0 21 + @JvmField var notedInfoId: Int = 0 22 + @JvmField var primaryMaleHeadPiece: Int = 0 23 + @JvmField var anInt339: Int = 0 24 + @JvmField var modelOffsetY: Int = 0 25 + @JvmField var destColors: IntArray? = null 26 + @JvmField var notedTemplateId: Int = 0 27 + @JvmField var value: Int = 0 28 + @JvmField var inventoryActions: Array<String?>? = null 29 + @JvmField var primaryMaleModel: Int = 0 30 + @JvmField var ambience: Int = 0 31 + @JvmField var secondaryFemaleModel: Int = 0 32 + @JvmField var modelRotationY: Int = 0 33 + @JvmField var groundScaleY: Int = 0 34 + @JvmField var diffusion: Int = 0 35 + @JvmField var modelRotationX: Int = 0 36 + @JvmField var modelId: Int = 0 37 + @JvmField var secondaryMaleHeadPiece: Int = 0 38 + @JvmField var secondaryFemaleHeadPiece: Int = 0 39 + @JvmField var id: Int = -1 40 + @JvmField var originalColours: IntArray? = null 41 + @JvmField var stackIds: IntArray? = null 42 + @JvmField var groundScaleX: Int = 0 43 + @JvmField var tertiaryFemaleEquipmentModel: Int = 0 44 + @JvmField var groundScaleZ: Int = 0 45 + @JvmField var modelScale: Int = 0 46 + @JvmField var tertiaryMaleEquipmentModel: Int = 0 47 + @JvmField var stackable: Boolean = false 48 + @JvmField var anInt372: Int = 0 49 + @JvmField var primaryFemaleHeadPiece: Int = 0 50 + @JvmField var stackAmounts: IntArray? = null 51 + @JvmField var members: Boolean = false 52 + @JvmField var maleTranslation: Byte = 0 53 + @JvmField var groundActions: Array<String?>? = null 54 + 55 + fun reset() { 56 + modelId = 0 57 + name = null 58 + description = null 59 + originalColours = null 60 + destColors = null 61 + modelScale = 2000 62 + modelRotationX = 0 63 + modelRotationY = 0 64 + anInt339 = 0 65 + modelOffsetX = 0 66 + modelOffsetY = 0 67 + anInt372 = -1 68 + stackable = false 69 + value = 1 70 + members = false 71 + groundActions = null 72 + inventoryActions = null 73 + primaryMaleModel = -1 74 + secondaryMaleModel = -1 75 + maleTranslation = 0 76 + primaryFemaleModel = -1 77 + secondaryFemaleModel = -1 78 + femaleTranslation = 0 79 + tertiaryMaleEquipmentModel = -1 80 + tertiaryFemaleEquipmentModel = -1 81 + primaryMaleHeadPiece = -1 82 + secondaryMaleHeadPiece = -1 83 + primaryFemaleHeadPiece = -1 84 + secondaryFemaleHeadPiece = -1 85 + stackIds = null 86 + stackAmounts = null 87 + notedInfoId = -1 88 + notedTemplateId = -1 89 + groundScaleX = 128 90 + groundScaleY = 128 91 + groundScaleZ = 128 92 + ambience = 0 93 + diffusion = 0 94 + team = 0 95 + } 96 + 97 + fun headPieceReady(gender: Int): Boolean { 98 + var primary = primaryMaleHeadPiece 99 + var secondary = secondaryMaleHeadPiece 100 + if (gender == 1) { 101 + primary = primaryFemaleHeadPiece 102 + secondary = secondaryFemaleHeadPiece 103 + } 104 + if (primary == -1) return true 105 + var ready = true 106 + if (!Model.loaded(primary)) ready = false 107 + if (secondary != -1 && !Model.loaded(secondary)) ready = false 108 + return ready 109 + } 110 + 111 + fun asEquipment(gender: Int): Model? { 112 + var primaryId = primaryMaleModel 113 + var secondaryId = secondaryMaleModel 114 + var tertiaryId = tertiaryMaleEquipmentModel 115 + if (gender == 1) { 116 + primaryId = primaryFemaleModel 117 + secondaryId = secondaryFemaleModel 118 + tertiaryId = tertiaryFemaleEquipmentModel 119 + } 120 + if (primaryId == -1) return null 121 + var primary = Model.getModel(primaryId) 122 + if (secondaryId != -1) { 123 + primary = if (tertiaryId == -1) { 124 + val secondary = Model.getModel(secondaryId) 125 + Model(2, arrayOf(primary, secondary)) 126 + } else { 127 + val secondary = Model.getModel(secondaryId) 128 + val tertiary = Model.getModel(tertiaryId) 129 + Model(3, arrayOf(primary, secondary, tertiary)) 130 + } 131 + } 132 + if (gender == 0 && maleTranslation.toInt() != 0) 133 + primary.translate(0, 0, maleTranslation.toInt()) 134 + if (gender == 1 && femaleTranslation.toInt() != 0) 135 + primary.translate(0, 0, femaleTranslation.toInt()) 136 + if (originalColours != null) { 137 + for (color in originalColours!!.indices) 138 + primary.replaceColor(originalColours!![color], destColors!![color]) 139 + } 140 + return primary 141 + } 142 + 143 + fun toNote() { 144 + val graphics = lookup(notedTemplateId) 145 + modelId = graphics.modelId 146 + modelScale = graphics.modelScale 147 + modelRotationX = graphics.modelRotationX 148 + modelRotationY = graphics.modelRotationY 149 + anInt339 = graphics.anInt339 150 + modelOffsetX = graphics.modelOffsetX 151 + modelOffsetY = graphics.modelOffsetY 152 + originalColours = graphics.originalColours 153 + destColors = graphics.destColors 154 + val info = lookup(notedInfoId) 155 + name = info.name 156 + members = info.members 157 + value = info.value 158 + val firstChar = info.name!!.first() 159 + val prefix = if (firstChar == 'A' || firstChar == 'E' || firstChar == 'I' || firstChar == 'O' || firstChar == 'U') "an" else "a" 160 + description = "Swap this note at any bank for $prefix ${info.name}.".toByteArray() 161 + stackable = true 162 + } 163 + 164 + fun equipmentReady(gender: Int): Boolean { 165 + var primary = primaryMaleModel 166 + var secondary = secondaryMaleModel 167 + var tertiary = tertiaryMaleEquipmentModel 168 + if (gender == 1) { 169 + primary = primaryFemaleModel 170 + secondary = secondaryFemaleModel 171 + tertiary = tertiaryFemaleEquipmentModel 172 + } 173 + if (primary == -1) return true 174 + var ready = true 175 + if (!Model.loaded(primary)) ready = false 176 + if (secondary != -1 && !Model.loaded(secondary)) ready = false 177 + if (tertiary != -1 && !Model.loaded(tertiary)) ready = false 178 + return ready 179 + } 180 + 181 + fun asStack(stackSize: Int): Model? { 182 + if (stackIds != null && stackSize > 1) { 183 + var id = -1 184 + for (i in 0 until 10) 185 + if (stackSize >= stackAmounts!![i] && stackAmounts!![i] != 0) id = stackIds!![i] 186 + if (id != -1) return lookup(id).asStack(1) 187 + } 188 + val model = Model.getModel(modelId) ?: return null 189 + if (originalColours != null) { 190 + for (i in originalColours!!.indices) 191 + model.replaceColor(originalColours!![i], destColors!![i]) 192 + } 193 + return model 194 + } 195 + 196 + fun decode(buffer: Buffer) { 197 + while (true) { 198 + val opcode = buffer.getUnsignedByte() 199 + if (opcode == 0) return 200 + when { 201 + opcode == 1 -> modelId = buffer.getUnsignedShortBE() 202 + opcode == 2 -> name = buffer.getString() 203 + opcode == 3 -> description = buffer.getStringBytes() 204 + opcode == 4 -> modelScale = buffer.getUnsignedShortBE() 205 + opcode == 5 -> modelRotationX = buffer.getUnsignedShortBE() 206 + opcode == 6 -> modelRotationY = buffer.getUnsignedShortBE() 207 + opcode == 7 -> { 208 + modelOffsetX = buffer.getUnsignedShortBE() 209 + if (modelOffsetX > 32767) modelOffsetX -= 0x10000 210 + } 211 + opcode == 8 -> { 212 + modelOffsetY = buffer.getUnsignedShortBE() 213 + if (modelOffsetY > 32767) modelOffsetY -= 0x10000 214 + } 215 + opcode == 10 -> buffer.getUnsignedShortBE() // Dummy 216 + opcode == 11 -> stackable = true 217 + opcode == 12 -> value = buffer.getIntBE() 218 + opcode == 16 -> members = true 219 + opcode == 23 -> { 220 + primaryMaleModel = buffer.getUnsignedShortBE() 221 + maleTranslation = buffer.getByte() 222 + } 223 + opcode == 24 -> secondaryMaleModel = buffer.getUnsignedShortBE() 224 + opcode == 25 -> { 225 + primaryFemaleModel = buffer.getUnsignedShortBE() 226 + femaleTranslation = buffer.getByte() 227 + } 228 + opcode == 26 -> secondaryFemaleModel = buffer.getUnsignedShortBE() 229 + opcode in 30..34 -> { 230 + if (groundActions == null) groundActions = arrayOfNulls(5) 231 + groundActions!![opcode - 30] = buffer.getString() 232 + if (groundActions!![opcode - 30].equals("hidden", ignoreCase = true)) 233 + groundActions!![opcode - 30] = null 234 + } 235 + opcode in 35..39 -> { 236 + if (inventoryActions == null) inventoryActions = arrayOfNulls(5) 237 + inventoryActions!![opcode - 35] = buffer.getString() 238 + } 239 + opcode == 40 -> { 240 + val colorCount = buffer.getUnsignedByte() 241 + originalColours = IntArray(colorCount) 242 + destColors = IntArray(colorCount) 243 + for (k in 0 until colorCount) { 244 + originalColours!![k] = buffer.getUnsignedShortBE() 245 + destColors!![k] = buffer.getUnsignedShortBE() 246 + } 247 + } 248 + opcode == 78 -> tertiaryMaleEquipmentModel = buffer.getUnsignedShortBE() 249 + opcode == 79 -> tertiaryFemaleEquipmentModel = buffer.getUnsignedShortBE() 250 + opcode == 90 -> primaryMaleHeadPiece = buffer.getUnsignedShortBE() 251 + opcode == 91 -> primaryFemaleHeadPiece = buffer.getUnsignedShortBE() 252 + opcode == 92 -> secondaryMaleHeadPiece = buffer.getUnsignedShortBE() 253 + opcode == 93 -> secondaryFemaleHeadPiece = buffer.getUnsignedShortBE() 254 + opcode == 95 -> anInt339 = buffer.getUnsignedShortBE() 255 + opcode == 97 -> notedInfoId = buffer.getUnsignedShortBE() 256 + opcode == 98 -> notedTemplateId = buffer.getUnsignedShortBE() 257 + opcode in 100..109 -> { 258 + if (stackIds == null) { 259 + stackIds = IntArray(10) 260 + stackAmounts = IntArray(10) 261 + } 262 + stackIds!![opcode - 100] = buffer.getUnsignedShortBE() 263 + stackAmounts!![opcode - 100] = buffer.getUnsignedShortBE() 264 + } 265 + opcode == 110 -> groundScaleX = buffer.getUnsignedShortBE() 266 + opcode == 111 -> groundScaleY = buffer.getUnsignedShortBE() 267 + opcode == 112 -> groundScaleZ = buffer.getUnsignedShortBE() 268 + opcode == 113 -> ambience = buffer.getByte().toInt() 269 + opcode == 114 -> diffusion = buffer.getByte().toInt() * 5 270 + opcode == 115 -> team = buffer.getUnsignedByte() 271 + } 272 + } 273 + } 274 + 275 + fun asHeadPiece(gender: Int): Model? { 276 + var primaryId = primaryMaleHeadPiece 277 + var secondaryId = secondaryMaleHeadPiece 278 + if (gender == 1) { 279 + primaryId = primaryFemaleHeadPiece 280 + secondaryId = secondaryFemaleHeadPiece 281 + } 282 + if (primaryId == -1) return null 283 + var primary = Model.getModel(primaryId) 284 + if (secondaryId != -1) { 285 + val secondary = Model.getModel(secondaryId) 286 + primary = Model(2, arrayOf(primary, secondary)) 287 + } 288 + if (originalColours != null) { 289 + for (index in originalColours!!.indices) 290 + primary.replaceColor(originalColours!![index], destColors!![index]) 291 + } 292 + return primary 293 + } 294 + 295 + fun asGroundStack(amount: Int): Model? { 296 + if (stackIds != null && amount > 1) { 297 + var id = -1 298 + for (i in 0 until 10) 299 + if (amount >= stackAmounts!![i] && stackAmounts!![i] != 0) id = stackIds!![i] 300 + if (id != -1) return lookup(id).asGroundStack(1) 301 + } 302 + var model = modelCache!!.get(id.toLong()) as Model? 303 + if (model != null) return model 304 + model = Model.getModel(modelId) ?: return null 305 + if (groundScaleX != 128 || groundScaleY != 128 || groundScaleZ != 128) 306 + model.scaleT(groundScaleY, groundScaleZ, 9, groundScaleX) 307 + if (originalColours != null) { 308 + for (l in originalColours!!.indices) 309 + model.replaceColor(originalColours!![l], destColors!![l]) 310 + } 311 + model.applyLighting(64 + ambience, 768 + diffusion, -50, -10, -50, true) 312 + model.singleTile = true 313 + modelCache!!.put(model, id.toLong()) 314 + return model 315 + } 316 + 317 + companion object { 318 + @JvmField var count: Int = 0 319 + @JvmField var cache: Array<ItemDefinition?>? = null 320 + @JvmField var modelCache: Cache? = Cache(50) 321 + @JvmField var offsets: IntArray? = null 322 + @JvmField var memberServer: Boolean = true 323 + @JvmField var rgbImageCache: Cache? = Cache(100) 324 + @JvmField var aBoolean350: Boolean = true 325 + @JvmField var cacheIndex: Int = 0 326 + @JvmField var buffer: Buffer? = null 327 + 328 + @JvmStatic 329 + fun dispose() { 330 + modelCache = null 331 + rgbImageCache = null 332 + offsets = null 333 + cache = null 334 + buffer = null 335 + } 336 + 337 + @JvmStatic 338 + fun lookup(id: Int): ItemDefinition { 339 + for (i in 0 until 10) 340 + if (cache!![i]!!.id == id) return cache!![i]!! 341 + 342 + cacheIndex = (cacheIndex + 1) % 10 343 + val definition = cache!![cacheIndex]!! 344 + buffer!!.currentPosition = offsets!![id] 345 + definition.id = id 346 + definition.reset() 347 + definition.decode(buffer!!) 348 + if (definition.notedTemplateId != -1) 349 + definition.toNote() 350 + if (!memberServer && definition.members) { 351 + definition.name = "Members Object" 352 + definition.description = "Login to a members' server to use this object.".toByteArray() 353 + definition.groundActions = null 354 + definition.inventoryActions = null 355 + definition.team = 0 356 + } 357 + return definition 358 + } 359 + 360 + @JvmStatic 361 + fun load(archive: Archive) { 362 + buffer = Buffer(archive.getFile("obj.dat")!!) 363 + val idxBuffer = Buffer(archive.getFile("obj.idx")!!) 364 + count = idxBuffer.getUnsignedShortBE() 365 + offsets = IntArray(count) 366 + var index = 2 367 + for (i in 0 until count) { 368 + offsets!![i] = index 369 + index += idxBuffer.getUnsignedShortBE() 370 + } 371 + cache = Array(10) { ItemDefinition() } 372 + } 373 + 374 + @JvmStatic 375 + fun sprite(id: Int, stackSize: Int, backColour: Int): ImageRGB? { 376 + if (backColour == 0) { 377 + var sprite = rgbImageCache!!.get(id.toLong()) as ImageRGB? 378 + if (sprite != null && sprite.maxHeight != stackSize && sprite.maxHeight != -1) { 379 + sprite.remove() 380 + sprite = null 381 + } 382 + if (sprite != null) return sprite 383 + } 384 + var definition = lookup(id) 385 + var actualStackSize = stackSize 386 + if (definition.stackIds == null) 387 + actualStackSize = -1 388 + if (actualStackSize > 1) { 389 + var stackId = -1 390 + for (i in 0 until 10) 391 + if (actualStackSize >= definition.stackAmounts!![i] && definition.stackAmounts!![i] != 0) 392 + stackId = definition.stackIds!![i] 393 + if (stackId != -1) 394 + definition = lookup(stackId) 395 + } 396 + val model = definition.asGroundStack(1) ?: return null 397 + var notedSprite: ImageRGB? = null 398 + if (definition.notedTemplateId != -1) { 399 + notedSprite = sprite(definition.notedInfoId, 10, -1) ?: return null 400 + } 401 + val rendered = ImageRGB(32, 32) 402 + val centreX = Rasterizer3D.center_x 403 + val centerY = Rasterizer3D.center_y 404 + val lineOffsets = Rasterizer3D.lineOffsets 405 + val pixels = Rasterizer.pixels 406 + val width = Rasterizer.width 407 + val height = Rasterizer.height 408 + val topX = Rasterizer.topX 409 + val bottomX = Rasterizer.bottomX 410 + val topY = Rasterizer.topY 411 + val bottomY = Rasterizer.bottomY 412 + Rasterizer3D.notTextured = false 413 + Rasterizer.createRasterizer(rendered.pixels, 32, 32) 414 + Rasterizer.drawFilledRectangle(0, 0, 32, 32, 0) 415 + Rasterizer3D.setDefaultBounds() 416 + var scale = definition.modelScale 417 + if (backColour == -1) 418 + scale = (scale * 1.5).toInt() 419 + if (backColour > 0) 420 + scale = (scale * 1.04).toInt() 421 + val sin = Rasterizer3D.SINE[definition.modelRotationX] * scale shr 16 422 + val cos = Rasterizer3D.COSINE[definition.modelRotationX] * scale shr 16 423 + model.render( 424 + 0, definition.modelRotationY, definition.anInt339, definition.modelRotationX, 425 + definition.modelOffsetX, 426 + sin + (model as Renderable).modelHeight / 2 + definition.modelOffsetY, 427 + cos + definition.modelOffsetY 428 + ) 429 + for (x in 31 downTo 0) { 430 + for (y in 31 downTo 0) { 431 + if (rendered.pixels[x + y * 32] == 0) { 432 + if (x > 0 && rendered.pixels[(x - 1) + y * 32] > 1) 433 + rendered.pixels[x + y * 32] = 1 434 + else if (y > 0 && rendered.pixels[x + (y - 1) * 32] > 1) 435 + rendered.pixels[x + y * 32] = 1 436 + else if (x < 31 && rendered.pixels[x + 1 + y * 32] > 1) 437 + rendered.pixels[x + y * 32] = 1 438 + else if (y < 31 && rendered.pixels[x + (y + 1) * 32] > 1) 439 + rendered.pixels[x + y * 32] = 1 440 + } 441 + } 442 + } 443 + if (backColour > 0) { 444 + for (x in 31 downTo 0) { 445 + for (y in 31 downTo 0) { 446 + if (rendered.pixels[x + y * 32] == 0) { 447 + if (x > 0 && rendered.pixels[(x - 1) + y * 32] == 1) 448 + rendered.pixels[x + y * 32] = backColour 449 + else if (y > 0 && rendered.pixels[x + (y - 1) * 32] == 1) 450 + rendered.pixels[x + y * 32] = backColour 451 + else if (x < 31 && rendered.pixels[x + 1 + y * 32] == 1) 452 + rendered.pixels[x + y * 32] = backColour 453 + else if (y < 31 && rendered.pixels[x + (y + 1) * 32] == 1) 454 + rendered.pixels[x + y * 32] = backColour 455 + } 456 + } 457 + } 458 + } else if (backColour == 0) { 459 + for (x in 31 downTo 0) { 460 + for (y in 31 downTo 0) { 461 + if (rendered.pixels[x + y * 32] == 0 && x > 0 && y > 0 462 + && rendered.pixels[(x - 1) + (y - 1) * 32] > 0 463 + ) 464 + rendered.pixels[x + y * 32] = 0x302020 465 + } 466 + } 467 + } 468 + if (definition.notedTemplateId != -1) { 469 + val resizeWidth = notedSprite!!.maxWidth 470 + val resizeHeight = notedSprite.maxHeight 471 + notedSprite.maxWidth = 32 472 + notedSprite.maxHeight = 32 473 + notedSprite.drawImage(0, 0) 474 + notedSprite.maxWidth = resizeWidth 475 + notedSprite.maxHeight = resizeHeight 476 + } 477 + if (backColour == 0) 478 + rgbImageCache!!.put(rendered, id.toLong()) 479 + Rasterizer.createRasterizer(pixels, width, height) 480 + Rasterizer.setCoordinates(topY, topX, bottomY, bottomX) 481 + Rasterizer3D.center_x = centreX 482 + Rasterizer3D.center_y = centerY 483 + Rasterizer3D.lineOffsets = lineOffsets 484 + Rasterizer3D.notTextured = true 485 + rendered.maxWidth = if (definition.stackable) 33 else 32 486 + rendered.maxHeight = actualStackSize 487 + return rendered 488 + } 489 + } 490 + }
-138
src/main/java/com/jagex/runescape/cache/media/AnimationSequence.java
··· 1 - package com.jagex.runescape.cache.media; 2 - 3 - import com.jagex.runescape.cache.Archive; 4 - import com.jagex.runescape.net.Buffer; 5 - import com.jagex.runescape.media.Animation; 6 - 7 - public class AnimationSequence { 8 - 9 - public static int count; 10 - public static AnimationSequence animations[]; 11 - public int frameCount; 12 - public int getPrimaryFrame[]; 13 - public int frame1Ids[]; 14 - public int frameLenghts[]; 15 - public int frameStep = -1; 16 - public int flowControl[]; 17 - public boolean dynamic = false; 18 - public int anInt301 = 5; 19 - public int getPlayerShieldDelta = -1; 20 - public int getPlayerWeaponDelta = -1; 21 - public int resetCycle = 99; 22 - public int speedFlag = -1; 23 - public int priority = -1; 24 - public int anInt307 = 2; 25 - 26 - public static void load(Archive archive) { 27 - Buffer buffer = new Buffer(archive.getFile("seq.dat")); 28 - AnimationSequence.count = buffer.getUnsignedShortBE(); 29 - if (AnimationSequence.animations == null) 30 - AnimationSequence.animations = new AnimationSequence[AnimationSequence.count]; 31 - for (int animation = 0; animation < count; animation++) { 32 - if (AnimationSequence.animations[animation] == null) 33 - AnimationSequence.animations[animation] = new AnimationSequence(); 34 - AnimationSequence.animations[animation].loadDefinition(buffer); 35 - } 36 - } 37 - 38 - public int getFrameLength(int animationId) { 39 - int frameLength = frameLenghts[animationId]; 40 - if (frameLength == 0) { 41 - Animation animation = Animation.getAnimation(getPrimaryFrame[animationId]); 42 - if (animation != null) 43 - frameLength = frameLenghts[animationId] = animation.anInt431; 44 - } 45 - if (frameLength == 0) 46 - frameLength = 1; 47 - return frameLength; 48 - } 49 - 50 - public void loadDefinition(Buffer buf) { 51 - while (true) { 52 - int attributeId = buf.getUnsignedByte(); 53 - if (attributeId == 0) 54 - break; 55 - switch (attributeId) { 56 - case 1: 57 - frameCount = buf.getUnsignedByte(); 58 - getPrimaryFrame = new int[frameCount]; 59 - frame1Ids = new int[frameCount]; 60 - frameLenghts = new int[frameCount]; 61 - for (int frame = 0; frame < frameCount; frame++) { 62 - getPrimaryFrame[frame] = buf.getUnsignedShortBE(); 63 - frame1Ids[frame] = buf.getUnsignedShortBE(); 64 - if (frame1Ids[frame] == 65535) 65 - frame1Ids[frame] = -1; 66 - frameLenghts[frame] = buf.getUnsignedShortBE(); 67 - } 68 - 69 - break; 70 - case 2: 71 - frameStep = buf.getUnsignedShortBE(); 72 - break; 73 - case 3: 74 - int flowCount = buf.getUnsignedByte(); 75 - flowControl = new int[flowCount + 1]; 76 - for (int flow = 0; flow < flowCount; flow++) 77 - flowControl[flow] = buf.getUnsignedByte(); 78 - 79 - flowControl[flowCount] = 0x98967f; 80 - break; 81 - case 4: 82 - dynamic = true; 83 - break; 84 - case 5: 85 - anInt301 = buf.getUnsignedByte(); 86 - break; 87 - case 6: 88 - getPlayerShieldDelta = buf.getUnsignedShortBE(); 89 - break; 90 - case 7: 91 - getPlayerWeaponDelta = buf.getUnsignedShortBE(); 92 - break; 93 - case 8: 94 - resetCycle = buf.getUnsignedByte(); 95 - break; 96 - case 9: 97 - speedFlag = buf.getUnsignedByte(); 98 - break; 99 - case 10: 100 - priority = buf.getUnsignedByte(); 101 - break; 102 - case 11: 103 - anInt307 = buf.getUnsignedByte(); 104 - break; 105 - case 12: 106 - buf.getIntBE(); //dummy 107 - break; 108 - default: 109 - System.out.println("Error unrecognised seq config code: " + attributeId); 110 - break; 111 - } 112 - } 113 - if (frameCount == 0) { 114 - frameCount = 1; 115 - getPrimaryFrame = new int[1]; 116 - getPrimaryFrame[0] = -1; 117 - frame1Ids = new int[1]; 118 - frame1Ids[0] = -1; 119 - frameLenghts = new int[1]; 120 - frameLenghts[0] = -1; 121 - } 122 - if (speedFlag == -1) 123 - if (flowControl != null) 124 - speedFlag = 2; 125 - else 126 - speedFlag = 0; 127 - if (priority == -1) { 128 - if (flowControl != null) { 129 - priority = 2; 130 - return; 131 - } 132 - priority = 0; 133 - } 134 - } 135 - 136 - 137 - 138 - }
+104
src/main/java/com/jagex/runescape/cache/media/AnimationSequence.kt
··· 1 + package com.jagex.runescape.cache.media 2 + 3 + import com.jagex.runescape.cache.Archive 4 + import com.jagex.runescape.media.Animation 5 + import com.jagex.runescape.net.Buffer 6 + 7 + class AnimationSequence { 8 + 9 + @JvmField var frameCount: Int = 0 10 + @JvmField var getPrimaryFrame: IntArray? = null 11 + @JvmField var frame1Ids: IntArray? = null 12 + @JvmField var frameLenghts: IntArray? = null 13 + @JvmField var frameStep: Int = -1 14 + @JvmField var flowControl: IntArray? = null 15 + @JvmField var dynamic: Boolean = false 16 + @JvmField var anInt301: Int = 5 17 + @JvmField var getPlayerShieldDelta: Int = -1 18 + @JvmField var getPlayerWeaponDelta: Int = -1 19 + @JvmField var resetCycle: Int = 99 20 + @JvmField var speedFlag: Int = -1 21 + @JvmField var priority: Int = -1 22 + @JvmField var anInt307: Int = 2 23 + 24 + fun getFrameLength(animationId: Int): Int { 25 + var frameLength = frameLenghts!![animationId] 26 + if (frameLength == 0) { 27 + val animation = Animation.getAnimation(getPrimaryFrame!![animationId]) 28 + if (animation != null) 29 + frameLength = animation.anInt431 30 + frameLenghts!![animationId] = frameLength 31 + } 32 + if (frameLength == 0) 33 + frameLength = 1 34 + return frameLength 35 + } 36 + 37 + fun loadDefinition(buf: Buffer) { 38 + while (true) { 39 + val attributeId = buf.getUnsignedByte() 40 + if (attributeId == 0) break 41 + when (attributeId) { 42 + 1 -> { 43 + frameCount = buf.getUnsignedByte() 44 + getPrimaryFrame = IntArray(frameCount) 45 + frame1Ids = IntArray(frameCount) 46 + frameLenghts = IntArray(frameCount) 47 + for (frame in 0 until frameCount) { 48 + getPrimaryFrame!![frame] = buf.getUnsignedShortBE() 49 + frame1Ids!![frame] = buf.getUnsignedShortBE() 50 + if (frame1Ids!![frame] == 65535) 51 + frame1Ids!![frame] = -1 52 + frameLenghts!![frame] = buf.getUnsignedShortBE() 53 + } 54 + } 55 + 2 -> frameStep = buf.getUnsignedShortBE() 56 + 3 -> { 57 + val flowCount = buf.getUnsignedByte() 58 + flowControl = IntArray(flowCount + 1) 59 + for (flow in 0 until flowCount) 60 + flowControl!![flow] = buf.getUnsignedByte() 61 + flowControl!![flowCount] = 0x98967f 62 + } 63 + 4 -> dynamic = true 64 + 5 -> anInt301 = buf.getUnsignedByte() 65 + 6 -> getPlayerShieldDelta = buf.getUnsignedShortBE() 66 + 7 -> getPlayerWeaponDelta = buf.getUnsignedShortBE() 67 + 8 -> resetCycle = buf.getUnsignedByte() 68 + 9 -> speedFlag = buf.getUnsignedByte() 69 + 10 -> priority = buf.getUnsignedByte() 70 + 11 -> anInt307 = buf.getUnsignedByte() 71 + 12 -> buf.getIntBE() // dummy 72 + else -> println("Error unrecognised seq config code: $attributeId") 73 + } 74 + } 75 + if (frameCount == 0) { 76 + frameCount = 1 77 + getPrimaryFrame = intArrayOf(-1) 78 + frame1Ids = intArrayOf(-1) 79 + frameLenghts = intArrayOf(-1) 80 + } 81 + if (speedFlag == -1) 82 + speedFlag = if (flowControl != null) 2 else 0 83 + if (priority == -1) 84 + priority = if (flowControl != null) 2 else 0 85 + } 86 + 87 + companion object { 88 + @JvmField var count: Int = 0 89 + @JvmField var animations: Array<AnimationSequence?>? = null 90 + 91 + @JvmStatic 92 + fun load(archive: Archive) { 93 + val buffer = Buffer(archive.getFile("seq.dat")!!) 94 + count = buffer.getUnsignedShortBE() 95 + if (animations == null) 96 + animations = arrayOfNulls(count) 97 + for (animation in 0 until count) { 98 + if (animations!![animation] == null) 99 + animations!![animation] = AnimationSequence() 100 + animations!![animation]!!.loadDefinition(buffer) 101 + } 102 + } 103 + } 104 + }
-118
src/main/java/com/jagex/runescape/cache/media/IdentityKit.java
··· 1 - package com.jagex.runescape.cache.media; 2 - 3 - import com.jagex.runescape.cache.Archive; 4 - import com.jagex.runescape.net.Buffer; 5 - import com.jagex.runescape.media.renderable.Model; 6 - 7 - public class IdentityKit { 8 - 9 - public static int count; 10 - public static IdentityKit cache[]; 11 - public int partId = -1; 12 - public int modelId[]; 13 - public int originalModelColors[] = new int[6]; 14 - public int modifiedModelColors[] = new int[6]; 15 - public int headModelIds[] = { -1, -1, -1, -1, -1 }; 16 - public boolean widgetDisplayed = false; 17 - 18 - public static void load(Archive archive) { 19 - Buffer buffer = new Buffer(archive.getFile("idk.dat")); 20 - IdentityKit.count = buffer.getUnsignedShortBE(); 21 - if (IdentityKit.cache == null) 22 - IdentityKit.cache = new IdentityKit[IdentityKit.count]; 23 - for (int identityKit = 0; identityKit < count; identityKit++) { 24 - if (IdentityKit.cache[identityKit] == null) 25 - IdentityKit.cache[identityKit] = new IdentityKit(); 26 - IdentityKit.cache[identityKit].loadDefinition(buffer); 27 - } 28 - } 29 - 30 - public void loadDefinition(Buffer buffer) { 31 - while (true) { 32 - int attributeId = buffer.getUnsignedByte(); 33 - if (attributeId == 0) 34 - return; 35 - if (attributeId == 1) 36 - partId = buffer.getUnsignedByte(); 37 - else if (attributeId == 2) { 38 - int modelCount = buffer.getUnsignedByte(); 39 - modelId = new int[modelCount]; 40 - for (int model = 0; model < modelCount; model++) 41 - modelId[model] = buffer.getUnsignedShortBE(); 42 - } else if (attributeId == 3) 43 - widgetDisplayed = true; 44 - else if (attributeId >= 40 && attributeId < 50) 45 - originalModelColors[attributeId - 40] = buffer.getUnsignedShortBE(); 46 - else if (attributeId >= 50 && attributeId < 60) 47 - modifiedModelColors[attributeId - 50] = buffer.getUnsignedShortBE(); 48 - else if (attributeId >= 60 && attributeId < 70) 49 - headModelIds[attributeId - 60] = buffer.getUnsignedShortBE(); 50 - else 51 - System.out.println("Error unrecognised config code: " + attributeId); 52 - } 53 - } 54 - 55 - public boolean isBodyModelCached() { 56 - if (modelId == null) 57 - return true; 58 - 59 - boolean isCached = true; 60 - for (int i = 0; i < modelId.length; i++) 61 - if (!Model.loaded(modelId[i])) 62 - isCached = false; 63 - 64 - return isCached; 65 - } 66 - 67 - public Model getBodyModel() { 68 - if (modelId == null) 69 - return null; 70 - 71 - Model models[] = new Model[modelId.length]; 72 - for (int model = 0; model < modelId.length; model++) 73 - models[model] = Model.getModel(modelId[model]); 74 - 75 - Model model; 76 - if (models.length == 1) 77 - model = models[0]; 78 - else 79 - model = new Model(models.length, models); 80 - 81 - for (int color = 0; color < 6; color++) { 82 - if (originalModelColors[color] == 0) 83 - break; 84 - model.replaceColor(originalModelColors[color], modifiedModelColors[color]); 85 - } 86 - 87 - return model; 88 - } 89 - 90 - public boolean isHeadModelCached() { 91 - boolean cached = true; 92 - for (int model = 0; model < 5; model++) 93 - if (headModelIds[model] != -1 && !Model.loaded(headModelIds[model])) 94 - cached = false; 95 - 96 - return cached; 97 - } 98 - 99 - public Model getHeadModel() { 100 - Model[] models = new Model[5]; 101 - 102 - int count = 0; 103 - for (int model = 0; model < 5; model++) 104 - if (headModelIds[model] != -1) 105 - models[count++] = Model.getModel(headModelIds[model]); 106 - 107 - Model model = new Model(count, models); 108 - for (int color = 0; color < 6; color++) { 109 - if (originalModelColors[color] == 0) 110 - break; 111 - model.replaceColor(originalModelColors[color], modifiedModelColors[color]); 112 - } 113 - 114 - return model; 115 - } 116 - 117 - 118 - }
+93
src/main/java/com/jagex/runescape/cache/media/IdentityKit.kt
··· 1 + package com.jagex.runescape.cache.media 2 + 3 + import com.jagex.runescape.cache.Archive 4 + import com.jagex.runescape.media.renderable.Model 5 + import com.jagex.runescape.net.Buffer 6 + 7 + class IdentityKit { 8 + 9 + @JvmField var partId: Int = -1 10 + @JvmField var modelId: IntArray? = null 11 + @JvmField var originalModelColors: IntArray = IntArray(6) 12 + @JvmField var modifiedModelColors: IntArray = IntArray(6) 13 + @JvmField var headModelIds: IntArray = intArrayOf(-1, -1, -1, -1, -1) 14 + @JvmField var widgetDisplayed: Boolean = false 15 + 16 + fun loadDefinition(buffer: Buffer) { 17 + while (true) { 18 + val attributeId = buffer.getUnsignedByte() 19 + if (attributeId == 0) return 20 + when { 21 + attributeId == 1 -> partId = buffer.getUnsignedByte() 22 + attributeId == 2 -> { 23 + val modelCount = buffer.getUnsignedByte() 24 + modelId = IntArray(modelCount) { buffer.getUnsignedShortBE() } 25 + } 26 + attributeId == 3 -> widgetDisplayed = true 27 + attributeId in 40..49 -> originalModelColors[attributeId - 40] = buffer.getUnsignedShortBE() 28 + attributeId in 50..59 -> modifiedModelColors[attributeId - 50] = buffer.getUnsignedShortBE() 29 + attributeId in 60..69 -> headModelIds[attributeId - 60] = buffer.getUnsignedShortBE() 30 + else -> println("Error unrecognised config code: $attributeId") 31 + } 32 + } 33 + } 34 + 35 + fun isBodyModelCached(): Boolean { 36 + if (modelId == null) return true 37 + var isCached = true 38 + for (i in modelId!!.indices) 39 + if (!Model.loaded(modelId!![i])) isCached = false 40 + return isCached 41 + } 42 + 43 + fun getBodyModel(): Model? { 44 + if (modelId == null) return null 45 + val models = Array(modelId!!.size) { Model.getModel(modelId!![it]) } 46 + val model = if (models.size == 1) models[0] else Model(models.size, models) 47 + for (color in 0 until 6) { 48 + if (originalModelColors[color] == 0) break 49 + model.replaceColor(originalModelColors[color], modifiedModelColors[color]) 50 + } 51 + return model 52 + } 53 + 54 + fun isHeadModelCached(): Boolean { 55 + var cached = true 56 + for (model in 0 until 5) 57 + if (headModelIds[model] != -1 && !Model.loaded(headModelIds[model])) 58 + cached = false 59 + return cached 60 + } 61 + 62 + fun getHeadModel(): Model { 63 + val models = arrayOfNulls<Model>(5) 64 + var count = 0 65 + for (model in 0 until 5) 66 + if (headModelIds[model] != -1) 67 + models[count++] = Model.getModel(headModelIds[model]) 68 + val model = Model(count, models) 69 + for (color in 0 until 6) { 70 + if (originalModelColors[color] == 0) break 71 + model.replaceColor(originalModelColors[color], modifiedModelColors[color]) 72 + } 73 + return model 74 + } 75 + 76 + companion object { 77 + @JvmField var count: Int = 0 78 + @JvmField var cache: Array<IdentityKit?>? = null 79 + 80 + @JvmStatic 81 + fun load(archive: Archive) { 82 + val buffer = Buffer(archive.getFile("idk.dat")!!) 83 + count = buffer.getUnsignedShortBE() 84 + if (cache == null) 85 + cache = arrayOfNulls(count) 86 + for (identityKit in 0 until count) { 87 + if (cache!![identityKit] == null) 88 + cache!![identityKit] = IdentityKit() 89 + cache!![identityKit]!!.loadDefinition(buffer) 90 + } 91 + } 92 + } 93 + }
-491
src/main/java/com/jagex/runescape/cache/media/ImageRGB.java
··· 1 - package com.jagex.runescape.cache.media; 2 - 3 - import com.jagex.runescape.cache.Archive; 4 - import com.jagex.runescape.media.Rasterizer; 5 - import com.jagex.runescape.net.Buffer; 6 - 7 - import java.awt.Component; 8 - import java.awt.Image; 9 - import java.awt.MediaTracker; 10 - import java.awt.Toolkit; 11 - import java.awt.image.PixelGrabber; 12 - 13 - public class ImageRGB extends Rasterizer { 14 - 15 - 16 - public int[] pixels; 17 - public int width; 18 - public int height; 19 - public int offsetX; 20 - public int offsetY; 21 - public int maxWidth; 22 - public int maxHeight; 23 - 24 - public ImageRGB(int width, int height) { 25 - pixels = new int[width * height]; 26 - this.width = maxWidth = width; 27 - this.height = maxHeight = height; 28 - offsetX = offsetY = 0; 29 - } 30 - 31 - public ImageRGB(byte[] imagedata, Component component) { 32 - try { 33 - Image image = Toolkit.getDefaultToolkit().createImage(imagedata); 34 - MediaTracker mediatracker = new MediaTracker(component); 35 - mediatracker.addImage(image, 0); 36 - mediatracker.waitForAll(); 37 - width = image.getWidth(component); 38 - height = image.getHeight(component); 39 - maxWidth = width; 40 - maxHeight = height; 41 - offsetX = 0; 42 - offsetY = 0; 43 - pixels = new int[width * height]; 44 - PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, width, height, pixels, 0, 45 - width); 46 - pixelgrabber.grabPixels(); 47 - return; 48 - } catch (Exception _ex) { 49 - System.out.println("Error converting jpg"); 50 - } 51 - } 52 - 53 - public ImageRGB(Archive archive, String archiveName, int archiveIndex) { 54 - Buffer dataBuffer = new Buffer(archive.getFile(archiveName + ".dat")); 55 - Buffer indexBuffer = new Buffer(archive.getFile("index.dat")); 56 - indexBuffer.currentPosition = dataBuffer.getUnsignedShortBE(); 57 - maxWidth = indexBuffer.getUnsignedShortBE(); 58 - maxHeight = indexBuffer.getUnsignedShortBE(); 59 - int length = indexBuffer.getUnsignedByte(); 60 - int[] pixels = new int[length]; 61 - for (int pixel = 0; pixel < length - 1; pixel++) { 62 - pixels[pixel + 1] = indexBuffer.getMediumBE(); 63 - if (pixels[pixel + 1] == 0) 64 - pixels[pixel + 1] = 1; 65 - } 66 - 67 - for (int index = 0; index < archiveIndex; index++) { 68 - indexBuffer.currentPosition += 2; 69 - dataBuffer.currentPosition += indexBuffer.getUnsignedShortBE() * indexBuffer.getUnsignedShortBE(); 70 - indexBuffer.currentPosition++; 71 - } 72 - 73 - offsetX = indexBuffer.getUnsignedByte(); 74 - offsetY = indexBuffer.getUnsignedByte(); 75 - width = indexBuffer.getUnsignedShortBE(); 76 - height = indexBuffer.getUnsignedShortBE(); 77 - int type = indexBuffer.getUnsignedByte(); 78 - int pixelCount = width * height; 79 - this.pixels = new int[pixelCount]; 80 - if (type == 0) { 81 - for (int pixel = 0; pixel < pixelCount; pixel++) 82 - this.pixels[pixel] = pixels[dataBuffer.getUnsignedByte()]; 83 - 84 - return; 85 - } 86 - if (type == 1) { 87 - for (int x = 0; x < width; x++) { 88 - for (int y = 0; y < height; y++) 89 - this.pixels[x + y * width] = pixels[dataBuffer.getUnsignedByte()]; 90 - 91 - } 92 - 93 - } 94 - } 95 - 96 - public void createRasterizer() { 97 - Rasterizer.createRasterizer(pixels, width, height); 98 - } 99 - 100 - public void adjustRGB(int redOffset, int greenOffset, int blueOffset) { 101 - for (int pixel = 0; pixel < pixels.length; pixel++) { 102 - int originalColor = pixels[pixel]; 103 - if (originalColor != 0) { 104 - int red = originalColor >> 16 & 0xff; 105 - red += redOffset; 106 - if (red < 1) 107 - red = 1; 108 - else if (red > 255) 109 - red = 255; 110 - int green = originalColor >> 8 & 0xff; 111 - green += greenOffset; 112 - if (green < 1) 113 - green = 1; 114 - else if (green > 255) 115 - green = 255; 116 - int blue = originalColor & 0xff; 117 - blue += blueOffset; 118 - if (blue < 1) 119 - blue = 1; 120 - else if (blue > 255) 121 - blue = 255; 122 - pixels[pixel] = (red << 16) + (green << 8) + blue; 123 - } 124 - } 125 - 126 - 127 - } 128 - 129 - public void trim() { 130 - int[] newPixels = new int[maxWidth * maxHeight]; 131 - for (int y = 0; y < height; y++) { 132 - for (int x = 0; x < width; x++) 133 - newPixels[(y + offsetY) * maxWidth + (x + offsetX)] = pixels[y * width + x]; 134 - 135 - } 136 - 137 - pixels = newPixels; 138 - width = maxWidth; 139 - height = maxHeight; 140 - offsetX = 0; 141 - offsetY = 0; 142 - } 143 - 144 - public void drawInverse(int x, int y) { 145 - x += offsetX; 146 - y += offsetY; 147 - int rasterizerPixel = x + y * Rasterizer.width; 148 - int pixel = 0; 149 - int newHeight = height; 150 - int newWidth = width; 151 - int rasterizerPixelOffset = Rasterizer.width - newWidth; 152 - int pixelOffset = 0; 153 - if (y < Rasterizer.topY) { 154 - int yOffset = Rasterizer.topY - y; 155 - newHeight -= yOffset; 156 - y = Rasterizer.topY; 157 - pixel += yOffset * newWidth; 158 - rasterizerPixel += yOffset * Rasterizer.width; 159 - } 160 - if (y + newHeight > Rasterizer.bottomY) 161 - newHeight -= (y + newHeight) - Rasterizer.bottomY; 162 - if (x < Rasterizer.topX) { 163 - int xOffset = Rasterizer.topX - x; 164 - newWidth -= xOffset; 165 - x = Rasterizer.topX; 166 - pixel += xOffset; 167 - rasterizerPixel += xOffset; 168 - pixelOffset += xOffset; 169 - rasterizerPixelOffset += xOffset; 170 - } 171 - if (x + newWidth > Rasterizer.bottomX) { 172 - int widthOffset = (x + newWidth) - Rasterizer.bottomX; 173 - newWidth -= widthOffset; 174 - pixelOffset += widthOffset; 175 - rasterizerPixelOffset += widthOffset; 176 - } 177 - if (newWidth <= 0 || newHeight <= 0) 178 - return; 179 - copyPixels(pixels, Rasterizer.pixels, pixel, rasterizerPixel, pixelOffset, rasterizerPixelOffset, newWidth, newHeight); 180 - } 181 - 182 - public void copyPixels(int[] pixels, int[] rasterizerPixels, int pixel, int rasterizerPixel, int pixelOffset, int rasterizerPixelOffset, int width, int height) { 183 - int shiftedWidth = -(width >> 2); 184 - width = -(width & 3); 185 - for (int heightCounter = -height; heightCounter < 0; heightCounter++) { 186 - for (int widthCounter = shiftedWidth; widthCounter < 0; widthCounter++) { 187 - rasterizerPixels[rasterizerPixel++] = pixels[pixel++]; 188 - rasterizerPixels[rasterizerPixel++] = pixels[pixel++]; 189 - rasterizerPixels[rasterizerPixel++] = pixels[pixel++]; 190 - rasterizerPixels[rasterizerPixel++] = pixels[pixel++]; 191 - } 192 - 193 - for (int widthCounter = width; widthCounter < 0; widthCounter++) 194 - rasterizerPixels[rasterizerPixel++] = pixels[pixel++]; 195 - 196 - rasterizerPixel += rasterizerPixelOffset; 197 - pixel += pixelOffset; 198 - } 199 - 200 - } 201 - 202 - public void drawImage(int x, int y) { 203 - x += offsetX; 204 - y += offsetY; 205 - int rasterizerOffset = x + y * Rasterizer.width; 206 - int pixelOffset = 0; 207 - int imageHeight = height; 208 - int imageWidth = width; 209 - int deviation = Rasterizer.width - imageWidth; 210 - int originalDeviation = 0; 211 - if (y < Rasterizer.topY) { 212 - int yOffset = Rasterizer.topY - y; 213 - imageHeight -= yOffset; 214 - y = Rasterizer.topY; 215 - pixelOffset += yOffset * imageWidth; 216 - rasterizerOffset += yOffset * Rasterizer.width; 217 - } 218 - if (y + imageHeight > Rasterizer.bottomY) 219 - imageHeight -= (y + imageHeight) - Rasterizer.bottomY; 220 - if (x < Rasterizer.topX) { 221 - int xOffset = Rasterizer.topX - x; 222 - imageWidth -= xOffset; 223 - x = Rasterizer.topX; 224 - pixelOffset += xOffset; 225 - rasterizerOffset += xOffset; 226 - originalDeviation += xOffset; 227 - deviation += xOffset; 228 - } 229 - if (x + imageWidth > Rasterizer.bottomX) { 230 - int xOffset = (x + imageWidth) - Rasterizer.bottomX; 231 - imageWidth -= xOffset; 232 - originalDeviation += xOffset; 233 - deviation += xOffset; 234 - } 235 - if (imageWidth <= 0 || imageHeight <= 0) { 236 - return; 237 - } else { 238 - shapeImageToPixels(pixels, Rasterizer.pixels, pixelOffset, rasterizerOffset, imageWidth, imageHeight, originalDeviation, deviation, 0); 239 - return; 240 - } 241 - } 242 - 243 - public void shapeImageToPixels(int[] pixels, int[] rasterizerPixels, int pixel, int rasterizerPixel, int width, int height, int pixelOffset, int rasterizerPixelOffset, int pixelColor) { 244 - int shiftedWidth = -(width >> 2); 245 - width = -(width & 3); 246 - for (int heightCounter = -height; heightCounter < 0; heightCounter++) { 247 - for (int widthCounter = shiftedWidth; widthCounter < 0; widthCounter++) { 248 - pixelColor = pixels[pixel++]; 249 - if (pixelColor != 0) 250 - rasterizerPixels[rasterizerPixel++] = pixelColor; 251 - else 252 - rasterizerPixel++; 253 - pixelColor = pixels[pixel++]; 254 - if (pixelColor != 0) 255 - rasterizerPixels[rasterizerPixel++] = pixelColor; 256 - else 257 - rasterizerPixel++; 258 - pixelColor = pixels[pixel++]; 259 - if (pixelColor != 0) 260 - rasterizerPixels[rasterizerPixel++] = pixelColor; 261 - else 262 - rasterizerPixel++; 263 - pixelColor = pixels[pixel++]; 264 - if (pixelColor != 0) 265 - rasterizerPixels[rasterizerPixel++] = pixelColor; 266 - else 267 - rasterizerPixel++; 268 - } 269 - 270 - for (int widthCounter = width; widthCounter < 0; widthCounter++) { 271 - pixelColor = pixels[pixel++]; 272 - if (pixelColor != 0) 273 - rasterizerPixels[rasterizerPixel++] = pixelColor; 274 - else 275 - rasterizerPixel++; 276 - } 277 - 278 - rasterizerPixel += rasterizerPixelOffset; 279 - pixel += pixelOffset; 280 - } 281 - 282 - } 283 - 284 - public void drawImageAlpha(int x, int y, int alpha) { 285 - x += offsetX; 286 - y += offsetY; 287 - int rasterizerPixel = x + y * Rasterizer.width; 288 - int pixel = 0; 289 - int newHeight = height; 290 - int newWidth = width; 291 - int rasterizerPixelOffset = Rasterizer.width - newWidth; 292 - int pixelOffset = 0; 293 - if (y < Rasterizer.topY) { 294 - int yOffset = Rasterizer.topY - y; 295 - newHeight -= yOffset; 296 - y = Rasterizer.topY; 297 - pixel += yOffset * newWidth; 298 - rasterizerPixel += yOffset * Rasterizer.width; 299 - } 300 - if (y + newHeight > Rasterizer.bottomY) 301 - newHeight -= (y + newHeight) - Rasterizer.bottomY; 302 - if (x < Rasterizer.topX) { 303 - int xOffset = Rasterizer.topX - x; 304 - newWidth -= xOffset; 305 - x = Rasterizer.topX; 306 - pixel += xOffset; 307 - rasterizerPixel += xOffset; 308 - pixelOffset += xOffset; 309 - rasterizerPixelOffset += xOffset; 310 - } 311 - if (x + newWidth > Rasterizer.bottomX) { 312 - int xOffset = (x + newWidth) - Rasterizer.bottomX; 313 - newWidth -= xOffset; 314 - pixelOffset += xOffset; 315 - rasterizerPixelOffset += xOffset; 316 - } 317 - if (newWidth > 0 && newHeight > 0) { 318 - copyPixelsAlpha(pixels, Rasterizer.pixels, pixel, rasterizerPixel, pixelOffset, rasterizerPixelOffset, newWidth, newHeight, 0, alpha); 319 - } 320 - } 321 - 322 - public void copyPixelsAlpha(int[] pixels, int[] rasterizerPixels, int pixel, int rasterizerPixel, int pixelOffset, int rasterizerPixelOffset, int width, int height, int color, int alpha) { 323 - int alphaValue = 256 - alpha; 324 - for (int heightCounter = -height; heightCounter < 0; heightCounter++) { 325 - for (int widthCounter = -width; widthCounter < 0; widthCounter++) { 326 - color = pixels[pixel++]; 327 - if (color != 0) { 328 - int rasterizerPixelColor = rasterizerPixels[rasterizerPixel]; 329 - rasterizerPixels[rasterizerPixel++] = ((color & 0xff00ff) * alpha + (rasterizerPixelColor & 0xff00ff) * alphaValue & 0xff00ff00) 330 - + ((color & 0xff00) * alpha + (rasterizerPixelColor & 0xff00) * alphaValue & 0xff0000) >> 8; 331 - } else { 332 - rasterizerPixel++; 333 - } 334 - } 335 - 336 - rasterizerPixel += rasterizerPixelOffset; 337 - pixel += pixelOffset; 338 - } 339 - 340 - } 341 - 342 - public void shapeImageToPixels(int x, int y, int width, int height, int zoom, int l, int[] ai, int k1, int[] ai1, int i2) { 343 - try { 344 - int centerX = -width / 2; 345 - int centerY = -height / 2; 346 - int sine = (int) (Math.sin(k1 / 326.11000000000001D) * 65536D); 347 - int cosine = (int) (Math.cos(k1 / 326.11000000000001D) * 65536D); 348 - sine = sine * zoom >> 8; 349 - cosine = cosine * zoom >> 8; 350 - int sourceOffsetX = (l << 16) + (centerY * sine + centerX * cosine); 351 - int sourceOffsetY = (i2 << 16) + (centerY * cosine - centerX * sine); 352 - int destinationOffset = x + y * Rasterizer.width; 353 - for (y = 0; y < height; y++) { 354 - int i4 = ai1[y]; 355 - int j4 = destinationOffset + i4; 356 - int k4 = sourceOffsetX + cosine * i4; 357 - int l4 = sourceOffsetY - sine * i4; 358 - for (x = -ai[y]; x < 0; x++) { 359 - Rasterizer.pixels[j4++] = pixels[(k4 >> 16) + (l4 >> 16) * this.width]; 360 - k4 += cosine; 361 - l4 -= sine; 362 - } 363 - 364 - sourceOffsetX += sine; 365 - sourceOffsetY += cosine; 366 - destinationOffset += Rasterizer.width; 367 - } 368 - 369 - } catch (Exception _ex) { 370 - } 371 - } 372 - 373 - public void drawRotated(int x, int y, int pivotX, int pivotY, int width, int height, int zoom, double angle) { 374 - try { 375 - int centerX = -width / 2; 376 - int centerY = -height / 2; 377 - int sine = (int) (Math.sin(angle) * 65536D); 378 - int cosine = (int) (Math.cos(angle) * 65536D); 379 - sine = sine * zoom >> 8; 380 - cosine = cosine * zoom >> 8; 381 - int sourceOffsetX = (pivotX << 16) + (centerY * sine + centerX * cosine); 382 - int sourceOffsetY = (pivotY << 16) + (centerY * cosine - centerX * sine); 383 - int destinationOffset = x + y * Rasterizer.width; 384 - for (y = 0; y < height; y++) { 385 - int i = destinationOffset; 386 - int offsetX = sourceOffsetX; 387 - int offsetY = sourceOffsetY; 388 - for (x = -width; x < 0; x++) { 389 - int colour = pixels[(offsetX >> 16) + (offsetY >> 16) * this.width]; 390 - if (colour != 0) 391 - Rasterizer.pixels[i++] = colour; 392 - else 393 - i++; 394 - offsetX += cosine; 395 - offsetY -= sine; 396 - } 397 - 398 - sourceOffsetX += sine; 399 - sourceOffsetY += cosine; 400 - destinationOffset += Rasterizer.width; 401 - } 402 - 403 - } catch (Exception _ex) { 404 - } 405 - } 406 - 407 - public void drawTo(IndexedImage indexedImage, int x, int y) { 408 - x += offsetX; 409 - y += offsetY; 410 - int l = x + y * Rasterizer.width; 411 - int i1 = 0; 412 - int j1 = height; 413 - int k1 = width; 414 - int l1 = Rasterizer.width - k1; 415 - int i2 = 0; 416 - if (y < Rasterizer.topY) { 417 - int j2 = Rasterizer.topY - y; 418 - j1 -= j2; 419 - y = Rasterizer.topY; 420 - i1 += j2 * k1; 421 - l += j2 * Rasterizer.width; 422 - } 423 - if (y + j1 > Rasterizer.bottomY) 424 - j1 -= (y + j1) - Rasterizer.bottomY; 425 - if (x < Rasterizer.topX) { 426 - int k2 = Rasterizer.topX - x; 427 - k1 -= k2; 428 - x = Rasterizer.topX; 429 - i1 += k2; 430 - l += k2; 431 - i2 += k2; 432 - l1 += k2; 433 - } 434 - if (x + k1 > Rasterizer.bottomX) { 435 - int l2 = (x + k1) - Rasterizer.bottomX; 436 - k1 -= l2; 437 - i2 += l2; 438 - l1 += l2; 439 - } 440 - if (k1 <= 0 || j1 <= 0) { 441 - return; 442 - } else { 443 - method468(l, l1, pixels, k1, Rasterizer.pixels, 444 - indexedImage.imgPixels, 40303, j1, i1, 0, i2); 445 - return; 446 - } 447 - } 448 - 449 - public void method468(int i, int j, int ai[], int k, int ai1[], byte abyte0[], int l, int i1, int j1, int k1, int l1) { 450 - int i2 = -(k >> 2); 451 - k = -(k & 3); 452 - for (int j2 = -i1; j2 < 0; j2++) { 453 - for (int k2 = i2; k2 < 0; k2++) { 454 - k1 = ai[j1++]; 455 - if (k1 != 0 && abyte0[i] == 0) 456 - ai1[i++] = k1; 457 - else 458 - i++; 459 - k1 = ai[j1++]; 460 - if (k1 != 0 && abyte0[i] == 0) 461 - ai1[i++] = k1; 462 - else 463 - i++; 464 - k1 = ai[j1++]; 465 - if (k1 != 0 && abyte0[i] == 0) 466 - ai1[i++] = k1; 467 - else 468 - i++; 469 - k1 = ai[j1++]; 470 - if (k1 != 0 && abyte0[i] == 0) 471 - ai1[i++] = k1; 472 - else 473 - i++; 474 - } 475 - 476 - for (int l2 = k; l2 < 0; l2++) { 477 - k1 = ai[j1++]; 478 - if (k1 != 0 && abyte0[i] == 0) 479 - ai1[i++] = k1; 480 - else 481 - i++; 482 - } 483 - 484 - i += j; 485 - j1 += l1; 486 - } 487 - 488 - } 489 - 490 - 491 - }
+443
src/main/java/com/jagex/runescape/cache/media/ImageRGB.kt
··· 1 + package com.jagex.runescape.cache.media 2 + 3 + import com.jagex.runescape.cache.Archive 4 + import com.jagex.runescape.media.Rasterizer 5 + import com.jagex.runescape.media.renderable.Renderable 6 + import com.jagex.runescape.net.Buffer 7 + import java.awt.Component 8 + import java.awt.MediaTracker 9 + import java.awt.Toolkit 10 + import java.awt.image.PixelGrabber 11 + 12 + class ImageRGB : Rasterizer { 13 + 14 + @JvmField var pixels: IntArray 15 + @JvmField var width: Int 16 + @JvmField var height: Int 17 + @JvmField var offsetX: Int 18 + @JvmField var offsetY: Int 19 + @JvmField var maxWidth: Int 20 + @JvmField var maxHeight: Int 21 + 22 + constructor(width: Int, height: Int) { 23 + pixels = IntArray(width * height) 24 + this.width = width 25 + this.height = height 26 + maxWidth = width 27 + maxHeight = height 28 + offsetX = 0 29 + offsetY = 0 30 + } 31 + 32 + constructor(imagedata: ByteArray, component: Component) { 33 + try { 34 + val image = Toolkit.getDefaultToolkit().createImage(imagedata) 35 + val mediatracker = MediaTracker(component) 36 + mediatracker.addImage(image, 0) 37 + mediatracker.waitForAll() 38 + width = image.getWidth(component) 39 + height = image.getHeight(component) 40 + maxWidth = width 41 + maxHeight = height 42 + offsetX = 0 43 + offsetY = 0 44 + pixels = IntArray(width * height) 45 + val pixelgrabber = PixelGrabber(image, 0, 0, width, height, pixels, 0, width) 46 + pixelgrabber.grabPixels() 47 + } catch (_: Exception) { 48 + println("Error converting jpg") 49 + // Fallback init for fields 50 + pixels = IntArray(0) 51 + width = 0 52 + height = 0 53 + maxWidth = 0 54 + maxHeight = 0 55 + offsetX = 0 56 + offsetY = 0 57 + } 58 + } 59 + 60 + constructor(archive: Archive, archiveName: String, archiveIndex: Int) { 61 + val dataBuffer = Buffer(archive.getFile("$archiveName.dat")!!) 62 + val indexBuffer = Buffer(archive.getFile("index.dat")!!) 63 + indexBuffer.currentPosition = dataBuffer.getUnsignedShortBE() 64 + maxWidth = indexBuffer.getUnsignedShortBE() 65 + maxHeight = indexBuffer.getUnsignedShortBE() 66 + val length = indexBuffer.getUnsignedByte() 67 + val palettePixels = IntArray(length) 68 + for (pixel in 0 until length - 1) { 69 + palettePixels[pixel + 1] = indexBuffer.getMediumBE() 70 + if (palettePixels[pixel + 1] == 0) 71 + palettePixels[pixel + 1] = 1 72 + } 73 + 74 + for (index in 0 until archiveIndex) { 75 + indexBuffer.currentPosition += 2 76 + dataBuffer.currentPosition += indexBuffer.getUnsignedShortBE() * indexBuffer.getUnsignedShortBE() 77 + indexBuffer.currentPosition++ 78 + } 79 + 80 + offsetX = indexBuffer.getUnsignedByte() 81 + offsetY = indexBuffer.getUnsignedByte() 82 + width = indexBuffer.getUnsignedShortBE() 83 + height = indexBuffer.getUnsignedShortBE() 84 + val type = indexBuffer.getUnsignedByte() 85 + val pixelCount = width * height 86 + pixels = IntArray(pixelCount) 87 + if (type == 0) { 88 + for (pixel in 0 until pixelCount) 89 + pixels[pixel] = palettePixels[dataBuffer.getUnsignedByte()] 90 + } else if (type == 1) { 91 + for (x in 0 until width) 92 + for (y in 0 until height) 93 + pixels[x + y * width] = palettePixels[dataBuffer.getUnsignedByte()] 94 + } 95 + } 96 + 97 + fun createRasterizer() { 98 + Rasterizer.createRasterizer(pixels, width, height) 99 + } 100 + 101 + fun adjustRGB(redOffset: Int, greenOffset: Int, blueOffset: Int) { 102 + for (pixel in pixels.indices) { 103 + val originalColor = pixels[pixel] 104 + if (originalColor != 0) { 105 + var red = originalColor shr 16 and 0xff 106 + red += redOffset 107 + if (red < 1) red = 1 else if (red > 255) red = 255 108 + var green = originalColor shr 8 and 0xff 109 + green += greenOffset 110 + if (green < 1) green = 1 else if (green > 255) green = 255 111 + var blue = originalColor and 0xff 112 + blue += blueOffset 113 + if (blue < 1) blue = 1 else if (blue > 255) blue = 255 114 + pixels[pixel] = (red shl 16) + (green shl 8) + blue 115 + } 116 + } 117 + } 118 + 119 + fun trim() { 120 + val newPixels = IntArray(maxWidth * maxHeight) 121 + for (y in 0 until height) 122 + for (x in 0 until width) 123 + newPixels[(y + offsetY) * maxWidth + (x + offsetX)] = pixels[y * width + x] 124 + pixels = newPixels 125 + width = maxWidth 126 + height = maxHeight 127 + offsetX = 0 128 + offsetY = 0 129 + } 130 + 131 + fun drawInverse(x: Int, y: Int) { 132 + var drawX = x + offsetX 133 + var drawY = y + offsetY 134 + var rasterizerPixel = drawX + drawY * Rasterizer.width 135 + var pixel = 0 136 + var newHeight = height 137 + var newWidth = width 138 + var rasterizerPixelOffset = Rasterizer.width - newWidth 139 + var pixelOffset = 0 140 + if (drawY < Rasterizer.topY) { 141 + val yOffset = Rasterizer.topY - drawY 142 + newHeight -= yOffset 143 + drawY = Rasterizer.topY 144 + pixel += yOffset * newWidth 145 + rasterizerPixel += yOffset * Rasterizer.width 146 + } 147 + if (drawY + newHeight > Rasterizer.bottomY) 148 + newHeight -= (drawY + newHeight) - Rasterizer.bottomY 149 + if (drawX < Rasterizer.topX) { 150 + val xOffset = Rasterizer.topX - drawX 151 + newWidth -= xOffset 152 + drawX = Rasterizer.topX 153 + pixel += xOffset 154 + rasterizerPixel += xOffset 155 + pixelOffset += xOffset 156 + rasterizerPixelOffset += xOffset 157 + } 158 + if (drawX + newWidth > Rasterizer.bottomX) { 159 + val widthOffset = (drawX + newWidth) - Rasterizer.bottomX 160 + newWidth -= widthOffset 161 + pixelOffset += widthOffset 162 + rasterizerPixelOffset += widthOffset 163 + } 164 + if (newWidth <= 0 || newHeight <= 0) return 165 + copyPixels(pixels, Rasterizer.pixels, pixel, rasterizerPixel, pixelOffset, rasterizerPixelOffset, newWidth, newHeight) 166 + } 167 + 168 + fun copyPixels( 169 + pixels: IntArray, rasterizerPixels: IntArray, pixel: Int, rasterizerPixel: Int, 170 + pixelOffset: Int, rasterizerPixelOffset: Int, width: Int, height: Int 171 + ) { 172 + val shiftedWidth = -(width shr 2) 173 + val remainingWidth = -(width and 3) 174 + var rPixel = rasterizerPixel 175 + var pPixel = pixel 176 + for (heightCounter in -height until 0) { 177 + for (widthCounter in shiftedWidth until 0) { 178 + rasterizerPixels[rPixel++] = pixels[pPixel++] 179 + rasterizerPixels[rPixel++] = pixels[pPixel++] 180 + rasterizerPixels[rPixel++] = pixels[pPixel++] 181 + rasterizerPixels[rPixel++] = pixels[pPixel++] 182 + } 183 + for (widthCounter in remainingWidth until 0) 184 + rasterizerPixels[rPixel++] = pixels[pPixel++] 185 + rPixel += rasterizerPixelOffset 186 + pPixel += pixelOffset 187 + } 188 + } 189 + 190 + fun drawImage(x: Int, y: Int) { 191 + var drawX = x + offsetX 192 + var drawY = y + offsetY 193 + var rasterizerOffset = drawX + drawY * Rasterizer.width 194 + var pixelOffset = 0 195 + var imageHeight = height 196 + var imageWidth = width 197 + var deviation = Rasterizer.width - imageWidth 198 + var originalDeviation = 0 199 + if (drawY < Rasterizer.topY) { 200 + val yOffset = Rasterizer.topY - drawY 201 + imageHeight -= yOffset 202 + drawY = Rasterizer.topY 203 + pixelOffset += yOffset * imageWidth 204 + rasterizerOffset += yOffset * Rasterizer.width 205 + } 206 + if (drawY + imageHeight > Rasterizer.bottomY) 207 + imageHeight -= (drawY + imageHeight) - Rasterizer.bottomY 208 + if (drawX < Rasterizer.topX) { 209 + val xOffset = Rasterizer.topX - drawX 210 + imageWidth -= xOffset 211 + drawX = Rasterizer.topX 212 + pixelOffset += xOffset 213 + rasterizerOffset += xOffset 214 + originalDeviation += xOffset 215 + deviation += xOffset 216 + } 217 + if (drawX + imageWidth > Rasterizer.bottomX) { 218 + val xOffset = (drawX + imageWidth) - Rasterizer.bottomX 219 + imageWidth -= xOffset 220 + originalDeviation += xOffset 221 + deviation += xOffset 222 + } 223 + if (imageWidth <= 0 || imageHeight <= 0) return 224 + shapeImageToPixels(pixels, Rasterizer.pixels, pixelOffset, rasterizerOffset, imageWidth, imageHeight, originalDeviation, deviation, 0) 225 + } 226 + 227 + fun shapeImageToPixels( 228 + pixels: IntArray, rasterizerPixels: IntArray, pixel: Int, rasterizerPixel: Int, 229 + width: Int, height: Int, pixelOffset: Int, rasterizerPixelOffset: Int, @Suppress("UNUSED_PARAMETER") pixelColor: Int 230 + ) { 231 + val shiftedWidth = -(width shr 2) 232 + val remainingWidth = -(width and 3) 233 + var rPixel = rasterizerPixel 234 + var pPixel = pixel 235 + for (heightCounter in -height until 0) { 236 + for (widthCounter in shiftedWidth until 0) { 237 + var color = pixels[pPixel++] 238 + if (color != 0) rasterizerPixels[rPixel++] = color else rPixel++ 239 + color = pixels[pPixel++] 240 + if (color != 0) rasterizerPixels[rPixel++] = color else rPixel++ 241 + color = pixels[pPixel++] 242 + if (color != 0) rasterizerPixels[rPixel++] = color else rPixel++ 243 + color = pixels[pPixel++] 244 + if (color != 0) rasterizerPixels[rPixel++] = color else rPixel++ 245 + } 246 + for (widthCounter in remainingWidth until 0) { 247 + val color = pixels[pPixel++] 248 + if (color != 0) rasterizerPixels[rPixel++] = color else rPixel++ 249 + } 250 + rPixel += rasterizerPixelOffset 251 + pPixel += pixelOffset 252 + } 253 + } 254 + 255 + fun drawImageAlpha(x: Int, y: Int, alpha: Int) { 256 + var drawX = x + offsetX 257 + var drawY = y + offsetY 258 + var rasterizerPixel = drawX + drawY * Rasterizer.width 259 + var pixel = 0 260 + var newHeight = height 261 + var newWidth = width 262 + var rasterizerPixelOffset = Rasterizer.width - newWidth 263 + var pixelOffset = 0 264 + if (drawY < Rasterizer.topY) { 265 + val yOffset = Rasterizer.topY - drawY 266 + newHeight -= yOffset 267 + drawY = Rasterizer.topY 268 + pixel += yOffset * newWidth 269 + rasterizerPixel += yOffset * Rasterizer.width 270 + } 271 + if (drawY + newHeight > Rasterizer.bottomY) 272 + newHeight -= (drawY + newHeight) - Rasterizer.bottomY 273 + if (drawX < Rasterizer.topX) { 274 + val xOffset = Rasterizer.topX - drawX 275 + newWidth -= xOffset 276 + drawX = Rasterizer.topX 277 + pixel += xOffset 278 + rasterizerPixel += xOffset 279 + pixelOffset += xOffset 280 + rasterizerPixelOffset += xOffset 281 + } 282 + if (drawX + newWidth > Rasterizer.bottomX) { 283 + val xOffset = (drawX + newWidth) - Rasterizer.bottomX 284 + newWidth -= xOffset 285 + pixelOffset += xOffset 286 + rasterizerPixelOffset += xOffset 287 + } 288 + if (newWidth > 0 && newHeight > 0) { 289 + copyPixelsAlpha(pixels, Rasterizer.pixels, pixel, rasterizerPixel, pixelOffset, rasterizerPixelOffset, newWidth, newHeight, 0, alpha) 290 + } 291 + } 292 + 293 + fun copyPixelsAlpha( 294 + pixels: IntArray, rasterizerPixels: IntArray, pixel: Int, rasterizerPixel: Int, 295 + pixelOffset: Int, rasterizerPixelOffset: Int, width: Int, height: Int, 296 + @Suppress("UNUSED_PARAMETER") color: Int, alpha: Int 297 + ) { 298 + val alphaValue = 256 - alpha 299 + var rPixel = rasterizerPixel 300 + var pPixel = pixel 301 + for (heightCounter in -height until 0) { 302 + for (widthCounter in -width until 0) { 303 + val c = pixels[pPixel++] 304 + if (c != 0) { 305 + val rasterizerPixelColor = rasterizerPixels[rPixel] 306 + rasterizerPixels[rPixel++] = ((c and 0xff00ff) * alpha + (rasterizerPixelColor and 0xff00ff) * alphaValue and 0xFF00FF00.toInt()) + 307 + ((c and 0xff00) * alpha + (rasterizerPixelColor and 0xff00) * alphaValue and 0xff0000) shr 8 308 + } else { 309 + rPixel++ 310 + } 311 + } 312 + rPixel += rasterizerPixelOffset 313 + pPixel += pixelOffset 314 + } 315 + } 316 + 317 + @Suppress("UNUSED_PARAMETER") 318 + fun shapeImageToPixels(x: Int, y: Int, width: Int, height: Int, zoom: Int, l: Int, ai: IntArray, k1: Int, ai1: IntArray, i2: Int) { 319 + try { 320 + val centerX = -width / 2 321 + val centerY = -height / 2 322 + var sine = (Math.sin(k1 / 326.11) * 65536.0).toInt() 323 + var cosine = (Math.cos(k1 / 326.11) * 65536.0).toInt() 324 + sine = sine * zoom shr 8 325 + cosine = cosine * zoom shr 8 326 + var sourceOffsetX = (l shl 16) + (centerY * sine + centerX * cosine) 327 + var sourceOffsetY = (i2 shl 16) + (centerY * cosine - centerX * sine) 328 + var destinationOffset = x + y * Rasterizer.width 329 + for (row in 0 until height) { 330 + val i4 = ai1[row] 331 + var j4 = destinationOffset + i4 332 + var k4 = sourceOffsetX + cosine * i4 333 + var l4 = sourceOffsetY - sine * i4 334 + for (col in -ai[row] until 0) { 335 + Rasterizer.pixels[j4++] = pixels[(k4 shr 16) + (l4 shr 16) * this.width] 336 + k4 += cosine 337 + l4 -= sine 338 + } 339 + sourceOffsetX += sine 340 + sourceOffsetY += cosine 341 + destinationOffset += Rasterizer.width 342 + } 343 + } catch (_: Exception) { 344 + } 345 + } 346 + 347 + fun drawRotated(x: Int, y: Int, pivotX: Int, pivotY: Int, width: Int, height: Int, zoom: Int, angle: Double) { 348 + try { 349 + val centerX = -width / 2 350 + val centerY = -height / 2 351 + var sine = (Math.sin(angle) * 65536.0).toInt() 352 + var cosine = (Math.cos(angle) * 65536.0).toInt() 353 + sine = sine * zoom shr 8 354 + cosine = cosine * zoom shr 8 355 + var sourceOffsetX = (pivotX shl 16) + (centerY * sine + centerX * cosine) 356 + var sourceOffsetY = (pivotY shl 16) + (centerY * cosine - centerX * sine) 357 + var destinationOffset = x + y * Rasterizer.width 358 + for (row in 0 until height) { 359 + var i = destinationOffset 360 + var oX = sourceOffsetX 361 + var oY = sourceOffsetY 362 + for (col in -width until 0) { 363 + val colour = pixels[(oX shr 16) + (oY shr 16) * this.width] 364 + if (colour != 0) Rasterizer.pixels[i++] = colour else i++ 365 + oX += cosine 366 + oY -= sine 367 + } 368 + sourceOffsetX += sine 369 + sourceOffsetY += cosine 370 + destinationOffset += Rasterizer.width 371 + } 372 + } catch (_: Exception) { 373 + } 374 + } 375 + 376 + fun drawTo(indexedImage: IndexedImage, x: Int, y: Int) { 377 + var drawX = x + offsetX 378 + var drawY = y + offsetY 379 + var l = drawX + drawY * Rasterizer.width 380 + var i1 = 0 381 + var j1 = height 382 + var k1 = width 383 + var l1 = Rasterizer.width - k1 384 + var i2 = 0 385 + if (drawY < Rasterizer.topY) { 386 + val j2 = Rasterizer.topY - drawY 387 + j1 -= j2 388 + drawY = Rasterizer.topY 389 + i1 += j2 * k1 390 + l += j2 * Rasterizer.width 391 + } 392 + if (drawY + j1 > Rasterizer.bottomY) 393 + j1 -= (drawY + j1) - Rasterizer.bottomY 394 + if (drawX < Rasterizer.topX) { 395 + val k2 = Rasterizer.topX - drawX 396 + k1 -= k2 397 + drawX = Rasterizer.topX 398 + i1 += k2 399 + l += k2 400 + i2 += k2 401 + l1 += k2 402 + } 403 + if (drawX + k1 > Rasterizer.bottomX) { 404 + val l2 = (drawX + k1) - Rasterizer.bottomX 405 + k1 -= l2 406 + i2 += l2 407 + l1 += l2 408 + } 409 + if (k1 <= 0 || j1 <= 0) return 410 + method468(l, l1, pixels, k1, Rasterizer.pixels, indexedImage.imgPixels, 40303, j1, i1, 0, i2) 411 + } 412 + 413 + @Suppress("UNUSED_PARAMETER") 414 + fun method468( 415 + i: Int, j: Int, ai: IntArray, k: Int, ai1: IntArray, abyte0: ByteArray, 416 + l: Int, i1: Int, j1: Int, k1: Int, l1: Int 417 + ) { 418 + val i2 = -(k shr 2) 419 + val remainingWidth = -(k and 3) 420 + var rPos = i 421 + var pPos = j1 422 + var color = k1 423 + for (j2 in -i1 until 0) { 424 + for (k2 in i2 until 0) { 425 + // abyte0 is byte[] — must use .toInt() for comparison 426 + color = ai[pPos++] 427 + if (color != 0 && abyte0[rPos].toInt() == 0) ai1[rPos++] = color else rPos++ 428 + color = ai[pPos++] 429 + if (color != 0 && abyte0[rPos].toInt() == 0) ai1[rPos++] = color else rPos++ 430 + color = ai[pPos++] 431 + if (color != 0 && abyte0[rPos].toInt() == 0) ai1[rPos++] = color else rPos++ 432 + color = ai[pPos++] 433 + if (color != 0 && abyte0[rPos].toInt() == 0) ai1[rPos++] = color else rPos++ 434 + } 435 + for (l2 in remainingWidth until 0) { 436 + color = ai[pPos++] 437 + if (color != 0 && abyte0[rPos].toInt() == 0) ai1[rPos++] = color else rPos++ 438 + } 439 + rPos += j 440 + pPos += l1 441 + } 442 + } 443 + }
-224
src/main/java/com/jagex/runescape/cache/media/IndexedImage.java
··· 1 - package com.jagex.runescape.cache.media; 2 - 3 - import com.jagex.runescape.cache.Archive; 4 - import com.jagex.runescape.media.Rasterizer; 5 - import com.jagex.runescape.net.Buffer; 6 - 7 - public class IndexedImage extends Rasterizer { 8 - 9 - public byte[] imgPixels; 10 - public int[] palette; 11 - public int imgWidth; 12 - public int height; 13 - public int xDrawOffset; 14 - public int yDrawOffset; 15 - public int maxWidth; 16 - public int maxHeight; 17 - 18 - public IndexedImage(Archive archive, String archiveName, int offset) { 19 - Buffer dataBuffer = new Buffer(archive.getFile(archiveName + ".dat")); 20 - Buffer indexBuffer = new Buffer(archive.getFile("index.dat")); 21 - indexBuffer.currentPosition = dataBuffer.getUnsignedShortBE(); 22 - maxWidth = indexBuffer.getUnsignedShortBE(); 23 - maxHeight = indexBuffer.getUnsignedShortBE(); 24 - int palleteLength = indexBuffer.getUnsignedByte(); 25 - palette = new int[palleteLength]; 26 - for (int index = 0; index < palleteLength - 1; index++) 27 - palette[index + 1] = indexBuffer.getMediumBE(); 28 - 29 - for (int counter = 0; counter < offset; counter++) { 30 - indexBuffer.currentPosition += 2; 31 - dataBuffer.currentPosition += indexBuffer.getUnsignedShortBE() * indexBuffer.getUnsignedShortBE(); 32 - indexBuffer.currentPosition++; 33 - } 34 - 35 - xDrawOffset = indexBuffer.getUnsignedByte(); 36 - yDrawOffset = indexBuffer.getUnsignedByte(); 37 - imgWidth = indexBuffer.getUnsignedShortBE(); 38 - height = indexBuffer.getUnsignedShortBE(); 39 - int type = indexBuffer.getUnsignedByte(); 40 - int pixelLength = imgWidth * height; 41 - imgPixels = new byte[pixelLength]; 42 - if (type == 0) { 43 - for (int pixel = 0; pixel < pixelLength; pixel++) 44 - imgPixels[pixel] = dataBuffer.getByte(); 45 - 46 - return; 47 - } 48 - if (type == 1) { 49 - for (int x = 0; x < imgWidth; x++) { 50 - for (int y = 0; y < height; y++) 51 - imgPixels[x + y * imgWidth] = dataBuffer.getByte(); 52 - 53 - } 54 - 55 - } 56 - } 57 - 58 - public void resizeToHalfLibSize() { 59 - maxWidth /= 2; 60 - maxHeight /= 2; 61 - byte[] resizedPixels = new byte[maxWidth * maxHeight]; 62 - int pixelCount = 0; 63 - for (int y = 0; y < height; y++) { 64 - for (int x = 0; x < imgWidth; x++) 65 - resizedPixels[(x + xDrawOffset >> 1) + (y + yDrawOffset >> 1) * maxWidth] = imgPixels[pixelCount++]; 66 - 67 - } 68 - 69 - imgPixels = resizedPixels; 70 - imgWidth = maxWidth; 71 - height = maxHeight; 72 - xDrawOffset = 0; 73 - yDrawOffset = 0; 74 - } 75 - 76 - public void resizeToLibSize() { 77 - if (imgWidth != maxWidth || height != maxHeight) { 78 - byte[] resizedPixels = new byte[maxWidth * maxHeight]; 79 - int pixelCount = 0; 80 - for (int y = 0; y < height; y++) { 81 - for (int x = 0; x < imgWidth; x++) 82 - resizedPixels[x + xDrawOffset + (y + yDrawOffset) * maxWidth] = imgPixels[pixelCount++]; 83 - 84 - } 85 - 86 - imgPixels = resizedPixels; 87 - imgWidth = maxWidth; 88 - height = maxHeight; 89 - xDrawOffset = 0; 90 - yDrawOffset = 0; 91 - } 92 - 93 - } 94 - 95 - public void flipHorizontal() { 96 - byte[] flipedPixels = new byte[imgWidth * height]; 97 - int pixelCount = 0; 98 - for (int y = 0; y < height; y++) { 99 - for (int x = imgWidth - 1; x >= 0; x--) 100 - flipedPixels[pixelCount++] = imgPixels[x + y * imgWidth]; 101 - 102 - } 103 - 104 - imgPixels = flipedPixels; 105 - xDrawOffset = maxWidth - imgWidth - xDrawOffset; 106 - 107 - } 108 - 109 - public void flipVertical() { 110 - byte[] flipedPixels = new byte[imgWidth * height]; 111 - int pixelCount = 0; 112 - for (int y = height - 1; y >= 0; y--) { 113 - for (int x = 0; x < imgWidth; x++) 114 - flipedPixels[pixelCount++] = imgPixels[x + y * imgWidth]; 115 - 116 - } 117 - imgPixels = flipedPixels; 118 - yDrawOffset = maxHeight - height - yDrawOffset; 119 - } 120 - 121 - public void mixPalette(int red, int green, int blue) { 122 - for (int index = 0; index < palette.length; index++) { 123 - int r = palette[index] >> 16 & 0xff; 124 - r += red; 125 - if (r < 0) 126 - r = 0; 127 - else if (r > 255) 128 - r = 255; 129 - int g = palette[index] >> 8 & 0xff; 130 - g += green; 131 - if (g < 0) 132 - g = 0; 133 - else if (g > 255) 134 - g = 255; 135 - int b = palette[index] & 0xff; 136 - b += blue; 137 - if (b < 0) 138 - b = 0; 139 - else if (b > 255) 140 - b = 255; 141 - palette[index] = (r << 16) + (g << 8) + b; 142 - } 143 - } 144 - 145 - public void drawImage(int x, int y) { 146 - x += xDrawOffset; 147 - y += yDrawOffset; 148 - int offset = x + y * Rasterizer.width; 149 - int originalOffset = 0; 150 - int imageHeight = height; 151 - int imageWidth = imgWidth; 152 - int deviation = Rasterizer.width - imageWidth; 153 - int originalDeviation = 0; 154 - if (y < Rasterizer.topY) { 155 - int yOffset = Rasterizer.topY - y; 156 - imageHeight -= yOffset; 157 - y = Rasterizer.topY; 158 - originalOffset += yOffset * imageWidth; 159 - offset += yOffset * Rasterizer.width; 160 - } 161 - if (y + imageHeight > Rasterizer.bottomY) 162 - imageHeight -= (y + imageHeight) - Rasterizer.bottomY; 163 - if (x < Rasterizer.topX) { 164 - int xOffset = Rasterizer.topX - x; 165 - imageWidth -= xOffset; 166 - x = Rasterizer.topX; 167 - originalOffset += xOffset; 168 - offset += xOffset; 169 - originalDeviation += xOffset; 170 - deviation += xOffset; 171 - } 172 - if (x + imageWidth > Rasterizer.bottomX) { 173 - int xOffset = (x + imageWidth) - Rasterizer.bottomX; 174 - imageWidth -= xOffset; 175 - originalDeviation += xOffset; 176 - deviation += xOffset; 177 - } 178 - if (imageWidth > 0 && imageHeight > 0) { 179 - copyPixels(imgPixels, Rasterizer.pixels, imageWidth, imageHeight, offset, originalOffset, deviation, originalDeviation, palette); 180 - } 181 - } 182 - 183 - public void copyPixels(byte[] pixels, int[] rasterizerPixels, int width, int height, int offset, int originalOffset, int deviation, int originalDeviation, int[] pallete) { 184 - int shiftedWidth = -(width >> 2); 185 - width = -(width & 3); 186 - for (int heightCounter = -height; heightCounter < 0; heightCounter++) { 187 - for (int shiftedWidthCounter = shiftedWidth; shiftedWidthCounter < 0; shiftedWidthCounter++) { 188 - byte pixel = pixels[originalOffset++]; 189 - if (pixel != 0) 190 - rasterizerPixels[offset++] = pallete[pixel & 0xff]; 191 - else 192 - offset++; 193 - pixel = pixels[originalOffset++]; 194 - if (pixel != 0) 195 - rasterizerPixels[offset++] = pallete[pixel & 0xff]; 196 - else 197 - offset++; 198 - pixel = pixels[originalOffset++]; 199 - if (pixel != 0) 200 - rasterizerPixels[offset++] = pallete[pixel & 0xff]; 201 - else 202 - offset++; 203 - pixel = pixels[originalOffset++]; 204 - if (pixel != 0) 205 - rasterizerPixels[offset++] = pallete[pixel & 0xff]; 206 - else 207 - offset++; 208 - } 209 - 210 - for (int widthCounter = width; widthCounter < 0; widthCounter++) { 211 - byte pixel = pixels[originalOffset++]; 212 - if (pixel != 0) 213 - rasterizerPixels[offset++] = pallete[pixel & 0xff]; 214 - else 215 - offset++; 216 - } 217 - 218 - offset += deviation; 219 - originalOffset += originalDeviation; 220 - } 221 - 222 - } 223 - 224 - }
+198
src/main/java/com/jagex/runescape/cache/media/IndexedImage.kt
··· 1 + package com.jagex.runescape.cache.media 2 + 3 + import com.jagex.runescape.cache.Archive 4 + import com.jagex.runescape.media.Rasterizer 5 + import com.jagex.runescape.net.Buffer 6 + 7 + class IndexedImage(archive: Archive, archiveName: String, offset: Int) : Rasterizer() { 8 + 9 + @JvmField var imgPixels: ByteArray 10 + @JvmField var palette: IntArray 11 + @JvmField var imgWidth: Int 12 + @JvmField var height: Int 13 + @JvmField var xDrawOffset: Int 14 + @JvmField var yDrawOffset: Int 15 + @JvmField var maxWidth: Int 16 + @JvmField var maxHeight: Int 17 + 18 + init { 19 + val dataBuffer = Buffer(archive.getFile("$archiveName.dat")!!) 20 + val indexBuffer = Buffer(archive.getFile("index.dat")!!) 21 + indexBuffer.currentPosition = dataBuffer.getUnsignedShortBE() 22 + maxWidth = indexBuffer.getUnsignedShortBE() 23 + maxHeight = indexBuffer.getUnsignedShortBE() 24 + val palleteLength = indexBuffer.getUnsignedByte() 25 + palette = IntArray(palleteLength) 26 + for (index in 0 until palleteLength - 1) 27 + palette[index + 1] = indexBuffer.getMediumBE() 28 + 29 + for (counter in 0 until offset) { 30 + indexBuffer.currentPosition += 2 31 + dataBuffer.currentPosition += indexBuffer.getUnsignedShortBE() * indexBuffer.getUnsignedShortBE() 32 + indexBuffer.currentPosition++ 33 + } 34 + 35 + xDrawOffset = indexBuffer.getUnsignedByte() 36 + yDrawOffset = indexBuffer.getUnsignedByte() 37 + imgWidth = indexBuffer.getUnsignedShortBE() 38 + height = indexBuffer.getUnsignedShortBE() 39 + val type = indexBuffer.getUnsignedByte() 40 + val pixelLength = imgWidth * height 41 + imgPixels = ByteArray(pixelLength) 42 + if (type == 0) { 43 + for (pixel in 0 until pixelLength) 44 + imgPixels[pixel] = dataBuffer.getByte() 45 + } else if (type == 1) { 46 + for (x in 0 until imgWidth) 47 + for (y in 0 until height) 48 + imgPixels[x + y * imgWidth] = dataBuffer.getByte() 49 + } 50 + } 51 + 52 + fun resizeToHalfLibSize() { 53 + maxWidth /= 2 54 + maxHeight /= 2 55 + val resizedPixels = ByteArray(maxWidth * maxHeight) 56 + var pixelCount = 0 57 + for (y in 0 until height) 58 + for (x in 0 until imgWidth) 59 + resizedPixels[(x + xDrawOffset shr 1) + (y + yDrawOffset shr 1) * maxWidth] = imgPixels[pixelCount++] 60 + imgPixels = resizedPixels 61 + imgWidth = maxWidth 62 + height = maxHeight 63 + xDrawOffset = 0 64 + yDrawOffset = 0 65 + } 66 + 67 + fun resizeToLibSize() { 68 + if (imgWidth != maxWidth || height != maxHeight) { 69 + val resizedPixels = ByteArray(maxWidth * maxHeight) 70 + var pixelCount = 0 71 + for (y in 0 until height) 72 + for (x in 0 until imgWidth) 73 + resizedPixels[x + xDrawOffset + (y + yDrawOffset) * maxWidth] = imgPixels[pixelCount++] 74 + imgPixels = resizedPixels 75 + imgWidth = maxWidth 76 + height = maxHeight 77 + xDrawOffset = 0 78 + yDrawOffset = 0 79 + } 80 + } 81 + 82 + fun flipHorizontal() { 83 + val flipedPixels = ByteArray(imgWidth * height) 84 + var pixelCount = 0 85 + for (y in 0 until height) 86 + for (x in imgWidth - 1 downTo 0) 87 + flipedPixels[pixelCount++] = imgPixels[x + y * imgWidth] 88 + imgPixels = flipedPixels 89 + xDrawOffset = maxWidth - imgWidth - xDrawOffset 90 + } 91 + 92 + fun flipVertical() { 93 + val flipedPixels = ByteArray(imgWidth * height) 94 + var pixelCount = 0 95 + for (y in height - 1 downTo 0) 96 + for (x in 0 until imgWidth) 97 + flipedPixels[pixelCount++] = imgPixels[x + y * imgWidth] 98 + imgPixels = flipedPixels 99 + yDrawOffset = maxHeight - height - yDrawOffset 100 + } 101 + 102 + fun mixPalette(red: Int, green: Int, blue: Int) { 103 + for (index in palette.indices) { 104 + var r = palette[index] shr 16 and 0xff 105 + r += red 106 + if (r < 0) r = 0 else if (r > 255) r = 255 107 + var g = palette[index] shr 8 and 0xff 108 + g += green 109 + if (g < 0) g = 0 else if (g > 255) g = 255 110 + var b = palette[index] and 0xff 111 + b += blue 112 + if (b < 0) b = 0 else if (b > 255) b = 255 113 + palette[index] = (r shl 16) + (g shl 8) + b 114 + } 115 + } 116 + 117 + fun drawImage(x: Int, y: Int) { 118 + var drawX = x + xDrawOffset 119 + var drawY = y + yDrawOffset 120 + var offset = drawX + drawY * Rasterizer.width 121 + var originalOffset = 0 122 + var imageHeight = height 123 + var imageWidth = imgWidth 124 + var deviation = Rasterizer.width - imageWidth 125 + var originalDeviation = 0 126 + if (drawY < Rasterizer.topY) { 127 + val yOffset = Rasterizer.topY - drawY 128 + imageHeight -= yOffset 129 + drawY = Rasterizer.topY 130 + originalOffset += yOffset * imageWidth 131 + offset += yOffset * Rasterizer.width 132 + } 133 + if (drawY + imageHeight > Rasterizer.bottomY) 134 + imageHeight -= (drawY + imageHeight) - Rasterizer.bottomY 135 + if (drawX < Rasterizer.topX) { 136 + val xOffset = Rasterizer.topX - drawX 137 + imageWidth -= xOffset 138 + drawX = Rasterizer.topX 139 + originalOffset += xOffset 140 + offset += xOffset 141 + originalDeviation += xOffset 142 + deviation += xOffset 143 + } 144 + if (drawX + imageWidth > Rasterizer.bottomX) { 145 + val xOffset = (drawX + imageWidth) - Rasterizer.bottomX 146 + imageWidth -= xOffset 147 + originalDeviation += xOffset 148 + deviation += xOffset 149 + } 150 + if (imageWidth > 0 && imageHeight > 0) { 151 + copyPixels(imgPixels, Rasterizer.pixels, imageWidth, imageHeight, offset, originalOffset, deviation, originalDeviation, palette) 152 + } 153 + } 154 + 155 + fun copyPixels( 156 + pixels: ByteArray, rasterizerPixels: IntArray, width: Int, height: Int, 157 + offset: Int, originalOffset: Int, deviation: Int, originalDeviation: Int, pallete: IntArray 158 + ) { 159 + val shiftedWidth = -(width shr 2) 160 + val remainingWidth = -(width and 3) 161 + var rOffset = offset 162 + var pOffset = originalOffset 163 + for (heightCounter in -height until 0) { 164 + for (shiftedWidthCounter in shiftedWidth until 0) { 165 + // Each byte is a palette index. Must mask with 0xff for unsigned lookup. 166 + var pixel = pixels[pOffset++] 167 + if (pixel.toInt() != 0) 168 + rasterizerPixels[rOffset++] = pallete[pixel.toInt() and 0xff] 169 + else 170 + rOffset++ 171 + pixel = pixels[pOffset++] 172 + if (pixel.toInt() != 0) 173 + rasterizerPixels[rOffset++] = pallete[pixel.toInt() and 0xff] 174 + else 175 + rOffset++ 176 + pixel = pixels[pOffset++] 177 + if (pixel.toInt() != 0) 178 + rasterizerPixels[rOffset++] = pallete[pixel.toInt() and 0xff] 179 + else 180 + rOffset++ 181 + pixel = pixels[pOffset++] 182 + if (pixel.toInt() != 0) 183 + rasterizerPixels[rOffset++] = pallete[pixel.toInt() and 0xff] 184 + else 185 + rOffset++ 186 + } 187 + for (widthCounter in remainingWidth until 0) { 188 + val pixel = pixels[pOffset++] 189 + if (pixel.toInt() != 0) 190 + rasterizerPixels[rOffset++] = pallete[pixel.toInt() and 0xff] 191 + else 192 + rOffset++ 193 + } 194 + rOffset += deviation 195 + pOffset += originalDeviation 196 + } 197 + } 198 + }
-88
src/main/java/com/jagex/runescape/cache/media/SpotAnimation.java
··· 1 - package com.jagex.runescape.cache.media; 2 - 3 - import com.jagex.runescape.cache.Archive; 4 - import com.jagex.runescape.collection.Cache; 5 - import com.jagex.runescape.media.renderable.Model; 6 - import com.jagex.runescape.net.Buffer; 7 - 8 - public class SpotAnimation { 9 - 10 - public static int spotAnimationCount; 11 - public static SpotAnimation cache[]; 12 - public int id; 13 - public int modelId; 14 - public int animationId = -1; 15 - public AnimationSequence sequences; 16 - public int originalModelColors[] = new int[6]; 17 - public int modifiedModelColors[] = new int[6]; 18 - public int resizeXY = 128; 19 - public int resizeZ = 128; 20 - public int rotation; 21 - public int modelLightFalloff; 22 - public int modelLightAmbient; 23 - public static Cache modelCache = new Cache(30); 24 - 25 - public static void load(Archive archive) { 26 - Buffer buffer = new Buffer(archive.getFile("spotanim.dat")); 27 - SpotAnimation.spotAnimationCount = buffer.getUnsignedShortBE(); 28 - if (SpotAnimation.cache == null) 29 - SpotAnimation.cache = new SpotAnimation[SpotAnimation.spotAnimationCount]; 30 - for (int spotAnimation = 0; spotAnimation < spotAnimationCount; spotAnimation++) { 31 - if (SpotAnimation.cache[spotAnimation] == null) 32 - SpotAnimation.cache[spotAnimation] = new SpotAnimation(); 33 - SpotAnimation.cache[spotAnimation].id = spotAnimation; 34 - SpotAnimation.cache[spotAnimation].loadDefinition(buffer); 35 - } 36 - 37 - } 38 - 39 - public void loadDefinition(Buffer buffer) { 40 - while (true) { 41 - int attributeId = buffer.getUnsignedByte(); 42 - if (attributeId == 0) 43 - return; 44 - if (attributeId == 1) 45 - modelId = buffer.getUnsignedShortBE(); 46 - else if (attributeId == 2) { 47 - animationId = buffer.getUnsignedShortBE(); 48 - if (AnimationSequence.animations != null) 49 - sequences = AnimationSequence.animations[animationId]; 50 - } else if (attributeId == 4) 51 - resizeXY = buffer.getUnsignedShortBE(); 52 - else if (attributeId == 5) 53 - resizeZ = buffer.getUnsignedShortBE(); 54 - else if (attributeId == 6) 55 - rotation = buffer.getUnsignedShortBE(); 56 - else if (attributeId == 7) 57 - modelLightFalloff = buffer.getUnsignedByte(); 58 - else if (attributeId == 8) 59 - modelLightAmbient = buffer.getUnsignedByte(); 60 - else if (attributeId >= 40 && attributeId < 50) 61 - originalModelColors[attributeId - 40] = buffer.getUnsignedShortBE(); 62 - else if (attributeId >= 50 && attributeId < 60) 63 - modifiedModelColors[attributeId - 50] = buffer.getUnsignedShortBE(); 64 - else 65 - System.out.println("Error unrecognised spotanim config code: " + attributeId); 66 - } 67 - } 68 - 69 - public Model getModel() { 70 - Model model = (Model) modelCache.get(id); 71 - if (model != null) 72 - return model; 73 - 74 - model = Model.getModel(modelId); 75 - if (model == null) 76 - return null; 77 - 78 - for (int nodelColor = 0; nodelColor < 6; nodelColor++) 79 - if (originalModelColors[0] != 0) 80 - model.replaceColor(originalModelColors[nodelColor], modifiedModelColors[nodelColor]); 81 - 82 - SpotAnimation.modelCache.put(model, id); 83 - return model; 84 - } 85 - 86 - 87 - 88 - }
+75
src/main/java/com/jagex/runescape/cache/media/SpotAnimation.kt
··· 1 + package com.jagex.runescape.cache.media 2 + 3 + import com.jagex.runescape.cache.Archive 4 + import com.jagex.runescape.collection.Cache 5 + import com.jagex.runescape.media.renderable.Model 6 + import com.jagex.runescape.net.Buffer 7 + 8 + class SpotAnimation { 9 + 10 + @JvmField var id: Int = 0 11 + @JvmField var modelId: Int = 0 12 + @JvmField var animationId: Int = -1 13 + @JvmField var sequences: AnimationSequence? = null 14 + @JvmField var originalModelColors: IntArray = IntArray(6) 15 + @JvmField var modifiedModelColors: IntArray = IntArray(6) 16 + @JvmField var resizeXY: Int = 128 17 + @JvmField var resizeZ: Int = 128 18 + @JvmField var rotation: Int = 0 19 + @JvmField var modelLightFalloff: Int = 0 20 + @JvmField var modelLightAmbient: Int = 0 21 + 22 + fun loadDefinition(buffer: Buffer) { 23 + while (true) { 24 + val attributeId = buffer.getUnsignedByte() 25 + if (attributeId == 0) return 26 + when { 27 + attributeId == 1 -> modelId = buffer.getUnsignedShortBE() 28 + attributeId == 2 -> { 29 + animationId = buffer.getUnsignedShortBE() 30 + if (AnimationSequence.animations != null) 31 + sequences = AnimationSequence.animations!![animationId] 32 + } 33 + attributeId == 4 -> resizeXY = buffer.getUnsignedShortBE() 34 + attributeId == 5 -> resizeZ = buffer.getUnsignedShortBE() 35 + attributeId == 6 -> rotation = buffer.getUnsignedShortBE() 36 + attributeId == 7 -> modelLightFalloff = buffer.getUnsignedByte() 37 + attributeId == 8 -> modelLightAmbient = buffer.getUnsignedByte() 38 + attributeId in 40..49 -> originalModelColors[attributeId - 40] = buffer.getUnsignedShortBE() 39 + attributeId in 50..59 -> modifiedModelColors[attributeId - 50] = buffer.getUnsignedShortBE() 40 + else -> println("Error unrecognised spotanim config code: $attributeId") 41 + } 42 + } 43 + } 44 + 45 + fun getModel(): Model? { 46 + var model = modelCache.get(id.toLong()) as Model? 47 + if (model != null) return model 48 + model = Model.getModel(modelId) ?: return null 49 + for (color in 0 until 6) 50 + if (originalModelColors[0] != 0) 51 + model.replaceColor(originalModelColors[color], modifiedModelColors[color]) 52 + modelCache.put(model, id.toLong()) 53 + return model 54 + } 55 + 56 + companion object { 57 + @JvmField var spotAnimationCount: Int = 0 58 + @JvmField var cache: Array<SpotAnimation?>? = null 59 + @JvmField var modelCache: Cache = Cache(30) 60 + 61 + @JvmStatic 62 + fun load(archive: Archive) { 63 + val buffer = Buffer(archive.getFile("spotanim.dat")!!) 64 + spotAnimationCount = buffer.getUnsignedShortBE() 65 + if (cache == null) 66 + cache = arrayOfNulls(spotAnimationCount) 67 + for (spotAnimation in 0 until spotAnimationCount) { 68 + if (cache!![spotAnimation] == null) 69 + cache!![spotAnimation] = SpotAnimation() 70 + cache!![spotAnimation]!!.id = spotAnimation 71 + cache!![spotAnimation]!!.loadDefinition(buffer) 72 + } 73 + } 74 + } 75 + }
-941
src/main/java/com/jagex/runescape/cache/media/TypeFace.java
··· 1 - package com.jagex.runescape.cache.media; 2 - 3 - import com.jagex.runescape.cache.Archive; 4 - import com.jagex.runescape.media.Rasterizer; 5 - import com.jagex.runescape.net.Buffer; 6 - 7 - import java.awt.*; 8 - import java.util.Random; 9 - 10 - public class TypeFace extends Rasterizer { 11 - 12 - // Todo: Clean up duplicate legacy methods, by checking if images are not loaded when they are needed instead 13 - public byte[][] characterPixels = new byte[256][]; 14 - public int[] characterWidths = new int[256]; 15 - public int[] characterHeights = new int[256]; 16 - public int[] characterXOffsets = new int[256]; 17 - public int[] characterYOffsets = new int[256]; 18 - public int[] characterScreenWidths = new int[256]; 19 - public int characterDefaultHeight; 20 - public Random random = new Random(); 21 - 22 - private static int strikethroughColor = -1; 23 - private static int underlineColor = -1; 24 - private static int anInt3748 = 0; 25 - private static int defaultTextColor = 0; 26 - private static int opacity = 256; 27 - private static int defaultOpacity = 256; 28 - private static int defaultShadowColor = -1; 29 - private static int shadowColor = -1; 30 - private static int textColor = 0xff00ff; 31 - private static int whiteSpace = 0; 32 - private ImageRGB[] moderatorIcon = null; 33 - private int[] imageWidths; 34 - private static String greaterThan = "gt"; 35 - private static String lessThan = "lt"; 36 - private static String euroSymbol = "euro"; 37 - private static String startShadow = "shad="; 38 - private static String softHyphen = "shy"; 39 - private static String startTrans = "trans="; 40 - private static String startUnderline = "u="; 41 - private static String startStrikethrough = "str="; 42 - private static String endColor = "/col"; 43 - private static String endShadow = "/shad"; 44 - private static String endTrans = "/trans"; 45 - private static String endUnderline = "/u"; 46 - private static String endStrikeThrough = "/str"; 47 - private static String startDefaultUnderline = "u"; 48 - private static String startDefaultStrikeThrough = "str"; 49 - private static String startDefaultShadow = "shad"; 50 - private static String startColor = "col="; 51 - private static String multiplicationSymbol = "times"; 52 - private static String nonBreakingSpace = "nbsp"; 53 - private static String image = "img="; 54 - private static String copyright = "copy"; 55 - private static String lineBreak = "br"; 56 - private static String registeredTrademark = "reg"; 57 - 58 - public TypeFace(boolean monospace, Archive archive, String archiveName) { 59 - Buffer dataBuffer = new Buffer(archive.getFile(archiveName + ".dat")); 60 - Buffer indexBuffer = new Buffer(archive.getFile("index.dat")); 61 - indexBuffer.currentPosition = dataBuffer.getUnsignedShortBE() + 4; 62 - int k = indexBuffer.getUnsignedByte(); 63 - if (k > 0) 64 - indexBuffer.currentPosition += 3 * (k - 1); 65 - for (int character = 0; character < 256; character++) { 66 - characterXOffsets[character] = indexBuffer.getUnsignedByte(); 67 - characterYOffsets[character] = indexBuffer.getUnsignedByte(); 68 - int characterWidth = characterWidths[character] = indexBuffer.getUnsignedShortBE(); 69 - int characterHeight = characterHeights[character] = indexBuffer.getUnsignedShortBE(); 70 - int characterType = indexBuffer.getUnsignedByte(); 71 - int characterSize = characterWidth * characterHeight; 72 - characterPixels[character] = new byte[characterSize]; 73 - if (characterType == 0) { 74 - for (int pixel = 0; pixel < characterSize; pixel++) 75 - characterPixels[character][pixel] = dataBuffer.getByte(); 76 - 77 - } else if (characterType == 1) { 78 - for (int characterX = 0; characterX < characterWidth; characterX++) { 79 - for (int characterY = 0; characterY < characterHeight; characterY++) 80 - characterPixels[character][characterX + characterY * characterWidth] = dataBuffer.getByte(); 81 - 82 - } 83 - 84 - } 85 - if (characterHeight > characterDefaultHeight && character < 128) 86 - characterDefaultHeight = characterHeight; 87 - characterXOffsets[character] = 1; 88 - characterScreenWidths[character] = characterWidth + 2; 89 - int pixelCount = 0; 90 - for (int characterY = characterHeight / 7; characterY < characterHeight; characterY++) 91 - pixelCount += characterPixels[character][characterY * characterWidth]; 92 - 93 - if (pixelCount <= characterHeight / 7) { 94 - characterScreenWidths[character]--; 95 - characterXOffsets[character] = 0; 96 - } 97 - pixelCount = 0; 98 - for (int characterY = characterHeight / 7; characterY < characterHeight; characterY++) 99 - pixelCount += characterPixels[character][(characterWidth - 1) + characterY * characterWidth]; 100 - 101 - if (pixelCount <= characterHeight / 7) 102 - characterScreenWidths[character]--; 103 - } 104 - 105 - if (monospace) { 106 - characterScreenWidths[32] = characterScreenWidths[73]; 107 - } else { 108 - characterScreenWidths[32] = characterScreenWidths[105]; 109 - } 110 - } 111 - 112 - public void drawStringRight(String string, int x, int y, int colour) { 113 - drawString(string, x - getDisplayedWidth(string), y, colour); 114 - } 115 - 116 - public void drawStringLeft(String string, int x, int y, int colour) { 117 - drawString(string, x - getDisplayedWidth(string) / 2, y, colour); 118 - } 119 - 120 - public void drawStringCenter(String string, int x, int y, int colour, boolean shadowed) { 121 - drawShadowedString(string, x - getStringEffectWidth(string) / 2, y, shadowed, colour); 122 - } 123 - 124 - public int getStringEffectWidth(String string) { 125 - return getDisplayedWidth(string); 126 - } 127 - 128 - public final int getDisplayedWidth(String string) { 129 - if (string == null) { 130 - return 0; 131 - } 132 - int index = -1; 133 - int width = 0; 134 - int length = string.length(); 135 - 136 - for (int idx = 0; idx < length; ++idx) { 137 - int character = string.charAt(idx); 138 - if (character == 60) { 139 - 140 - index = idx; 141 - } else { 142 - if (character == 62 && index != -1) { 143 - String effect = string.substring(index + 1, idx); 144 - index = -1; 145 - if (effect.equals(lessThan)) { 146 - character = 60; 147 - } else if (effect.equals(greaterThan)) { 148 - character = 62; 149 - } else if (effect.equals(nonBreakingSpace)) { 150 - character = 160; 151 - } else if (effect.equals(softHyphen)) { 152 - character = 173; 153 - } else if (effect.equals(multiplicationSymbol)) { 154 - character = 215; 155 - } else if (effect.equals(euroSymbol)) { 156 - character = 128; 157 - } else if (effect.equals(copyright)) { 158 - character = 169; 159 - } else { 160 - if (!effect.equals(registeredTrademark)) { 161 - if (effect.startsWith(image, 0)) { 162 - try { 163 - int icon = Integer.parseInt(effect.substring(4)); 164 - width += moderatorIcon[icon].maxWidth; 165 - } catch (Exception var10) { 166 - 167 - } 168 - } 169 - continue; 170 - } 171 - 172 - character = 174; 173 - } 174 - } 175 - if (character == '@' && idx + 4 < string.length() && string.charAt(idx + 4) == '@') { 176 - idx += 4; 177 - continue; 178 - } 179 - 180 - if (index == -1) { 181 - width += characterScreenWidths[character]; 182 - } 183 - } 184 - } 185 - 186 - return width; 187 - 188 - } 189 - 190 - public void drawString(String string, int x, int y, int colour) { 191 - if (this.moderatorIcon != null) { 192 - this.drawString(string, x, y, colour, -1); 193 - 194 - } else { 195 - if (string == null) 196 - return; 197 - y -= characterDefaultHeight; 198 - for (int index = 0; index < string.length(); index++) { 199 - char character = string.charAt(index); 200 - if (character != ' ') 201 - drawCharacterLegacy(characterPixels[character], x + characterXOffsets[character], y + characterYOffsets[character], characterWidths[character], 202 - characterHeights[character], colour); 203 - x += characterScreenWidths[character]; 204 - } 205 - } 206 - 207 - 208 - } 209 - 210 - public void drawCenteredStringWaveY(String string, int x, int y, int wave, int colour) { 211 - if (string == null) 212 - return; 213 - x -= getDisplayedWidth(string) / 2; 214 - y -= characterDefaultHeight; 215 - for (int index = 0; index < string.length(); index++) { 216 - char character = string.charAt(index); 217 - if (character != ' ') 218 - drawCharacterLegacy(characterPixels[character], x + characterXOffsets[character], y + characterYOffsets[character] 219 - + (int) (Math.sin(index / 2D + wave / 5D) * 5D), characterWidths[character], characterHeights[character], colour); 220 - x += characterScreenWidths[character]; 221 - } 222 - 223 - } 224 - 225 - public void drawCenteredString(String text, int x, int y, int color, int shadow) { 226 - if (text != null) { 227 - setEffects(color, shadow); 228 - drawBasicString(text, x - getDisplayedWidth(text) / 2, y); 229 - } 230 - } 231 - 232 - public void drawCenteredStringWaveXY(String string, int x, int y, int wave, int colour) { 233 - if (string == null) 234 - return; 235 - x -= getDisplayedWidth(string) / 2; 236 - y -= characterDefaultHeight; 237 - for (int index = 0; index < string.length(); index++) { 238 - char character = string.charAt(index); 239 - if (character != ' ') 240 - drawCharacterLegacy(characterPixels[character], x + characterXOffsets[character] + (int) (Math.sin(index / 5D + wave / 5D) * 5D), y 241 - + characterYOffsets[character] + (int) (Math.sin(index / 3D + wave / 5D) * 5D), characterWidths[character], 242 - characterHeights[character], colour); 243 - x += characterScreenWidths[character]; 244 - } 245 - 246 - } 247 - 248 - public void drawCenteredStringWaveXYMove(String string, int x, int y, int waveAmount, int waveSpeed, int colour) { 249 - if (string == null) 250 - return; 251 - double speed = 7D - waveSpeed / 8D; 252 - if (speed < 0.0D) 253 - speed = 0.0D; 254 - x -= getDisplayedWidth(string) / 2; 255 - y -= characterDefaultHeight; 256 - for (int index = 0; index < string.length(); index++) { 257 - char character = string.charAt(index); 258 - if (character != ' ') 259 - drawCharacterLegacy(characterPixels[character], x + characterXOffsets[character], y + characterYOffsets[character] 260 - + (int) (Math.sin(index / 1.5D + waveAmount) * speed), characterWidths[character], characterHeights[character], colour); 261 - x += characterScreenWidths[character]; 262 - } 263 - 264 - } 265 - 266 - public void drawShadowedString(String string, int x, int y, boolean shadow, int colour) { 267 - if (!shadow) { 268 - drawString(string, x, y, colour); 269 - return; 270 - } 271 - if (this.moderatorIcon != null) { 272 - this.drawString(string, x, y, colour, 0); 273 - } else { 274 - strikethroughColor = -1; 275 - int originalX = x; 276 - if (string == null) 277 - return; 278 - y -= characterDefaultHeight; 279 - for (int character = 0; character < string.length(); character++) 280 - if (string.charAt(character) == '@' && character + 4 < string.length() && string.charAt(character + 4) == '@') { 281 - int stringColour = getColour(string.substring(character + 1, character + 4)); 282 - if (stringColour != -1) 283 - colour = stringColour; 284 - character += 4; 285 - } else { 286 - char c = string.charAt(character); 287 - if (c != ' ') { 288 - if (shadow) 289 - drawCharacterLegacy(characterPixels[c], x + characterXOffsets[c] + 1, y + characterYOffsets[c] + 1, 290 - characterWidths[c], characterHeights[c], 0); 291 - drawCharacterLegacy(characterPixels[c], x + characterXOffsets[c], y + characterYOffsets[c], characterWidths[c], 292 - characterHeights[c], colour); 293 - } 294 - x += characterScreenWidths[c]; 295 - } 296 - 297 - if (strikethroughColor != -1) 298 - Rasterizer.drawHorizontalLine(originalX, y + (int) (characterDefaultHeight * 0.69999999999999996D), x - originalX, strikethroughColor); 299 - } 300 - } 301 - 302 - public void drawShadowedSeededAlphaString(String string, int x, int y, int colour, int seed) { 303 - if (string == null) 304 - return; 305 - random.setSeed(seed); 306 - int alpha = 192 + (random.nextInt() & 0x1f); 307 - y -= characterDefaultHeight; 308 - for (int index = 0; index < string.length(); index++) 309 - if (string.charAt(index) == '@' && index + 4 < string.length() && string.charAt(index + 4) == '@') { 310 - int stringColour = getColour(string.substring(index + 1, index + 4)); 311 - if (stringColour != -1) 312 - colour = stringColour; 313 - index += 4; 314 - } else { 315 - char c = string.charAt(index); 316 - if (c != ' ') { 317 - 318 - drawAlphaCharacter(characterPixels[c], x + characterXOffsets[c] + 1, y + characterYOffsets[c] + 1, characterWidths[c], characterHeights[c], 0, 319 - 192); 320 - drawAlphaCharacter(characterPixels[c], x + characterXOffsets[c], y + characterYOffsets[c], characterWidths[c], characterHeights[c], colour, 321 - alpha); 322 - } 323 - x += characterScreenWidths[c]; 324 - if ((random.nextInt() & 3) == 0) 325 - x++; 326 - } 327 - 328 - } 329 - 330 - public int getColour(String code) { 331 - if (code.equals("red")) 332 - return 0xff0000; 333 - if (code.equals("gre")) 334 - return 65280; 335 - if (code.equals("blu")) 336 - return 255; 337 - if (code.equals("yel")) 338 - return 0xffff00; 339 - if (code.equals("cya")) 340 - return 0x00ffff; 341 - if (code.equals("mag")) 342 - return 0xff00ff; 343 - if (code.equals("whi")) 344 - return 0xffffff; 345 - if (code.equals("bla")) 346 - return 0; 347 - if (code.equals("lre")) 348 - return 0xff9040; 349 - if (code.equals("dre")) 350 - return 0x800000; 351 - if (code.equals("dbl")) 352 - return 128; 353 - if (code.equals("or1")) 354 - return 0xffb000; 355 - if (code.equals("or2")) 356 - return 0xff7000; 357 - if (code.equals("or3")) 358 - return 0xff3000; 359 - if (code.equals("gr1")) 360 - return 0xc0ff00; 361 - if (code.equals("gr2")) 362 - return 0x80ff00; 363 - if (code.equals("gr3")) 364 - return 0x40ff00; 365 - if (code.equals("str")) 366 - strikethroughColor = 0; 367 - if (code.equals("end")) 368 - strikethroughColor = -1; 369 - return -1; 370 - } 371 - 372 - 373 - public void drawCharacter(int character, int x, int y, int width, int height, 374 - int colour) { 375 - int rasterizerPixel = x + y * Rasterizer.width; 376 - int rasterizerPixelOffset = Rasterizer.width - width; 377 - int characterPixelOffset = 0; 378 - int characterPixel = 0; 379 - if (y < Rasterizer.topY) { 380 - int offsetY = Rasterizer.topY - y; 381 - height -= offsetY; 382 - y = Rasterizer.topY; 383 - characterPixel += offsetY * width; 384 - rasterizerPixel += offsetY * Rasterizer.width; 385 - } 386 - if (y + height > Rasterizer.bottomY) { 387 - height -= y + height - Rasterizer.bottomY; 388 - } 389 - if (x < Rasterizer.topX) { 390 - int offsetX = Rasterizer.topX - x; 391 - width -= offsetX; 392 - x = Rasterizer.topX; 393 - characterPixel += offsetX; 394 - rasterizerPixel += offsetX; 395 - characterPixelOffset += offsetX; 396 - rasterizerPixelOffset += offsetX; 397 - } 398 - if (x + width > Rasterizer.bottomX) { 399 - int endOffsetX = x + width - Rasterizer.bottomX; 400 - width -= endOffsetX; 401 - characterPixelOffset += endOffsetX; 402 - rasterizerPixelOffset += endOffsetX; 403 - } 404 - if (width > 0 && height > 0) { 405 - drawCharacterPixels(characterPixels[character], Rasterizer.pixels, characterPixel, rasterizerPixel, 406 - characterPixelOffset, rasterizerPixelOffset, width, height, colour); 407 - 408 - } 409 - } 410 - 411 - 412 - public void drawCharacterLegacy(byte[] pixels, int x, int y, int width, int height, int colour) { 413 - int rasterizerPixel = x + y * Rasterizer.width; 414 - int remainingWidth = Rasterizer.width - width; 415 - int characterPixelOffset = 0; 416 - int characterPixel = 0; 417 - if (y < Rasterizer.topY) { 418 - int offsetY = Rasterizer.topY - y; 419 - height -= offsetY; 420 - y = Rasterizer.topY; 421 - characterPixel += offsetY * width; 422 - rasterizerPixel += offsetY * Rasterizer.width; 423 - } 424 - if (y + height >= Rasterizer.bottomY) 425 - height -= ((y + height) - Rasterizer.bottomY) + 1; 426 - if (x < Rasterizer.topX) { 427 - int offsetX = Rasterizer.topX - x; 428 - width -= offsetX; 429 - x = Rasterizer.topX; 430 - characterPixel += offsetX; 431 - rasterizerPixel += offsetX; 432 - characterPixelOffset += offsetX; 433 - remainingWidth += offsetX; 434 - } 435 - if (x + width >= Rasterizer.bottomX) { 436 - int endOffsetX = ((x + width) - Rasterizer.bottomX) + 1; 437 - width -= endOffsetX; 438 - characterPixelOffset += endOffsetX; 439 - remainingWidth += endOffsetX; 440 - } 441 - if (width > 0 && height > 0) { 442 - drawCharacterPixels(pixels, Rasterizer.pixels, characterPixel, rasterizerPixel, characterPixelOffset, remainingWidth, width, height, colour); 443 - } 444 - } 445 - 446 - public void drawCharacterPixels(byte[] characterPixels, int[] rasterizerPixels, int characterPixel, 447 - int rasterizerPixel, int characterPixelOffset, int rasterizerPixelOffset, int width, int height, int colour) { 448 - int negativeQuaterWidth = -(width >> 2); 449 - width = -(width & 3); 450 - for (int heightCounter = -height; heightCounter < 0; heightCounter++) { 451 - for (int widthCounter = negativeQuaterWidth; widthCounter < 0; widthCounter++) { 452 - if (characterPixels[characterPixel++] != 0) 453 - rasterizerPixels[rasterizerPixel++] = colour; 454 - else 455 - rasterizerPixel++; 456 - if (characterPixels[characterPixel++] != 0) 457 - rasterizerPixels[rasterizerPixel++] = colour; 458 - else 459 - rasterizerPixel++; 460 - if (characterPixels[characterPixel++] != 0) 461 - rasterizerPixels[rasterizerPixel++] = colour; 462 - else 463 - rasterizerPixel++; 464 - if (characterPixels[characterPixel++] != 0) 465 - rasterizerPixels[rasterizerPixel++] = colour; 466 - else 467 - rasterizerPixel++; 468 - } 469 - 470 - for (int widthCounter = width; widthCounter < 0; widthCounter++) 471 - if (characterPixels[characterPixel++] != 0) 472 - rasterizerPixels[rasterizerPixel++] = colour; 473 - else 474 - rasterizerPixel++; 475 - 476 - rasterizerPixel += rasterizerPixelOffset; 477 - characterPixel += characterPixelOffset; 478 - } 479 - 480 - } 481 - 482 - private void setEffectsAlpha(int color, int shadow, int opac) { 483 - strikethroughColor = -1; 484 - underlineColor = -1; 485 - defaultShadowColor = shadow; 486 - shadowColor = shadow; 487 - defaultTextColor = color; 488 - textColor = color; 489 - defaultOpacity = opac; 490 - opacity = opac; 491 - whiteSpace = 0; 492 - anInt3748 = 0; 493 - } 494 - 495 - public void parseStringForEffects(String string) { 496 - do { 497 - try { 498 - if (string.startsWith(startColor)) { 499 - String color = string.substring(4); 500 - textColor = color.length() < 6 ? Color.decode(color).getRGB() : Integer.parseInt(color, 16); 501 - 502 - } else if (string.equals(endColor)) { 503 - textColor = defaultTextColor; 504 - } else if (string.startsWith(startTrans)) { 505 - opacity = Integer.valueOf(string.substring(6)); 506 - } else if (string.equals(endTrans)) { 507 - opacity = defaultOpacity; 508 - } else if (string.startsWith(startStrikethrough)) { 509 - String color = string.substring(4); 510 - strikethroughColor = color.length() < 6 ? Color.decode(color).getRGB() : Integer.parseInt(color, 16); 511 - } else if (string.equals(startDefaultStrikeThrough)) { 512 - strikethroughColor = 8388608; 513 - } else if (string.equals(endStrikeThrough)) { 514 - strikethroughColor = -1; 515 - } else if (string.startsWith(startUnderline)) { 516 - String color = string.substring(2); 517 - underlineColor = color.length() < 6 ? Color.decode(color).getRGB() : Integer.parseInt(color, 16); 518 - } else if (string.equals(startDefaultUnderline)) { 519 - underlineColor = 0; 520 - } else if (string.equals(endUnderline)) { 521 - underlineColor = -1; 522 - } else if (string.startsWith(startShadow)) { 523 - String color = string.substring(5); 524 - shadowColor = color.length() < 6 ? Color.decode(color).getRGB() : Integer.parseInt(color, 16); 525 - } else if (string.equals(startDefaultShadow)) { 526 - shadowColor = 0; 527 - } else if (string.equals(endShadow)) { 528 - shadowColor = defaultShadowColor; 529 - } else { 530 - if (!string.equals(lineBreak)) { 531 - break; 532 - } 533 - setEffectsAlpha(defaultTextColor, defaultShadowColor, defaultOpacity); 534 - } 535 - } catch (Exception exception) { 536 - break; 537 - } 538 - break; 539 - } while (false); 540 - } 541 - 542 - public final void drawBasicStringXYMods(String string, int drawX, int drawY, int[] xmodifiers, int[] ymodifiers) { 543 - drawY -= characterDefaultHeight; 544 - int effect = -1; 545 - int var7 = 0; 546 - int modifier = 0; 547 - int length = string.length(); 548 - 549 - for (int pos = 0; pos < length; ++pos) { 550 - int character = string.charAt(pos); 551 - if (character == 60) { 552 - effect = pos; 553 - } else { 554 - int xOff; 555 - int yOffset; 556 - int symbolWidth; 557 - if (character == 62 && effect != -1) { 558 - String symbol = string.substring(pos, effect + 1); 559 - effect = -1; 560 - if (symbol.equals(lessThan)) { 561 - character = 60; 562 - } else if (symbol.equals(greaterThan)) { 563 - character = 62; 564 - } else if (symbol.equals(nonBreakingSpace)) { 565 - character = 160; 566 - } else if (symbol.equals(softHyphen)) { 567 - character = 173; 568 - } else if (symbol.equals(multiplicationSymbol)) { 569 - character = 215; 570 - } else if (symbol.equals(euroSymbol)) { 571 - character = 128; 572 - } else if (symbol.equals(copyright)) { 573 - character = 169; 574 - } else { 575 - if (!symbol.equals(registeredTrademark)) { 576 - if (symbol.startsWith(image, 0)) { 577 - try { 578 - if (xmodifiers != null) { 579 - xOff = xmodifiers[modifier]; 580 - } else { 581 - xOff = 0; 582 - } 583 - 584 - if (ymodifiers != null) { 585 - yOffset = ymodifiers[modifier]; 586 - } else { 587 - yOffset = 0; 588 - } 589 - 590 - ++modifier; 591 - symbolWidth = Integer.parseInt(symbol.substring(4)); 592 - ImageRGB image = moderatorIcon[symbolWidth]; 593 - int imageHeight = imageWidths != null ? imageWidths[symbolWidth] : image.maxHeight; 594 - if (opacity == 256) { 595 - image.drawImage(drawX + xOff, drawY + characterDefaultHeight - imageHeight + yOffset); 596 - } else { 597 - image.drawImageAlpha( 598 - drawX + xOff, drawY + characterDefaultHeight - imageHeight + yOffset, opacity); 599 - } 600 - 601 - drawX += image.width; 602 - var7 = 0; 603 - } catch (Exception var18) { 604 - } 605 - } else { 606 - parseStringForEffects(symbol); 607 - } 608 - continue; 609 - } 610 - 611 - character = 174; 612 - } 613 - } 614 - if (character == '@' && character + 4 < string.length() && string.charAt(character + 4) == '@') { 615 - int stringColour = getColour(string.substring(character + 1, character + 4)); 616 - if (stringColour != -1) 617 - textColor = stringColour; 618 - pos += 4; 619 - continue; 620 - } 621 - 622 - if (effect == -1) { 623 - int cWidth = characterWidths[character]; 624 - xOff = characterHeights[character]; 625 - if (xmodifiers != null) { 626 - yOffset = xmodifiers[modifier]; 627 - } else { 628 - yOffset = 0; 629 - } 630 - 631 - if (ymodifiers != null) { 632 - symbolWidth = ymodifiers[modifier]; 633 - } else { 634 - symbolWidth = 0; 635 - } 636 - 637 - ++modifier; 638 - if (character != 32) { 639 - if (opacity == 256) { 640 - if (shadowColor != -1) { 641 - drawCharacter(character, drawX + characterXOffsets[character] + 1 + yOffset, drawY + characterYOffsets[character] + 1 + symbolWidth, cWidth, xOff, shadowColor); 642 - } 643 - 644 - drawCharacter(character, drawX + characterXOffsets[character] + yOffset, drawY + characterYOffsets[character] + symbolWidth, cWidth, xOff, textColor); 645 - } else { 646 - if (shadowColor != -1) { 647 - drawCharacterAlpha(character, drawX + characterXOffsets[character] + 1 + yOffset, drawY + characterYOffsets[character] + 1 + symbolWidth, cWidth, xOff, shadowColor, opacity); 648 - } 649 - 650 - drawCharacterAlpha(character, drawX + characterXOffsets[character] + yOffset, drawY + characterYOffsets[character] + symbolWidth, cWidth, xOff, textColor, opacity); 651 - } 652 - } else if (whiteSpace > 0) { 653 - anInt3748 += whiteSpace; 654 - drawX += anInt3748 >> 8; 655 - anInt3748 &= 255; 656 - } 657 - 658 - int charWidth = characterScreenWidths[character]; 659 - if (strikethroughColor != -1) { 660 - if (opacity > 255) { 661 - Rasterizer.drawHorizontalLine(drawX, drawY + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor); 662 - } else { 663 - Rasterizer.drawHorizontalLineAlpha(drawX, drawY + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor, opacity); 664 - 665 - } 666 - } 667 - 668 - if (underlineColor != -1) { 669 - if (opacity > 255) { 670 - Rasterizer.drawHorizontalLine(drawX, drawY + characterDefaultHeight, charWidth, underlineColor); 671 - 672 - } else { 673 - 674 - Rasterizer.drawHorizontalLineAlpha(drawX, drawY + characterDefaultHeight, charWidth, underlineColor, opacity); 675 - } 676 - } 677 - 678 - drawX += charWidth; 679 - var7 = character; 680 - } 681 - } 682 - } 683 - 684 - } 685 - 686 - public void drawString(String string, int x, int y, int color, int shadow) { 687 - if (string != null) { 688 - setEffects(color, shadow); 689 - drawBasicString(string, x, y); 690 - } 691 - } 692 - 693 - 694 - public void drawStringAlignedLeft(String string, int x, int y, int color, int shadow) { 695 - if (string != null) { 696 - setEffects(color, shadow); 697 - drawBasicString(string, x - getDisplayedWidth(string), y); 698 - } 699 - } 700 - 701 - public void drawStringWave(String string, int x, int y, int color, int shadow, int var6) { 702 - if (string != null) { 703 - setEffects(color, shadow); 704 - int length = string.length(); 705 - int[] var8 = new int[length]; 706 - int[] var9 = new int[length]; 707 - 708 - for (int pos = 0; pos < length; ++pos) { 709 - var8[pos] = (int) (Math.sin((double) pos / 5.0D + (double) var6 / 5.0D) * 5.0D); 710 - var9[pos] = (int) (Math.sin((double) pos / 3.0D + (double) var6 / 5.0D) * 5.0D); 711 - } 712 - 713 - drawBasicStringXYMods(string, x - getDisplayedWidth(string) / 2, y, var8, var9); 714 - } 715 - } 716 - 717 - public void drawStringWaveY(String string, int x, int y, int color, int shadow, int tick) { 718 - if (string != null) { 719 - setEffects(color, shadow); 720 - int var7 = string.length(); 721 - int[] vertWaveOffset = new int[var7]; 722 - 723 - for (int whichChar = 0; whichChar < var7; ++whichChar) { 724 - vertWaveOffset[whichChar] = (int) (Math.sin((double) whichChar / 2.0D + (double) tick / 5.0D) * 5.0D); 725 - } 726 - 727 - drawBasicStringXYMods(string, x - getDisplayedWidth(string) / 2, y, (int[]) null, vertWaveOffset); 728 - } 729 - } 730 - 731 - 732 - public void drawCenteredStringXMod(String var1, int var2, int var3, int var4, int var5, int var6, int var7) { 733 - if (var1 != null) { 734 - setEffects(var4, var5); 735 - double amplitude = 7.0D - (double) var7 / 8.0D; 736 - if (amplitude < 0.0D) { 737 - amplitude = 0.0D; 738 - } 739 - 740 - int length = var1.length(); 741 - int[] xmod = new int[length]; 742 - 743 - for (int pos = 0; pos < length; ++pos) { 744 - xmod[pos] = (int) (Math.sin((double) pos / 1.5D + (double) var6 / 1.0D) * amplitude); 745 - } 746 - 747 - drawBasicStringXYMods(var1, var2 - getDisplayedWidth(var1) / 2, var3, (int[]) null, xmod); 748 - } 749 - } 750 - 751 - 752 - private void setEffects(int color, int shadow) { 753 - strikethroughColor = -1; 754 - underlineColor = -1; 755 - defaultShadowColor = shadow; 756 - shadowColor = shadow; 757 - defaultTextColor = color; 758 - textColor = color; 759 - defaultOpacity = 256; 760 - opacity = 256; 761 - whiteSpace = 0; 762 - anInt3748 = 0; 763 - } 764 - 765 - public void drawBasicString(String string, int x, int y) { 766 - y -= characterDefaultHeight; 767 - int effectIndex = -1; 768 - int var5 = 0; 769 - int textLength = string.length(); 770 - 771 - for (int character = 0; character < textLength; ++character) { 772 - int c = string.charAt(character); 773 - if (c > 255) { 774 - c = 32; 775 - } 776 - if (c == 60) { 777 - effectIndex = character; 778 - 779 - } else { 780 - if (c == 62 && effectIndex != -1) { 781 - 782 - String effectString = string.substring(effectIndex + 1, character); 783 - effectIndex = -1; 784 - if (effectString.equals(lessThan)) { 785 - c = 60; 786 - } else if (effectString.equals(greaterThan)) { 787 - c = 62; 788 - } else if (effectString.equals(nonBreakingSpace)) { 789 - c = 160; 790 - } else if (effectString.equals(softHyphen)) { 791 - c = 173; 792 - } else if (effectString.equals(multiplicationSymbol)) { 793 - c = 215; 794 - } else if (effectString.equals(euroSymbol)) { 795 - c = 128; 796 - } else if (effectString.equals(copyright)) { 797 - c = 169; 798 - } else { 799 - if (!effectString.equals(registeredTrademark)) { 800 - if (effectString.startsWith(image, 0)) { 801 - try { 802 - int icon = Integer.valueOf(effectString.substring(4)); 803 - ImageRGB nameIcon = moderatorIcon[icon]; 804 - int imageHeight = imageWidths != null ? imageWidths[icon] : nameIcon.maxHeight; 805 - if (opacity == 256) { 806 - nameIcon.drawImage(x, y + characterDefaultHeight - imageHeight); 807 - } else { 808 - nameIcon.drawImageAlpha(x, y + characterDefaultHeight - imageHeight, opacity); 809 - } 810 - 811 - x += nameIcon.maxWidth; 812 - var5 = 0; 813 - } catch (Exception e) { 814 - 815 - } 816 - } else { 817 - parseStringForEffects(effectString); 818 - } 819 - continue; 820 - } 821 - c = 174; 822 - } 823 - } 824 - if (c == '@' && character + 4 < string.length() && string.charAt(character + 4) == '@') { 825 - int stringColour = getColour(string.substring(character + 1, character + 4)); 826 - if (stringColour != -1) 827 - textColor = stringColour; 828 - character += 4; 829 - continue; 830 - } 831 - if (effectIndex == -1) { 832 - int width = characterWidths[c]; 833 - int height = characterHeights[c]; 834 - if (c != 32) { 835 - if (opacity == 256) { 836 - 837 - if (shadowColor != -1) { 838 - drawCharacter(c, x + characterXOffsets[c] + 1, y + characterYOffsets[c] + 1, width, height, shadowColor); 839 - } 840 - 841 - drawCharacter(c, x + characterXOffsets[c], y + characterYOffsets[c], width, height, textColor); 842 - } else { 843 - 844 - if (shadowColor != -1) { 845 - drawCharacterAlpha(c, x + characterXOffsets[c] + 1, y + characterYOffsets[c] + 1, width, height, shadowColor, opacity); 846 - 847 - } 848 - drawCharacterAlpha(c, x + characterXOffsets[c], y + characterYOffsets[c], width, height, textColor, opacity); 849 - } 850 - } else if (whiteSpace > 0) { 851 - anInt3748 += whiteSpace; 852 - x += anInt3748 >> 8; 853 - anInt3748 &= 255; 854 - } 855 - 856 - int charWidth = characterScreenWidths[c]; 857 - if (strikethroughColor != -1) { 858 - Rasterizer.drawHorizontalLine(x, y + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor); 859 - } 860 - if (underlineColor != -1) { 861 - Rasterizer.drawHorizontalLine(x, y + characterDefaultHeight + 1, charWidth, underlineColor); 862 - } 863 - x += charWidth; 864 - var5 = c; 865 - } 866 - } 867 - } 868 - 869 - } 870 - 871 - public void drawCharacterAlpha(int character, int x, int y, int width, int height, 872 - int colour, int alpha) { 873 - this.drawAlphaCharacter(characterPixels[character], x, y, width, height, colour, alpha); 874 - } 875 - 876 - public void drawAlphaCharacter(byte[] characterPixels, int x, int y, int width, int height, int colour, 877 - int alpha) { 878 - int rasterizerPixel = x + y * Rasterizer.width; 879 - int rasterizerPixelOffset = Rasterizer.width - width; 880 - int characterPixelOffset = 0; 881 - int characterPixel = 0; 882 - if (y < Rasterizer.topY) { 883 - int yOffset = Rasterizer.topY - y; 884 - height -= yOffset; 885 - y = Rasterizer.topY; 886 - characterPixel += yOffset * width; 887 - rasterizerPixel += yOffset * Rasterizer.width; 888 - } 889 - if (y + height >= Rasterizer.bottomY) 890 - height -= ((y + height) - Rasterizer.bottomY) + 1; 891 - if (x < Rasterizer.topX) { 892 - int xOffset = Rasterizer.topX - x; 893 - width -= xOffset; 894 - x = Rasterizer.topX; 895 - characterPixel += xOffset; 896 - rasterizerPixel += xOffset; 897 - characterPixelOffset += xOffset; 898 - rasterizerPixelOffset += xOffset; 899 - } 900 - if (x + width >= Rasterizer.bottomX) { 901 - int widthoffset = ((x + width) - Rasterizer.bottomX) + 1; 902 - width -= widthoffset; 903 - characterPixelOffset += widthoffset; 904 - rasterizerPixelOffset += widthoffset; 905 - } 906 - if (width > 0 && height > 0) { 907 - drawCharacterPixelsAlpha(characterPixel, rasterizerPixelOffset, characterPixelOffset, rasterizerPixel, alpha, Rasterizer.pixels, colour, height, width, characterPixels); 908 - } 909 - } 910 - 911 - 912 - public void drawCharacterPixelsAlpha(int characterPixel, int rasterizerPixelOffset, int characterPixelOffset, 913 - int rasterizerPixel, int alpha, 914 - int[] rasterizerPixels, int colour, int height, int width, 915 - byte[] characterPixels) { 916 - colour = ((colour & 0xff00ff) * alpha & 0xff00ff00) + ((colour & 0xff00) * alpha & 0xff0000) >> 8; 917 - alpha = 256 - alpha; 918 - for (int heightCounter = -height; heightCounter < 0; heightCounter++) { 919 - for (int widthCounter = -width; widthCounter < 0; widthCounter++) 920 - if (characterPixels[characterPixel++] != 0) { 921 - int rasterizerPixelColor = rasterizerPixels[rasterizerPixel]; 922 - rasterizerPixels[rasterizerPixel++] = (((rasterizerPixelColor & 0xff00ff) * alpha & 0xff00ff00) + ((rasterizerPixelColor & 0xff00) * alpha & 0xff0000) >> 8) + colour; 923 - } else { 924 - rasterizerPixel++; 925 - } 926 - 927 - rasterizerPixel += rasterizerPixelOffset; 928 - characterPixel += characterPixelOffset; 929 - } 930 - 931 - } 932 - 933 - public void setNameIcons(ImageRGB[] images, int[] widths) { 934 - if (widths != null && widths.length != images.length) { 935 - throw new IllegalArgumentException(); 936 - } else { 937 - moderatorIcon = images; 938 - imageWidths = widths; 939 - } 940 - } 941 - }
+841
src/main/java/com/jagex/runescape/cache/media/TypeFace.kt
··· 1 + package com.jagex.runescape.cache.media 2 + 3 + import com.jagex.runescape.cache.Archive 4 + import com.jagex.runescape.media.Rasterizer 5 + import com.jagex.runescape.net.Buffer 6 + import java.awt.Color 7 + import java.util.Random 8 + 9 + class TypeFace(monospace: Boolean, archive: Archive, archiveName: String) : Rasterizer() { 10 + 11 + @JvmField var characterPixels: Array<ByteArray?> = arrayOfNulls(256) 12 + @JvmField var characterWidths: IntArray = IntArray(256) 13 + @JvmField var characterHeights: IntArray = IntArray(256) 14 + @JvmField var characterXOffsets: IntArray = IntArray(256) 15 + @JvmField var characterYOffsets: IntArray = IntArray(256) 16 + @JvmField var characterScreenWidths: IntArray = IntArray(256) 17 + @JvmField var characterDefaultHeight: Int = 0 18 + @JvmField var random: Random = Random() 19 + 20 + private var moderatorIcon: Array<ImageRGB>? = null 21 + private var imageWidths: IntArray? = null 22 + 23 + init { 24 + val dataBuffer = Buffer(archive.getFile("$archiveName.dat")!!) 25 + val indexBuffer = Buffer(archive.getFile("index.dat")!!) 26 + indexBuffer.currentPosition = dataBuffer.getUnsignedShortBE() + 4 27 + val k = indexBuffer.getUnsignedByte() 28 + if (k > 0) 29 + indexBuffer.currentPosition += 3 * (k - 1) 30 + for (character in 0 until 256) { 31 + characterXOffsets[character] = indexBuffer.getUnsignedByte() 32 + characterYOffsets[character] = indexBuffer.getUnsignedByte() 33 + val characterWidth = indexBuffer.getUnsignedShortBE() 34 + characterWidths[character] = characterWidth 35 + val characterHeight = indexBuffer.getUnsignedShortBE() 36 + characterHeights[character] = characterHeight 37 + val characterType = indexBuffer.getUnsignedByte() 38 + val characterSize = characterWidth * characterHeight 39 + characterPixels[character] = ByteArray(characterSize) 40 + if (characterType == 0) { 41 + for (pixel in 0 until characterSize) 42 + characterPixels[character]!![pixel] = dataBuffer.getByte() 43 + } else if (characterType == 1) { 44 + for (characterX in 0 until characterWidth) 45 + for (characterY in 0 until characterHeight) 46 + characterPixels[character]!![characterX + characterY * characterWidth] = dataBuffer.getByte() 47 + } 48 + if (characterHeight > characterDefaultHeight && character < 128) 49 + characterDefaultHeight = characterHeight 50 + characterXOffsets[character] = 1 51 + characterScreenWidths[character] = characterWidth + 2 52 + var pixelCount = 0 53 + for (characterY in characterHeight / 7 until characterHeight) 54 + pixelCount += characterPixels[character]!![characterY * characterWidth].toInt() 55 + if (pixelCount <= characterHeight / 7) { 56 + characterScreenWidths[character]-- 57 + characterXOffsets[character] = 0 58 + } 59 + pixelCount = 0 60 + for (characterY in characterHeight / 7 until characterHeight) 61 + pixelCount += characterPixels[character]!![(characterWidth - 1) + characterY * characterWidth].toInt() 62 + if (pixelCount <= characterHeight / 7) 63 + characterScreenWidths[character]-- 64 + } 65 + if (monospace) { 66 + characterScreenWidths[32] = characterScreenWidths[73] 67 + } else { 68 + characterScreenWidths[32] = characterScreenWidths[105] 69 + } 70 + } 71 + 72 + fun drawStringRight(string: String, x: Int, y: Int, colour: Int) { 73 + drawString(string, x - getDisplayedWidth(string), y, colour) 74 + } 75 + 76 + fun drawStringLeft(string: String, x: Int, y: Int, colour: Int) { 77 + drawString(string, x - getDisplayedWidth(string) / 2, y, colour) 78 + } 79 + 80 + fun drawStringCenter(string: String, x: Int, y: Int, colour: Int, shadowed: Boolean) { 81 + drawShadowedString(string, x - getStringEffectWidth(string) / 2, y, shadowed, colour) 82 + } 83 + 84 + fun getStringEffectWidth(string: String): Int { 85 + return getDisplayedWidth(string) 86 + } 87 + 88 + fun getDisplayedWidth(string: String?): Int { 89 + if (string == null) return 0 90 + var index = -1 91 + var width = 0 92 + val length = string.length 93 + for (idx in 0 until length) { 94 + var character = string[idx].code 95 + if (character == 60) { 96 + index = idx 97 + } else { 98 + if (character == 62 && index != -1) { 99 + val effect = string.substring(index + 1, idx) 100 + index = -1 101 + if (effect == lessThan) character = 60 102 + else if (effect == greaterThan) character = 62 103 + else if (effect == nonBreakingSpace) character = 160 104 + else if (effect == softHyphen) character = 173 105 + else if (effect == multiplicationSymbol) character = 215 106 + else if (effect == euroSymbol) character = 128 107 + else if (effect == copyright) character = 169 108 + else { 109 + if (effect != registeredTrademark) { 110 + if (effect.startsWith(image, 0)) { 111 + try { 112 + val icon = effect.substring(4).toInt() 113 + width += moderatorIcon!![icon].maxWidth 114 + } catch (_: Exception) { 115 + } 116 + } 117 + continue 118 + } 119 + character = 174 120 + } 121 + } 122 + if (character == '@'.code && idx + 4 < string.length && string[idx + 4] == '@') { 123 + @Suppress("NAME_SHADOWING") 124 + var idx = idx 125 + idx += 4 126 + continue 127 + } 128 + if (index == -1) { 129 + width += characterScreenWidths[character] 130 + } 131 + } 132 + } 133 + return width 134 + } 135 + 136 + fun drawString(string: String?, x: Int, y: Int, colour: Int) { 137 + if (this.moderatorIcon != null) { 138 + this.drawString(string, x, y, colour, -1) 139 + } else { 140 + if (string == null) return 141 + var drawX = x 142 + val drawY = y - characterDefaultHeight 143 + for (index in string.indices) { 144 + val character = string[index] 145 + if (character != ' ') 146 + drawCharacterLegacy( 147 + characterPixels[character.code]!!, 148 + drawX + characterXOffsets[character.code], 149 + drawY + characterYOffsets[character.code], 150 + characterWidths[character.code], 151 + characterHeights[character.code], colour 152 + ) 153 + drawX += characterScreenWidths[character.code] 154 + } 155 + } 156 + } 157 + 158 + fun drawCenteredStringWaveY(string: String?, x: Int, y: Int, wave: Int, colour: Int) { 159 + if (string == null) return 160 + var drawX = x - getDisplayedWidth(string) / 2 161 + val drawY = y - characterDefaultHeight 162 + for (index in string.indices) { 163 + val character = string[index] 164 + if (character != ' ') 165 + drawCharacterLegacy( 166 + characterPixels[character.code]!!, 167 + drawX + characterXOffsets[character.code], 168 + drawY + characterYOffsets[character.code] + (Math.sin(index / 2.0 + wave / 5.0) * 5.0).toInt(), 169 + characterWidths[character.code], characterHeights[character.code], colour 170 + ) 171 + drawX += characterScreenWidths[character.code] 172 + } 173 + } 174 + 175 + fun drawCenteredString(text: String?, x: Int, y: Int, color: Int, shadow: Int) { 176 + if (text != null) { 177 + setEffects(color, shadow) 178 + drawBasicString(text, x - getDisplayedWidth(text) / 2, y) 179 + } 180 + } 181 + 182 + fun drawCenteredStringWaveXY(string: String?, x: Int, y: Int, wave: Int, colour: Int) { 183 + if (string == null) return 184 + var drawX = x - getDisplayedWidth(string) / 2 185 + val drawY = y - characterDefaultHeight 186 + for (index in string.indices) { 187 + val character = string[index] 188 + if (character != ' ') 189 + drawCharacterLegacy( 190 + characterPixels[character.code]!!, 191 + drawX + characterXOffsets[character.code] + (Math.sin(index / 5.0 + wave / 5.0) * 5.0).toInt(), 192 + drawY + characterYOffsets[character.code] + (Math.sin(index / 3.0 + wave / 5.0) * 5.0).toInt(), 193 + characterWidths[character.code], characterHeights[character.code], colour 194 + ) 195 + drawX += characterScreenWidths[character.code] 196 + } 197 + } 198 + 199 + fun drawCenteredStringWaveXYMove(string: String?, x: Int, y: Int, waveAmount: Int, waveSpeed: Int, colour: Int) { 200 + if (string == null) return 201 + var speed = 7.0 - waveSpeed / 8.0 202 + if (speed < 0.0) speed = 0.0 203 + var drawX = x - getDisplayedWidth(string) / 2 204 + val drawY = y - characterDefaultHeight 205 + for (index in string.indices) { 206 + val character = string[index] 207 + if (character != ' ') 208 + drawCharacterLegacy( 209 + characterPixels[character.code]!!, 210 + drawX + characterXOffsets[character.code], 211 + drawY + characterYOffsets[character.code] + (Math.sin(index / 1.5 + waveAmount.toDouble()) * speed).toInt(), 212 + characterWidths[character.code], characterHeights[character.code], colour 213 + ) 214 + drawX += characterScreenWidths[character.code] 215 + } 216 + } 217 + 218 + fun drawShadowedString(string: String?, x: Int, y: Int, shadow: Boolean, colour: Int) { 219 + if (!shadow) { 220 + drawString(string, x, y, colour) 221 + return 222 + } 223 + if (this.moderatorIcon != null) { 224 + this.drawString(string, x, y, colour, 0) 225 + } else { 226 + strikethroughColor = -1 227 + val originalX = x 228 + if (string == null) return 229 + var drawX = x 230 + var drawColour = colour 231 + val drawY = y - characterDefaultHeight 232 + var character = 0 233 + while (character < string.length) { 234 + if (string[character] == '@' && character + 4 < string.length && string[character + 4] == '@') { 235 + val stringColour = getColour(string.substring(character + 1, character + 4)) 236 + if (stringColour != -1) drawColour = stringColour 237 + character += 4 238 + } else { 239 + val c = string[character] 240 + if (c != ' ') { 241 + if (shadow) 242 + drawCharacterLegacy( 243 + characterPixels[c.code]!!, drawX + characterXOffsets[c.code] + 1, 244 + drawY + characterYOffsets[c.code] + 1, characterWidths[c.code], characterHeights[c.code], 0 245 + ) 246 + drawCharacterLegacy( 247 + characterPixels[c.code]!!, drawX + characterXOffsets[c.code], 248 + drawY + characterYOffsets[c.code], characterWidths[c.code], characterHeights[c.code], drawColour 249 + ) 250 + } 251 + drawX += characterScreenWidths[c.code] 252 + } 253 + character++ 254 + } 255 + if (strikethroughColor != -1) 256 + Rasterizer.drawHorizontalLine(originalX, drawY + (characterDefaultHeight * 0.7).toInt(), drawX - originalX, strikethroughColor) 257 + } 258 + } 259 + 260 + fun drawShadowedSeededAlphaString(string: String?, x: Int, y: Int, colour: Int, seed: Int) { 261 + if (string == null) return 262 + random.setSeed(seed.toLong()) 263 + val alpha = 192 + (random.nextInt() and 0x1f) 264 + var drawX = x 265 + var drawColour = colour 266 + val drawY = y - characterDefaultHeight 267 + var index = 0 268 + while (index < string.length) { 269 + if (string[index] == '@' && index + 4 < string.length && string[index + 4] == '@') { 270 + val stringColour = getColour(string.substring(index + 1, index + 4)) 271 + if (stringColour != -1) drawColour = stringColour 272 + index += 4 273 + } else { 274 + val c = string[index] 275 + if (c != ' ') { 276 + drawAlphaCharacter( 277 + characterPixels[c.code]!!, drawX + characterXOffsets[c.code] + 1, 278 + drawY + characterYOffsets[c.code] + 1, characterWidths[c.code], characterHeights[c.code], 0, 192 279 + ) 280 + drawAlphaCharacter( 281 + characterPixels[c.code]!!, drawX + characterXOffsets[c.code], 282 + drawY + characterYOffsets[c.code], characterWidths[c.code], characterHeights[c.code], drawColour, alpha 283 + ) 284 + } 285 + drawX += characterScreenWidths[c.code] 286 + if ((random.nextInt() and 3) == 0) 287 + drawX++ 288 + } 289 + index++ 290 + } 291 + } 292 + 293 + fun getColour(code: String): Int { 294 + if (code == "red") return 0xff0000 295 + if (code == "gre") return 65280 296 + if (code == "blu") return 255 297 + if (code == "yel") return 0xffff00 298 + if (code == "cya") return 0x00ffff 299 + if (code == "mag") return 0xff00ff 300 + if (code == "whi") return 0xffffff 301 + if (code == "bla") return 0 302 + if (code == "lre") return 0xff9040 303 + if (code == "dre") return 0x800000 304 + if (code == "dbl") return 128 305 + if (code == "or1") return 0xffb000 306 + if (code == "or2") return 0xff7000 307 + if (code == "or3") return 0xff3000 308 + if (code == "gr1") return 0xc0ff00 309 + if (code == "gr2") return 0x80ff00 310 + if (code == "gr3") return 0x40ff00 311 + if (code == "str") strikethroughColor = 0 312 + if (code == "end") strikethroughColor = -1 313 + return -1 314 + } 315 + 316 + fun drawCharacter(character: Int, x: Int, y: Int, width: Int, height: Int, colour: Int) { 317 + var drawX = x 318 + var drawY = y 319 + var drawW = width 320 + var drawH = height 321 + var rasterizerPixel = drawX + drawY * Rasterizer.width 322 + var rasterizerPixelOffset = Rasterizer.width - drawW 323 + var characterPixelOffset = 0 324 + var characterPixel = 0 325 + if (drawY < Rasterizer.topY) { 326 + val offsetY = Rasterizer.topY - drawY 327 + drawH -= offsetY 328 + drawY = Rasterizer.topY 329 + characterPixel += offsetY * drawW 330 + rasterizerPixel += offsetY * Rasterizer.width 331 + } 332 + if (drawY + drawH > Rasterizer.bottomY) 333 + drawH -= drawY + drawH - Rasterizer.bottomY 334 + if (drawX < Rasterizer.topX) { 335 + val offsetX = Rasterizer.topX - drawX 336 + drawW -= offsetX 337 + drawX = Rasterizer.topX 338 + characterPixel += offsetX 339 + rasterizerPixel += offsetX 340 + characterPixelOffset += offsetX 341 + rasterizerPixelOffset += offsetX 342 + } 343 + if (drawX + drawW > Rasterizer.bottomX) { 344 + val endOffsetX = drawX + drawW - Rasterizer.bottomX 345 + drawW -= endOffsetX 346 + characterPixelOffset += endOffsetX 347 + rasterizerPixelOffset += endOffsetX 348 + } 349 + if (drawW > 0 && drawH > 0) { 350 + drawCharacterPixels( 351 + characterPixels[character]!!, Rasterizer.pixels, characterPixel, rasterizerPixel, 352 + characterPixelOffset, rasterizerPixelOffset, drawW, drawH, colour 353 + ) 354 + } 355 + } 356 + 357 + fun drawCharacterLegacy(pixels: ByteArray, x: Int, y: Int, width: Int, height: Int, colour: Int) { 358 + var drawX = x 359 + var drawY = y 360 + var drawW = width 361 + var drawH = height 362 + var rasterizerPixel = drawX + drawY * Rasterizer.width 363 + var remainingWidth = Rasterizer.width - drawW 364 + var characterPixelOffset = 0 365 + var characterPixel = 0 366 + if (drawY < Rasterizer.topY) { 367 + val offsetY = Rasterizer.topY - drawY 368 + drawH -= offsetY 369 + drawY = Rasterizer.topY 370 + characterPixel += offsetY * drawW 371 + rasterizerPixel += offsetY * Rasterizer.width 372 + } 373 + if (drawY + drawH >= Rasterizer.bottomY) 374 + drawH -= ((drawY + drawH) - Rasterizer.bottomY) + 1 375 + if (drawX < Rasterizer.topX) { 376 + val offsetX = Rasterizer.topX - drawX 377 + drawW -= offsetX 378 + drawX = Rasterizer.topX 379 + characterPixel += offsetX 380 + rasterizerPixel += offsetX 381 + characterPixelOffset += offsetX 382 + remainingWidth += offsetX 383 + } 384 + if (drawX + drawW >= Rasterizer.bottomX) { 385 + val endOffsetX = ((drawX + drawW) - Rasterizer.bottomX) + 1 386 + drawW -= endOffsetX 387 + characterPixelOffset += endOffsetX 388 + remainingWidth += endOffsetX 389 + } 390 + if (drawW > 0 && drawH > 0) { 391 + drawCharacterPixels(pixels, Rasterizer.pixels, characterPixel, rasterizerPixel, characterPixelOffset, remainingWidth, drawW, drawH, colour) 392 + } 393 + } 394 + 395 + fun drawCharacterPixels( 396 + characterPixels: ByteArray, rasterizerPixels: IntArray, characterPixel: Int, 397 + rasterizerPixel: Int, characterPixelOffset: Int, rasterizerPixelOffset: Int, 398 + width: Int, height: Int, colour: Int 399 + ) { 400 + val negativeQuaterWidth = -(width shr 2) 401 + val remainingWidth = -(width and 3) 402 + var rPixel = rasterizerPixel 403 + var cPixel = characterPixel 404 + for (heightCounter in -height until 0) { 405 + for (widthCounter in negativeQuaterWidth until 0) { 406 + // byte != 0 check: must use .toInt() since Kotlin Byte can't compare to Int directly 407 + if (characterPixels[cPixel++].toInt() != 0) 408 + rasterizerPixels[rPixel++] = colour 409 + else 410 + rPixel++ 411 + if (characterPixels[cPixel++].toInt() != 0) 412 + rasterizerPixels[rPixel++] = colour 413 + else 414 + rPixel++ 415 + if (characterPixels[cPixel++].toInt() != 0) 416 + rasterizerPixels[rPixel++] = colour 417 + else 418 + rPixel++ 419 + if (characterPixels[cPixel++].toInt() != 0) 420 + rasterizerPixels[rPixel++] = colour 421 + else 422 + rPixel++ 423 + } 424 + for (widthCounter in remainingWidth until 0) 425 + if (characterPixels[cPixel++].toInt() != 0) 426 + rasterizerPixels[rPixel++] = colour 427 + else 428 + rPixel++ 429 + rPixel += rasterizerPixelOffset 430 + cPixel += characterPixelOffset 431 + } 432 + } 433 + 434 + private fun setEffectsAlpha(color: Int, shadow: Int, opac: Int) { 435 + strikethroughColor = -1 436 + underlineColor = -1 437 + defaultShadowColor = shadow 438 + shadowColor = shadow 439 + defaultTextColor = color 440 + textColor = color 441 + defaultOpacity = opac 442 + opacity = opac 443 + whiteSpace = 0 444 + anInt3748 = 0 445 + } 446 + 447 + fun parseStringForEffects(string: String) { 448 + do { 449 + try { 450 + if (string.startsWith(startColor)) { 451 + val color = string.substring(4) 452 + textColor = if (color.length < 6) Color.decode(color).rgb else color.toInt(16) 453 + } else if (string == endColor) { 454 + textColor = defaultTextColor 455 + } else if (string.startsWith(startTrans)) { 456 + opacity = string.substring(6).toInt() 457 + } else if (string == endTrans) { 458 + opacity = defaultOpacity 459 + } else if (string.startsWith(startStrikethrough)) { 460 + val color = string.substring(4) 461 + strikethroughColor = if (color.length < 6) Color.decode(color).rgb else color.toInt(16) 462 + } else if (string == startDefaultStrikeThrough) { 463 + strikethroughColor = 8388608 464 + } else if (string == endStrikeThrough) { 465 + strikethroughColor = -1 466 + } else if (string.startsWith(startUnderline)) { 467 + val color = string.substring(2) 468 + underlineColor = if (color.length < 6) Color.decode(color).rgb else color.toInt(16) 469 + } else if (string == startDefaultUnderline) { 470 + underlineColor = 0 471 + } else if (string == endUnderline) { 472 + underlineColor = -1 473 + } else if (string.startsWith(startShadow)) { 474 + val color = string.substring(5) 475 + shadowColor = if (color.length < 6) Color.decode(color).rgb else color.toInt(16) 476 + } else if (string == startDefaultShadow) { 477 + shadowColor = 0 478 + } else if (string == endShadow) { 479 + shadowColor = defaultShadowColor 480 + } else { 481 + if (string != lineBreak) break 482 + setEffectsAlpha(defaultTextColor, defaultShadowColor, defaultOpacity) 483 + } 484 + } catch (_: Exception) { 485 + break 486 + } 487 + break 488 + } while (false) 489 + } 490 + 491 + fun drawBasicStringXYMods(string: String, drawX: Int, drawY: Int, xmodifiers: IntArray?, ymodifiers: IntArray?) { 492 + var x = drawX 493 + val y = drawY - characterDefaultHeight 494 + var effect = -1 495 + @Suppress("UNUSED_VARIABLE") 496 + var var7 = 0 497 + var modifier = 0 498 + val length = string.length 499 + for (pos in 0 until length) { 500 + var character = string[pos].code 501 + if (character == 60) { 502 + effect = pos 503 + } else { 504 + if (character == 62 && effect != -1) { 505 + val symbol = string.substring(pos, effect + 1) 506 + effect = -1 507 + if (symbol == lessThan) character = 60 508 + else if (symbol == greaterThan) character = 62 509 + else if (symbol == nonBreakingSpace) character = 160 510 + else if (symbol == softHyphen) character = 173 511 + else if (symbol == multiplicationSymbol) character = 215 512 + else if (symbol == euroSymbol) character = 128 513 + else if (symbol == copyright) character = 169 514 + else { 515 + if (symbol != registeredTrademark) { 516 + if (symbol.startsWith(image, 0)) { 517 + try { 518 + val xOff = if (xmodifiers != null) xmodifiers[modifier] else 0 519 + val yOffset = if (ymodifiers != null) ymodifiers[modifier] else 0 520 + ++modifier 521 + val symbolWidth = symbol.substring(4).toInt() 522 + val img = moderatorIcon!![symbolWidth] 523 + val imageHeight = if (imageWidths != null) imageWidths!![symbolWidth] else img.maxHeight 524 + if (opacity == 256) 525 + img.drawImage(x + xOff, y + characterDefaultHeight - imageHeight + yOffset) 526 + else 527 + img.drawImageAlpha(x + xOff, y + characterDefaultHeight - imageHeight + yOffset, opacity) 528 + x += img.width 529 + var7 = 0 530 + } catch (_: Exception) { 531 + } 532 + } else { 533 + parseStringForEffects(symbol) 534 + } 535 + continue 536 + } 537 + character = 174 538 + } 539 + } 540 + if (character == '@'.code && character + 4 < string.length && string[character + 4] == '@') { 541 + val stringColour = getColour(string.substring(character + 1, character + 4)) 542 + if (stringColour != -1) textColor = stringColour 543 + continue 544 + } 545 + if (effect == -1) { 546 + val cWidth = characterWidths[character] 547 + val cHeight = characterHeights[character] 548 + val xOff = if (xmodifiers != null) xmodifiers[modifier] else 0 549 + val yOffset = if (ymodifiers != null) ymodifiers[modifier] else 0 550 + ++modifier 551 + if (character != 32) { 552 + if (opacity == 256) { 553 + if (shadowColor != -1) 554 + drawCharacter(character, x + characterXOffsets[character] + 1 + xOff, y + characterYOffsets[character] + 1 + yOffset, cWidth, cHeight, shadowColor) 555 + drawCharacter(character, x + characterXOffsets[character] + xOff, y + characterYOffsets[character] + yOffset, cWidth, cHeight, textColor) 556 + } else { 557 + if (shadowColor != -1) 558 + drawCharacterAlpha(character, x + characterXOffsets[character] + 1 + xOff, y + characterYOffsets[character] + 1 + yOffset, cWidth, cHeight, shadowColor, opacity) 559 + drawCharacterAlpha(character, x + characterXOffsets[character] + xOff, y + characterYOffsets[character] + yOffset, cWidth, cHeight, textColor, opacity) 560 + } 561 + } else if (whiteSpace > 0) { 562 + anInt3748 += whiteSpace 563 + x += anInt3748 shr 8 564 + anInt3748 = anInt3748 and 255 565 + } 566 + val charWidth = characterScreenWidths[character] 567 + if (strikethroughColor != -1) { 568 + if (opacity > 255) 569 + Rasterizer.drawHorizontalLine(x, y + (characterDefaultHeight.toDouble() * 0.7).toInt(), charWidth, strikethroughColor) 570 + else 571 + Rasterizer.drawHorizontalLineAlpha(x, y + (characterDefaultHeight.toDouble() * 0.7).toInt(), charWidth, strikethroughColor, opacity) 572 + } 573 + if (underlineColor != -1) { 574 + if (opacity > 255) 575 + Rasterizer.drawHorizontalLine(x, y + characterDefaultHeight, charWidth, underlineColor) 576 + else 577 + Rasterizer.drawHorizontalLineAlpha(x, y + characterDefaultHeight, charWidth, underlineColor, opacity) 578 + } 579 + x += charWidth 580 + var7 = character 581 + } 582 + } 583 + } 584 + } 585 + 586 + fun drawString(string: String?, x: Int, y: Int, color: Int, shadow: Int) { 587 + if (string != null) { 588 + setEffects(color, shadow) 589 + drawBasicString(string, x, y) 590 + } 591 + } 592 + 593 + fun drawStringAlignedLeft(string: String?, x: Int, y: Int, color: Int, shadow: Int) { 594 + if (string != null) { 595 + setEffects(color, shadow) 596 + drawBasicString(string, x - getDisplayedWidth(string), y) 597 + } 598 + } 599 + 600 + fun drawStringWave(string: String?, x: Int, y: Int, color: Int, shadow: Int, var6: Int) { 601 + if (string != null) { 602 + setEffects(color, shadow) 603 + val length = string.length 604 + val var8 = IntArray(length) { (Math.sin(it / 5.0 + var6 / 5.0) * 5.0).toInt() } 605 + val var9 = IntArray(length) { (Math.sin(it / 3.0 + var6 / 5.0) * 5.0).toInt() } 606 + drawBasicStringXYMods(string, x - getDisplayedWidth(string) / 2, y, var8, var9) 607 + } 608 + } 609 + 610 + fun drawStringWaveY(string: String?, x: Int, y: Int, color: Int, shadow: Int, tick: Int) { 611 + if (string != null) { 612 + setEffects(color, shadow) 613 + val var7 = string.length 614 + val vertWaveOffset = IntArray(var7) { (Math.sin(it / 2.0 + tick / 5.0) * 5.0).toInt() } 615 + drawBasicStringXYMods(string, x - getDisplayedWidth(string) / 2, y, null, vertWaveOffset) 616 + } 617 + } 618 + 619 + fun drawCenteredStringXMod(var1: String?, var2: Int, var3: Int, var4: Int, var5: Int, var6: Int, var7: Int) { 620 + if (var1 != null) { 621 + setEffects(var4, var5) 622 + var amplitude = 7.0 - var7 / 8.0 623 + if (amplitude < 0.0) amplitude = 0.0 624 + val length = var1.length 625 + val xmod = IntArray(length) { (Math.sin(it / 1.5 + var6 / 1.0) * amplitude).toInt() } 626 + drawBasicStringXYMods(var1, var2 - getDisplayedWidth(var1) / 2, var3, null, xmod) 627 + } 628 + } 629 + 630 + private fun setEffects(color: Int, shadow: Int) { 631 + strikethroughColor = -1 632 + underlineColor = -1 633 + defaultShadowColor = shadow 634 + shadowColor = shadow 635 + defaultTextColor = color 636 + textColor = color 637 + defaultOpacity = 256 638 + opacity = 256 639 + whiteSpace = 0 640 + anInt3748 = 0 641 + } 642 + 643 + fun drawBasicString(string: String, x: Int, y: Int) { 644 + var drawX = x 645 + val drawY = y - characterDefaultHeight 646 + var effectIndex = -1 647 + @Suppress("UNUSED_VARIABLE") 648 + var var5 = 0 649 + val textLength = string.length 650 + var character = 0 651 + while (character < textLength) { 652 + var c = string[character].code 653 + if (c > 255) c = 32 654 + if (c == 60) { 655 + effectIndex = character 656 + } else { 657 + if (c == 62 && effectIndex != -1) { 658 + val effectString = string.substring(effectIndex + 1, character) 659 + effectIndex = -1 660 + if (effectString == lessThan) c = 60 661 + else if (effectString == greaterThan) c = 62 662 + else if (effectString == nonBreakingSpace) c = 160 663 + else if (effectString == softHyphen) c = 173 664 + else if (effectString == multiplicationSymbol) c = 215 665 + else if (effectString == euroSymbol) c = 128 666 + else if (effectString == copyright) c = 169 667 + else { 668 + if (effectString != registeredTrademark) { 669 + if (effectString.startsWith(image, 0)) { 670 + try { 671 + val icon = effectString.substring(4).toInt() 672 + val nameIcon = moderatorIcon!![icon] 673 + val imageHeight = if (imageWidths != null) imageWidths!![icon] else nameIcon.maxHeight 674 + if (opacity == 256) 675 + nameIcon.drawImage(drawX, drawY + characterDefaultHeight - imageHeight) 676 + else 677 + nameIcon.drawImageAlpha(drawX, drawY + characterDefaultHeight - imageHeight, opacity) 678 + drawX += nameIcon.maxWidth 679 + var5 = 0 680 + } catch (_: Exception) { 681 + } 682 + } else { 683 + parseStringForEffects(effectString) 684 + } 685 + character++ 686 + continue 687 + } 688 + c = 174 689 + } 690 + } 691 + if (c == '@'.code && character + 4 < string.length && string[character + 4] == '@') { 692 + val stringColour = getColour(string.substring(character + 1, character + 4)) 693 + if (stringColour != -1) textColor = stringColour 694 + character += 4 695 + character++ 696 + continue 697 + } 698 + if (effectIndex == -1) { 699 + val w = characterWidths[c] 700 + val h = characterHeights[c] 701 + if (c != 32) { 702 + if (opacity == 256) { 703 + if (shadowColor != -1) 704 + drawCharacter(c, drawX + characterXOffsets[c] + 1, drawY + characterYOffsets[c] + 1, w, h, shadowColor) 705 + drawCharacter(c, drawX + characterXOffsets[c], drawY + characterYOffsets[c], w, h, textColor) 706 + } else { 707 + if (shadowColor != -1) 708 + drawCharacterAlpha(c, drawX + characterXOffsets[c] + 1, drawY + characterYOffsets[c] + 1, w, h, shadowColor, opacity) 709 + drawCharacterAlpha(c, drawX + characterXOffsets[c], drawY + characterYOffsets[c], w, h, textColor, opacity) 710 + } 711 + } else if (whiteSpace > 0) { 712 + anInt3748 += whiteSpace 713 + drawX += anInt3748 shr 8 714 + anInt3748 = anInt3748 and 255 715 + } 716 + val charWidth = characterScreenWidths[c] 717 + if (strikethroughColor != -1) 718 + Rasterizer.drawHorizontalLine(drawX, drawY + (characterDefaultHeight.toDouble() * 0.7).toInt(), charWidth, strikethroughColor) 719 + if (underlineColor != -1) 720 + Rasterizer.drawHorizontalLine(drawX, drawY + characterDefaultHeight + 1, charWidth, underlineColor) 721 + drawX += charWidth 722 + var5 = c 723 + } 724 + } 725 + character++ 726 + } 727 + } 728 + 729 + fun drawCharacterAlpha(character: Int, x: Int, y: Int, width: Int, height: Int, colour: Int, alpha: Int) { 730 + this.drawAlphaCharacter(characterPixels[character]!!, x, y, width, height, colour, alpha) 731 + } 732 + 733 + fun drawAlphaCharacter(characterPixels: ByteArray, x: Int, y: Int, width: Int, height: Int, colour: Int, alpha: Int) { 734 + var drawX = x 735 + var drawY = y 736 + var drawW = width 737 + var drawH = height 738 + var rasterizerPixel = drawX + drawY * Rasterizer.width 739 + var rasterizerPixelOffset = Rasterizer.width - drawW 740 + var characterPixelOffset = 0 741 + var characterPixel = 0 742 + if (drawY < Rasterizer.topY) { 743 + val yOffset = Rasterizer.topY - drawY 744 + drawH -= yOffset 745 + drawY = Rasterizer.topY 746 + characterPixel += yOffset * drawW 747 + rasterizerPixel += yOffset * Rasterizer.width 748 + } 749 + if (drawY + drawH >= Rasterizer.bottomY) 750 + drawH -= ((drawY + drawH) - Rasterizer.bottomY) + 1 751 + if (drawX < Rasterizer.topX) { 752 + val xOffset = Rasterizer.topX - drawX 753 + drawW -= xOffset 754 + drawX = Rasterizer.topX 755 + characterPixel += xOffset 756 + rasterizerPixel += xOffset 757 + characterPixelOffset += xOffset 758 + rasterizerPixelOffset += xOffset 759 + } 760 + if (drawX + drawW >= Rasterizer.bottomX) { 761 + val widthoffset = ((drawX + drawW) - Rasterizer.bottomX) + 1 762 + drawW -= widthoffset 763 + characterPixelOffset += widthoffset 764 + rasterizerPixelOffset += widthoffset 765 + } 766 + if (drawW > 0 && drawH > 0) { 767 + drawCharacterPixelsAlpha(characterPixel, rasterizerPixelOffset, characterPixelOffset, rasterizerPixel, alpha, Rasterizer.pixels, colour, drawH, drawW, characterPixels) 768 + } 769 + } 770 + 771 + fun drawCharacterPixelsAlpha( 772 + characterPixel: Int, rasterizerPixelOffset: Int, characterPixelOffset: Int, 773 + rasterizerPixel: Int, alpha: Int, rasterizerPixels: IntArray, colour: Int, 774 + height: Int, width: Int, characterPixels: ByteArray 775 + ) { 776 + // Pre-multiply the colour by alpha — pure int arithmetic, no byte issues 777 + val premultColour = ((colour and 0xff00ff) * alpha and 0xFF00FF00.toInt()) + ((colour and 0xff00) * alpha and 0xff0000) shr 8 778 + val invAlpha = 256 - alpha 779 + var rPixel = rasterizerPixel 780 + var cPixel = characterPixel 781 + for (heightCounter in -height until 0) { 782 + for (widthCounter in -width until 0) { 783 + // byte != 0 check: explicit .toInt() 784 + if (characterPixels[cPixel++].toInt() != 0) { 785 + val rasterizerPixelColor = rasterizerPixels[rPixel] 786 + rasterizerPixels[rPixel++] = (((rasterizerPixelColor and 0xff00ff) * invAlpha and 0xFF00FF00.toInt()) + ((rasterizerPixelColor and 0xff00) * invAlpha and 0xff0000) shr 8) + premultColour 787 + } else { 788 + rPixel++ 789 + } 790 + } 791 + rPixel += rasterizerPixelOffset 792 + cPixel += characterPixelOffset 793 + } 794 + } 795 + 796 + fun setNameIcons(images: Array<ImageRGB>, widths: IntArray?) { 797 + if (widths != null && widths.size != images.size) { 798 + throw IllegalArgumentException() 799 + } else { 800 + moderatorIcon = images 801 + imageWidths = widths 802 + } 803 + } 804 + 805 + companion object { 806 + private var strikethroughColor: Int = -1 807 + private var underlineColor: Int = -1 808 + private var anInt3748: Int = 0 809 + private var defaultTextColor: Int = 0 810 + private var opacity: Int = 256 811 + private var defaultOpacity: Int = 256 812 + private var defaultShadowColor: Int = -1 813 + private var shadowColor: Int = -1 814 + private var textColor: Int = 0xff00ff 815 + private var whiteSpace: Int = 0 816 + 817 + private val greaterThan = "gt" 818 + private val lessThan = "lt" 819 + private val euroSymbol = "euro" 820 + private val startShadow = "shad=" 821 + private val softHyphen = "shy" 822 + private val startTrans = "trans=" 823 + private val startUnderline = "u=" 824 + private val startStrikethrough = "str=" 825 + private val endColor = "/col" 826 + private val endShadow = "/shad" 827 + private val endTrans = "/trans" 828 + private val endUnderline = "/u" 829 + private val endStrikeThrough = "/str" 830 + private val startDefaultUnderline = "u" 831 + private val startDefaultStrikeThrough = "str" 832 + private val startDefaultShadow = "shad" 833 + private val startColor = "col=" 834 + private val multiplicationSymbol = "times" 835 + private val nonBreakingSpace = "nbsp" 836 + private val image = "img=" 837 + private val copyright = "copy" 838 + private val lineBreak = "br" 839 + private val registeredTrademark = "reg" 840 + } 841 + }
-424
src/main/java/com/jagex/runescape/cache/media/Widget.java
··· 1 - package com.jagex.runescape.cache.media; 2 - 3 - import com.jagex.runescape.Game; 4 - import com.jagex.runescape.cache.Archive; 5 - import com.jagex.runescape.cache.def.ActorDefinition; 6 - import com.jagex.runescape.cache.def.ItemDefinition; 7 - import com.jagex.runescape.collection.Cache; 8 - import com.jagex.runescape.media.Animation; 9 - import com.jagex.runescape.media.renderable.Model; 10 - import com.jagex.runescape.net.Buffer; 11 - import com.jagex.runescape.util.TextUtils; 12 - 13 - public class Widget { 14 - 15 - public String optionText; 16 - public ImageRGB disabledImage; 17 - public int imageY[]; 18 - public static Archive mediaArchive; 19 - public int id; 20 - public static Widget interfaces[]; 21 - public boolean itemDeletesDraged; 22 - public int anInt218; 23 - public boolean hiddenUntilHovered; 24 - public byte alpha; 25 - public int imageX[]; 26 - public int optionAttributes; 27 - public static TypeFace fonts[]; 28 - public int itemAmounts[]; 29 - public int unknownOne; 30 - public int enabledHoveredColor; 31 - public int animationDuration; 32 - public int xOffset; 33 - public boolean isInventory; 34 - public String disabledText; 35 - public int scrollPosition; 36 - public int childrenX[]; 37 - public boolean unknownTwo; 38 - public int cs1opcodes[][]; // [idx][0] opcode [idx][1] configid 39 - public int animationFrame; 40 - public int type; 41 - public TypeFace typeFaces; 42 - public int height; 43 - public boolean filled; 44 - public int disabledColor; 45 - public int width; 46 - public int contentType; 47 - public static int anInt243; 48 - public int itemSpritePadsY; 49 - public ImageRGB enabledImage; 50 - public static int instanceWidgetParent = -1; 51 - public boolean typeFaceShadowed; 52 - public int parentId; 53 - public String enabledText; 54 - public static Cache spriteCache; 55 - public int zoom; 56 - public int rotationX; 57 - public int rotationY; 58 - public int hoveredPopup; 59 - public static int anInt255 = -1; 60 - public int conditionValues[]; 61 - public int children[]; 62 - public int yOffset; 63 - public int enabledColor; 64 - public int disabledHoveredColor; 65 - public String options[]; 66 - public int itemSpritePadsX; 67 - public static Cache modelCache = new Cache(30); 68 - public ImageRGB images[]; 69 - public int enabledModelType; 70 - public int enabledModelId; 71 - public String tooltip; 72 - public int items[]; 73 - public boolean typeFaceCentered; 74 - public int conditionTypes[]; 75 - public boolean itemSwapable; 76 - public int childrenY[]; 77 - public static int anInt277 = -1; 78 - public static int anInt280; 79 - public String optionCircumfix; 80 - public static byte data[][]; 81 - public int modelType; 82 - public int modelId; 83 - public int scrollLimit; 84 - public int disabledAnimation; 85 - public int enabledAnimation; 86 - public boolean itemUsable; 87 - public int actionType; 88 - 89 - public static ImageRGB getImage(int spriteId, String spriteName) { 90 - long spriteHash = (TextUtils.spriteToHash(spriteName) << 8) + spriteId; 91 - ImageRGB sprite = (ImageRGB) spriteCache.get(spriteHash); 92 - if (sprite != null) 93 - return sprite; 94 - if (mediaArchive == null) 95 - return null; 96 - try { 97 - sprite = new ImageRGB(mediaArchive, spriteName, spriteId); 98 - spriteCache.put(sprite, spriteHash); 99 - } catch (Exception _ex) { 100 - return null; 101 - } 102 - return sprite; 103 - } 104 - 105 - public static Widget forId(int id) { 106 - if (interfaces[id] == null) { 107 - Buffer buf = new Buffer(data[id]); 108 - int j = buf.getUnsignedShortBE(); 109 - interfaces[id] = parse(j, buf, id); 110 - } 111 - return interfaces[id]; 112 - } 113 - 114 - public void swapItems(int originalSlot, int newSlot) { 115 - int originalItem = items[originalSlot]; 116 - items[originalSlot] = items[newSlot]; 117 - items[newSlot] = originalItem; 118 - originalItem = itemAmounts[originalSlot]; 119 - itemAmounts[originalSlot] = itemAmounts[newSlot]; 120 - itemAmounts[newSlot] = originalItem; 121 - } 122 - 123 - public Model getModel(int modelType, int modelId) { 124 - ItemDefinition item = null; 125 - if (modelType == 4) { 126 - item = ItemDefinition.lookup(modelId); 127 - anInt280 += item.ambience; 128 - anInt243 += item.diffusion; 129 - } 130 - Model model = (Model) modelCache.get((modelType << 16) + modelId); 131 - if (model != null) 132 - return model; 133 - if (modelType == 1) 134 - model = Model.getModel(modelId); 135 - if (modelType == 2) 136 - model = ActorDefinition.getDefinition(modelId).getHeadModel(); 137 - if (modelType == 3) 138 - model = Game.localPlayer.getHeadModel(); 139 - if (modelType == 4) 140 - model = item.asStack(50); 141 - if (modelType == 5) 142 - model = null; 143 - if (model != null) 144 - modelCache.put(model, (modelType << 16) + modelId); 145 - return model; 146 - } 147 - 148 - public static Widget parse(int parentId, Buffer buffer, int widgetIndex) { 149 - Widget widget = new Widget(); 150 - widget.id = widgetIndex; 151 - widget.parentId = parentId; 152 - widget.type = buffer.getUnsignedByte(); 153 - widget.actionType = buffer.getUnsignedByte(); 154 - widget.contentType = buffer.getUnsignedShortBE(); 155 - widget.width = buffer.getUnsignedShortBE(); 156 - widget.height = buffer.getUnsignedShortBE(); 157 - widget.alpha = (byte) buffer.getUnsignedByte(); 158 - widget.hoveredPopup = buffer.getUnsignedByte(); 159 - if (widget.hoveredPopup != 0) 160 - widget.hoveredPopup = (widget.hoveredPopup - 1 << 8) + buffer.getUnsignedByte(); 161 - else 162 - widget.hoveredPopup = -1; 163 - if (widget.contentType == 600) 164 - instanceWidgetParent = parentId; 165 - if (widget.contentType == 650) 166 - anInt255 = parentId; 167 - if (widget.contentType == 655) 168 - anInt277 = parentId; 169 - int conditionCount = buffer.getUnsignedByte(); 170 - if (conditionCount > 0) { 171 - widget.conditionTypes = new int[conditionCount]; 172 - widget.conditionValues = new int[conditionCount]; 173 - for (int condition = 0; condition < conditionCount; condition++) { 174 - widget.conditionTypes[condition] = buffer.getUnsignedByte(); 175 - widget.conditionValues[condition] = buffer.getUnsignedShortBE(); 176 - } 177 - 178 - } 179 - int cs1length = buffer.getUnsignedByte(); 180 - if (cs1length > 0) { 181 - widget.cs1opcodes = new int[cs1length][]; 182 - for (int blockIdx = 0; blockIdx < cs1length; blockIdx++) { 183 - int cs1blocklen = buffer.getUnsignedShortBE(); 184 - widget.cs1opcodes[blockIdx] = new int[cs1blocklen]; 185 - for (int cs1opcIdx = 0; cs1opcIdx < cs1blocklen; cs1opcIdx++) 186 - widget.cs1opcodes[blockIdx][cs1opcIdx] = buffer.getUnsignedShortBE(); 187 - 188 - } 189 - 190 - } 191 - if (widget.type == 0) { 192 - widget.scrollLimit = buffer.getUnsignedShortBE(); 193 - widget.hiddenUntilHovered = buffer.getUnsignedByte() == 1; 194 - int childrenCount = buffer.getUnsignedShortBE(); 195 - widget.children = new int[childrenCount]; 196 - widget.childrenX = new int[childrenCount]; 197 - widget.childrenY = new int[childrenCount]; 198 - for (int child = 0; child < childrenCount; child++) { 199 - widget.children[child] = buffer.getUnsignedShortBE(); 200 - widget.childrenX[child] = buffer.getShortBE(); 201 - widget.childrenY[child] = buffer.getShortBE(); 202 - } 203 - 204 - } 205 - if (widget.type == 1) { 206 - widget.unknownOne = buffer.getUnsignedShortBE(); 207 - widget.unknownTwo = buffer.getUnsignedByte() == 1; 208 - } 209 - if (widget.type == 2) { 210 - widget.items = new int[widget.width * widget.height]; 211 - widget.itemAmounts = new int[widget.width * widget.height]; 212 - widget.itemSwapable = buffer.getUnsignedByte() == 1; 213 - widget.isInventory = buffer.getUnsignedByte() == 1; 214 - widget.itemUsable = buffer.getUnsignedByte() == 1; 215 - widget.itemDeletesDraged = buffer.getUnsignedByte() == 1; 216 - widget.itemSpritePadsX = buffer.getUnsignedByte(); 217 - widget.itemSpritePadsY = buffer.getUnsignedByte(); 218 - widget.imageX = new int[20]; 219 - widget.imageY = new int[20]; 220 - widget.images = new ImageRGB[20]; 221 - for (int sprite = 0; sprite < 20; sprite++) { 222 - int hasSprite = buffer.getUnsignedByte(); 223 - if (hasSprite == 1) { 224 - widget.imageX[sprite] = buffer.getShortBE(); 225 - widget.imageY[sprite] = buffer.getShortBE(); 226 - String spriteName = buffer.getString(); 227 - if (spriteName.length() > 0) { 228 - int spriteId = spriteName.lastIndexOf(","); 229 - widget.images[sprite] = getImage(Integer.parseInt(spriteName.substring(spriteId + 1)), 230 - spriteName.substring(0, spriteId)); 231 - } 232 - } 233 - } 234 - 235 - widget.options = new String[5]; 236 - for (int optionId = 0; optionId < 5; optionId++) { 237 - widget.options[optionId] = buffer.getString(); 238 - if (widget.options[optionId].length() == 0) 239 - widget.options[optionId] = null; 240 - } 241 - 242 - } 243 - if (widget.type == 3) 244 - widget.filled = buffer.getUnsignedByte() == 1; 245 - if (widget.type == 4 || widget.type == 1) { 246 - widget.typeFaceCentered = buffer.getUnsignedByte() == 1; 247 - int typeFace = buffer.getUnsignedByte(); 248 - if (fonts != null) 249 - widget.typeFaces = fonts[typeFace]; 250 - widget.typeFaceShadowed = buffer.getUnsignedByte() == 1; 251 - } 252 - if (widget.type == 4) { 253 - widget.disabledText = buffer.getString(); 254 - widget.enabledText = buffer.getString(); 255 - } 256 - if (widget.type == 1 || widget.type == 3 || widget.type == 4) 257 - widget.disabledColor = buffer.getIntBE(); 258 - if (widget.type == 3 || widget.type == 4) { 259 - widget.enabledColor = buffer.getIntBE(); 260 - widget.disabledHoveredColor = buffer.getIntBE(); 261 - widget.enabledHoveredColor = buffer.getIntBE(); 262 - } 263 - if (widget.type == 5) { 264 - String spriteName = buffer.getString(); 265 - if (spriteName.length() > 0) { 266 - int spriteId = spriteName.lastIndexOf(","); 267 - widget.disabledImage = getImage(Integer.parseInt(spriteName.substring(spriteId + 1)), spriteName.substring(0, 268 - spriteId)); 269 - } 270 - spriteName = buffer.getString(); 271 - if (spriteName.length() > 0) { 272 - int spriteId = spriteName.lastIndexOf(","); 273 - widget.enabledImage = getImage(Integer.parseInt(spriteName.substring(spriteId + 1)), spriteName.substring(0, 274 - spriteId)); 275 - } 276 - } 277 - if (widget.type == 6) { 278 - widgetIndex = buffer.getUnsignedByte(); 279 - if (widgetIndex != 0) { 280 - widget.modelType = 1; 281 - widget.modelId = (widgetIndex - 1 << 8) + buffer.getUnsignedByte(); 282 - } 283 - widgetIndex = buffer.getUnsignedByte(); 284 - if (widgetIndex != 0) { 285 - widget.enabledModelType = 1; 286 - widget.enabledModelId = (widgetIndex - 1 << 8) + buffer.getUnsignedByte(); 287 - } 288 - widgetIndex = buffer.getUnsignedByte(); 289 - if (widgetIndex != 0) 290 - widget.disabledAnimation = (widgetIndex - 1 << 8) + buffer.getUnsignedByte(); 291 - else 292 - widget.disabledAnimation = -1; 293 - widgetIndex = buffer.getUnsignedByte(); 294 - if (widgetIndex != 0) 295 - widget.enabledAnimation = (widgetIndex - 1 << 8) + buffer.getUnsignedByte(); 296 - else 297 - widget.enabledAnimation = -1; 298 - widget.zoom = buffer.getUnsignedShortBE(); 299 - widget.rotationX = buffer.getUnsignedShortBE(); 300 - widget.rotationY = buffer.getUnsignedShortBE(); 301 - } 302 - if (widget.type == 7) { 303 - widget.items = new int[widget.width * widget.height]; 304 - widget.itemAmounts = new int[widget.width * widget.height]; 305 - widget.typeFaceCentered = buffer.getUnsignedByte() == 1; 306 - int typeFaceCount = buffer.getUnsignedByte(); 307 - if (fonts != null) 308 - widget.typeFaces = fonts[typeFaceCount]; 309 - widget.typeFaceShadowed = buffer.getUnsignedByte() == 1; 310 - widget.disabledColor = buffer.getIntBE(); 311 - widget.itemSpritePadsX = buffer.getShortBE(); 312 - widget.itemSpritePadsY = buffer.getShortBE(); 313 - widget.isInventory = buffer.getUnsignedByte() == 1; 314 - widget.options = new String[5]; 315 - for (int optionId = 0; optionId < 5; optionId++) { 316 - widget.options[optionId] = buffer.getString(); 317 - if (widget.options[optionId].length() == 0) 318 - widget.options[optionId] = null; 319 - } 320 - 321 - } 322 - if (widget.type == 8) 323 - widget.disabledText = buffer.getString(); 324 - if (widget.actionType == 2 || widget.type == 2) { 325 - widget.optionCircumfix = buffer.getString(); 326 - widget.optionText = buffer.getString(); 327 - widget.optionAttributes = buffer.getUnsignedShortBE(); 328 - } 329 - if (widget.actionType == 1 || widget.actionType == 4 || widget.actionType == 5 || widget.actionType == 6) { 330 - widget.tooltip = buffer.getString(); 331 - if (widget.tooltip.length() == 0) { 332 - if (widget.actionType == 1) 333 - widget.tooltip = "Ok"; 334 - if (widget.actionType == 4) 335 - widget.tooltip = "Select"; 336 - if (widget.actionType == 5) 337 - widget.tooltip = "Select"; 338 - if (widget.actionType == 6) 339 - widget.tooltip = "Continue"; 340 - } 341 - } 342 - return widget; 343 - } 344 - 345 - public static void load(Archive widgetArchive, TypeFace[] fonts, Archive mediaArchive) { 346 - spriteCache = new Cache(50000); 347 - Buffer buffer = new Buffer(widgetArchive.getFile("data")); 348 - Widget.mediaArchive = mediaArchive; 349 - Widget.fonts = fonts; 350 - int parentId = -1; 351 - int widgetCount = buffer.getUnsignedShortBE(); 352 - interfaces = new Widget[widgetCount]; 353 - data = new byte[widgetCount][]; 354 - while (buffer.currentPosition < buffer.buffer.length) { 355 - int widgetIndex = buffer.getUnsignedShortBE(); 356 - if (widgetIndex == 65535) { 357 - parentId = buffer.getUnsignedShortBE(); 358 - widgetIndex = buffer.getUnsignedShortBE(); 359 - } 360 - int i1 = buffer.currentPosition; 361 - Widget widget = parse(parentId, buffer, widgetIndex); 362 - byte temp[] = data[widget.id] = new byte[(buffer.currentPosition - i1) + 2]; 363 - for (int j1 = i1; j1 < buffer.currentPosition; j1++) 364 - temp[(j1 - i1) + 2] = buffer.buffer[j1]; 365 - 366 - temp[0] = (byte) (parentId >> 8); 367 - temp[1] = (byte) parentId; 368 - } 369 - Widget.mediaArchive = null; 370 - 371 - // Enable item dragging on the bank items grid (5382). 372 - // The cache definition has itemSwapable=false, preventing the client 373 - // from sending swap packets to the server for bank rearrangement. 374 - if (interfaces.length > 5382 && interfaces[5382] != null) { 375 - interfaces[5382].itemSwapable = true; 376 - } 377 - } 378 - 379 - public static void method200(int i) { 380 - if (i == -1) 381 - return; 382 - for (int j = 0; j < interfaces.length; j++) 383 - if (interfaces[j] != null && interfaces[j].parentId == i && interfaces[j].type != 2) 384 - interfaces[j] = null; 385 - 386 - } 387 - 388 - public static void setModel(int modelType, Model model, int modelId) { 389 - modelCache.removeAll(); 390 - if (model != null && modelType != 4) 391 - modelCache.put(model, (modelType << 16) + modelId); 392 - } 393 - 394 - public static void reset() { 395 - interfaces = null; 396 - mediaArchive = null; 397 - spriteCache = null; 398 - fonts = null; 399 - data = null; 400 - } 401 - 402 - public Model getAnimatedModel(int frame1Id, int frame2Id, boolean modelEnabled) { 403 - Model model; 404 - if (modelEnabled) 405 - model = getModel(enabledModelType, enabledModelId); 406 - else 407 - model = getModel(modelType, modelId); 408 - if (model == null) 409 - return null; 410 - if (frame2Id == -1 && frame1Id == -1 && model.triangleColorValues == null) 411 - return model; 412 - Model animatedModel = new Model(true, 413 - model, Animation.exists(frame2Id) & Animation.exists(frame1Id)); 414 - if (frame2Id != -1 || frame1Id != -1) 415 - animatedModel.createBones(); 416 - if (frame2Id != -1) 417 - animatedModel.applyTransform(frame2Id); 418 - if (frame1Id != -1) 419 - animatedModel.applyTransform(frame1Id); 420 - animatedModel.applyLighting(64, 768, -50, -10, -50, true); 421 - return animatedModel; 422 - } 423 - 424 - }
+406
src/main/java/com/jagex/runescape/cache/media/Widget.kt
··· 1 + package com.jagex.runescape.cache.media 2 + 3 + import com.jagex.runescape.Game 4 + import com.jagex.runescape.cache.Archive 5 + import com.jagex.runescape.cache.def.ActorDefinition 6 + import com.jagex.runescape.cache.def.ItemDefinition 7 + import com.jagex.runescape.collection.Cache 8 + import com.jagex.runescape.media.Animation 9 + import com.jagex.runescape.media.renderable.Model 10 + import com.jagex.runescape.net.Buffer 11 + import com.jagex.runescape.util.TextUtils 12 + 13 + class Widget { 14 + 15 + @JvmField var optionText: String? = null 16 + @JvmField var disabledImage: ImageRGB? = null 17 + @JvmField var imageY: IntArray? = null 18 + @JvmField var id: Int = 0 19 + @JvmField var itemDeletesDraged: Boolean = false 20 + @JvmField var anInt218: Int = 0 21 + @JvmField var hiddenUntilHovered: Boolean = false 22 + @JvmField var alpha: Byte = 0 23 + @JvmField var imageX: IntArray? = null 24 + @JvmField var optionAttributes: Int = 0 25 + @JvmField var itemAmounts: IntArray? = null 26 + @JvmField var unknownOne: Int = 0 27 + @JvmField var enabledHoveredColor: Int = 0 28 + @JvmField var animationDuration: Int = 0 29 + @JvmField var xOffset: Int = 0 30 + @JvmField var isInventory: Boolean = false 31 + @JvmField var disabledText: String? = null 32 + @JvmField var scrollPosition: Int = 0 33 + @JvmField var childrenX: IntArray? = null 34 + @JvmField var unknownTwo: Boolean = false 35 + @JvmField var cs1opcodes: Array<IntArray?>? = null 36 + @JvmField var animationFrame: Int = 0 37 + @JvmField var type: Int = 0 38 + @JvmField var typeFaces: TypeFace? = null 39 + @JvmField var height: Int = 0 40 + @JvmField var filled: Boolean = false 41 + @JvmField var disabledColor: Int = 0 42 + @JvmField var width: Int = 0 43 + @JvmField var contentType: Int = 0 44 + @JvmField var itemSpritePadsY: Int = 0 45 + @JvmField var enabledImage: ImageRGB? = null 46 + @JvmField var typeFaceShadowed: Boolean = false 47 + @JvmField var parentId: Int = 0 48 + @JvmField var enabledText: String? = null 49 + @JvmField var zoom: Int = 0 50 + @JvmField var rotationX: Int = 0 51 + @JvmField var rotationY: Int = 0 52 + @JvmField var hoveredPopup: Int = 0 53 + @JvmField var conditionValues: IntArray? = null 54 + @JvmField var children: IntArray? = null 55 + @JvmField var yOffset: Int = 0 56 + @JvmField var enabledColor: Int = 0 57 + @JvmField var disabledHoveredColor: Int = 0 58 + @JvmField var options: Array<String?>? = null 59 + @JvmField var itemSpritePadsX: Int = 0 60 + @JvmField var images: Array<ImageRGB?>? = null 61 + @JvmField var enabledModelType: Int = 0 62 + @JvmField var enabledModelId: Int = 0 63 + @JvmField var tooltip: String? = null 64 + @JvmField var items: IntArray? = null 65 + @JvmField var typeFaceCentered: Boolean = false 66 + @JvmField var conditionTypes: IntArray? = null 67 + @JvmField var itemSwapable: Boolean = false 68 + @JvmField var childrenY: IntArray? = null 69 + @JvmField var optionCircumfix: String? = null 70 + @JvmField var modelType: Int = 0 71 + @JvmField var modelId: Int = 0 72 + @JvmField var scrollLimit: Int = 0 73 + @JvmField var disabledAnimation: Int = 0 74 + @JvmField var enabledAnimation: Int = 0 75 + @JvmField var itemUsable: Boolean = false 76 + @JvmField var actionType: Int = 0 77 + 78 + fun swapItems(originalSlot: Int, newSlot: Int) { 79 + var originalItem = items!![originalSlot] 80 + items!![originalSlot] = items!![newSlot] 81 + items!![newSlot] = originalItem 82 + originalItem = itemAmounts!![originalSlot] 83 + itemAmounts!![originalSlot] = itemAmounts!![newSlot] 84 + itemAmounts!![newSlot] = originalItem 85 + } 86 + 87 + fun getModel(modelType: Int, modelId: Int): Model? { 88 + var item: ItemDefinition? = null 89 + if (modelType == 4) { 90 + item = ItemDefinition.lookup(modelId) 91 + anInt280 += item.ambience 92 + anInt243 += item.diffusion 93 + } 94 + var model = modelCache.get(((modelType shl 16) + modelId).toLong()) as Model? 95 + if (model != null) return model 96 + when (modelType) { 97 + 1 -> model = Model.getModel(modelId) 98 + 2 -> model = ActorDefinition.getDefinition(modelId).getHeadModel() 99 + 3 -> model = Game.localPlayer.getHeadModel() 100 + 4 -> model = item!!.asStack(50) 101 + 5 -> model = null 102 + } 103 + if (model != null) 104 + modelCache.put(model, ((modelType shl 16) + modelId).toLong()) 105 + return model 106 + } 107 + 108 + fun getAnimatedModel(frame1Id: Int, frame2Id: Int, modelEnabled: Boolean): Model? { 109 + val model: Model? = if (modelEnabled) getModel(enabledModelType, enabledModelId) 110 + else getModel(modelType, modelId) 111 + if (model == null) return null 112 + if (frame2Id == -1 && frame1Id == -1 && model.triangleColorValues == null) 113 + return model 114 + val animatedModel = Model(true, model, Animation.exists(frame2Id) and Animation.exists(frame1Id)) 115 + if (frame2Id != -1 || frame1Id != -1) 116 + animatedModel.createBones() 117 + if (frame2Id != -1) 118 + animatedModel.applyTransform(frame2Id) 119 + if (frame1Id != -1) 120 + animatedModel.applyTransform(frame1Id) 121 + animatedModel.applyLighting(64, 768, -50, -10, -50, true) 122 + return animatedModel 123 + } 124 + 125 + companion object { 126 + @JvmField var mediaArchive: Archive? = null 127 + @JvmField var interfaces: Array<Widget?>? = null 128 + @JvmField var fonts: Array<TypeFace?>? = null 129 + @JvmField var anInt243: Int = 0 130 + @JvmField var instanceWidgetParent: Int = -1 131 + @JvmField var spriteCache: Cache? = null 132 + @JvmField var anInt255: Int = -1 133 + @JvmField var anInt277: Int = -1 134 + @JvmField var anInt280: Int = 0 135 + @JvmField var data: Array<ByteArray?>? = null 136 + @JvmField var modelCache: Cache = Cache(30) 137 + 138 + @JvmStatic 139 + fun getImage(spriteId: Int, spriteName: String): ImageRGB? { 140 + val spriteHash = (TextUtils.spriteToHash(spriteName).toLong() shl 8) + spriteId 141 + var sprite = spriteCache!!.get(spriteHash) as ImageRGB? 142 + if (sprite != null) return sprite 143 + if (mediaArchive == null) return null 144 + return try { 145 + sprite = ImageRGB(mediaArchive!!, spriteName, spriteId) 146 + spriteCache!!.put(sprite, spriteHash) 147 + sprite 148 + } catch (_: Exception) { 149 + null 150 + } 151 + } 152 + 153 + @JvmStatic 154 + fun forId(id: Int): Widget { 155 + if (interfaces!![id] == null) { 156 + val buf = Buffer(data!![id]!!) 157 + val j = buf.getUnsignedShortBE() 158 + interfaces!![id] = parse(j, buf, id) 159 + } 160 + return interfaces!![id]!! 161 + } 162 + 163 + @JvmStatic 164 + fun parse(parentId: Int, buffer: Buffer, widgetIndex: Int): Widget { 165 + var idx = widgetIndex 166 + val widget = Widget() 167 + widget.id = idx 168 + widget.parentId = parentId 169 + widget.type = buffer.getUnsignedByte() 170 + widget.actionType = buffer.getUnsignedByte() 171 + widget.contentType = buffer.getUnsignedShortBE() 172 + widget.width = buffer.getUnsignedShortBE() 173 + widget.height = buffer.getUnsignedShortBE() 174 + widget.alpha = buffer.getUnsignedByte().toByte() 175 + widget.hoveredPopup = buffer.getUnsignedByte() 176 + if (widget.hoveredPopup != 0) 177 + widget.hoveredPopup = (widget.hoveredPopup - 1 shl 8) + buffer.getUnsignedByte() 178 + else 179 + widget.hoveredPopup = -1 180 + if (widget.contentType == 600) instanceWidgetParent = parentId 181 + if (widget.contentType == 650) anInt255 = parentId 182 + if (widget.contentType == 655) anInt277 = parentId 183 + 184 + val conditionCount = buffer.getUnsignedByte() 185 + if (conditionCount > 0) { 186 + widget.conditionTypes = IntArray(conditionCount) 187 + widget.conditionValues = IntArray(conditionCount) 188 + for (condition in 0 until conditionCount) { 189 + widget.conditionTypes!![condition] = buffer.getUnsignedByte() 190 + widget.conditionValues!![condition] = buffer.getUnsignedShortBE() 191 + } 192 + } 193 + val cs1length = buffer.getUnsignedByte() 194 + if (cs1length > 0) { 195 + widget.cs1opcodes = arrayOfNulls(cs1length) 196 + for (blockIdx in 0 until cs1length) { 197 + val cs1blocklen = buffer.getUnsignedShortBE() 198 + widget.cs1opcodes!![blockIdx] = IntArray(cs1blocklen) { buffer.getUnsignedShortBE() } 199 + } 200 + } 201 + if (widget.type == 0) { 202 + widget.scrollLimit = buffer.getUnsignedShortBE() 203 + widget.hiddenUntilHovered = buffer.getUnsignedByte() == 1 204 + val childrenCount = buffer.getUnsignedShortBE() 205 + widget.children = IntArray(childrenCount) 206 + widget.childrenX = IntArray(childrenCount) 207 + widget.childrenY = IntArray(childrenCount) 208 + for (child in 0 until childrenCount) { 209 + widget.children!![child] = buffer.getUnsignedShortBE() 210 + widget.childrenX!![child] = buffer.getShortBE() 211 + widget.childrenY!![child] = buffer.getShortBE() 212 + } 213 + } 214 + if (widget.type == 1) { 215 + widget.unknownOne = buffer.getUnsignedShortBE() 216 + widget.unknownTwo = buffer.getUnsignedByte() == 1 217 + } 218 + if (widget.type == 2) { 219 + widget.items = IntArray(widget.width * widget.height) 220 + widget.itemAmounts = IntArray(widget.width * widget.height) 221 + widget.itemSwapable = buffer.getUnsignedByte() == 1 222 + widget.isInventory = buffer.getUnsignedByte() == 1 223 + widget.itemUsable = buffer.getUnsignedByte() == 1 224 + widget.itemDeletesDraged = buffer.getUnsignedByte() == 1 225 + widget.itemSpritePadsX = buffer.getUnsignedByte() 226 + widget.itemSpritePadsY = buffer.getUnsignedByte() 227 + widget.imageX = IntArray(20) 228 + widget.imageY = IntArray(20) 229 + widget.images = arrayOfNulls(20) 230 + for (sprite in 0 until 20) { 231 + val hasSprite = buffer.getUnsignedByte() 232 + if (hasSprite == 1) { 233 + widget.imageX!![sprite] = buffer.getShortBE() 234 + widget.imageY!![sprite] = buffer.getShortBE() 235 + val spriteName = buffer.getString() 236 + if (spriteName.isNotEmpty()) { 237 + val spriteId = spriteName.lastIndexOf(",") 238 + widget.images!![sprite] = getImage( 239 + spriteName.substring(spriteId + 1).toInt(), 240 + spriteName.substring(0, spriteId) 241 + ) 242 + } 243 + } 244 + } 245 + widget.options = arrayOfNulls(5) 246 + for (optionId in 0 until 5) { 247 + widget.options!![optionId] = buffer.getString() 248 + if (widget.options!![optionId]!!.isEmpty()) 249 + widget.options!![optionId] = null 250 + } 251 + } 252 + if (widget.type == 3) 253 + widget.filled = buffer.getUnsignedByte() == 1 254 + if (widget.type == 4 || widget.type == 1) { 255 + widget.typeFaceCentered = buffer.getUnsignedByte() == 1 256 + val typeFace = buffer.getUnsignedByte() 257 + if (fonts != null) 258 + widget.typeFaces = fonts!![typeFace] 259 + widget.typeFaceShadowed = buffer.getUnsignedByte() == 1 260 + } 261 + if (widget.type == 4) { 262 + widget.disabledText = buffer.getString() 263 + widget.enabledText = buffer.getString() 264 + } 265 + if (widget.type == 1 || widget.type == 3 || widget.type == 4) 266 + widget.disabledColor = buffer.getIntBE() 267 + if (widget.type == 3 || widget.type == 4) { 268 + widget.enabledColor = buffer.getIntBE() 269 + widget.disabledHoveredColor = buffer.getIntBE() 270 + widget.enabledHoveredColor = buffer.getIntBE() 271 + } 272 + if (widget.type == 5) { 273 + var spriteName = buffer.getString() 274 + if (spriteName.isNotEmpty()) { 275 + val spriteId = spriteName.lastIndexOf(",") 276 + widget.disabledImage = getImage( 277 + spriteName.substring(spriteId + 1).toInt(), 278 + spriteName.substring(0, spriteId) 279 + ) 280 + } 281 + spriteName = buffer.getString() 282 + if (spriteName.isNotEmpty()) { 283 + val spriteId = spriteName.lastIndexOf(",") 284 + widget.enabledImage = getImage( 285 + spriteName.substring(spriteId + 1).toInt(), 286 + spriteName.substring(0, spriteId) 287 + ) 288 + } 289 + } 290 + if (widget.type == 6) { 291 + idx = buffer.getUnsignedByte() 292 + if (idx != 0) { 293 + widget.modelType = 1 294 + widget.modelId = (idx - 1 shl 8) + buffer.getUnsignedByte() 295 + } 296 + idx = buffer.getUnsignedByte() 297 + if (idx != 0) { 298 + widget.enabledModelType = 1 299 + widget.enabledModelId = (idx - 1 shl 8) + buffer.getUnsignedByte() 300 + } 301 + idx = buffer.getUnsignedByte() 302 + widget.disabledAnimation = if (idx != 0) (idx - 1 shl 8) + buffer.getUnsignedByte() else -1 303 + idx = buffer.getUnsignedByte() 304 + widget.enabledAnimation = if (idx != 0) (idx - 1 shl 8) + buffer.getUnsignedByte() else -1 305 + widget.zoom = buffer.getUnsignedShortBE() 306 + widget.rotationX = buffer.getUnsignedShortBE() 307 + widget.rotationY = buffer.getUnsignedShortBE() 308 + } 309 + if (widget.type == 7) { 310 + widget.items = IntArray(widget.width * widget.height) 311 + widget.itemAmounts = IntArray(widget.width * widget.height) 312 + widget.typeFaceCentered = buffer.getUnsignedByte() == 1 313 + val typeFaceCount = buffer.getUnsignedByte() 314 + if (fonts != null) 315 + widget.typeFaces = fonts!![typeFaceCount] 316 + widget.typeFaceShadowed = buffer.getUnsignedByte() == 1 317 + widget.disabledColor = buffer.getIntBE() 318 + widget.itemSpritePadsX = buffer.getShortBE() 319 + widget.itemSpritePadsY = buffer.getShortBE() 320 + widget.isInventory = buffer.getUnsignedByte() == 1 321 + widget.options = arrayOfNulls(5) 322 + for (optionId in 0 until 5) { 323 + widget.options!![optionId] = buffer.getString() 324 + if (widget.options!![optionId]!!.isEmpty()) 325 + widget.options!![optionId] = null 326 + } 327 + } 328 + if (widget.type == 8) 329 + widget.disabledText = buffer.getString() 330 + if (widget.actionType == 2 || widget.type == 2) { 331 + widget.optionCircumfix = buffer.getString() 332 + widget.optionText = buffer.getString() 333 + widget.optionAttributes = buffer.getUnsignedShortBE() 334 + } 335 + if (widget.actionType == 1 || widget.actionType == 4 || widget.actionType == 5 || widget.actionType == 6) { 336 + widget.tooltip = buffer.getString() 337 + if (widget.tooltip!!.isEmpty()) { 338 + widget.tooltip = when (widget.actionType) { 339 + 1 -> "Ok" 340 + 4, 5 -> "Select" 341 + 6 -> "Continue" 342 + else -> widget.tooltip 343 + } 344 + } 345 + } 346 + return widget 347 + } 348 + 349 + @JvmStatic 350 + fun load(widgetArchive: Archive, fonts: Array<TypeFace?>, mediaArchive: Archive) { 351 + spriteCache = Cache(50000) 352 + val buffer = Buffer(widgetArchive.getFile("data")!!) 353 + Widget.mediaArchive = mediaArchive 354 + Widget.fonts = fonts 355 + var parentId = -1 356 + val widgetCount = buffer.getUnsignedShortBE() 357 + interfaces = arrayOfNulls(widgetCount) 358 + data = arrayOfNulls(widgetCount) 359 + while (buffer.currentPosition < buffer.buffer.size) { 360 + var widgetIndex = buffer.getUnsignedShortBE() 361 + if (widgetIndex == 65535) { 362 + parentId = buffer.getUnsignedShortBE() 363 + widgetIndex = buffer.getUnsignedShortBE() 364 + } 365 + val i1 = buffer.currentPosition 366 + val widget = parse(parentId, buffer, widgetIndex) 367 + val temp = ByteArray((buffer.currentPosition - i1) + 2) 368 + data!![widget.id] = temp 369 + for (j1 in i1 until buffer.currentPosition) 370 + temp[(j1 - i1) + 2] = buffer.buffer[j1] 371 + temp[0] = (parentId shr 8).toByte() 372 + temp[1] = parentId.toByte() 373 + } 374 + Widget.mediaArchive = null 375 + 376 + // Enable item dragging on the bank items grid (5382). 377 + if (interfaces!!.size > 5382 && interfaces!![5382] != null) { 378 + interfaces!![5382]!!.itemSwapable = true 379 + } 380 + } 381 + 382 + @JvmStatic 383 + fun method200(i: Int) { 384 + if (i == -1) return 385 + for (j in interfaces!!.indices) 386 + if (interfaces!![j] != null && interfaces!![j]!!.parentId == i && interfaces!![j]!!.type != 2) 387 + interfaces!![j] = null 388 + } 389 + 390 + @JvmStatic 391 + fun setModel(modelType: Int, model: Model?, modelId: Int) { 392 + modelCache.removeAll() 393 + if (model != null && modelType != 4) 394 + modelCache.put(model, ((modelType shl 16) + modelId).toLong()) 395 + } 396 + 397 + @JvmStatic 398 + fun reset() { 399 + interfaces = null 400 + mediaArchive = null 401 + spriteCache = null 402 + fonts = null 403 + data = null 404 + } 405 + } 406 + }