86 lines
2.4 KiB
C++
86 lines
2.4 KiB
C++
|
|
#include "LockedWrapper.h"
|
|
#include "LuprexGameModeBase.h"
|
|
#include "lpx-drvutil.hpp"
|
|
#include "lpx-paths.hpp"
|
|
|
|
using namespace LpxCommonTypes;
|
|
|
|
|
|
void FlxLockedWrapper::DPrintHook(const char *Msg, size_t Size)
|
|
{
|
|
FString FMessage(Size, (const UTF8CHAR *)Msg);
|
|
UE_LOG(LogLuprex, Error, TEXT("%s"), *FMessage);
|
|
}
|
|
|
|
void FlxLockedWrapper::InitWrapper() {
|
|
if (Lockable.Wrapper.play_initialize != nullptr) {
|
|
// Already initialized.
|
|
return;
|
|
}
|
|
FString dll((const UTF8CHAR*)LUPREX_DLL_PATH);
|
|
UE_LOG(LogLuprex, Verbose, TEXT("Luprex DLL Path: %s"), *dll);
|
|
void* DLL = FPlatformProcess::GetDllHandle(*dll);
|
|
if (DLL != nullptr) {
|
|
using InitFn = void (*)(EngineWrapper*);
|
|
InitFn init = (InitFn)FPlatformProcess::GetDllExport(DLL, TEXT("init_engine_wrapper"));
|
|
if (init != nullptr) {
|
|
init(&Lockable.Wrapper);
|
|
Lockable.Wrapper.hook_dprint(DPrintHook);
|
|
}
|
|
}
|
|
}
|
|
|
|
FString FlxLockedWrapper::FetchStdout() {
|
|
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("");
|
|
}
|
|
|
|
int64 FlxLockedWrapper::GetActor() {
|
|
return Lockable.Wrapper.get_actor_id(Get());
|
|
}
|
|
|
|
IdView FlxLockedWrapper::GetNear(int64 id, double rx, double ry, double rz) {
|
|
uint32 size;
|
|
int64* data;
|
|
Lockable.Wrapper.get_tangibles_near(Get(), id, rx, ry, rz, &size, (int64_t**)&data);
|
|
return IdView(data, size);
|
|
}
|
|
|
|
StringViewVec FlxLockedWrapper::GetAnimationQueues(IdView ids) {
|
|
// 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.
|
|
Lockable.Wrapper.get_animation_queues(Get(), num, (const int64_t *)ids.GetData(), LenBuf, StrBuf);
|
|
|
|
// 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;
|
|
}
|