Skip to content

Commit cd76bc4

Browse files
committed
.NET: Add NativeObject.FromAddress
1 parent 3dccaaa commit cd76bc4

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

csharp-api/REFrameworkNET/NativeObject.hpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
namespace REFrameworkNET {
1212
value struct InvokeRet;
1313

14-
// Native objects are objects that are NOT managed objects
15-
// However, they still have reflection information associated with them
16-
// So this intends to be the "ManagedObject" class for native objects
17-
// So we can easily interact with them in C#
14+
/// <summary>
15+
// Native objects are objects that are NOT managed objects <br/>
16+
// However, they still have reflection information associated with them <br/>
17+
// So this intends to be the "ManagedObject" class for native objects <br/>
18+
// So we can easily interact with them in C# <br/>
19+
/// </summary>
1820
public ref class NativeObject : public REFrameworkNET::UnifiedObject
1921
{
2022
public:
@@ -48,22 +50,40 @@ public ref class NativeObject : public REFrameworkNET::UnifiedObject
4850
m_object = nullptr;
4951
}
5052

53+
/// <returns>The type of the object</returns>
5154
virtual TypeDefinition^ GetTypeDefinition() override {
5255
return m_type;
5356
}
5457

58+
/// <returns>The address of the object as a void* pointer</returns>
5559
virtual void* Ptr() override {
5660
return m_object;
5761
}
5862

63+
/// <returns>The address of the object</returns>
5964
virtual uintptr_t GetAddress() override {
6065
return (uintptr_t)m_object;
6166
}
6267

6368
generic <typename T>
6469
virtual T As() override;
6570

66-
private:
71+
/// <summary>
72+
/// Creates a NativeObject wrapper over the given address
73+
/// </summary>
74+
/// <remarks>
75+
/// This function can be very dangerous if used incorrectly. <br/>
76+
/// Always double check that you are feeding the correct address <br/>
77+
/// and type to this function. <br/>
78+
/// </remarks>
79+
/// <param name="obj">The address of the object</param>
80+
/// <param name="t">The type of the object</param>
81+
/// <returns>A NativeObject wrapper over the given address</returns>
82+
static NativeObject^ FromAddress(uintptr_t obj, TypeDefinition^ t) {
83+
return gcnew NativeObject(obj, t);
84+
}
85+
86+
protected:
6787
void* m_object{};
6888
TypeDefinition^ m_type{};
6989
};

0 commit comments

Comments
 (0)