package com.firemint.realracing; import android.annotation.TargetApi; import android.hardware.input.InputManager; import android.util.Log; import android.view.InputDevice; import android.view.KeyEvent; import android.view.MotionEvent; import androidx.core.view.InputDeviceCompat; import com.ironsource.v8; /* loaded from: classes2.dex */ public class ControllerManager { public static final int BUTTON_A = 64; public static final int BUTTON_B = 128; public static final int BUTTON_L1 = 1; public static final int BUTTON_L2 = 2; public static final int BUTTON_R1 = 8; public static final int BUTTON_R2 = 16; public static final int BUTTON_X = 256; public static final int BUTTON_Y = 512; public static final int LTRIGGER = 4; public static final int RTRIGGER = 32; private boolean m_bEnableLogging = false; private ControllerManager_Moga m_controllerManager_Moga; protected ControllerInputListener m_inputListener; protected MainActivity m_mainActivity; public enum ControllerAxis { AXIS_LTHUMB_X, AXIS_LTHUMB_Y, AXIS_RTHUMB_X, AXIS_RTHUMB_Y, AXIS_LTRIGGER, AXIS_RTRIGGER, AXIS_MOTION_X, AXIS_MOTION_Y, AXIS_COUNT } public enum ControllerButtons { BTN_A, BTN_B, BTN_X, BTN_Y, BTN_L1, BTN_R1, BTN_L2, BTN_R2, BTN_DPAD_LEFT, BTN_DPAD_RIGHT, BTN_DPAD_UP, BTN_DPAD_DOWN, BTN_SELECT, BTN_START, BTN_DPAD_CENTER, BTN_MEIDA_PLAY_PAUSE, BTN_LEFT_THUMB_LEFT, BTN_LEFT_THUMB_RIGHT, BTN_LEFT_THUMB_UP, BTN_LEFT_THUMB_DOWN, BTN_LEFT_THUMB_PRESS, BTN_RIGHT_THUMB_LEFT, BTN_RIGHT_THUMB_RIGHT, BTN_RIGHT_THUMB_UP, BTN_RIGHT_THUMB_DOWN, BTN_RIGHT_THUMB_PRESS, BTN_COUNT } public native void ControllerConnectedJNI(String str, String str2, int i, int i2); public native void ControllerDisconnectedJNI(int i); public boolean IsControllerEvent(int i) { return (i & 1025) == 1025; } public boolean IsDpadEvent(int i) { return (i & InputDeviceCompat.SOURCE_DPAD) == 513; } public boolean IsJoystickEvent(int i) { return (i & InputDeviceCompat.SOURCE_JOYSTICK) == 16777232; } public native void SetButtonValueJNI(int i, boolean z, int i2); public native void SetJoystickValueJNI(int i, float f, int i2); @TargetApi(16) public class ControllerInputListener implements InputManager.InputDeviceListener { ControllerManager m_controllerManager; InputManager m_inputManager; @Override // android.hardware.input.InputManager.InputDeviceListener public void onInputDeviceChanged(int i) { } public ControllerInputListener(ControllerManager controllerManager) { this.m_inputManager = null; this.m_controllerManager = controllerManager; InputManager inputManager = (InputManager) ControllerManager.this.m_mainActivity.getSystemService("input"); this.m_inputManager = inputManager; inputManager.registerInputDeviceListener(this, ControllerManager.this.m_mainActivity.handler); this.m_inputManager.getInputDevice(-1); CheckExistingControllers(); } public void onDestroy() { this.m_inputManager.unregisterInputDeviceListener(this); } public boolean IsDeviceBlacklisted(InputDevice inputDevice) { return inputDevice.getName().equals("uinput-fpc") || inputDevice.getName().equals("uinput-fortsense"); } public boolean IsInputDeviceAllowed(InputDevice inputDevice) { if (inputDevice.isVirtual()) { return false; } return ((inputDevice.getSources() & 1025) == 1025) && ((inputDevice.getSources() & InputDeviceCompat.SOURCE_JOYSTICK) == 16777232) && !IsDeviceBlacklisted(inputDevice); } @Override // android.hardware.input.InputManager.InputDeviceListener public void onInputDeviceAdded(int i) { InputDevice inputDevice = this.m_inputManager.getInputDevice(i); if (inputDevice != null) { if (IsInputDeviceAllowed(inputDevice)) { ControllerManager.this.Log("onInputDeviceAdded::" + inputDevice.toString()); this.m_controllerManager.ControllerConnected(inputDevice.getName(), inputDevice.getDescriptor(), i, GetOptionalButtonFlags(inputDevice)); return; } ControllerManager.this.Log("onInputDeviceAdded::Input device ignored: " + inputDevice.toString()); } } @Override // android.hardware.input.InputManager.InputDeviceListener public void onInputDeviceRemoved(int i) { ControllerManager.this.Log("onInputDeviceRemoved::Id(" + i + ")"); this.m_controllerManager.ControllerDisconnected(i); } public void CheckExistingControllers() { for (int i : this.m_inputManager.getInputDeviceIds()) { InputDevice inputDevice = this.m_inputManager.getInputDevice(i); if (IsInputDeviceAllowed(inputDevice)) { ControllerManager.this.Log("CheckExistingControllers::" + inputDevice.toString()); this.m_controllerManager.ControllerConnected(inputDevice.getName(), inputDevice.getDescriptor(), i, GetOptionalButtonFlags(inputDevice)); } else { ControllerManager.this.Log("CheckExistingControllers::Input device ignored: " + inputDevice.toString()); } } } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r1v10, types: [int] */ /* JADX WARN: Type inference failed for: r1v13 */ /* JADX WARN: Type inference failed for: r1v14 */ /* JADX WARN: Type inference failed for: r1v15 */ /* JADX WARN: Type inference failed for: r1v16 */ /* JADX WARN: Type inference failed for: r1v17 */ /* JADX WARN: Type inference failed for: r1v18 */ /* JADX WARN: Type inference failed for: r1v19 */ /* JADX WARN: Type inference failed for: r1v42 */ /* JADX WARN: Type inference failed for: r1v43 */ public int GetOptionalButtonFlags(InputDevice inputDevice) { boolean[] hasKeys = ControllerManager.this.IsAtLeastKitKat() ? inputDevice.hasKeys(102, 104, 103, 105, 96, 97, 99, 100) : new boolean[]{true, false, true, false, true, true, true, true}; boolean z = hasKeys[0]; boolean z2 = z; if (hasKeys[1]) { z2 = (z ? 1 : 0) | 2; } boolean z3 = z2; if (hasKeys[2]) { z3 = (z2 ? 1 : 0) | '\b'; } boolean z4 = z3; if (hasKeys[3]) { z4 = (z3 ? 1 : 0) | 16; } boolean z5 = z4; if (hasKeys[4]) { z5 = (z4 ? 1 : 0) | '@'; } boolean z6 = z5; if (hasKeys[5]) { z6 = (z5 ? 1 : 0) | 128; } boolean z7 = z6; if (hasKeys[6]) { z7 = (z6 ? 1 : 0) | 256; } boolean z8 = z7; if (hasKeys[7]) { z8 = (z7 ? 1 : 0) | 512; } ?? r1 = z8; if (ControllerManager.this.HasLTrigger(inputDevice)) { r1 = (z8 ? 1 : 0) | 4; } return ControllerManager.this.HasRTrigger(inputDevice) ? r1 | 32 : r1; } } public boolean HasLTrigger(InputDevice inputDevice) { return (inputDevice.getMotionRange(17) == null && inputDevice.getMotionRange(23) == null) ? false : true; } public boolean HasRTrigger(InputDevice inputDevice) { return (inputDevice.getMotionRange(18) == null && inputDevice.getMotionRange(22) == null && inputDevice.getMotionRange(19) == null) ? false : true; } public void Log(String str) { if (this.m_bEnableLogging) { str.length(); } } public void LogError(String str) { Log.e("RR3ControllerManager", str); } public ControllerManager(MainActivity mainActivity) { this.m_controllerManager_Moga = null; this.m_mainActivity = null; this.m_inputListener = null; Log("onCreate"); this.m_mainActivity = mainActivity; try { this.m_controllerManager_Moga = new ControllerManager_Moga(mainActivity, this); } catch (Exception e) { LogError("Failed to create MOGA controller manager: " + e.toString()); this.m_controllerManager_Moga = null; } if (IsAtLeastJellyBean()) { this.m_inputListener = new ControllerInputListener(this); } } public void onDestroy() { Log("onDestroy"); ControllerManager_Moga controllerManager_Moga = this.m_controllerManager_Moga; if (controllerManager_Moga != null) { controllerManager_Moga.onDestroy(); } ControllerInputListener controllerInputListener = this.m_inputListener; if (controllerInputListener != null) { controllerInputListener.onDestroy(); } } public void onPause() { Log(v8.h.t0); ControllerManager_Moga controllerManager_Moga = this.m_controllerManager_Moga; if (controllerManager_Moga != null) { controllerManager_Moga.onPause(); } } public void onResume() { Log(v8.h.u0); ControllerManager_Moga controllerManager_Moga = this.m_controllerManager_Moga; if (controllerManager_Moga != null) { controllerManager_Moga.onResume(); } ControllerInputListener controllerInputListener = this.m_inputListener; if (controllerInputListener != null) { controllerInputListener.CheckExistingControllers(); } } public boolean IsAtLeastJellyBean() { return MainActivity.IsAtLeastAPI(16); } public boolean IsAtLeastKitKat() { return MainActivity.IsAtLeastAPI(19); } public void PrintButtonString(String str, int i) { StringBuilder sb = new StringBuilder(); sb.append(str); sb.append(" "); sb.append(i == 0 ? "pressed" : "released"); Log(sb.toString()); } @TargetApi(16) public boolean HandleKeyEvents(KeyEvent keyEvent) { if (keyEvent == null || keyEvent.getDevice() == null || !IsAtLeastJellyBean() || keyEvent.getAction() == 2) { return false; } int keyCode = keyEvent.getKeyCode(); if ((keyCode == 104 && HasLTrigger(keyEvent.getDevice())) || (keyCode == 105 && HasRTrigger(keyEvent.getDevice()))) { return false; } return HandleKeyEvents(keyEvent.getDevice().getId(), keyCode, keyEvent.getAction()); } /* JADX WARN: Failed to find 'out' block for switch in B:13:0x001c. Please report as an issue. */ /* JADX WARN: Removed duplicated region for block: B:19:0x010e */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public boolean HandleKeyEvents(final int r6, int r7, int r8) { /* Method dump skipped, instructions count: 320 To view this dump add '--comments-level debug' option */ throw new UnsupportedOperationException("Method not decompiled: com.firemint.realracing.ControllerManager.HandleKeyEvents(int, int, int):boolean"); } public boolean HandleMotionEvents(MotionEvent motionEvent) { if (motionEvent == null || motionEvent.getDevice() == null || !IsAtLeastJellyBean()) { return false; } if (IsControllerEvent(motionEvent.getSource())) { Log("Got motion input from a gamepad??"); return false; } if (IsJoystickEvent(motionEvent.getSource())) { return HandleJoystick(motionEvent); } if (IsDpadEvent(motionEvent.getSource())) { return HandleDpad(motionEvent); } return false; } public float GetJoystickAxisValue(int i, MotionEvent motionEvent) { InputDevice device = motionEvent.getDevice(); if (device != null) { float axisValue = motionEvent.getAxisValue(i); float abs = Math.abs(axisValue); InputDevice.MotionRange motionRange = device.getMotionRange(i); if (motionRange == null || abs >= motionRange.getFlat()) { return axisValue; } return 0.0f; } Log("Input device was null!!!!!"); return 0.0f; } @TargetApi(16) public boolean HandleJoystick(MotionEvent motionEvent) { float GetJoystickAxisValue; boolean HandleDpad = HandleDpad(motionEvent); if (motionEvent.getAction() != 2) { return HandleDpad; } float GetJoystickAxisValue2 = GetJoystickAxisValue(0, motionEvent); float GetJoystickAxisValue3 = GetJoystickAxisValue(1, motionEvent); float GetJoystickAxisValue4 = GetJoystickAxisValue(11, motionEvent); float GetJoystickAxisValue5 = GetJoystickAxisValue(14, motionEvent); float GetJoystickAxisValue6 = GetJoystickAxisValue4 + GetJoystickAxisValue(12, motionEvent); float GetJoystickAxisValue7 = GetJoystickAxisValue5 + GetJoystickAxisValue(13, motionEvent); InputDevice device = motionEvent.getDevice(); float f = 0.0f; if (device.getMotionRange(17) != null) { GetJoystickAxisValue = GetJoystickAxisValue(17, motionEvent); } else { GetJoystickAxisValue = device.getMotionRange(23) != null ? GetJoystickAxisValue(23, motionEvent) : 0.0f; } if (device.getMotionRange(18) != null) { f = GetJoystickAxisValue(18, motionEvent); } else if (device.getMotionRange(22) != null) { f = GetJoystickAxisValue(22, motionEvent); } else if (device.getMotionRange(19) != null) { f = GetJoystickAxisValue(19, motionEvent); } int id = motionEvent.getDevice().getId(); SetJoystickValues(id, GetJoystickAxisValue2, ControllerAxis.AXIS_LTHUMB_X); SetJoystickValues(id, GetJoystickAxisValue3, ControllerAxis.AXIS_LTHUMB_Y); SetJoystickValues(id, GetJoystickAxisValue6, ControllerAxis.AXIS_RTHUMB_X); SetJoystickValues(id, GetJoystickAxisValue7, ControllerAxis.AXIS_RTHUMB_Y); SetJoystickValues(id, GetJoystickAxisValue, ControllerAxis.AXIS_LTRIGGER); SetJoystickValues(id, f, ControllerAxis.AXIS_RTRIGGER); return true; } public void SetJoystickValues(final int i, final float f, final ControllerAxis controllerAxis) { this.m_mainActivity.getGLView().queueEvent(new Runnable() { // from class: com.firemint.realracing.ControllerManager.2 @Override // java.lang.Runnable public void run() { ControllerManager.this.SetJoystickValueJNI(i, f, controllerAxis.ordinal()); } }); } /* JADX WARN: Code restructure failed: missing block: B:15:0x00c1, code lost: if (HandleKeyEvents(r11.getDevice().getId(), 20, 1) != false) goto L32; */ /* JADX WARN: Code restructure failed: missing block: B:16:0x00c3, code lost: r1 = true; */ /* JADX WARN: Code restructure failed: missing block: B:26:0x00ea, code lost: if (HandleKeyEvents(r11.getDevice().getId(), 20, 0) != false) goto L32; */ /* JADX WARN: Code restructure failed: missing block: B:32:0x0112, code lost: if (HandleKeyEvents(r11.getDevice().getId(), 20, 1) != false) goto L32; */ /* JADX WARN: Code restructure failed: missing block: B:40:0x006c, code lost: if (HandleKeyEvents(r11.getDevice().getId(), 22, 0) != false) goto L10; */ /* JADX WARN: Code restructure failed: missing block: B:46:0x0094, code lost: if (HandleKeyEvents(r11.getDevice().getId(), 22, 1) != false) goto L10; */ /* JADX WARN: Code restructure failed: missing block: B:8:0x0043, code lost: if (HandleKeyEvents(r11.getDevice().getId(), 22, 1) != false) goto L10; */ /* JADX WARN: Code restructure failed: missing block: B:9:0x0045, code lost: r2 = true; */ @android.annotation.TargetApi(16) /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public boolean HandleDpad(android.view.InputEvent r11) { /* Method dump skipped, instructions count: 313 To view this dump add '--comments-level debug' option */ throw new UnsupportedOperationException("Method not decompiled: com.firemint.realracing.ControllerManager.HandleDpad(android.view.InputEvent):boolean"); } public void ControllerConnected(final String str, final String str2, final int i, final int i2) { this.m_mainActivity.getGLView().queueEvent(new Runnable() { // from class: com.firemint.realracing.ControllerManager.3 @Override // java.lang.Runnable public void run() { ControllerManager.this.ControllerConnectedJNI(str, str2, i, i2); } }); } public void ControllerDisconnected(final int i) { this.m_mainActivity.getGLView().queueEvent(new Runnable() { // from class: com.firemint.realracing.ControllerManager.4 @Override // java.lang.Runnable public void run() { ControllerManager.this.ControllerDisconnectedJNI(i); } }); } }