From 153a125329dc94add4dcfb3aed7490529db2d463 Mon Sep 17 00:00:00 2001 From: Altixal <73398287+Altixal@users.noreply.github.com> Date: Tue, 4 Jul 2023 14:49:10 +0700 Subject: [PATCH] Provi sound failsafe + Lava --- ILEditing/ILChangesLoading.cs | 14 ++----- ILEditing/ILHelperMethods.cs | 9 +++++ ILEditing/MechanicILChanges.cs | 70 +++++++++++++++++++++------------- NPCs/Providence/Providence.cs | 4 +- 4 files changed, 60 insertions(+), 37 deletions(-) diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index 8d6e15ab50..1477d1b090 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -34,16 +34,10 @@ namespace CalamityMod.ILEditing Terraria.On_Main.SetDisplayMode += ResetRenderTargetSizes; Terraria.On_Main.SortDrawCacheWorms += DrawFusableParticles; Terraria.On_Main.DrawInfernoRings += DrawForegroundParticles; - - // ERROR - //Terraria.GameContent.Drawing.On_TileDrawing.DrawPartialLiquid += DrawCustomLava; - // ERROR - //Terraria.IL_WaterfallManager.DrawWaterfall += DrawCustomLavafalls; - // ERROR - //Terraria.GameContent.Liquid.IL_LiquidRenderer.InternalDraw += ChangeWaterQuadColors; - // ERROR - //Terraria.IL_Main.oldDrawWater += DrawCustomLava3; - + Terraria.GameContent.Drawing.On_TileDrawing.DrawPartialLiquid += DrawCustomLava; + Terraria.On_WaterfallManager.DrawWaterfall_int_int_int_float_Vector2_Rectangle_Color_SpriteEffects += DrawCustomLavafalls; + Terraria.GameContent.Liquid.IL_LiquidRenderer.DrawNormalLiquids += ChangeWaterQuadColors; + Terraria.IL_Main.oldDrawWater += DrawCustomLava3; Terraria.Graphics.Light.On_TileLightScanner.GetTileLight += MakeSulphSeaWaterBetter; Terraria.GameContent.Drawing.On_TileDrawing.PreDrawTiles += ClearForegroundStuff; Terraria.GameContent.Drawing.On_TileDrawing.Draw += ClearTilePings; diff --git a/ILEditing/ILHelperMethods.cs b/ILEditing/ILHelperMethods.cs index f11c936e0a..8065c7551b 100644 --- a/ILEditing/ILHelperMethods.cs +++ b/ILEditing/ILHelperMethods.cs @@ -91,6 +91,15 @@ namespace CalamityMod.ILEditing return initialTexture; } + private static VertexColors SelectLavaQuadColor(Texture2D initialTexture, VertexColors initialColor, bool forceTrue = false) + { + initialColor.TopLeftColor = SelectLavaColor(initialTexture, initialColor.TopLeftColor, forceTrue); + initialColor.TopRightColor = SelectLavaColor(initialTexture, initialColor.TopRightColor, forceTrue); + initialColor.BottomLeftColor = SelectLavaColor(initialTexture, initialColor.BottomLeftColor, forceTrue); + initialColor.BottomRightColor = SelectLavaColor(initialTexture, initialColor.BottomRightColor, forceTrue); + return initialColor; + } + private static Color SelectLavaColor(Texture2D initialTexture, Color initialLightColor, bool forceTrue = false) { // Use the initial color if it isn't lava. diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index b55bff0509..f0aa4de51c 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -687,9 +687,12 @@ namespace CalamityMod.ILEditing #endregion General Particle Rendering #region Custom Lava Visuals - /*private static void DrawCustomLava(Terraria.GameContent.Drawing.On_TileDrawing.orig_DrawPartialLiquid orig, TileDrawing self, Tile tileCache, Vector2 position, Rectangle liquidSize, int liquidType, Color aColor) + private static void DrawCustomLava(Terraria.GameContent.Drawing.On_TileDrawing.orig_DrawPartialLiquid orig, TileDrawing self, bool behindBlocks, Tile tileCache, ref Vector2 position, ref Rectangle liquidSize, int liquidType, ref VertexColors colors) { - if (liquidType != 1) + //liquidType = CustomLavaManagement.SelectLavafallStyle(liquidType); + //orig(self, behindBlocks, tileCache, ref position, ref liquidSize, liquidType, ref colors); + + /*if (liquidType != 1) { orig(self, tileCache, position, liquidSize, liquidType, aColor); return; @@ -725,8 +728,41 @@ namespace CalamityMod.ILEditing if (tileCache.Slope == SlopeType.SlopeUpRight) { Main.spriteBatch.Draw(slopeTexture, position, liquidSize, aColor, 0f, Vector2.Zero, 1f, 0, 0f); + }*/ + + if (liquidType != 1) + { + orig(self, behindBlocks, tileCache, ref position, ref liquidSize, liquidType, ref colors); + return; } - }*/ + + int slope = (int)tileCache.Slope; + colors = SelectLavaQuadColor(TextureAssets.LiquidSlope[liquidType].Value, colors, liquidType == 1); + if (!TileID.Sets.BlocksWaterDrawingBehindSelf[tileCache.TileType] || behindBlocks || slope == 0) + { + Texture2D liquidTexture = SelectLavaTexture(liquidType == 1 ? CustomLavaManagement.LavaBlockTexture : TextureAssets.Liquid[liquidType].Value, LiquidTileType.Block); + Main.tileBatch.Draw(liquidTexture, position, liquidSize, colors, default(Vector2), 1f, SpriteEffects.None); + return; + } + + Texture2D slopeTexture = SelectLavaTexture(liquidType == 1 ? CustomLavaManagement.LavaSlopeTexture : TextureAssets.LiquidSlope[liquidType].Value, LiquidTileType.Slope); + liquidSize.X += 18 * (slope - 1); + switch (slope) + { + case 1: + Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None); + break; + case 2: + Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None); + break; + case 3: + Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None); + break; + case 4: + Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None); + break; + } + } private static void ChangeWaterQuadColors(ILContext il) { @@ -764,10 +800,7 @@ namespace CalamityMod.ILEditing cursor.Emit(OpCodes.Ldloc, 4); cursor.EmitDelegate>((initialColor, initialTexture, liquidType, x, y) => { - initialColor.TopLeftColor = SelectLavaColor(initialTexture, initialColor.TopLeftColor, liquidType == 1); - initialColor.TopRightColor = SelectLavaColor(initialTexture, initialColor.TopRightColor, liquidType == 1); - initialColor.BottomLeftColor = SelectLavaColor(initialTexture, initialColor.BottomLeftColor, liquidType == 1); - initialColor.BottomRightColor = SelectLavaColor(initialTexture, initialColor.BottomRightColor, liquidType == 1); + initialColor = SelectLavaQuadColor(initialTexture, initialColor, liquidType == 1); if (liquidType == ModContent.Find("CalamityMod/SunkenSeaWater").Slot || liquidType == ModContent.Find("CalamityMod/SulphuricWater").Slot || @@ -873,27 +906,12 @@ namespace CalamityMod.ILEditing } } - private static void DrawCustomLavafalls(ILContext il) + private static void DrawCustomLavafalls(Terraria.On_WaterfallManager.orig_DrawWaterfall_int_int_int_float_Vector2_Rectangle_Color_SpriteEffects orig, WaterfallManager self, int waterfallType, int x, int y, float opacity, Vector2 position, Rectangle sourceRect, Color color, SpriteEffects effects) { - ILCursor cursor = new ILCursor(il); + waterfallType = CustomLavaManagement.SelectLavafallStyle(waterfallType); + color = CustomLavaManagement.SelectLavafallColor(waterfallType, color); - // Search for the color and alter it based on the same conditions as the lava. - if (!cursor.TryGotoNext(c => c.MatchCallOrCallvirt(typeof(Color).GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) })))) - { - LogFailure("Custom Lavafall Drawing", "Could not locate the waterfall color."); - return; - } - - // Determine the waterfall type. This happens after all the "If Lava do blahblahblah" color checks, meaning it will have the same - // color properties as lava. - cursor.Emit(OpCodes.Ldloc, 12); - cursor.EmitDelegate>(initialWaterfallStyle => CustomLavaManagement.SelectLavafallStyle(initialWaterfallStyle)); - cursor.Emit(OpCodes.Stloc, 12); - - cursor.Emit(OpCodes.Ldloc, 12); - cursor.Emit(OpCodes.Ldloc, 54); - cursor.EmitDelegate>((initialWaterfallStyle, initialLavafallColor) => CustomLavaManagement.SelectLavafallColor(initialWaterfallStyle, initialLavafallColor)); - cursor.Emit(OpCodes.Stloc, 54); + orig(self, waterfallType, x, y, opacity, position, sourceRect, color, effects); } #endregion Custom Lava Visuals diff --git a/NPCs/Providence/Providence.cs b/NPCs/Providence/Providence.cs index 05edcc3ade..70cba956b5 100644 --- a/NPCs/Providence/Providence.cs +++ b/NPCs/Providence/Providence.cs @@ -409,6 +409,8 @@ namespace CalamityMod.NPCs.Providence SoundWarningLevel = 0f; } } + else if (SoundWarningLevel > 0f) + SoundWarningLevel -= 1 / 50f; // Updating the looping sound if (SoundEngine.TryGetActiveSound(BurningSoundSlot, out var burningSound) && burningSound.IsPlaying) @@ -419,7 +421,7 @@ namespace CalamityMod.NPCs.Providence { if (SoundWarningLevel <= 1f) burningSound?.Stop(); - else if(SoundWarningLevel < 2f) + else if(SoundWarningLevel <= 2f) burningSound.Volume = SoundWarningLevel - 1f; }