commit e4c4af8a6390f3ec767c2fc4b4d52ea640eb7947
parent a877c04461f07e282575ed288e6663b356d14b80
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Tue, 20 Aug 2024 10:25:42 +0200

feat(core): show battery level

Diffstat:
Mcommon/src/main/assets/lang/en_US.json | 4++++
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Global.kt | 1+
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/util/protobuf/ProtoReader.kt | 3+++
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/BetterLocation.kt | 16++++++++++++++--
4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -771,6 +771,10 @@ "spoof_headphones": { "name": "Spoof Headphones", "description": "Spoofs the status of listening to music on map" + }, + "show_battery_level": { + "name": "Show Battery Level", + "description": "Shows the battery level of your friends on the map" } } }, diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Global.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Global.kt @@ -27,6 +27,7 @@ class Global : ConfigContainer() { val suspendLocationUpdates = boolean("suspend_location_updates") val spoofBatteryLevel = string("spoof_battery_level") { requireRestart(); inputCheck = { it.isEmpty() || it.toIntOrNull() in 0..100 } } val spoofHeadphones = boolean("spoof_headphones") { requireRestart() } + val showBatteryLevel = boolean("show_battery_level") { requireRestart() } } inner class MediaUploadQualityConfig : ConfigContainer() { 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 @@ -201,6 +201,9 @@ class ProtoReader(private val buffer: ByteArray) { return value } + @JSFunction + fun getFixed32(vararg ids: Int) = followPath(*ids, excludeLast = true)?.getFixed32(ids.last()) + private fun prettyPrint(tabSize: Int): String { val tabLine = " ".repeat(tabSize) val stringBuilder = StringBuilder() 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 @@ -29,6 +29,7 @@ import me.rhunk.snapenhance.core.util.RandomWalking import me.rhunk.snapenhance.core.util.hook.HookStage import me.rhunk.snapenhance.core.util.hook.hook import me.rhunk.snapenhance.core.util.ktx.getId +import me.rhunk.snapenhance.core.util.ktx.getObjectField import me.rhunk.snapenhance.core.util.ktx.isDarkTheme import me.rhunk.snapenhance.mapper.impl.CallbackMapper import java.nio.ByteBuffer @@ -40,7 +41,8 @@ data class FriendLocation( val longitude: Double, val lastUpdated: Long, val locality: String?, - val localityPieces: List<String> + val localityPieces: List<String>, + val batteryLevel: Float, ) class BetterLocation : Feature("Better Location") { @@ -137,7 +139,8 @@ class BetterLocation : Feature("Better Location") { if (index != 11) return@forEach it.add((wire.value as ByteArray).toString(Charsets.UTF_8) ) } - } + }, + batteryLevel = getFixed32(7, 13)?.let { Float.fromBits(it) } ?: -1F, ) locationHistory[userId] = friendCluster @@ -181,6 +184,15 @@ class BetterLocation : Feature("Better Location") { val mapFeaturesRootId = context.resources.getId("map_features_root") + if (context.config.global.betterLocation.showBatteryLevel.get()) { + findClass("snap.snap_maps_sdk.nano.SnapMapsSdk\$PublicUserInfo").hook("setDisplayName", HookStage.BEFORE) { param -> + val instance = param.thisObject<Any>() + val userId = instance.getObjectField("userId_") as? String ?: return@hook + val batteryLevel = locationHistory[userId]?.batteryLevel?.takeIf { it > -1F } ?: return@hook + param.setArg(0, param.arg<String>(0) + " (${(batteryLevel * 100).toInt()}%)") + } + } + context.event.subscribe(AddViewEvent::class) { event -> if (event.view.id != mapFeaturesRootId) return@subscribe val view = event.view as RelativeLayout