Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions v2rayN/ServiceLib/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ public static string GetFontsPath(string filename = "")
}
}

public static string GetBinConfigPath(string filename = "")
public static string GetBinConfigPath(string filename = "", ECoreType coreType = ECoreType.v2rayN)
{
var tempPath = Path.Combine(StartupPath(), "binConfigs");
if (!Directory.Exists(tempPath))
Expand All @@ -827,10 +827,27 @@ public static string GetBinConfigPath(string filename = "")
}
else
{
return Path.Combine(tempPath, filename);
return Path.Combine(tempPath, GetBinConfigFileName(filename, coreType));
}
}

public static string GetBinConfigFileName(string filename, ECoreType coreType = ECoreType.v2rayN)
{
var fileSuffix = coreType switch
{
ECoreType.sing_box => ".json",
ECoreType.Xray => ".json",
ECoreType.hysteria2 => ".json",
ECoreType.naiveproxy => ".json",
ECoreType.tuic => ".json",
ECoreType.juicity => ".json",
ECoreType.brook => ".cac",
ECoreType.shadowquic => ".yaml",
_ => string.Empty
};
return filename.EndsWith(fileSuffix) ? filename : $"{filename}{fileSuffix}";
}

#endregion TempPath

#region Platform
Expand Down
6 changes: 5 additions & 1 deletion v2rayN/ServiceLib/Enums/EConfigType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ public enum EConfigType
TUIC = 8,
WireGuard = 9,
HTTP = 10,
Anytls = 11
Anytls = 11,
NaiveProxy = 100,
Juicity = 101,
Brook = 102,
Shadowquic = 103,
}
1 change: 1 addition & 0 deletions v2rayN/ServiceLib/Enums/EInboundProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public enum EInboundProtocol
api,
api2,
mixed,
split,
speedtest = 21
}
94 changes: 89 additions & 5 deletions v2rayN/ServiceLib/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class Global

public const string PromotionUrl = @"aHR0cHM6Ly85LjIzNDQ1Ni54eXovYWJjLmh0bWw=";
public const string ConfigFileName = "guiNConfig.json";
public const string CoreConfigFileName = "config.json";
public const string CorePreConfigFileName = "configPre.json";
public const string CoreConfigFileName = "config";
public const string CorePreConfigFileName = "configPre";
public const string CoreSpeedtestConfigFileName = "configTest{0}.json";
public const string CoreMultipleLoadConfigFileName = "configMultipleLoad.json";
public const string ClashMixinConfigFileName = "Mixin.yaml";
Expand Down Expand Up @@ -170,7 +170,11 @@ public class Global
{ EConfigType.Hysteria2, "hysteria2://" },
{ EConfigType.TUIC, "tuic://" },
{ EConfigType.WireGuard, "wireguard://" },
{ EConfigType.Anytls, "anytls://" }
{ EConfigType.Anytls, "anytls://" },
{ EConfigType.NaiveProxy, "naive://" },
{ EConfigType.Juicity, "juicity://" },
{ EConfigType.Brook, "brook://" },
{ EConfigType.Shadowquic, "shadowquic://" }
};

public static readonly Dictionary<EConfigType, string> ProtocolTypes = new()
Expand All @@ -184,7 +188,11 @@ public class Global
{ EConfigType.Hysteria2, "hysteria2" },
{ EConfigType.TUIC, "tuic" },
{ EConfigType.WireGuard, "wireguard" },
{ EConfigType.Anytls, "anytls" }
{ EConfigType.Anytls, "anytls" },
{ EConfigType.NaiveProxy, "naiveproxy" },
{ EConfigType.Juicity, "juicity" },
{ EConfigType.Brook, "brook" },
{ EConfigType.Shadowquic, "shadowquic" }
};

public static readonly List<string> VmessSecurities =
Expand Down Expand Up @@ -278,6 +286,75 @@ public class Global
"sing_box"
];

public static readonly List<string> Hysteria2CoreTypes =
[
"sing_box",
"hysteria2"
];

public static readonly List<string> TuicCoreTypes =
[
"sing_box",
"tuic"
];

public static readonly List<string> NaiveProxyCoreTypes =
[
"naiveproxy"
];

public static readonly List<string> JuicityProxyCoreTypes =
[
"juicity"
];

public static readonly List<string> BrookCoreTypes =
[
"brook"
];

public static readonly List<string> ShadowquicCoreTypes =
[
"shadowquic"
];

