From c42a2b2921e69e5056f3caaca7704446af60a38c Mon Sep 17 00:00:00 2001 From: Linwenxuan Date: Fri, 1 Mar 2024 22:23:00 +0800 Subject: [PATCH] [Core] Fixed Compat type of ImageEntity for CustomFace(GroupImage) --- .../Internal/Context/Uploader/ImageUploader.cs | 4 ++-- .../Event/Message/ImageGroupUploadEvent.cs | 6 +++--- .../Element/Implementation/CustomFace.cs | 2 +- .../Service/Message/ImageGroupUploadService.cs | 4 ++-- Lagrange.Core/Message/Entity/ImageEntity.cs | 17 +++++++++++++---- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs b/Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs index 372cce0a7..6416c29fa 100644 --- a/Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs +++ b/Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs @@ -38,7 +38,7 @@ public async Task UploadPrivate(ContextCollection context, MessageChain chain, I if (!hwSuccess) throw new Exception(); image.MsgInfo = metaResult.MsgInfo; // directly constructed by Tencent's BDH Server - image.Compat = metaResult.Compat; // for legacy QQ + image.CompatImage = metaResult.Compat; // for legacy QQ await image.ImageStream.DisposeAsync(); } } @@ -71,7 +71,7 @@ public async Task UploadGroup(ContextCollection context, MessageChain chain, IMe if (!hwSuccess) throw new Exception(); image.MsgInfo = metaResult.MsgInfo; // directly constructed by Tencent's BDH Server - image.Compat = metaResult.Compat; // for legacy QQ + image.CompatFace = metaResult.Compat; // for legacy QQ await image.ImageStream.DisposeAsync(); } } diff --git a/Lagrange.Core/Internal/Event/Message/ImageGroupUploadEvent.cs b/Lagrange.Core/Internal/Event/Message/ImageGroupUploadEvent.cs index 4bd3a8390..85f9e7b58 100644 --- a/Lagrange.Core/Internal/Event/Message/ImageGroupUploadEvent.cs +++ b/Lagrange.Core/Internal/Event/Message/ImageGroupUploadEvent.cs @@ -18,7 +18,7 @@ internal class ImageGroupUploadEvent : ProtocolEvent public List Network { get; } - public NotOnlineImage Compat { get; } + public CustomFace Compat { get; } private ImageGroupUploadEvent(ImageEntity entity, uint groupUin) : base(true) { @@ -26,7 +26,7 @@ private ImageGroupUploadEvent(ImageEntity entity, uint groupUin) : base(true) GroupUin = groupUin; } - private ImageGroupUploadEvent(int resultCode, string uKey, MsgInfo msgInfo, List network, NotOnlineImage compat) : base(resultCode) + private ImageGroupUploadEvent(int resultCode, string uKey, MsgInfo msgInfo, List network, CustomFace compat) : base(resultCode) { UKey = uKey; MsgInfo = msgInfo; @@ -37,6 +37,6 @@ private ImageGroupUploadEvent(int resultCode, string uKey, MsgInfo msgInfo, List public static ImageGroupUploadEvent Create(ImageEntity entity, uint groupUin) => new(entity, groupUin); - public static ImageGroupUploadEvent Result(int resultCode, string uKey, MsgInfo msgInfo, List network, NotOnlineImage compat) + public static ImageGroupUploadEvent Result(int resultCode, string uKey, MsgInfo msgInfo, List network, CustomFace compat) => new(resultCode, uKey, msgInfo, network, compat); } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/Message/Element/Implementation/CustomFace.cs b/Lagrange.Core/Internal/Packets/Message/Element/Implementation/CustomFace.cs index 8b4aed55f..a4f7d97ac 100644 --- a/Lagrange.Core/Internal/Packets/Message/Element/Implementation/CustomFace.cs +++ b/Lagrange.Core/Internal/Packets/Message/Element/Implementation/CustomFace.cs @@ -75,5 +75,5 @@ internal class CustomFace [ProtoMember(33)] public int X400Height { get; set; } - [ProtoMember(34)] public CustomFaceExtra? PbReserve { get; set; } + [ProtoMember(34)] public byte[]? PbReserve { get; set; } } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Service/Message/ImageGroupUploadService.cs b/Lagrange.Core/Internal/Service/Message/ImageGroupUploadService.cs index ff811cdff..8543cb269 100644 --- a/Lagrange.Core/Internal/Service/Message/ImageGroupUploadService.cs +++ b/Lagrange.Core/Internal/Service/Message/ImageGroupUploadService.cs @@ -88,7 +88,7 @@ protected override bool Build(ImageGroupUploadEvent input, BotKeystore keystore, TryFastUploadCompleted = true, SrvSendMsg = false, ClientRandomId = (ulong)Random.Shared.Next(), - CompatQMsgSceneType = 1, + CompatQMsgSceneType = 2, ExtBizInfo = new ExtBizInfo { Pic = new PicExtBizInfo @@ -118,7 +118,7 @@ protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo app { var packet = Serializer.Deserialize>(input.AsSpan()); var upload = packet.Body.Upload; - var compat = Serializer.Deserialize(upload.CompatQMsg.AsSpan()); + var compat = Serializer.Deserialize(upload.CompatQMsg.AsSpan()); output = ImageGroupUploadEvent.Result((int)packet.ErrorCode, upload.UKey, upload.MsgInfo, upload.IPv4s, compat); extraEvents = null; diff --git a/Lagrange.Core/Message/Entity/ImageEntity.cs b/Lagrange.Core/Message/Entity/ImageEntity.cs index 0ef8e4370..208611f98 100644 --- a/Lagrange.Core/Message/Entity/ImageEntity.cs +++ b/Lagrange.Core/Message/Entity/ImageEntity.cs @@ -2,6 +2,7 @@ using Lagrange.Core.Internal.Packets.Message.Component.Extra; using Lagrange.Core.Internal.Packets.Message.Element; using Lagrange.Core.Internal.Packets.Message.Element.Implementation; +using Lagrange.Core.Internal.Packets.Message.Element.Implementation.Extra; using Lagrange.Core.Internal.Packets.Service.Oidb.Common; using Lagrange.Core.Utility.Extension; using ProtoBuf; @@ -33,7 +34,9 @@ public class ImageEntity : IMessageEntity internal MsgInfo? MsgInfo { get; set; } - internal NotOnlineImage? Compat { get; set; } + internal NotOnlineImage? CompatImage { get; set; } + + internal CustomFace? CompatFace { get; set; } public ImageEntity() { } @@ -52,9 +55,10 @@ public ImageEntity(byte[] file) IEnumerable IMessageEntity.PackElement() { var common = MsgInfo.Serialize(); - return new Elem[] + + var elems = new Elem[] { - new() { NotOnlineImage = Compat }, + new(), new() { CommonElem = new CommonElem @@ -65,6 +69,11 @@ IEnumerable IMessageEntity.PackElement() } } }; + + if (CompatFace != null) elems[0].CustomFace = CompatFace; + if (CompatImage != null) elems[0].NotOnlineImage = CompatImage; + + return elems; } IMessageEntity? IMessageEntity.UnpackElement(Elem elems) @@ -84,7 +93,7 @@ IEnumerable IMessageEntity.PackElement() if (elems.CustomFace is { } face) { - if (face.PbReserve?.Hash != null) + if (face.PbReserve != null && Serializer.Deserialize(face.PbReserve.AsSpan()).Hash != null) { return new ImageEntity // NTQQ Mobile {