File size: 5,733 Bytes
66423d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "UObject/Class.h"
#include "DebugLogger.h"
#include "UnrealFunctions.h"
#include "UObject/UObjectBaseUtility.h"
#include "WideStringWrapper.h"
#include "EdGraph/EdGraphNode.h"

namespace RiderDebuggerSupport
{
    constexpr int StringBufferSizeInWideChars = 1024;
    constexpr int GWideCharSizeInBytes = sizeof(wchar_t);
    constexpr int GStringSizeInBytes = StringBufferSizeInWideChars * GWideCharSizeInBytes;
    constexpr int GLengthSizeInBytes = sizeof(uint32_t);
    constexpr int GResultCodeSizeInBytes = sizeof(uint32_t);
    constexpr int GStringEntrySizeInBytes = GStringSizeInBytes + GLengthSizeInBytes;
    constexpr int GFirstStringOffset = GLengthSizeInBytes;
    constexpr int GSecondStringOffset = GFirstStringOffset + GStringEntrySizeInBytes;
    constexpr int GThirdStringOffset = GSecondStringOffset + GStringEntrySizeInBytes;
    constexpr int GBufferSizeInBytes = GResultCodeSizeInBytes + 3 * GStringEntrySizeInBytes;
}

/* Start Identifiers available from IDEA */

extern "C" DLLEXPORT void __stdcall RiderDebuggerSupport_GetBlueprintFunction(void* PFunction, void* PContext);

struct FJbCallContextModule
{
    void* Context;
    void* Function;
} RiderDebuggerSupportBlueprintFunctionCallContext;

int RiderDebuggerSupportModuleVersion = 1346;

char RiderDebuggerSupportBlueprintFunctionBuffer[RiderDebuggerSupport::GBufferSizeInBytes] = {0};
int RiderDebuggerSupportBlueprintBufferSizeInBytes = RiderDebuggerSupport::GBufferSizeInBytes;
int RiderDebuggerSupportBlueprintStringBufferSizeInChars = RiderDebuggerSupport::StringBufferSizeInWideChars;
int RiderDebuggerSupportBlueprintWideCharSizeInBytes = RiderDebuggerSupport::GWideCharSizeInBytes;

/* End Identifiers available from IDEA */

namespace RiderDebuggerSupport
{
    static FWideStringWrapper GJbFullNameWrapper(RiderDebuggerSupportBlueprintFunctionBuffer + GFirstStringOffset, GStringEntrySizeInBytes);
    static FWideStringWrapper GJbScopeDisplayNameWrapper(RiderDebuggerSupportBlueprintFunctionBuffer + GSecondStringOffset, GStringEntrySizeInBytes);
    static FWideStringWrapper GJbFunctionDisplayNameWrapper(RiderDebuggerSupportBlueprintFunctionBuffer + GThirdStringOffset, GStringEntrySizeInBytes);

    uint32_t* GJbPOperationResultCode = reinterpret_cast<uint32_t*>(RiderDebuggerSupportBlueprintFunctionBuffer);

    static void SetLastExecutedLine(const uint16 LineNumber)
    {
        *GJbPOperationResultCode = (*GJbPOperationResultCode & 0xFFFF0000) | LineNumber;
    }

    static void SetResultCodeFlag(const uint8 FlagOffset)
    {
        *GJbPOperationResultCode |= 1 << FlagOffset;
    }
}

void RiderDebuggerSupport_GetBlueprintFunction(void* PFunction, void* PContext)
{
    using namespace RiderDebuggerSupport;

    SendLogToDebugger("Called %s: Context=%p Function=%p", __func__, PContext, PFunction);
    *GJbPOperationResultCode = 0;

    const UObject* Context = static_cast<UObject*>(PContext);
    UFunction* Function = static_cast<UFunction*>(PFunction);

    if (nullptr == Context)
    {
        SendLogToDebugger("Context is null");
        SetLastExecutedLine(__LINE__);
        return;
    }

    if (nullptr == Function)
    {
        SendLogToDebugger("Function is null");
        SetLastExecutedLine(__LINE__);
        return;
    }
    SetLastExecutedLine(__LINE__);

    FString FullName;
    SetLastExecutedLine(__LINE__);

    Function->GetFullName(nullptr, FullName, EObjectFullNameFlags::None);
    GJbFullNameWrapper.CopyFromNullTerminatedStr(
        GetData(FullName), FullName.Len());
    SetLastExecutedLine(__LINE__);

    const auto Outer = Function->GetOuter();

    SendLogToDebugger("Trying to get SourceClass");

    const UClass* SourceClass = CastToUClass(Outer);

    SendLogToDebugger("SourceClass=%p", SourceClass);

    SetLastExecutedLine(__LINE__);
    if (nullptr != SourceClass)
    {
        constexpr int SourceCodeNotNullFlag = 16;
        SetResultCodeFlag(SourceCodeNotNullFlag);
    }

    FString SourceClassDisplayName = GetClassNameWithoutSuffix(SourceClass);
    SendLogToDebugger(
        "SourceClassDisplayName length=%u, str_ptr=%p",
        SourceClassDisplayName.Len(), GetData(SourceClassDisplayName));
    SetLastExecutedLine(__LINE__);

    SendLogToDebugger("Trying to get outerDisplayName");
    FString OuterDisplayName = FText::FromName(Outer->GetFName()).ToString();
    SendLogToDebugger(
        "OuterDisplayName length=%u, str_ptr=%p",
        OuterDisplayName.Len(), GetData(OuterDisplayName));

    const auto ScopeDisplayName = SourceClass ? &SourceClassDisplayName : &OuterDisplayName;
    GJbScopeDisplayNameWrapper.CopyFromNullTerminatedStr(
        GetData(*ScopeDisplayName), ScopeDisplayName->Len());
    SetLastExecutedLine(__LINE__);

    auto FunctionDisplayName = FText::FromName(Function->GetFName()).ToString();
    GJbFunctionDisplayNameWrapper.CopyFromNullTerminatedStr(GetData(FunctionDisplayName), FunctionDisplayName.Len());
    SetLastExecutedLine(__LINE__);

#if WITH_EDITORONLY_DATA
    if (SourceClass)
    {
        const auto GraphNode = FindSourceNodeForCodeLocation(Context, Function);
        SetLastExecutedLine(__LINE__);

        if (nullptr != GraphNode)
        {
            constexpr int SourceCodeNotNullFlag = 17;
            SetResultCodeFlag(SourceCodeNotNullFlag);

            const FText NodeTitle = GraphNode->GetNodeTitle(ENodeTitleType::Type::ListView);
            SetLastExecutedLine(__LINE__);

            FString NodeTitleStr = NodeTitle.ToString();
            SetLastExecutedLine(__LINE__);

            GJbFunctionDisplayNameWrapper.CopyFromNullTerminatedStr(
                GetData(NodeTitleStr), NodeTitleStr.Len());
            SetLastExecutedLine(__LINE__);
        }
    }
#endif
}