Fast Orange v3.5.3版本的 MD5 值为:33b91aba50c566533dfd683a85f79158

以下内容为反编译后的 ConfigBuilderKt.java 源代码,内容仅作参考


package com.github.shadowsocks.fmt;

import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.google.shortcuts.utils.ShortcutUtils;
import com.free.vpn.proxy.hotspot.an1;
import com.free.vpn.proxy.hotspot.br0;
import com.free.vpn.proxy.hotspot.br1;
import com.free.vpn.proxy.hotspot.da;
import com.free.vpn.proxy.hotspot.gk3;
import com.free.vpn.proxy.hotspot.jf2;
import com.free.vpn.proxy.hotspot.m53;
import com.free.vpn.proxy.hotspot.ne2;
import com.free.vpn.proxy.hotspot.pl0;
import com.free.vpn.proxy.hotspot.q00;
import com.free.vpn.proxy.hotspot.t00;
import com.free.vpn.proxy.hotspot.uq1;
import com.free.vpn.proxy.hotspot.x74;
import com.free.vpn.proxy.hotspot.yq0;
import com.free.vpn.proxy.hotspot.zm2;
import com.free.vpn.proxy.hotspot.zq0;
import com.free.vpn.proxy.hotspot.zs4;
import com.github.shadowsocks.Core;
import com.github.shadowsocks.Key;
import com.github.shadowsocks.database.DataStore;
import com.github.shadowsocks.database.ProxyEntity;
import com.github.shadowsocks.database.RuleEntity;
import com.github.shadowsocks.database.ShadowsocksDatabase;
import com.github.shadowsocks.fmt.Alerts;
import com.github.shadowsocks.fmt.V2rayBuildResult;
import com.github.shadowsocks.fmt.gson.GsonsKt;
import com.github.shadowsocks.fmt.http.HttpBean;
import com.github.shadowsocks.fmt.internal.BalancerBean;
import com.github.shadowsocks.fmt.internal.ChainBean;
import com.github.shadowsocks.fmt.internal.ConfigBean;
import com.github.shadowsocks.fmt.shadowsocks.ShadowsocksBean;
import com.github.shadowsocks.fmt.shadowsocksr.ShadowsocksRBean;
import com.github.shadowsocks.fmt.socks.SOCKSBean;
import com.github.shadowsocks.fmt.ssh.SSHBean;
import com.github.shadowsocks.fmt.trojan.TrojanBean;
import com.github.shadowsocks.fmt.v2ray.StandardV2RayBean;
import com.github.shadowsocks.fmt.v2ray.V2RayConfig;
import com.github.shadowsocks.fmt.v2ray.VLESSBean;
import com.github.shadowsocks.fmt.v2ray.VMessBean;
import com.github.shadowsocks.fmt.wireguard.WireGuardBean;
import com.github.shadowsocks.ktx.NetsKt;
import com.github.shadowsocks.ktx.UtilsKt;
import com.github.shadowsocks.plugin.PluginConfiguration;
import com.github.shadowsocks.plugin.PluginManager;
import com.github.shadowsocks.plugin.PluginOptions;
import com.github.shadowsocks.utils.PackageCache;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import fr.bmartel.protocol.http.constants.HttpHeader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import kotlin.Lazy;
import kotlin.LazyKt;
import kotlin.Metadata;
import kotlin.Pair;
import kotlin.TuplesKt;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.Ref$BooleanRef;
import kotlin.jvm.internal.Ref$ObjectRef;
import libcore.Libcore;
import libcore.URL;

@Metadata(d1 = {"\u0000$\n\u0000\n\u0002\u0010\u000e\n\u0002\b\f\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0000\u001a\u0016\u0010\r\u001a\u00020\u000e2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0011\u001a\u00020\u0012\u001a\u0018\u0010\u0013\u001a\u00020\u000e2\u0006\u0010\u000f\u001a\u00020\u00102\b\b\u0002\u0010\u0014\u001a\u00020\u0015\"\u000e\u0010\u0000\u001a\u00020\u0001X\u0086T¢\u0006\u0002\n\u0000\"\u000e\u0010\u0002\u001a\u00020\u0001X\u0086T¢\u0006\u0002\n\u0000\"\u000e\u0010\u0003\u001a\u00020\u0001X\u0086T¢\u0006\u0002\n\u0000\"\u000e\u0010\u0004\u001a\u00020\u0001X\u0086T¢\u0006\u0002\n\u0000\"\u000e\u0010\u0005\u001a\u00020\u0001X\u0086T¢\u0006\u0002\n\u0000\"\u000e\u0010\u0006\u001a\u00020\u0001X\u0086T¢\u0006\u0002\n\u0000\"\u000e\u0010\u0007\u001a\u00020\u0001X\u0086T¢\u0006\u0002\n\u0000\"\u000e\u0010\b\u001a\u00020\u0001X\u0086T¢\u0006\u0002\n\u0000\"\u000e\u0010\t\u001a\u00020\u0001X\u0086T¢\u0006\u0002\n\u0000\"\u000e\u0010\n\u001a\u00020\u0001X\u0086T¢\u0006\u0002\n\u0000\"\u000e\u0010\u000b\u001a\u00020\u0001X\u0086T¢\u0006\u0002\n\u0000\"\u000e\u0010\f\u001a\u00020\u0001X\u0086T¢\u0006\u0002\n\u0000¨\u0006\u0016"}, d2 = {"IP6_LOCALHOST", "", "LOCALHOST", "TAG_AGENT", "TAG_API_IN", "TAG_BLOCK", "TAG_BYPASS", "TAG_DIRECT", "TAG_DNS_IN", "TAG_DNS_OUT", "TAG_HTTP", "TAG_SOCKS", "TAG_TRANS", "buildCustomConfig", "Lcom/github/shadowsocks/fmt/V2rayBuildResult;", "proxy", "Lcom/github/shadowsocks/database/ProxyEntity;", "port", "", "buildV2RayConfig", "forTest", "", "shadowsocks_release"}, k = 2, mv = {1, 8, 0}, xi = ConstraintLayout.LayoutParams.Table.LAYOUT_CONSTRAINT_VERTICAL_CHAINSTYLE)
public final class ConfigBuilderKt {
    public static final String IP6_LOCALHOST = "::1";
    public static final String LOCALHOST = "127.0.0.1";
    public static final String TAG_AGENT = "proxy";
    public static final String TAG_API_IN = "api-in";
    public static final String TAG_BLOCK = "block";
    public static final String TAG_BYPASS = "bypass";
    public static final String TAG_DIRECT = "direct";
    public static final String TAG_DNS_IN = "dns-in";
    public static final String TAG_DNS_OUT = "dns-out";
    public static final String TAG_HTTP = "http";
    public static final String TAG_SOCKS = "socks";
    public static final String TAG_TRANS = "trans";

    public static final V2rayBuildResult buildCustomConfig(ProxyEntity proxyEntity, int i) {
        ArrayList arrayList;
        ArrayList arrayList2;
        Object obj;
        boolean z;
        int i2;
        ArrayList arrayList3;
        V2RayConfig.OutboundObject outboundObject;
        boolean z2;
        boolean z3;
        String str;
        Iterator it;
        Iterator it2;
        Object obj2;
        String str2;
        boolean z4;
        uq1 a;
        boolean z5;
        uq1 a2;
        V2RayConfig.DnsObject.StringOrServerObject stringOrServerObject;
        zs4.o(proxyEntity, "proxy");
        boolean trafficSniffing = DataStore.INSTANCE.getTrafficSniffing();
        ConfigBean configBean = proxyEntity.getConfigBean();
        zs4.l(configBean);
        br1 br1Var = new br1(configBean.getContent());
        uq1 a3 = pl0.a(br1Var, "inbounds");
        boolean z6 = false;
        if (a3 != null) {
            ArrayList arrayList4 = new ArrayList();
            Iterator it3 = a3.iterator();
            while (it3.hasNext()) {
                Object next = it3.next();
                if (next instanceof br1) {
                    arrayList4.add(next);
                }
            }
            ArrayList arrayList5 = new ArrayList(q00.A0(arrayList4, 10));
            Iterator it4 = arrayList4.iterator();
            while (it4.hasNext()) {
                br1 br1Var2 = (br1) it4.next();
                Gson gson = GsonsKt.getGson();
                br1Var2.getClass();
                arrayList5.add((V2RayConfig.InboundObject) gson.fromJson(pl0.c(br1Var2, 0), V2RayConfig.InboundObject.class));
            }
            arrayList = t00.I1(arrayList5);
        } else {
            arrayList = new ArrayList();
        }
        br1 b = pl0.b(br1Var, "dns");
        if (b != null && (a2 = pl0.a(b, "servers")) != null) {
            ArrayList arrayList6 = new ArrayList(q00.A0(a2, 10));
            Iterator it5 = a2.iterator();
            while (it5.hasNext()) {
                ?? next2 = it5.next();
                if (next2 instanceof String) {
                    stringOrServerObject = new V2RayConfig.DnsObject.StringOrServerObject();
                    stringOrServerObject.valueX = next2;
                } else {
                    stringOrServerObject = new V2RayConfig.DnsObject.StringOrServerObject();
                    stringOrServerObject.valueY = GsonsKt.getGson().fromJson(next2.toString(), V2RayConfig.DnsObject.ServerObject.class);
                }
                arrayList6.add(stringOrServerObject);
            }
        }
        DataStore.INSTANCE.getIpv6Mode();
        Iterator it6 = arrayList.iterator();
        while (true) {
            arrayList2 = null;
            if (it6.hasNext()) {
                obj = it6.next();
                if (zs4.h(((V2RayConfig.InboundObject) obj).tag, TAG_SOCKS)) {
                    break;
                }
            } else {
                obj = null;
                break;
            }
        }
        V2RayConfig.InboundObject inboundObject = (V2RayConfig.InboundObject) obj;
        if (inboundObject != null) {
            if (!zs4.h(inboundObject.protocol, TAG_SOCKS)) {
                throw new IllegalStateException(("Inbound " + inboundObject.tag + " with type " + inboundObject.protocol + ", excepted socks.").toString());
            }
        } else {
            inboundObject = null;
        }
        boolean z7 = true;
        if (inboundObject == null) {
            ArrayList arrayList7 = new ArrayList();
            for (Object obj3 : arrayList) {
                if (zs4.h(((V2RayConfig.InboundObject) obj3).protocol, TAG_SOCKS)) {
                    arrayList7.add(obj3);
                }
            }
            if (arrayList7.size() == 1) {
                inboundObject = (V2RayConfig.InboundObject) arrayList7.get(0);
            }
        }
        if (inboundObject != null) {
            inboundObject.listen = "127.0.0.1";
            inboundObject.port = Integer.valueOf(i);
        } else {
            V2RayConfig.InboundObject inboundObject2 = new V2RayConfig.InboundObject();
            inboundObject2.tag = TAG_SOCKS;
            inboundObject2.listen = "127.0.0.1";
            inboundObject2.port = Integer.valueOf(i);
            inboundObject2.protocol = TAG_SOCKS;
            V2RayConfig.SocksInboundConfigurationObject socksInboundConfigurationObject = new V2RayConfig.SocksInboundConfigurationObject();
            socksInboundConfigurationObject.auth = "noauth";
            Boolean bool = Boolean.TRUE;
            socksInboundConfigurationObject.udp = bool;
            Unit unit = Unit.INSTANCE;
            inboundObject2.settings = new V2RayConfig.LazyInboundConfigurationObject(inboundObject2, socksInboundConfigurationObject);
            if (trafficSniffing) {
                V2RayConfig.InboundObject.SniffingObject sniffingObject = new V2RayConfig.InboundObject.SniffingObject();
                sniffingObject.enabled = bool;
                sniffingObject.destOverride = zm2.d0("http", StandardV2RayBean.SECURITY_TLS, StandardV2RayBean.TYPE_QUIC);
                sniffingObject.metadataOnly = Boolean.FALSE;
                inboundObject2.sniffing = sniffingObject;
            }
            arrayList.add(inboundObject2);
        }
        if (br1Var.containsKey("browserForwarder")) {
            Gson gson2 = GsonsKt.getGson();
            V2RayConfig.BrowserForwarderObject browserForwarderObject = new V2RayConfig.BrowserForwarderObject();
            browserForwarderObject.listenAddr = "127.0.0.1";
            Integer valueOf = Integer.valueOf(NetsKt.mkPort());
            browserForwarderObject.listenPort = valueOf;
            zs4.n(valueOf, "listenPort");
            int intValue = valueOf.intValue();
            Unit unit2 = Unit.INSTANCE;
            br1Var.m(new br1(gson2.toJson(browserForwarderObject)), "browserForwarder");
            z = true;
            i2 = intValue;
        } else {
            z = false;
            i2 = 0;
        }
        try {
            a = pl0.a(br1Var, "outbounds");
        } catch (JsonSyntaxException unused) {
        }
        if (a != null) {
            ArrayList arrayList8 = new ArrayList();
            Iterator it7 = a.iterator();
            while (it7.hasNext()) {
                Object next3 = it7.next();
                if (next3 instanceof br1) {
                    arrayList8.add(next3);
                }
            }
            ArrayList arrayList9 = new ArrayList(q00.A0(arrayList8, 10));
            Iterator it8 = arrayList8.iterator();
            while (it8.hasNext()) {
                br1 br1Var3 = (br1) it8.next();
                Gson gson3 = GsonsKt.getGson();
                br1Var3.getClass();
                String c = pl0.c(br1Var3, 0);
                zs4.n(c, "it");
                if (!x74.a1(c)) {
                    z5 = true;
                } else {
                    z5 = false;
                }
                if (!Boolean.valueOf(z5).booleanValue()) {
                    c = null;
                }
                if (c == null) {
                    c = "{}";
                }
                arrayList9.add((V2RayConfig.OutboundObject) gson3.fromJson(c, V2RayConfig.OutboundObject.class));
            }
            arrayList3 = t00.I1(arrayList9);
            ArrayList arrayList10 = new ArrayList();
            if (arrayList3 == null) {
                outboundObject = (V2RayConfig.OutboundObject) arrayList3.get(0);
            } else {
                outboundObject = null;
            }
            if (outboundObject != null) {
                String str3 = outboundObject.tag;
                if (str3 == null) {
                    outboundObject.tag = "proxy";
                    arrayList10.add("proxy");
                    z2 = true;
                    if (arrayList3 != null) {
                        arrayList2 = new ArrayList();
                        for (Object obj4 : arrayList3) {
                            if (zs4.h(((V2RayConfig.OutboundObject) obj4).protocol, "freedom")) {
                                arrayList2.add(obj4);
                            }
                        }
                    }
                    if (arrayList2 == null && !arrayList2.isEmpty()) {
                        z3 = false;
                    } else {
                        z3 = true;
                    }
                    if (!z3) {
                        if (arrayList2.size() != 1) {
                            ArrayList arrayList11 = new ArrayList();
                            for (Object obj5 : arrayList2) {
                                if (((V2RayConfig.OutboundObject) obj5).tag != null) {
                                    z4 = true;
                                } else {
                                    z4 = false;
                                }
                                if (z4) {
                                    arrayList11.add(obj5);
                                }
                            }
                            if (!arrayList11.isEmpty()) {
                                obj2 = arrayList11.get(0);
                                V2RayConfig.OutboundObject outboundObject2 = (V2RayConfig.OutboundObject) obj2;
                                str2 = outboundObject2.tag;
                                if (str2 != null || x74.a1(str2)) {
                                    z6 = true;
                                }
                                if (!z6) {
                                    outboundObject2.tag = "direct";
                                } else {
                                    z7 = z2;
                                }
                                String str4 = outboundObject2.tag;
                                zs4.n(str4, "directOutbound.tag");
                                str = str4;
                                z2 = z7;
                            }
                        }
                        obj2 = arrayList2.get(0);
                        V2RayConfig.OutboundObject outboundObject22 = (V2RayConfig.OutboundObject) obj2;
                        str2 = outboundObject22.tag;
                        if (str2 != null) {
                        }
                        z6 = true;
                        if (!z6) {
                        }
                        String str42 = outboundObject22.tag;
                        zs4.n(str42, "directOutbound.tag");
                        str = str42;
                        z2 = z7;
                    } else {
                        str = "";
                    }
                    it = arrayList.iterator();
                    while (it.hasNext()) {
                        ((V2RayConfig.InboundObject) it.next()).init();
                    }
                    ArrayList arrayList12 = new ArrayList(q00.A0(arrayList, 10));
                    it2 = arrayList.iterator();
                    while (it2.hasNext()) {
                        arrayList12.add(new br1(GsonsKt.getGson().toJson((V2RayConfig.InboundObject) it2.next())));
                    }
                    br1Var.m(new uq1(arrayList12), "inbounds");
                    if (z2) {
                        zs4.l(arrayList3);
                        Iterator it9 = arrayList3.iterator();
                        while (it9.hasNext()) {
                            ((V2RayConfig.OutboundObject) it9.next()).init();
                        }
                        ArrayList arrayList13 = new ArrayList(q00.A0(arrayList3, 10));
                        Iterator it10 = arrayList3.iterator();
                        while (it10.hasNext()) {
                            arrayList13.add(new br1(GsonsKt.getGson().toJson((V2RayConfig.OutboundObject) it10.next())));
                        }
                        br1Var.m(new uq1(arrayList13), "outbounds");
                    }
                    String c2 = pl0.c(br1Var, 4);
                    zs4.n(c2, "config.toStringPretty()");
                    yq0 yq0Var = yq0.a;
                    return new V2rayBuildResult(c2, yq0Var, z, i2, arrayList10, arrayList10, zq0.a, str, "", br0.a, false, yq0Var);
                }
                arrayList10.add(str3);
            }
            z2 = false;
            if (arrayList3 != null) {
            }
            if (arrayList2 == null) {
            }
            z3 = true;
            if (!z3) {
            }
            it = arrayList.iterator();
            while (it.hasNext()) {
            }
            ArrayList arrayList122 = new ArrayList(q00.A0(arrayList, 10));
            it2 = arrayList.iterator();
            while (it2.hasNext()) {
            }
            br1Var.m(new uq1(arrayList122), "inbounds");
            if (z2) {
            }
            String c22 = pl0.c(br1Var, 4);
            zs4.n(c22, "config.toStringPretty()");
            yq0 yq0Var2 = yq0.a;
            return new V2rayBuildResult(c22, yq0Var2, z, i2, arrayList10, arrayList10, zq0.a, str, "", br0.a, false, yq0Var2);
        }
        arrayList3 = null;
        ArrayList arrayList102 = new ArrayList();
        if (arrayList3 == null) {
        }
        if (outboundObject != null) {
        }
        z2 = false;
        if (arrayList3 != null) {
        }
        if (arrayList2 == null) {
        }
        z3 = true;
        if (!z3) {
        }
        it = arrayList.iterator();
        while (it.hasNext()) {
        }
        ArrayList arrayList1222 = new ArrayList(q00.A0(arrayList, 10));
        it2 = arrayList.iterator();
        while (it2.hasNext()) {
        }
        br1Var.m(new uq1(arrayList1222), "inbounds");
        if (z2) {
        }
        String c222 = pl0.c(br1Var, 4);
        zs4.n(c222, "config.toStringPretty()");
        yq0 yq0Var22 = yq0.a;
        return new V2rayBuildResult(c222, yq0Var22, z, i2, arrayList102, arrayList102, zq0.a, str, "", br0.a, false, yq0Var22);
    }

