diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/util/protobuf/ProtoReader.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/util/protobuf/ProtoReader.kt index 1297d9fa..abbf9d46 100644 --- a/common/src/main/kotlin/me/rhunk/snapenhance/common/util/protobuf/ProtoReader.kt +++ b/common/src/main/kotlin/me/rhunk/snapenhance/common/util/protobuf/ProtoReader.kt @@ -192,8 +192,8 @@ class ProtoReader(private val buffer: ByteArray) { @JSFunction - fun getFixed32(id: Int): Int { - val bytes = getByteArray(id) ?: return 0 + fun getFixed32(id: Int): Int? { + val bytes = getByteArray(id) ?: return null var value = 0 for (i in 0..3) { value = value or ((bytes[i].toInt() and 0xFF) shl (i * 8)) diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/BetterLocation.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/BetterLocation.kt index c5c6a97e..be96dd96 100644 --- a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/BetterLocation.kt +++ b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/BetterLocation.kt @@ -129,23 +129,33 @@ class BetterLocation : Feature("Better Location") { private fun onLocationEvent(protoReader: ProtoReader) { protoReader.eachBuffer(3, 1) { - val userId = UUID(getFixed64(1, 1) ?: return@eachBuffer, getFixed64(1, 2) ?: return@eachBuffer).toString() - val friendCluster = FriendLocation( - userId = userId, - latitude = Float.fromBits(getFixed32(4)).toDouble(), - longitude = Float.fromBits(getFixed32(5)).toDouble(), - lastUpdated = getVarInt(7, 2) ?: -1L, - locality = getString(10), - localityPieces = mutableListOf().also { - forEach { index, wire -> - if (index != 11) return@forEach - it.add((wire.value as ByteArray).toString(Charsets.UTF_8) ) - } - }, - batteryLevel = getFixed32(7, 13)?.let { Float.fromBits(it) } ?: -1F, - ) + val clusterId = UUID(getFixed64(1, 1) ?: return@eachBuffer, getFixed64(1, 2) ?: return@eachBuffer).toString() - locationHistory[userId] = friendCluster + val latitude = getFixed32(4)?.let { Float.fromBits(it) }?.toDouble() ?: return@eachBuffer + val longitude = getFixed32(5)?.let { Float.fromBits(it) }?.toDouble() ?: return@eachBuffer + + val locality = getString(10) + val localityPieces = mutableListOf().also { + forEach { index, wire -> + if (index != 11) return@forEach + it.add((wire.value as ByteArray).toString(Charsets.UTF_8) ) + } + } + + eachBuffer(7) friend@{ + val userId = if (contains(1)) UUID(getFixed64(1, 1) ?: return@friend, getFixed64(1, 2) ?: return@friend).toString() else clusterId + val friendLocation = FriendLocation( + userId = userId, + latitude = latitude, + longitude = longitude, + lastUpdated = getVarInt(2) ?: -1L, + locality = locality, + localityPieces = localityPieces, + batteryLevel = getFixed32(13)?.let { Float.fromBits(it) } ?: -1F, + ) + + locationHistory[userId] = friendLocation + } } }