Skip to content

Commit

Permalink
.NET: Add NativeObject.FromAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Apr 25, 2024
1 parent 3dccaaa commit cd76bc4
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions csharp-api/REFrameworkNET/NativeObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
namespace REFrameworkNET {
value struct InvokeRet;

// Native objects are objects that are NOT managed objects
// However, they still have reflection information associated with them
// So this intends to be the "ManagedObject" class for native objects
// So we can easily interact with them in C#
/// <summary>
// Native objects are objects that are NOT managed objects <br/>
// However, they still have reflection information associated with them <br/>
// So this intends to be the "ManagedObject" class for native objects <br/>
// So we can easily interact with them in C# <br/>
/// </summary>
public ref class NativeObject : public REFrameworkNET::UnifiedObject
{
public:
Expand Down Expand Up @@ -48,22 +50,40 @@ public ref class NativeObject : public REFrameworkNET::UnifiedObject
m_object = nullptr;
}

/// <returns>The type of the object</returns>
virtual TypeDefinition^ GetTypeDefinition() override {
return m_type;
}

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

/// <returns>The address of the object</returns>
virtual uintptr_t GetAddress() override {
return (uintptr_t)m_object;
}

generic <typename T>
virtual T As() override;

private:
/// <summary>
/// Creates a NativeObject wrapper over the given address
/// </summary>
/// <remarks>
/// This function can be very dangerous if used incorrectly. <br/>
/// Always double check that you are feeding the correct address <br/>
/// and type to this function. <br/>
/// </remarks>
/// <param name="obj">The address of the object</param>
/// <param name="t">The type of the object</param>
/// <returns>A NativeObject wrapper over the given address</returns>
static NativeObject^ FromAddress(uintptr_t obj, TypeDefinition^ t) {
return gcnew NativeObject(obj, t);
}

protected:
void* m_object{};
TypeDefinition^ m_type{};
};
Expand Down

0 comments on commit cd76bc4

Please sign in to comment.