fix(core): old bitmoji selfie

This commit is contained in:
rhunk
2023-10-29 13:17:09 +01:00
parent a879419fc5
commit 45f4c65ab3
3 changed files with 26 additions and 11 deletions

View File

@ -274,9 +274,9 @@
"name": "Hide UI Components", "name": "Hide UI Components",
"description": "Select which UI components to hide" "description": "Select which UI components to hide"
}, },
"2d_bitmoji_selfie": { "old_bitmoji_selfie": {
"name": "2D Bitmoji Selfie", "name": "Old Bitmoji Selfie",
"description": "Brings back the 2D Bitmoji selfies from older Snapchat versions\nYou may need to clean the Snapchat cache for this to take effect" "description": "Brings back the Bitmoji selfies from older Snapchat versions"
}, },
"disable_spotlight": { "disable_spotlight": {
"name": "Disable Spotlight", "name": "Disable Spotlight",
@ -693,6 +693,10 @@
"bypass_video_length_restriction": { "bypass_video_length_restriction": {
"single": "Single media", "single": "Single media",
"split": "Split media" "split": "Split media"
},
"old_bitmoji_selfie": {
"2d": "2D Bitmoji",
"3d": "3D Bitmoji"
} }
} }
}, },

View File

@ -41,7 +41,7 @@ class UserInterfaceTweaks : ConfigContainer() {
"hide_chat_call_buttons", "hide_chat_call_buttons",
"hide_profile_call_buttons" "hide_profile_call_buttons"
) { requireRestart() } ) { requireRestart() }
val ddBitmojiSelfie = boolean("2d_bitmoji_selfie") { requireCleanCache() } val oldBitmojiSelfie = unique("old_bitmoji_selfie", "2d", "3d") { requireCleanCache() }
val disableSpotlight = boolean("disable_spotlight") { requireRestart() } val disableSpotlight = boolean("disable_spotlight") { requireRestart() }
val storyViewerOverride = unique("story_viewer_override", "DISCOVER_PLAYBACK_SEEKBAR", "VERTICAL_STORY_VIEWER") { requireRestart() } val storyViewerOverride = unique("story_viewer_override", "DISCOVER_PLAYBACK_SEEKBAR", "VERTICAL_STORY_VIEWER") { requireRestart() }
} }

View File

@ -1,5 +1,6 @@
package me.rhunk.snapenhance.core.features.impl.ui package me.rhunk.snapenhance.core.features.impl.ui
import android.net.Uri
import me.rhunk.snapenhance.common.util.snap.BitmojiSelfie import me.rhunk.snapenhance.common.util.snap.BitmojiSelfie
import me.rhunk.snapenhance.core.event.events.impl.NetworkApiRequestEvent import me.rhunk.snapenhance.core.event.events.impl.NetworkApiRequestEvent
import me.rhunk.snapenhance.core.features.Feature import me.rhunk.snapenhance.core.features.Feature
@ -8,15 +9,25 @@ import me.rhunk.snapenhance.core.features.FeatureLoadParams
class OldBitmojiSelfie : Feature("OldBitmojiSelfie", loadParams = FeatureLoadParams.INIT_SYNC) { class OldBitmojiSelfie : Feature("OldBitmojiSelfie", loadParams = FeatureLoadParams.INIT_SYNC) {
override fun init() { override fun init() {
val urlPrefixes = arrayOf("https://images.bitmoji.com/3d/render/", "https://cf-st.sc-cdn.net/3d/render/") val urlPrefixes = arrayOf("https://images.bitmoji.com/3d/render/", "https://cf-st.sc-cdn.net/3d/render/")
val state by context.config.userInterface.ddBitmojiSelfie val oldBitmojiSelfie = context.config.userInterface.oldBitmojiSelfie.getNullable() ?: return
context.event.subscribe(NetworkApiRequestEvent::class, { state }) { event -> context.event.subscribe(NetworkApiRequestEvent::class) { event ->
if (urlPrefixes.firstOrNull { event.url.startsWith(it) } == null) return@subscribe if (urlPrefixes.firstOrNull { event.url.startsWith(it) } == null) return@subscribe
val bitmojiURI = event.url.substringAfterLast("/") event.url = event.url.replace("ua=1", "") // replace ua=1 with nothing for old 3d selfies/background
event.url =
BitmojiSelfie.BitmojiSelfieType.STANDARD.prefixUrl + // replace with old 2d selfies
bitmojiURI + if (oldBitmojiSelfie == "2d" && event.url.contains("trim=circle")) {
(bitmojiURI.takeIf { !it.contains("?") }?.let { "?" } ?: "&") + "transparent=1" val bitmojiPath = event.url.substringAfterLast("/").substringBeforeLast("?")
event.url = Uri.parse(BitmojiSelfie.BitmojiSelfieType.STANDARD.prefixUrl)
.buildUpon()
.appendPath(bitmojiPath)
.appendQueryParameter("transparent", "1")
.appendQueryParameter("trim", "circle")
.build()
.toString()
}
if (arrayOf("?", "&").any { event.url.endsWith(it) }) event.url = event.url.dropLast(1)
} }
} }
} }