From 82e9a298adea42eae8d99e7caf4d2171b6c37ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis?= <97699850+janisslsm@users.noreply.github.com> Date: Thu, 15 Dec 2022 06:13:51 +0200 Subject: [PATCH] fix: sounds res id resolving (#3) --- .../discord/sounds/SoundManagerModule.java | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 app/src/main/java/com/discord/sounds/SoundManagerModule.java diff --git a/app/src/main/java/com/discord/sounds/SoundManagerModule.java b/app/src/main/java/com/discord/sounds/SoundManagerModule.java new file mode 100644 index 0000000..6862960 --- /dev/null +++ b/app/src/main/java/com/discord/sounds/SoundManagerModule.java @@ -0,0 +1,125 @@ +package com.discord.sounds; + +import com.discord.BuildConfig; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import android.content.Context; +import com.discord.logging.Log; +import com.facebook.react.bridge.Callback; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactMethod; +import kotlin.jvm.internal.r; + +public final class SoundManagerModule extends ReactContextBaseJavaModule { + private final SoundManager soundManager; + + public SoundManagerModule(ReactApplicationContext reactApplicationContext0) { + super(reactApplicationContext0); + r.g(reactApplicationContext0, "reactContext"); + this.soundManager = new SoundManager(reactApplicationContext0); + } + + @Override // com.facebook.react.bridge.NativeModule + public String getName() { + return "DCDSoundManager"; + } + + @ReactMethod + public final void pause(int v) { + Log.i$default(Log.INSTANCE, "SoundManager", "Pause " + v, null, 4, null); + this.soundManager.pause(v); + } + + @ReactMethod + public final void play(int v) { + Log.i$default(Log.INSTANCE, "SoundManager", "Play " + v, null, 4, null); + this.soundManager.play(v); + } + + @ReactMethod + public final void prepare(String s, String s1, int v, Callback callback0) { + r.g(s, "fileName"); + r.g(callback0, "callback"); + Log.i$default(Log.INSTANCE, "SoundManager", "Prepare " + s + " with " + v + ".", null, 4, null); + int v1 = 5; + if(s1 != null) { + int hashCode = s1.hashCode(); + if(hashCode != 0x6B2E132) { + switch(hashCode) { + case 0x11F69621: { + if(s1.equals("ring_tone")) { + v1 = 6; + } + + break; + } + case 595233003: { + s1.equals("notification"); + } + } + } + else if(s1.equals("voice")) { + v1 = 2; + } + } + + ReactApplicationContext reactApplicationContext0 = this.getReactApplicationContext(); + r.f(reactApplicationContext0, "reactApplicationContext"); + int v3 = SoundManagerModule.resolveRawResId$default(this, reactApplicationContext0, s, null, 2, null); + com.discord.sounds.SoundManagerModule$prepare$1 soundManagerModule$prepare$10 = new com.discord.sounds.SoundManagerModule$prepare$1(callback0); + this.soundManager.prepare(v, v1, v3, soundManagerModule$prepare$10); + } + + @ReactMethod + public final void release(int v) { + Log.i$default(Log.INSTANCE, "SoundManager", "Release " + v, null, 4, null); + this.soundManager.release(v); + } + + private final int resolveRawResId(Context context0, String s, String s1) { + // ALIUCORD CHANGED: dynamic package name lookup -> BuildConfig.APPLICATION_ID + int v = context0.getResources().getIdentifier(s, s1, BuildConfig.APPLICATION_ID); + if(v > 0) { + return v; + } + + throw new IllegalArgumentException("Trying to resolve unknown sound " + s); + } + + static int resolveRawResId$default(SoundManagerModule soundManagerModule0, Context context0, String s, String s1, int v, Object object0) { + if((v & 2) != 0) { + s1 = "raw"; + } + + return soundManagerModule0.resolveRawResId(context0, s, s1); + } + + @ReactMethod + public final void setCurrentTime(int v, int v1) { + Log.i$default(Log.INSTANCE, "SoundManager", "Set current time for " + v + " with value " + v1, null, 4, null); + this.soundManager.setCurrentTime(v, v1); + } + + @ReactMethod + public final void setNumberOfLoops(int v, int v1) { + Log.i$default(Log.INSTANCE, "SoundManager", "Set number of loops for " + v + " with value " + v1, null, 4, null); + this.soundManager.setNumberOfLoops(v, v1); + } + + @ReactMethod + public final void setPan(int v, int v1) { + Log.i$default(Log.INSTANCE, "SoundManager", "Set pan for " + v + " with value " + v1, null, 4, null); + this.soundManager.setPan(v, ((float)v1)); + } + + @ReactMethod + public final void setVolume(int v, float f) { + Log.i$default(Log.INSTANCE, "SoundManager", "Set volume for " + v + " with value " + f, null, 4, null); + this.soundManager.setVolume(v, f); + } + + @ReactMethod + public final void stop(int v) { + Log.i$default(Log.INSTANCE, "SoundManager", "Stop " + v, null, 4, null); + this.soundManager.stop(v); + } +}