Fixed vanilla not accounting for spritebatch modification in held projectile drawing (#13)

* - Properly restore spritebatch to its original settings.

* - Try-Catch + error logging.

* Actually check the bool.

---------

Co-authored-by: Cameron Ewell <spazeglitch@gmail.com>
This commit is contained in:
ToastyandCameron Ewell authored and Ozzatron committed 2023-12-10 19:04:07 -05:00
1 parent c902dc5d2f
commit 42497f3aeb
2 files changed
+32

No files matched your search

+4
View File
@@ -6,6 +6,7 @@ using CalamityMod.Items.Armor.LunicCorps;
using CalamityMod.Tiles.DraedonStructures;
using CalamityMod.Tiles.FurnitureExo;
using Terraria;
using Terraria.DataStructures;
using Terraria.GameContent;
using Terraria.GameContent.Drawing;
using Terraria.GameContent.Events;
@@ -146,6 +147,9 @@ namespace CalamityMod.ILEditing
// Fix vanilla bugs exposed by Calamity mechanics
IL_NPC.NPCLoot += FixSplittingWormBannerDrops;
// Fix vanilla not accounting for spritebatch modification in held projectile drawing
On_PlayerDrawLayers.DrawHeldProj += FixHeldProjectileBlendState;
//Additional detours that are in their own item files given they are only relevant to these specific items:
//Rover drive detours on Player.DrawInfernoRings to draw its shield
//Wulfrum armor hooks on Player.KeyDoubleTap and DrawPendingMouseText to activate its set bonus and spoof the mouse text to display the stats of the activated weapon if shift is held
+28
View File
@@ -1,8 +1,11 @@
using CalamityMod.NPCs;
using Microsoft.Xna.Framework.Graphics;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using System;
using Terraria;
using Terraria.DataStructures;
using Terraria.Graphics.Renderers;
namespace CalamityMod.ILEditing
{
@@ -41,5 +44,30 @@ namespace CalamityMod.ILEditing
cursor.Emit(OpCodes.Brfalse, ret);
}
#endregion Fixing Splitting Worm Banner Spam in Deathmode
#region Fixing Vanilla Not Accounting For Spritebatch Modification in Held Projectiles
private static bool HasLoggedHeldProjectileBlendStateCatch = false;
private void FixHeldProjectileBlendState(On_PlayerDrawLayers.orig_DrawHeldProj orig, PlayerDrawSet drawinfo, Projectile proj)
{
orig(drawinfo, proj);
// Vanilla uses a worse quality sampler state for mounts when moving for some reason. Really couldn't say why.
var sampler = (drawinfo.drawPlayer.mount.Active && drawinfo.drawPlayer.fullRotation != 0f) ? LegacyPlayerRenderer.MountedSamplerState : Main.DefaultSamplerState;
try
{
// Restart the spritebatch, to ensure that modifications made to it are properly restored.
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, sampler, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
}
catch
{
if (!HasLoggedHeldProjectileBlendStateCatch)
LogFailure("FixHeldProjectileBlendState", "The spritebatch was not left properly by another mod! The game will now most likely crash.");
HasLoggedHeldProjectileBlendStateCatch = true;
}
}
#endregion
}
}