2024-03-30 07:00:02 +00:00
|
|
|
|
using LinePutScript;
|
|
|
|
|
using LinePutScript.Dictionary;
|
|
|
|
|
using LinePutScript.Localization.WPF;
|
|
|
|
|
using Panuon.WPF.UI;
|
|
|
|
|
using Steamworks;
|
|
|
|
|
using Steamworks.Data;
|
2022-12-22 08:13:05 +00:00
|
|
|
|
using System;
|
2022-12-13 07:10:18 +00:00
|
|
|
|
using System.Collections.Generic;
|
2024-03-30 07:00:02 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Globalization;
|
2022-12-13 07:10:18 +00:00
|
|
|
|
using System.IO;
|
2024-03-30 07:00:02 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2022-12-13 07:10:18 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-03-30 07:00:02 +00:00
|
|
|
|
using System.Timers;
|
2022-12-13 07:10:18 +00:00
|
|
|
|
using System.Windows;
|
2024-03-30 07:00:02 +00:00
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Interop;
|
2022-12-13 07:10:18 +00:00
|
|
|
|
using VPet_Simulator.Core;
|
2023-04-01 15:15:50 +00:00
|
|
|
|
using VPet_Simulator.Windows.Interface;
|
2024-03-30 07:00:02 +00:00
|
|
|
|
using static VPet_Simulator.Core.GraphInfo;
|
2023-07-03 11:41:16 +00:00
|
|
|
|
using static VPet_Simulator.Windows.PerformanceDesktopTransparentWindow;
|
2023-07-13 13:43:09 +00:00
|
|
|
|
using Line = LinePutScript.Line;
|
2022-12-13 07:10:18 +00:00
|
|
|
|
|
|
|
|
|
namespace VPet_Simulator.Windows
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// MainWindow.xaml 的交互逻辑
|
|
|
|
|
/// </summary>
|
2023-04-01 15:15:50 +00:00
|
|
|
|
public partial class MainWindow : WindowX
|
2022-12-13 07:10:18 +00:00
|
|
|
|
{
|
2024-03-16 11:22:07 +00:00
|
|
|
|
private System.Windows.Forms.NotifyIcon notifyIcon;
|
2023-07-03 11:41:16 +00:00
|
|
|
|
public PetHelper petHelper;
|
2023-01-24 06:56:16 +00:00
|
|
|
|
public System.Timers.Timer AutoSaveTimer = new System.Timers.Timer();
|
2023-10-10 13:04:22 +00:00
|
|
|
|
|
2022-12-13 07:10:18 +00:00
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
2023-10-10 13:04:22 +00:00
|
|
|
|
//处理ARGS
|
|
|
|
|
Args = new LPS_D();
|
|
|
|
|
foreach (var str in App.Args)
|
|
|
|
|
{
|
|
|
|
|
Args.Add(new Line(str));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//存档前缀
|
|
|
|
|
if (Args.ContainsLine("prefix"))
|
2023-10-11 17:24:35 +00:00
|
|
|
|
{
|
2023-10-10 17:03:23 +00:00
|
|
|
|
PrefixSave = '-' + Args["prefix"].Info;
|
2023-10-11 17:24:35 +00:00
|
|
|
|
}
|
2023-11-14 12:33:44 +00:00
|
|
|
|
|
2023-08-31 16:05:07 +00:00
|
|
|
|
#if X64
|
2024-03-29 15:33:24 +00:00
|
|
|
|
PNGAnimation.MaxLoadNumber = 100;
|
2023-08-31 16:05:07 +00:00
|
|
|
|
#else
|
2024-03-29 15:33:24 +00:00
|
|
|
|
PNGAnimation.MaxLoadNumber = 50;
|
2023-08-31 16:05:07 +00:00
|
|
|
|
#endif
|
2023-09-10 14:03:47 +00:00
|
|
|
|
ExtensionValue.BaseDirectory = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName;
|
2023-08-31 16:05:07 +00:00
|
|
|
|
|
2023-07-01 07:46:08 +00:00
|
|
|
|
LocalizeCore.StoreTranslation = true;
|
2023-08-14 18:30:36 +00:00
|
|
|
|
CultureInfo.CurrentCulture = new CultureInfo(CultureInfo.CurrentCulture.Name);
|
|
|
|
|
CultureInfo.CurrentCulture.NumberFormat = new CultureInfo("en-US").NumberFormat;
|
2023-10-10 13:04:22 +00:00
|
|
|
|
|
2022-12-22 08:13:05 +00:00
|
|
|
|
//判断是不是Steam用户,因为本软件会发布到Steam
|
|
|
|
|
//在 https://store.steampowered.com/app/1920960/VPet
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-01-29 08:27:24 +00:00
|
|
|
|
#if DEMO
|
2023-04-01 19:31:28 +00:00
|
|
|
|
SteamClient.Init(2293870, true);
|
2023-01-23 17:31:16 +00:00
|
|
|
|
#else
|
2022-12-22 08:13:05 +00:00
|
|
|
|
SteamClient.Init(1920960, true);
|
2023-01-23 17:31:16 +00:00
|
|
|
|
#endif
|
2022-12-22 08:13:05 +00:00
|
|
|
|
SteamClient.RunCallbacks();
|
|
|
|
|
IsSteamUser = SteamClient.IsValid;
|
|
|
|
|
////同时看看有没有买dlc,如果有就添加dlc按钮
|
|
|
|
|
//if (Steamworks.SteamApps.IsDlcInstalled(1386450))
|
2023-03-28 13:18:14 +00:00
|
|
|
|
// dlcToolStripMenuItem.Visible = true;
|
2022-12-22 08:13:05 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
IsSteamUser = false;
|
|
|
|
|
}
|
2023-11-14 12:33:44 +00:00
|
|
|
|
|
|
|
|
|
//更新存档系统
|
|
|
|
|
if (Directory.Exists(ExtensionValue.BaseDirectory + @"\BackUP"))
|
2022-12-22 08:13:05 +00:00
|
|
|
|
{
|
2023-11-14 12:33:44 +00:00
|
|
|
|
if (!Directory.Exists(ExtensionValue.BaseDirectory + @"\Saves"))
|
|
|
|
|
Directory.Move(ExtensionValue.BaseDirectory + @"\BackUP", ExtensionValue.BaseDirectory + @"\Saves");
|
2023-08-25 17:07:14 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2023-11-14 12:33:44 +00:00
|
|
|
|
foreach (var file in new DirectoryInfo(ExtensionValue.BaseDirectory + @"\BackUP").GetFiles())
|
|
|
|
|
if (!File.Exists(ExtensionValue.BaseDirectory + @"\Saves\" + file.Name))
|
|
|
|
|
file.MoveTo(ExtensionValue.BaseDirectory + @"\Saves\" + file.Name);
|
|
|
|
|
else
|
|
|
|
|
file.Delete();
|
|
|
|
|
Directory.Delete(ExtensionValue.BaseDirectory + @"\BackUP", true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-03 11:41:16 +00:00
|
|
|
|
|
2023-11-14 12:33:44 +00:00
|
|
|
|
_dwmEnabled = Win32.Dwmapi.DwmIsCompositionEnabled();
|
|
|
|
|
_hwnd = new WindowInteropHelper(this).EnsureHandle();
|
2023-07-03 11:41:16 +00:00
|
|
|
|
|
2023-11-14 12:33:44 +00:00
|
|
|
|
GameInitialization();
|
2022-12-13 07:10:18 +00:00
|
|
|
|
|
2024-03-15 10:25:40 +00:00
|
|
|
|
Task.Run(async () =>
|
2023-11-14 12:33:44 +00:00
|
|
|
|
{
|
|
|
|
|
//加载所有MOD
|
|
|
|
|
List<DirectoryInfo> Path = new List<DirectoryInfo>();
|
|
|
|
|
Path.AddRange(new DirectoryInfo(ModPath).EnumerateDirectories());
|
2023-01-28 06:12:01 +00:00
|
|
|
|
|
2023-11-14 12:33:44 +00:00
|
|
|
|
bool NOCancel = true;
|
|
|
|
|
CancellationTokenSource source = new CancellationTokenSource();
|
|
|
|
|
var tsk = Task.Run(async () =>
|
2023-04-03 18:11:12 +00:00
|
|
|
|
{
|
2023-11-14 12:33:44 +00:00
|
|
|
|
if (IsSteamUser)//如果是steam用户,尝试加载workshop
|
|
|
|
|
{
|
2024-01-25 14:40:50 +00:00
|
|
|
|
//Leaderboard? leaderboard = await SteamUserStats.FindLeaderboardAsync("chatgpt_auth");
|
|
|
|
|
//leaderboard?.ReplaceScore(Function.Rnd.Next());
|
2023-11-14 12:33:44 +00:00
|
|
|
|
var workshop = new Line_D("workshop");
|
|
|
|
|
await Dispatcher.InvokeAsync(new Action(() =>
|
|
|
|
|
{
|
|
|
|
|
LoadingText.Content = "Loading Steam Workshop\nDouble Click To Skip";
|
|
|
|
|
LoadingText.MouseDoubleClick += (_, _) =>
|
|
|
|
|
{
|
|
|
|
|
if ((string)LoadingText.Content == "Loading Steam Workshop\nDouble Click To Skip")
|
|
|
|
|
{
|
|
|
|
|
NOCancel = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}));
|
|
|
|
|
int i = 1;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
2024-01-25 14:40:50 +00:00
|
|
|
|
var page = await Steamworks.Ugc.Query.ItemsReadyToUse.GetPageAsync(i++);
|
2023-11-14 12:33:44 +00:00
|
|
|
|
if (page.HasValue && page.Value.ResultCount != 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (Steamworks.Ugc.Item entry in page.Value.Entries)
|
|
|
|
|
{
|
2023-11-14 13:24:57 +00:00
|
|
|
|
if (!NOCancel)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-14 12:33:44 +00:00
|
|
|
|
if (entry.Directory != null)
|
|
|
|
|
{
|
|
|
|
|
Path.Add(new DirectoryInfo(entry.Directory));
|
|
|
|
|
workshop.Add(new Sub(entry.Directory, ""));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (workshop.Count != 0)
|
|
|
|
|
Set["workshop"] = workshop;
|
|
|
|
|
}
|
|
|
|
|
else
|
2023-08-25 17:07:14 +00:00
|
|
|
|
{
|
2023-11-14 12:33:44 +00:00
|
|
|
|
var workshop = Set["workshop"];
|
|
|
|
|
foreach (Sub ws in workshop)
|
|
|
|
|
{
|
|
|
|
|
Path.Add(new DirectoryInfo(ws.Name));
|
|
|
|
|
}
|
2023-08-25 17:07:14 +00:00
|
|
|
|
}
|
2023-11-14 12:33:44 +00:00
|
|
|
|
}, source.Token);
|
|
|
|
|
|
|
|
|
|
while (NOCancel && !tsk.IsCompleted)
|
2023-08-25 17:07:14 +00:00
|
|
|
|
{
|
2023-11-14 12:33:44 +00:00
|
|
|
|
Thread.Sleep(500);
|
2023-04-03 18:11:12 +00:00
|
|
|
|
}
|
2023-11-14 12:33:44 +00:00
|
|
|
|
if (!NOCancel)
|
2023-09-04 05:01:16 +00:00
|
|
|
|
{
|
2023-11-14 12:33:44 +00:00
|
|
|
|
source.Cancel();
|
|
|
|
|
var workshop = Set["workshop"];
|
|
|
|
|
foreach (Sub ws in workshop)
|
|
|
|
|
{
|
|
|
|
|
Path.Add(new DirectoryInfo(ws.Name));
|
|
|
|
|
}
|
2023-09-04 05:01:16 +00:00
|
|
|
|
}
|
2023-04-03 18:11:12 +00:00
|
|
|
|
|
2023-11-24 07:10:30 +00:00
|
|
|
|
|
2023-11-14 12:33:44 +00:00
|
|
|
|
Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = "Loading Translate")).Wait();
|
|
|
|
|
//加载语言
|
|
|
|
|
LocalizeCore.StoreTranslation = true;
|
|
|
|
|
if (Set.Language == "null")
|
2023-08-25 17:07:14 +00:00
|
|
|
|
{
|
2023-11-14 12:33:44 +00:00
|
|
|
|
LocalizeCore.LoadDefaultCulture();
|
|
|
|
|
if (LocalizeCore.CurrentCulture == "null")
|
|
|
|
|
LocalizeCore.CurrentCulture = "en";
|
|
|
|
|
Set.Language = LocalizeCore.CurrentCulture;
|
2023-08-25 17:07:14 +00:00
|
|
|
|
}
|
2023-11-14 12:33:44 +00:00
|
|
|
|
else
|
|
|
|
|
LocalizeCore.LoadCulture(Set.Language);
|
2023-09-10 17:32:13 +00:00
|
|
|
|
|
2023-11-14 12:33:44 +00:00
|
|
|
|
//旧版本设置兼容
|
|
|
|
|
var cgpte = Set.FindLine("CGPT");
|
|
|
|
|
if (cgpte != null)
|
2023-09-24 13:17:48 +00:00
|
|
|
|
{
|
2023-11-14 12:33:44 +00:00
|
|
|
|
var cgpteb = cgpte.Find("enable");
|
|
|
|
|
if (cgpteb != null)
|
2023-09-25 09:44:02 +00:00
|
|
|
|
{
|
2023-11-14 12:33:44 +00:00
|
|
|
|
if (Set["CGPT"][(gbol)"enable"])
|
|
|
|
|
{
|
|
|
|
|
Set["CGPT"][(gstr)"type"] = "API";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Set["CGPT"][(gstr)"type"] = "LB";
|
|
|
|
|
}
|
|
|
|
|
Set["CGPT"].Remove(cgpteb);
|
2023-09-25 09:44:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-14 12:33:44 +00:00
|
|
|
|
else if (Set["CGPT"][(gstr)"type"] == "OFF")
|
|
|
|
|
{//为老玩家开启选项聊天功能
|
|
|
|
|
Set["CGPT"][(gstr)"type"] = "LB";
|
|
|
|
|
}
|
|
|
|
|
else//新玩家,默认设置为
|
|
|
|
|
Set["CGPT"][(gstr)"type"] = "LB";
|
2023-09-24 13:17:48 +00:00
|
|
|
|
|
2024-03-15 10:25:40 +00:00
|
|
|
|
await GameLoad(Path);
|
|
|
|
|
if (IsSteamUser)
|
2024-03-16 11:22:07 +00:00
|
|
|
|
{
|
2024-03-15 10:25:40 +00:00
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
2024-03-16 14:39:25 +00:00
|
|
|
|
var menuItem = new MenuItem()
|
|
|
|
|
{
|
|
|
|
|
Header = "访客表".Translate(),
|
|
|
|
|
HorizontalContentAlignment = HorizontalAlignment.Center
|
|
|
|
|
};
|
|
|
|
|
Main.ToolBar.MenuInteract.Items.Add(menuItem);
|
|
|
|
|
|
|
|
|
|
var menuCreate = new MenuItem()
|
|
|
|
|
{
|
|
|
|
|
Header = "创建".Translate(),
|
|
|
|
|
HorizontalContentAlignment = HorizontalAlignment.Center
|
|
|
|
|
};
|
|
|
|
|
menuCreate.Click += (_, _) =>
|
2024-03-15 10:25:40 +00:00
|
|
|
|
{
|
|
|
|
|
if (winMutiPlayer == null)
|
|
|
|
|
{
|
|
|
|
|
winMutiPlayer = new winMutiPlayer(this);
|
|
|
|
|
winMutiPlayer.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-03-16 14:39:25 +00:00
|
|
|
|
MessageBoxX.Show("已经有加入了一个访客表,无法再创建更多".Translate());
|
2024-03-15 10:25:40 +00:00
|
|
|
|
winMutiPlayer.Focus();
|
|
|
|
|
}
|
2024-03-16 14:39:25 +00:00
|
|
|
|
};
|
|
|
|
|
menuItem.Items.Add(menuCreate);
|
|
|
|
|
|
|
|
|
|
var menuJoin = new MenuItem()
|
|
|
|
|
{
|
|
|
|
|
Header = "加入".Translate(),
|
|
|
|
|
HorizontalContentAlignment = HorizontalAlignment.Center
|
|
|
|
|
};
|
|
|
|
|
menuJoin.Click += (_, _) =>
|
|
|
|
|
{
|
|
|
|
|
if (winMutiPlayer == null)
|
|
|
|
|
{
|
|
|
|
|
winInputBox.Show(this, "请输入访客表ID".Translate(), "加入访客表".Translate(), "", (id) =>
|
|
|
|
|
{
|
|
|
|
|
if (ulong.TryParse(id, NumberStyles.HexNumber, null, out ulong lid))
|
|
|
|
|
{
|
|
|
|
|
winMutiPlayer = new winMutiPlayer(this, lid);
|
|
|
|
|
winMutiPlayer.Show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBoxX.Show("已经有加入了一个访客表,无法再创建更多".Translate());
|
|
|
|
|
winMutiPlayer.Focus();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
menuItem.Items.Add(menuJoin);
|
|
|
|
|
|
2024-03-15 17:33:56 +00:00
|
|
|
|
int clid = Array.IndexOf(App.Args, "connect_lobby");
|
|
|
|
|
if (clid != -1)
|
|
|
|
|
{
|
|
|
|
|
if (ulong.TryParse(App.Args[clid + 1], out ulong lid))
|
|
|
|
|
{
|
|
|
|
|
winMutiPlayer = new winMutiPlayer(this, lid);
|
|
|
|
|
winMutiPlayer.Show();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-15 10:25:40 +00:00
|
|
|
|
});
|
2024-03-16 11:22:07 +00:00
|
|
|
|
SteamMatchmaking.OnLobbyInvite += SteamMatchmaking_OnLobbyInvite;
|
2024-03-16 17:02:08 +00:00
|
|
|
|
SteamFriends.OnGameLobbyJoinRequested += SteamFriends_OnGameLobbyJoinRequested;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SteamFriends_OnGameLobbyJoinRequested(Lobby lobby, SteamId id)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
if (winMutiPlayer == null)
|
|
|
|
|
{
|
|
|
|
|
winMutiPlayer = new winMutiPlayer(this, lobby.Id.Value);
|
|
|
|
|
winMutiPlayer.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBoxX.Show("已经有加入了一个访客表,无法再创建更多".Translate());
|
|
|
|
|
winMutiPlayer.Focus();
|
2024-03-16 11:22:07 +00:00
|
|
|
|
}
|
2023-11-14 12:33:44 +00:00
|
|
|
|
});
|
2023-01-08 16:57:10 +00:00
|
|
|
|
}
|
2024-03-16 11:22:07 +00:00
|
|
|
|
|
|
|
|
|
private void SteamMatchmaking_OnLobbyInvite(Friend friend, Lobby lobby)
|
|
|
|
|
{
|
|
|
|
|
if (winMutiPlayer != null)
|
|
|
|
|
return;
|
2024-03-16 17:02:08 +00:00
|
|
|
|
Dispatcher.Invoke(() =>
|
2024-03-16 11:22:07 +00:00
|
|
|
|
{
|
2024-03-16 17:02:08 +00:00
|
|
|
|
Button btn = new Button();
|
|
|
|
|
btn.Content = "加入访客表";
|
|
|
|
|
btn.Style = FindResource("ThemedButtonStyle") as Style;
|
|
|
|
|
btn.Click += (_, _) =>
|
|
|
|
|
{
|
|
|
|
|
winMutiPlayer = new winMutiPlayer(this, lobby.Id);
|
|
|
|
|
winMutiPlayer.Show();
|
2024-03-17 16:25:04 +00:00
|
|
|
|
Main.MsgBar.ForceClose();
|
2024-03-16 17:02:08 +00:00
|
|
|
|
};
|
|
|
|
|
Main.Say("收到来自{0}的访客邀请,是否加入?".Translate(friend.Name), msgcontent: btn);
|
|
|
|
|
});
|
2024-03-16 11:22:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-03-15 10:25:40 +00:00
|
|
|
|
internal winMutiPlayer winMutiPlayer;
|
2023-10-13 12:02:48 +00:00
|
|
|
|
|
2023-03-07 08:11:23 +00:00
|
|
|
|
public new void Close()
|
|
|
|
|
{
|
|
|
|
|
if (Main == null)
|
|
|
|
|
{
|
|
|
|
|
base.Close();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-07-16 23:58:09 +00:00
|
|
|
|
Main.Display(GraphType.Shutdown, AnimatType.Single, () => Dispatcher.Invoke(base.Close));
|
2023-03-07 08:11:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void Restart()
|
|
|
|
|
{
|
|
|
|
|
this.Closed -= Window_Closed;
|
|
|
|
|
this.Closed += Restart_Closed;
|
|
|
|
|
base.Close();
|
|
|
|
|
}
|
2023-07-03 11:41:16 +00:00
|
|
|
|
|
2023-03-07 08:11:23 +00:00
|
|
|
|
private void Restart_Closed(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-08-12 07:13:30 +00:00
|
|
|
|
CloseConfirm = false;
|
2023-04-01 19:31:28 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//关闭所有插件
|
|
|
|
|
foreach (MainPlugin mp in Plugins)
|
|
|
|
|
mp.EndGame();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
2023-08-16 03:09:44 +00:00
|
|
|
|
Save();
|
2023-10-13 15:31:52 +00:00
|
|
|
|
if (App.MainWindows.Count == 1)
|
2024-03-19 07:26:26 +00:00
|
|
|
|
{
|
|
|
|
|
var psi = new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = Path.ChangeExtension(System.Reflection.Assembly.GetExecutingAssembly().Location, "exe"),
|
|
|
|
|
UseShellExecute = true
|
|
|
|
|
};
|
|
|
|
|
Process.Start(psi);
|
|
|
|
|
}
|
2023-10-13 15:31:52 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
new MainWindow(PrefixSave).Show();
|
|
|
|
|
}
|
2023-08-16 03:09:44 +00:00
|
|
|
|
Exit();
|
|
|
|
|
}
|
|
|
|
|
private void Exit()
|
2024-03-30 07:00:02 +00:00
|
|
|
|
{
|
2023-11-14 12:33:44 +00:00
|
|
|
|
if (App.MainWindows.Count <= 1)
|
2023-08-16 03:09:44 +00:00
|
|
|
|
{
|
2024-03-22 14:45:18 +00:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(10000);//等待10秒不退出强退
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
});
|
2023-10-13 15:31:52 +00:00
|
|
|
|
try
|
2024-01-25 14:40:50 +00:00
|
|
|
|
{
|
2023-11-14 12:33:44 +00:00
|
|
|
|
if (Core != null && Core.Graph != null)
|
2023-08-16 03:09:44 +00:00
|
|
|
|
{
|
2023-10-13 15:31:52 +00:00
|
|
|
|
foreach (var igs in Core.Graph.GraphsList.Values)
|
2023-08-16 03:09:44 +00:00
|
|
|
|
{
|
2023-10-13 15:31:52 +00:00
|
|
|
|
foreach (var ig2 in igs.Values)
|
2023-08-17 08:39:26 +00:00
|
|
|
|
{
|
2023-10-13 15:31:52 +00:00
|
|
|
|
foreach (var ig3 in ig2)
|
|
|
|
|
{
|
|
|
|
|
ig3.Stop();
|
|
|
|
|
}
|
2023-08-17 08:39:26 +00:00
|
|
|
|
}
|
2023-08-16 03:09:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-20 15:57:54 +00:00
|
|
|
|
while (Windows.Count != 0)
|
2023-10-13 15:31:52 +00:00
|
|
|
|
{
|
2024-03-17 16:25:04 +00:00
|
|
|
|
var w = Windows[0];
|
|
|
|
|
w.Close();
|
|
|
|
|
Windows.Remove(w);
|
2023-10-13 15:31:52 +00:00
|
|
|
|
}
|
2023-11-20 15:57:54 +00:00
|
|
|
|
Main?.Dispose();
|
2023-10-13 15:31:52 +00:00
|
|
|
|
AutoSaveTimer?.Stop();
|
|
|
|
|
MusicTimer?.Stop();
|
|
|
|
|
petHelper?.Close();
|
2023-11-20 15:57:54 +00:00
|
|
|
|
winSetting?.Close();
|
|
|
|
|
winBetterBuy?.Close();
|
2024-03-14 11:31:34 +00:00
|
|
|
|
winWorkMenu?.Close();
|
2024-03-22 13:39:53 +00:00
|
|
|
|
if (winMutiPlayer != null)
|
|
|
|
|
{
|
|
|
|
|
winMutiPlayer.lb.Leave();
|
|
|
|
|
winMutiPlayer.lb = default;
|
|
|
|
|
winMutiPlayer.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-20 15:57:54 +00:00
|
|
|
|
if (IsSteamUser)
|
|
|
|
|
SteamClient.Shutdown();//关掉和Steam的连线
|
2023-10-13 15:31:52 +00:00
|
|
|
|
if (notifyIcon != null)
|
|
|
|
|
{
|
|
|
|
|
notifyIcon.Visible = false;
|
|
|
|
|
notifyIcon.Dispose();
|
|
|
|
|
}
|
|
|
|
|
notifyIcon?.Dispose();
|
2023-08-16 03:09:44 +00:00
|
|
|
|
}
|
2023-10-13 15:31:52 +00:00
|
|
|
|
finally
|
2023-08-17 08:39:26 +00:00
|
|
|
|
{
|
2023-10-13 15:31:52 +00:00
|
|
|
|
Environment.Exit(0);
|
2023-08-17 08:39:26 +00:00
|
|
|
|
}
|
2023-10-13 15:31:52 +00:00
|
|
|
|
while (true)
|
|
|
|
|
Environment.Exit(0);
|
2023-08-16 03:09:44 +00:00
|
|
|
|
}
|
2023-10-13 15:31:52 +00:00
|
|
|
|
else
|
2023-10-15 13:12:00 +00:00
|
|
|
|
{
|
2023-11-20 15:57:54 +00:00
|
|
|
|
if (Core != null && Core.Graph != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var igs in Core.Graph.GraphsList.Values)
|
|
|
|
|
{
|
|
|
|
|
foreach (var ig2 in igs.Values)
|
|
|
|
|
{
|
|
|
|
|
foreach (var ig3 in ig2)
|
|
|
|
|
{
|
|
|
|
|
ig3.Stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-31 06:34:57 +00:00
|
|
|
|
while (Windows.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
Windows[0].Close();
|
|
|
|
|
}
|
2023-11-20 15:57:54 +00:00
|
|
|
|
Main?.Dispose();
|
|
|
|
|
AutoSaveTimer?.Stop();
|
|
|
|
|
MusicTimer?.Stop();
|
|
|
|
|
petHelper?.Close();
|
2023-10-15 13:12:00 +00:00
|
|
|
|
winSetting?.Close();
|
|
|
|
|
winBetterBuy?.Close();
|
2024-03-14 11:31:34 +00:00
|
|
|
|
winWorkMenu?.Close();
|
2024-03-22 13:39:53 +00:00
|
|
|
|
if (winMutiPlayer != null)
|
|
|
|
|
{
|
|
|
|
|
winMutiPlayer.lb.Leave();
|
|
|
|
|
winMutiPlayer.lb = default;
|
|
|
|
|
winMutiPlayer.Close();
|
|
|
|
|
}
|
2023-10-13 15:31:52 +00:00
|
|
|
|
App.MainWindows.Remove(this);
|
2023-10-22 06:23:43 +00:00
|
|
|
|
if (notifyIcon != null)
|
|
|
|
|
{
|
|
|
|
|
notifyIcon.Visible = false;
|
|
|
|
|
notifyIcon.Dispose();
|
|
|
|
|
}
|
|
|
|
|
notifyIcon?.Dispose();
|
2023-10-15 13:12:00 +00:00
|
|
|
|
}
|
2023-03-07 08:11:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-16 03:09:44 +00:00
|
|
|
|
|
2023-04-01 19:31:28 +00:00
|
|
|
|
public long lastclicktime { get; set; }
|
2023-07-13 13:43:09 +00:00
|
|
|
|
|
2023-08-09 14:17:28 +00:00
|
|
|
|
public void LoadLatestSave(string petname)
|
2023-07-13 13:43:09 +00:00
|
|
|
|
{
|
2023-09-24 13:17:48 +00:00
|
|
|
|
if (Directory.Exists(ExtensionValue.BaseDirectory + @"\Saves"))
|
2023-07-13 13:43:09 +00:00
|
|
|
|
{
|
2023-10-10 17:03:23 +00:00
|
|
|
|
var ds = new List<string>(Directory.GetFiles(ExtensionValue.BaseDirectory + @"\Saves", $@"Save{PrefixSave}_*.lps"))
|
|
|
|
|
.OrderBy(x =>
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(x.Split('_').Last().Split('.')[0], out int i))
|
|
|
|
|
return i;
|
|
|
|
|
return 0;
|
|
|
|
|
}).ToList();
|
2023-10-04 11:53:52 +00:00
|
|
|
|
|
|
|
|
|
if (ds.Count != 0)
|
2023-10-04 05:58:06 +00:00
|
|
|
|
{
|
2023-10-10 17:03:23 +00:00
|
|
|
|
int.TryParse(ds.Last().Split('_').Last().Split('.')[0], out int lastid);
|
2023-10-04 11:53:52 +00:00
|
|
|
|
if (Set.SaveTimes < lastid)
|
|
|
|
|
{
|
|
|
|
|
Set.SaveTimes = lastid;
|
|
|
|
|
}
|
2023-10-04 05:58:06 +00:00
|
|
|
|
}
|
2023-10-02 12:03:25 +00:00
|
|
|
|
for (int i = ds.Count - 1; i >= 0; i--)
|
2023-07-13 13:43:09 +00:00
|
|
|
|
{
|
2023-10-02 12:03:25 +00:00
|
|
|
|
var latestsave = ds[i];
|
|
|
|
|
if (latestsave != null)
|
2023-08-30 17:44:38 +00:00
|
|
|
|
{
|
2024-03-11 17:35:52 +00:00
|
|
|
|
#if !DEBUG
|
2023-10-02 12:03:25 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2024-03-11 17:35:52 +00:00
|
|
|
|
#endif
|
2024-03-15 10:25:40 +00:00
|
|
|
|
if (SavesLoad(new LPS(File.ReadAllText(latestsave))))
|
|
|
|
|
return;
|
|
|
|
|
//MessageBoxX.Show("存档损毁,无法加载该存档\n可能是上次储存出错或Steam云同步导致的\n请在设置中加载备份还原存档", "存档损毁".Translate());
|
2024-03-11 17:35:52 +00:00
|
|
|
|
#if !DEBUG
|
2023-10-02 12:03:25 +00:00
|
|
|
|
}
|
2024-03-11 17:35:52 +00:00
|
|
|
|
catch (Exception ex)
|
2023-10-02 12:03:25 +00:00
|
|
|
|
{
|
2024-03-11 17:35:52 +00:00
|
|
|
|
MessageBoxX.Show("存档损毁,无法加载该存档\n可能是数据溢出/超模导致的" + '\n' + ex.Message, "存档损毁".Translate());
|
2023-10-02 12:03:25 +00:00
|
|
|
|
}
|
2024-03-11 17:35:52 +00:00
|
|
|
|
#endif
|
2023-08-30 17:44:38 +00:00
|
|
|
|
}
|
2023-07-13 13:43:09 +00:00
|
|
|
|
}
|
2023-10-02 12:03:25 +00:00
|
|
|
|
|
2023-07-13 13:43:09 +00:00
|
|
|
|
}
|
2023-09-22 18:10:15 +00:00
|
|
|
|
GameSavesData = new GameSave_v2(petname.Translate());
|
|
|
|
|
Core.Save = GameSavesData.GameSave;
|
2023-07-13 13:43:09 +00:00
|
|
|
|
}
|
2023-08-25 22:39:13 +00:00
|
|
|
|
|
2023-09-24 15:35:49 +00:00
|
|
|
|
private void WorkTimer_E_FinishWork(WorkTimer.FinishWorkInfo obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj.work.Type == GraphHelper.Work.WorkType.Work)
|
|
|
|
|
{
|
|
|
|
|
GameSavesData.Statistics[(gint)"stat_single_profit_money"] = (int)obj.count;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GameSavesData.Statistics[(gint)"stat_single_profit_exp"] = (int)obj.count;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-11 06:49:43 +00:00
|
|
|
|
|
2023-07-23 20:46:21 +00:00
|
|
|
|
private void Main_Event_TouchBody()
|
|
|
|
|
{
|
2023-09-22 13:24:02 +00:00
|
|
|
|
GameSavesData.Statistics[(gint)"stat_touch_body"]++;
|
2023-07-23 20:46:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Main_Event_TouchHead()
|
|
|
|
|
{
|
2023-09-22 13:24:02 +00:00
|
|
|
|
GameSavesData.Statistics[(gint)"stat_touch_head"]++;
|
2023-07-23 20:46:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Main_OnSay(string obj)
|
|
|
|
|
{
|
2023-09-22 13:24:02 +00:00
|
|
|
|
GameSavesData.Statistics[(gint)"stat_say_times"]++;
|
2023-07-23 20:46:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MoveTimer_Elapsed(object sender, ElapsedEventArgs e)
|
|
|
|
|
{
|
2023-09-22 13:24:02 +00:00
|
|
|
|
GameSavesData.Statistics[(gint)"stat_move_length"] += (int)(Math.Abs(Main.MoveTimerPoint.X) + Math.Abs(Main.MoveTimerPoint.Y));
|
2023-07-23 20:46:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-18 18:11:40 +00:00
|
|
|
|
private void AutoSaveTimer_Elapsed(object sender, ElapsedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Save();
|
|
|
|
|
}
|
2023-06-16 03:39:29 +00:00
|
|
|
|
|
2023-01-20 17:01:10 +00:00
|
|
|
|
|
2023-06-18 18:11:40 +00:00
|
|
|
|
private void Window_Closed(object sender, EventArgs e)
|
2023-01-12 22:11:55 +00:00
|
|
|
|
{
|
2023-08-12 07:13:30 +00:00
|
|
|
|
CloseConfirm = false;
|
2023-06-18 18:11:40 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//关闭所有插件
|
|
|
|
|
foreach (MainPlugin mp in Plugins)
|
|
|
|
|
mp.EndGame();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
2023-07-05 03:22:34 +00:00
|
|
|
|
Save();
|
2023-08-16 03:09:44 +00:00
|
|
|
|
Exit();
|
2023-01-12 22:11:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-03 11:41:16 +00:00
|
|
|
|
[DllImport("user32", EntryPoint = "SetWindowLong")]
|
|
|
|
|
private static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);
|
2023-04-01 19:31:28 +00:00
|
|
|
|
|
2023-07-03 11:41:16 +00:00
|
|
|
|
[DllImport("user32", EntryPoint = "GetWindowLong")]
|
|
|
|
|
private static extern uint GetWindowLong(IntPtr hwnd, int nIndex);
|
|
|
|
|
private void Window_SourceInitialized(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//const int WS_EX_TRANSPARENT = 0x20;
|
|
|
|
|
//const int GWL_EXSTYLE = -20;
|
|
|
|
|
//IntPtr hwnd = new WindowInteropHelper(this).Handle;
|
|
|
|
|
//uint extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
|
|
|
|
|
//SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
|
|
|
|
|
((HwndSource)PresentationSource.FromVisual(this)).AddHook((IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
|
|
|
|
|
{
|
|
|
|
|
//想要让窗口透明穿透鼠标和触摸等,需要同时设置 WS_EX_LAYERED 和 WS_EX_TRANSPARENT 样式,
|
|
|
|
|
//确保窗口始终有 WS_EX_LAYERED 这个样式,并在开启穿透时设置 WS_EX_TRANSPARENT 样式
|
|
|
|
|
//但是WPF窗口在未设置 AllowsTransparency = true 时,会自动去掉 WS_EX_LAYERED 样式(在 HwndTarget 类中),
|
|
|
|
|
//如果设置了 AllowsTransparency = true 将使用WPF内置的低性能的透明实现,
|
|
|
|
|
//所以这里通过 Hook 的方式,在不使用WPF内置的透明实现的情况下,强行保证这个样式存在。
|
|
|
|
|
if (msg == (int)Win32.WM.STYLECHANGING && (long)wParam == (long)Win32.GetWindowLongFields.GWL_EXSTYLE)
|
|
|
|
|
{
|
|
|
|
|
var styleStruct = (STYLESTRUCT)Marshal.PtrToStructure(lParam, typeof(STYLESTRUCT));
|
|
|
|
|
styleStruct.styleNew |= (int)Win32.ExtendedWindowStyles.WS_EX_LAYERED;
|
2023-09-16 09:33:54 +00:00
|
|
|
|
|
|
|
|
|
// Hide windows from alt+tab: https://stackoverflow.com/questions/357076/best-way-to-hide-a-window-from-the-alt-tab-program-switcher
|
|
|
|
|
if (Set.HideFromTaskControl)
|
|
|
|
|
{
|
|
|
|
|
styleStruct.styleNew |= (int)Win32.ExtendedWindowStyles.WS_EX_TOOLWINDOW;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-03 11:41:16 +00:00
|
|
|
|
Marshal.StructureToPtr(styleStruct, lParam, false);
|
|
|
|
|
handled = true;
|
|
|
|
|
}
|
|
|
|
|
return IntPtr.Zero;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
private readonly bool _dwmEnabled;
|
|
|
|
|
private readonly IntPtr _hwnd;
|
|
|
|
|
public bool HitThrough { get; private set; } = false;
|
2023-07-16 23:58:09 +00:00
|
|
|
|
public bool MouseHitThrough
|
|
|
|
|
{
|
|
|
|
|
get => HitThrough;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != HitThrough)
|
|
|
|
|
SetTransparentHitThrough();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-03 11:41:16 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置点击穿透到后面透明的窗口
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void SetTransparentHitThrough()
|
|
|
|
|
{
|
|
|
|
|
if (_dwmEnabled)
|
|
|
|
|
{
|
|
|
|
|
//const int WS_EX_TRANSPARENT = 0x20;
|
|
|
|
|
//const int GWL_EXSTYLE = -20;
|
|
|
|
|
//IntPtr hwnd = new WindowInteropHelper(this).Handle;
|
|
|
|
|
//uint extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
|
|
|
|
|
//SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
|
|
|
|
|
HitThrough = !HitThrough;
|
2024-03-16 11:22:07 +00:00
|
|
|
|
(notifyIcon.ContextMenuStrip.Items.Find("NotifyIcon_HitThrough", false).First() as System.Windows.Forms.ToolStripMenuItem).Checked = HitThrough;
|
2023-07-03 11:41:16 +00:00
|
|
|
|
if (HitThrough)
|
|
|
|
|
{
|
|
|
|
|
Win32.User32.SetWindowLongPtr(_hwnd, Win32.GetWindowLongFields.GWL_EXSTYLE,
|
|
|
|
|
(IntPtr)(int)((long)Win32.User32.GetWindowLongPtr(_hwnd, Win32.GetWindowLongFields.GWL_EXSTYLE) | (long)Win32.ExtendedWindowStyles.WS_EX_TRANSPARENT));
|
|
|
|
|
petHelper?.SetOpacity(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Win32.User32.SetWindowLongPtr(_hwnd, Win32.GetWindowLongFields.GWL_EXSTYLE,
|
|
|
|
|
(IntPtr)(int)((long)Win32.User32.GetWindowLongPtr(_hwnd, Win32.GetWindowLongFields.GWL_EXSTYLE) & ~(long)Win32.ExtendedWindowStyles.WS_EX_TRANSPARENT));
|
|
|
|
|
petHelper?.SetOpacity(true);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void WindowX_LocationChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-07-03 23:17:17 +00:00
|
|
|
|
petHelper?.SetLocation();
|
2023-07-03 11:41:16 +00:00
|
|
|
|
}
|
2023-06-18 18:11:40 +00:00
|
|
|
|
//public void DEBUGValue()
|
|
|
|
|
//{
|
|
|
|
|
// Dispatcher.Invoke(() =>
|
|
|
|
|
// {
|
|
|
|
|
// Console.WriteLine("Left:" + mwc.GetWindowsDistanceLeft());
|
|
|
|
|
// Console.WriteLine("Right:" + mwc.GetWindowsDistanceRight());
|
|
|
|
|
// });
|
|
|
|
|
// Thread.Sleep(1000);
|
|
|
|
|
// DEBUGValue();
|
|
|
|
|
//}
|
2023-07-03 11:41:16 +00:00
|
|
|
|
//
|
2023-06-18 18:11:40 +00:00
|
|
|
|
}
|
2022-12-13 07:10:18 +00:00
|
|
|
|
}
|