mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
Rework custom intro logic
This commit is contained in:
1 parent
beb670f0d8
commit
3342bb536b
1 file changed
+84
-52
@@ -7,10 +7,14 @@ namespace BetterAmongUs.Patches.Client;
|
||||
[HarmonyPatch]
|
||||
internal static class SplashIntroPatch
|
||||
{
|
||||
private const float MinIntroDuration = 3f;
|
||||
private const float AudioDestroyTime = 1.8f;
|
||||
|
||||
internal static bool Skip = false;
|
||||
internal static bool BetterIntro = false;
|
||||
internal static bool IsReallyDoneLoading = false;
|
||||
private static GameObject? BetterLogo;
|
||||
|
||||
private static GameObject? _betterLogo;
|
||||
|
||||
[HarmonyPatch(typeof(SplashManager), nameof(SplashManager.Start))]
|
||||
[HarmonyPrefix]
|
||||
@@ -22,84 +26,112 @@ internal static class SplashIntroPatch
|
||||
IsReallyDoneLoading = false;
|
||||
|
||||
// Hide black overlay by moving it out of view
|
||||
__instance.logoAnimFinish.transform.Find("BlackOverlay").transform.SetLocalY(100f);
|
||||
__instance.logoAnimFinish.transform
|
||||
.Find("BlackOverlay").transform
|
||||
.SetLocalY(100f);
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(SplashManager), nameof(SplashManager.Update))]
|
||||
[HarmonyPrefix]
|
||||
private static bool SplashManager_Update_Prefix(SplashManager __instance)
|
||||
{
|
||||
// If skip is triggered, just check if loading is done
|
||||
if (Skip)
|
||||
{
|
||||
CheckIfDone(__instance);
|
||||
return false;
|
||||
}
|
||||
|
||||
// After 1.8 seconds in BAU intro, remove audio to prevent overlap
|
||||
if (Time.time - __instance.startTime > 1.8f && BetterIntro)
|
||||
HandleAudioDestruction(__instance);
|
||||
|
||||
if (TryHandleSkipClick(__instance))
|
||||
{
|
||||
Skip = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CanStartBetterIntro(__instance))
|
||||
{
|
||||
StartBetterIntro(__instance);
|
||||
return false;
|
||||
}
|
||||
|
||||
CheckIfDone(__instance);
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void HandleAudioDestruction(SplashManager __instance)
|
||||
{
|
||||
if (!BetterIntro) return;
|
||||
|
||||
if (Time.time - __instance.startTime > AudioDestroyTime)
|
||||
{
|
||||
UnityEngine.Object.Destroy(__instance.logoAnimFinish.GetComponent<AudioSource>());
|
||||
}
|
||||
}
|
||||
|
||||
// Allow mouse click to skip splash screen
|
||||
if (Input.GetKeyDown(KeyCode.Mouse0) || Input.GetKeyDown(KeyCode.Mouse1))
|
||||
{
|
||||
if (CheckIfDone(__instance, true))
|
||||
{
|
||||
Skip = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private static bool TryHandleSkipClick(SplashManager __instance)
|
||||
{
|
||||
if (!Input.GetKeyDown(KeyCode.Mouse0) && !Input.GetKeyDown(KeyCode.Mouse1))
|
||||
return false;
|
||||
|
||||
// When game data is loaded and minimum time has passed
|
||||
if (__instance.doneLoadingRefdata && !__instance.startedSceneLoad && Time.time - __instance.startTime > __instance.minimumSecondsBeforeSceneChange)
|
||||
{
|
||||
if (!BetterIntro)
|
||||
{
|
||||
// Start BAU custom intro sequence
|
||||
__instance.startTime = Time.time;
|
||||
__instance.logoAnimFinish.gameObject.SetActive(false);
|
||||
__instance.logoAnimFinish.gameObject.SetActive(true);
|
||||
return CheckIfDone(__instance, true);
|
||||
}
|
||||
|
||||
// Replace InnerSloth logo with BAU logo
|
||||
GameObject InnerLogo = __instance.logoAnimFinish.transform.Find("LogoRoot/ISLogo").gameObject;
|
||||
BetterLogo = UnityEngine.Object.Instantiate(InnerLogo, InnerLogo.transform.parent);
|
||||
InnerLogo.DestroyObj();
|
||||
BetterLogo.name = "BetterLogo";
|
||||
BetterLogo.GetComponent<SpriteRenderer>().sprite = Utils.LoadSprite("BetterAmongUs.Resources.Images.BetterAmongUs-Logo.png", 150f);
|
||||
private static bool CanStartBetterIntro(SplashManager __instance)
|
||||
{
|
||||
return __instance.doneLoadingRefdata &&
|
||||
!__instance.startedSceneLoad &&
|
||||
Time.time - __instance.startTime > __instance.minimumSecondsBeforeSceneChange;
|
||||
}
|
||||
|
||||
// Show black overlay
|
||||
__instance.logoAnimFinish.transform.Find("BlackOverlay").transform.SetLocalY(0f);
|
||||
private static void StartBetterIntro(SplashManager __instance)
|
||||
{
|
||||
if (BetterIntro) return;
|
||||
|
||||
BetterIntro = true;
|
||||
return false;
|
||||
}
|
||||
// Start BAU custom intro sequence
|
||||
__instance.startTime = Time.time;
|
||||
__instance.logoAnimFinish.gameObject.SetActive(false);
|
||||
__instance.logoAnimFinish.gameObject.SetActive(true);
|
||||
|
||||
// Check if BAU intro has completed
|
||||
CheckIfDone(__instance);
|
||||
}
|
||||
// Replace InnerSloth logo with BAU logo
|
||||
ReplaceLogo(__instance);
|
||||
|
||||
// Return false to prevent original Update from running (we handle everything)
|
||||
return false;
|
||||
// Show black overlay
|
||||
__instance.logoAnimFinish.transform
|
||||
.Find("BlackOverlay").transform
|
||||
.SetLocalY(0f);
|
||||
|
||||
BetterIntro = true;
|
||||
}
|
||||
|
||||
private static void ReplaceLogo(SplashManager __instance)
|
||||
{
|
||||
var innerLogo = __instance.logoAnimFinish.transform
|
||||
.Find("LogoRoot/ISLogo").gameObject;
|
||||
|
||||
_betterLogo = UnityEngine.Object.Instantiate(innerLogo, innerLogo.transform.parent);
|
||||
innerLogo.DestroyObj();
|
||||
|
||||
_betterLogo.name = "BetterLogo";
|
||||
_betterLogo.GetComponent<SpriteRenderer>().sprite =
|
||||
Utils.LoadSprite("BetterAmongUs.Resources.Images.BetterAmongUs-Logo.png", 150f);
|
||||
}
|
||||
|
||||
private static bool CheckIfDone(SplashManager __instance, bool isSkip = false)
|
||||
{
|
||||
// Allow transition if:
|
||||
// 1. BAU intro played for 2 seconds OR
|
||||
// 2. User skipped and BAU intro was shown
|
||||
if ((Time.time - __instance.startTime > 2f && BetterIntro) || (isSkip && BetterIntro))
|
||||
{
|
||||
IsReallyDoneLoading = true;
|
||||
// Allow transition if intro played for minimum duration or user skipped
|
||||
var introComplete = (Time.time - __instance.startTime > MinIntroDuration && BetterIntro) ||
|
||||
(isSkip && BetterIntro);
|
||||
|
||||
// Allow scene transition to proceed
|
||||
__instance.sceneChanger.AllowFinishLoadingScene();
|
||||
__instance.startedSceneLoad = true;
|
||||
__instance.loadingObject.SetActive(true);
|
||||
return true;
|
||||
}
|
||||
if (!introComplete) return false;
|
||||
|
||||
return false;
|
||||
IsReallyDoneLoading = true;
|
||||
|
||||
// Allow scene transition to proceed
|
||||
__instance.sceneChanger.AllowFinishLoadingScene();
|
||||
__instance.startedSceneLoad = true;
|
||||
__instance.loadingObject.SetActive(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user