Skip to content

Commit

Permalink
[CKPE]
Browse files Browse the repository at this point in the history
FO4:
- 983.1 Refuse BSPointerHandle support 64mln ref's only 8mln, stable +-.
  • Loading branch information
Perchik71 committed Nov 7, 2024
1 parent 1650c02 commit f282428
Show file tree
Hide file tree
Showing 15 changed files with 710 additions and 554 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,46 @@ namespace CreationKitPlatformExtended
}
}

void BGSRenderWindowReferenceEditModule::MoveSelectObjectsExtremlyNG(NiPoint3* NewPosition, int32_t Unk)
{
auto Picker = _Renderer->GetPickHandler();
if (!Picker || !Picker->Count) return;
// Reset var the relative grid offset
if (_TempPosition == ZERO_P3)
MoveSnapObjectIntermediate = ZERO_P3;
// If the offset is too small, then it is not needed
/*if (NewPosition->Magnitude2() >= 0.001f)
return;*/
// Increase the offset while pull the mouse, this offset cannot be touched, it seems to be used to restore the cursor
_TempPosition += *NewPosition;
// Also for the relative grid
MoveSnapObjectIntermediate += *NewPosition;

auto It = Picker->Items->First;
for (uint32_t i = 0; i < Picker->Count; i++, It = It->Next)
{
// Get a REFR to object and increase the counter
auto FormRef = BGSUniqueObjectRef((TESObjectREFR_Extremly_NG*)It->GetRef());
if (FormRef.Empty()) continue;
// I have no idea what for, but it is used in the original, also incrementing the counter
auto NodeRef = FormRef->GetFadeNode();
if (NodeRef.Empty()) continue;

auto ObjectPosition = FormRef->GetPosition();
if (BGSRenderWindow::HasSnapToGrid() || BGSRenderWindow::HasSnapToConnectPoints())
{
NiPoint3 NewPos;
if (ComputeGridOrConnectPoint(ObjectPosition, *NewPosition, NewPos, i, Picker->Count))
FormRef->SetPosition(FormRef.Get(), &NewPos);
}
else
{
ObjectPosition += *NewPosition;
FormRef->SetPosition(FormRef.Get(), &ObjectPosition);
}
}
}

void BGSRenderWindowReferenceEditModule::MoveSelectObjectsExtremly(NiPoint3* NewPosition, int32_t Unk)
{
auto Picker = _Renderer->GetPickHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace CreationKitPlatformExtended

void MoveSelectObjects(NiPoint3* NewPosition, int32_t Unk = 0);
void MoveSelectObjectsExtremly(NiPoint3* NewPosition, int32_t Unk = 0);
void MoveSelectObjectsExtremlyNG(NiPoint3* NewPosition, int32_t Unk = 0);

bool ComputeGridOrConnectPoint(const NiPoint3& Position, NiPoint3& OffsetInstant,
NiPoint3& NewPosition, uint32_t Index, uint32_t Count) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ namespace CreationKitPlatformExtended
static_assert(sizeof(IBSUntypedPointerHandle<uint32_t>) == 0x4);

typedef IBSUntypedPointerHandle<uint32_t, 21, 5> BSUntypedPointerHandle_Original;
typedef IBSUntypedPointerHandle<uint32_t, 23, 5> BSUntypedPointerHandle_Extended_NG;
typedef IBSUntypedPointerHandle<uint32_t, 26, 5> BSUntypedPointerHandle_Extended;

template<typename _Ty, typename HandleType, typename HandleRef>
Expand Down Expand Up @@ -145,10 +146,13 @@ namespace CreationKitPlatformExtended

typedef IBSPointerHandleManagerEntry<uint32_t, BSUntypedPointerHandle_Original,
BSHandleRefObject_Original> BSPointerHandleManagerEntry_Original;
typedef IBSPointerHandleManagerEntry<uint32_t, BSUntypedPointerHandle_Extended_NG,
BSHandleRefObject_Extremly> BSPointerHandleManagerEntry_Extended_NG;
typedef IBSPointerHandleManagerEntry<uint32_t, BSUntypedPointerHandle_Extended,
BSHandleRefObject_64_Extremly> BSPointerHandleManagerEntry_Extended;

static_assert(sizeof(BSPointerHandleManagerEntry_Original) == 0x10);
static_assert(sizeof(BSPointerHandleManagerEntry_Extended_NG) == 0x10);
static_assert(sizeof(BSPointerHandleManagerEntry_Extended) == 0x10);

template<typename _Ty, typename HandleType, typename HandleRef>
Expand Down Expand Up @@ -223,6 +227,8 @@ namespace CreationKitPlatformExtended

typedef IBSPointerHandleManager<uint32_t, BSUntypedPointerHandle_Original,
BSHandleRefObject_Original> BSPointerHandleManager_Original;
typedef IBSPointerHandleManager<uint64_t, BSUntypedPointerHandle_Extended_NG,
BSHandleRefObject_Extremly> BSPointerHandleManager_Extended_NG;
typedef IBSPointerHandleManager<uint64_t, BSUntypedPointerHandle_Extended,
BSHandleRefObject_64_Extremly> BSPointerHandleManager_Extended;

Expand All @@ -242,6 +248,7 @@ namespace CreationKitPlatformExtended
};

