fix autopickup

This commit is contained in:
Gray
2024-01-14 17:42:05 -05:00
parent 89231ccf42
commit f8e078161c
4 changed files with 27 additions and 75 deletions

View File

@@ -12,8 +12,8 @@ struct FAthenaMatchTeamStats
static auto GetStructSize() { return GetStruct()->GetPropertiesSize(); } static auto GetStructSize() { return GetStruct()->GetPropertiesSize(); }
int Place; // 0x0000(0x0004) (Edit, BlueprintVisible, BlueprintReadOnly, ZeroConstructor, IsPlainOldData, NoDestructor, HasGetValueTypeHash, NativeAccessSpecifierPublic) int Place;
int TotalPlayers; // 0x0004(0x0004) (Edit, BlueprintVisible, BlueprintReadOnly, ZeroConstructor, IsPlainOldData, NoDestructor, HasGetValueTypeHash, NativeAccessSpecifierPublic) int TotalPlayers;
int& GetPlace() int& GetPlace()
{ {
@@ -49,7 +49,7 @@ public:
static UClass* StaticClass() static UClass* StaticClass()
{ {
static auto Class = FindObject<UClass>("/Script/FortniteGame.AthenaPlayerMatchReport"); static auto Class = FindObject<UClass>(L"/Script/FortniteGame.AthenaPlayerMatchReport");
return Class; return Class;
} }
}; };

View File

@@ -240,10 +240,15 @@ public:
this->ProcessEvent(ClientOnPawnRevivedFn, &EventInstigator); this->ProcessEvent(ClientOnPawnRevivedFn, &EventInstigator);
} }
bool& IsMarkedAlive() bool IsMarkedAlive()
{ {
static auto bMarkedAliveOffset = GetOffset("bMarkedAlive"); static auto bMarkedAliveOffset = GetOffset("bMarkedAlive", false);
return Get<bool>(bMarkedAliveOffset);
if (bMarkedAliveOffset == -1) // nots ure if this is possible
return true;
static auto bMarkedAliveFieldMask = GetFieldMask(GetProperty("bMarkedAlive"));
return ReadBitfieldValue(bMarkedAliveOffset, bMarkedAliveFieldMask);
} }
static void StartGhostModeHook(UObject* Context, FFrame* Stack, void* Ret); // we could native hook this but eh static void StartGhostModeHook(UObject* Context, FFrame* Stack, void* Ret); // we could native hook this but eh

View File

@@ -14,7 +14,7 @@ void AFortPlayerPawnAthena::OnCapsuleBeginOverlapHook(UObject* Context, FFrame*
bool bFromSweep; bool bFromSweep;
auto SweepResultPtr = (FHitResult*)std::realloc(0, FHitResult::GetStructSize()); auto SweepResultPtr = (FHitResult*)std::realloc(0, FHitResult::GetStructSize());
// LOG_INFO(LogDev, "OnCapsuleBeginOverlapHook!"); LOG_INFO(LogDev, "OnCapsuleBeginOverlapHook!");
Stack->StepCompiledIn(&OverlappedComp); Stack->StepCompiledIn(&OverlappedComp);
Stack->StepCompiledIn(&OtherActor); Stack->StepCompiledIn(&OtherActor);
@@ -28,81 +28,28 @@ void AFortPlayerPawnAthena::OnCapsuleBeginOverlapHook(UObject* Context, FFrame*
// LOG_INFO(LogDev, "OtherActor: {}", __int64(OtherActor)); // LOG_INFO(LogDev, "OtherActor: {}", __int64(OtherActor));
// LOG_INFO(LogDev, "OtherActorName: {}", OtherActor->IsValidLowLevel() ? OtherActor->GetName() : "BadRead") // LOG_INFO(LogDev, "OtherActorName: {}", OtherActor->IsValidLowLevel() ? OtherActor->GetName() : "BadRead")
if (auto Pickup = Cast<AFortPickup>(OtherActor)) if (!Pawn->IsDBNO())
{ {
static auto PawnWhoDroppedPickupOffset = Pickup->GetOffset("PawnWhoDroppedPickup"); if (auto Pickup = Cast<AFortPickup>(OtherActor))
if (Pickup->Get<AFortPawn*>(PawnWhoDroppedPickupOffset) != Pawn)
{ {
auto ItemDefinition = Pickup->GetPrimaryPickupItemEntry()->GetItemDefinition(); static auto PawnWhoDroppedPickupOffset = Pickup->GetOffset("PawnWhoDroppedPickup");
if (!ItemDefinition) if (Pickup->Get<AFortPawn*>(PawnWhoDroppedPickupOffset) != Pawn)
{ {
return; auto ItemDefinition = Pickup->GetPrimaryPickupItemEntry()->GetItemDefinition();
}
auto PlayerController = Cast<AFortPlayerControllerAthena>(Pawn->GetController()); if (!ItemDefinition)
if (!PlayerController)
{
return;
}
auto WorldInventory = PlayerController->GetWorldInventory();
if (!WorldInventory)
{
return;
}
auto& ItemInstances = WorldInventory->GetItemList().GetItemInstances();
bool ItemDefGoingInPrimary = IsPrimaryQuickbar(ItemDefinition);
int PrimarySlotsFilled = 0;
bool bCanStack = false;
bool bFoundStack = false;
for (int i = 0; i < ItemInstances.Num(); ++i)
{
auto ItemInstance = ItemInstances.at(i);
if (!ItemInstance)
continue;
auto CurrentItemDefinition = ItemInstance->GetItemEntry()->GetItemDefinition();
if (!CurrentItemDefinition)
continue;
if (ItemDefGoingInPrimary && IsPrimaryQuickbar(CurrentItemDefinition))
PrimarySlotsFilled++;
bool bIsInventoryFull = (PrimarySlotsFilled /* - 6 */) >= 5;
if (CurrentItemDefinition == ItemDefinition)
{
bFoundStack = true;
if (ItemInstance->GetItemEntry()->GetCount() < ItemDefinition->GetMaxStackSize())
{
bCanStack = true;
break;
}
}
if (bIsInventoryFull)
{ {
return; return;
} }
if (!IsPrimaryQuickbar(ItemDefinition))
{
ServerHandlePickupHook(Pawn, Pickup, 0.4f, FVector(), true);
}
} }
// std::cout << "bCanStack: " << bCanStack << '\n';
// std::cout << "bFoundStack: " << bFoundStack << '\n';
if (!bCanStack ? (!bFoundStack ? true : ItemDefinition->DoesAllowMultipleStacks()) : true)
ServerHandlePickupHook(Pawn, Pickup, 0.4f, FVector(), true);
} }
} }
// return OnCapsuleBeginOverlapOriginal(Context, Stack, Ret); // return OnCapsuleBeginOverlapOriginal(Context, Stack, Ret); // we love explicit
} }

