mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-13 13:47:47 +02:00
refactor: location spoofer
This commit is contained in:
@ -1,21 +0,0 @@
|
||||
package me.rhunk.snapenhance.core.action.impl
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import me.rhunk.snapenhance.common.BuildConfig
|
||||
import me.rhunk.snapenhance.core.action.AbstractAction
|
||||
|
||||
class OpenMap: AbstractAction() {
|
||||
override fun run() {
|
||||
context.runOnUiThread {
|
||||
val mapActivityIntent = Intent()
|
||||
mapActivityIntent.setClassName(BuildConfig.APPLICATION_ID, BuildConfig.APPLICATION_ID + ".ui.MapActivity")
|
||||
mapActivityIntent.putExtra("location", Bundle().apply {
|
||||
putDouble("latitude", context.config.experimental.spoof.location.latitude.get().toDouble())
|
||||
putDouble("longitude", context.config.experimental.spoof.location.longitude.get().toDouble())
|
||||
})
|
||||
|
||||
context.mainActivity!!.startActivityForResult(mapActivityIntent, 0x1337)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +1,28 @@
|
||||
package me.rhunk.snapenhance.core.features.impl.global
|
||||
|
||||
import android.content.Intent
|
||||
import android.location.Location
|
||||
import android.location.LocationManager
|
||||
import me.rhunk.snapenhance.core.features.Feature
|
||||
import me.rhunk.snapenhance.core.features.FeatureLoadParams
|
||||
import me.rhunk.snapenhance.core.util.hook.HookStage
|
||||
import me.rhunk.snapenhance.core.util.hook.Hooker
|
||||
import me.rhunk.snapenhance.core.util.hook.hook
|
||||
|
||||
class LocationSpoofer: Feature("LocationSpoof", loadParams = FeatureLoadParams.ACTIVITY_CREATE_ASYNC) {
|
||||
override fun asyncOnActivityCreate() {
|
||||
Hooker.hook(context.mainActivity!!.javaClass, "onActivityResult", HookStage.BEFORE) { param ->
|
||||
val intent = param.argNullable<Intent>(2) ?: return@hook
|
||||
val bundle = intent.getBundleExtra("location") ?: return@hook
|
||||
param.setResult(null)
|
||||
class LocationSpoofer: Feature("LocationSpoof", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
|
||||
override fun onActivityCreate() {
|
||||
if (context.config.global.spoofLocation.globalState != true) return
|
||||
|
||||
with(context.config.experimental.spoof.location) {
|
||||
latitude.set(bundle.getFloat("latitude"))
|
||||
longitude.set(bundle.getFloat("longitude"))
|
||||
val coordinates by context.config.global.spoofLocation.coordinates
|
||||
|
||||
context.longToast("Location set to $latitude, $longitude")
|
||||
}
|
||||
Location::class.java.apply {
|
||||
hook("getLatitude", HookStage.BEFORE) { it.setResult(coordinates.first) }
|
||||
hook("getLongitude", HookStage.BEFORE) { it.setResult(coordinates.second) }
|
||||
hook("getAccuracy", HookStage.BEFORE) { it.setResult(0.0F) }
|
||||
}
|
||||
|
||||
if (context.config.experimental.spoof.location.globalState != true) return
|
||||
|
||||
val latitude by context.config.experimental.spoof.location.latitude
|
||||
val longitude by context.config.experimental.spoof.location.longitude
|
||||
|
||||
val locationClass = android.location.Location::class.java
|
||||
val locationManagerClass = android.location.LocationManager::class.java
|
||||
|
||||
locationClass.hook("getLatitude", HookStage.BEFORE) { it.setResult(latitude.toDouble()) }
|
||||
locationClass.hook("getLongitude", HookStage.BEFORE) { it.setResult(longitude.toDouble()) }
|
||||
locationClass.hook("getAccuracy", HookStage.BEFORE) { it.setResult(0.0F) }
|
||||
|
||||
//Might be redundant because it calls isProviderEnabledForUser which we also hook, meaning if isProviderEnabledForUser returns true this will also return true
|
||||
locationManagerClass.hook("isProviderEnabled", HookStage.BEFORE) { it.setResult(true) }
|
||||
locationManagerClass.hook("isProviderEnabledForUser", HookStage.BEFORE) { it.setResult(true) }
|
||||
LocationManager::class.java.apply {
|
||||
//Might be redundant because it calls isProviderEnabledForUser which we also hook, meaning if isProviderEnabledForUser returns true this will also return true
|
||||
hook("isProviderEnabled", HookStage.BEFORE) { it.setResult(true) }
|
||||
hook("isProviderEnabledForUser", HookStage.BEFORE) { it.setResult(true) }
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ import me.rhunk.snapenhance.common.action.EnumAction
|
||||
import me.rhunk.snapenhance.core.ModContext
|
||||
import me.rhunk.snapenhance.core.action.impl.CleanCache
|
||||
import me.rhunk.snapenhance.core.action.impl.ExportChatMessages
|
||||
import me.rhunk.snapenhance.core.action.impl.OpenMap
|
||||
import me.rhunk.snapenhance.core.manager.Manager
|
||||
|
||||
class ActionManager(
|
||||
@ -16,7 +15,6 @@ class ActionManager(
|
||||
mapOf(
|
||||
EnumAction.CLEAN_CACHE to CleanCache::class,
|
||||
EnumAction.EXPORT_CHAT_MESSAGES to ExportChatMessages::class,
|
||||
EnumAction.OPEN_MAP to OpenMap::class,
|
||||
).map {
|
||||
it.key to it.value.java.getConstructor().newInstance().apply {
|
||||
this.context = modContext
|
||||
|
Reference in New Issue
Block a user