public static readonly List<EConfigType> SupportSplitConfigTypes =
[
EConfigType.VMess,
EConfigType.VLESS,
EConfigType.Shadowsocks,
EConfigType.Trojan,
EConfigType.Hysteria2,
EConfigType.TUIC,
EConfigType.WireGuard,
EConfigType.SOCKS,
];

public static readonly HashSet<EConfigType> XraySupportConfigType =
[
EConfigType.VMess,
EConfigType.VLESS,
EConfigType.Shadowsocks,
EConfigType.Trojan,
EConfigType.WireGuard,
EConfigType.SOCKS,
EConfigType.HTTP,
];

public static readonly HashSet<EConfigType> SingboxSupportConfigType =
[
EConfigType.VMess,
EConfigType.VLESS,
EConfigType.Shadowsocks,
EConfigType.Trojan,
EConfigType.Hysteria2,
EConfigType.TUIC,
EConfigType.Anytls,
EConfigType.WireGuard,
EConfigType.SOCKS,
EConfigType.HTTP,
];

public static readonly List<string> DomainStrategies =
[
"AsIs",
Expand Down Expand Up @@ -464,13 +541,20 @@ public class Global
""
];

public static readonly List<string> TuicCongestionControls =
public static readonly List<string> CongestionControls =
[
"cubic",
"new_reno",
"bbr"
];

public static readonly List<string> NaiveProxyProtocols =
[
"https",
"http",
"quic"
];

public static readonly List<string> allowSelectType =
[
"selector",
Expand Down
84 changes: 84 additions & 0 deletions v2rayN/ServiceLib/Handler/AppHandler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
using DynamicData;
using ServiceLib.Enums;
using ServiceLib.Models;

namespace ServiceLib.Handler;

public sealed class AppHandler
Expand Down Expand Up @@ -231,9 +235,89 @@ public ECoreType GetCoreType(ProfileItem profileItem, EConfigType eConfigType)
return (ECoreType)profileItem.CoreType;
}

return GetCoreType(eConfigType);
}

public ECoreType GetCoreType(EConfigType eConfigType)
{
var item = _config.CoreTypeItem?.FirstOrDefault(it => it.ConfigType == eConfigType);
return item?.CoreType ?? ECoreType.Xray;
}

public ECoreType GetSplitCoreType(ProfileItem profileItem, EConfigType eConfigType)
{
if (profileItem?.CoreType != null)
{
return (ECoreType)profileItem.CoreType;
}

return GetSplitCoreType(eConfigType);
}

public ECoreType GetSplitCoreType(EConfigType eConfigType)
{
var item = _config.SplitCoreItem.SplitCoreTypes?.FirstOrDefault(it => it.ConfigType == eConfigType);
return item?.CoreType ?? ECoreType.Xray;
}

public (bool, ECoreType, ECoreType?) GetCoreAndPreType(ProfileItem profileItem)
{
var splitCore = _config.SplitCoreItem.EnableSplitCore;
var coreType = GetCoreType(profileItem, profileItem.ConfigType);
ECoreType? preCoreType = null;

var pureEndpointCore = profileItem.CoreType ?? GetSplitCoreType(profileItem, profileItem.ConfigType);
var splitRouteCore = _config.SplitCoreItem.RouteCoreType;
var enableTun = _config.TunModeItem.EnableTun;

if (profileItem.ConfigType == EConfigType.Custom)
{
splitCore = false;
coreType = profileItem.CoreType ?? ECoreType.Xray;
if (profileItem.PreSocksPort > 0)
{
preCoreType = enableTun ? ECoreType.sing_box : GetCoreType(profileItem.ConfigType);
}
else
{
preCoreType = null;
}
}
else if (!splitCore && profileItem.CoreType is not (ECoreType.Xray or ECoreType.sing_box))
{
// Force SplitCore for cores that don't support direct routing (like Hysteria2, TUIC, etc.)
splitCore = true;
preCoreType = enableTun ? ECoreType.sing_box : splitRouteCore;
}
else if (splitCore)
{
// User explicitly enabled SplitCore
preCoreType = enableTun ? ECoreType.sing_box : splitRouteCore;
coreType = pureEndpointCore;

if (preCoreType == coreType)
{
preCoreType = null;
splitCore = false;
}
}
else if (enableTun) // EnableTun is true but SplitCore is false
{
// TUN mode handling for Xray/sing_box cores
preCoreType = ECoreType.sing_box;

if (preCoreType == coreType) // CoreType is sing_box
{
preCoreType = null;
}
else // CoreType is xray, etc.
{
// Force SplitCore for non-split cores
splitCore = true;
}
}
return (splitCore, coreType, preCoreType);
}

#endregion Core Type
}
Loading