From cabf3fde209063abe549d4bde09e498dd9483b41 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Tue, 23 Nov 2021 19:54:39 +0100 Subject: [PATCH] Change IntroAnimationPatch to run closer to how it does on MpEx --- .gitignore | 4 +- .../src/Hooks/MaxPlayerHooks.cpp | 80 ++++++++----------- 2 files changed, 37 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 2d0c526..7685831 100644 --- a/.gitignore +++ b/.gitignore @@ -344,4 +344,6 @@ ARM/ ARM64/ # User props -ndkbuild.props \ No newline at end of file +ndkbuild.props +/MultiQuestensions/log_timestamp +*.qmod diff --git a/MultiQuestensions/src/Hooks/MaxPlayerHooks.cpp b/MultiQuestensions/src/Hooks/MaxPlayerHooks.cpp index 428ceac..e2ec394 100644 --- a/MultiQuestensions/src/Hooks/MaxPlayerHooks.cpp +++ b/MultiQuestensions/src/Hooks/MaxPlayerHooks.cpp @@ -40,48 +40,50 @@ namespace MultiQuestensions { } MAKE_HOOK_MATCH(IntroAnimationPatch, &MultiplayerIntroAnimationController::PlayIntroAnimation, void, MultiplayerIntroAnimationController* self, float maxDesiredIntroAnimationDuration, Action* onCompleted) { - targetIterations = ((((IReadOnlyCollection_1*)self->multiplayerPlayersManager->allActiveAtGameStartPlayers)->get_Count() - 1) / 4) + 1; PlayableDirector* realDirector = self->introPlayableDirector; - + if (targetIterations == 0) + { + targetIterations = floor((reinterpret_cast*>(self->multiplayerPlayersManager->allActiveAtGameStartPlayers)->get_Count() - 1) / 4) + 1; + } try { // Run animation one time for each set of 4 players - while (targetIterations > 0) { - if (targetIterations != 1) { - // Create duplicated animations - GameObject* newPlayableGameObject = GameObject::New_ctor(); - self->introPlayableDirector = newPlayableGameObject->AddComponent(); - - using SetPlayableAsset = function_ptr_t; - static SetPlayableAsset setPlayableAsset = reinterpret_cast(il2cpp_functions::resolve_icall("UnityEngine.Playables.PlayableDirector::SetPlayableAsset")); - setPlayableAsset(self->introPlayableDirector, realDirector->get_playableAsset()); - - // Mute duplicated animations except one (otherwise audio is very loud) - TimelineAsset* animationTimeline = reinterpret_cast(self->introPlayableDirector->get_playableAsset()); - - static auto* Enumerable_ToList_Generic = THROW_UNLESS(il2cpp_utils::FindMethodUnsafe(classof(Enumerable*), "ToList", 1)); - static auto* Enumerable_ToList = THROW_UNLESS(il2cpp_utils::MakeGenericMethod(Enumerable_ToList_Generic, { classof(TrackAsset*) })); - - //List* outputTracks = Enumerable::ToList(animationTimeline->GetOutputTracks()); - List* outputTracks = il2cpp_utils::RunMethodThrow*, false>(static_cast(nullptr), - Enumerable_ToList, animationTimeline->GetOutputTracks()); - - for (int i = 0; i < outputTracks->get_Count(); i++) { - TrackAsset* currentTrack = outputTracks->get_Item(i); - bool isAudio = il2cpp_utils::AssignableFrom(reinterpret_cast(currentTrack)->klass); - currentTrack->set_muted(isAudio); - } - } + if (targetIterations != 1) { + // Create duplicated animations + GameObject* newPlayableGameObject = GameObject::New_ctor(); + self->introPlayableDirector = newPlayableGameObject->AddComponent(); + + using SetPlayableAsset = function_ptr_t; + static SetPlayableAsset setPlayableAsset = reinterpret_cast(il2cpp_functions::resolve_icall("UnityEngine.Playables.PlayableDirector::SetPlayableAsset")); + setPlayableAsset(self->introPlayableDirector, realDirector->get_playableAsset()); + + // Mute duplicated animations except one (otherwise audio is very loud) + TimelineAsset* mutedTimeline = reinterpret_cast(self->introPlayableDirector->get_playableAsset()); - self->bindingFinished = false; - IntroAnimationPatch(self, maxDesiredIntroAnimationDuration, onCompleted); - self->introPlayableDirector = realDirector; - targetIterations--; + static auto* Enumerable_ToList_Generic = THROW_UNLESS(il2cpp_utils::FindMethodUnsafe(classof(Enumerable*), "ToList", 1)); + static auto* Enumerable_ToList = THROW_UNLESS(il2cpp_utils::MakeGenericMethod(Enumerable_ToList_Generic, { classof(TrackAsset*) })); + + //List* outputTracks = Enumerable::ToList(animationTimeline->GetOutputTracks()); + List* outputTracks = il2cpp_utils::RunMethodThrow*, false>(static_cast(nullptr), + Enumerable_ToList, mutedTimeline->GetOutputTracks()); + + for (int i = 0; i < outputTracks->get_Count(); i++) { + TrackAsset* currentTrack = outputTracks->get_Item(i); + bool isAudio = il2cpp_utils::AssignableFrom(reinterpret_cast(currentTrack)->klass); + currentTrack->set_muted(isAudio); + } } + self->bindingFinished = false; + IntroAnimationPatch(self, maxDesiredIntroAnimationDuration, onCompleted); // Reset director to real director self->introPlayableDirector = realDirector; + targetIterations--; + if (targetIterations != 0) + self->PlayIntroAnimation(maxDesiredIntroAnimationDuration, onCompleted); } catch (const std::runtime_error& e) { + // Reset director to real director + self->introPlayableDirector = realDirector; getLogger().critical("REPORT TO ENDER: Hook IntroAnimationPatch" __FILE__ " at Line %d: %s", __LINE__, e.what()); IntroAnimationPatch(self, maxDesiredIntroAnimationDuration, onCompleted); } @@ -105,9 +107,6 @@ namespace MultiQuestensions { MAKE_HOOK_MATCH(MultiplayerPlayersManager_get_allActiveAtGameStartPlayers, &MultiplayerPlayersManager::get_allActiveAtGameStartPlayers, IReadOnlyList_1*, MultiplayerPlayersManager* self) { getLogger().debug("Start: MultiplayerPlayersManager_get_allActiveAtGameStartPlayers"); - // 09-21 14:30:26.025 4647 4672 D QuestHook[UtilsLogger|v2.3.0]: (il2cpp_utils::FindMethod) Method 27: - // 09-21 14:30:26.026 4647 4672 D QuestHook[UtilsLogger|v2.3.0]: (il2cpp_utils::FindMethod) static - // System.Collections.Generic.List ToList(System.Collections.Generic.IEnumerable source); static auto* Enumerable_ToList_Generic = THROW_UNLESS(il2cpp_utils::FindMethodUnsafe(classof(Enumerable*), "ToList", 1)); static auto* Enumerable_ToList = THROW_UNLESS(il2cpp_utils::MakeGenericMethod(Enumerable_ToList_Generic, { classof(IConnectedPlayer*) })); @@ -177,17 +176,6 @@ namespace MultiQuestensions { CreateServerFormData result = CreateServerFormController_get_formData(self); result.maxPlayers = (int)std::clamp(self->dyn__maxPlayersList()->value, 2.0f, fminf(getConfig().config["MaxPlayers"].GetFloat(), 100)); return result; - //return CreateServerFormData - //{ - // (int)std::clamp(self->dyn__maxPlayersList()->value, 2.0f, 10.0f), - // self->dyn__netDiscoverable(), - // BeatmapDifficultyMask::All, - // GameplayModifierMask::All, - // SongPackMask::get_all(), - // GameplayServerMode::Managed, - // SongSelectionMode::OwnerPicks, - // GameplayServerControlSettings::All - //}; } MAKE_HOOK_MATCH(CreateServerFormController_Setup, &CreateServerFormController::Setup, void, CreateServerFormController* self, int selectedNumberOfPlayers, bool netDiscoverable) {