mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-12 13:17:42 +02:00
fix(video_length_bypass): story black videos
This commit is contained in:
@ -10,6 +10,7 @@ import me.rhunk.snapenhance.core.eventbus.events.impl.OnSnapInteractionEvent
|
||||
import me.rhunk.snapenhance.core.eventbus.events.impl.SendMessageWithContentEvent
|
||||
import me.rhunk.snapenhance.core.eventbus.events.impl.SnapWidgetBroadcastReceiveEvent
|
||||
import me.rhunk.snapenhance.data.wrapper.impl.MessageContent
|
||||
import me.rhunk.snapenhance.data.wrapper.impl.MessageDestinations
|
||||
import me.rhunk.snapenhance.data.wrapper.impl.SnapUUID
|
||||
import me.rhunk.snapenhance.hook.HookStage
|
||||
import me.rhunk.snapenhance.hook.hook
|
||||
@ -23,8 +24,10 @@ class EventDispatcher(
|
||||
) : Manager {
|
||||
override fun init() {
|
||||
context.classCache.conversationManager.hook("sendMessageWithContent", HookStage.BEFORE) { param ->
|
||||
val messageContent = MessageContent(param.arg(1))
|
||||
context.event.post(SendMessageWithContentEvent(messageContent).apply { adapter = param })?.also {
|
||||
context.event.post(SendMessageWithContentEvent(
|
||||
destinations = MessageDestinations(param.arg(0)),
|
||||
messageContent = MessageContent(param.arg(1))
|
||||
).apply { adapter = param })?.also {
|
||||
if (it.canceled) {
|
||||
param.setResult(null)
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package me.rhunk.snapenhance.core.eventbus.events.impl
|
||||
|
||||
import me.rhunk.snapenhance.core.eventbus.events.AbstractHookEvent
|
||||
import me.rhunk.snapenhance.data.wrapper.impl.MessageContent
|
||||
import me.rhunk.snapenhance.data.wrapper.impl.MessageDestinations
|
||||
|
||||
class SendMessageWithContentEvent(
|
||||
val destinations: MessageDestinations,
|
||||
val messageContent: MessageContent
|
||||
) : AbstractHookEvent()
|
@ -1,15 +1,48 @@
|
||||
package me.rhunk.snapenhance.features.impl.tweaks
|
||||
|
||||
import android.os.Build
|
||||
import android.os.FileObserver
|
||||
import com.google.gson.JsonParser
|
||||
import me.rhunk.snapenhance.Logger
|
||||
import me.rhunk.snapenhance.core.eventbus.events.impl.SendMessageWithContentEvent
|
||||
import me.rhunk.snapenhance.features.Feature
|
||||
import me.rhunk.snapenhance.features.FeatureLoadParams
|
||||
import me.rhunk.snapenhance.hook.HookStage
|
||||
import me.rhunk.snapenhance.hook.Hooker
|
||||
import java.io.File
|
||||
|
||||
class DisableVideoLengthRestriction : Feature("DisableVideoLengthRestriction", loadParams = FeatureLoadParams.ACTIVITY_CREATE_ASYNC) {
|
||||
private lateinit var fileObserver: FileObserver
|
||||
|
||||
override fun asyncOnActivityCreate() {
|
||||
val defaultMediaItem = context.mappings.getMappedClass("DefaultMediaItem")
|
||||
val isState by context.config.global.disableVideoLengthRestrictions
|
||||
|
||||
//fix black videos when story is posted
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val postedStorySnapFolder = File(context.androidContext.filesDir, "file_manager/posted_story_snap")
|
||||
|
||||
fileObserver = (object : FileObserver(postedStorySnapFolder, MOVED_TO) {
|
||||
override fun onEvent(event: Int, path: String?) {
|
||||
if (event != MOVED_TO || path?.endsWith("posted_story_snap.2") != true) return
|
||||
fileObserver.stopWatching()
|
||||
|
||||
val file = File(postedStorySnapFolder, path)
|
||||
runCatching {
|
||||
val fileContent = JsonParser.parseReader(file.reader()).asJsonObject
|
||||
if (fileContent["timerOrDuration"].asLong < 0) file.delete()
|
||||
}.onFailure {
|
||||
Logger.error("Failed to read story metadata file", it)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
context.event.subscribe(SendMessageWithContentEvent::class) { event ->
|
||||
if (event.destinations.stories.isEmpty()) return@subscribe
|
||||
fileObserver.startWatching()
|
||||
}
|
||||
}
|
||||
|
||||
Hooker.hookConstructor(defaultMediaItem, HookStage.BEFORE, { isState }) { param ->
|
||||
//set the video length argument
|
||||
param.setArg(5, -1L)
|
||||
|
Reference in New Issue
Block a user