package com.unity3d.player;

import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Iterator;

/* loaded from: /storage/emulated/0/Documents/jadec/sources/com.UBI.A90.WW/dex-files/2.dex */
class ReflectionHelper {
    protected static boolean LOG = false;
    protected static final boolean LOGV = false;

    ReflectionHelper() {
    }

    private static float a(Class cls, Class cls2) {
        if (cls.equals(cls2)) {
            return 1.0f;
        }
        if (!cls.isPrimitive() && !cls2.isPrimitive()) {
            try {
                if (cls.asSubclass(cls2) != null) {
                    return 0.5f;
                }
            } catch (ClassCastException e) {
            }
            try {
                if (cls2.asSubclass(cls) != null) {
                    return 0.1f;
                }
            } catch (ClassCastException e2) {
            }
        }
        return 0.0f;
    }

    private static float a(Class cls, Class[] clsArr, Class[] clsArr2) {
        int i = 0;
        if (clsArr2.length == 0) {
            return 0.1f;
        }
        if ((clsArr == null ? 0 : clsArr.length) + 1 != clsArr2.length) {
            return 0.0f;
        }
        float f = 1.0f;
        if (clsArr != null) {
            int length = clsArr.length;
            int i2 = 0;
            while (i < length) {
                f *= a(clsArr[i], clsArr2[i2]);
                i++;
                i2++;
            }
        }
        return f * a(cls, clsArr2[clsArr2.length - 1]);
    }

    private static Class a(String str, int[] iArr) {
        while (true) {
            if (iArr[0] >= str.length()) {
                break;
            }
            int i = iArr[0];
            iArr[0] = i + 1;
            char charAt = str.charAt(i);
            if (charAt != '(' && charAt != ')') {
                if (charAt == 'L') {
                    int indexOf = str.indexOf(59, iArr[0]);
                    if (indexOf != -1) {
                        String substring = str.substring(iArr[0], indexOf);
                        iArr[0] = indexOf + 1;
                        try {
                            return Class.forName(substring.replace('/', '.'));
                        } catch (ClassNotFoundException e) {
                        }
                    }
                } else if (charAt == 'Z') {
                    return Boolean.TYPE;
                } else {
                    if (charAt == 'I') {
                        return Integer.TYPE;
                    }
                    if (charAt == 'F') {
                        return Float.TYPE;
                    }
                    if (charAt == 'V') {
                        return Void.TYPE;
                    }
                    if (charAt == 'B') {
                        return Byte.TYPE;
                    }
                    if (charAt == 'S') {
                        return Short.TYPE;
                    }
                    if (charAt == 'J') {
                        return Long.TYPE;
                    }
                    if (charAt == 'D') {
                        return Double.TYPE;
                    }
                    if (charAt == '[') {
                        return Array.newInstance(a(str, iArr), 0).getClass();
                    }
                    m.Log(5, "! parseType; " + charAt + " is not known!");
                }
            }
        }
        return null;
    }

    private static Class[] a(String str) {
        Class a;
        int[] iArr = {0};
        ArrayList arrayList = new ArrayList();
        while (iArr[0] < str.length() && (a = a(str, iArr)) != null) {
            arrayList.add(a);
        }
        Class[] clsArr = new Class[arrayList.size()];
        Iterator it = arrayList.iterator();
        int i = 0;
        while (it.hasNext()) {
            clsArr[i] = (Class) it.next();
            i++;
        }
        return clsArr;
    }

    protected static Constructor getConstructorID(Class cls, String str) {
        Constructor<?> constructor;
        Constructor<?> constructor2;
        Class[] a = a(str);
        Constructor<?> constructor3 = null;
        float f = 0.0f;
        Constructor<?>[] constructors = cls.getConstructors();
        int length = constructors.length;
        int i = 0;
        while (true) {
            if (i >= length) {
                constructor = constructor3;
                break;
            }
            constructor = constructors[i];
            float a2 = a(Void.TYPE, constructor.getParameterTypes(), a);
            if (a2 <= f) {
                a2 = f;
                constructor2 = constructor3;
            } else if (a2 == 1.0f) {
                break;
            } else {
                constructor2 = constructor;
            }
            i++;
            constructor3 = constructor2;
            f = a2;
        }
        if (constructor == null) {
            m.Log(6, "! getConstructorID(\"" + cls.getName() + "\", \"" + str + "\") FAILED!");
        }
        return constructor;
    }

