11using CustomLoadingScreens . Managers ;
22using HarmonyLib ;
33using Il2Cpp ;
4- using Il2CppAssets . Scripts . PeroTools . Commons ;
5- using Il2CppInterop . Runtime . InteropTypes . Arrays ;
64using UnityEngine ;
75using UnityEngine . UI ;
86using Logger = CustomLoadingScreens . Utilities . Logger ;
@@ -11,45 +9,44 @@ namespace CustomLoadingScreens.Patches
119{
1210 internal class LoadingImagePatch
1311 {
14-
1512 /// <summary>
1613 /// This HarmonyPatch class does all the work for setting the custom backgrounds and text.
1714 /// </summary>
1815 [ HarmonyPatch ( typeof ( LoadingImg ) , nameof ( LoadingImg . OnEnable ) ) ]
1916 internal class LoadingImgPatch
2017 {
2118 private static readonly Logger Logger = new ( nameof ( LoadingImgPatch ) ) ;
22- private static bool Is43AspectRatio ( double width , double height ) => width % height / height <= 1.7 ;
19+ private static bool Is43AspectRatio ( double width , double height ) => width % height / height <= 1.7 ;
2320 private static void Postfix ( ref LoadingImg __instance )
2421 {
2522
2623 // Rolled a custom image and we have a custom image
2724 if ( ProbabilityManager . UseCustomImage && CustomDataManager . CustomImages . Any ( ) )
2825 {
2926 var customImage = ProbabilityManager . GetRandomImage ( ) ;
30- Il2CppArrayBase < Image > components ;
27+ Main . CurrentCustomImage = customImage ;
3128
3229 __instance . simpleIllus . SetActive ( false ) ;
3330 __instance . specialIllus . SetActive ( false ) ;
3431 __instance . verySpecialIllus . SetActive ( false ) ;
3532 __instance . specialIllusfor43 . SetActive ( false ) ;
3633
3734 // Deal with the specialIllus variables, respective of aspect ratio
38- if ( Is43AspectRatio ( customImage . Sprite . texture . width , customImage . Sprite . texture . height ) )
35+ if ( Is43AspectRatio ( customImage . Sprites [ 0 ] . texture . width , customImage . Sprites [ 0 ] . texture . height ) )
3936 {
4037 __instance . specialIllusfor43 . SetActive ( true ) ;
41- components = __instance . specialIllusfor43 . GetComponents < Image > ( ) ;
38+ Main . Images = __instance . specialIllusfor43 . GetComponents < Image > ( ) ;
4239 }
4340 else
4441 {
4542 __instance . specialIllus . SetActive ( true ) ;
46- components = __instance . simpleIllus . GetComponents < Image > ( ) ;
43+ Main . Images = __instance . simpleIllus . GetComponents < Image > ( ) ;
4744 }
4845
4946 // Sets all image components in the Illus to the custom image
50- foreach ( var image in components )
47+ foreach ( var image in Main . Images )
5148 {
52- image . sprite = customImage . Sprite ;
49+ image . sprite = customImage . Sprites [ 0 ] ;
5350 }
5451
5552 // We can only use bound quotes if that image exists, bound quotes will always be displayed
@@ -85,6 +82,24 @@ private static void Postfix(ref LoadingImg __instance)
8582
8683 Logger . Msg ( "Custom random loading text has been loaded." ) ;
8784 }
85+
86+ /// <summary>
87+ /// Adds support for GIF images.
88+ /// </summary>
89+ internal static void Update ( )
90+ {
91+ if ( Main . CurrentCustomImage is null || Main . Images == null || Main . CurrentCustomImage . FramesPerSecond == 0 ) return ;
92+
93+ var frame = ( int ) Mathf . Floor ( Time . time * 1000 ) %
94+ ( Main . CurrentCustomImage . FramesPerSecond * Main . CurrentCustomImage . FrameCount ) / Main . CurrentCustomImage . FramesPerSecond ;
95+
96+ // Updates animated loading screens
97+ foreach ( var compImage in Main . Images )
98+ {
99+ if ( compImage == null ) return ;
100+ compImage . sprite = Main . CurrentCustomImage . Sprites [ frame ] ;
101+ }
102+ }
88103 }
89104 }
90105}
0 commit comments