Added MultiVariantModWall
This commit is contained in:
1 parent
f4c60af34a
commit
10f91e6339
2 files changed
+81
No files matched your search
@@ -0,0 +1,72 @@
|
||||
using CalamityMod.ILEditing;
|
||||
using CalamityMod.Walls;
|
||||
using Microsoft.Xna.Framework;
|
||||
using MonoMod.Cil;
|
||||
using Terraria;
|
||||
using Terraria.GameContent.Drawing;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Systems
|
||||
{
|
||||
internal sealed class MultiVariantWallDrawingSystem : ModSystem
|
||||
{
|
||||
public sealed override void Load()
|
||||
{
|
||||
IL_WallDrawing.DrawWalls += DrawingFrameOffsetForWallSupport;
|
||||
}
|
||||
|
||||
private void DrawingFrameOffsetForWallSupport(ILContext il)
|
||||
{
|
||||
var cursor = new ILCursor(il);
|
||||
|
||||
if (!cursor.TryGotoNext(x => x.MatchCall<Tile>("wallFrameY")))
|
||||
{
|
||||
LogILFailure("call::Tile.wallFrameY was not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
int tileLocalIdx = -1;
|
||||
int rectLocalIdx = -1;
|
||||
if (!cursor.TryGotoPrev(x => x.MatchLdloca(out tileLocalIdx))) // First ldloca should be "tile"
|
||||
{
|
||||
LogILFailure("Ldloca::tile was not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cursor.TryGotoPrev(x => x.MatchLdloca(out rectLocalIdx))) // Second ldloca should be "value" which is Rectangle for drawing
|
||||
{
|
||||
LogILFailure("Ldloca::rect was not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cursor.TryGotoNext(x => x.MatchStfld<Rectangle>(nameof(Rectangle.Y))))
|
||||
{
|
||||
LogILFailure("Stfld::Rectangle.Y was not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
cursor.EmitLdloc(tileLocalIdx);
|
||||
cursor.EmitLdloca(rectLocalIdx);
|
||||
cursor.EmitDelegate((Tile tile, ref Rectangle drawRect) =>
|
||||
{
|
||||
if (ModContent.GetModWall(tile.WallType) is MultiVariantModWall mvWall)
|
||||
{
|
||||
tile.TilePos(out var i, out var j);
|
||||
|
||||
int offsetX = 0;
|
||||
int offsetY = 0;
|
||||
|
||||
mvWall.PopulateWallVariant(i, j, ref offsetX, ref offsetY);
|
||||
|
||||
drawRect.X += offsetX;
|
||||
drawRect.Y += offsetY;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void LogILFailure(string reason)
|
||||
{
|
||||
ILChanges.LogFailure("Support for Wall FrameOffset", reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Walls
|
||||
{
|
||||
public abstract class MultiVariantModWall : ModWall
|
||||
{
|
||||
public virtual void PopulateWallVariant(int i, int j, ref int frameXOffset, ref int frameYOffset) { }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user