typedef IBSHandleManager<BSPointerHandleManager_Original> HandleManager_Original;
typedef IBSHandleManager<BSPointerHandleManager_Extended_NG> HandleManager_Extended_NG;
typedef IBSHandleManager<BSPointerHandleManager_Extended> HandleManager_Extended;

template<typename ObjectType, typename HandleType, typename Manager>
Expand Down Expand Up @@ -452,7 +459,9 @@ namespace CreationKitPlatformExtended
typedef IBSPointerHandleManagerInterface<TESObjectREFR_Original,
BSUntypedPointerHandle_Original, HandleManager_Original>
BSPointerHandleManagerInterface_Original;

typedef IBSPointerHandleManagerInterface<TESObjectREFR_Extremly_NG,
BSUntypedPointerHandle_Extended_NG, HandleManager_Extended_NG>
BSPointerHandleManagerInterface_Extended_NG;
typedef IBSPointerHandleManagerInterface<TESObjectREFR_Extremly,
BSUntypedPointerHandle_Extended, HandleManager_Extended>
BSPointerHandleManagerInterface_Extended;
Expand All @@ -468,6 +477,8 @@ namespace CreationKitPlatformExtended
{
case 1:
return BSPointerHandleManagerInterface_Extended::GetPointer(UniqueId);
case 2:
return BSPointerHandleManagerInterface_Extended_NG::GetPointer(UniqueId);
default:
return BSPointerHandleManagerInterface_Original::GetPointer(UniqueId);
}
Expand Down
49 changes: 49 additions & 0 deletions Creation Kit Platform Extended Core/Editor API/FO4/TESObjectREFR.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace CreationKitPlatformExtended
};

typedef TESObjectREFR_base<BSHandleRefObject_Original> TESObjectREFR_base_Original;
typedef TESObjectREFR_base<BSHandleRefObject_Extremly> TESObjectREFR_base_Extremly_NG;
typedef TESObjectREFR_base<BSHandleRefObject_64_Extremly> TESObjectREFR_base_Extremly;

static_assert(sizeof(TESObjectREFR_base_Original) == 0x40);
Expand Down Expand Up @@ -90,6 +91,54 @@ namespace CreationKitPlatformExtended
};
static_assert(sizeof(TESObjectREFR_Original) == 0x140);

