-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngine.h
More file actions
59 lines (49 loc) · 2.11 KB
/
Copy pathEngine.h
File metadata and controls
59 lines (49 loc) · 2.11 KB
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
#pragma once
#include <cmath>
#include <cstdint>
#include <string>
#include <pybind11/embed.h>
#include "../../ue/Engine.h"
#include "../../native/WorldToScreen.h"
/**
* @file
* @brief pybind11 module exposing a curated, safe subset of engine utilities to user scripts as
* `SplitgateInternal.Engine.*` — object lookup by name, native world->screen projection, the
* viewport size, and a distance helper. Deliberately not the raw SDK.
*/
namespace py = pybind11;
namespace Scripts
{
namespace Modules
{
/// Registers the `Engine` submodule.
void Engine(py::module_& m)
{
auto engine = m.def_submodule("Engine");
// Resolve a UObject by its full name (e.g. "Class PortalWars.PortalWarsCharacter").
// Returns the object address as an int (0 if not found) for advanced use.
engine.def("find_object", [](std::string name) -> std::uintptr_t
{
if (!Engine::GObjects) return 0;
return reinterpret_cast<std::uintptr_t>(Engine::GObjects->FindObject(name.c_str())); }, py::arg("name"));
// Project a world point to screen space; returns (x, y) or None if behind the camera /
// not ready. Honors the Debug native/UFunction projection toggle.
engine.def("world_to_screen", [](float x, float y, float z) -> py::object
{
FVector2D out{};
if (Projection::WorldToScreen(FVector{x, y, z}, out)) return py::make_tuple(out.X, out.Y);
return py::none(); }, py::arg("x"), py::arg("y"), py::arg("z"));
// Viewport size in pixels, or None if the canvas isn't ready.
engine.def("canvas_size", []() -> py::object
{
if (!Engine::Canvas) return py::none();
return py::make_tuple(Engine::Canvas->ClipX, Engine::Canvas->ClipY); });
// Euclidean distance between two world points, in metres (UE units are cm).
engine.def("distance", [](float x1, float y1, float z1, float x2, float y2, float z2)
{
const float dx = x1 - x2, dy = y1 - y2, dz = z1 - z2;
return std::sqrt(dx * dx + dy * dy + dz * dz) / 100.f; },
py::arg("x1"), py::arg("y1"), py::arg("z1"), py::arg("x2"), py::arg("y2"), py::arg("z2"));
}
} // namespace Modules
} // namespace Scripts