From 1b3e968640fd5c621bd0b4f16a3cbdcd808f9c08 Mon Sep 17 00:00:00 2001 From: apple1417 Date: Sun, 19 Jan 2025 10:23:42 +1300 Subject: [PATCH 1/2] add `_get_address` method to wrapped struct, array, and delegates mainly useful for wrapped structs which you've constructed yourself --- src/pyunrealsdk/unreal_bindings/wrapped_array.cpp | 5 +++++ src/pyunrealsdk/unreal_bindings/wrapped_array.h | 2 ++ .../unreal_bindings/wrapped_array_methods.cpp | 4 ++++ .../unreal_bindings/wrapped_multicast_delegate.cpp | 9 +++++++++ src/pyunrealsdk/unreal_bindings/wrapped_struct.cpp | 7 +++++++ stubs/unrealsdk/unreal/_wrapped_array.pyi | 7 +++++++ stubs/unrealsdk/unreal/_wrapped_multicast_delegate.pyi | 8 ++++++++ stubs/unrealsdk/unreal/_wrapped_struct.pyi | 7 +++++++ 8 files changed, 49 insertions(+) diff --git a/src/pyunrealsdk/unreal_bindings/wrapped_array.cpp b/src/pyunrealsdk/unreal_bindings/wrapped_array.cpp index ba2b977..ce101f4 100644 --- a/src/pyunrealsdk/unreal_bindings/wrapped_array.cpp +++ b/src/pyunrealsdk/unreal_bindings/wrapped_array.cpp @@ -189,6 +189,11 @@ void register_wrapped_array(py::module_& mod) { " key: A one-arg function used to extract a comparison key.\n" " reverse: If true, the list is sorted as if each comparison were reversed.", py::kw_only{}, "key"_a = py::none{}, "reverse"_a = false) + .def("_get_address", &impl::array_py_getaddress, + "Gets the address of this array, for debugging.\n" + "\n" + "Returns:\n" + " This array's address.") .def_readwrite("_type", &WrappedArray::type); // Create as a class method, see pybind11#1693 diff --git a/src/pyunrealsdk/unreal_bindings/wrapped_array.h b/src/pyunrealsdk/unreal_bindings/wrapped_array.h index 514e6c1..a5dea51 100644 --- a/src/pyunrealsdk/unreal_bindings/wrapped_array.h +++ b/src/pyunrealsdk/unreal_bindings/wrapped_array.h @@ -207,6 +207,8 @@ void array_py_remove(WrappedArray& self, const py::object& value); void array_py_reverse(WrappedArray& self); // sort void array_py_sort(WrappedArray& self, const py::object& key, bool reverse); +// _get_address +uintptr_t array_py_getaddress(const WrappedArray& self); } // namespace impl diff --git a/src/pyunrealsdk/unreal_bindings/wrapped_array_methods.cpp b/src/pyunrealsdk/unreal_bindings/wrapped_array_methods.cpp index 9eb2d32..c051dea 100644 --- a/src/pyunrealsdk/unreal_bindings/wrapped_array_methods.cpp +++ b/src/pyunrealsdk/unreal_bindings/wrapped_array_methods.cpp @@ -182,6 +182,10 @@ void array_py_sort(WrappedArray& self, const py::object& key, bool reverse) { }); } +uintptr_t array_py_getaddress(const WrappedArray& self) { + return reinterpret_cast(self.base.get()); +} + } // namespace pyunrealsdk::unreal::impl #endif diff --git a/src/pyunrealsdk/unreal_bindings/wrapped_multicast_delegate.cpp b/src/pyunrealsdk/unreal_bindings/wrapped_multicast_delegate.cpp index eef217a..e608afa 100644 --- a/src/pyunrealsdk/unreal_bindings/wrapped_multicast_delegate.cpp +++ b/src/pyunrealsdk/unreal_bindings/wrapped_multicast_delegate.cpp @@ -262,6 +262,15 @@ void register_wrapped_multicast_delegate(py::module_& mod) { "Args:\n" " value: The function to remove.", "value"_a) + .def( + "_get_address", + [](const WrappedMulticastDelegate& self) { + return reinterpret_cast(self.base.get()); + }, + "Gets the address of this delegate, for debugging.\n" + "\n" + "Returns:\n" + " This delegate's address.") .def_readwrite("_signature", &WrappedMulticastDelegate::signature); } diff --git a/src/pyunrealsdk/unreal_bindings/wrapped_struct.cpp b/src/pyunrealsdk/unreal_bindings/wrapped_struct.cpp index d435f94..c4b7459 100644 --- a/src/pyunrealsdk/unreal_bindings/wrapped_struct.cpp +++ b/src/pyunrealsdk/unreal_bindings/wrapped_struct.cpp @@ -228,6 +228,13 @@ void register_wrapped_struct(py::module_& mod) { "Returns:\n" " A new, python-owned copy of this struct.", "memo"_a) + .def( + "_get_address", + [](const WrappedStruct& self) { return reinterpret_cast(self.base.get()); }, + "Gets the address of this struct, for debugging.\n" + "\n" + "Returns:\n" + " This struct's address.") .def_readwrite("_type", &WrappedStruct::type); } diff --git a/stubs/unrealsdk/unreal/_wrapped_array.pyi b/stubs/unrealsdk/unreal/_wrapped_array.pyi index 1cc4489..d6ffaf6 100644 --- a/stubs/unrealsdk/unreal/_wrapped_array.pyi +++ b/stubs/unrealsdk/unreal/_wrapped_array.pyi @@ -162,6 +162,13 @@ class WrappedArray[T]: range: The range to set. value: The values to set. """ + def _get_address(self) -> int: + """ + Gets the address of this array, for debugging. + + Returns: + This array's address. + """ def append(self, value: T) -> None: """ Appends a value to the end of the array. diff --git a/stubs/unrealsdk/unreal/_wrapped_multicast_delegate.pyi b/stubs/unrealsdk/unreal/_wrapped_multicast_delegate.pyi index f969cd1..9328edc 100644 --- a/stubs/unrealsdk/unreal/_wrapped_multicast_delegate.pyi +++ b/stubs/unrealsdk/unreal/_wrapped_multicast_delegate.pyi @@ -52,6 +52,14 @@ class WrappedMulticastDelegate: The string representation. """ + def _get_address(self) -> int: + """ + Gets the address of this delegate, for debugging. + + Returns: + This delegate's address. + """ + def add(self, value: BoundFunction) -> None: """ Binds a new function to this delegate. diff --git a/stubs/unrealsdk/unreal/_wrapped_struct.pyi b/stubs/unrealsdk/unreal/_wrapped_struct.pyi index 5d36f32..6ff25b0 100644 --- a/stubs/unrealsdk/unreal/_wrapped_struct.pyi +++ b/stubs/unrealsdk/unreal/_wrapped_struct.pyi @@ -72,6 +72,13 @@ class WrappedStruct: name: The name of the field to set. value: The value to write. """ + def _get_address(self) -> int: + """ + Gets the address of this struct, for debugging. + + Returns: + This struct's address. + """ def _get_field(self, field: UField) -> Any: """ Reads an unreal field off of the struct. From 9fa2d30333e69755defb1471b891ea79bd4d0cdf Mon Sep 17 00:00:00 2001 From: apple1417 Date: Sun, 19 Jan 2025 10:27:28 +1300 Subject: [PATCH 2/2] update changelog --- changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index 8e4d389..9a42bca 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,10 @@ [10bdc130](https://github.com/bl-sdk/pyunrealsdk/commit/10bdc130) +- Added a `_get_address` method to `WrappedArray`, `WrappedMulticastDelegate`, and `WrappedStruct`. + + [1b3e9686](https://github.com/bl-sdk/pyunrealsdk/commit/1b3e9686) + ## v1.5.2 ### unrealsdk v1.6.1