添加证书验证容错

This commit is contained in:
ZouJin 2024-03-22 23:05:10 +08:00
parent 7dfb9952dd
commit faf789c139

View File

@ -82,202 +82,202 @@ namespace VPet_Simulator.Windows
try try
{ {
#endif #endif
Path = directory; Path = directory;
LpsDocument modlps = new LpsDocument(File.ReadAllText(directory.FullName + @"\info.lps")); LpsDocument modlps = new LpsDocument(File.ReadAllText(directory.FullName + @"\info.lps"));
Name = modlps.FindLine("vupmod").Info; Name = modlps.FindLine("vupmod").Info;
NowLoading = Name; NowLoading = Name;
Intro = modlps.FindLine("intro").Info; Intro = modlps.FindLine("intro").Info;
GameVer = modlps.FindSub("gamever").InfoToInt; GameVer = modlps.FindSub("gamever").InfoToInt;
Ver = modlps.FindSub("ver").InfoToInt; Ver = modlps.FindSub("ver").InfoToInt;
Author = modlps.FindSub("author").Info.Split('[').First(); Author = modlps.FindSub("author").Info.Split('[').First();
if (modlps.FindLine("authorid") != null) if (modlps.FindLine("authorid") != null)
AuthorID = modlps.FindLine("authorid").InfoToInt64; AuthorID = modlps.FindLine("authorid").InfoToInt64;
else else
AuthorID = 0; AuthorID = 0;
if (modlps.FindLine("itemid") != null) if (modlps.FindLine("itemid") != null)
ItemID = Convert.ToUInt64(modlps.FindLine("itemid").info); ItemID = Convert.ToUInt64(modlps.FindLine("itemid").info);
else else
ItemID = 0; ItemID = 0;
CacheDate = modlps.GetDateTime("cachedate", DateTime.MinValue); CacheDate = modlps.GetDateTime("cachedate", DateTime.MinValue);
//MOD未加载时支持翻译 //MOD未加载时支持翻译
foreach (var line in modlps.FindAllLine("lang")) foreach (var line in modlps.FindAllLine("lang"))
{
List<ILine> ls = new List<ILine>();
foreach (var sub in line)
{ {
ls.Add(new Line(sub.Name, sub.info)); List<ILine> ls = new List<ILine>();
foreach (var sub in line)
{
ls.Add(new Line(sub.Name, sub.info));
}
LocalizeCore.AddCulture(line.info, ls);
} }
LocalizeCore.AddCulture(line.info, ls);
}
if (mw.CoreMODs.FirstOrDefault(x => x.Name == Name) != null) if (mw.CoreMODs.FirstOrDefault(x => x.Name == Name) != null)
{
Name += $"({"MOD名称重复".Translate()})";
ErrorMessage = "MOD名称重复".Translate();
return;
}
if (!IsOnMOD(mw))
{
Tag.Add("该模组已停用");
foreach (DirectoryInfo di in Path.EnumerateDirectories())
Tag.Add(di.Name.ToLower());
return;
}
foreach (DirectoryInfo di in Path.EnumerateDirectories())
{
switch (di.Name.ToLower())
{ {
case "theme": Name += $"({"MOD名称重复".Translate()})";
Tag.Add("theme"); ErrorMessage = "MOD名称重复".Translate();
if (Directory.Exists(di.FullName + @"\fonts")) return;
foreach (var str in Directory.EnumerateFiles(di.FullName + @"\fonts", "*.ttf")) }
{
mw.Fonts.Add(new IFont(new FileInfo(str)));
}
foreach (FileInfo fi in di.EnumerateFiles("*.lps")) if (!IsOnMOD(mw))
{ {
var tmp = new Theme(new LpsDocument(File.ReadAllText(fi.FullName))); Tag.Add("该模组已停用");
var oldtheme = mw.Themes.Find(x => x.xName == tmp.xName); foreach (DirectoryInfo di in Path.EnumerateDirectories())
if (oldtheme != null) Tag.Add(di.Name.ToLower());
mw.Themes.Remove(oldtheme); return;
mw.Themes.Add(tmp); }
//加载图片包
DirectoryInfo tmpdi = new DirectoryInfo(di.FullName + '\\' + tmp.Image); foreach (DirectoryInfo di in Path.EnumerateDirectories())
if (tmpdi.Exists) {
{ switch (di.Name.ToLower())
foreach (FileInfo tmpfi in tmpdi.EnumerateFiles("*.png")) {
case "theme":
Tag.Add("theme");
if (Directory.Exists(di.FullName + @"\fonts"))
foreach (var str in Directory.EnumerateFiles(di.FullName + @"\fonts", "*.ttf"))
{ {
tmp.Images.AddSource(tmpfi.Name.ToLower().Substring(0, tmpfi.Name.Length - 4), tmpfi.FullName); mw.Fonts.Add(new IFont(new FileInfo(str)));
} }
foreach (DirectoryInfo fordi in tmpdi.EnumerateDirectories())
foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
{
var tmp = new Theme(new LpsDocument(File.ReadAllText(fi.FullName)));
var oldtheme = mw.Themes.Find(x => x.xName == tmp.xName);
if (oldtheme != null)
mw.Themes.Remove(oldtheme);
mw.Themes.Add(tmp);
//加载图片包
DirectoryInfo tmpdi = new DirectoryInfo(di.FullName + '\\' + tmp.Image);
if (tmpdi.Exists)
{ {
foreach (FileInfo tmpfi in fordi.EnumerateFiles("*.png")) foreach (FileInfo tmpfi in tmpdi.EnumerateFiles("*.png"))
{ {
tmp.Images.AddSource(fordi.Name + '_' + tmpfi.Name.ToLower().Substring(0, tmpfi.Name.Length - 4), tmpfi.FullName); tmp.Images.AddSource(tmpfi.Name.ToLower().Substring(0, tmpfi.Name.Length - 4), tmpfi.FullName);
}
foreach (DirectoryInfo fordi in tmpdi.EnumerateDirectories())
{
foreach (FileInfo tmpfi in fordi.EnumerateFiles("*.png"))
{
tmp.Images.AddSource(fordi.Name + '_' + tmpfi.Name.ToLower().Substring(0, tmpfi.Name.Length - 4), tmpfi.FullName);
}
} }
} }
} }
} break;
break; case "pet":
case "pet": //宠物模型
//宠物模型 foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
{
LpsDocument lps = new LpsDocument(File.ReadAllText(fi.FullName));
if (lps.First().Name.ToLower() == "pet")
{ {
var name = lps.First().Info; LpsDocument lps = new LpsDocument(File.ReadAllText(fi.FullName));
if (name == "默认虚拟桌宠") if (lps.First().Name.ToLower() == "pet")
name = "vup";//旧版本名称兼容 {
var name = lps.First().Info;
if (name == "默认虚拟桌宠")
name = "vup";//旧版本名称兼容
var p = mw.Pets.FirstOrDefault(x => x.Name == name); var p = mw.Pets.FirstOrDefault(x => x.Name == name);
if (p == null) if (p == null)
{
Tag.Add("pet");
p = new PetLoader(lps, di);
if (p.Config.Works.Count > 0)
Tag.Add("work");
mw.Pets.Add(p);
}
else
{
if (lps.FindAllLine("work").Length >= 0)
{ {
Tag.Add("work");
}
var dis = new DirectoryInfo(di.FullName + "\\" + lps.First()["path"].Info);
if (dis.Exists && dis.GetDirectories().Length > 0)
Tag.Add("pet"); Tag.Add("pet");
p.path.Add(di.FullName + "\\" + lps.First()["path"].Info); p = new PetLoader(lps, di);
p.Config.Set(lps); if (p.Config.Works.Count > 0)
Tag.Add("work");
mw.Pets.Add(p);
}
else
{
if (lps.FindAllLine("work").Length >= 0)
{
Tag.Add("work");
}
var dis = new DirectoryInfo(di.FullName + "\\" + lps.First()["path"].Info);
if (dis.Exists && dis.GetDirectories().Length > 0)
Tag.Add("pet");
p.path.Add(di.FullName + "\\" + lps.First()["path"].Info);
p.Config.Set(lps);
}
} }
} }
} break;
break; case "food":
case "food": Tag.Add("food");
Tag.Add("food"); foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
{
var tmp = new LpsDocument(File.ReadAllText(fi.FullName));
foreach (ILine li in tmp)
{ {
if (li.Name != "food") var tmp = new LpsDocument(File.ReadAllText(fi.FullName));
continue; foreach (ILine li in tmp)
string tmps = li.Find("name").info;
mw.Foods.RemoveAll(x => x.Name == tmps);
mw.Foods.Add(LPSConvert.DeserializeObject<Food>(li));
}
}
break;
case "image":
Tag.Add("image");
LoadImage(mw, di);
break;
case "text":
Tag.Add("text");
foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
{
var tmp = new LpsDocument(File.ReadAllText(fi.FullName));
foreach (ILine li in tmp)
{
switch (li.Name.ToLower())
{ {
case "lowfoodtext": if (li.Name != "food")
mw.LowFoodText.Add(LPSConvert.DeserializeObject<LowText>(li)); continue;
Tag.Add("lowtext"); string tmps = li.Find("name").info;
break; mw.Foods.RemoveAll(x => x.Name == tmps);
case "lowdrinktext": mw.Foods.Add(LPSConvert.DeserializeObject<Food>(li));
mw.LowDrinkText.Add(LPSConvert.DeserializeObject<LowText>(li));
Tag.Add("lowtext");
break;
case "clicktext":
mw.ClickTexts.Add(LPSConvert.DeserializeObject<ClickText>(li));
Tag.Add("clicktext");
break;
case "selecttext":
mw.SelectTexts.Add(LPSConvert.DeserializeObject<SelectText>(li));
Tag.Add("selecttext");
break;
} }
} }
} break;
break; case "image":
case "lang": Tag.Add("image");
Tag.Add("lang"); LoadImage(mw, di);
foreach (FileInfo fi in di.EnumerateFiles("*.lps")) break;
{ case "text":
LocalizeCore.AddCulture(fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length), new LPS_D(File.ReadAllText(fi.FullName))); Tag.Add("text");
} foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
foreach (DirectoryInfo dis in di.EnumerateDirectories())
{
foreach (FileInfo fi in dis.EnumerateFiles("*.lps"))
{ {
LocalizeCore.AddCulture(dis.Name, new LPS_D(File.ReadAllText(fi.FullName))); var tmp = new LpsDocument(File.ReadAllText(fi.FullName));
foreach (ILine li in tmp)
{
switch (li.Name.ToLower())
{
case "lowfoodtext":
mw.LowFoodText.Add(LPSConvert.DeserializeObject<LowText>(li));
Tag.Add("lowtext");
break;
case "lowdrinktext":
mw.LowDrinkText.Add(LPSConvert.DeserializeObject<LowText>(li));
Tag.Add("lowtext");
break;
case "clicktext":
mw.ClickTexts.Add(LPSConvert.DeserializeObject<ClickText>(li));
Tag.Add("clicktext");
break;
case "selecttext":
mw.SelectTexts.Add(LPSConvert.DeserializeObject<SelectText>(li));
Tag.Add("selecttext");
break;
}
}
}
break;
case "lang":
Tag.Add("lang");
foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
{
LocalizeCore.AddCulture(fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length), new LPS_D(File.ReadAllText(fi.FullName)));
}
foreach (DirectoryInfo dis in di.EnumerateDirectories())
{
foreach (FileInfo fi in dis.EnumerateFiles("*.lps"))
{
LocalizeCore.AddCulture(dis.Name, new LPS_D(File.ReadAllText(fi.FullName)));
}
} }
}
if (mw.Set.Language == "null") if (mw.Set.Language == "null")
{
LocalizeCore.LoadDefaultCulture();
}
else
LocalizeCore.LoadCulture(mw.Set.Language);
break;
case "plugin":
Tag.Add("plugin");
SuccessLoad = true;
string authtype = "";
foreach (FileInfo tmpfi in di.EnumerateFiles("*.dll"))
{
#if X64
if (tmpfi.Name.Contains("x86"))
{ {
continue; LocalizeCore.LoadDefaultCulture();
} }
else
LocalizeCore.LoadCulture(mw.Set.Language);
break;
case "plugin":
Tag.Add("plugin");
SuccessLoad = true;
string authtype = "";
foreach (FileInfo tmpfi in di.EnumerateFiles("*.dll"))
{
#if X64
if (tmpfi.Name.Contains("x86"))
{
continue;
}
#else #else
if (tmpfi.Name.Contains("x64")) if (tmpfi.Name.Contains("x64"))
{ {
@ -285,65 +285,68 @@ namespace VPet_Simulator.Windows
} }
#endif #endif
try try
{ {
var path = tmpfi.Name; var path = tmpfi.Name;
if (LoadedDLL.Contains(path)) if (LoadedDLL.Contains(path))
continue;
LoadedDLL.Add(path);
X509Certificate2 certificate = new X509Certificate2(tmpfi.FullName);
if (certificate != null)
{
if (certificate.Subject == "CN=\"Shenzhen Lingban Computer Technology Co., Ltd.\", O=\"Shenzhen Lingban Computer Technology Co., Ltd.\", L=Shenzhen, S=Guangdong Province, C=CN, SERIALNUMBER=91440300MA5H8REU3K, OID.2.5.4.15=Private Organization, OID.1.3.6.1.4.1.311.60.2.1.1=Shenzhen, OID.1.3.6.1.4.1.311.60.2.1.2=Guangdong Province, OID.1.3.6.1.4.1.311.60.2.1.3=CN"
&& certificate.Issuer == "CN=DigiCert Trusted G4 Code Signing RSA4096 SHA384 2021 CA1, O=\"DigiCert, Inc.\", C=US")
{//LBGame 信任的证书
if (authtype != "FAIL")
authtype = "[认证]".Translate();
}
else if (certificate.Subject != "CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" && !IsPassMOD(mw))
{//不是通过模组,不加载
SuccessLoad = false;
continue; continue;
} LoadedDLL.Add(path);
else if (authtype != "") X509Certificate2 certificate;
try
{ {
authtype = "[签名]".Translate(); certificate = new X509Certificate2(tmpfi.FullName);
//Intro += $"\nSubject:{certificate.Subject}\nIssuer:{certificate.Subject}";
} }
} catch
else
{
authtype = "FAIL";
if (!IsPassMOD(mw))
{//不是通过模组,不加载
SuccessLoad = false;
Author = modlps.FindSub("author").Info.Split('[').First();
continue;
}
}
Assembly dll = Assembly.LoadFrom(tmpfi.FullName);
var v = dll.GetExportedTypes();
foreach (Type exportedType in v)
{
if (exportedType.BaseType == typeof(MainPlugin))
{ {
mw.Plugins.Add((MainPlugin)Activator.CreateInstance(exportedType, mw)); certificate = null;
}
if (certificate != null)
{
if (certificate.Subject == "CN=\"Shenzhen Lingban Computer Technology Co., Ltd.\", O=\"Shenzhen Lingban Computer Technology Co., Ltd.\", L=Shenzhen, S=Guangdong Province, C=CN, SERIALNUMBER=91440300MA5H8REU3K, OID.2.5.4.15=Private Organization, OID.1.3.6.1.4.1.311.60.2.1.1=Shenzhen, OID.1.3.6.1.4.1.311.60.2.1.2=Guangdong Province, OID.1.3.6.1.4.1.311.60.2.1.3=CN"
&& certificate.Issuer == "CN=DigiCert Trusted G4 Code Signing RSA4096 SHA384 2021 CA1, O=\"DigiCert, Inc.\", C=US")
{//LBGame 信任的证书
if (authtype != "FAIL")
authtype = "[认证]".Translate();
}
else if (certificate.Subject != "CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" && !IsPassMOD(mw))
{//不是通过模组,不加载
SuccessLoad = false;
continue;
}
}
else
{
authtype = "FAIL";
if (!IsPassMOD(mw))
{//不是通过模组,不加载
SuccessLoad = false;
Author = modlps.FindSub("author").Info.Split('[').First();
continue;
}
}
Assembly dll = Assembly.LoadFrom(tmpfi.FullName);
var v = dll.GetExportedTypes();
foreach (Type exportedType in v)
{
if (exportedType.BaseType == typeof(MainPlugin))
{
mw.Plugins.Add((MainPlugin)Activator.CreateInstance(exportedType, mw));
}
} }
}
}
catch (Exception e)
{
ErrorMessage = e.Message;
SuccessLoad = false;
}
} }
catch (Exception e) if (authtype != "FAIL")
{ Author += authtype;
ErrorMessage = e.Message; break;
SuccessLoad = false; }
}
}
if (authtype != "FAIL")
Author += authtype;
break;
} }
}
#if !DEBUG #if !DEBUG
} }
catch (Exception e) catch (Exception e)