View File

@@ -868,8 +868,8 @@ DWORD WINAPI Main(LPVOID)
AFortPawn::NetMulticast_Athena_BatchedDamageCuesHook, (PVOID*)&AFortPawn::NetMulticast_Athena_BatchedDamageCuesOriginal, false, true); AFortPawn::NetMulticast_Athena_BatchedDamageCuesHook, (PVOID*)&AFortPawn::NetMulticast_Athena_BatchedDamageCuesOriginal, false, true);
Hooking::MinHook::Hook(FortPlayerPawnAthenaDefault, FindObject<UFunction>(L"/Script/FortniteGame.FortPawn.MovingEmoteStopped"), Hooking::MinHook::Hook(FortPlayerPawnAthenaDefault, FindObject<UFunction>(L"/Script/FortniteGame.FortPawn.MovingEmoteStopped"),
AFortPawn::MovingEmoteStoppedHook, (PVOID*)&AFortPawn::MovingEmoteStoppedOriginal, false, true); AFortPawn::MovingEmoteStoppedHook, (PVOID*)&AFortPawn::MovingEmoteStoppedOriginal, false, true);
// Hooking::MinHook::Hook(FortPlayerPawnAthenaDefault, FindObject<UFunction>(L"/Script/FortniteGame.FortPlayerPawnAthena.OnCapsuleBeginOverlap") ? FindObject<UFunction>(L"/Script/FortniteGame.FortPlayerPawnAthena.OnCapsuleBeginOverlap") : FindObject<UFunction>(L"/Script/FortniteGame.FortPlayerPawn.OnCapsuleBeginOverlap"), Hooking::MinHook::Hook(FortPlayerPawnAthenaDefault, FindObject<UFunction>(L"/Script/FortniteGame.FortPlayerPawnAthena.OnCapsuleBeginOverlap") ? FindObject<UFunction>(L"/Script/FortniteGame.FortPlayerPawnAthena.OnCapsuleBeginOverlap") : FindObject<UFunction>(L"/Script/FortniteGame.FortPlayerPawn.OnCapsuleBeginOverlap"),
// AFortPlayerPawnAthena::OnCapsuleBeginOverlapHook, (PVOID*)&AFortPlayerPawnAthena::OnCapsuleBeginOverlapOriginal, false, true); AFortPlayerPawnAthena::OnCapsuleBeginOverlapHook, (PVOID*)&AFortPlayerPawnAthena::OnCapsuleBeginOverlapOriginal, false, true);
Hooking::MinHook::Hook(FortKismetLibraryDefault, FindObject<UFunction>(L"/Script/FortniteGame.FortKismetLibrary.K2_RemoveFortItemFromPlayer"), Hooking::MinHook::Hook(FortKismetLibraryDefault, FindObject<UFunction>(L"/Script/FortniteGame.FortKismetLibrary.K2_RemoveFortItemFromPlayer"),
UFortKismetLibrary::K2_RemoveFortItemFromPlayerHook, (PVOID*)&UFortKismetLibrary::K2_RemoveFortItemFromPlayerOriginal, false, true); UFortKismetLibrary::K2_RemoveFortItemFromPlayerHook, (PVOID*)&UFortKismetLibrary::K2_RemoveFortItemFromPlayerOriginal, false, true);