commit 81f626cc3be11789f03aac1321cf72ffb11d6a2f parent 8823093b30746348bbfb1310823822f9f738e931 Author: rhunk <101876869+rhunk@users.noreply.github.com> Date: Wed, 8 Nov 2023 17:30:48 +0100 feat(core/camera_tweaks): black photos Diffstat:
3 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -434,6 +434,10 @@ "name": "Disable Camera", "description": "Prevents Snapchat from using the cameras available on your device" }, + "black_photos": { + "name": "Black Photos", + "description": "Replaces captured photos with a black background\nVideos are not affected" + }, "immersive_camera_preview": { "name": "Immersive Preview", "description": "Prevents Snapchat from Cropping the Camera preview\nThis might cause the camera to flicker on some devices" diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Camera.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Camera.kt @@ -40,6 +40,7 @@ class Camera : ConfigContainer() { val disable = boolean("disable_camera") val immersiveCameraPreview = boolean("immersive_camera_preview") { addNotices(FeatureNotice.UNSTABLE) } + val blackPhotos = boolean("black_photos") val overridePreviewResolution get() = _overridePreviewResolution val overridePictureResolution get() = _overridePictureResolution val customFrameRate = unique("custom_frame_rate", diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/tweaks/CameraTweaks.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/tweaks/CameraTweaks.kt @@ -4,9 +4,11 @@ import android.Manifest import android.annotation.SuppressLint import android.content.ContextWrapper import android.content.pm.PackageManager +import android.graphics.Bitmap import android.hardware.camera2.CameraCharacteristics import android.hardware.camera2.CameraCharacteristics.Key import android.hardware.camera2.CameraManager +import android.media.Image import android.util.Range import me.rhunk.snapenhance.core.features.Feature import me.rhunk.snapenhance.core.features.FeatureLoadParams @@ -15,6 +17,8 @@ import me.rhunk.snapenhance.core.util.hook.hook import me.rhunk.snapenhance.core.util.hook.hookConstructor import me.rhunk.snapenhance.core.util.ktx.setObjectField import me.rhunk.snapenhance.core.wrapper.impl.ScSize +import java.io.ByteArrayOutputStream +import java.nio.ByteBuffer class CameraTweaks : Feature("Camera Tweaks", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) { @@ -71,5 +75,20 @@ class CameraTweaks : Feature("Camera Tweaks", loadParams = FeatureLoadParams.ACT } } } + + if (context.config.camera.blackPhotos.get()) { + findClass("android.media.ImageReader\$SurfaceImage").hook("getPlanes", HookStage.AFTER) { param -> + val image = param.thisObject() as? Image ?: return@hook + val planes = param.getResult() as? Array<*> ?: return@hook + val output = ByteArrayOutputStream() + Bitmap.createBitmap(image.width, image.height, Bitmap.Config.ARGB_8888).apply { + compress(Bitmap.CompressFormat.JPEG, 100, output) + recycle() + } + planes.filterNotNull().forEach { plane -> + plane.setObjectField("mBuffer", ByteBuffer.wrap(output.toByteArray())) + } + } + } } } \ No newline at end of file