Skip to content

Commit

Permalink
[Core] Fixed Compat type of ImageEntity for CustomFace(GroupImage)
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan04 committed Mar 1, 2024
1 parent 8e205fc commit c42a2b2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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();
}
}
Expand Down
6 changes: 3 additions & 3 deletions Lagrange.Core/Internal/Event/Message/ImageGroupUploadEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ internal class ImageGroupUploadEvent : ProtocolEvent

public List<IPv4> Network { get; }

public NotOnlineImage Compat { get; }
public CustomFace Compat { get; }

private ImageGroupUploadEvent(ImageEntity entity, uint groupUin) : base(true)
{
Entity = entity;
GroupUin = groupUin;
}

private ImageGroupUploadEvent(int resultCode, string uKey, MsgInfo msgInfo, List<IPv4> network, NotOnlineImage compat) : base(resultCode)
private ImageGroupUploadEvent(int resultCode, string uKey, MsgInfo msgInfo, List<IPv4> network, CustomFace compat) : base(resultCode)
{
UKey = uKey;
MsgInfo = msgInfo;
Expand All @@ -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<IPv4> network, NotOnlineImage compat)
public static ImageGroupUploadEvent Result(int resultCode, string uKey, MsgInfo msgInfo, List<IPv4> network, CustomFace compat)
=> new(resultCode, uKey, msgInfo, network, compat);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -118,7 +118,7 @@ protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo app
{
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<NTV2RichMediaResp>>(input.AsSpan());
var upload = packet.Body.Upload;
var compat = Serializer.Deserialize<NotOnlineImage>(upload.CompatQMsg.AsSpan());
var compat = Serializer.Deserialize<CustomFace>(upload.CompatQMsg.AsSpan());

output = ImageGroupUploadEvent.Result((int)packet.ErrorCode, upload.UKey, upload.MsgInfo, upload.IPv4s, compat);
extraEvents = null;
Expand Down
17 changes: 13 additions & 4 deletions Lagrange.Core/Message/Entity/ImageEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() { }

Expand All @@ -52,9 +55,10 @@ public ImageEntity(byte[] file)
IEnumerable<Elem> IMessageEntity.PackElement()
{
var common = MsgInfo.Serialize();
return new Elem[]

var elems = new Elem[]
{
new() { NotOnlineImage = Compat },
new(),
new()
{
CommonElem = new CommonElem
Expand All @@ -65,6 +69,11 @@ IEnumerable<Elem> IMessageEntity.PackElement()
}
}
};

if (CompatFace != null) elems[0].CustomFace = CompatFace;
if (CompatImage != null) elems[0].NotOnlineImage = CompatImage;

return elems;
}

IMessageEntity? IMessageEntity.UnpackElement(Elem elems)
Expand All @@ -84,7 +93,7 @@ IEnumerable<Elem> IMessageEntity.PackElement()

if (elems.CustomFace is { } face)
{
if (face.PbReserve?.Hash != null)
if (face.PbReserve != null && Serializer.Deserialize<CustomFaceExtra>(face.PbReserve.AsSpan()).Hash != null)
{
return new ImageEntity // NTQQ Mobile
{
Expand Down

0 comments on commit c42a2b2

Please sign in to comment.