2023-09-03 02:01:32 -04:00
|
|
|
|
|
|
|
|
#include "LockedWrapper.h"
|
2023-09-07 03:57:29 -04:00
|
|
|
#include "lpx-drvutil.hpp"
|
2023-10-16 16:54:41 -04:00
|
|
|
#include "lpx-paths.hpp"
|
2023-09-03 02:01:32 -04:00
|
|
|
|
2026-02-09 13:54:00 -05:00
|
|
|
using namespace LpxCommonTypes;
|
2023-09-08 01:52:30 -04:00
|
|
|
|
2025-03-28 23:31:44 -04:00
|
|
|
|
|
|
|
|
void FlxLockedWrapper::DPrintHook(const char *Msg, size_t Size)
|
|
|
|
|
{
|
|
|
|
|
FString FMessage(Size, (const UTF8CHAR *)Msg);
|
|
|
|
|
UE_LOG(LogLuprex, Error, TEXT("%s"), *FMessage);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-15 13:28:18 -04:00
|
|
|
void FlxLockedWrapper::InitWrapper() {
|
2023-09-03 02:01:32 -04:00
|
|
|
if (Lockable.Wrapper.play_initialize != nullptr) {
|
|
|
|
|
// Already initialized.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-16 16:54:41 -04:00
|
|
|
FString dll((const UTF8CHAR*)LUPREX_DLL_PATH);
|
2025-03-28 23:31:44 -04:00
|
|
|
UE_LOG(LogLuprex, Verbose, TEXT("Luprex DLL Path: %s"), *dll);
|
2023-10-16 16:54:41 -04:00
|
|
|
void* DLL = FPlatformProcess::GetDllHandle(*dll);
|
2023-09-03 02:01:32 -04:00
|
|
|
if (DLL != nullptr) {
|
|
|
|
|
using InitFn = void (*)(EngineWrapper*);
|
|
|
|
|
InitFn init = (InitFn)FPlatformProcess::GetDllExport(DLL, TEXT("init_engine_wrapper"));
|
|
|
|
|
if (init != nullptr) {
|
|
|
|
|
init(&Lockable.Wrapper);
|
2025-03-28 23:31:44 -04:00
|
|
|
Lockable.Wrapper.hook_dprint(DPrintHook);
|
2023-09-03 02:01:32 -04:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-05 03:20:11 -04:00
|
|
|
}
|
|
|
|
|
|
2026-02-25 17:07:36 -05:00
|
|
|
FString FlxLockedWrapper::ChannelPrints() {
|
2025-12-15 23:54:55 -05:00
|
|
|
if (Lockable.Wrapper.get_have_prints(Get()))
|
|
|
|
|
{
|
|
|
|
|
uint32_t ndata; const char* data;
|
|
|
|
|
Lockable.Wrapper.play_access(Get(), AccessKind::CHANNEL_PRINTS, 0, 0, "", &ndata, &data);
|
|
|
|
|
if (ndata > 0)
|
|
|
|
|
{
|
|
|
|
|
FString result(ndata, (const UTF8CHAR *)data);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return TEXT("");
|
2023-09-05 03:20:11 -04:00
|
|
|
}
|
|
|
|
|
|
2023-09-15 13:28:18 -04:00
|
|
|
int64 FlxLockedWrapper::GetActor() {
|
2023-09-06 23:25:37 -04:00
|
|
|
return Lockable.Wrapper.get_actor_id(Get());
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-15 13:28:18 -04:00
|
|
|
IdView FlxLockedWrapper::GetNear(int64 id, double rx, double ry, double rz) {
|
2023-09-06 23:25:37 -04:00
|
|
|
uint32 size;
|
|
|
|
|
int64* data;
|
2023-10-16 15:08:11 -04:00
|
|
|
Lockable.Wrapper.get_tangibles_near(Get(), id, rx, ry, rz, &size, (int64_t**)&data);
|
2023-09-07 23:50:49 -04:00
|
|
|
return IdView(data, size);
|
2023-09-06 23:25:37 -04:00
|
|
|
}
|
2023-09-08 01:52:30 -04:00
|
|
|
|
2023-09-15 13:28:18 -04:00
|
|
|
StringViewVec FlxLockedWrapper::GetAnimationQueues(IdView ids) {
|
2023-09-08 01:52:30 -04:00
|
|
|
// How many animation queues are we fetching?
|
|
|
|
|
int num = ids.Num();
|
|
|
|
|
|
|
|
|
|
// Enlarge the static buffers if necessary.
|
|
|
|
|
// Add a little extra space so we don't have to enlarge
|
|
|
|
|
// the buffers every time we get a new tangible.
|
|
|
|
|
if (num > Lockable.AQLenBuffer.Num()) {
|
|
|
|
|
Lockable.AQLenBuffer.SetNum(num + 1000);
|
|
|
|
|
Lockable.AQStrBuffer.SetNum(num + 1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get pointers to the static buffers.
|
|
|
|
|
uint32* LenBuf = Lockable.AQLenBuffer.GetData();
|
|
|
|
|
const char** StrBuf = Lockable.AQStrBuffer.GetData();
|
|
|
|
|
|
|
|
|
|
// Get the animation queues into the static buffers.
|
2023-10-16 15:08:11 -04:00
|
|
|
Lockable.Wrapper.get_animation_queues(Get(), num, (const int64_t *)ids.GetData(), LenBuf, StrBuf);
|
2023-09-08 01:52:30 -04:00
|
|
|
|
|
|
|
|
// Transfer data from static buffers into an array of string_view
|
|
|
|
|
StringViewVec result;
|
|
|
|
|
result.SetNum(num);
|
|
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
|
|
result[i] = std::string_view(StrBuf[i], LenBuf[i]);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2023-10-16 15:08:11 -04:00
|
|
|
}
|
2026-02-14 03:35:08 -05:00
|
|
|
|
|
|
|
|
ElxLuaSyntaxCheck FlxLockedWrapper::ValidateLuaExpr(const FString &Code, FString &ErrorMessage) {
|
|
|
|
|
FTCHARToUTF8 UCode(*Code);
|
|
|
|
|
uint32_t retpklen;
|
|
|
|
|
const char *retpk;
|
|
|
|
|
Lockable.Wrapper.play_access(Get(), AccessKind::VALIDATE_LUA_EXPR, 0, UCode.Length(), UCode.Get(), &retpklen, &retpk);
|
|
|
|
|
ErrorMessage = FString(retpklen, (const UTF8CHAR*)retpk);
|
|
|
|
|
if (ErrorMessage.IsEmpty())
|
|
|
|
|
return ElxLuaSyntaxCheck::ValidLua;
|
|
|
|
|
if (ErrorMessage == TEXT("slash command"))
|
|
|
|
|
return ElxLuaSyntaxCheck::SlashCommand;
|
|
|
|
|
if (ErrorMessage == TEXT("white space"))
|
|
|
|
|
return ElxLuaSyntaxCheck::Whitespace;
|
|
|
|
|
if (ErrorMessage == TEXT("truncated lua"))
|
|
|
|
|
return ElxLuaSyntaxCheck::TruncatedLua;
|
|
|
|
|
return ElxLuaSyntaxCheck::InvalidLua;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlxLockedWrapper::ProbeLuaFunction(std::string_view datapk, int64 place_id, TFunction<void(std::string_view)> OnResult) {
|
|
|
|
|
if (place_id == 0) place_id = GetActor();
|
|
|
|
|
uint32_t retpklen;
|
|
|
|
|
const char *retpk;
|
|
|
|
|
Lockable.Wrapper.play_access(Get(), AccessKind::PROBE_LUA_CALL, place_id, datapk.size(), datapk.data(), &retpklen, &retpk);
|
|
|
|
|
OnResult(std::string_view(retpk, retpklen));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlxLockedWrapper::InvokeLuaFunction(std::string_view datapk, int64 place_id) {
|
|
|
|
|
if (place_id == 0) place_id = GetActor();
|
|
|
|
|
uint32_t retpklen;
|
|
|
|
|
const char *retpk;
|
|
|
|
|
Lockable.Wrapper.play_access(Get(), AccessKind::INVOKE_LUA_CALL, place_id, datapk.size(), datapk.data(), &retpklen, &retpk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlxLockedWrapper::InvokeLuaExpr(const FString &Code) {
|
|
|
|
|
FTCHARToUTF8 UCode(*Code);
|
|
|
|
|
uint32_t retpklen;
|
|
|
|
|
const char *retpk;
|
|
|
|
|
Lockable.Wrapper.play_access(Get(), AccessKind::INVOKE_LUA_EXPR, 0, UCode.Length(), UCode.Get(), &retpklen, &retpk);
|
|
|
|
|
}
|