fix reestarting looting

This commit is contained in:
Milxnor
2023-04-16 11:15:10 -04:00
parent 228a06bd62
commit d308c9ad91
7 changed files with 44 additions and 14 deletions

View File

@@ -261,16 +261,32 @@ public:
return -1; return -1;
} }
void FreeReal() void FreeReal(SizeType Size = sizeof(InElementType))
{ {
if (Data && ArrayNum > 0 && sizeof(InElementType) > 0) if (!IsBadReadPtr(Data, 8) && ArrayNum > 0 && sizeof(InElementType) > 0)
{ {
for (int i = 0; i < ArrayNum; i++)
{
auto current = AtPtr(i, Size);
RtlSecureZeroMemory(current, Size);
}
// VirtualFree(Data, _msize(Data), MEM_RELEASE); // VirtualFree(Data, _msize(Data), MEM_RELEASE);
// VirtualFree(Data, sizeof(InElementType) * ArrayNum, MEM_RELEASE); // ik this does nothing // VirtualFree(Data, sizeof(InElementType) * ArrayNum, MEM_RELEASE); // ik this does nothing
// auto res = VirtualFree(Data, 0, MEM_RELEASE);
// LOG_INFO(LogDev, "Free: {} aa: 0x{:x}", res, res ? 0 : GetLastError()); /* static void (*FreeOriginal)(void*) = decltype(FreeOriginal)(Addresses::Free);
static void (*FreeOriginal)(void*) = decltype(FreeOriginal)(Addresses::Free);
// FreeOriginal(Data); if (FreeOriginal)
{
FreeOriginal(Data);
}
else */
{
auto res = VirtualFree(Data, 0, MEM_RELEASE);
// auto res = VirtualFree(Data, sizeof(InElementType) * ArrayNum, MEM_RELEASE);
LOG_INFO(LogDev, "Free: {} aa: 0x{:x}", res, res ? 0 : GetLastError());
}
} }
Data = nullptr; Data = nullptr;

View File

@@ -150,15 +150,15 @@ std::pair<std::vector<UFortItem*>, std::vector<UFortItem*>> AFortInventory::AddI
if (bEnableStateValues) if (bEnableStateValues)
{ {
FFortItemEntryStateValue* StateValue = (FFortItemEntryStateValue*)FMemory::Realloc(0, FFortItemEntryStateValue::GetStructSize(), 0); FFortItemEntryStateValue* StateValue = Alloc<FFortItemEntryStateValue>(FFortItemEntryStateValue::GetStructSize());
// Alloc<FFortItemEntryStateValue>(FFortItemEntryStateValue::GetStructSize());
StateValue->GetIntValue() = bShowItemToast; StateValue->GetIntValue() = bShowItemToast;
StateValue->GetStateType() = EFortItemEntryState::ShouldShowItemToast; StateValue->GetStateType() = EFortItemEntryState::ShouldShowItemToast;
NewItemInstance->GetItemEntry()->GetStateValues().AddPtr(StateValue, FFortItemEntryStateValue::GetStructSize()); NewItemInstance->GetItemEntry()->GetStateValues().AddPtr(StateValue, FFortItemEntryStateValue::GetStructSize());
} }
ItemInstances.Add(NewItemInstance); ItemInstances.Add(NewItemInstance);
GetItemList().GetReplicatedEntries().Add(*NewItemInstance->GetItemEntry(), FortItemEntrySize); auto ReplicatedEntryIdx = GetItemList().GetReplicatedEntries().Add(*NewItemInstance->GetItemEntry(), FortItemEntrySize);
// GetItemList().GetReplicatedEntries().AtPtr(ReplicatedEntryIdx, FFortItemEntry::GetStructSize())->GetIsReplicatedCopy() = true;
if (WorldItemDefinition->IsValidLowLevel()) if (WorldItemDefinition->IsValidLowLevel())
{ {

View File

@@ -65,6 +65,12 @@ struct FFortItemEntry : FFastArraySerializerItem
return *(FGuid*)(__int64(this) + ItemGuidOffset); return *(FGuid*)(__int64(this) + ItemGuidOffset);
} }
bool& GetIsReplicatedCopy()
{
static auto bIsReplicatedCopyOffset = FindOffsetStruct("/Script/FortniteGame.FortItemEntry", "bIsReplicatedCopy");
return *(bool*)(__int64(this) + bIsReplicatedCopyOffset);
}
class UFortItemDefinition*& GetItemDefinition() class UFortItemDefinition*& GetItemDefinition()
{ {
static auto ItemDefinitionOffset = FindOffsetStruct("/Script/FortniteGame.FortItemEntry", "ItemDefinition"); static auto ItemDefinitionOffset = FindOffsetStruct("/Script/FortniteGame.FortItemEntry", "ItemDefinition");

View File

@@ -95,13 +95,13 @@ std::vector<LootDrop> PickLootDrops(FName TierGroupName, bool bPrint, int recurs
static auto DataTableClass = FindObject<UClass>("/Script/Engine.DataTable"); static auto DataTableClass = FindObject<UClass>("/Script/Engine.DataTable");
static auto CompositeDataTableClass = FindObject<UClass>("/Script/Engine.CompositeDataTable"); static auto CompositeDataTableClass = FindObject<UClass>("/Script/Engine.CompositeDataTable");
static bool bHasFoundTables = false; static int LastNum1 = 14915;
auto CurrentPlaylist = CurrentPlaylistDataOffset == -1 && Fortnite_Version < 6 ? nullptr : GameState->GetCurrentPlaylist(); auto CurrentPlaylist = CurrentPlaylistDataOffset == -1 && Fortnite_Version < 6 ? nullptr : GameState->GetCurrentPlaylist();
if (!bHasFoundTables) if (LastNum1 != AmountOfRestarts)
{ {
bHasFoundTables = true; LastNum1 = AmountOfRestarts;
bool bFoundPlaylistTable = false; bool bFoundPlaylistTable = false;

View File

@@ -175,6 +175,11 @@ void AFortPlayerController::ApplyCosmeticLoadout()
UFortKismetLibrary::StaticClass()->ProcessEvent(UpdatePlayerCustomCharacterPartsVisualizationFn, &PlayerStateAsFort); UFortKismetLibrary::StaticClass()->ProcessEvent(UpdatePlayerCustomCharacterPartsVisualizationFn, &PlayerStateAsFort);
} }
void AFortPlayerController::ServerSetInventoryStateValueHook(AFortPlayerController* PlayerController, FGuid a2, __int64 StateValue)
{
LOG_INFO(LogDev, "ServerSetInventoryStateValueHook! Please tell Milxnor if this gets logged.");
}
void AFortPlayerController::ServerLoadingScreenDroppedHook(UObject* Context, FFrame* Stack, void* Ret) void AFortPlayerController::ServerLoadingScreenDroppedHook(UObject* Context, FFrame* Stack, void* Ret)
{ {
auto PlayerController = (AFortPlayerController*)Context; auto PlayerController = (AFortPlayerController*)Context;
@@ -704,7 +709,7 @@ void AFortPlayerController::ServerCreateBuildingActorHook(UObject* Context, FFra
auto MatInstance = WorldInventory->FindItemInstance(MatDefinition); auto MatInstance = WorldInventory->FindItemInstance(MatDefinition);
bool bShouldDestroy = MatInstance ? (PlayerController->DoesBuildFree() ? false : MatInstance->GetItemEntry()->GetCount() < 10) : true; bool bShouldDestroy = MatInstance && MatInstance->GetItemEntry() ? (PlayerController->DoesBuildFree() ? false : MatInstance->GetItemEntry()->GetCount() < 10) : true;
if (bShouldDestroy) if (bShouldDestroy)
{ {

View File

@@ -84,6 +84,7 @@ public:
void DropAllItems(const std::vector<UFortItemDefinition*>& IgnoreItemDefs, bool bIgnoreSecondaryQuickbar = false, bool bRemoveIfNotDroppable = false); void DropAllItems(const std::vector<UFortItemDefinition*>& IgnoreItemDefs, bool bIgnoreSecondaryQuickbar = false, bool bRemoveIfNotDroppable = false);
void ApplyCosmeticLoadout(); void ApplyCosmeticLoadout();
static void ServerSetInventoryStateValueHook(AFortPlayerController* PlayerController, FGuid a2, __int64 StateValue);
static void ServerLoadingScreenDroppedHook(UObject* Context, FFrame* Stack, void* Ret); static void ServerLoadingScreenDroppedHook(UObject* Context, FFrame* Stack, void* Ret);
static void ServerRepairBuildingActorHook(AFortPlayerController* PlayerController, ABuildingSMActor* BuildingActorToRepair); static void ServerRepairBuildingActorHook(AFortPlayerController* PlayerController, ABuildingSMActor* BuildingActorToRepair);
static void ServerExecuteInventoryItemHook(AFortPlayerController* PlayerController, FGuid ItemGuid); static void ServerExecuteInventoryItemHook(AFortPlayerController* PlayerController, FGuid ItemGuid);

View File

@@ -417,6 +417,8 @@ DWORD WINAPI Main(LPVOID)
Hooking::MinHook::Hook(FortPlayerControllerAthenaDefault, FindObject<UFunction>(L"/Script/FortniteGame.FortPlayerController.ServerDropAllItems"), Hooking::MinHook::Hook(FortPlayerControllerAthenaDefault, FindObject<UFunction>(L"/Script/FortniteGame.FortPlayerController.ServerDropAllItems"),
AFortPlayerController::ServerDropAllItemsHook, nullptr, false); AFortPlayerController::ServerDropAllItemsHook, nullptr, false);
Hooking::MinHook::Hook(FortPlayerControllerAthenaDefault, FindObject<UFunction>(L"/Script/FortniteGame.FortPlayerController.ServerSetInventoryStateValue"),
AFortPlayerController::ServerSetInventoryStateValueHook, nullptr, false);
Hooking::MinHook::Hook(FortPlayerControllerAthenaDefault, Hooking::MinHook::Hook(FortPlayerControllerAthenaDefault,
FindObject<UFunction>("/Script/FortniteGame.FortPlayerController.ServerSpawnInventoryDrop") FindObject<UFunction>("/Script/FortniteGame.FortPlayerController.ServerSpawnInventoryDrop")
? FindObject<UFunction>("/Script/FortniteGame.FortPlayerController.ServerSpawnInventoryDrop") : FindObject<UFunction>(L"/Script/FortniteGame.FortPlayerController.ServerAttemptInventoryDrop"), ? FindObject<UFunction>("/Script/FortniteGame.FortPlayerController.ServerSpawnInventoryDrop") : FindObject<UFunction>(L"/Script/FortniteGame.FortPlayerController.ServerAttemptInventoryDrop"),