Skip to content

Commit

Permalink
fix: Disable force original audio in settings when using Android VR…
Browse files Browse the repository at this point in the history
… spoofing
  • Loading branch information
LisoUseInAIKyrios committed Dec 20, 2024
1 parent c1add51 commit e635f87
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public class SpoofVideoStreamsPatch {
private static final String UNREACHABLE_HOST_URI_STRING = "https://127.0.0.0";
private static final Uri UNREACHABLE_HOST_URI = Uri.parse(UNREACHABLE_HOST_URI_STRING);

/**
* @return If this patch was included during patching.
*/
public static boolean isPatchIncluded() {
return false; // Modified during patching.
}

/**
* Injection point.
* Blocks /get_watch requests by returning an unreachable URI.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
package app.revanced.extension.youtube.patches;

import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.settings.BaseSettings;
import app.revanced.extension.shared.settings.EnumSetting;
import app.revanced.extension.shared.settings.Setting;
import app.revanced.extension.shared.spoof.ClientType;
import app.revanced.extension.shared.spoof.SpoofVideoStreamsPatch;
import app.revanced.extension.youtube.settings.Settings;

@SuppressWarnings("unused")
public class ForceOriginalAudioPatch {

private static final String DEFAULT_AUDIO_TRACKS_SUFFIX = ".4";

public static final class ForceOriginalAudioAvailability implements Setting.Availability {
@Override
public boolean isAvailable() {
if (SpoofVideoStreamsPatch.isPatchIncluded()) {
// Force audio does not work with Android VR.
EnumSetting<ClientType> clientType = BaseSettings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE;
return clientType.isAvailable() && clientType.get() != ClientType.ANDROID_VR;
}

return true;
}
}

/**
* Injection point.
*/
Expand All @@ -34,8 +52,8 @@ public static boolean isDefaultAudioStream(boolean isDefault, String audioTrackI
return isOriginal;
} catch (Exception ex) {
Logger.printException(() -> "isDefaultAudioStream failure", ex);
}

return isDefault;
return isDefault;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static app.revanced.extension.shared.settings.Setting.parent;
import static app.revanced.extension.shared.settings.Setting.parentsAny;
import static app.revanced.extension.youtube.patches.ChangeStartPagePatch.StartPage;
import static app.revanced.extension.youtube.patches.ForceOriginalAudioPatch.ForceOriginalAudioAvailability;
import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerHideExpandCloseAvailability;
import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerHorizontalDragAvailability;
import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerType;
Expand Down Expand Up @@ -53,7 +54,7 @@ public class Settings extends BaseSettings {
public static final StringSetting CUSTOM_PLAYBACK_SPEEDS = new StringSetting("revanced_custom_playback_speeds",
"0.25\n0.5\n0.75\n0.9\n0.95\n1.0\n1.05\n1.1\n1.25\n1.5\n1.75\n2.0\n3.0\n4.0\n5.0", true);
// Audio
public static final BooleanSetting FORCE_ORIGINAL_AUDIO = new BooleanSetting("revanced_force_original_audio", FALSE);
public static final BooleanSetting FORCE_ORIGINAL_AUDIO = new BooleanSetting("revanced_force_original_audio", FALSE, new ForceOriginalAudioAvailability());

// Ads
public static final BooleanSetting HIDE_BUTTONED_ADS = new BooleanSetting("revanced_hide_buttoned_ads", TRUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,12 @@ internal val hlsCurrentTimeFingerprint = fingerprint {
HLS_CURRENT_TIME_FEATURE_FLAG
}
}

internal val patchIncludedExtensionMethodFingerprint = fingerprint {
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC)
returns("Z")
parameters()
custom { method, classDef ->
classDef.type == EXTENSION_CLASS_DESCRIPTOR && method.name == "isPatchIncluded"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import app.revanced.patches.all.misc.resources.addResourcesPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.insertFeatureFlagBooleanOverride
import app.revanced.util.returnEarly
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
Expand All @@ -39,6 +40,12 @@ fun spoofVideoStreamsPatch(
dependsOn(addResourcesPatch)

execute {
// region Enable extension helper method used by other patches

patchIncludedExtensionMethodFingerprint.method.returnEarly(true)

// endregion

// region Block /initplayback requests to fall back to /get_watch requests.

val moveUriStringIndex = buildInitPlaybackRequestFingerprint.patternMatch!!.startIndex
Expand Down

0 comments on commit e635f87

Please sign in to comment.