From e79445d22ed28abddf8ccdc19b5616eb3b0e6872 Mon Sep 17 00:00:00 2001 From: Milxnor Date: Fri, 16 Jun 2023 10:24:59 -0400 Subject: [PATCH] fixed some ltm stuff --- .../FortAthenaMutator_Barrier.cpp | 7 ++ Project Reboot 3.0/FortLootPackage.cpp | 71 +++++--------- Project Reboot 3.0/GameModeBase.cpp | 12 +-- Project Reboot 3.0/addresses.cpp | 3 + Project Reboot 3.0/addresses.h | 1 + Project Reboot 3.0/finder.cpp | 96 ++++++++++++------- Project Reboot 3.0/finder.h | 1 + 7 files changed, 106 insertions(+), 85 deletions(-) diff --git a/Project Reboot 3.0/FortAthenaMutator_Barrier.cpp b/Project Reboot 3.0/FortAthenaMutator_Barrier.cpp index 3501da4..bbd26f7 100644 --- a/Project Reboot 3.0/FortAthenaMutator_Barrier.cpp +++ b/Project Reboot 3.0/FortAthenaMutator_Barrier.cpp @@ -2,6 +2,13 @@ void AFortAthenaMutator_Barrier::OnGamePhaseStepChangedHook(UObject* Context, FFrame& Stack, void* Ret) { + auto GameState = Cast(GetWorld()->GetGameState()); + + if (!GameState) + return OnGamePhaseStepChangedOriginal(Context, Stack, Ret); + + LOG_INFO(LogDev, "OnGamePhaseStepChangedHook gamepadsl gwrigjsafjob fs: {}", (int)GameState->GetGamePhaseStep()); + /* TScriptInterface SafeZoneInterface; EAthenaGamePhaseStep GamePhaseStep; diff --git a/Project Reboot 3.0/FortLootPackage.cpp b/Project Reboot 3.0/FortLootPackage.cpp index a8879c2..4537a14 100644 --- a/Project Reboot 3.0/FortLootPackage.cpp +++ b/Project Reboot 3.0/FortLootPackage.cpp @@ -151,63 +151,45 @@ float GetAmountOfLootPackagesToDrop(FFortLootTierData* LootTierData, int Origina std::vector ItemEntries; }; */ -bool PickRowForLootTier(FName* OutName, FFortLootTierData** OutLTD, float RandMultiplier, const LOOTING_MAP_TYPE& Rows) -{ - float Rand = RandomFloatForLoot(RandMultiplier); - - if (!Rows.size()) - return false; - - for (auto& currentPair : Rows) - { - float currentWeight = currentPair.second->GetWeight(); - - if (Rand <= currentWeight) - { - *OutName = currentPair.first; - *OutLTD = currentPair.second; - return true; - } - - Rand -= currentWeight; - } - - return false; -} - -FFortLootTierData* PickLootTierData(const std::vector& LTDTables, FName LootTierGroup, int ForcedLootTier = -1, FName* OutRowName = nullptr, int* OutLootTierDataTier = nullptr) // Fortnite returns the row name and then finds the tier data again, but I really don't see the point of this. +FFortLootTierData* PickLootTierData(const std::vector& LTDTables, FName LootTierGroup, int ForcedLootTier = -1, FName* OutRowName = nullptr) // Fortnite returns the row name and then finds the tier data again, but I really don't see the point of this. { // This like isn't right, at all. - float TotalWeight = 0; + float LootTier = ForcedLootTier; - LOOTING_MAP_TYPE TierGroupLTDs; - - if (ForcedLootTier == -1) + if (LootTier == -1) { - CollectDataTablesRows(LTDTables, &TierGroupLTDs, [&](FName RowName, FFortLootTierData* TierData) -> bool { - if (LootTierGroup == TierData->GetTierGroup()) - { - TotalWeight += TierData->GetWeight(); - return true; - } - - return false; - }); + // LootTier = ?? } else { // buncha code im too lazy to reverse } - if (fabs(TotalWeight) <= 0.0000000099999999) - return 0; + // if (fabs(LootTier) <= 0.0000000099999999) + // return 0; + + int Multiplier = LootTier == -1 ? 1 : LootTier; // Idk i think we need to fill out the code above for this to work properly maybe + + LOOTING_MAP_TYPE TierGroupLTDs; + + CollectDataTablesRows(LTDTables, &TierGroupLTDs, [&](FName RowName, FFortLootTierData* TierData) -> bool { + if (LootTierGroup == TierData->GetTierGroup()) + { + if ((LootTier == -1 ? true : LootTier == TierData->GetLootTier())) + { + return true; + } + } + + return false; + }); // LOG_INFO(LogDev, "TierGroupLTDs.size(): {}", TierGroupLTDs.size()); - FFortLootTierData* ChosenRowLootTierData = nullptr; - - PickRowForLootTier(OutRowName, &ChosenRowLootTierData, TotalWeight, TierGroupLTDs); + FFortLootTierData* ChosenRowLootTierData = PickWeightedElement(TierGroupLTDs, + [](FFortLootTierData* LootTierData) -> float { return LootTierData->GetWeight(); }, RandomFloatForLoot, -1, + true, Multiplier, OutRowName); return ChosenRowLootTierData; } @@ -678,8 +660,7 @@ std::vector PickLootDrops(FName TierGroupName, int WorldLevel, int For } FName LootTierRowName; - int ltdLootTier = 0; - auto ChosenRowLootTierData = PickLootTierData(LTDTables, TierGroupName, ForcedLootTier, &LootTierRowName, <dLootTier); + auto ChosenRowLootTierData = PickLootTierData(LTDTables, TierGroupName, ForcedLootTier, &LootTierRowName); if (!ChosenRowLootTierData) { diff --git a/Project Reboot 3.0/GameModeBase.cpp b/Project Reboot 3.0/GameModeBase.cpp index 0848352..67e2b55 100644 --- a/Project Reboot 3.0/GameModeBase.cpp +++ b/Project Reboot 3.0/GameModeBase.cpp @@ -11,7 +11,7 @@ void AGameModeBase::RestartPlayerAtTransform(AController* NewPlayer, FTransform SpawnTransform) { - static auto RestartPlayerAtTransformFn = FindObject("/Script/Engine.GameModeBase.RestartPlayerAtTransform"); + static auto RestartPlayerAtTransformFn = FindObject(L"/Script/Engine.GameModeBase.RestartPlayerAtTransform"); struct { @@ -24,7 +24,7 @@ void AGameModeBase::RestartPlayerAtTransform(AController* NewPlayer, FTransform void AGameModeBase::RestartPlayerAtPlayerStart(AController* NewPlayer, AActor* StartSpot) { - static auto RestartPlayerAtPlayerStartFn = FindObject("/Script/Engine.GameModeBase.RestartPlayerAtPlayerStart"); + static auto RestartPlayerAtPlayerStartFn = FindObject(L"/Script/Engine.GameModeBase.RestartPlayerAtPlayerStart"); struct { @@ -37,13 +37,13 @@ void AGameModeBase::RestartPlayerAtPlayerStart(AController* NewPlayer, AActor* S void AGameModeBase::RestartPlayer(AController* NewPlayer) { - static auto RestartPlayerFn = FindObject("/Script/Engine.GameModeBase.RestartPlayer"); + static auto RestartPlayerFn = FindObject(L"/Script/Engine.GameModeBase.RestartPlayer"); this->ProcessEvent(RestartPlayerFn, &NewPlayer); } UClass* AGameModeBase::GetDefaultPawnClassForController(AController* InController) { - static auto GetDefaultPawnClassForControllerFn = FindObject("/Script/Engine.GameModeBase.GetDefaultPawnClassForController"); + static auto GetDefaultPawnClassForControllerFn = FindObject(L"/Script/Engine.GameModeBase.GetDefaultPawnClassForController"); struct { AController* InController; // (Parm, ZeroConstructor, IsPlainOldData, NoDestructor, HasGetValueTypeHash, NativeAccessSpecifierPublic) @@ -57,7 +57,7 @@ UClass* AGameModeBase::GetDefaultPawnClassForController(AController* InControlle void AGameModeBase::ChangeName(AController* Controller, const FString& NewName, bool bNameChange) { - static auto ChangeNameFn = FindObject("/Script/Engine.GameModeBase.ChangeName"); + static auto ChangeNameFn = FindObject(L"/Script/Engine.GameModeBase.ChangeName"); struct { @@ -71,7 +71,7 @@ void AGameModeBase::ChangeName(AController* Controller, const FString& NewName, AActor* AGameModeBase::K2_FindPlayerStart(AController* Player, FString IncomingName) { - static auto K2_FindPlayerStartFn = FindObject("/Script/Engine.GameModeBase.K2_FindPlayerStart"); + static auto K2_FindPlayerStartFn = FindObject(L"/Script/Engine.GameModeBase.K2_FindPlayerStart"); struct { diff --git a/Project Reboot 3.0/addresses.cpp b/Project Reboot 3.0/addresses.cpp index 14c50ce..f67b70d 100644 --- a/Project Reboot 3.0/addresses.cpp +++ b/Project Reboot 3.0/addresses.cpp @@ -312,6 +312,9 @@ void Addresses::FindAll() LOG_INFO(LogDev, "Finding AddToAlivePlayers"); Addresses::AddToAlivePlayers = FindAddToAlivePlayers(); + LOG_INFO(LogDev, "Applying GameSessionPatch"); + ApplyGameSessionPatch(); + LOG_INFO(LogDev, "Finished finding!"); } diff --git a/Project Reboot 3.0/addresses.h b/Project Reboot 3.0/addresses.h index 906b507..fc7bdec 100644 --- a/Project Reboot 3.0/addresses.h +++ b/Project Reboot 3.0/addresses.h @@ -74,6 +74,7 @@ namespace Addresses extern inline uint64 GetSquadIdForCurrentPlayer = 0; extern inline uint64 FinishResurrection = 0; extern inline uint64 AddToAlivePlayers = 0; + extern inline uint64 GameSessionPatch = 0; void SetupVersion(); // Finds Engine Version void FindAll(); diff --git a/Project Reboot 3.0/finder.cpp b/Project Reboot 3.0/finder.cpp index 2edb556..36eb5d8 100644 --- a/Project Reboot 3.0/finder.cpp +++ b/Project Reboot 3.0/finder.cpp @@ -47,56 +47,84 @@ uint64 FindGetPlayerViewpoint() } return __int64(PlayerControllerVFT[FailedToSpawnPawnIdx - 1]); +} - // LITERALLY KMS BRO +uint64 ApplyGameSessionPatch() +{ + auto GamePhaseStepStringAddr = Memcury::Scanner::FindStringRef(L"Gamephase Step: %s", false).Get(); - if (Engine_Version == 420 && Fortnite_Version < 4.5) + uint64 BeginningOfGamePhaseStepFn = 0; + uint8_t* ByteToPatch = 0; + + if (!GamePhaseStepStringAddr) { - return Memcury::Scanner::FindPattern("48 89 5C 24 ? 48 89 74 24 ? 55 41 56 41 57 48 8B EC 48 83 EC 50").Get(); // idk why finder doesnt work and cba to debug - } + LOG_WARN(LogFinder, "Unable to find GamePhaseStepString!"); + // return 0; - auto Addrr = Memcury::Scanner::FindStringRef(L"APlayerController::GetPlayerViewPoint: out_Location, ViewTarget=%s").Get(); + BeginningOfGamePhaseStepFn = Memcury::Scanner::FindPattern("48 89 5C 24 ? 57 48 83 EC 20 E8 ? ? ? ? 48 8B D8 48 85 C0 0F 84 ? ? ? ? E8").Get(); // not actually the func but its fine - LOG_INFO(LogDev, "GetPlayerViewpoint StringRef: 0x{:x}", __int64(Addrr) - __int64(GetModuleHandleW(0))); - - for (int i = 0; i < Fortnite_Version >= 20 ? 2000 : 1000; i++) - { - if (*(uint8_t*)(uint8_t*)(Addrr - i) == 0x40 && *(uint8_t*)(uint8_t*)(Addrr - i + 1) == 0x55) + if (!BeginningOfGamePhaseStepFn) { - LOG_INFO(LogDev, "GetPlayerViewpoint1!"); - return Addrr - i; - } - - if (*(uint8_t*)(uint8_t*)(Addrr - i) == 0x48 && *(uint8_t*)(uint8_t*)(Addrr - i + 1) == 0x8B && *(uint8_t*)(uint8_t*)(Addrr - i + 2) == 0xC4) - { - LOG_INFO(LogDev, "GetPlayerViewpoint2!"); - return Addrr - i; - } - - if (Fortnite_Version == 7.20 && *(uint8_t*)(uint8_t*)(Addrr - i) == 0xC3) // hmm scuffed lmfao - { - LOG_INFO(LogDev, "Hit C3!"); - break; + LOG_WARN(LogFinder, "Unable to find fallback sig for gamephase step! Report to Milxnor immediately."); + return 0; } } - for (int i = 0; i < 1000; i++) + if (!BeginningOfGamePhaseStepFn && !ByteToPatch) { - if (*(uint8_t*)(uint8_t*)(Addrr - i) == 0x48 && *(uint8_t*)(uint8_t*)(Addrr - i + 1) == 0x89 && *(uint8_t*)(uint8_t*)(Addrr - i + 2) == 0x74) + for (int i = 0; i < 3000; i++) { - LOG_INFO(LogDev, "GetPlayerViewpoint3!"); - return Addrr - i; + if (*(uint8_t*)(uint8_t*)(GamePhaseStepStringAddr - i) == 0x40 && *(uint8_t*)(uint8_t*)(GamePhaseStepStringAddr - i + 1) == 0x55) + { + BeginningOfGamePhaseStepFn = GamePhaseStepStringAddr - i; + break; + } + + if (*(uint8_t*)(uint8_t*)(GamePhaseStepStringAddr - i) == 0x48 && *(uint8_t*)(uint8_t*)(GamePhaseStepStringAddr - i + 1) == 0x89 && *(uint8_t*)(uint8_t*)(GamePhaseStepStringAddr - i + 2) == 0x5C) + { + BeginningOfGamePhaseStepFn = GamePhaseStepStringAddr - i; + break; + } + + if (*(uint8_t*)(uint8_t*)(GamePhaseStepStringAddr - i) == 0x48 && *(uint8_t*)(uint8_t*)(GamePhaseStepStringAddr - i + 1) == 0x8B && *(uint8_t*)(uint8_t*)(GamePhaseStepStringAddr - i + 2) == 0xC4) + { + BeginningOfGamePhaseStepFn = GamePhaseStepStringAddr - i; + break; + } + } + } + + if (!BeginningOfGamePhaseStepFn && !ByteToPatch) + { + LOG_WARN(LogFinder, "Unable to find beginning of GamePhaseStep! Report to Milxnor immediately."); + return 0; + } + + if (!ByteToPatch) + { + for (int i = 0; i < 500; i++) + { + if (*(uint8_t*)(uint8_t*)(BeginningOfGamePhaseStepFn + i) == 0x0F && *(uint8_t*)(uint8_t*)(BeginningOfGamePhaseStepFn + i + 1) == 0x84) + { + ByteToPatch = (uint8_t*)(uint8_t*)(BeginningOfGamePhaseStepFn + i + 1); + break; + } } } - for (int i = 0; i < 1000; i++) + if (!ByteToPatch) { - if (*(uint8_t*)(uint8_t*)(Addrr - i) == 0x48 && *(uint8_t*)(uint8_t*)(Addrr - i + 1) == 0x89 && *(uint8_t*)(uint8_t*)(Addrr - i + 2) == 0x5C) - { - LOG_INFO(LogDev, "GetPlayerViewpoint4!"); - return Addrr - i; - } + LOG_WARN(LogFinder, "Unable to find byte to patch for GamePhaseStep!"); + return 0; } + DWORD dwProtection; + VirtualProtect((PVOID)ByteToPatch, 1, PAGE_EXECUTE_READWRITE, &dwProtection); + + *ByteToPatch = 0x85; + + DWORD dwTemp; + VirtualProtect((PVOID)ByteToPatch, 1, dwProtection, &dwTemp); + return 0; } \ No newline at end of file diff --git a/Project Reboot 3.0/finder.h b/Project Reboot 3.0/finder.h index d3d27f2..9a9ffb4 100644 --- a/Project Reboot 3.0/finder.h +++ b/Project Reboot 3.0/finder.h @@ -492,6 +492,7 @@ static inline uint64 FindGetMaxTickRate() // UEngine::getmaxtickrate } uint64 FindGetPlayerViewpoint(); +uint64 ApplyGameSessionPatch(); static inline uint64 FindFree() {