Skip to content
This repository has been archived by the owner on Dec 11, 2021. It is now read-only.

Commit

Permalink
Fix function HistoryMessage::GetComponent (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Jun 22, 2021
1 parent f0c6f1f commit 0c46c2b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions Source/Telegram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,24 @@ bool HistoryMessage::IsMessage()
}

template <class CompT>
CompT* HistoryMessage::GetComponent(uint32_t Index)
CompT* HistoryMessage::GetComponent(uint32_t index)
{
CompT* Result = NULL;
CompT *result = nullptr;

Safe::TryExcept(
[&]()
{
auto pData = *(void***)((uintptr_t)this + 8);
int32_t Offset = *(int32_t*)((uintptr_t)(*pData) + 4ui64 * Index + 8);
if (Offset >= 4) {
Result = (CompT*)((uintptr_t)pData + Offset);
[&]() {
struct RuntimeComposerMetadata {
size_t size;
size_t align;
size_t offsets[64];
int last;
};

auto data = *(void***)((uintptr_t)this + 8);
auto metaData = (RuntimeComposerMetadata*)(*data);
auto offset = metaData->offsets[index];
if (offset >= sizeof(RuntimeComposerMetadata*)) {
result = (CompT*)((uintptr_t)data + offset);
}

}, [&](ULONG ExceptionCode)
Expand All @@ -156,7 +163,7 @@ CompT* HistoryMessage::GetComponent(uint32_t Index)
}
);

return Result;
return result;
}

HistoryMessageEdited* HistoryMessage::GetEdited()
Expand Down
2 changes: 1 addition & 1 deletion Source/Telegram.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class HistoryMessage /* : public HistoryItem */
bool IsMessage();

template <class CompT>
CompT* GetComponent(uint32_t Index);
CompT* GetComponent(uint32_t index);

HistoryMessageEdited* GetEdited();
HistoryMessageSigned* GetSigned();
Expand Down

0 comments on commit 0c46c2b

Please sign in to comment.