diff --git a/YaeAchievement.csproj b/YaeAchievement.csproj index 36d3598..c4eb518 100644 --- a/YaeAchievement.csproj +++ b/YaeAchievement.csproj @@ -9,6 +9,7 @@ res\app.manifest 2.0.0 2.0.0 + icon.ico diff --git a/icon.ico b/icon.ico new file mode 100644 index 0000000..91256b2 Binary files /dev/null and b/icon.ico differ diff --git a/lib/src/dllmain.cpp b/lib/src/dllmain.cpp index 0967963..0b9d04f 100644 --- a/lib/src/dllmain.cpp +++ b/lib/src/dllmain.cpp @@ -8,7 +8,7 @@ using std::to_string; HWND unityWnd = 0; HANDLE hPipe = 0; -std::set PacketWhitelist = { 109, 131, 141, 2668, 32, 17 }; +std::set PacketWhitelist = { 172, 198, 112, 2676, 7, 21 }; // ping, token, loginreq bool OnPacket(KcpPacket* pkt) { if (pkt->data == nullptr) return true; @@ -28,11 +28,11 @@ bool OnPacket(KcpPacket* pkt) { delete[] data; return false; } - if (ReadMapped(data->vector, 2) == 2668) { + if (ReadMapped(data->vector, 2) == 2676) { auto headLength = ReadMapped(data->vector, 4); auto dataLength = ReadMapped(data->vector, 6); auto iStr = Genshin::Convert_ToBase64String(data, 10 + headLength, dataLength, nullptr); - auto cStr = IlStringToString(reinterpret_cast(iStr)) + "\n"; + auto cStr = IlStringToString(iStr) + "\n"; WriteFile(hPipe, cStr.c_str(), cStr.length(), nullptr, nullptr); CloseHandle(hPipe); ExitProcess(0); @@ -57,10 +57,8 @@ namespace Hook { } void Run(HMODULE* phModule) { - #ifdef _DEBUG - AllocConsole(); - freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); - #endif + //AllocConsole(); + //freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); while ( GetModuleHandle("UserAssembly.dll") == nullptr || (unityWnd = FindMainWindowByPID(GetCurrentProcessId())) == 0 diff --git a/lib/src/il2cpp-appdata.h b/lib/src/il2cpp-appdata.h index dd232f1..33e17b3 100644 --- a/lib/src/il2cpp-appdata.h +++ b/lib/src/il2cpp-appdata.h @@ -7,7 +7,7 @@ #undef DO_API // Application-specific functions -#define DO_APP_FUNC(a, r, n, p) extern r (*n) p +#define DO_APP_FUNC(ca, oa, r, n, p) extern r (*n) p namespace Genshin { #include "il2cpp-functions.h" } diff --git a/lib/src/il2cpp-functions.h b/lib/src/il2cpp-functions.h index a8c7186..e503775 100644 --- a/lib/src/il2cpp-functions.h +++ b/lib/src/il2cpp-functions.h @@ -1,7 +1,7 @@ using namespace Genshin; -DO_APP_FUNC(0x04E9B0A0, String*, Convert_ToBase64String, (ByteArray* value, int offset, int length, void* method)); -DO_APP_FUNC(0x015913C0, void, Packet_Xor, (ByteArray** data, int length, void* method)); +DO_APP_FUNC(0x05E24240, 0x04EA1150, Il2CppString*, Convert_ToBase64String, (ByteArray* value, int offset, int length, void* method)); +DO_APP_FUNC(0x018280A0, 0x018293F0, void, Packet_Xor, (ByteArray** data, int length, void* method)); -DO_APP_FUNC(0x016F70C0, int, Kcp_Send, (void* client, KcpPacket* pkt, void* method)); -DO_APP_FUNC(0x02AB08D0, bool, Kcp_Recv, (void* client, ClientKcpEvent* evt, void* method)); +DO_APP_FUNC(0x0193BA70, 0x0193C7D0, int, Kcp_Send, (void* client, KcpPacket* pkt, void* method)); +DO_APP_FUNC(0x029EF820, 0x029F05C0, bool, Kcp_Recv, (void* client, ClientKcpEvent* evt, void* method)); diff --git a/lib/src/il2cpp-init.cpp b/lib/src/il2cpp-init.cpp index 06e07be..635e011 100644 --- a/lib/src/il2cpp-init.cpp +++ b/lib/src/il2cpp-init.cpp @@ -6,7 +6,7 @@ #include "il2cpp-api-functions.h" #undef DO_API -#define DO_APP_FUNC(a, r, n, p) r (*n) p +#define DO_APP_FUNC(ca, oa, r, n, p) r (*n) p namespace Genshin { #include "il2cpp-functions.h" } @@ -20,12 +20,15 @@ UINT64 GetAddressByExports(HMODULE base, const char* name) { } void InitIL2CPP() { + TCHAR szFileName[MAX_PATH]; + GetModuleFileName(NULL, szFileName, MAX_PATH); + auto isCN = string(szFileName).contains("YuanShen.exe"); auto hBase = GetModuleHandle("UserAssembly.dll"); auto bAddr = (UINT64)hBase; #define DO_API(r, n, p) n = (r (*) p) GetAddressByExports(hBase, #n); #include "il2cpp-api-functions.h" #undef DO_API - #define DO_APP_FUNC(a, r, n, p) n = (r (*) p)(bAddr + a) + #define DO_APP_FUNC(ca, oa, r, n, p) n = (r (*) p)(bAddr + (isCN ? ca : oa)) #include "il2cpp-functions.h" #undef DO_APP_FUNC } diff --git a/src/Export.cs b/src/Export.cs index 539dbe2..7f5194a 100644 --- a/src/Export.cs +++ b/src/Export.cs @@ -18,15 +18,14 @@ public static class Export { [4] 表格文件 输入一个数字(0-4): ".Split("\n").Select(s => s.Trim()).JoinToString("\n") + " "); if (!int.TryParse(Console.ReadLine(), out var num)) num = 0; - Action act = num switch { + ((Action) (num switch { 1 => ToSnapGenshin, 2 => ToPaimon, 3 => ToSeelie, 4 => ToCSV, 7 => ToRawJson, _ => ToCocogoat - }; - act(data); + })).Invoke(data); } private static void ToCocogoat(AchievementAllDataNotify data) { diff --git a/src/Logger.cs b/src/Logger.cs index 8da3f93..5ee8b90 100644 --- a/src/Logger.cs +++ b/src/Logger.cs @@ -28,7 +28,7 @@ public static class Logger { private static void Log(string msg, Level level) { if (level >= GlobalVars.LogLevel) { - Console.WriteLine($"{DateTime.Now:MM/dd HH:mm:ss} {level.ToString().ToUpper().PadLeft(5)} : {msg}"); + Console.WriteLine(msg); } } diff --git a/src/Proto/AchievementAllDataNotify.cs b/src/Proto/AchievementAllDataNotify.cs index b045592..8fbb0af 100644 --- a/src/Proto/AchievementAllDataNotify.cs +++ b/src/Proto/AchievementAllDataNotify.cs @@ -1,4 +1,4 @@ -// +// // Generated by the protocol buffer compiler. DO NOT EDIT! // source: AchievementAllDataNotify.proto // @@ -23,11 +23,11 @@ public static partial class AchievementAllDataNotifyReflection { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( "Ch5BY2hpZXZlbWVudEFsbERhdGFOb3RpZnkucHJvdG8iowIKGEFjaGlldmVt", - "ZW50QWxsRGF0YU5vdGlmeRIzCgRsaXN0GAUgAygLMiUuQWNoaWV2ZW1lbnRB", + "ZW50QWxsRGF0YU5vdGlmeRIzCgRsaXN0GAQgAygLMiUuQWNoaWV2ZW1lbnRB", "bGxEYXRhTm90aWZ5LkFjaGlldmVtZW50GtEBCgtBY2hpZXZlbWVudBIKCgJp", - "ZBgPIAEoDRI8CgZzdGF0dXMYDSABKA4yLC5BY2hpZXZlbWVudEFsbERhdGFO", - "b3RpZnkuQWNoaWV2ZW1lbnQuU3RhdHVzEg8KB2N1cnJlbnQYCyABKA0SDQoF", - "dG90YWwYBiABKA0SEQoJdGltZXN0YW1wGAwgASgNIkUKBlN0YXR1cxILCgdJ", + "ZBgOIAEoDRI8CgZzdGF0dXMYDSABKA4yLC5BY2hpZXZlbWVudEFsbERhdGFO", + "b3RpZnkuQWNoaWV2ZW1lbnQuU3RhdHVzEg8KB2N1cnJlbnQYDCABKA0SDQoF", + "dG90YWwYCCABKA0SEQoJdGltZXN0YW1wGAsgASgNIkUKBlN0YXR1cxILCgdJ", "TlZBTElEEAASDgoKVU5GSU5JU0hFRBABEgwKCEZJTklTSEVEEAISEAoMUkVX", "QVJEX1RBS0VOEANiBnByb3RvMw==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, @@ -85,9 +85,9 @@ public sealed partial class AchievementAllDataNotify : pb::IMessageField number for the "list" field. - public const int ListFieldNumber = 5; + public const int ListFieldNumber = 4; private static readonly pb::FieldCodec _repeated_list_codec - = pb::FieldCodec.ForMessage(42, global::AchievementAllDataNotify.Types.Achievement.Parser); + = pb::FieldCodec.ForMessage(34, global::AchievementAllDataNotify.Types.Achievement.Parser); private readonly pbc::RepeatedField list_ = new pbc::RepeatedField(); [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] @@ -188,7 +188,7 @@ public sealed partial class AchievementAllDataNotify : pb::IMessageField number for the "id" field. - public const int IdFieldNumber = 15; + public const int IdFieldNumber = 14; private uint id_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] @@ -294,7 +294,7 @@ public sealed partial class AchievementAllDataNotify : pb::IMessageField number for the "current" field. - public const int CurrentFieldNumber = 11; + public const int CurrentFieldNumber = 12; private uint current_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] @@ -306,7 +306,7 @@ public sealed partial class AchievementAllDataNotify : pb::IMessageField number for the "total" field. - public const int TotalFieldNumber = 6; + public const int TotalFieldNumber = 8; private uint total_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] @@ -318,7 +318,7 @@ public sealed partial class AchievementAllDataNotify : pb::IMessageField number for the "timestamp" field. - public const int TimestampFieldNumber = 12; + public const int TimestampFieldNumber = 11; private uint timestamp_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] @@ -380,23 +380,23 @@ public sealed partial class AchievementAllDataNotify : pb::IMessage())) { + if (path == null || !CheckGamePathValid(path.GetValue())) { GlobalVars.GamePath = SelectGameExecutable(); conf["location"] = GlobalVars.GamePath; File.WriteAllText(GlobalVars.ConfigFileName, conf.ToJsonString()); @@ -130,7 +130,7 @@ public static class Utils { } } if (info.EnableLibDownload) { - File.WriteAllBytes("YaeLib.dll", GetBucketFileAsByteArray("schicksal/lib.dll")); + File.WriteAllBytes(GlobalVars.LibName, GetBucketFileAsByteArray("schicksal/lib.dll")); } } @@ -239,10 +239,12 @@ public static class Utils { // ReSharper disable once UnusedMethodReturnValue.Global public static Thread StartAndWaitResult(string exePath, Func onReceive) { + const string lib = "C:/ProgramData/yae.dll"; + File.Copy(Path.GetFullPath(GlobalVars.LibName), lib, true); if (!Injector.CreateProcess(exePath, out var hProcess, out var hThread, out var pid)) { Environment.Exit(new Win32Exception().PrintMsgAndReturnErrCode("ICreateProcess fail")); } - if (Injector.LoadLibraryAndInject(hProcess, Path.GetFullPath(GlobalVars.LibName)) != 0) { + if (Injector.LoadLibraryAndInject(hProcess, lib) != 0) { if (!Native.TerminateProcess(hProcess, 0)) { Environment.Exit(new Win32Exception().PrintMsgAndReturnErrCode("TerminateProcess fail")); } @@ -257,6 +259,9 @@ public static class Utils { Environment.Exit(114514); } }; + AppDomain.CurrentDomain.ProcessExit += (_, _) => { + File.Delete(lib); + }; if (Native.ResumeThread(hThread) == 0xFFFFFFFF) { var e = new Win32Exception(); if (!Native.TerminateProcess(hProcess, 0)) {