    public static final V2rayBuildResult buildV2RayConfig(ProxyEntity proxyEntity, boolean z) {
        Map map;
        String str;
        String str2;
        int J;
        Iterator it;
        ArrayList arrayList;
        Iterator it2;
        Integer num;
        Map map2;
        ArrayList arrayList2;
        String str3;
        String str4;
        String str5;
        Iterator<ProxyEntity> it3;
        Set<String> set;
        Iterator it4;
        Iterator it5;
        int i;
        V2RayConfig.DNSOutboundConfigurationObject dNSOutboundConfigurationObject;
        String str6;
        Uri parse;
        String scheme;
        HashSet hashSet;
        HashSet hashSet2;
        Iterator it6;
        Iterator it7;
        boolean z2;
        Object obj;
        V2RayConfig.MultiObservatoryObject.MultiObservatoryItem multiObservatoryItem;
        String str7;
        V2RayConfig.ObservatoryObject observatoryObject;
        Iterator it8;
        Object obj2;
        Object obj3;
        String str8;
        String scheme2;
        String str9;
        Object obj4;
        ArrayList arrayList3;
        Integer num2;
        boolean z3;
        Iterator it9;
        String str10;
        boolean z4;
        int i2;
        LinkedHashMap linkedHashMap;
        String str11;
        String str12;
        String host;
        int i3;
        String str13;
        String str14;
        zs4.o(proxyEntity, "proxy");
        ArrayList arrayList4 = new ArrayList();
        ArrayList arrayList5 = new ArrayList();
        HashMap hashMap = new HashMap();
        ArrayList arrayList6 = new ArrayList();
        List<ProxyEntity> buildV2RayConfig$resolveChain = buildV2RayConfig$resolveChain(proxyEntity);
        Integer num3 = 0;
        List enabledRules$default = z ? yq0.a : RuleEntity.Dao.DefaultImpls.enabledRules$default(ShadowsocksDatabase.INSTANCE.getRulesDao(), false, 1, null);
        Map map3 = zq0.a;
        if (z) {
            map = map3;
        } else {
            ProxyEntity.Dao proxyDao = ShadowsocksDatabase.INSTANCE.getProxyDao();
            ArrayList arrayList7 = new ArrayList();
            Iterator it10 = enabledRules$default.iterator();
            while (it10.hasNext()) {
                Long valueOf = Long.valueOf(((RuleEntity) it10.next()).getOutbound());
                long longValue = valueOf.longValue();
                if (!(longValue > 0 && longValue != proxyEntity.getId())) {
                    valueOf = null;
                }
                if (valueOf != null) {
                    arrayList7.add(valueOf);
                }
            }
            List<ProxyEntity> entities = proxyDao.getEntities(t00.H1(t00.F1(arrayList7)));
            int J2 = an1.J(q00.A0(entities, 10));
            Map linkedHashMap2 = new LinkedHashMap(J2 >= 16 ? J2 : 16);
            for (ProxyEntity proxyEntity2 : entities) {
                Pair pair = TuplesKt.to(TuplesKt.to(Long.valueOf(proxyEntity2.getId()), TuplesKt.to(Boolean.valueOf(proxyEntity2.getType() == 14), LazyKt.lazy(new ConfigBuilderKt$buildV2RayConfig$extraProxies$2$1(proxyEntity2)))), buildV2RayConfig$resolveChain(proxyEntity2));
                linkedHashMap2.put(pair.getFirst(), pair.getSecond());
            }
            map = linkedHashMap2;
        }
        DataStore dataStore = DataStore.INSTANCE;
        boolean allowAccess = dataStore.getAllowAccess();
        String str15 = "127.0.0.1";
        String str16 = (z || !allowAccess) ? "127.0.0.1" : "0.0.0.0";
        List p1 = x74.p1(dataStore.getRemoteDns(), new String[]{"\n"});
        ArrayList arrayList8 = new ArrayList();
        Iterator it11 = p1.iterator();
        while (it11.hasNext()) {
            String obj5 = x74.D1((String) it11.next()).toString();
            if (!((x74.a1(obj5) ^ true) && !x74.r1(obj5, "#", false))) {
                obj5 = null;
            }
            if (obj5 != null) {
                arrayList8.add(obj5);
            }
        }
        List p12 = x74.p1(DataStore.INSTANCE.getDirectDns(), new String[]{"\n"});
        ArrayList arrayList9 = new ArrayList();
        Iterator it12 = p12.iterator();
        while (it12.hasNext()) {
            String obj6 = x74.D1((String) it12.next()).toString();
            if (!((x74.a1(obj6) ^ true) && !x74.r1(obj6, "#", false))) {
                obj6 = null;
            }
            if (obj6 != null) {
                arrayList9.add(obj6);
            }
        }
        DataStore dataStore2 = DataStore.INSTANCE;
        String str17 = "localhost";
        Collection collection = arrayList9;
        if (dataStore2.getUseLocalDnsAsDirectDns()) {
            collection = zm2.c0("localhost");
        }
        Collection collection2 = collection;
        boolean enableDnsRouting = dataStore2.getEnableDnsRouting();
        boolean trafficSniffing = dataStore2.getTrafficSniffing();
        ArrayList arrayList10 = new ArrayList();
        Ref$BooleanRef ref$BooleanRef = new Ref$BooleanRef();
        boolean z5 = !z && dataStore2.getRequireHttp();
        boolean requireTransproxy = z ? false : dataStore2.getRequireTransproxy();
        int ipv6Mode = z ? 1 : dataStore2.getIpv6Mode();
        boolean resolveDestination = dataStore2.getResolveDestination();
        boolean destinationOverride = dataStore2.getDestinationOverride();
        boolean z6 = !z && dataStore2.getProfileTrafficStatistics();
        dataStore2.getTunImplementation();
        if (!destinationOverride || resolveDestination) {
            if (ipv6Mode == 0) {
                str2 = "UseIPv4";
            } else if (ipv6Mode == 2) {
                str = "PreferIPv6";
            } else if (ipv6Mode == 3) {
                str2 = "UseIPv6";
            } else {
                str = "PreferIPv4";
            }
            ArrayList arrayList11 = new ArrayList();
            V2RayConfig v2RayConfig = new V2RayConfig();
            V2RayConfig.DnsObject dnsObject = new V2RayConfig.DnsObject();
            List p13 = x74.p1(dataStore2.getHosts(), new String[]{"\n"});
            ArrayList arrayList12 = new ArrayList();
            for (Object obj7 : p13) {
                Collection collection3 = collection2;
                if (!x74.a1((String) obj7)) {
                    arrayList12.add(obj7);
                }
                collection2 = collection3;
            }
            Collection collection4 = collection2;
            J = an1.J(q00.A0(arrayList12, 10));
            if (J < 16) {
                J = 16;
            }
            LinkedHashMap linkedHashMap3 = new LinkedHashMap(J);
            it = arrayList12.iterator();
            while (it.hasNext()) {
                String str18 = (String) it.next();
                Iterator it13 = it;
                Pair pair2 = TuplesKt.to(x74.A1(str18, " "), x74.v1(str18, " ", str18));
                linkedHashMap3.put(pair2.getFirst(), pair2.getSecond());
                it = it13;
                str15 = str15;
            }
            String str19 = str15;
            dnsObject.hosts = ne2.l0(linkedHashMap3);
            ArrayList arrayList13 = new ArrayList();
            dnsObject.servers = arrayList13;
            arrayList = new ArrayList(q00.A0(arrayList8, 10));
            it2 = arrayList8.iterator();
            while (true) {
                num = num3;
                map2 = map3;
                arrayList2 = arrayList8;
                if (it2.hasNext()) {
                    break;
                }
                String str20 = (String) it2.next();
                Iterator it14 = it2;
                V2RayConfig.DnsObject.StringOrServerObject stringOrServerObject = new V2RayConfig.DnsObject.StringOrServerObject();
                ArrayList arrayList14 = arrayList6;
                ?? serverObject = new V2RayConfig.DnsObject.ServerObject();
                if (zs4.h(str20, str17)) {
                    str14 = str17;
                } else {
                    URL parseURL = Libcore.parseURL(str20);
                    str14 = str17;
                    String scheme3 = parseURL.getScheme();
                    zs4.n(scheme3, "lnk.scheme");
                    if (x74.a1(scheme3)) {
                        parseURL.setScheme("udp");
                    }
                    str20 = parseURL.getString();
                    zs4.n(str20, "lnk.string");
                }
                serverObject.address = str20;
                serverObject.concurrency = true;
                stringOrServerObject.valueY = serverObject;
                arrayList.add(stringOrServerObject);
                num3 = num;
                map3 = map2;
                arrayList8 = arrayList2;
                it2 = it14;
                arrayList6 = arrayList14;
                str17 = str14;
            }
            ArrayList arrayList15 = arrayList6;
            String str21 = str17;
            arrayList13.addAll(arrayList);
            Boolean bool = Boolean.TRUE;
            dnsObject.disableFallbackIfMatch = bool;
            if (ipv6Mode == 0) {
                str13 = ipv6Mode == 3 ? "UseIPv6" : "UseIPv4";
                Unit unit = Unit.INSTANCE;
                v2RayConfig.dns = dnsObject;
                V2RayConfig.LogObject logObject = new V2RayConfig.LogObject();
                DataStore dataStore3 = DataStore.INSTANCE;
                logObject.loglevel = dataStore3.getEnableLog() ? "debug" : "error";
                v2RayConfig.log = logObject;
                V2RayConfig.PolicyObject policyObject = new V2RayConfig.PolicyObject();
                V2RayConfig.PolicyObject.LevelPolicyObject levelPolicyObject = new V2RayConfig.PolicyObject.LevelPolicyObject();
                levelPolicyObject.connIdle = 30;
                policyObject.levels = an1.K(TuplesKt.to("1", levelPolicyObject));
                if (z6) {
                    V2RayConfig.PolicyObject.SystemPolicyObject systemPolicyObject = new V2RayConfig.PolicyObject.SystemPolicyObject();
                    systemPolicyObject.statsOutboundDownlink = bool;
                    systemPolicyObject.statsOutboundUplink = bool;
                    policyObject.system = systemPolicyObject;
                }
                v2RayConfig.policy = policyObject;
                ArrayList arrayList16 = new ArrayList();
                v2RayConfig.inbounds = arrayList16;
                if (z) {
                    str3 = "lnk.scheme";
                } else {
                    V2RayConfig.InboundObject inboundObject = new V2RayConfig.InboundObject();
                    inboundObject.tag = TAG_SOCKS;
                    inboundObject.listen = str16;
                    str3 = "lnk.scheme";
                    inboundObject.port = Integer.valueOf(dataStore3.getSocksPort());
                    inboundObject.protocol = TAG_SOCKS;
                    V2RayConfig.SocksInboundConfigurationObject socksInboundConfigurationObject = new V2RayConfig.SocksInboundConfigurationObject();
                    socksInboundConfigurationObject.auth = "noauth";
                    socksInboundConfigurationObject.udp = bool;
                    inboundObject.settings = new V2RayConfig.LazyInboundConfigurationObject(inboundObject, socksInboundConfigurationObject);
                    if (trafficSniffing) {
                        V2RayConfig.InboundObject.SniffingObject sniffingObject = new V2RayConfig.InboundObject.SniffingObject();
                        sniffingObject.enabled = bool;
                        sniffingObject.destOverride = zm2.d0("http", StandardV2RayBean.SECURITY_TLS, StandardV2RayBean.TYPE_QUIC);
                        sniffingObject.routeOnly = Boolean.valueOf(!destinationOverride);
                        inboundObject.sniffing = sniffingObject;
                    }
                    arrayList16.add(inboundObject);
                }
                if (z5) {
                    List<V2RayConfig.InboundObject> list = v2RayConfig.inbounds;
                    V2RayConfig.InboundObject inboundObject2 = new V2RayConfig.InboundObject();
                    inboundObject2.tag = "http";
                    inboundObject2.listen = str16;
                    inboundObject2.port = Integer.valueOf(dataStore3.getHttpPort());
                    inboundObject2.protocol = "http";
                    V2RayConfig.HTTPInboundConfigurationObject hTTPInboundConfigurationObject = new V2RayConfig.HTTPInboundConfigurationObject();
                    hTTPInboundConfigurationObject.allowTransparent = bool;
                    inboundObject2.settings = new V2RayConfig.LazyInboundConfigurationObject(inboundObject2, hTTPInboundConfigurationObject);
                    if (trafficSniffing) {
                        V2RayConfig.InboundObject.SniffingObject sniffingObject2 = new V2RayConfig.InboundObject.SniffingObject();
                        sniffingObject2.enabled = bool;
                        sniffingObject2.destOverride = zm2.d0("http", StandardV2RayBean.SECURITY_TLS, StandardV2RayBean.TYPE_QUIC);
                        sniffingObject2.routeOnly = Boolean.valueOf(!destinationOverride);
                        inboundObject2.sniffing = sniffingObject2;
                    }
                    list.add(inboundObject2);
                }
                if (requireTransproxy) {
                    List<V2RayConfig.InboundObject> list2 = v2RayConfig.inbounds;
                    V2RayConfig.InboundObject inboundObject3 = new V2RayConfig.InboundObject();
                    str5 = "lnk.string";
                    inboundObject3.tag = TAG_TRANS;
                    inboundObject3.listen = str16;
                    inboundObject3.port = Integer.valueOf(dataStore3.getTransproxyPort());
                    inboundObject3.protocol = "dokodemo-door";
                    V2RayConfig.DokodemoDoorInboundConfigurationObject dokodemoDoorInboundConfigurationObject = new V2RayConfig.DokodemoDoorInboundConfigurationObject();
                    dokodemoDoorInboundConfigurationObject.network = "tcp,udp";
                    dokodemoDoorInboundConfigurationObject.followRedirect = bool;
                    str4 = "dokodemo-door";
                    inboundObject3.settings = new V2RayConfig.LazyInboundConfigurationObject(inboundObject3, dokodemoDoorInboundConfigurationObject);
                    if (trafficSniffing) {
                        V2RayConfig.InboundObject.SniffingObject sniffingObject3 = new V2RayConfig.InboundObject.SniffingObject();
                        sniffingObject3.enabled = bool;
                        sniffingObject3.destOverride = zm2.d0("http", StandardV2RayBean.SECURITY_TLS, StandardV2RayBean.TYPE_QUIC);
                        i3 = 1;
                        sniffingObject3.routeOnly = Boolean.valueOf(!destinationOverride);
                        inboundObject3.sniffing = sniffingObject3;
                    } else {
                        i3 = 1;
                    }
                    if (dataStore3.getTransproxyMode() == i3) {
                        V2RayConfig.StreamSettingsObject streamSettingsObject = new V2RayConfig.StreamSettingsObject();
                        V2RayConfig.StreamSettingsObject.SockoptObject sockoptObject = new V2RayConfig.StreamSettingsObject.SockoptObject();
                        sockoptObject.tproxy = "tproxy";
                        streamSettingsObject.sockopt = sockoptObject;
                        inboundObject3.streamSettings = streamSettingsObject;
                    }
                    list2.add(inboundObject3);
                } else {
                    str4 = "dokodemo-door";
                    str5 = "lnk.string";
                }
                v2RayConfig.outbounds = new ArrayList();
                V2RayConfig.RoutingObject routingObject = new V2RayConfig.RoutingObject();
                routingObject.domainStrategy = dataStore3.getDomainStrategy();
                routingObject.rules = new ArrayList();
                HashMap hashMap2 = new HashMap();
                it3 = buildV2RayConfig$resolveChain.iterator();
                while (it3.hasNext()) {
                    AbstractBean requireBean = it3.next().requireBean();
                    if (requireBean instanceof StandardV2RayBean) {
                        StandardV2RayBean standardV2RayBean = (StandardV2RayBean) requireBean;
                        Iterator<ProxyEntity> it15 = it3;
                        if (zs4.h(standardV2RayBean.getType(), StandardV2RayBean.TYPE_WS) && standardV2RayBean.getWsUseBrowserForwarder()) {
                            V2RayConfig.RoutingObject.RuleObject ruleObject = new V2RayConfig.RoutingObject.RuleObject();
                            ruleObject.type = "field";
                            ruleObject.outboundTag = "direct";
                            if (NetsKt.isIpAddress(standardV2RayBean.getHost())) {
                                str12 = standardV2RayBean.getHost();
                            } else {
                                if (!x74.a1(standardV2RayBean.getHost())) {
                                    str11 = standardV2RayBean.getHost();
                                } else {
                                    String str22 = requireBean.serverAddress;
                                    zs4.n(str22, "bean.serverAddress");
                                    if (NetsKt.isIpAddress(str22)) {
                                        str12 = requireBean.serverAddress;
                                    } else {
                                        str11 = requireBean.serverAddress;
                                    }
                                }
                                ruleObject.domain = zm2.c0(str11);
                                host = standardV2RayBean.getHost();
                                if (!(!(host != null || x74.a1(host)))) {
                                    host = null;
                                }
                                if (host == null) {
                                    host = requireBean.serverAddress;
                                }
                                zs4.n(host, "bean.host.takeIf { !it.i…) } ?: bean.serverAddress");
                                hashMap2.put(host, ruleObject);
                            }
                            ruleObject.ip = zm2.c0(str12);
                            host = standardV2RayBean.getHost();
                            if (!(!(host != null || x74.a1(host)))) {
                            }
                            if (host == null) {
                            }
                            zs4.n(host, "bean.host.takeIf { !it.i…) } ?: bean.serverAddress");
                            hashMap2.put(host, ruleObject);
                        }
                        it3 = it15;
                    }
                }
                List<V2RayConfig.RoutingObject.RuleObject> list3 = routingObject.rules;
                Collection<? extends V2RayConfig.RoutingObject.RuleObject> values = hashMap2.values();
                zs4.n(values, "wsRules.values");
                list3.addAll(values);
                if (!z) {
                    DataStore dataStore4 = DataStore.INSTANCE;
                    if (dataStore4.getBypassLan() && (z5 || dataStore4.getBypassLanInCoreOnly())) {
                        List<V2RayConfig.RoutingObject.RuleObject> list4 = routingObject.rules;
                        V2RayConfig.RoutingObject.RuleObject ruleObject2 = new V2RayConfig.RoutingObject.RuleObject();
                        ruleObject2.type = "field";
                        ruleObject2.outboundTag = TAG_BYPASS;
                        ruleObject2.ip = zm2.c0("geoip:private");
                        list4.add(ruleObject2);
                    }
                }
                Unit unit2 = Unit.INSTANCE;
                v2RayConfig.routing = routingObject;
                Ref$ObjectRef ref$ObjectRef = new Ref$ObjectRef();
                Ref$ObjectRef ref$ObjectRef2 = new Ref$ObjectRef();
                boolean z7 = proxyEntity.getBalancerBean() != null;
                V2RayConfig v2RayConfig2 = v2RayConfig;
                ConfigBuilderKt$buildV2RayConfig$1$tagProxy$1 configBuilderKt$buildV2RayConfig$1$tagProxy$1 = new ConfigBuilderKt$buildV2RayConfig$1$tagProxy$1(proxyEntity);
                set = null;
                ArrayList arrayList17 = arrayList11;
                String str23 = "field";
                String str24 = str4;
                Object obj8 = StandardV2RayBean.SECURITY_TLS;
                String str25 = str21;
                String str26 = str3;
                String str27 = str16;
                Object obj9 = StandardV2RayBean.TYPE_QUIC;
                String str28 = str5;
                Object obj10 = "udp";
                Integer num4 = num;
                String buildV2RayConfig$lambda$152$buildChain = buildV2RayConfig$lambda$152$buildChain(arrayList10, v2RayConfig2, ref$ObjectRef2, ref$ObjectRef, arrayList15, hashMap, arrayList4, arrayList5, str2, proxyEntity, ref$BooleanRef, z, z5, requireTransproxy, "proxy", buildV2RayConfig$resolveChain, z7, configBuilderKt$buildV2RayConfig$1$tagProxy$1);
                LinkedHashMap linkedHashMap4 = new LinkedHashMap();
                LinkedHashMap linkedHashMap5 = new LinkedHashMap();
                it4 = map.entrySet().iterator();
                while (it4.hasNext()) {
                    Map.Entry entry = (Map.Entry) it4.next();
                    Pair pair3 = (Pair) entry.getKey();
                    List list5 = (List) entry.getValue();
                    long longValue2 = ((Number) pair3.component1()).longValue();
                    Pair pair4 = (Pair) pair3.component2();
                    boolean booleanValue = ((Boolean) pair4.component1()).booleanValue();
                    Iterator it16 = it4;
                    LinkedHashMap linkedHashMap6 = linkedHashMap5;
                    LinkedHashMap linkedHashMap7 = linkedHashMap4;
                    linkedHashMap6.put(Long.valueOf(longValue2), buildV2RayConfig$lambda$152$buildChain(arrayList10, v2RayConfig2, ref$ObjectRef2, ref$ObjectRef, arrayList15, hashMap, arrayList4, arrayList5, str2, proxyEntity, ref$BooleanRef, z, z5, requireTransproxy, pl0.o("proxy-", longValue2), list5, booleanValue, new m53((Lazy) pair4.component2()) {
                        @Override
                        public Object get() {
                            return ((Lazy) this.receiver).getValue();
                        }
                    }));
                    if (booleanValue) {
                        linkedHashMap = linkedHashMap7;
                        linkedHashMap.put(Long.valueOf(longValue2), "balancer-proxy-" + longValue2);
                    } else {
                        linkedHashMap = linkedHashMap7;
                    }
                    linkedHashMap5 = linkedHashMap6;
                    linkedHashMap4 = linkedHashMap;
                    it4 = it16;
                }
                LinkedHashMap linkedHashMap8 = linkedHashMap5;
                LinkedHashMap linkedHashMap9 = linkedHashMap4;
                boolean h = zs4.h(DataStore.INSTANCE.getServiceMode(), Key.MODE_VPN);
                it5 = enabledRules$default.iterator();
                boolean z8 = false;
                while (it5.hasNext()) {
                    RuleEntity ruleEntity = (RuleEntity) it5.next();
                    if (!(!ruleEntity.getPackages().isEmpty())) {
                        arrayList3 = arrayList17;
                        num2 = num4;
                    } else if (h) {
                        arrayList3 = arrayList17;
                        num2 = num4;
                        z8 = true;
                    } else {
                        arrayList17.add(TuplesKt.to(num4, ruleEntity.displayName()));
                        z8 = true;
                    }
                    V2RayConfig v2RayConfig3 = v2RayConfig2;
                    List<V2RayConfig.RoutingObject.RuleObject> list6 = v2RayConfig3.routing.rules;
                    V2RayConfig.RoutingObject.RuleObject ruleObject3 = new V2RayConfig.RoutingObject.RuleObject();
                    String str29 = str23;
                    ruleObject3.type = str29;
                    if (!ruleEntity.getPackages().isEmpty()) {
                        PackageCache.INSTANCE.awaitLoadSync();
                        List<String> packages = ruleEntity.getPackages();
                        z3 = h;
                        it9 = it5;
                        ArrayList arrayList18 = new ArrayList(q00.A0(packages, 10));
                        Iterator it17 = packages.iterator();
                        while (it17.hasNext()) {
                            Iterator it18 = it17;
                            Integer num5 = PackageCache.INSTANCE.get((String) it17.next());
                            if (num5 != null) {
                                Integer num6 = num5.intValue() >= 10000 ? num5 : null;
                                if (num6 != null) {
                                    i2 = num6.intValue();
                                    arrayList18.add(Integer.valueOf(i2));
                                    it17 = it18;
                                }
                            }
                            i2 = 1000;
                            arrayList18.add(Integer.valueOf(i2));
                            it17 = it18;
                        }
                        ruleObject3.uidList = t00.H1(t00.F1(arrayList18));
                    } else {
                        z3 = h;
                        it9 = it5;
                    }
                    if (!x74.a1(ruleEntity.getSsid())) {
                        int i4 = Build.VERSION.SDK_INT;
                        if (UtilsKt.getApp().checkSelfPermission("android.permission.ACCESS_BACKGROUND_LOCATION") != 0) {
                            throw new Alerts.RouteAlertException(1, ruleEntity.displayName());
                        }
                        if (i4 >= 28) {
                            z4 = Core.INSTANCE.getLocation().isLocationEnabled();
                        } else {
                            try {
                                if (Settings.Secure.getInt(UtilsKt.getApp().getContentResolver(), "location_mode") != 0) {
                                    z4 = true;
                                }
                            } catch (Settings.SettingNotFoundException e) {
                                e.printStackTrace();
                            }
                            z4 = false;
                        }
                        if (!z4) {
                            throw new Alerts.RouteAlertException(2, ruleEntity.displayName());
                        }
                    }
                    if (!x74.a1(ruleEntity.getDomains())) {
                        ruleObject3.domain = x74.p1(ruleEntity.getDomains(), new String[]{"\n"});
                    }
                    if (!x74.a1(ruleEntity.getIp())) {
                        ruleObject3.ip = x74.p1(ruleEntity.getIp(), new String[]{"\n"});
                    }
                    if (!x74.a1(ruleEntity.getPort())) {
                        ruleObject3.port = ruleEntity.getPort();
                    }
                    if (!x74.a1(ruleEntity.getSourcePort())) {
                        ruleObject3.sourcePort = ruleEntity.getSourcePort();
                    }
                    if (!x74.a1(ruleEntity.getNetwork())) {
                        ruleObject3.network = ruleEntity.getNetwork();
                    }
                    if (!x74.a1(ruleEntity.getSource())) {
                        ruleObject3.source = x74.p1(ruleEntity.getSource(), new String[]{"\n"});
                    }
                    if (!x74.a1(ruleEntity.getProtocol())) {
                        ruleObject3.protocol = x74.p1(ruleEntity.getProtocol(), new String[]{"\n"});
                    }
                    if (!x74.a1(ruleEntity.getAttrs())) {
                        ruleObject3.attrs = ruleEntity.getAttrs();
                    }
                    if (!x74.a1(ruleEntity.getSsid())) {
                        ruleObject3.ssidList = x74.p1(ruleEntity.getSsid(), new String[]{"\n"});
                    }
                    if (!x74.a1(ruleEntity.getNetworkType())) {
                        ruleObject3.networkType = ruleEntity.getNetworkType();
                    }
                    boolean z9 = z8;
                    arrayList17 = arrayList3;
                    if (ruleEntity.getReverse()) {
                        ruleObject3.inboundTag = zm2.c0("reverse-" + ruleEntity.getId());
                    } else {
                        boolean containsKey = linkedHashMap9.containsKey(Long.valueOf(ruleEntity.getOutbound()));
                        long outbound = ruleEntity.getOutbound();
                        if (containsKey) {
                            ruleObject3.balancerTag = (String) linkedHashMap9.get(Long.valueOf(outbound));
                        } else {
                            if (outbound != 0) {
                                if (outbound == -1) {
                                    str10 = TAG_BYPASS;
                                } else if (outbound == -2) {
                                    str10 = TAG_BLOCK;
                                } else if (outbound != proxyEntity.getId()) {
                                    str10 = (String) linkedHashMap8.get(Long.valueOf(outbound));
                                }
                                ruleObject3.outboundTag = str10;
                            }
                            str10 = buildV2RayConfig$lambda$152$buildChain;
                            ruleObject3.outboundTag = str10;
                        }
                    }
                    Unit unit3 = Unit.INSTANCE;
                    list6.add(ruleObject3);
                    if (ruleEntity.getReverse()) {
                        List<V2RayConfig.OutboundObject> list7 = v2RayConfig3.outbounds;
                        V2RayConfig.OutboundObject outboundObject = new V2RayConfig.OutboundObject();
                        outboundObject.tag = pl0.o("reverse-out-", ruleEntity.getId());
                        outboundObject.protocol = "freedom";
                        V2RayConfig.FreedomOutboundConfigurationObject freedomOutboundConfigurationObject = new V2RayConfig.FreedomOutboundConfigurationObject();
                        freedomOutboundConfigurationObject.redirect = ruleEntity.getRedirect();
                        outboundObject.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject, freedomOutboundConfigurationObject);
                        list7.add(outboundObject);
                        if (v2RayConfig3.reverse == null) {
                            V2RayConfig.ReverseObject reverseObject = new V2RayConfig.ReverseObject();
                            reverseObject.bridges = new ArrayList();
                            v2RayConfig3.reverse = reverseObject;
                        }
                        List<V2RayConfig.ReverseObject.BridgeObject> list8 = v2RayConfig3.reverse.bridges;
                        V2RayConfig.ReverseObject.BridgeObject bridgeObject = new V2RayConfig.ReverseObject.BridgeObject();
                        bridgeObject.tag = pl0.o("reverse-", ruleEntity.getId());
                        String domains = ruleEntity.getDomains();
                        bridgeObject.domain = x74.v1(domains, "full:", domains);
                        list8.add(bridgeObject);
                        List<V2RayConfig.RoutingObject.RuleObject> list9 = v2RayConfig3.routing.rules;
                        V2RayConfig.RoutingObject.RuleObject ruleObject4 = new V2RayConfig.RoutingObject.RuleObject();
                        ruleObject4.type = str29;
                        ruleObject4.inboundTag = zm2.c0("reverse-" + ruleEntity.getId());
                        ruleObject4.outboundTag = pl0.o("reverse-out-", ruleEntity.getId());
                        list9.add(ruleObject4);
                    }
                    z8 = z9;
                    v2RayConfig2 = v2RayConfig3;
                    num4 = num2;
                    str23 = str29;
                    h = z3;
                    it5 = it9;
                }
                V2RayConfig v2RayConfig4 = v2RayConfig2;
                String str30 = str23;
                Integer num7 = num4;
                if (ref$BooleanRef.a) {
                    V2RayConfig.BrowserForwarderObject browserForwarderObject = new V2RayConfig.BrowserForwarderObject();
                    browserForwarderObject.listenAddr = str19;
                    browserForwarderObject.listenPort = Integer.valueOf(NetsKt.mkPort());
                    Unit unit4 = Unit.INSTANCE;
                    v2RayConfig4.browserForwarder = browserForwarderObject;
                }
                String[] strArr = {"direct", TAG_BYPASS};
                for (i = 0; i < 2; i++) {
                    String str31 = strArr[i];
                    List<V2RayConfig.OutboundObject> list10 = v2RayConfig4.outbounds;
                    V2RayConfig.OutboundObject outboundObject2 = new V2RayConfig.OutboundObject();
                    outboundObject2.tag = str31;
                    outboundObject2.protocol = "freedom";
                    Unit unit5 = Unit.INSTANCE;
                    list10.add(outboundObject2);
                }
                List<V2RayConfig.OutboundObject> list11 = v2RayConfig4.outbounds;
                V2RayConfig.OutboundObject outboundObject3 = new V2RayConfig.OutboundObject();
                outboundObject3.tag = TAG_BLOCK;
                outboundObject3.protocol = "blackhole";
                Unit unit6 = Unit.INSTANCE;
                list11.add(outboundObject3);
                if (!z) {
                    List<V2RayConfig.InboundObject> list12 = v2RayConfig4.inbounds;
                    V2RayConfig.InboundObject inboundObject4 = new V2RayConfig.InboundObject();
                    inboundObject4.tag = TAG_DNS_IN;
                    inboundObject4.listen = str27;
                    inboundObject4.port = Integer.valueOf(DataStore.INSTANCE.getLocalDNSPort());
                    inboundObject4.protocol = str24;
                    V2RayConfig.DokodemoDoorInboundConfigurationObject dokodemoDoorInboundConfigurationObject2 = new V2RayConfig.DokodemoDoorInboundConfigurationObject();
                    dokodemoDoorInboundConfigurationObject2.address = "1.0.0.1";
                    dokodemoDoorInboundConfigurationObject2.network = "tcp,udp";
                    dokodemoDoorInboundConfigurationObject2.port = 53;
                    inboundObject4.settings = new V2RayConfig.LazyInboundConfigurationObject(inboundObject4, dokodemoDoorInboundConfigurationObject2);
                    list12.add(inboundObject4);
                }
                List<V2RayConfig.OutboundObject> list13 = v2RayConfig4.outbounds;
                V2RayConfig.OutboundObject outboundObject4 = new V2RayConfig.OutboundObject();
                outboundObject4.protocol = "dns";
                outboundObject4.tag = TAG_DNS_OUT;
                dNSOutboundConfigurationObject = new V2RayConfig.DNSOutboundConfigurationObject();
                dNSOutboundConfigurationObject.userLevel = 1;
                str6 = (String) t00.a1(arrayList2);
                if (!x74.L0(str6, "://", false)) {
                    str6 = "udp://".concat(str6);
                }
                parse = Uri.parse(str6);
                dNSOutboundConfigurationObject.address = parse.getHost();
                if (parse.getPort() > 0) {
                    dNSOutboundConfigurationObject.port = Integer.valueOf(parse.getPort());
                }
                scheme = parse.getScheme();
                boolean z10 = z8;
                if (scheme != null && (x74.r1(scheme, StandardV2RayBean.TYPE_TCP, false) || x74.r1(scheme, "https", false))) {
                    dNSOutboundConfigurationObject.network = StandardV2RayBean.TYPE_TCP;
                }
                outboundObject4.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject4, dNSOutboundConfigurationObject);
                list13.add(outboundObject4);
                hashSet = new HashSet();
                hashSet2 = new HashSet();
                it6 = t00.r1(q00.B0(map.values()), buildV2RayConfig$resolveChain).iterator();
                while (it6.hasNext()) {
                    AbstractBean requireBean2 = ((ProxyEntity) it6.next()).requireBean();
                    String str32 = requireBean2.serverAddress;
                    zs4.n(str32, Key.SERVER_ADDRESS);
                    boolean isIpAddress = NetsKt.isIpAddress(str32);
                    String str33 = requireBean2.serverAddress;
                    if (isIpAddress) {
                        hashSet.add(str33);
                    } else {
                        hashSet2.add("full:" + str33);
                    }
                }
                if (!hashSet.isEmpty()) {
                    List<V2RayConfig.RoutingObject.RuleObject> list14 = v2RayConfig4.routing.rules;
                    V2RayConfig.RoutingObject.RuleObject ruleObject5 = new V2RayConfig.RoutingObject.RuleObject();
                    ruleObject5.type = str30;
                    ruleObject5.ip = t00.H1(hashSet);
                    ruleObject5.outboundTag = "direct";
                    Unit unit7 = Unit.INSTANCE;
                    list14.add(0, ruleObject5);
                }
                if (enableDnsRouting) {
                    ArrayList arrayList19 = new ArrayList();
                    for (Object obj11 : enabledRules$default) {
                        if (((RuleEntity) obj11).isBypassRule()) {
                            arrayList19.add(obj11);
                        }
                    }
                    Iterator it19 = arrayList19.iterator();
                    while (it19.hasNext()) {
                        RuleEntity ruleEntity2 = (RuleEntity) it19.next();
                        if (!x74.a1(ruleEntity2.getDomains())) {
                            hashSet2.addAll(x74.p1(ruleEntity2.getDomains(), new String[]{"\n"}));
                        }
                    }
                }
                it7 = arrayList2.iterator();
                while (it7.hasNext()) {
                    String host2 = Uri.parse((String) it7.next()).getHost();
                    if (host2 != null) {
                        if (!(!NetsKt.isIpAddress(host2))) {
                            host2 = null;
                        }
                        if (host2 != null) {
                            hashSet2.add("full:".concat(host2));
                        }
                    }
                }
                if (!hashSet2.isEmpty()) {
                    List<V2RayConfig.DnsObject.StringOrServerObject> list15 = v2RayConfig4.dns.servers;
                    ArrayList arrayList20 = new ArrayList(q00.A0(collection4, 10));
                    Iterator it20 = collection4.iterator();
                    while (it20.hasNext()) {
                        String str34 = (String) it20.next();
                        V2RayConfig.DnsObject.StringOrServerObject stringOrServerObject2 = new V2RayConfig.DnsObject.StringOrServerObject();
                        ?? serverObject2 = new V2RayConfig.DnsObject.ServerObject();
                        String str35 = str25;
                        if (zs4.h(str34, str35)) {
                            it8 = it20;
                            str25 = str35;
                            obj2 = obj8;
                            obj3 = obj9;
                            str8 = str28;
                        } else {
                            URL parseURL2 = Libcore.parseURL(str34);
                            it8 = it20;
                            String scheme4 = parseURL2.getScheme();
                            str25 = str35;
                            zs4.n(scheme4, str26);
                            if (x74.a1(scheme4)) {
                                parseURL2.setScheme("udp+local");
                                obj2 = obj8;
                                obj3 = obj9;
                            } else {
                                String scheme5 = parseURL2.getScheme();
                                if (scheme5 != null) {
                                    switch (scheme5.hashCode()) {
                                        case 114939:
                                            obj2 = obj8;
                                            obj3 = obj9;
                                            if (scheme5.equals(obj2)) {
                                                scheme2 = "tls+local";
                                                break;
                                            }
                                            scheme2 = parseURL2.getScheme();
                                            break;
                                        case 115649:
                                            str9 = "udp+local";
                                            obj3 = obj9;
                                            obj4 = obj10;
                                            break;
                                        case 3482174:
                                            Object obj12 = obj9;
                                            if (scheme5.equals(obj12)) {
                                                str9 = "quic+local";
                                                obj3 = obj12;
                                                obj4 = obj10;
                                                obj10 = obj4;
                                                scheme2 = str9;
                                                obj2 = obj8;
                                                break;
                                            } else {
                                                obj3 = obj12;
                                                obj4 = obj10;
                                                obj10 = obj4;
                                                obj2 = obj8;
                                                scheme2 = parseURL2.getScheme();
                                                break;
                                            }
                                        case 99617003:
                                            if (scheme5.equals("https")) {
                                                scheme2 = "https+local";
                                                obj2 = obj8;
                                                obj3 = obj9;
                                                break;
                                            }
                                        default:
                                            obj2 = obj8;
                                            obj3 = obj9;
                                            scheme2 = parseURL2.getScheme();
                                            break;
                                    }
                                    parseURL2.setScheme(scheme2);
                                }
                                obj2 = obj8;
                                obj3 = obj9;
                                scheme2 = parseURL2.getScheme();
                                parseURL2.setScheme(scheme2);
                            }
                            str34 = parseURL2.getString();
                            str8 = str28;
                            zs4.n(str34, str8);
                        }
                        serverObject2.address = str34;
                        serverObject2.domains = t00.H1(hashSet2);
                        serverObject2.skipFallback = Boolean.TRUE;
                        serverObject2.concurrency = true;
                        stringOrServerObject2.valueY = serverObject2;
                        arrayList20.add(stringOrServerObject2);
                        str28 = str8;
                        obj8 = obj2;
                        obj9 = obj3;
                        it20 = it8;
                    }
                    z2 = true;
                    list15.addAll(arrayList20);
                } else {
                    z2 = true;
                }
                List<V2RayConfig.RoutingObject.RuleObject> list16 = v2RayConfig4.routing.rules;
                V2RayConfig.RoutingObject.RuleObject ruleObject6 = new V2RayConfig.RoutingObject.RuleObject();
                ruleObject6.type = str30;
                ruleObject6.protocol = zm2.c0("dns");
                ruleObject6.outboundTag = TAG_DNS_OUT;
                Unit unit8 = Unit.INSTANCE;
                list16.add(0, ruleObject6);
                if (!z) {
                    List<V2RayConfig.RoutingObject.RuleObject> list17 = v2RayConfig4.routing.rules;
                    V2RayConfig.RoutingObject.RuleObject ruleObject7 = new V2RayConfig.RoutingObject.RuleObject();
                    ruleObject7.type = str30;
                    ruleObject7.inboundTag = zm2.c0(TAG_DNS_IN);
                    ruleObject7.outboundTag = TAG_DNS_OUT;
                    list17.add(0, ruleObject7);
                }
                if (allowAccess) {
                    List<V2RayConfig.RoutingObject.RuleObject> list18 = v2RayConfig4.routing.rules;
                    V2RayConfig.RoutingObject.RuleObject ruleObject8 = new V2RayConfig.RoutingObject.RuleObject();
                    ruleObject8.type = str30;
                    ruleObject8.ip = zm2.c0("255.255.255.255");
                    ruleObject8.outboundTag = TAG_BLOCK;
                    list18.add(ruleObject8);
                }
                obj = ref$ObjectRef.a;
                if (obj != null) {
                    v2RayConfig4.routing.rules.add(obj);
                }
                if (z6) {
                    v2RayConfig4.stats = map2;
                }
                if (!z) {
                    V2RayConfig.PingObject pingObject = new V2RayConfig.PingObject();
                    pingObject.protocol = "unprivileged";
                    if (DataStore.INSTANCE.getIpv6Mode() != 0) {
                        z2 = false;
                    }
                    pingObject.disableIPv6 = Boolean.valueOf(z2);
                    v2RayConfig4.ping = pingObject;
                }
                String json = GsonsKt.getGson().toJson(v2RayConfig4);
                zs4.n(json, "gson.toJson(this)");
                boolean z11 = ref$BooleanRef.a;
                Integer num8 = z11 ? v2RayConfig4.browserForwarder.listenPort : num7;
                zs4.n(num8, "if (requireWs) browserForwarder.listenPort else 0");
                int intValue = num8.intValue();
                multiObservatoryItem = (V2RayConfig.MultiObservatoryObject.MultiObservatoryItem) ref$ObjectRef2.a;
                str7 = multiObservatoryItem != null ? multiObservatoryItem.tag : null;
                if (str7 == null) {
                    str7 = "";
                }
                String str36 = str7;
                if (multiObservatoryItem != null && (observatoryObject = multiObservatoryItem.settings) != null) {
                    set = observatoryObject.subjectSelector;
                }
                return new V2rayBuildResult(json, arrayList10, z11, intValue, arrayList4, arrayList5, hashMap, TAG_BYPASS, str36, set == null ? new HashSet() : set, z10, arrayList17);
            }
            dnsObject.queryStrategy = str13;
            Unit unit9 = Unit.INSTANCE;
            v2RayConfig.dns = dnsObject;
            V2RayConfig.LogObject logObject2 = new V2RayConfig.LogObject();
            DataStore dataStore32 = DataStore.INSTANCE;
            logObject2.loglevel = dataStore32.getEnableLog() ? "debug" : "error";
            v2RayConfig.log = logObject2;
            V2RayConfig.PolicyObject policyObject2 = new V2RayConfig.PolicyObject();
            V2RayConfig.PolicyObject.LevelPolicyObject levelPolicyObject2 = new V2RayConfig.PolicyObject.LevelPolicyObject();
            levelPolicyObject2.connIdle = 30;
            policyObject2.levels = an1.K(TuplesKt.to("1", levelPolicyObject2));
            if (z6) {
            }
            v2RayConfig.policy = policyObject2;
            ArrayList arrayList162 = new ArrayList();
            v2RayConfig.inbounds = arrayList162;
            if (z) {
            }
            if (z5) {
            }
            if (requireTransproxy) {
            }
            v2RayConfig.outbounds = new ArrayList();
            V2RayConfig.RoutingObject routingObject2 = new V2RayConfig.RoutingObject();
            routingObject2.domainStrategy = dataStore32.getDomainStrategy();
            routingObject2.rules = new ArrayList();
            HashMap hashMap22 = new HashMap();
            it3 = buildV2RayConfig$resolveChain.iterator();
            while (it3.hasNext()) {
            }
            List<V2RayConfig.RoutingObject.RuleObject> list32 = routingObject2.rules;
            Collection<? extends V2RayConfig.RoutingObject.RuleObject> values2 = hashMap22.values();
            zs4.n(values2, "wsRules.values");
            list32.addAll(values2);
            if (!z) {
            }
            Unit unit22 = Unit.INSTANCE;
            v2RayConfig.routing = routingObject2;
            Ref$ObjectRef ref$ObjectRef3 = new Ref$ObjectRef();
            Ref$ObjectRef ref$ObjectRef22 = new Ref$ObjectRef();
            if (proxyEntity.getBalancerBean() != null) {
            }
            V2RayConfig v2RayConfig22 = v2RayConfig;
            ConfigBuilderKt$buildV2RayConfig$1$tagProxy$1 configBuilderKt$buildV2RayConfig$1$tagProxy$12 = new ConfigBuilderKt$buildV2RayConfig$1$tagProxy$1(proxyEntity);
            set = null;
            ArrayList arrayList172 = arrayList11;
            String str232 = "field";
            String str242 = str4;
            Object obj82 = StandardV2RayBean.SECURITY_TLS;
            String str252 = str21;
            String str262 = str3;
            String str272 = str16;
            Object obj92 = StandardV2RayBean.TYPE_QUIC;
            String str282 = str5;
            Object obj102 = "udp";
            Integer num42 = num;
            String buildV2RayConfig$lambda$152$buildChain2 = buildV2RayConfig$lambda$152$buildChain(arrayList10, v2RayConfig22, ref$ObjectRef22, ref$ObjectRef3, arrayList15, hashMap, arrayList4, arrayList5, str2, proxyEntity, ref$BooleanRef, z, z5, requireTransproxy, "proxy", buildV2RayConfig$resolveChain, z7, configBuilderKt$buildV2RayConfig$1$tagProxy$12);
            LinkedHashMap linkedHashMap42 = new LinkedHashMap();
            LinkedHashMap linkedHashMap52 = new LinkedHashMap();
            it4 = map.entrySet().iterator();
            while (it4.hasNext()) {
            }
            LinkedHashMap linkedHashMap82 = linkedHashMap52;
            LinkedHashMap linkedHashMap92 = linkedHashMap42;
            boolean h2 = zs4.h(DataStore.INSTANCE.getServiceMode(), Key.MODE_VPN);
            it5 = enabledRules$default.iterator();
            boolean z82 = false;
            while (it5.hasNext()) {
            }
            V2RayConfig v2RayConfig42 = v2RayConfig22;
            String str302 = str232;
            Integer num72 = num42;
            if (ref$BooleanRef.a) {
            }
            String[] strArr2 = {"direct", TAG_BYPASS};
            while (i < 2) {
            }
            List<V2RayConfig.OutboundObject> list112 = v2RayConfig42.outbounds;
            V2RayConfig.OutboundObject outboundObject32 = new V2RayConfig.OutboundObject();
            outboundObject32.tag = TAG_BLOCK;
            outboundObject32.protocol = "blackhole";
            Unit unit62 = Unit.INSTANCE;
            list112.add(outboundObject32);
            if (!z) {
            }
            List<V2RayConfig.OutboundObject> list132 = v2RayConfig42.outbounds;
            V2RayConfig.OutboundObject outboundObject42 = new V2RayConfig.OutboundObject();
            outboundObject42.protocol = "dns";
            outboundObject42.tag = TAG_DNS_OUT;
            dNSOutboundConfigurationObject = new V2RayConfig.DNSOutboundConfigurationObject();
            dNSOutboundConfigurationObject.userLevel = 1;
            str6 = (String) t00.a1(arrayList2);
            if (!x74.L0(str6, "://", false)) {
            }
            parse = Uri.parse(str6);
            dNSOutboundConfigurationObject.address = parse.getHost();
            if (parse.getPort() > 0) {
            }
            scheme = parse.getScheme();
            boolean z102 = z82;
            if (scheme != null) {
                dNSOutboundConfigurationObject.network = StandardV2RayBean.TYPE_TCP;
            }
            outboundObject42.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject42, dNSOutboundConfigurationObject);
            list132.add(outboundObject42);
            hashSet = new HashSet();
            hashSet2 = new HashSet();
            it6 = t00.r1(q00.B0(map.values()), buildV2RayConfig$resolveChain).iterator();
            while (it6.hasNext()) {
            }
            if (!hashSet.isEmpty()) {
            }
            if (enableDnsRouting) {
            }
            it7 = arrayList2.iterator();
            while (it7.hasNext()) {
            }
            if (!hashSet2.isEmpty()) {
            }
            List<V2RayConfig.RoutingObject.RuleObject> list162 = v2RayConfig42.routing.rules;
            V2RayConfig.RoutingObject.RuleObject ruleObject62 = new V2RayConfig.RoutingObject.RuleObject();
            ruleObject62.type = str302;
            ruleObject62.protocol = zm2.c0("dns");
            ruleObject62.outboundTag = TAG_DNS_OUT;
            Unit unit82 = Unit.INSTANCE;
            list162.add(0, ruleObject62);
            if (!z) {
            }
            if (allowAccess) {
            }
            obj = ref$ObjectRef3.a;
            if (obj != null) {
            }
            if (z6) {
            }
            if (!z) {
            }
            String json2 = GsonsKt.getGson().toJson(v2RayConfig42);
            zs4.n(json2, "gson.toJson(this)");
            boolean z112 = ref$BooleanRef.a;
            if (z112) {
            }
            zs4.n(num8, "if (requireWs) browserForwarder.listenPort else 0");
            int intValue2 = num8.intValue();
            multiObservatoryItem = (V2RayConfig.MultiObservatoryObject.MultiObservatoryItem) ref$ObjectRef22.a;
            if (multiObservatoryItem != null) {
            }
            if (str7 == null) {
            }
            String str362 = str7;
            if (multiObservatoryItem != null) {
                set = observatoryObject.subjectSelector;
            }
            return new V2rayBuildResult(json2, arrayList10, z112, intValue2, arrayList4, arrayList5, hashMap, TAG_BYPASS, str362, set == null ? new HashSet() : set, z102, arrayList172);
        }
        str = "AsIs";
        str2 = str;
        ArrayList arrayList112 = new ArrayList();
        V2RayConfig v2RayConfig5 = new V2RayConfig();
        V2RayConfig.DnsObject dnsObject2 = new V2RayConfig.DnsObject();
        List p132 = x74.p1(dataStore2.getHosts(), new String[]{"\n"});
        ArrayList arrayList122 = new ArrayList();
        while (r2.hasNext()) {
        }
        Collection collection42 = collection2;
        J = an1.J(q00.A0(arrayList122, 10));
        if (J < 16) {
        }
        LinkedHashMap linkedHashMap32 = new LinkedHashMap(J);
        it = arrayList122.iterator();
        while (it.hasNext()) {
        }
        String str192 = str15;
        dnsObject2.hosts = ne2.l0(linkedHashMap32);
        ArrayList arrayList132 = new ArrayList();
        dnsObject2.servers = arrayList132;
        arrayList = new ArrayList(q00.A0(arrayList8, 10));
        it2 = arrayList8.iterator();
        while (true) {
            num = num3;
            map2 = map3;
            arrayList2 = arrayList8;
            if (it2.hasNext()) {
            }
            serverObject.address = str20;
            serverObject.concurrency = true;
            stringOrServerObject.valueY = serverObject;
            arrayList.add(stringOrServerObject);
            num3 = num;
            map3 = map2;
            arrayList8 = arrayList2;
            it2 = it14;
            arrayList6 = arrayList14;
            str17 = str14;
        }
        ArrayList arrayList152 = arrayList6;
        String str212 = str17;
        arrayList132.addAll(arrayList);
        Boolean bool2 = Boolean.TRUE;
        dnsObject2.disableFallbackIfMatch = bool2;
        if (ipv6Mode == 0) {
        }
        dnsObject2.queryStrategy = str13;
        Unit unit92 = Unit.INSTANCE;
        v2RayConfig5.dns = dnsObject2;
        V2RayConfig.LogObject logObject22 = new V2RayConfig.LogObject();
        DataStore dataStore322 = DataStore.INSTANCE;
        logObject22.loglevel = dataStore322.getEnableLog() ? "debug" : "error";
        v2RayConfig5.log = logObject22;
        V2RayConfig.PolicyObject policyObject22 = new V2RayConfig.PolicyObject();
        V2RayConfig.PolicyObject.LevelPolicyObject levelPolicyObject22 = new V2RayConfig.PolicyObject.LevelPolicyObject();
        levelPolicyObject22.connIdle = 30;
        policyObject22.levels = an1.K(TuplesKt.to("1", levelPolicyObject22));
        if (z6) {
        }
        v2RayConfig5.policy = policyObject22;
        ArrayList arrayList1622 = new ArrayList();
        v2RayConfig5.inbounds = arrayList1622;
        if (z) {
        }
        if (z5) {
        }
        if (requireTransproxy) {
        }
        v2RayConfig5.outbounds = new ArrayList();
        V2RayConfig.RoutingObject routingObject22 = new V2RayConfig.RoutingObject();
        routingObject22.domainStrategy = dataStore322.getDomainStrategy();
        routingObject22.rules = new ArrayList();
        HashMap hashMap222 = new HashMap();
        it3 = buildV2RayConfig$resolveChain.iterator();
        while (it3.hasNext()) {
        }
        List<V2RayConfig.RoutingObject.RuleObject> list322 = routingObject22.rules;
        Collection<? extends V2RayConfig.RoutingObject.RuleObject> values22 = hashMap222.values();
        zs4.n(values22, "wsRules.values");
        list322.addAll(values22);
        if (!z) {
        }
        Unit unit222 = Unit.INSTANCE;
        v2RayConfig5.routing = routingObject22;
        Ref$ObjectRef ref$ObjectRef32 = new Ref$ObjectRef();
        Ref$ObjectRef ref$ObjectRef222 = new Ref$ObjectRef();
        if (proxyEntity.getBalancerBean() != null) {
        }
        V2RayConfig v2RayConfig222 = v2RayConfig5;
        ConfigBuilderKt$buildV2RayConfig$1$tagProxy$1 configBuilderKt$buildV2RayConfig$1$tagProxy$122 = new ConfigBuilderKt$buildV2RayConfig$1$tagProxy$1(proxyEntity);
        set = null;
        ArrayList arrayList1722 = arrayList112;
        String str2322 = "field";
        String str2422 = str4;
        Object obj822 = StandardV2RayBean.SECURITY_TLS;
        String str2522 = str212;
        String str2622 = str3;
        String str2722 = str16;
        Object obj922 = StandardV2RayBean.TYPE_QUIC;
        String str2822 = str5;
        Object obj1022 = "udp";
        Integer num422 = num;
        String buildV2RayConfig$lambda$152$buildChain22 = buildV2RayConfig$lambda$152$buildChain(arrayList10, v2RayConfig222, ref$ObjectRef222, ref$ObjectRef32, arrayList152, hashMap, arrayList4, arrayList5, str2, proxyEntity, ref$BooleanRef, z, z5, requireTransproxy, "proxy", buildV2RayConfig$resolveChain, z7, configBuilderKt$buildV2RayConfig$1$tagProxy$122);
        LinkedHashMap linkedHashMap422 = new LinkedHashMap();
        LinkedHashMap linkedHashMap522 = new LinkedHashMap();
        it4 = map.entrySet().iterator();
        while (it4.hasNext()) {
        }
        LinkedHashMap linkedHashMap822 = linkedHashMap522;
        LinkedHashMap linkedHashMap922 = linkedHashMap422;
        boolean h22 = zs4.h(DataStore.INSTANCE.getServiceMode(), Key.MODE_VPN);
        it5 = enabledRules$default.iterator();
        boolean z822 = false;
        while (it5.hasNext()) {
        }
        V2RayConfig v2RayConfig422 = v2RayConfig222;
        String str3022 = str2322;
        Integer num722 = num422;
        if (ref$BooleanRef.a) {
        }
        String[] strArr22 = {"direct", TAG_BYPASS};
        while (i < 2) {
        }
        List<V2RayConfig.OutboundObject> list1122 = v2RayConfig422.outbounds;
        V2RayConfig.OutboundObject outboundObject322 = new V2RayConfig.OutboundObject();
        outboundObject322.tag = TAG_BLOCK;
        outboundObject322.protocol = "blackhole";
        Unit unit622 = Unit.INSTANCE;
        list1122.add(outboundObject322);
        if (!z) {
        }
        List<V2RayConfig.OutboundObject> list1322 = v2RayConfig422.outbounds;
        V2RayConfig.OutboundObject outboundObject422 = new V2RayConfig.OutboundObject();
        outboundObject422.protocol = "dns";
        outboundObject422.tag = TAG_DNS_OUT;
        dNSOutboundConfigurationObject = new V2RayConfig.DNSOutboundConfigurationObject();
        dNSOutboundConfigurationObject.userLevel = 1;
        str6 = (String) t00.a1(arrayList2);
        if (!x74.L0(str6, "://", false)) {
        }
        parse = Uri.parse(str6);
        dNSOutboundConfigurationObject.address = parse.getHost();
        if (parse.getPort() > 0) {
        }
        scheme = parse.getScheme();
        boolean z1022 = z822;
        if (scheme != null) {
        }
        outboundObject422.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject422, dNSOutboundConfigurationObject);
        list1322.add(outboundObject422);
        hashSet = new HashSet();
        hashSet2 = new HashSet();
        it6 = t00.r1(q00.B0(map.values()), buildV2RayConfig$resolveChain).iterator();
        while (it6.hasNext()) {
        }
        if (!hashSet.isEmpty()) {
        }
        if (enableDnsRouting) {
        }
        it7 = arrayList2.iterator();
        while (it7.hasNext()) {
        }
        if (!hashSet2.isEmpty()) {
        }
        List<V2RayConfig.RoutingObject.RuleObject> list1622 = v2RayConfig422.routing.rules;
        V2RayConfig.RoutingObject.RuleObject ruleObject622 = new V2RayConfig.RoutingObject.RuleObject();
        ruleObject622.type = str3022;
        ruleObject622.protocol = zm2.c0("dns");
        ruleObject622.outboundTag = TAG_DNS_OUT;
        Unit unit822 = Unit.INSTANCE;
        list1622.add(0, ruleObject622);
        if (!z) {
        }
        if (allowAccess) {
        }
        obj = ref$ObjectRef32.a;
        if (obj != null) {
        }
        if (z6) {
        }
        if (!z) {
        }
        String json22 = GsonsKt.getGson().toJson(v2RayConfig422);
        zs4.n(json22, "gson.toJson(this)");
        boolean z1122 = ref$BooleanRef.a;
        if (z1122) {
        }
        zs4.n(num8, "if (requireWs) browserForwarder.listenPort else 0");
        int intValue22 = num8.intValue();
        multiObservatoryItem = (V2RayConfig.MultiObservatoryObject.MultiObservatoryItem) ref$ObjectRef222.a;
        if (multiObservatoryItem != null) {
        }
        if (str7 == null) {
        }
        String str3622 = str7;
        if (multiObservatoryItem != null) {
        }
        return new V2rayBuildResult(json22, arrayList10, z1122, intValue22, arrayList4, arrayList5, hashMap, TAG_BYPASS, str3622, set == null ? new HashSet() : set, z1022, arrayList1722);
    }

    public static V2rayBuildResult buildV2RayConfig$default(ProxyEntity proxyEntity, boolean z, int i, Object obj) {
        if ((i & 2) != 0) {
            z = false;
        }
        return buildV2RayConfig(proxyEntity, z);
    }

    private static final String buildV2RayConfig$lambda$152$buildChain(ArrayList<V2rayBuildResult.IndexEntity> arrayList, V2RayConfig v2RayConfig, Ref$ObjectRef ref$ObjectRef, Ref$ObjectRef ref$ObjectRef2, ArrayList<String> arrayList2, HashMap<String, ProxyEntity> hashMap, ArrayList<String> arrayList3, ArrayList<String> arrayList4, String str, ProxyEntity proxyEntity, Ref$BooleanRef ref$BooleanRef, boolean z, boolean z2, boolean z3, String str2, List<ProxyEntity> list, boolean z4, Function0 function0) {
        String str3;
        boolean z5;
        V2RayConfig.OutboundObject outboundObject;
        String o;
        boolean z6;
        String str4;
        LinkedHashMap linkedHashMap;
        boolean z7;
        int i;
        String str5;
        ProxyEntity proxyEntity2;
        String str6;
        V2RayConfig v2RayConfig2;
        String str7;
        V2RayConfig.OutboundObject outboundObject2;
        String str8;
        ArrayList arrayList5;
        String str9;
        String str10;
        String password;
        V2RayConfig.StreamSettingsObject streamSettingsObject;
        V2RayConfig.StreamSettingsObject.SockoptObject sockoptObject;
        String str11;
        String str12;
        boolean z8;
        int i2;
        String str13;
        String str14;
        int packetEncoding;
        V2RayConfig.LazyOutboundConfigurationObject lazyOutboundConfigurationObject;
        StandardV2RayBean standardV2RayBean;
        String str15;
        String str16;
        String str17;
        V2RayConfig.StreamSettingsObject streamSettingsObject2;
        V2RayConfig.StreamSettingsObject.SockoptObject sockoptObject2;
        String str18;
        V2RayConfig v2RayConfig3 = v2RayConfig;
        ArrayList<String> arrayList6 = arrayList2;
        String str19 = str2;
        boolean z9 = z4;
        LinkedHashMap linkedHashMap2 = new LinkedHashMap();
        arrayList.add(new V2rayBuildResult.IndexEntity(z9, linkedHashMap2));
        ArrayList arrayList7 = new ArrayList();
        Iterator it = list.iterator();
        String str20 = "";
        V2RayConfig.OutboundObject outboundObject3 = null;
        boolean z10 = false;
        int i3 = 0;
        String str21 = null;
        String str22 = "";
        while (true) {
            ArrayList arrayList8 = arrayList7;
            String str23 = str22;
            String str24 = str21;
            if (!it.hasNext()) {
                String str25 = str19;
                V2RayConfig v2RayConfig4 = v2RayConfig3;
                if (z4) {
                    Object invoke = function0.invoke();
                    zs4.l(invoke);
                    BalancerBean balancerBean = (BalancerBean) invoke;
                    V2RayConfig.ObservatoryObject observatoryObject = new V2RayConfig.ObservatoryObject();
                    String probeUrl = balancerBean.getProbeUrl();
                    if (x74.a1(probeUrl)) {
                        probeUrl = DataStore.INSTANCE.getConnectionTestURL();
                    }
                    observatoryObject.probeUrl = probeUrl;
                    if (balancerBean.getProbeInterval() > 0) {
                        observatoryObject.probeInterval = balancerBean.getProbeInterval() + "s";
                    }
                    observatoryObject.enableConcurrency = Boolean.TRUE;
                    ArrayList arrayList9 = new ArrayList(q00.A0(arrayList8, 10));
                    Iterator it2 = arrayList8.iterator();
                    while (it2.hasNext()) {
                        arrayList9.add(((V2RayConfig.OutboundObject) it2.next()).tag);
                    }
                    observatoryObject.subjectSelector = new HashSet(arrayList9);
                    V2RayConfig.MultiObservatoryObject.MultiObservatoryItem multiObservatoryItem = new V2RayConfig.MultiObservatoryObject.MultiObservatoryItem();
                    multiObservatoryItem.tag = jf2.o("observer-", str25);
                    multiObservatoryItem.settings = observatoryObject;
                    if (v2RayConfig4.multiObservatory == null) {
                        V2RayConfig.MultiObservatoryObject multiObservatoryObject = new V2RayConfig.MultiObservatoryObject();
                        multiObservatoryObject.observers = new ArrayList();
                        Unit unit = Unit.INSTANCE;
                        v2RayConfig4.multiObservatory = multiObservatoryObject;
                    }
                    v2RayConfig4.multiObservatory.observers.add(multiObservatoryItem);
                    V2RayConfig.RoutingObject routingObject = v2RayConfig4.routing;
                    if (routingObject.balancers == null) {
                        routingObject.balancers = new ArrayList();
                    }
                    List<V2RayConfig.RoutingObject.BalancerObject> list2 = v2RayConfig4.routing.balancers;
                    V2RayConfig.RoutingObject.BalancerObject balancerObject = new V2RayConfig.RoutingObject.BalancerObject();
                    balancerObject.tag = jf2.o("balancer-", str25);
                    ArrayList arrayList10 = new ArrayList(q00.A0(arrayList8, 10));
                    Iterator it3 = arrayList8.iterator();
                    while (it3.hasNext()) {
                        arrayList10.add(((V2RayConfig.OutboundObject) it3.next()).tag);
                    }
                    balancerObject.selector = arrayList10;
                    if (v2RayConfig4.multiObservatory == null) {
                        V2RayConfig.MultiObservatoryObject multiObservatoryObject2 = new V2RayConfig.MultiObservatoryObject();
                        multiObservatoryObject2.observers = new ArrayList();
                        v2RayConfig4.multiObservatory = multiObservatoryObject2;
                    }
                    V2RayConfig.RoutingObject.BalancerObject.StrategyObject strategyObject = new V2RayConfig.RoutingObject.BalancerObject.StrategyObject();
                    String strategy = balancerBean.getStrategy();
                    String str26 = Boolean.valueOf(x74.a1(strategy) ^ true).booleanValue() ? strategy : null;
                    if (str26 == null) {
                        str26 = "random";
                    }
                    strategyObject.type = str26;
                    if (!zs4.h(str26, "random")) {
                        V2RayConfig.RoutingObject.BalancerObject.StrategyObject.StrategyLeastPingConfig strategyLeastPingConfig = new V2RayConfig.RoutingObject.BalancerObject.StrategyObject.StrategyLeastPingConfig();
                        strategyLeastPingConfig.observerTag = jf2.o("observer-", str25);
                        strategyObject.settings = strategyLeastPingConfig;
                    }
                    balancerObject.strategy = strategyObject;
                    Unit unit2 = Unit.INSTANCE;
                    list2.add(balancerObject);
                    if (zs4.h(str25, "proxy")) {
                        if (zs4.h(multiObservatoryItem.settings.probeUrl, DataStore.INSTANCE.getConnectionTestURL())) {
                            ref$ObjectRef.a = multiObservatoryItem;
                        }
                        V2RayConfig.RoutingObject.RuleObject ruleObject = new V2RayConfig.RoutingObject.RuleObject();
                        ruleObject.type = "field";
                        ArrayList arrayList11 = new ArrayList();
                        ruleObject.inboundTag = arrayList11;
                        if (!z) {
                            arrayList11.add(TAG_SOCKS);
                        }
                        if (z2) {
                            ruleObject.inboundTag.add("http");
                        }
                        if (z3) {
                            ruleObject.inboundTag.add(TAG_TRANS);
                        }
                        ruleObject.balancerTag = jf2.o("balancer-", str25);
                        ref$ObjectRef2.a = ruleObject;
                        List<V2RayConfig.OutboundObject> list3 = v2RayConfig4.outbounds;
                        V2RayConfig.OutboundObject outboundObject4 = new V2RayConfig.OutboundObject();
                        outboundObject4.protocol = "loopback";
                        V2RayConfig.LoopbackOutboundConfigurationObject loopbackOutboundConfigurationObject = new V2RayConfig.LoopbackOutboundConfigurationObject();
                        loopbackOutboundConfigurationObject.inboundTag = TAG_SOCKS;
                        outboundObject4.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject4, loopbackOutboundConfigurationObject);
                        list3.add(0, outboundObject4);
                    }
                }
                return str23;
            }
            Object next = it.next();
            int i4 = i3 + 1;
            if (i3 < 0) {
                zm2.w0();
                throw null;
            }
            ProxyEntity proxyEntity3 = (ProxyEntity) next;
            Iterator it4 = it;
            AbstractBean requireBean = proxyEntity3.requireBean();
            V2RayConfig.OutboundObject outboundObject5 = new V2RayConfig.OutboundObject();
            if (z9 || (i3 == zm2.R(list) && !z10)) {
                str3 = str20;
                z5 = z10;
                outboundObject = outboundObject3;
                o = pl0.o("proxy-global-", proxyEntity3.getId());
                z6 = true;
            } else {
                if (i3 == 0) {
                    o = str19;
                    str3 = str20;
                    z5 = z10;
                    outboundObject = outboundObject3;
                } else {
                    boolean z11 = z10;
                    outboundObject = outboundObject3;
                    long id = proxyEntity3.getId();
                    z5 = z11;
                    StringBuilder sb = new StringBuilder();
                    sb.append(str19);
                    str3 = str20;
                    sb.append("-");
                    sb.append(id);
                    o = sb.toString();
                }
                z6 = false;
            }
            if (i3 == 0) {
                str23 = o;
            }
            if (z6 && !arrayList6.contains(o)) {
                arrayList6.add(o);
                z6 = false;
            }
            if (z6) {
                str4 = "127.0.0.1";
                linkedHashMap = linkedHashMap2;
                z7 = z6;
                i = i3;
                str5 = "UseIP";
                proxyEntity2 = proxyEntity3;
                str6 = str3;
            } else {
                z7 = z6;
                hashMap.put(o, proxyEntity3);
                if (z9 || i3 == 0) {
                    arrayList3.add(o);
                    if (zs4.h(str19, "proxy")) {
                        arrayList4.add(o);
                        if (proxyEntity3.needExternal()) {
                            int tcpKeepAliveInterval = DataStore.INSTANCE.getTcpKeepAliveInterval();
                            linkedHashMap = linkedHashMap2;
                            boolean z12 = !(da.Y0(tcpKeepAliveInterval, new int[]{0, 15}) >= 0);
                            str4 = "127.0.0.1";
                            String str27 = "packet";
                            str5 = "UseIP";
                            String str28 = o;
                            if (requireBean instanceof SOCKSBean) {
                                outboundObject5.protocol = TAG_SOCKS;
                                V2RayConfig.SocksOutboundConfigurationObject socksOutboundConfigurationObject = new V2RayConfig.SocksOutboundConfigurationObject();
                                V2RayConfig.SocksOutboundConfigurationObject.ServerObject serverObject = new V2RayConfig.SocksOutboundConfigurationObject.ServerObject();
                                serverObject.address = requireBean.serverAddress;
                                serverObject.port = requireBean.serverPort;
                                SOCKSBean sOCKSBean = (SOCKSBean) requireBean;
                                String username = sOCKSBean.getUsername();
                                if (username == null || x74.a1(username)) {
                                    i = i3;
                                    proxyEntity2 = proxyEntity3;
                                } else {
                                    proxyEntity2 = proxyEntity3;
                                    V2RayConfig.SocksOutboundConfigurationObject.ServerObject.UserObject userObject = new V2RayConfig.SocksOutboundConfigurationObject.ServerObject.UserObject();
                                    i = i3;
                                    userObject.user = sOCKSBean.getUsername();
                                    userObject.pass = sOCKSBean.getPassword();
                                    serverObject.users = zm2.c0(userObject);
                                }
                                socksOutboundConfigurationObject.servers = zm2.c0(serverObject);
                                socksOutboundConfigurationObject.version = sOCKSBean.protocolVersionName();
                                Unit unit3 = Unit.INSTANCE;
                                outboundObject5.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, socksOutboundConfigurationObject);
                                if (sOCKSBean.getTls() || z12) {
                                    streamSettingsObject2 = new V2RayConfig.StreamSettingsObject();
                                    streamSettingsObject2.network = StandardV2RayBean.TYPE_TCP;
                                    if (sOCKSBean.getTls()) {
                                        streamSettingsObject2.security = StandardV2RayBean.SECURITY_TLS;
                                        V2RayConfig.TLSObject tLSObject = new V2RayConfig.TLSObject();
                                        if (!x74.a1(sOCKSBean.getSni())) {
                                            tLSObject.serverName = sOCKSBean.getSni();
                                        }
                                        streamSettingsObject2.tlsSettings = tLSObject;
                                    }
                                    if (z12) {
                                        sockoptObject2 = new V2RayConfig.StreamSettingsObject.SockoptObject();
                                        sockoptObject2.tcpKeepAliveInterval = Integer.valueOf(tcpKeepAliveInterval);
                                        streamSettingsObject2.sockopt = sockoptObject2;
                                    }
                                    outboundObject5.streamSettings = streamSettingsObject2;
                                }
                                str9 = "packet";
                                str10 = "xudp";
                                str6 = str3;
                                str11 = str;
                            } else {
                                i = i3;
                                proxyEntity2 = proxyEntity3;
                                if (requireBean instanceof HttpBean) {
                                    outboundObject5.protocol = "http";
                                    V2RayConfig.HTTPOutboundConfigurationObject hTTPOutboundConfigurationObject = new V2RayConfig.HTTPOutboundConfigurationObject();
                                    V2RayConfig.HTTPOutboundConfigurationObject.ServerObject serverObject2 = new V2RayConfig.HTTPOutboundConfigurationObject.ServerObject();
                                    serverObject2.address = requireBean.serverAddress;
                                    serverObject2.port = requireBean.serverPort;
                                    HttpBean httpBean = (HttpBean) requireBean;
                                    String username2 = httpBean.getUsername();
                                    if (!(username2 == null || x74.a1(username2))) {
                                        V2RayConfig.HTTPInboundConfigurationObject.AccountObject accountObject = new V2RayConfig.HTTPInboundConfigurationObject.AccountObject();
                                        accountObject.user = httpBean.getUsername();
                                        accountObject.pass = httpBean.getPassword();
                                        serverObject2.users = zm2.c0(accountObject);
                                    }
                                    hTTPOutboundConfigurationObject.servers = zm2.c0(serverObject2);
                                    Unit unit4 = Unit.INSTANCE;
                                    outboundObject5.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, hTTPOutboundConfigurationObject);
                                    if (httpBean.getTls() || z12) {
                                        streamSettingsObject2 = new V2RayConfig.StreamSettingsObject();
                                        streamSettingsObject2.network = StandardV2RayBean.TYPE_TCP;
                                        if (httpBean.getTls()) {
                                            streamSettingsObject2.security = StandardV2RayBean.SECURITY_TLS;
                                            V2RayConfig.TLSObject tLSObject2 = new V2RayConfig.TLSObject();
                                            if (!x74.a1(httpBean.getSni())) {
                                                tLSObject2.serverName = httpBean.getSni();
                                            }
                                            streamSettingsObject2.tlsSettings = tLSObject2;
                                        }
                                        if (z12) {
                                            sockoptObject2 = new V2RayConfig.StreamSettingsObject.SockoptObject();
                                            sockoptObject2.tcpKeepAliveInterval = Integer.valueOf(tcpKeepAliveInterval);
                                            streamSettingsObject2.sockopt = sockoptObject2;
                                        }
                                        outboundObject5.streamSettings = streamSettingsObject2;
                                    }
                                    str9 = "packet";
                                    str10 = "xudp";
                                    str6 = str3;
                                    str11 = str;
                                } else if (requireBean instanceof StandardV2RayBean) {
                                    if (requireBean instanceof VMessBean) {
                                        outboundObject5.protocol = "vmess";
                                        V2RayConfig.VMessOutboundConfigurationObject vMessOutboundConfigurationObject = new V2RayConfig.VMessOutboundConfigurationObject();
                                        V2RayConfig.VMessOutboundConfigurationObject.ServerObject serverObject3 = new V2RayConfig.VMessOutboundConfigurationObject.ServerObject();
                                        serverObject3.address = requireBean.serverAddress;
                                        serverObject3.port = requireBean.serverPort;
                                        V2RayConfig.VMessOutboundConfigurationObject.ServerObject.UserObject userObject2 = new V2RayConfig.VMessOutboundConfigurationObject.ServerObject.UserObject();
                                        StandardV2RayBean standardV2RayBean2 = (StandardV2RayBean) requireBean;
                                        i2 = tcpKeepAliveInterval;
                                        userObject2.id = standardV2RayBean2.uuidOrGenerate();
                                        String encryption = standardV2RayBean2.getEncryption();
                                        if (!Boolean.valueOf(!x74.a1(encryption)).booleanValue()) {
                                            encryption = null;
                                        }
                                        if (encryption == null) {
                                            encryption = "auto";
                                        }
                                        userObject2.security = encryption;
                                        String str29 = str3;
                                        userObject2.experimental = str29;
                                        VMessBean vMessBean = (VMessBean) requireBean;
                                        if (vMessBean.getExperimentalAuthenticatedLength()) {
                                            str6 = str29;
                                            z8 = z12;
                                            userObject2.experimental = jf2.C(userObject2.experimental, "AuthenticatedLength");
                                        } else {
                                            z8 = z12;
                                            str6 = str29;
                                        }
                                        if (vMessBean.getExperimentalNoTerminationSignal()) {
                                            userObject2.experimental = jf2.C(userObject2.experimental, "NoTerminationSignal");
                                        }
                                        String str30 = userObject2.experimental;
                                        zs4.n(str30, "experimental");
                                        if (x74.a1(str30)) {
                                            userObject2.experimental = null;
                                        }
                                        serverObject3.users = zm2.c0(userObject2);
                                        vMessOutboundConfigurationObject.vnext = zm2.c0(serverObject3);
                                        int packetEncoding2 = standardV2RayBean2.getPacketEncoding();
                                        if (packetEncoding2 == 1) {
                                            vMessOutboundConfigurationObject.packetEncoding = "packet";
                                            if (zs4.h(str, "AsIs")) {
                                                str13 = str5;
                                                Unit unit5 = Unit.INSTANCE;
                                                lazyOutboundConfigurationObject = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, vMessOutboundConfigurationObject);
                                            }
                                        } else if (packetEncoding2 == 2) {
                                            vMessOutboundConfigurationObject.packetEncoding = "xudp";
                                        }
                                        str13 = str;
                                        Unit unit52 = Unit.INSTANCE;
                                        lazyOutboundConfigurationObject = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, vMessOutboundConfigurationObject);
                                    } else {
                                        z8 = z12;
                                        i2 = tcpKeepAliveInterval;
                                        str6 = str3;
                                        if (requireBean instanceof VLESSBean) {
                                            outboundObject5.protocol = "vless";
                                            V2RayConfig.VLESSOutboundConfigurationObject vLESSOutboundConfigurationObject = new V2RayConfig.VLESSOutboundConfigurationObject();
                                            V2RayConfig.VLESSOutboundConfigurationObject.ServerObject serverObject4 = new V2RayConfig.VLESSOutboundConfigurationObject.ServerObject();
                                            serverObject4.address = requireBean.serverAddress;
                                            serverObject4.port = requireBean.serverPort;
                                            V2RayConfig.VLESSOutboundConfigurationObject.ServerObject.UserObject userObject3 = new V2RayConfig.VLESSOutboundConfigurationObject.ServerObject.UserObject();
                                            StandardV2RayBean standardV2RayBean3 = (StandardV2RayBean) requireBean;
                                            userObject3.id = standardV2RayBean3.uuidOrGenerate();
                                            userObject3.encryption = standardV2RayBean3.getEncryption();
                                            if (!x74.a1(standardV2RayBean3.getFlow())) {
                                                str14 = standardV2RayBean3.getFlow();
                                            } else {
                                                if (zs4.h(standardV2RayBean3.getSecurity(), StandardV2RayBean.SECURITY_XTLS)) {
                                                    str14 = "xtls-rprx-direct";
                                                }
                                                serverObject4.users = zm2.c0(userObject3);
                                                vLESSOutboundConfigurationObject.vnext = zm2.c0(serverObject4);
                                                packetEncoding = standardV2RayBean3.getPacketEncoding();
                                                if (packetEncoding != 1) {
                                                    vLESSOutboundConfigurationObject.packetEncoding = "packet";
                                                    if (zs4.h(str, "AsIs")) {
                                                        str13 = str5;
                                                        Unit unit6 = Unit.INSTANCE;
                                                        lazyOutboundConfigurationObject = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, vLESSOutboundConfigurationObject);
                                                    }
                                                } else if (packetEncoding == 2) {
                                                    vLESSOutboundConfigurationObject.packetEncoding = "xudp";
                                                }
                                                str13 = str;
                                                Unit unit62 = Unit.INSTANCE;
                                                lazyOutboundConfigurationObject = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, vLESSOutboundConfigurationObject);
                                            }
                                            userObject3.flow = str14;
                                            serverObject4.users = zm2.c0(userObject3);
                                            vLESSOutboundConfigurationObject.vnext = zm2.c0(serverObject4);
                                            packetEncoding = standardV2RayBean3.getPacketEncoding();
                                            if (packetEncoding != 1) {
                                            }
                                            str13 = str;
                                            Unit unit622 = Unit.INSTANCE;
                                            lazyOutboundConfigurationObject = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, vLESSOutboundConfigurationObject);
                                        } else {
                                            str13 = str;
                                            V2RayConfig.StreamSettingsObject streamSettingsObject3 = new V2RayConfig.StreamSettingsObject();
                                            standardV2RayBean = (StandardV2RayBean) requireBean;
                                            streamSettingsObject3.network = standardV2RayBean.getType();
                                            if (!x74.a1(standardV2RayBean.getSecurity())) {
                                                streamSettingsObject3.security = standardV2RayBean.getSecurity();
                                            }
                                            str15 = streamSettingsObject3.security;
                                            if (!zs4.h(str15, StandardV2RayBean.SECURITY_XTLS)) {
                                                V2RayConfig.TLSObject tLSObject3 = new V2RayConfig.TLSObject();
                                                if (!x74.a1(standardV2RayBean.getSni())) {
                                                    tLSObject3.serverName = standardV2RayBean.getSni();
                                                }
                                                if (!x74.a1(standardV2RayBean.getAlpn())) {
                                                    tLSObject3.alpn = x74.p1(standardV2RayBean.getAlpn(), new String[]{"\n"});
                                                }
                                                streamSettingsObject3.xtlsSettings = tLSObject3;
                                            } else if (zs4.h(str15, StandardV2RayBean.SECURITY_TLS)) {
                                                V2RayConfig.TLSObject tLSObject4 = new V2RayConfig.TLSObject();
                                                if (!x74.a1(standardV2RayBean.getSni())) {
                                                    tLSObject4.serverName = standardV2RayBean.getSni();
                                                }
                                                if (!x74.a1(standardV2RayBean.getAlpn())) {
                                                    tLSObject4.alpn = x74.p1(standardV2RayBean.getAlpn(), new String[]{"\n"});
                                                }
                                                if (!x74.a1(standardV2RayBean.getCertificates())) {
                                                    tLSObject4.disableSystemRoot = Boolean.TRUE;
                                                    V2RayConfig.TLSObject.CertificateObject certificateObject = new V2RayConfig.TLSObject.CertificateObject();
                                                    certificateObject.usage = "verify";
                                                    List p1 = x74.p1(standardV2RayBean.getCertificates(), new String[]{"\n"});
                                                    ArrayList arrayList12 = new ArrayList();
                                                    Iterator it5 = p1.iterator();
                                                    while (true) {
                                                        str9 = str27;
                                                        if (it5.hasNext()) {
                                                            Object next2 = it5.next();
                                                            if (!x74.a1((String) next2)) {
                                                                arrayList12.add(next2);
                                                            }
                                                            str27 = str9;
                                                        } else {
                                                            certificateObject.certificate = arrayList12;
                                                            tLSObject4.certificates = zm2.c0(certificateObject);
                                                        }
                                                    }
                                                } else {
                                                    str9 = "packet";
                                                }
                                                if (!x74.a1(standardV2RayBean.getPinnedPeerCertificateChainSha256())) {
                                                    List p12 = x74.p1(standardV2RayBean.getPinnedPeerCertificateChainSha256(), new String[]{"\n"});
                                                    ArrayList arrayList13 = new ArrayList();
                                                    for (Object obj : p12) {
                                                        if (!x74.a1((String) obj)) {
                                                            arrayList13.add(obj);
                                                        }
                                                    }
                                                    tLSObject4.pinnedPeerCertificateChainSha256 = arrayList13;
                                                }
                                                if (standardV2RayBean.getAllowInsecure()) {
                                                    tLSObject4.allowInsecure = Boolean.TRUE;
                                                }
                                                streamSettingsObject3.tlsSettings = tLSObject4;
                                                str16 = streamSettingsObject3.network;
                                                if (str16 != null) {
                                                    int hashCode = str16.hashCode();
                                                    String str31 = ShortcutUtils.CAPABILITY_PARAM_SEPARATOR;
                                                    switch (hashCode) {
                                                        case 3804:
                                                            str10 = "xudp";
                                                            str17 = str13;
                                                            if (str16.equals(StandardV2RayBean.TYPE_WS)) {
                                                                V2RayConfig.WebSocketObject webSocketObject = new V2RayConfig.WebSocketObject();
                                                                webSocketObject.headers = new LinkedHashMap();
                                                                if (!x74.a1(standardV2RayBean.getHost())) {
                                                                    Map<String, String> map = webSocketObject.headers;
                                                                    zs4.n(map, "headers");
                                                                    map.put(HttpHeader.HOST, standardV2RayBean.getHost());
                                                                }
                                                                String path = standardV2RayBean.getPath();
                                                                if (!Boolean.valueOf(!x74.a1(path)).booleanValue()) {
                                                                    path = null;
                                                                }
                                                                if (path != null) {
                                                                    str31 = path;
                                                                }
                                                                webSocketObject.path = str31;
                                                                if (standardV2RayBean.getWsMaxEarlyData() > 0) {
                                                                    webSocketObject.maxEarlyData = Integer.valueOf(standardV2RayBean.getWsMaxEarlyData());
                                                                }
                                                                if (!x74.a1(standardV2RayBean.getEarlyDataHeaderName())) {
                                                                    webSocketObject.earlyDataHeaderName = standardV2RayBean.getEarlyDataHeaderName();
                                                                }
                                                                if (standardV2RayBean.getWsUseBrowserForwarder()) {
                                                                    webSocketObject.useBrowserForwarding = Boolean.TRUE;
                                                                    ref$BooleanRef.a = true;
                                                                }
                                                                streamSettingsObject3.wsSettings = webSocketObject;
                                                                break;
                                                            }
                                                            break;
                                                        case 106008:
                                                            str10 = "xudp";
                                                            str17 = str13;
                                                            if (str16.equals(StandardV2RayBean.TYPE_KCP)) {
                                                                V2RayConfig.KcpObject kcpObject = new V2RayConfig.KcpObject();
                                                                kcpObject.mtu = 1350;
                                                                kcpObject.tti = 50;
                                                                kcpObject.uplinkCapacity = 12;
                                                                kcpObject.downlinkCapacity = 100;
                                                                kcpObject.congestion = Boolean.FALSE;
                                                                kcpObject.readBufferSize = 1;
                                                                kcpObject.writeBufferSize = 1;
                                                                V2RayConfig.KcpObject.HeaderObject headerObject = new V2RayConfig.KcpObject.HeaderObject();
                                                                headerObject.type = standardV2RayBean.getHeaderType();
                                                                kcpObject.header = headerObject;
                                                                if (true ^ x74.a1(standardV2RayBean.getMKcpSeed())) {
                                                                    kcpObject.seed = standardV2RayBean.getMKcpSeed();
                                                                }
                                                                streamSettingsObject3.kcpSettings = kcpObject;
                                                            }
                                                            break;
                                                        case 114657:
                                                            if (str16.equals(StandardV2RayBean.TYPE_TCP)) {
                                                                V2RayConfig.TcpObject tcpObject = new V2RayConfig.TcpObject();
                                                                if (zs4.h(standardV2RayBean.getHeaderType(), "http")) {
                                                                    V2RayConfig.TcpObject.HeaderObject headerObject2 = new V2RayConfig.TcpObject.HeaderObject();
                                                                    headerObject2.type = "http";
                                                                    if ((!x74.a1(standardV2RayBean.getHost())) || (!x74.a1(standardV2RayBean.getPath()))) {
                                                                        V2RayConfig.TcpObject.HeaderObject.HTTPRequestObject hTTPRequestObject = new V2RayConfig.TcpObject.HeaderObject.HTTPRequestObject();
                                                                        hTTPRequestObject.headers = new LinkedHashMap();
                                                                        if (!x74.a1(standardV2RayBean.getHost())) {
                                                                            Map<String, V2RayConfig.TcpObject.HeaderObject.StringOrListObject> map2 = hTTPRequestObject.headers;
                                                                            zs4.n(map2, "headers");
                                                                            V2RayConfig.TcpObject.HeaderObject.StringOrListObject stringOrListObject = new V2RayConfig.TcpObject.HeaderObject.StringOrListObject();
                                                                            str10 = "xudp";
                                                                            List p13 = x74.p1(standardV2RayBean.getHost(), new String[]{","});
                                                                            str17 = str13;
                                                                            ?? arrayList14 = new ArrayList(q00.A0(p13, 10));
                                                                            Iterator it6 = p13.iterator();
                                                                            while (it6.hasNext()) {
                                                                                arrayList14.add(x74.D1((String) it6.next()).toString());
                                                                            }
                                                                            stringOrListObject.valueY = arrayList14;
                                                                            map2.put(HttpHeader.HOST, stringOrListObject);
                                                                        } else {
                                                                            str10 = "xudp";
                                                                            str17 = str13;
                                                                        }
                                                                        if (!x74.a1(standardV2RayBean.getPath())) {
                                                                            hTTPRequestObject.path = x74.p1(standardV2RayBean.getPath(), new String[]{","});
                                                                        }
                                                                        headerObject2.request = hTTPRequestObject;
                                                                    } else {
                                                                        str10 = "xudp";
                                                                        str17 = str13;
                                                                    }
                                                                    tcpObject.header = headerObject2;
                                                                } else {
                                                                    str10 = "xudp";
                                                                    str17 = str13;
                                                                }
                                                                streamSettingsObject3.tcpSettings = tcpObject;
                                                                break;
                                                            }
                                                            break;
                                                        case 3181598:
                                                            if (str16.equals(StandardV2RayBean.TYPE_GRPC)) {
                                                                V2RayConfig.GrpcObject grpcObject = new V2RayConfig.GrpcObject();
                                                                grpcObject.serviceName = standardV2RayBean.getGrpcServiceName();
                                                                if (!x74.a1(standardV2RayBean.getGrpcMode())) {
                                                                    grpcObject.mode = standardV2RayBean.getGrpcMode();
                                                                }
                                                                streamSettingsObject3.grpcSettings = grpcObject;
                                                                break;
                                                            }
                                                            break;
                                                        case 3213448:
                                                            if (str16.equals("http")) {
                                                                streamSettingsObject3.network = "http";
                                                                V2RayConfig.HttpObject httpObject = new V2RayConfig.HttpObject();
                                                                if (!x74.a1(standardV2RayBean.getHost())) {
                                                                    httpObject.host = x74.p1(standardV2RayBean.getHost(), new String[]{","});
                                                                }
                                                                String path2 = standardV2RayBean.getPath();
                                                                if (!Boolean.valueOf(!x74.a1(path2)).booleanValue()) {
                                                                    path2 = null;
                                                                }
                                                                if (path2 != null) {
                                                                    str31 = path2;
                                                                }
                                                                httpObject.path = str31;
                                                                streamSettingsObject3.httpSettings = httpObject;
                                                                break;
                                                            }
                                                            break;
                                                        case 3482174:
                                                            if (str16.equals(StandardV2RayBean.TYPE_QUIC)) {
                                                                V2RayConfig.QuicObject quicObject = new V2RayConfig.QuicObject();
                                                                String quicSecurity = standardV2RayBean.getQuicSecurity();
                                                                if (!Boolean.valueOf(!x74.a1(quicSecurity)).booleanValue()) {
                                                                    quicSecurity = null;
                                                                }
                                                                if (quicSecurity == null) {
                                                                    quicSecurity = "none";
                                                                }
                                                                quicObject.security = quicSecurity;
                                                                quicObject.key = standardV2RayBean.getQuicKey();
                                                                V2RayConfig.QuicObject.HeaderObject headerObject3 = new V2RayConfig.QuicObject.HeaderObject();
                                                                String headerType = standardV2RayBean.getHeaderType();
                                                                if (!Boolean.valueOf(!x74.a1(headerType)).booleanValue()) {
                                                                    headerType = null;
                                                                }
                                                                headerObject3.type = headerType != null ? headerType : "none";
                                                                quicObject.header = headerObject3;
                                                                streamSettingsObject3.quicSettings = quicObject;
                                                                break;
                                                            }
                                                            break;
                                                    }
                                                    if (z8) {
                                                        V2RayConfig.StreamSettingsObject.SockoptObject sockoptObject3 = new V2RayConfig.StreamSettingsObject.SockoptObject();
                                                        sockoptObject3.tcpKeepAliveInterval = Integer.valueOf(i2);
                                                        streamSettingsObject3.sockopt = sockoptObject3;
                                                    }
                                                    Unit unit7 = Unit.INSTANCE;
                                                    outboundObject5.streamSettings = streamSettingsObject3;
                                                    str11 = str17;
                                                }
                                                str10 = "xudp";
                                                str17 = str13;
                                                if (z8) {
                                                }
                                                Unit unit72 = Unit.INSTANCE;
                                                outboundObject5.streamSettings = streamSettingsObject3;
                                                str11 = str17;
                                            }
                                            str9 = "packet";
                                            str16 = streamSettingsObject3.network;
                                            if (str16 != null) {
                                            }
                                            str10 = "xudp";
                                            str17 = str13;
                                            if (z8) {
                                            }
                                            Unit unit722 = Unit.INSTANCE;
                                            outboundObject5.streamSettings = streamSettingsObject3;
                                            str11 = str17;
                                        }
                                    }
                                    outboundObject5.settings = lazyOutboundConfigurationObject;
                                    V2RayConfig.StreamSettingsObject streamSettingsObject32 = new V2RayConfig.StreamSettingsObject();
                                    standardV2RayBean = (StandardV2RayBean) requireBean;
                                    streamSettingsObject32.network = standardV2RayBean.getType();
                                    if (!x74.a1(standardV2RayBean.getSecurity())) {
                                    }
                                    str15 = streamSettingsObject32.security;
                                    if (!zs4.h(str15, StandardV2RayBean.SECURITY_XTLS)) {
                                    }
                                    str9 = "packet";
                                    str16 = streamSettingsObject32.network;
                                    if (str16 != null) {
                                    }
                                    str10 = "xudp";
                                    str17 = str13;
                                    if (z8) {
                                    }
                                    Unit unit7222 = Unit.INSTANCE;
                                    outboundObject5.streamSettings = streamSettingsObject32;
                                    str11 = str17;
                                } else {
                                    str9 = "packet";
                                    str10 = "xudp";
                                    str6 = str3;
                                    if ((requireBean instanceof ShadowsocksBean) || (requireBean instanceof ShadowsocksRBean)) {
                                        outboundObject5.protocol = "shadowsocks";
                                        V2RayConfig.ShadowsocksOutboundConfigurationObject shadowsocksOutboundConfigurationObject = new V2RayConfig.ShadowsocksOutboundConfigurationObject();
                                        V2RayConfig.ShadowsocksOutboundConfigurationObject.ServerObject serverObject5 = new V2RayConfig.ShadowsocksOutboundConfigurationObject.ServerObject();
                                        serverObject5.address = requireBean.serverAddress;
                                        serverObject5.port = requireBean.serverPort;
                                        boolean z13 = requireBean instanceof ShadowsocksBean;
                                        if (z13) {
                                            ShadowsocksBean shadowsocksBean = (ShadowsocksBean) requireBean;
                                            serverObject5.method = shadowsocksBean.getMethod();
                                            serverObject5.password = shadowsocksBean.getPassword();
                                            if (shadowsocksBean.getUot()) {
                                                serverObject5.uot = Boolean.TRUE;
                                            }
                                            if (shadowsocksBean.getExperimentReducedIvHeadEntropy()) {
                                                serverObject5.experimentReducedIvHeadEntropy = Boolean.TRUE;
                                            }
                                            if (shadowsocksBean.getEncryptedProtocolExtension()) {
                                                serverObject5.encryptedProtocolExtension = Boolean.TRUE;
                                            }
                                        } else if (requireBean instanceof ShadowsocksRBean) {
                                            ShadowsocksRBean shadowsocksRBean = (ShadowsocksRBean) requireBean;
                                            serverObject5.method = shadowsocksRBean.getMethod();
                                            serverObject5.password = shadowsocksRBean.getPassword();
                                        }
                                        shadowsocksOutboundConfigurationObject.servers = zm2.c0(serverObject5);
                                        if (z12) {
                                            V2RayConfig.StreamSettingsObject streamSettingsObject4 = new V2RayConfig.StreamSettingsObject();
                                            V2RayConfig.StreamSettingsObject.SockoptObject sockoptObject4 = new V2RayConfig.StreamSettingsObject.SockoptObject();
                                            sockoptObject4.tcpKeepAliveInterval = Integer.valueOf(tcpKeepAliveInterval);
                                            streamSettingsObject4.sockopt = sockoptObject4;
                                            outboundObject5.streamSettings = streamSettingsObject4;
                                        }
                                        if (requireBean instanceof ShadowsocksRBean) {
                                            shadowsocksOutboundConfigurationObject.plugin = "shadowsocksr";
                                            ShadowsocksRBean shadowsocksRBean2 = (ShadowsocksRBean) requireBean;
                                            shadowsocksOutboundConfigurationObject.pluginArgs = zm2.d0(jf2.o("--obfs=", shadowsocksRBean2.getObfs()), jf2.o("--obfs-param=", shadowsocksRBean2.getObfsParam()), jf2.o("--protocol=", shadowsocksRBean2.getProtocol()), jf2.o("--protocol-param=", shadowsocksRBean2.getProtocolParam()));
                                        } else if (z13) {
                                            ShadowsocksBean shadowsocksBean2 = (ShadowsocksBean) requireBean;
                                            if (!x74.a1(shadowsocksBean2.getPlugin())) {
                                                PluginConfiguration pluginConfiguration = new PluginConfiguration(shadowsocksBean2.getPlugin());
                                                try {
                                                    PluginManager.InitResult init = PluginManager.INSTANCE.init(pluginConfiguration);
                                                    if (init != null) {
                                                        String path3 = init.getPath();
                                                        PluginOptions options = init.getOptions();
                                                        shadowsocksOutboundConfigurationObject.plugin = path3;
                                                        shadowsocksOutboundConfigurationObject.pluginOpts = String.valueOf(options);
                                                        Unit unit8 = Unit.INSTANCE;
                                                    }
                                                } catch (PluginManager.PluginNotFoundException e) {
                                                    if (!da.E0(new String[]{"v2ray-plugin", "obfs-local"}, e.getPlugin())) {
                                                        throw e;
                                                    }
                                                    shadowsocksOutboundConfigurationObject.plugin = e.getPlugin();
                                                    shadowsocksOutboundConfigurationObject.pluginOpts = PluginConfiguration.getOptions$default(pluginConfiguration, null, null, 3, null).toString();
                                                }
                                            }
                                        }
                                        Unit unit9 = Unit.INSTANCE;
                                        outboundObject5.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, shadowsocksOutboundConfigurationObject);
                                    } else {
                                        boolean z14 = requireBean instanceof TrojanBean;
                                        if (z14 && !zs4.h(((TrojanBean) requireBean).getSecurity(), StandardV2RayBean.SECURITY_XTLS)) {
                                            outboundObject5.protocol = "trojan_sing";
                                            V2RayConfig.TrojanSingOutboundConfigurationObject trojanSingOutboundConfigurationObject = new V2RayConfig.TrojanSingOutboundConfigurationObject();
                                            trojanSingOutboundConfigurationObject.address = requireBean.serverAddress;
                                            trojanSingOutboundConfigurationObject.port = requireBean.serverPort;
                                            TrojanBean trojanBean = (TrojanBean) requireBean;
                                            trojanSingOutboundConfigurationObject.password = trojanBean.getPassword();
                                            if (!x74.a1(trojanBean.getSni())) {
                                                trojanSingOutboundConfigurationObject.serverName = trojanBean.getSni();
                                            }
                                            if (!x74.a1(trojanBean.getAlpn())) {
                                                trojanSingOutboundConfigurationObject.nextProtos = x74.p1(trojanBean.getAlpn(), new String[]{"\n"});
                                            }
                                            if (trojanBean.getAllowInsecure()) {
                                                trojanSingOutboundConfigurationObject.insecure = Boolean.TRUE;
                                            }
                                            Unit unit10 = Unit.INSTANCE;
                                            outboundObject5.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, trojanSingOutboundConfigurationObject);
                                        } else if (z14) {
                                            outboundObject5.protocol = "trojan";
                                            V2RayConfig.TrojanOutboundConfigurationObject trojanOutboundConfigurationObject = new V2RayConfig.TrojanOutboundConfigurationObject();
                                            V2RayConfig.TrojanOutboundConfigurationObject.ServerObject serverObject6 = new V2RayConfig.TrojanOutboundConfigurationObject.ServerObject();
                                            serverObject6.address = requireBean.serverAddress;
                                            serverObject6.port = requireBean.serverPort;
                                            TrojanBean trojanBean2 = (TrojanBean) requireBean;
                                            serverObject6.password = trojanBean2.getPassword();
                                            if (!x74.a1(trojanBean2.getFlow())) {
                                                str12 = trojanBean2.getFlow();
                                            } else {
                                                if (zs4.h(trojanBean2.getSecurity(), StandardV2RayBean.SECURITY_XTLS)) {
                                                    str12 = "xtls-rprx-direct";
                                                }
                                                trojanOutboundConfigurationObject.servers = zm2.c0(serverObject6);
                                                Unit unit11 = Unit.INSTANCE;
                                                outboundObject5.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, trojanOutboundConfigurationObject);
                                                streamSettingsObject = new V2RayConfig.StreamSettingsObject();
                                                streamSettingsObject.network = StandardV2RayBean.TYPE_TCP;
                                                if (zs4.h(trojanBean2.getSecurity(), StandardV2RayBean.SECURITY_XTLS)) {
                                                    streamSettingsObject.security = StandardV2RayBean.SECURITY_TLS;
                                                    V2RayConfig.TLSObject tLSObject5 = new V2RayConfig.TLSObject();
                                                    if (!x74.a1(trojanBean2.getSni())) {
                                                        tLSObject5.serverName = trojanBean2.getSni();
                                                    }
                                                    if (!x74.a1(trojanBean2.getAlpn())) {
                                                        tLSObject5.alpn = x74.p1(trojanBean2.getAlpn(), new String[]{"\n"});
                                                    }
                                                    streamSettingsObject.tlsSettings = tLSObject5;
                                                    if (trojanBean2.getAllowInsecure()) {
                                                        V2RayConfig.TLSObject tLSObject6 = streamSettingsObject.tlsSettings;
                                                        if (tLSObject6 == null) {
                                                            tLSObject6 = new V2RayConfig.TLSObject();
                                                        }
                                                        streamSettingsObject.tlsSettings = tLSObject6;
                                                        tLSObject6.allowInsecure = Boolean.TRUE;
                                                    }
                                                } else {
                                                    streamSettingsObject.security = trojanBean2.getSecurity();
                                                    V2RayConfig.TLSObject tLSObject7 = new V2RayConfig.TLSObject();
                                                    if (!x74.a1(trojanBean2.getSni())) {
                                                        tLSObject7.serverName = trojanBean2.getSni();
                                                    }
                                                    if (!x74.a1(trojanBean2.getAlpn())) {
                                                        tLSObject7.alpn = x74.p1(trojanBean2.getAlpn(), new String[]{"\n"});
                                                    }
                                                    streamSettingsObject.xtlsSettings = tLSObject7;
                                                }
                                                if (z12) {
                                                    sockoptObject = new V2RayConfig.StreamSettingsObject.SockoptObject();
                                                    sockoptObject.tcpKeepAliveInterval = Integer.valueOf(tcpKeepAliveInterval);
                                                    streamSettingsObject.sockopt = sockoptObject;
                                                }
                                                outboundObject5.streamSettings = streamSettingsObject;
                                            }
                                            serverObject6.flow = str12;
                                            trojanOutboundConfigurationObject.servers = zm2.c0(serverObject6);
                                            Unit unit112 = Unit.INSTANCE;
                                            outboundObject5.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, trojanOutboundConfigurationObject);
                                            streamSettingsObject = new V2RayConfig.StreamSettingsObject();
                                            streamSettingsObject.network = StandardV2RayBean.TYPE_TCP;
                                            if (zs4.h(trojanBean2.getSecurity(), StandardV2RayBean.SECURITY_XTLS)) {
                                            }
                                            if (z12) {
                                            }
                                            outboundObject5.streamSettings = streamSettingsObject;
                                        } else if (requireBean instanceof WireGuardBean) {
                                            outboundObject5.protocol = "wireguard";
                                            V2RayConfig.WireGuardOutbounzConfigurationObject wireGuardOutbounzConfigurationObject = new V2RayConfig.WireGuardOutbounzConfigurationObject();
                                            wireGuardOutbounzConfigurationObject.address = requireBean.finalAddress;
                                            wireGuardOutbounzConfigurationObject.port = Integer.valueOf(requireBean.finalPort);
                                            wireGuardOutbounzConfigurationObject.network = "udp";
                                            WireGuardBean wireGuardBean = (WireGuardBean) requireBean;
                                            wireGuardOutbounzConfigurationObject.localAddresses = x74.p1(wireGuardBean.getLocalAddress(), new String[]{"\n"});
                                            wireGuardOutbounzConfigurationObject.privateKey = wireGuardBean.getPrivateKey();
                                            wireGuardOutbounzConfigurationObject.peerPublicKey = wireGuardBean.getPeerPublicKey();
                                            wireGuardOutbounzConfigurationObject.preSharedKey = wireGuardBean.getPeerPreSharedKey();
                                            wireGuardOutbounzConfigurationObject.mtu = Integer.valueOf(wireGuardBean.getMtu());
                                            Unit unit12 = Unit.INSTANCE;
                                            outboundObject5.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, wireGuardOutbounzConfigurationObject);
                                            V2RayConfig.StreamSettingsObject streamSettingsObject5 = new V2RayConfig.StreamSettingsObject();
                                            if (z12) {
                                                V2RayConfig.StreamSettingsObject.SockoptObject sockoptObject5 = new V2RayConfig.StreamSettingsObject.SockoptObject();
                                                sockoptObject5.tcpKeepAliveInterval = Integer.valueOf(tcpKeepAliveInterval);
                                                streamSettingsObject5.sockopt = sockoptObject5;
                                            }
                                            outboundObject5.streamSettings = streamSettingsObject5;
                                            if (zs4.h(str, "AsIs")) {
                                                str11 = str5;
                                            }
                                        } else if (requireBean instanceof SSHBean) {
                                            outboundObject5.protocol = "ssh";
                                            V2RayConfig.SSHOutbountConfigurationObject sSHOutbountConfigurationObject = new V2RayConfig.SSHOutbountConfigurationObject();
                                            sSHOutbountConfigurationObject.address = requireBean.finalAddress;
                                            sSHOutbountConfigurationObject.port = Integer.valueOf(requireBean.finalPort);
                                            SSHBean sSHBean = (SSHBean) requireBean;
                                            sSHOutbountConfigurationObject.user = sSHBean.getUsername();
                                            if (sSHBean.getAuthType() == 2) {
                                                sSHOutbountConfigurationObject.privateKey = sSHBean.getPrivateKey();
                                                password = sSHBean.getPrivateKeyPassphrase();
                                            } else {
                                                password = sSHBean.getPassword();
                                            }
                                            sSHOutbountConfigurationObject.password = password;
                                            sSHOutbountConfigurationObject.publicKey = sSHBean.getPublicKey();
                                            Unit unit13 = Unit.INSTANCE;
                                            outboundObject5.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, sSHOutbountConfigurationObject);
                                            streamSettingsObject = new V2RayConfig.StreamSettingsObject();
                                            if (z12) {
                                                sockoptObject = new V2RayConfig.StreamSettingsObject.SockoptObject();
                                                sockoptObject.tcpKeepAliveInterval = Integer.valueOf(tcpKeepAliveInterval);
                                                streamSettingsObject.sockopt = sockoptObject;
                                            }
                                            outboundObject5.streamSettings = streamSettingsObject;
                                        }
                                    }
                                    str11 = str;
                                }
                            }
                            if ((z4 || i == 0) && proxyEntity2.needCoreMux()) {
                                DataStore dataStore = DataStore.INSTANCE;
                                if (dataStore.getEnableMux()) {
                                    V2RayConfig.OutboundObject.MuxObject muxObject = new V2RayConfig.OutboundObject.MuxObject();
                                    muxObject.enabled = Boolean.TRUE;
                                    muxObject.concurrency = Integer.valueOf(dataStore.getMuxConcurrency());
                                    if (requireBean instanceof StandardV2RayBean) {
                                        int packetEncoding3 = ((StandardV2RayBean) requireBean).getPacketEncoding();
                                        if (packetEncoding3 == 1) {
                                            str18 = str9;
                                        } else if (packetEncoding3 == 2) {
                                            str18 = str10;
                                        }
                                        muxObject.packetEncoding = str18;
                                    }
                                    Unit unit14 = Unit.INSTANCE;
                                    outboundObject5.mux = muxObject;
                                }
                            }
                            o = str28;
                        } else {
                            int mkPort = NetsKt.mkPort();
                            linkedHashMap2.put(Integer.valueOf(mkPort), proxyEntity3);
                            outboundObject5.protocol = TAG_SOCKS;
                            V2RayConfig.SocksOutboundConfigurationObject socksOutboundConfigurationObject2 = new V2RayConfig.SocksOutboundConfigurationObject();
                            V2RayConfig.SocksOutboundConfigurationObject.ServerObject serverObject7 = new V2RayConfig.SocksOutboundConfigurationObject.ServerObject();
                            serverObject7.address = "127.0.0.1";
                            serverObject7.port = Integer.valueOf(mkPort);
                            if (proxyEntity.needUoT()) {
                                socksOutboundConfigurationObject2.uot = Boolean.TRUE;
                            }
                            socksOutboundConfigurationObject2.servers = zm2.c0(serverObject7);
                            Unit unit15 = Unit.INSTANCE;
                            outboundObject5.settings = new V2RayConfig.LazyOutboundConfigurationObject(outboundObject5, socksOutboundConfigurationObject2);
                            str11 = zs4.h(str, "AsIs") ? "UseIP" : str;
                            str4 = "127.0.0.1";
                            linkedHashMap = linkedHashMap2;
                            i = i3;
                            str5 = "UseIP";
                            proxyEntity2 = proxyEntity3;
                            str6 = str3;
                        }
                        outboundObject5.tag = o;
                        outboundObject5.domainStrategy = str11;
                    }
                }
                if (proxyEntity3.needExternal()) {
                }
                outboundObject5.tag = o;
                outboundObject5.domainStrategy = str11;
            }
            if (z4 || i <= 0) {
                v2RayConfig2 = v2RayConfig;
                str7 = "field";
                outboundObject2 = outboundObject;
            } else if (z5) {
                v2RayConfig2 = v2RayConfig;
                outboundObject2 = outboundObject;
                List<V2RayConfig.RoutingObject.RuleObject> list4 = v2RayConfig2.routing.rules;
                V2RayConfig.RoutingObject.RuleObject ruleObject2 = new V2RayConfig.RoutingObject.RuleObject();
                str7 = "field";
                ruleObject2.type = str7;
                if (str24 == null) {
                    zs4.s0("pastInboundTag");
                    throw null;
                }
                ruleObject2.inboundTag = zm2.c0(str24);
                ruleObject2.outboundTag = o;
                if (zs4.h(outboundObject5.domainStrategy, "AsIs")) {
                    outboundObject5.domainStrategy = str5;
                }
                Unit unit16 = Unit.INSTANCE;
                list4.add(ruleObject2);
            } else {
                if (outboundObject == null) {
                    zs4.s0("pastOutbound");
                    throw null;
                }
                V2RayConfig.OutboundObject.ProxySettingsObject proxySettingsObject = new V2RayConfig.OutboundObject.ProxySettingsObject();
                proxySettingsObject.tag = o;
                proxySettingsObject.transportLayer = Boolean.TRUE;
                Unit unit17 = Unit.INSTANCE;
                outboundObject2 = outboundObject;
                outboundObject2.proxySettings = proxySettingsObject;
                v2RayConfig2 = v2RayConfig;
                str7 = "field";
            }
            if (!proxyEntity2.needExternal() || z4 || i == zm2.R(list)) {
                str8 = str2;
                String str32 = str4;
                if (requireBean.canMapping() && proxyEntity2.needExternal()) {
                    int mkPort2 = NetsKt.mkPort();
                    requireBean.finalAddress = str32;
                    requireBean.finalPort = mkPort2;
                    List<V2RayConfig.InboundObject> list5 = v2RayConfig2.inbounds;
                    V2RayConfig.InboundObject inboundObject = new V2RayConfig.InboundObject();
                    inboundObject.listen = str32;
                    inboundObject.port = Integer.valueOf(mkPort2);
                    inboundObject.tag = str8 + "-mapping-" + proxyEntity2.getId();
                    inboundObject.protocol = "dokodemo-door";
                    V2RayConfig.DokodemoDoorInboundConfigurationObject dokodemoDoorInboundConfigurationObject = new V2RayConfig.DokodemoDoorInboundConfigurationObject();
                    dokodemoDoorInboundConfigurationObject.address = requireBean.serverAddress;
                    dokodemoDoorInboundConfigurationObject.network = requireBean.network();
                    dokodemoDoorInboundConfigurationObject.port = requireBean.serverPort;
                    Unit unit18 = Unit.INSTANCE;
                    inboundObject.settings = new V2RayConfig.LazyInboundConfigurationObject(inboundObject, dokodemoDoorInboundConfigurationObject);
                    List<V2RayConfig.RoutingObject.RuleObject> list6 = v2RayConfig2.routing.rules;
                    V2RayConfig.RoutingObject.RuleObject ruleObject3 = new V2RayConfig.RoutingObject.RuleObject();
                    ruleObject3.type = str7;
                    ruleObject3.inboundTag = zm2.c0(inboundObject.tag);
                    ruleObject3.outboundTag = "direct";
                    list6.add(ruleObject3);
                    list5.add(inboundObject);
                }
                str21 = str24;
            } else {
                int mkPort3 = NetsKt.mkPort();
                String str33 = str4;
                requireBean.finalAddress = str33;
                requireBean.finalPort = mkPort3;
                requireBean.isChain = true;
                List<V2RayConfig.InboundObject> list7 = v2RayConfig2.inbounds;
                V2RayConfig.InboundObject inboundObject2 = new V2RayConfig.InboundObject();
                inboundObject2.listen = str33;
                inboundObject2.port = Integer.valueOf(mkPort3);
                long id2 = proxyEntity2.getId();
                StringBuilder sb2 = new StringBuilder();
                str8 = str2;
                sb2.append(str8);
                sb2.append("-mapping-");
                sb2.append(id2);
                inboundObject2.tag = sb2.toString();
                inboundObject2.protocol = "dokodemo-door";
                V2RayConfig.DokodemoDoorInboundConfigurationObject dokodemoDoorInboundConfigurationObject2 = new V2RayConfig.DokodemoDoorInboundConfigurationObject();
                dokodemoDoorInboundConfigurationObject2.address = requireBean.serverAddress;
                dokodemoDoorInboundConfigurationObject2.network = requireBean.network();
                dokodemoDoorInboundConfigurationObject2.port = requireBean.serverPort;
                Unit unit19 = Unit.INSTANCE;
                inboundObject2.settings = new V2RayConfig.LazyInboundConfigurationObject(inboundObject2, dokodemoDoorInboundConfigurationObject2);
                String str34 = inboundObject2.tag;
                zs4.n(str34, "tag");
                list7.add(inboundObject2);
                str21 = str34;
            }
            if (z7) {
                arrayList5 = arrayList8;
                outboundObject3 = outboundObject2;
                z10 = z5;
            } else {
                v2RayConfig2.outbounds.add(outboundObject5);
                arrayList5 = arrayList8;
                arrayList5.add(outboundObject5);
                z10 = proxyEntity2.needExternal();
                outboundObject3 = outboundObject5;
            }
            arrayList6 = arrayList2;
            z9 = z4;
            arrayList7 = arrayList5;
            v2RayConfig3 = v2RayConfig2;
            str19 = str8;
            str22 = str23;
            i3 = i4;
            it = it4;
            linkedHashMap2 = linkedHashMap;
            str20 = str6;
        }
    }

    private static final List<ProxyEntity> buildV2RayConfig$resolveChain(ProxyEntity proxyEntity) {
        List<ProxyEntity> byGroup;
        AbstractBean requireBean = proxyEntity.requireBean();
        int i = 16;
        if (requireBean instanceof ChainBean) {
            ChainBean chainBean = (ChainBean) requireBean;
            List<ProxyEntity> entities = ShadowsocksDatabase.INSTANCE.getProxyDao().getEntities(chainBean.getProxies());
            int J = an1.J(q00.A0(entities, 10));
            if (J >= 16) {
                i = J;
            }
            LinkedHashMap linkedHashMap = new LinkedHashMap(i);
            for (Object obj : entities) {
                linkedHashMap.put(Long.valueOf(((ProxyEntity) obj).getId()), obj);
            }
            ArrayList arrayList = new ArrayList();
            Iterator<Long> it = chainBean.getProxies().iterator();
            while (it.hasNext()) {
                ProxyEntity proxyEntity2 = (ProxyEntity) linkedHashMap.get(Long.valueOf(it.next().longValue()));
                if (proxyEntity2 != null) {
                    int type = proxyEntity2.getType();
                    if (type != 13) {
                        if (type != 14) {
                            arrayList.addAll(buildV2RayConfig$resolveChain(proxyEntity2));
                        } else {
                            throw new IllegalStateException("Balancer is incompatible with chain".toString());
                        }
                    } else {
                        throw new IllegalStateException("Custom config is incompatible with chain".toString());
                    }
                }
            }
            return new gk3(arrayList);
        }
        if (requireBean instanceof BalancerBean) {
            BalancerBean balancerBean = (BalancerBean) requireBean;
            if (balancerBean.getType() == 0) {
                byGroup = ShadowsocksDatabase.INSTANCE.getProxyDao().getEntities(balancerBean.getProxies());
            } else {
                byGroup = ShadowsocksDatabase.INSTANCE.getProxyDao().getByGroup(balancerBean.getGroupId());
            }
            int J2 = an1.J(q00.A0(byGroup, 10));
            if (J2 >= 16) {
                i = J2;
            }
            LinkedHashMap linkedHashMap2 = new LinkedHashMap(i);
            for (Object obj2 : byGroup) {
                linkedHashMap2.put(Long.valueOf(((ProxyEntity) obj2).getId()), obj2);
            }
            ArrayList arrayList2 = new ArrayList();
            Iterator it2 = linkedHashMap2.keySet().iterator();
            while (it2.hasNext()) {
                ProxyEntity proxyEntity3 = (ProxyEntity) linkedHashMap2.get(Long.valueOf(((Number) it2.next()).longValue()));
                if (proxyEntity3 != null && proxyEntity3.getId() != proxyEntity.getId()) {
                    int type2 = proxyEntity3.getType();
                    if (type2 != 8) {
                        if (type2 != 14) {
                            arrayList2.add(proxyEntity3);
                        } else {
                            throw new IllegalStateException("Nested balancers are not supported".toString());
                        }
                    } else {
                        throw new IllegalStateException("Chain is incompatible with balancer".toString());
                    }
                }
            }
            return arrayList2;
        }
        return zm2.f0(proxyEntity);
    }
}