Update FortPlayerController.cpp

This commit is contained in:
max_the
2024-01-14 23:01:21 +01:00
committed by GitHub
parent c11ffdaa0e
commit 28d5870f73

View File

@@ -549,83 +549,179 @@ void AFortPlayerController::ServerAttemptInteractHook(UObject* Context, FFrame*
} }
else if (ReceivingActor->IsA(BuildingItemCollectorActorClass)) else if (ReceivingActor->IsA(BuildingItemCollectorActorClass))
{ {
auto WorldInventory = PlayerController->GetWorldInventory(); if (Engine_Version >= 424 && /*Fortnite_Version < 15 && */ReceivingActor->GetFullName().contains("Wumba"))
if (!WorldInventory)
return ServerAttemptInteractOriginal(Context, Stack, Ret);
auto ItemCollector = ReceivingActor;
static auto ActiveInputItemOffset = ItemCollector->GetOffset("ActiveInputItem");
auto CurrentMaterial = ItemCollector->Get<UFortWorldItemDefinition*>(ActiveInputItemOffset); // InteractType->OptionalObjectData
if (!CurrentMaterial)
return ServerAttemptInteractOriginal(Context, Stack, Ret);
int Index = 0;
// this is a weird way of getting the current item collection we are on.
static auto StoneItemData = FindObject<UFortResourceItemDefinition>(L"/Game/Items/ResourcePickups/StoneItemData.StoneItemData");
static auto MetalItemData = FindObject<UFortResourceItemDefinition>(L"/Game/Items/ResourcePickups/MetalItemData.MetalItemData");
if (CurrentMaterial == StoneItemData)
Index = 1;
else if (CurrentMaterial == MetalItemData)
Index = 2;
static auto ItemCollectionsOffset = ItemCollector->GetOffset("ItemCollections");
auto& ItemCollections = ItemCollector->Get<TArray<FCollectorUnitInfo>>(ItemCollectionsOffset);
auto ItemCollection = ItemCollections.AtPtr(Index, FCollectorUnitInfo::GetPropertiesSize());
if (Fortnite_Version < 8.10)
{ {
auto Cost = ItemCollection->GetInputCount()->GetValue(); bool bIsSidegrading = InteractionBeingAttempted == EInteractionBeingAttempted::SecondInteraction ? true : false;
if (!CurrentMaterial) LOG_INFO(LogDev, "bIsSidegrading: {}", (bool)bIsSidegrading);
return ServerAttemptInteractOriginal(Context, Stack, Ret);
struct FWeaponUpgradeItemRow
auto MatInstance = WorldInventory->FindItemInstance(CurrentMaterial); {
void* FTableRowBaseInheritance;
if (!MatInstance) UFortWeaponItemDefinition* CurrentWeaponDef; // 0x8(0x8)(Edit, ZeroConstructor, DisableEditOnInstance, IsPlainOldData, NoDestructor, HasGetValueTypeHash, NativeAccessSpecifierPublic)
return ServerAttemptInteractOriginal(Context, Stack, Ret); UFortWeaponItemDefinition* UpgradedWeaponDef; // 0x10(0x8)(Edit, ZeroConstructor, DisableEditOnInstance, IsPlainOldData, NoDestructor, HasGetValueTypeHash, NativeAccessSpecifierPublic)
EFortWeaponUpgradeCosts WoodCost; // 0x18(0x1)(Edit, ZeroConstructor, DisableEditOnInstance, IsPlainOldData, NoDestructor, HasGetValueTypeHash, NativeAccessSpecifierPublic)
EFortWeaponUpgradeCosts MetalCost; // 0x19(0x1)(Edit, ZeroConstructor, DisableEditOnInstance, IsPlainOldData, NoDestructor, HasGetValueTypeHash, NativeAccessSpecifierPublic)
EFortWeaponUpgradeCosts BrickCost; // 0x1A(0x1)(Edit, ZeroConstructor, DisableEditOnInstance, IsPlainOldData, NoDestructor, HasGetValueTypeHash, NativeAccessSpecifierPublic)
EFortWeaponUpgradeDirection Direction;
};
static auto WumbaDataTable = FindObject<UDataTable>("/Game/Items/Datatables/AthenaWumbaData.AthenaWumbaData");
static auto LootPackagesRowMap = WumbaDataTable->GetRowMap();
auto Pawn = Cast<AFortPawn>(PlayerController->GetPawn());
auto CurrentHeldWeapon = Pawn->GetCurrentWeapon();
auto CurrentHeldWeaponDef = CurrentHeldWeapon->GetWeaponData();
auto Direction = bIsSidegrading ? EFortWeaponUpgradeDirection::Horizontal : EFortWeaponUpgradeDirection::Vertical;
LOG_INFO(LogDev, "Direction: {}", (int)Direction);
FWeaponUpgradeItemRow* FoundRow = nullptr;
for (int i = 0; i < LootPackagesRowMap.Pairs.Elements.Data.Num(); i++)
{
auto& Pair = LootPackagesRowMap.Pairs.Elements.Data.at(i).ElementData.Value;
auto First = Pair.First;
auto Row = (FWeaponUpgradeItemRow*)Pair.Second;
if (Row->CurrentWeaponDef == CurrentHeldWeaponDef && Row->Direction == Direction)
{
FoundRow = Row;
break;
}
}
if (!FoundRow)
{
LOG_WARN(LogGame, "Failed to find row!");
return;
}
auto NewDefinition = FoundRow->UpgradedWeaponDef;
LOG_INFO(LogDev, "UpgradedWeaponDef: {}", NewDefinition->GetFullName());
int WoodCost = (int)FoundRow->WoodCost * 50;
int StoneCost = (int)FoundRow->BrickCost * 50 - 400;
int MetalCost = (int)FoundRow->MetalCost * 50 - 200;
if (bIsSidegrading)
{
WoodCost = 20;
StoneCost = 20;
MetalCost = 20;
}
static auto WoodItemData = FindObject<UFortItemDefinition>("/Game/Items/ResourcePickups/WoodItemData.WoodItemData");
static auto StoneItemData = FindObject<UFortItemDefinition>("/Game/Items/ResourcePickups/StoneItemData.StoneItemData");
static auto MetalItemData = FindObject<UFortItemDefinition>("/Game/Items/ResourcePickups/MetalItemData.MetalItemData");
auto WorldInventory = PlayerController->GetWorldInventory();
auto WoodInstance = WorldInventory->FindItemInstance(WoodItemData);
auto WoodCount = WoodInstance->GetItemEntry()->GetCount();
auto StoneInstance = WorldInventory->FindItemInstance(StoneItemData);
auto StoneCount = StoneInstance->GetItemEntry()->GetCount();
auto MetalInstance = WorldInventory->FindItemInstance(MetalItemData);
auto MetalCount = MetalInstance->GetItemEntry()->GetCount();
bool bShouldUpdate = false; bool bShouldUpdate = false;
if (!WorldInventory->RemoveItem(MatInstance->GetItemEntry()->GetItemGuid(), &bShouldUpdate, Cost, true)) WorldInventory->RemoveItem(WoodInstance->GetItemEntry()->GetItemGuid(), &bShouldUpdate, WoodCost);
return ServerAttemptInteractOriginal(Context, Stack, Ret); WorldInventory->RemoveItem(StoneInstance->GetItemEntry()->GetItemGuid(), &bShouldUpdate, StoneCost);
WorldInventory->RemoveItem(MetalInstance->GetItemEntry()->GetItemGuid(), &bShouldUpdate, MetalCost);
WorldInventory->RemoveItem(CurrentHeldWeapon->GetItemEntryGuid(), &bShouldUpdate, 1, true);
WorldInventory->AddItem(NewDefinition, &bShouldUpdate);
if (bShouldUpdate) if (bShouldUpdate)
WorldInventory->Update(); WorldInventory->Update();
} }
else
for (int z = 0; z < ItemCollection->GetOutputItemEntry()->Num(); z++)
{ {
auto Entry = ItemCollection->GetOutputItemEntry()->AtPtr(z, FFortItemEntry::GetStructSize()); auto WorldInventory = PlayerController->GetWorldInventory();
PickupCreateData CreateData; if (!WorldInventory)
CreateData.ItemEntry = FFortItemEntry::MakeItemEntry(Entry->GetItemDefinition(), Entry->GetCount(), Entry->GetLoadedAmmo(), MAX_DURABILITY, Entry->GetLevel()); return ServerAttemptInteractOriginal(Context, Stack, Ret);
CreateData.SpawnLocation = LocationToSpawnLoot;
CreateData.PawnOwner = PlayerController->GetMyFortPawn(); // hmm auto ItemCollector = ReceivingActor;
CreateData.bShouldFreeItemEntryWhenDeconstructed = true; static auto ActiveInputItemOffset = ItemCollector->GetOffset("ActiveInputItem");
auto CurrentMaterial = ItemCollector->Get<UFortWorldItemDefinition*>(ActiveInputItemOffset); // InteractType->OptionalObjectData
AFortPickup::SpawnPickup(CreateData);
} if (!CurrentMaterial)
return ServerAttemptInteractOriginal(Context, Stack, Ret);
static auto bCurrentInteractionSuccessOffset = ItemCollector->GetOffset("bCurrentInteractionSuccess", false);
int Index = 0;
if (bCurrentInteractionSuccessOffset != -1)
{ // this is a weird way of getting the current item collection we are on.
static auto bCurrentInteractionSuccessFieldMask = GetFieldMask(ItemCollector->GetProperty("bCurrentInteractionSuccess"));
ItemCollector->SetBitfieldValue(bCurrentInteractionSuccessOffset, bCurrentInteractionSuccessFieldMask, true); // idek if this is needed static auto StoneItemData = FindObject<UFortResourceItemDefinition>(L"/Game/Items/ResourcePickups/StoneItemData.StoneItemData");
} static auto MetalItemData = FindObject<UFortResourceItemDefinition>(L"/Game/Items/ResourcePickups/MetalItemData.MetalItemData");
static auto DoVendDeath = FindObject<UFunction>(L"/Game/Athena/Items/Gameplay/VendingMachine/B_Athena_VendingMachine.B_Athena_VendingMachine_C.DoVendDeath"); if (CurrentMaterial == StoneItemData)
Index = 1;
if (DoVendDeath) else if (CurrentMaterial == MetalItemData)
{ Index = 2;
ItemCollector->ProcessEvent(DoVendDeath);
ItemCollector->K2_DestroyActor(); static auto ItemCollectionsOffset = ItemCollector->GetOffset("ItemCollections");
auto& ItemCollections = ItemCollector->Get<TArray<FCollectorUnitInfo>>(ItemCollectionsOffset);
auto ItemCollection = ItemCollections.AtPtr(Index, FCollectorUnitInfo::GetPropertiesSize());
if (Fortnite_Version < 8.10)
{
auto Cost = ItemCollection->GetInputCount()->GetValue();
if (!CurrentMaterial)
return ServerAttemptInteractOriginal(Context, Stack, Ret);
auto MatInstance = WorldInventory->FindItemInstance(CurrentMaterial);
if (!MatInstance)
return ServerAttemptInteractOriginal(Context, Stack, Ret);
bool bShouldUpdate = false;
if (!WorldInventory->RemoveItem(MatInstance->GetItemEntry()->GetItemGuid(), &bShouldUpdate, Cost, true))
return ServerAttemptInteractOriginal(Context, Stack, Ret);
if (bShouldUpdate)
WorldInventory->Update();
}
for (int z = 0; z < ItemCollection->GetOutputItemEntry()->Num(); z++)
{
auto Entry = ItemCollection->GetOutputItemEntry()->AtPtr(z, FFortItemEntry::GetStructSize());
PickupCreateData CreateData;
CreateData.ItemEntry = FFortItemEntry::MakeItemEntry(Entry->GetItemDefinition(), Entry->GetCount(), Entry->GetLoadedAmmo(), MAX_DURABILITY, Entry->GetLevel());
CreateData.SpawnLocation = LocationToSpawnLoot;
CreateData.PawnOwner = PlayerController->GetMyFortPawn(); // hmm
CreateData.bShouldFreeItemEntryWhenDeconstructed = true;
AFortPickup::SpawnPickup(CreateData);
}
static auto bCurrentInteractionSuccessOffset = ItemCollector->GetOffset("bCurrentInteractionSuccess", false);
if (bCurrentInteractionSuccessOffset != -1)
{
static auto bCurrentInteractionSuccessFieldMask = GetFieldMask(ItemCollector->GetProperty("bCurrentInteractionSuccess"));
ItemCollector->SetBitfieldValue(bCurrentInteractionSuccessOffset, bCurrentInteractionSuccessFieldMask, true); // idek if this is needed
}
static auto DoVendDeath = FindObject<UFunction>(L"/Game/Athena/Items/Gameplay/VendingMachine/B_Athena_VendingMachine.B_Athena_VendingMachine_C.DoVendDeath");
if (DoVendDeath)
{
ItemCollector->ProcessEvent(DoVendDeath);
ItemCollector->K2_DestroyActor();
}
} }
} }
@@ -1692,4 +1788,4 @@ void AFortPlayerController::ServerEndEditingBuildingActorHook(AFortPlayerControl
EditTool->GetEditActor() = nullptr; EditTool->GetEditActor() = nullptr;
EditTool->OnRep_EditActor(); EditTool->OnRep_EditActor();
} }
} }