diff --git a/lib/YaeAchievementLib.vcxproj b/lib/YaeAchievementLib.vcxproj index c0c5a11..82d6bb4 100644 --- a/lib/YaeAchievementLib.vcxproj +++ b/lib/YaeAchievementLib.vcxproj @@ -48,6 +48,7 @@ true $(SolutionDir)build\$(Platform)\$(Configuration)\ build\$(Platform)\$(Configuration)\ + YaeLib false diff --git a/src/Export.cs b/src/Export.cs new file mode 100644 index 0000000..c5e3b84 --- /dev/null +++ b/src/Export.cs @@ -0,0 +1,7 @@ +namespace YaeAchievement; + +public static class Export { + + public static void A() {} + +} \ No newline at end of file diff --git a/src/Injector.cs b/src/Injector.cs index d8ced07..7a11d0f 100644 --- a/src/Injector.cs +++ b/src/Injector.cs @@ -8,9 +8,10 @@ public static class Injector { public static unsafe bool CreateProcess(string path, out IntPtr hProc, out IntPtr hThread, out uint pid) { var si = new StartupInfo(); SecurityAttributes* attr = null; + var dir = Path.GetDirectoryName(path)!; var result = Native.CreateProcess( path, null, ref *attr, ref *attr, false, - CreationFlags.CreateSuspended, IntPtr.Zero, null, ref si, out var pi + CreationFlags.CreateSuspended, IntPtr.Zero, dir, ref si, out var pi ); pid = pi.dwProcessID; hProc = pi.hProcess; diff --git a/src/Proto/AchievementInfo.cs b/src/Proto/AchievementInfo.cs new file mode 100644 index 0000000..ed55dc2 --- /dev/null +++ b/src/Proto/AchievementInfo.cs @@ -0,0 +1,588 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: AchievementInfo.proto +// +#pragma warning disable 1591, 0612, 3021, 8981 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +/// Holder for reflection information generated from AchievementInfo.proto +public static partial class AchievementInfoReflection { + + #region Descriptor + /// File descriptor for AchievementInfo.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static AchievementInfoReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "ChVBY2hpZXZlbWVudEluZm8ucHJvdG8iUAoPQWNoaWV2ZW1lbnRJdGVtEgsK", + "A3ByZRgBIAEoDRINCgVncm91cBgCIAEoDRIMCgRuYW1lGAMgASgJEhMKC2Rl", + "c2NyaXB0aW9uGAQgASgJIugBCg9BY2hpZXZlbWVudEluZm8SDwoHdmVyc2lv", + "bhgBIAEoCRIqCgVncm91cBgCIAMoCzIbLkFjaGlldmVtZW50SW5mby5Hcm91", + "cEVudHJ5EioKBWl0ZW1zGAMgAygLMhsuQWNoaWV2ZW1lbnRJbmZvLkl0ZW1z", + "RW50cnkaLAoKR3JvdXBFbnRyeRILCgNrZXkYASABKA0SDQoFdmFsdWUYAiAB", + "KAk6AjgBGj4KCkl0ZW1zRW50cnkSCwoDa2V5GAEgASgNEh8KBXZhbHVlGAIg", + "ASgLMhAuQWNoaWV2ZW1lbnRJdGVtOgI4AWIGcHJvdG8z")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::AchievementItem), global::AchievementItem.Parser, new[]{ "Pre", "Group", "Name", "Description" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::AchievementInfo), global::AchievementInfo.Parser, new[]{ "Version", "Group", "Items" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { null, null, }) + })); + } + #endregion + +} +#region Messages +public sealed partial class AchievementItem : pb::IMessage +#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage +#endif +{ + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new AchievementItem()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::AchievementInfoReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public AchievementItem() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public AchievementItem(AchievementItem other) : this() { + pre_ = other.pre_; + group_ = other.group_; + name_ = other.name_; + description_ = other.description_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public AchievementItem Clone() { + return new AchievementItem(this); + } + + /// Field number for the "pre" field. + public const int PreFieldNumber = 1; + private uint pre_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public uint Pre { + get { return pre_; } + set { + pre_ = value; + } + } + + /// Field number for the "group" field. + public const int GroupFieldNumber = 2; + private uint group_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public uint Group { + get { return group_; } + set { + group_ = value; + } + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 3; + private string name_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Name { + get { return name_; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "description" field. + public const int DescriptionFieldNumber = 4; + private string description_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Description { + get { return description_; } + set { + description_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as AchievementItem); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(AchievementItem other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Pre != other.Pre) return false; + if (Group != other.Group) return false; + if (Name != other.Name) return false; + if (Description != other.Description) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (Pre != 0) hash ^= Pre.GetHashCode(); + if (Group != 0) hash ^= Group.GetHashCode(); + if (Name.Length != 0) hash ^= Name.GetHashCode(); + if (Description.Length != 0) hash ^= Description.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Pre != 0) { + output.WriteRawTag(8); + output.WriteUInt32(Pre); + } + if (Group != 0) { + output.WriteRawTag(16); + output.WriteUInt32(Group); + } + if (Name.Length != 0) { + output.WriteRawTag(26); + output.WriteString(Name); + } + if (Description.Length != 0) { + output.WriteRawTag(34); + output.WriteString(Description); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Pre != 0) { + output.WriteRawTag(8); + output.WriteUInt32(Pre); + } + if (Group != 0) { + output.WriteRawTag(16); + output.WriteUInt32(Group); + } + if (Name.Length != 0) { + output.WriteRawTag(26); + output.WriteString(Name); + } + if (Description.Length != 0) { + output.WriteRawTag(34); + output.WriteString(Description); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (Pre != 0) { + size += 1 + pb::CodedOutputStream.ComputeUInt32Size(Pre); + } + if (Group != 0) { + size += 1 + pb::CodedOutputStream.ComputeUInt32Size(Group); + } + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (Description.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Description); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(AchievementItem other) { + if (other == null) { + return; + } + if (other.Pre != 0) { + Pre = other.Pre; + } + if (other.Group != 0) { + Group = other.Group; + } + if (other.Name.Length != 0) { + Name = other.Name; + } + if (other.Description.Length != 0) { + Description = other.Description; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Pre = input.ReadUInt32(); + break; + } + case 16: { + Group = input.ReadUInt32(); + break; + } + case 26: { + Name = input.ReadString(); + break; + } + case 34: { + Description = input.ReadString(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Pre = input.ReadUInt32(); + break; + } + case 16: { + Group = input.ReadUInt32(); + break; + } + case 26: { + Name = input.ReadString(); + break; + } + case 34: { + Description = input.ReadString(); + break; + } + } + } + } + #endif + +} + +public sealed partial class AchievementInfo : pb::IMessage +#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage +#endif +{ + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new AchievementInfo()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::AchievementInfoReflection.Descriptor.MessageTypes[1]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public AchievementInfo() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public AchievementInfo(AchievementInfo other) : this() { + version_ = other.version_; + group_ = other.group_.Clone(); + items_ = other.items_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public AchievementInfo Clone() { + return new AchievementInfo(this); + } + + /// Field number for the "version" field. + public const int VersionFieldNumber = 1; + private string version_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Version { + get { return version_; } + set { + version_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "group" field. + public const int GroupFieldNumber = 2; + private static readonly pbc::MapField.Codec _map_group_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForUInt32(8, 0), pb::FieldCodec.ForString(18, ""), 18); + private readonly pbc::MapField group_ = new pbc::MapField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public pbc::MapField Group { + get { return group_; } + } + + /// Field number for the "items" field. + public const int ItemsFieldNumber = 3; + private static readonly pbc::MapField.Codec _map_items_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForUInt32(8, 0), pb::FieldCodec.ForMessage(18, global::AchievementItem.Parser), 26); + private readonly pbc::MapField items_ = new pbc::MapField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public pbc::MapField Items { + get { return items_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as AchievementInfo); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(AchievementInfo other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Version != other.Version) return false; + if (!Group.Equals(other.Group)) return false; + if (!Items.Equals(other.Items)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (Version.Length != 0) hash ^= Version.GetHashCode(); + hash ^= Group.GetHashCode(); + hash ^= Items.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Version.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Version); + } + group_.WriteTo(output, _map_group_codec); + items_.WriteTo(output, _map_items_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Version.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Version); + } + group_.WriteTo(ref output, _map_group_codec); + items_.WriteTo(ref output, _map_items_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (Version.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Version); + } + size += group_.CalculateSize(_map_group_codec); + size += items_.CalculateSize(_map_items_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(AchievementInfo other) { + if (other == null) { + return; + } + if (other.Version.Length != 0) { + Version = other.Version; + } + group_.Add(other.group_); + items_.Add(other.items_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Version = input.ReadString(); + break; + } + case 18: { + group_.AddEntriesFrom(input, _map_group_codec); + break; + } + case 26: { + items_.AddEntriesFrom(input, _map_items_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Version = input.ReadString(); + break; + } + case 18: { + group_.AddEntriesFrom(ref input, _map_group_codec); + break; + } + case 26: { + items_.AddEntriesFrom(ref input, _map_items_codec); + break; + } + } + } + } + #endif + +} + +#endregion + + +#endregion Designer generated code diff --git a/src/Utils.cs b/src/Utils.cs index 9b189d6..9784f0d 100644 --- a/src/Utils.cs +++ b/src/Utils.cs @@ -18,7 +18,8 @@ public static class Utils { private static readonly Lazy CHttpClient = new (() => { var c = new HttpClient(new HttpClientHandler { - Proxy = new WebProxy("http://127.0.0.1:8888") + Proxy = new WebProxy("http://127.0.0.1:8888"), + AutomaticDecompression = DecompressionMethods.Brotli | DecompressionMethods.GZip }) { DefaultRequestHeaders = { UserAgent = { @@ -47,7 +48,6 @@ public static class Utils { using var dInput = new GZipStream(input, CompressionMode.Decompress); ci = CacheItem.Parser.ParseFrom(dInput); msg.Headers.TryAddWithoutValidation("If-None-Match", $"{ci.Etag}"); - } } using var response = CHttpClient.Value.Send(msg); @@ -151,6 +151,12 @@ public static class Utils { Marshal.FreeHGlobal(fnPtr); return path; } + + // ReSharper disable once UnusedMethodReturnValue.Global + public static bool TryDisableQuickEdit() { + var handle = Native.GetStdHandle(); + return Native.GetConsoleMode(handle, out var mode) && Native.SetConsoleMode(handle, mode&~64); + } public static void CheckGenshinIsRunning() { Process.EnterDebugMode(); @@ -183,11 +189,19 @@ public static class Utils { if (!Injector.CreateProcess(exePath, out var hProcess, out var hThread, out var pid)) { Environment.Exit(new Win32Exception().PrintMsgAndReturnErrCode("ICreateProcess fail")); } - if (Injector.LoadLibraryAndInject(hProcess, GlobalVars.LibName) != 0) { + if (Injector.LoadLibraryAndInject(hProcess, Path.GetFullPath(GlobalVars.LibName)) != 0) { if (!Native.TerminateProcess(hProcess, 0)) { Environment.Exit(new Win32Exception().PrintMsgAndReturnErrCode("TerminateProcess fail")); } } + var proc = Process.GetProcessById(Convert.ToInt32(pid)); + proc.EnableRaisingEvents = true; + proc.Exited += (_, _) => { + if (GlobalVars.UnexpectedExit) { + Console.WriteLine("游戏进程异常退出"); + Environment.Exit(114514); + } + }; if (Native.ResumeThread(hThread) == 0xFFFFFFFF) { var e = new Win32Exception(); if (!Native.TerminateProcess(hProcess, 0)) { @@ -198,14 +212,6 @@ public static class Utils { if (!Native.CloseHandle(hProcess)) { Environment.Exit(new Win32Exception().PrintMsgAndReturnErrCode("CloseHandle fail")); } - var proc = Process.GetProcessById(Convert.ToInt32(pid)); - proc.EnableRaisingEvents = true; - proc.Exited += (_, _) => { - if (GlobalVars.UnexpectedExit) { - Console.WriteLine("游戏进程异常退出"); - Environment.Exit(114514); - } - }; var ts = new ThreadStart(() => { var server = new NamedPipeServerStream(GlobalVars.PipeName); server.WaitForConnection(); diff --git a/src/Win32/Native.cs b/src/Win32/Native.cs index 11f14d1..51ac2bb 100644 --- a/src/Win32/Native.cs +++ b/src/Win32/Native.cs @@ -75,6 +75,18 @@ public static class Native { [DllImport("kernel32.dll")] public static extern IntPtr GetConsoleWindow(); + // ReSharper disable once InconsistentNaming + private const int STD_INPUT_HANDLE = -10; + + [DllImport("kernel32.dll", SetLastError = true)] + public static extern IntPtr GetStdHandle(int nStdHandle = STD_INPUT_HANDLE); + + [DllImport("kernel32.dll", SetLastError = true)] + public static extern bool GetConsoleMode(IntPtr handle, out int lpMode); + + [DllImport("kernel32.dll", SetLastError = true)] + public static extern bool SetConsoleMode(IntPtr handle, int ioMode); + [DllImport("comdlg32.dll", SetLastError = true)] public static extern int CommDlgExtendedError();