class TESObjectREFR_Extremly_NG : public TESObjectREFR_base_Extremly_NG
{
public:
constexpr static uint8_t TYPE_ID = FormType::ftReference;
enum SpecialFlagsForm {
// https://github.com/shadeMe/Construction-Set-Extender/blob/master/EditorAPI/TESObjectREFR.h
fs3DInvisible = 1 << 31,
fsChildren3DInvisible = 1 << 30,
fsFrozen = 1 << 29,
};
protected:
BSTEventSink<void*> _unkEventSink02; // 0x040
BSTEventSink<void*> _unkEventSink03; // 0x048
BSTEventSink<void*> _unkEventSink04; // 0x050
char _pad0[0x70]; // 0x058
TESObjectCELL* _parentCell; // 0x0C8
NiPoint3 _rotate; // 0x0D0, 0x0D4, 0x0D8
float _unkDC; // 0x0DC
NiPoint3 _position; // 0x0E0, 0x0E4, 0x0E8
float _unkEC; // 0x0EC
TESForm* _baseForm; // 0x0F0
void* _unkE8; // 0x0F8
void* _unk100; // 0x100
void* _unk108; // 0x108
void* _extraData; // 0x110
uint16_t _scale; // 0x118
char _pad118[0x26]; // 0x11A
public:
inline NiPoint3 GetPosition() const { return _position; }
inline NiPoint3 GetRotate() const { return _rotate; }
inline void SetRotate(const NiPoint3& val) { _rotate = val; }
inline uint16_t GetScale() const { return _scale; }
inline void SetScale(uint16_t val) { _scale = val; }
inline float GetScaleFloat() const { return ((float)_scale / 100); }
inline void SetScaleFloat(float val) { _scale = uint16_t(val * 100); }
inline bool IsInvisible() const { return (_FormFlags & SpecialFlagsForm::fs3DInvisible); }
inline bool IsChildrenInvisible() const { return (_FormFlags & SpecialFlagsForm::fsChildren3DInvisible); }
inline bool IsFrozen() const { return (_FormFlags & SpecialFlagsForm::fsFrozen); }

READ_PROPERTY2(TESObjectCELL*, ParentCell, _parentCell);
READ_PROPERTY2(TESForm*, Parent, _baseForm);
PROPERTY(GetPosition, SetPosition) NiPoint3 Position;
PROPERTY(GetRotate, SetRotate) NiPoint3 Rotate;
PROPERTY(GetScale, SetScale) uint16_t Scale;
PROPERTY(GetScaleFloat, SetScaleFloat) float ScaleFloat;
};
static_assert(sizeof(TESObjectREFR_Extremly_NG) == 0x140);

class TESObjectREFR_Extremly : public TESObjectREFR_base_Extremly
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ namespace CreationKitPlatformExtended
{
lpRelocator->DetourCall(lpRelocationDatabaseItem->At(0), (uintptr_t)&HKInsertMenuA);

*(uintptr_t*)&EditorAPI::Fallout4::TESObjectREFR::SetParentWithRedraw =
lpRelocator->Rav2Off(lpRelocationDatabaseItem->At(1));
*(uintptr_t*)&EditorAPI::Fallout4::TESObjectREFR_Extremly::SetParentWithRedraw =
lpRelocator->Rav2Off(lpRelocationDatabaseItem->At(1));
*(uintptr_t*)&EditorAPI::Fallout4::TESObjectREFR::SetParentWithRedraw = _RELDATA_ADDR(1);
*(uintptr_t*)&EditorAPI::Fallout4::TESObjectREFR_Extremly_NG::SetParentWithRedraw = _RELDATA_ADDR(1);
*(uintptr_t*)&EditorAPI::Fallout4::TESObjectREFR_Extremly::SetParentWithRedraw = _RELDATA_ADDR(1);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ namespace CreationKitPlatformExtended
if (!BSPointerHandleManagerCurrent::PointerHandleManagerCurrentId)
lpRelocator->DetourJump(_RELDATA_RAV(0), &BGSRenderWindowReferenceEditModule::MoveSelectObjects);
else
lpRelocator->DetourJump(_RELDATA_RAV(0), &BGSRenderWindowReferenceEditModule::MoveSelectObjectsExtremly);
{
if (GlobalEnginePtr->GetEditorVersion() == EDITOR_FALLOUT_C4_1_10_162_0)
lpRelocator->DetourJump(_RELDATA_RAV(0), &BGSRenderWindowReferenceEditModule::MoveSelectObjectsExtremly);
else
lpRelocator->DetourJump(_RELDATA_RAV(0), &BGSRenderWindowReferenceEditModule::MoveSelectObjectsExtremlyNG);
}

*(uintptr_t*)&TESObjectREFR::SetPosition = _RELDATA_ADDR(1);
*(uintptr_t*)&TESObjectREFR_Extremly_NG::SetPosition = _RELDATA_ADDR(1);
*(uintptr_t*)&TESObjectREFR_Extremly::SetPosition = _RELDATA_ADDR(1);

return true;
Expand Down
Loading

0 comments on commit f282428

Please sign in to comment.