2023-01-08 16:57:10 +00:00
|
|
|
|
using LinePutScript;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using VPet_Simulator.Core;
|
2023-04-01 19:31:28 +00:00
|
|
|
|
using VPet_Simulator.Windows.Interface;
|
2023-01-08 16:57:10 +00:00
|
|
|
|
|
|
|
|
|
namespace VPet_Simulator.Windows
|
|
|
|
|
{
|
|
|
|
|
public class CoreMOD
|
|
|
|
|
{
|
2023-04-01 19:31:28 +00:00
|
|
|
|
public static List<string> LoadedDLL { get; } = new List<string>()
|
|
|
|
|
{
|
|
|
|
|
"ChatGPT.API.Framework.dll","Panuon.WPF.dll","steam_api.dll","Panuon.WPF.UI.dll","steam_api64.dll",
|
|
|
|
|
"LinePutScript.dll","Newtonsoft.Json.dll","Facepunch.Steamworks.Win32.dll", "Facepunch.Steamworks.Win64.dll",
|
|
|
|
|
"VPet-Simulator.Core.dll","VPet-Simulator.Windows.Interface.dll"
|
|
|
|
|
};
|
2023-01-08 16:57:10 +00:00
|
|
|
|
public static string NowLoading = null;
|
|
|
|
|
public string Name;
|
|
|
|
|
public string Author;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 如果是上传至Steam,则为SteamUserID
|
|
|
|
|
/// </summary>
|
|
|
|
|
public long AuthorID;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上传至Steam的ItemID
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ulong ItemID;
|
|
|
|
|
public string Intro;
|
|
|
|
|
public DirectoryInfo Path;
|
|
|
|
|
public int GameVer;
|
|
|
|
|
public int Ver;
|
|
|
|
|
public string Content = "";
|
|
|
|
|
public bool SuccessLoad = true;
|
|
|
|
|
public static string INTtoVER(int ver) => $"{ver / 100}.{ver % 100:00}";
|
|
|
|
|
public CoreMOD(DirectoryInfo directory, MainWindow mw)
|
|
|
|
|
{
|
|
|
|
|
Path = directory;
|
|
|
|
|
LpsDocument modlps = new LpsDocument(File.ReadAllText(directory.FullName + @"\info.lps"));
|
|
|
|
|
Name = modlps.FindLine("vupmod").Info;
|
|
|
|
|
NowLoading = Name;
|
|
|
|
|
Intro = modlps.FindLine("intro").Info;
|
|
|
|
|
GameVer = modlps.FindSub("gamever").InfoToInt;
|
|
|
|
|
Ver = modlps.FindSub("ver").InfoToInt;
|
|
|
|
|
Author = modlps.FindSub("author").Info;
|
|
|
|
|
if (modlps.FindLine("authorid") != null)
|
|
|
|
|
AuthorID = modlps.FindLine("authorid").InfoToInt64;
|
|
|
|
|
else
|
|
|
|
|
AuthorID = 0;
|
|
|
|
|
if (modlps.FindLine("itemid") != null)
|
|
|
|
|
ItemID = Convert.ToUInt64(modlps.FindLine("itemid").info);
|
|
|
|
|
else
|
|
|
|
|
ItemID = 0;
|
|
|
|
|
if (IsBanMOD(mw))
|
|
|
|
|
{
|
|
|
|
|
Content = "该模组已停用";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (DirectoryInfo di in Path.EnumerateDirectories())
|
|
|
|
|
{
|
|
|
|
|
switch (di.Name.ToLower())
|
|
|
|
|
{
|
|
|
|
|
case "pet":
|
|
|
|
|
//宠物模型
|
|
|
|
|
Content += "宠物形象\n";
|
|
|
|
|
foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
|
|
|
|
|
{
|
|
|
|
|
LpsDocument lps = new LpsDocument(File.ReadAllText(fi.FullName));
|
|
|
|
|
if (lps.First().Name.ToLower() == "pet")
|
|
|
|
|
{
|
2023-01-10 10:43:32 +00:00
|
|
|
|
var name = lps.First().Info;
|
|
|
|
|
var p = mw.Pets.FirstOrDefault(x => x.Name == name);
|
|
|
|
|
if (p == null)
|
2023-01-20 07:08:28 +00:00
|
|
|
|
mw.Pets.Add(new PetLoader(lps, di));
|
2023-01-10 10:43:32 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
p.path.Add(di.FullName + "\\" + lps.First()["path"].Info);
|
2023-01-20 07:08:28 +00:00
|
|
|
|
p.Config.Set(lps);
|
2023-01-10 10:43:32 +00:00
|
|
|
|
}
|
2023-01-08 16:57:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2023-04-01 19:31:28 +00:00
|
|
|
|
case "plugin":
|
|
|
|
|
Content += "代码插件\n";
|
|
|
|
|
SuccessLoad = false;
|
|
|
|
|
if (!IsPassMOD(mw))
|
|
|
|
|
{//不是通过模组,不加载
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (FileInfo tmpfi in di.EnumerateFiles("*.dll"))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-04-03 18:11:12 +00:00
|
|
|
|
var path = tmpfi.Name;
|
2023-04-01 19:31:28 +00:00
|
|
|
|
if (LoadedDLL.Contains(path))
|
|
|
|
|
continue;
|
|
|
|
|
LoadedDLL.Add(path);
|
2023-04-03 18:11:12 +00:00
|
|
|
|
Assembly dll = Assembly.LoadFrom(tmpfi.FullName);
|
2023-04-01 19:31:28 +00:00
|
|
|
|
var v = dll.GetExportedTypes();
|
|
|
|
|
foreach (Type exportedType in v)
|
|
|
|
|
{
|
|
|
|
|
if (exportedType.BaseType == typeof(MainPlugin))
|
|
|
|
|
{
|
|
|
|
|
mw.Plugins.Add((MainPlugin)Activator.CreateInstance(exportedType, mw));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
SuccessLoad = true;
|
|
|
|
|
break;
|
2023-01-08 16:57:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public bool IsBanMOD(MainWindow mw) => mw.Set.IsBanMod(Name);
|
|
|
|
|
public bool IsPassMOD(MainWindow mw) => mw.Set.IsPassMOD(Name);
|
|
|
|
|
|
|
|
|
|
public void WriteFile()
|
|
|
|
|
{
|
|
|
|
|
LpsDocument modlps = new LpsDocument(File.ReadAllText(Path.FullName + @"\info.lps"));
|
|
|
|
|
modlps.FindLine("vupmod").Info = Name;
|
|
|
|
|
modlps.FindLine("intro").Info = Intro;
|
|
|
|
|
modlps.FindSub("gamever").InfoToInt = GameVer;
|
|
|
|
|
modlps.FindSub("ver").InfoToInt = Ver;
|
|
|
|
|
modlps.FindSub("author").Info = Author;
|
|
|
|
|
modlps.FindorAddLine("authorid").InfoToInt64 = AuthorID;
|
|
|
|
|
modlps.FindorAddLine("itemid").info = ItemID.ToString();
|
|
|
|
|
File.WriteAllText(Path.FullName + @"\info.lps", modlps.ToString());
|
2023-05-25 18:44:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static class ExtensionSetting
|
|
|
|
|
{
|
|
|
|
|
public static bool IsBanMod(this Setting t, string ModName)
|
|
|
|
|
{
|
|
|
|
|
var line = t.FindLine("banmod");
|
|
|
|
|
if (line == null)
|
|
|
|
|
return false;
|
|
|
|
|
return line.Find(ModName.ToLower()) != null;
|
|
|
|
|
}
|
|
|
|
|
public static bool IsPassMOD(this Setting t, string ModName)
|
|
|
|
|
{
|
|
|
|
|
var line = t.FindLine("passmod");
|
|
|
|
|
if (line == null)
|
|
|
|
|
return false;
|
|
|
|
|
return line.Find(ModName.ToLower()) != null;
|
|
|
|
|
}
|
|
|
|
|
public static bool IsMSGMOD(this Setting t, string ModName)
|
|
|
|
|
{
|
|
|
|
|
var line = t.FindorAddLine("msgmod");
|
|
|
|
|
if (line.GetBool(ModName))
|
|
|
|
|
return false;
|
|
|
|
|
line.SetBool(ModName, true);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
public static void BanMod(this Setting t, string ModName)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(ModName))
|
|
|
|
|
return;
|
|
|
|
|
t.FindorAddLine("banmod").AddorReplaceSub(new Sub(ModName.ToLower()));
|
|
|
|
|
}
|
|
|
|
|
public static void BanModRemove(this Setting t, string ModName)
|
|
|
|
|
{
|
|
|
|
|
t.FindorAddLine("banmod").Remove(ModName.ToLower());
|
|
|
|
|
}
|
|
|
|
|
public static void PassMod(this Setting t, string ModName)
|
|
|
|
|
{
|
|
|
|
|
t.FindorAddLine("passmod").AddorReplaceSub(new Sub(ModName.ToLower()));
|
|
|
|
|
}
|
|
|
|
|
public static void PassModRemove(this Setting t, string ModName)
|
|
|
|
|
{
|
|
|
|
|
t.FindorAddLine("passmod").Remove(ModName.ToLower());
|
2023-01-08 16:57:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|