    /* JADX WARN: Code restructure failed: missing block: B:29:0x006c, code lost:
        com.unity3d.player.m.Log(6, "! getFieldID(\"" + r12 + "\", \"" + r13 + "\") FAILED!");
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    protected static java.lang.reflect.Field getFieldID(java.lang.Class r11, java.lang.String r12, java.lang.String r13, boolean r14) {
        /*
            r4 = 0
            r10 = 1065353216(0x3f800000, float:1.0)
            java.lang.Class[] r6 = a(r13)
            r0 = 0
            r1 = r0
            r0 = r4
        La:
            if (r11 == 0) goto L6a
            java.lang.reflect.Field[] r7 = r11.getDeclaredFields()
            int r8 = r7.length
            r2 = 0
            r5 = r2
            r3 = r0
        L14:
            if (r5 >= r8) goto L93
            r2 = r7[r5]
            int r0 = r2.getModifiers()
            boolean r0 = java.lang.reflect.Modifier.isStatic(r0)
            if (r14 != r0) goto L90
            java.lang.String r0 = r2.getName()
            int r0 = r0.compareTo(r12)
            if (r0 != 0) goto L90
            java.lang.Class r0 = r2.getType()
            float r0 = a(r0, r4, r6)
            int r9 = (r0 > r1 ? 1 : (r0 == r1 ? 0 : -1))
            if (r9 <= 0) goto L90
            int r1 = (r0 > r10 ? 1 : (r0 == r10 ? 0 : -1))
            if (r1 == 0) goto L43
            r1 = r2
        L3d:
            int r2 = r5 + 1
            r5 = r2
            r3 = r1
            r1 = r0
            goto L14
        L43:
            r1 = r0
            r0 = r2
        L45:
            int r2 = (r1 > r10 ? 1 : (r1 == r10 ? 0 : -1))
            if (r2 == 0) goto L6a
            boolean r2 = r11.isPrimitive()
            if (r2 != 0) goto L6a
            boolean r2 = r11.isInterface()
            if (r2 != 0) goto L6a
            java.lang.Class<java.lang.Object> r2 = java.lang.Object.class
            boolean r2 = r11.equals(r2)
            if (r2 != 0) goto L6a
            java.lang.Class r2 = java.lang.Void.TYPE
            boolean r2 = r11.equals(r2)
            if (r2 != 0) goto L6a
            java.lang.Class r11 = r11.getSuperclass()
            goto La
        L6a:
            if (r0 != 0) goto L8f
            r1 = 6
            java.lang.StringBuilder r2 = new java.lang.StringBuilder
            java.lang.String r3 = "! getFieldID(\""
            r2.<init>(r3)
            java.lang.StringBuilder r2 = r2.append(r12)
            java.lang.String r3 = "\", \""
            java.lang.StringBuilder r2 = r2.append(r3)
            java.lang.StringBuilder r2 = r2.append(r13)
            java.lang.String r3 = "\") FAILED!"
            java.lang.StringBuilder r2 = r2.append(r3)
            java.lang.String r2 = r2.toString()
            com.unity3d.player.m.Log(r1, r2)
        L8f:
            return r0
        L90:
            r0 = r1
            r1 = r3
            goto L3d
        L93:
            r0 = r3
            goto L45
        */
        throw new UnsupportedOperationException("Method not decompiled: com.unity3d.player.ReflectionHelper.getFieldID(java.lang.Class, java.lang.String, java.lang.String, boolean):java.lang.reflect.Field");
    }

    /* JADX WARN: Code restructure failed: missing block: B:29:0x0071, code lost:
        com.unity3d.player.m.Log(6, "! getMethodID(\"" + r12 + "\", \"" + r13 + "\") FAILED!");
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    protected static java.lang.reflect.Method getMethodID(java.lang.Class r11, java.lang.String r12, java.lang.String r13, boolean r14) {
        /*
            r9 = 1065353216(0x3f800000, float:1.0)
            java.lang.Class[] r5 = a(r13)
            r1 = 0
            r0 = 0
            r10 = r0
            r0 = r1
            r1 = r10
        Lb:
            if (r11 == 0) goto L6f
            java.lang.reflect.Method[] r6 = r11.getDeclaredMethods()
            int r7 = r6.length
            r2 = 0
            r4 = r2
            r3 = r0
        L15:
            if (r4 >= r7) goto L98
            r2 = r6[r4]
            int r0 = r2.getModifiers()
            boolean r0 = java.lang.reflect.Modifier.isStatic(r0)
            if (r14 != r0) goto L95
            java.lang.String r0 = r2.getName()
            int r0 = r0.compareTo(r12)
            if (r0 != 0) goto L95
            java.lang.Class r0 = r2.getReturnType()
            java.lang.Class[] r8 = r2.getParameterTypes()
            float r0 = a(r0, r8, r5)
            int r8 = (r0 > r1 ? 1 : (r0 == r1 ? 0 : -1))
            if (r8 <= 0) goto L95
            int r1 = (r0 > r9 ? 1 : (r0 == r9 ? 0 : -1))
            if (r1 == 0) goto L48
            r1 = r2
        L42:
            int r2 = r4 + 1
            r4 = r2
            r3 = r1
            r1 = r0
            goto L15
        L48:
            r1 = r0
            r0 = r2
        L4a:
            int r2 = (r1 > r9 ? 1 : (r1 == r9 ? 0 : -1))
            if (r2 == 0) goto L6f
            boolean r2 = r11.isPrimitive()
            if (r2 != 0) goto L6f
            boolean r2 = r11.isInterface()
            if (r2 != 0) goto L6f
            java.lang.Class<java.lang.Object> r2 = java.lang.Object.class
            boolean r2 = r11.equals(r2)
            if (r2 != 0) goto L6f
            java.lang.Class r2 = java.lang.Void.TYPE
            boolean r2 = r11.equals(r2)
            if (r2 != 0) goto L6f
            java.lang.Class r11 = r11.getSuperclass()
            goto Lb
        L6f:
            if (r0 != 0) goto L94
            r1 = 6
            java.lang.StringBuilder r2 = new java.lang.StringBuilder
            java.lang.String r3 = "! getMethodID(\""
            r2.<init>(r3)
            java.lang.StringBuilder r2 = r2.append(r12)
            java.lang.String r3 = "\", \""
            java.lang.StringBuilder r2 = r2.append(r3)
            java.lang.StringBuilder r2 = r2.append(r13)
            java.lang.String r3 = "\") FAILED!"
            java.lang.StringBuilder r2 = r2.append(r3)
            java.lang.String r2 = r2.toString()
            com.unity3d.player.m.Log(r1, r2)
        L94:
            return r0
        L95:
            r0 = r1
            r1 = r3
            goto L42
        L98:
            r0 = r3
            goto L4a
        */
        throw new UnsupportedOperationException("Method not decompiled: com.unity3d.player.ReflectionHelper.getMethodID(java.lang.Class, java.lang.String, java.lang.String, boolean):java.lang.reflect.Method");
    }
}
