3.1 native lib

This commit is contained in:
HolographicHat
2022-09-27 19:02:13 +08:00
parent 656589bc80
commit 07a08f56d4
6 changed files with 52 additions and 24 deletions

View File

@@ -105,7 +105,7 @@
<AdditionalDependencies>detours-x64.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>detours-x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
<PostBuildEvent> <PostBuildEvent>
<Command>copy $(TargetPath) $(ProjectDir)..\bin\Debug\net6.0</Command> <Command>copy $(TargetPath) $(ProjectDir)..\bin\Debug\net6.0\win-x64</Command>
</PostBuildEvent> </PostBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>

View File

@@ -16,7 +16,7 @@ bool OnPacket(KcpPacket* pkt) {
auto data = (ByteArray*)new BYTE[len + 32]; auto data = (ByteArray*)new BYTE[len + 32];
data->max_length = len; data->max_length = len;
memcpy(data->vector, pkt->data, len); memcpy(data->vector, pkt->data, len);
Genshin::Packet_Xor(&data, len, nullptr); Genshin::XorEncrypt(&data, len, nullptr);
if (ReadMapped<UINT16>(data->vector, 0) != 0x4567) { if (ReadMapped<UINT16>(data->vector, 0) != 0x4567) {
delete[] data; delete[] data;
return true; return true;
@@ -32,7 +32,7 @@ bool OnPacket(KcpPacket* pkt) {
if (ReadMapped<UINT16>(data->vector, 2) == 2676) { if (ReadMapped<UINT16>(data->vector, 2) == 2676) {
auto headLength = ReadMapped<UINT16>(data->vector, 4); auto headLength = ReadMapped<UINT16>(data->vector, 4);
auto dataLength = ReadMapped<UINT32>(data->vector, 6); auto dataLength = ReadMapped<UINT32>(data->vector, 6);
auto iStr = Genshin::Convert_ToBase64String(data, 10 + headLength, dataLength, nullptr); auto iStr = Genshin::ToBase64String(data, 10 + headLength, dataLength, nullptr);
auto cStr = IlStringToString(iStr) + "\n"; auto cStr = IlStringToString(iStr) + "\n";
WriteFile(hPipe, cStr.c_str(), cStr.length(), nullptr, nullptr); WriteFile(hPipe, cStr.c_str(), cStr.length(), nullptr, nullptr);
CloseHandle(hPipe); CloseHandle(hPipe);
@@ -44,18 +44,18 @@ bool OnPacket(KcpPacket* pkt) {
namespace Hook { namespace Hook {
int Kcp_Send(void* client, KcpPacket* pkt, void* method) { int KcpSend(void* client, KcpPacket* pkt, void* method) {
return OnPacket(pkt) ? CALL_ORIGIN(Kcp_Send, client, pkt, method) : 0; return OnPacket(pkt) ? CALL_ORIGIN(KcpSend, client, pkt, method) : 0;
} }
void MonoLoginMainPage__set_version(void* obj, Il2CppString* value, void* method) { void SetVersion(void* obj, Il2CppString* value, void* method) {
auto version = IlStringToString(value); auto version = IlStringToString(value);
value = string_new(version + " YaeAchievement"); value = string_new(version + " YaeAchievement");
CALL_ORIGIN(MonoLoginMainPage__set_version, obj, value, method); CALL_ORIGIN(SetVersion, obj, value, method);
} }
bool Kcp_Recv(void* client, ClientKcpEvent* evt, void* method) { bool KcpRecv(void* client, ClientKcpEvent* evt, void* method) {
auto result = CALL_ORIGIN(Kcp_Recv, client, evt, method); auto result = CALL_ORIGIN(KcpRecv, client, evt, method);
if (result == 0 || evt->fields.type != KcpEventType::EventRecvMsg) { if (result == 0 || evt->fields.type != KcpEventType::EventRecvMsg) {
return result; return result;
} }
@@ -68,29 +68,33 @@ namespace Hook {
if (signatures.count(type)) { if (signatures.count(type)) {
return GCHandle_GetObject<ByteArray>(signatures[type]); return GCHandle_GetObject<ByteArray>(signatures[type]);
} }
auto encoder = Genshin::Encoding_GetDefault(nullptr);
auto result = CALL_ORIGIN(UnityEngine_RecordUserData, type); auto result = CALL_ORIGIN(UnityEngine_RecordUserData, type);
auto str = Genshin::Encoding_GetString(encoder, result, nullptr);
printf("RecordUserData%d: %s\n", type, IlStringToString(str).c_str());
signatures[type] = GCHandle_New(result, true); signatures[type] = GCHandle_New(result, true);
return result; return result;
} }
} }
void Run(HMODULE* phModule) { void Run(HMODULE* phModule) {
//AllocConsole(); AllocConsole();
//freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
while ( while (
GetModuleHandle("UserAssembly.dll") == nullptr || GetModuleHandle("UserAssembly.dll") == nullptr ||
(unityWnd = FindMainWindowByPID(GetCurrentProcessId())) == 0 (unityWnd = FindMainWindowByPID(GetCurrentProcessId())) == 0
) { ) {
Sleep(1000); Sleep(1000);
} }
Sleep(5000);
InitIL2CPP(); InitIL2CPP();
HookManager::install(Genshin::UnityEngine_RecordUserData, Hook::UnityEngine_RecordUserData); HookManager::install(Genshin::UnityEngine_RecordUserData, Hook::UnityEngine_RecordUserData);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
Genshin::Application_RecordUserData(i, nullptr); Genshin::RecordUserData(i, nullptr);
} }
HookManager::install(Genshin::Kcp_Send, Hook::Kcp_Send); HookManager::install(Genshin::KcpSend, Hook::KcpSend);
HookManager::install(Genshin::Kcp_Recv, Hook::Kcp_Recv); HookManager::install(Genshin::KcpRecv, Hook::KcpRecv);
HookManager::install(Genshin::MonoLoginMainPage__set_version, Hook::MonoLoginMainPage__set_version); HookManager::install(Genshin::SetVersion, Hook::SetVersion);
hPipe = CreateFile(R"(\\.\pipe\YaeAchievementPipe)", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); hPipe = CreateFile(R"(\\.\pipe\YaeAchievementPipe)", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr);
if (hPipe == INVALID_HANDLE_VALUE) { if (hPipe == INVALID_HANDLE_VALUE) {
Win32ErrorDialog(1001); Win32ErrorDialog(1001);

View File

@@ -1,10 +1,33 @@
using namespace Genshin; using namespace Genshin;
DO_APP_FUNC(0x05254960, 0x052544E0, Il2CppString*, Convert_ToBase64String, (ByteArray* value, int offset, int length, void* method)); // DO_APP_FUNC(CN_OFFSET, OS_OFFSET, RETURN, FUNC_NAME, (ARGS...));
DO_APP_FUNC(0x020127B0, 0x02012D40, void, Packet_Xor, (ByteArray** data, int length, void* method));
DO_APP_FUNC(0X01AD8E40, 0x01AD9740, void, MonoLoginMainPage__set_version, (void* obj, Il2CppString* value, void* method)); // N: System.Convert$ToBase64String
DO_APP_FUNC(0x05C25AC0, 0x05C25E60, ByteArray*, Application_RecordUserData, (int32_t nType, void* method)); // L: mscorlib
DO_APP_FUNC(0x051CC420, 0x051CCB00, Il2CppString*, ToBase64String, (ByteArray* value, int offset, int length, void* method));
DO_APP_FUNC(0x015C19D0, 0x015C2150, int, Kcp_Send, (void* client, KcpPacket* pkt, void* method)); // N: MoleMole.MonoLoginMainPage.version$set
DO_APP_FUNC(0x02CF31D0, 0x02CF33A0, bool, Kcp_Recv, (void* client, ClientKcpEvent* evt, void* method)); // L: Assembly-CSharp
DO_APP_FUNC(0X01E6CC80, 0x01E6CD90, void, SetVersion, (void* obj, Il2CppString* value, void* method));
// N: UnityEngine.Application$RecordUserData
// L: UnityEngine.CoreModule
DO_APP_FUNC(0x05AFD640, 0x05AFD630, ByteArray*, RecordUserData, (int32_t nType, void* method));
// N: MoleMole.Packet$XorEncrypt [Obfuscated]
// L: Assembly-CSharp
DO_APP_FUNC(0x0133C8A0, 0x0133D110, void, XorEncrypt, (ByteArray** data, int length, void* method));
// N: Kcp.KcpNative$kcp_client_send_packet [Obfuscated]
// L: Assembly-CSharp
DO_APP_FUNC(0x0094FBD0, 0x0094FCF0, int, KcpSend, (void* client, KcpPacket* pkt, void* method));
// N: MoleMole.KcpClient$TryDequeueEvent [Obfuscated]
// L: Assembly-CSharp
DO_APP_FUNC(0x026C8690, 0x026C9030, bool, KcpRecv, (void* client, ClientKcpEvent* evt, void* method));
DO_APP_FUNC(0x054AC8A0, 0x054AC8A0, void*, Encoding_GetDefault, (void* method));
// N: System.Text.Encoding$GetBytes
// L: mscorlib
DO_APP_FUNC(0x054AB010, 0x054AB010, Il2CppString*, Encoding_GetString, (void* obj, ByteArray* s, void* method));

View File

@@ -1,3 +1,3 @@
using namespace Genshin; using namespace Genshin;
DO_UNI_FUNC(0x00B9D710, 0x00B9D710, ByteArray*, UnityEngine_RecordUserData, (int32_t nType)); DO_UNI_FUNC(0x00BAB2B0, 0x00BAB2B0, ByteArray*, UnityEngine_RecordUserData, (int32_t nType));

View File

@@ -8,7 +8,7 @@ public static class AppConfig {
public static string GamePath { get; private set; } = null!; public static string GamePath { get; private set; } = null!;
internal static void Load(string argumentPath) { internal static void Load(string argumentPath) {
if (argumentPath == "auto" && File.Exists(argumentPath)) { if (argumentPath != "auto" && File.Exists(argumentPath)) {
GamePath = argumentPath; GamePath = argumentPath;
return; return;
} }

View File

@@ -102,7 +102,8 @@ public static class Utils {
} }
} }
if (useLocalLib) { if (useLocalLib) {
File.Copy(GlobalVars.LibPath, Path.Combine(GlobalVars.AppPath, "YaeLib.dll")); Console.WriteLine(@"Use local native lib.");
File.Copy(Path.Combine(GlobalVars.AppPath, "YaeAchievementLib.dll"), GlobalVars.LibPath, true);
} else if (info.EnableLibDownload) { } else if (info.EnableLibDownload) {
File.WriteAllBytes(GlobalVars.LibPath, GetBucketFileAsByteArray("schicksal/lib.dll")); File.WriteAllBytes(GlobalVars.LibPath, GetBucketFileAsByteArray("schicksal/lib.dll"));
} }