This commit is contained in:
HolographicHat
2022-07-14 16:47:05 +08:00
parent 31e23de4d6
commit d5a20b44d5
10 changed files with 62 additions and 56 deletions

View File

@@ -9,6 +9,7 @@
<ApplicationManifest>res\app.manifest</ApplicationManifest>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>

BIN
icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

View File

@@ -8,7 +8,7 @@ using std::to_string;
HWND unityWnd = 0;
HANDLE hPipe = 0;
std::set<UINT16> PacketWhitelist = { 109, 131, 141, 2668, 32, 17 };
std::set<UINT16> 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<UINT16>(data->vector, 2) == 2668) {
if (ReadMapped<UINT16>(data->vector, 2) == 2676) {
auto headLength = ReadMapped<UINT16>(data->vector, 4);
auto dataLength = ReadMapped<UINT32>(data->vector, 6);
auto iStr = Genshin::Convert_ToBase64String(data, 10 + headLength, dataLength, nullptr);
auto cStr = IlStringToString(reinterpret_cast<Il2CppString*>(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

View File

@@ -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"
}

View File

@@ -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));

View File

@@ -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
}

View File

@@ -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<AchievementAllDataNotify> act = num switch {
((Action<AchievementAllDataNotify>) (num switch {
1 => ToSnapGenshin,
2 => ToPaimon,
3 => ToSeelie,
4 => ToCSV,
7 => ToRawJson,
_ => ToCocogoat
};
act(data);
})).Invoke(data);
}
private static void ToCocogoat(AchievementAllDataNotify data) {

View File

@@ -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);
}
}

View File

@@ -1,4 +1,4 @@
// <auto-generated>
// <auto-generated>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: AchievementAllDataNotify.proto
// </auto-generated>
@@ -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::IMessage<AchievementA
}
/// <summary>Field number for the "list" field.</summary>
public const int ListFieldNumber = 5;
public const int ListFieldNumber = 4;
private static readonly pb::FieldCodec<global::AchievementAllDataNotify.Types.Achievement> _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<global::AchievementAllDataNotify.Types.Achievement> list_ = new pbc::RepeatedField<global::AchievementAllDataNotify.Types.Achievement>();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
@@ -188,7 +188,7 @@ public sealed partial class AchievementAllDataNotify : pb::IMessage<AchievementA
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 42: {
case 34: {
list_.AddEntriesFrom(input, _repeated_list_codec);
break;
}
@@ -207,7 +207,7 @@ public sealed partial class AchievementAllDataNotify : pb::IMessage<AchievementA
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 42: {
case 34: {
list_.AddEntriesFrom(ref input, _repeated_list_codec);
break;
}
@@ -270,7 +270,7 @@ public sealed partial class AchievementAllDataNotify : pb::IMessage<AchievementA
}
/// <summary>Field number for the "id" field.</summary>
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::IMessage<AchievementA
}
/// <summary>Field number for the "current" field.</summary>
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::IMessage<AchievementA
}
/// <summary>Field number for the "total" field.</summary>
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::IMessage<AchievementA
}
/// <summary>Field number for the "timestamp" field.</summary>
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<AchievementA
output.WriteRawMessage(this);
#else
if (Total != 0) {
output.WriteRawTag(48);
output.WriteRawTag(64);
output.WriteUInt32(Total);
}
if (Current != 0) {
output.WriteRawTag(88);
output.WriteUInt32(Current);
}
if (Timestamp != 0) {
output.WriteRawTag(96);
output.WriteRawTag(88);
output.WriteUInt32(Timestamp);
}
if (Current != 0) {
output.WriteRawTag(96);
output.WriteUInt32(Current);
}
if (Status != global::AchievementAllDataNotify.Types.Achievement.Types.Status.Invalid) {
output.WriteRawTag(104);
output.WriteEnum((int) Status);
}
if (Id != 0) {
output.WriteRawTag(120);
output.WriteRawTag(112);
output.WriteUInt32(Id);
}
if (_unknownFields != null) {
@@ -410,23 +410,23 @@ public sealed partial class AchievementAllDataNotify : pb::IMessage<AchievementA
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (Total != 0) {
output.WriteRawTag(48);
output.WriteRawTag(64);
output.WriteUInt32(Total);
}
if (Current != 0) {
output.WriteRawTag(88);
output.WriteUInt32(Current);
}
if (Timestamp != 0) {
output.WriteRawTag(96);
output.WriteRawTag(88);
output.WriteUInt32(Timestamp);
}
if (Current != 0) {
output.WriteRawTag(96);
output.WriteUInt32(Current);
}
if (Status != global::AchievementAllDataNotify.Types.Achievement.Types.Status.Invalid) {
output.WriteRawTag(104);
output.WriteEnum((int) Status);
}
if (Id != 0) {
output.WriteRawTag(120);
output.WriteRawTag(112);
output.WriteUInt32(Id);
}
if (_unknownFields != null) {
@@ -496,23 +496,23 @@ public sealed partial class AchievementAllDataNotify : pb::IMessage<AchievementA
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 48: {
case 64: {
Total = input.ReadUInt32();
break;
}
case 88: {
Current = input.ReadUInt32();
Timestamp = input.ReadUInt32();
break;
}
case 96: {
Timestamp = input.ReadUInt32();
Current = input.ReadUInt32();
break;
}
case 104: {
Status = (global::AchievementAllDataNotify.Types.Achievement.Types.Status) input.ReadEnum();
break;
}
case 120: {
case 112: {
Id = input.ReadUInt32();
break;
}
@@ -531,23 +531,23 @@ public sealed partial class AchievementAllDataNotify : pb::IMessage<AchievementA
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 48: {
case 64: {
Total = input.ReadUInt32();
break;
}
case 88: {
Current = input.ReadUInt32();
Timestamp = input.ReadUInt32();
break;
}
case 96: {
Timestamp = input.ReadUInt32();
Current = input.ReadUInt32();
break;
}
case 104: {
Status = (global::AchievementAllDataNotify.Types.Achievement.Types.Status) input.ReadEnum();
break;
}
case 120: {
case 112: {
Id = input.ReadUInt32();
break;
}

View File

@@ -101,7 +101,7 @@ public static class Utils {
public static void LoadConfig() {
var conf = JsonNode.Parse(File.ReadAllText(GlobalVars.ConfigFileName))!;
var path = conf["location"];
if (path == null || CheckGamePathValid(path.GetValue<string>())) {
if (path == null || !CheckGamePathValid(path.GetValue<string>())) {
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<string, bool> 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)) {