Brimstone works again (kinda)
This commit is contained in:
1 parent
761301317b
commit
079c829e4f
8 files changed
+93
-25
No files matched your search
@@ -51,7 +51,7 @@ namespace CalamityMod.ILEditing
|
||||
On.Terraria.Main.DrawInterface += DrawGeneralParticles;
|
||||
On.Terraria.Main.SortDrawCacheWorms += DrawFusableParticles;
|
||||
On.Terraria.Main.SetDisplayMode += ResetRenderTargetSizes;
|
||||
IL.Terraria.Main.DrawTiles += DrawCustomLava;
|
||||
IL.Terraria.GameContent.Drawing.TileDrawing.DrawPartialLiquid += DrawCustomLava;
|
||||
IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw += DrawCustomLava2;
|
||||
IL.Terraria.Main.oldDrawWater += DrawCustomLava3;
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace CalamityMod.ILEditing
|
||||
On.Terraria.Main.DrawInterface -= DrawGeneralParticles;
|
||||
On.Terraria.Main.SortDrawCacheWorms -= DrawFusableParticles;
|
||||
On.Terraria.Main.SetDisplayMode -= ResetRenderTargetSizes;
|
||||
IL.Terraria.Main.DrawTiles -= DrawCustomLava;
|
||||
IL.Terraria.GameContent.Drawing.TileDrawing.DrawPartialLiquid -= DrawCustomLava;
|
||||
IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw -= DrawCustomLava2;
|
||||
IL.Terraria.Main.oldDrawWater -= DrawCustomLava3;
|
||||
IL.Terraria.WaterfallManager.DrawWaterfall -= DrawCustomLavafalls;
|
||||
|
||||
@@ -60,16 +60,28 @@ namespace CalamityMod.ILEditing
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Texture2D SelectLavaTexture(Texture2D initialTexture, bool blockTexture)
|
||||
private static Texture2D SelectLavaTexture(Texture2D initialTexture, LiquidTileType type)
|
||||
{
|
||||
// Use the initial texture if it isn't lava.
|
||||
if (initialTexture != CustomLavaManagement.LavaTexture && initialTexture != CustomLavaManagement.LavaBlockTexture)
|
||||
if (initialTexture != CustomLavaManagement.LavaTexture &&
|
||||
initialTexture != CustomLavaManagement.LavaBlockTexture &&
|
||||
initialTexture != CustomLavaManagement.LavaSlopeTexture)
|
||||
return initialTexture;
|
||||
|
||||
foreach (CustomLavaStyle lavaStyle in CustomLavaManagement.CustomLavaStyles)
|
||||
{
|
||||
if (lavaStyle.ChooseLavaStyle())
|
||||
return blockTexture ? lavaStyle.BlockTexture : lavaStyle.LavaTexture;
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case LiquidTileType.Block:
|
||||
return lavaStyle.BlockTexture;
|
||||
case LiquidTileType.Waterflow:
|
||||
return lavaStyle.LavaTexture;
|
||||
case LiquidTileType.Slope:
|
||||
return lavaStyle.SlopeTexture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return initialTexture;
|
||||
@@ -78,7 +90,9 @@ namespace CalamityMod.ILEditing
|
||||
private static Color SelectLavaColor(Texture2D initialTexture, Color initialLightColor)
|
||||
{
|
||||
// Use the initial color if it isn't lava.
|
||||
if (initialTexture != CustomLavaManagement.LavaTexture && initialTexture != CustomLavaManagement.LavaBlockTexture)
|
||||
if (initialTexture != CustomLavaManagement.LavaTexture &&
|
||||
initialTexture != CustomLavaManagement.LavaBlockTexture &&
|
||||
initialTexture != CustomLavaManagement.LavaSlopeTexture)
|
||||
return initialLightColor;
|
||||
|
||||
foreach (CustomLavaStyle lavaStyle in CustomLavaManagement.CustomLavaStyles)
|
||||
|
||||
@@ -514,28 +514,60 @@ namespace CalamityMod.ILEditing
|
||||
{
|
||||
ILCursor cursor = new ILCursor(il);
|
||||
|
||||
if (!cursor.TryGotoNext(c => c.MatchLdsfld<Main>("liquidTexture")))
|
||||
FieldInfo liquidTexturesField = typeof(TextureAssets).GetField("Liquid");
|
||||
FieldInfo liquidSlopeTexturesField = typeof(TextureAssets).GetField("LiquidSlope");
|
||||
MethodInfo textureGetValueMethod = typeof(Asset<Texture2D>).GetMethod("get_Value");
|
||||
|
||||
void replaceLiquidTexture(LiquidTileType type)
|
||||
{
|
||||
// While this may seem crazy, under no circumstances should there not be a load after exactly 3 instructions.
|
||||
// The order is load is texture array field -> load index -> load the reference to the texture at that index -> call get_Value().
|
||||
cursor.Index += 4;
|
||||
cursor.EmitDelegate<Func<Texture2D, Texture2D>>(initialTexture => SelectLavaTexture(initialTexture, type));
|
||||
}
|
||||
|
||||
void replaceLiquidColor(bool sloped)
|
||||
{
|
||||
// Pass the texture in so that the method can ensure it is not messing around with non-lava textures.
|
||||
cursor.Emit(OpCodes.Ldsfld, sloped ? liquidSlopeTexturesField : liquidTexturesField);
|
||||
cursor.Emit(OpCodes.Ldarg, 4);
|
||||
cursor.Emit(OpCodes.Ldelem_Ref);
|
||||
cursor.Emit(OpCodes.Callvirt, textureGetValueMethod);
|
||||
cursor.EmitDelegate<Func<Color, Texture2D, Color>>((initialColor, initialTexture) => SelectLavaColor(initialTexture, initialColor));
|
||||
}
|
||||
|
||||
// Replace initial textures and colors.
|
||||
if (!cursor.TryGotoNext(c => c.MatchLdsfld(liquidTexturesField)))
|
||||
{
|
||||
LogFailure("Custom Lava Drawing", "Could not locate the liquid texture array load.");
|
||||
return;
|
||||
}
|
||||
replaceLiquidTexture(LiquidTileType.Waterflow);
|
||||
|
||||
// While this may seem crazy, under no circumstances should there not be a load after exactly 3 instructions.
|
||||
// The order is load is texture array field -> load index -> load the reference to the texture at that index.
|
||||
cursor.Index += 3;
|
||||
cursor.EmitDelegate<Func<Texture2D, Texture2D>>(initialTexture => SelectLavaTexture(initialTexture, true));
|
||||
|
||||
if (!cursor.TryGotoNext(MoveType.After, c => c.MatchLdloc(155)))
|
||||
if (!cursor.TryGotoNext(MoveType.After, c => c.MatchLdarg(5)))
|
||||
{
|
||||
LogFailure("Custom Lava Drawing", "Could not locate the liquid light color.");
|
||||
return;
|
||||
}
|
||||
replaceLiquidColor(false);
|
||||
|
||||
// Pass the texture in so that the method can ensure it is not messing around with non-lava textures.
|
||||
cursor.Emit(OpCodes.Ldsfld, typeof(Main).GetField("liquidTexture"));
|
||||
cursor.Emit(OpCodes.Ldloc, 151);
|
||||
cursor.Emit(OpCodes.Ldelem_Ref);
|
||||
cursor.EmitDelegate<Func<Color, Texture2D, Color>>((initialColor, initialTexture) => SelectLavaColor(initialTexture, initialColor));
|
||||
// Replace sloped textures and colors.
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (!cursor.TryGotoNext(c => c.MatchLdsfld(liquidSlopeTexturesField)))
|
||||
{
|
||||
LogFailure("Custom Lava Drawing", "Could not locate the sloped liquid texture array load.");
|
||||
return;
|
||||
}
|
||||
replaceLiquidTexture(LiquidTileType.Slope);
|
||||
|
||||
if (!cursor.TryGotoNext(MoveType.After, c => c.MatchLdarg(5)))
|
||||
{
|
||||
LogFailure("Custom Lava Drawing", "Could not locate the liquid light color.");
|
||||
return;
|
||||
}
|
||||
replaceLiquidColor(true);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawCustomLava2(ILContext il)
|
||||
@@ -549,9 +581,9 @@ namespace CalamityMod.ILEditing
|
||||
}
|
||||
|
||||
// While this may seem crazy, under no circumstances should there not be a load after exactly 3 instructions.
|
||||
// The order is load is texture array field -> load index -> load the reference to the texture at that index.
|
||||
cursor.Index += 3;
|
||||
cursor.EmitDelegate<Func<Texture2D, Texture2D>>(initialTexture => SelectLavaTexture(initialTexture, false));
|
||||
// The order is load is texture array field -> load index -> load the reference to the texture at that index -> call get_Value().
|
||||
cursor.Index += 4;
|
||||
cursor.EmitDelegate<Func<Texture2D, Texture2D>>(initialTexture => SelectLavaTexture(initialTexture, LiquidTileType.Waterflow));
|
||||
|
||||
if (!cursor.TryGotoNext(MoveType.After, c => c.MatchLdloc(9)))
|
||||
{
|
||||
@@ -600,9 +632,9 @@ namespace CalamityMod.ILEditing
|
||||
while (cursor.TryGotoNext(c => c.MatchLdsfld(typeof(TextureAssets).GetField("Liquid"))))
|
||||
{
|
||||
// While this may seem crazy, under no circumstances should there not be a load after exactly 3 instructions.
|
||||
// The order is load is texture array field -> load index -> load the reference to the texture at that index -> call Value.
|
||||
// The order is load is texture array field -> load index -> load the reference to the texture at that index -> call get_Value().
|
||||
cursor.Index += 4;
|
||||
cursor.EmitDelegate<Func<Texture2D, Texture2D>>(initialTexture => SelectLavaTexture(initialTexture, true));
|
||||
cursor.EmitDelegate<Func<Texture2D, Texture2D>>(initialTexture => SelectLavaTexture(initialTexture, LiquidTileType.Block));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace CalamityMod.Waters
|
||||
|
||||
public override string BlockTexturePath => LavaTexturePath + "_Block";
|
||||
|
||||
public override string SlopeTexturePath => LavaTexturePath + "_Slope";
|
||||
|
||||
public override bool ChooseLavaStyle() => Main.LocalPlayer.Calamity().ZoneCalamity;
|
||||
|
||||
public override int ChooseWaterfallStyle() => ModContent.Find<ModWaterfallStyle>("CalamityMod/CragsLavaflow").Slot;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 252 B |
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using ReLogic.Content;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -14,6 +15,7 @@ namespace CalamityMod.Waters
|
||||
internal static List<CustomLavaStyle> CustomLavaStyles;
|
||||
internal static Texture2D LavaBlockTexture;
|
||||
internal static Texture2D LavaTexture;
|
||||
internal static Texture2D LavaSlopeTexture;
|
||||
|
||||
// The IL Edits are loaded separately.
|
||||
internal static void Load()
|
||||
@@ -33,8 +35,9 @@ namespace CalamityMod.Waters
|
||||
|
||||
if (Main.netMode != NetmodeID.Server)
|
||||
{
|
||||
LavaBlockTexture = ModContent.Request<Texture2D>("Terraria/Images/Liquid_1").Value;
|
||||
LavaTexture = ModContent.Request<Texture2D>("Terraria/Images/Misc/water_1").Value;
|
||||
LavaBlockTexture = ModContent.Request<Texture2D>("Terraria/Images/Liquid_1", AssetRequestMode.ImmediateLoad).Value;
|
||||
LavaTexture = ModContent.Request<Texture2D>("Terraria/Images/Misc/water_1", AssetRequestMode.ImmediateLoad).Value;
|
||||
LavaSlopeTexture = ModContent.Request<Texture2D>("Terraria/Images/LiquidSlope_1", AssetRequestMode.ImmediateLoad).Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace CalamityMod.Waters
|
||||
{
|
||||
internal Texture2D LavaTexture;
|
||||
internal Texture2D BlockTexture;
|
||||
internal Texture2D SlopeTexture;
|
||||
|
||||
internal void Load()
|
||||
{
|
||||
@@ -20,6 +21,7 @@ namespace CalamityMod.Waters
|
||||
|
||||
LavaTexture = ModContent.Request<Texture2D>(LavaTexturePath, AssetRequestMode.ImmediateLoad).Value;
|
||||
BlockTexture = ModContent.Request<Texture2D>(BlockTexturePath, AssetRequestMode.ImmediateLoad).Value;
|
||||
SlopeTexture = ModContent.Request<Texture2D>(SlopeTexturePath, AssetRequestMode.ImmediateLoad).Value;
|
||||
}
|
||||
|
||||
internal void Unload()
|
||||
@@ -32,6 +34,8 @@ namespace CalamityMod.Waters
|
||||
|
||||
public abstract string BlockTexturePath { get; }
|
||||
|
||||
public abstract string SlopeTexturePath { get; }
|
||||
|
||||
public virtual bool ChooseLavaStyle() => false;
|
||||
|
||||
public abstract int ChooseWaterfallStyle();
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Waters
|
||||
{
|
||||
public enum LiquidTileType
|
||||
{
|
||||
Block,
|
||||
Waterflow,
|
||||
Slope
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user