feat(core): show battery level

This commit is contained in:
rhunk
2024-08-20 10:25:42 +02:00
parent a877c04461
commit e4c4af8a63
4 changed files with 22 additions and 2 deletions

View File

@@ -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"
}
}
},

View File

@@ -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() {

View File

@@ -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()

View File

@@ -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