AquaDX/AquaMai/AquaMai.Mods/GameSystem/RemoveEncryption.cs

64 lines
2.3 KiB
C#
Raw Normal View History

2024-07-09 18:11:06 +08:00
using System.Collections.Generic;
2024-09-11 01:35:17 +08:00
using System.Linq;
2024-07-09 18:11:06 +08:00
using System.Reflection;
using AquaMai.Config.Attributes;
2024-07-09 18:11:06 +08:00
using HarmonyLib;
using Net.Packet;
namespace AquaMai.Mods.GameSystem;
2024-07-09 18:11:06 +08:00
[ConfigSection(
en: """
If you are using an unmodified client, requests to the server will be encrypted by default, but requests to the private server should not be encrypted.
With this option enabled, the connection will not be encrypted, and the suffix added by different versions of the client to the API names are also removed.
Please keep this option enabled normally.
""",
zh: """
API
""",
defaultOn: true)]
2024-07-09 18:11:06 +08:00
public class RemoveEncryption
{
[HarmonyPrefix]
2024-09-11 01:35:17 +08:00
[HarmonyPatch(typeof(Packet), "Obfuscator", typeof(string))]
public static bool PreObfuscator(string srcStr, ref string __result)
2024-07-09 18:11:06 +08:00
{
__result = srcStr.Replace("MaimaiExp", "").Replace("MaimaiChn", "");
return false;
}
[HarmonyPatch]
public class EncryptDecrypt
2024-07-09 18:11:06 +08:00
{
public static IEnumerable<MethodBase> TargetMethods()
{
var methods = AccessTools.TypeByName("Net.CipherAES").GetMethods();
return
[
methods.FirstOrDefault(it => it.Name == "Encrypt" && it.IsPublic),
methods.FirstOrDefault(it => it.Name == "Decrypt" && it.IsPublic)
];
2024-07-09 18:11:06 +08:00
}
public static bool Prefix(object[] __args, ref object __result)
2024-07-09 18:11:06 +08:00
{
if (__args.Length == 1)
{
// public static byte[] Encrypt(byte[] data)
// public static byte[] Decrypt(byte[] encryptData)
__result = __args[0];
}
else if (__args.Length == 2)
{
// public static bool Encrypt(byte[] data, out byte[] encryptData)
// public static bool Decrypt(byte[] encryptData, out byte[] plainData)
__args[1] = __args[0];
__result = true;
}
2024-09-11 01:35:17 +08:00
return false;
}
2024-07-09 18:11:06 +08:00
}
}