Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Celeste.Mod.mm/Mod/Meta/MapMeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public MapMeta(BinaryPacker.Element meta) {
public string Sprites { get; set; }
public string Portraits { get; set; }

public string SceneryTiles { get; set; }

public bool? OverrideASideMeta { get; set; }

public MapMetaModeProperties[] Modes { get; set; }
Expand Down Expand Up @@ -114,6 +116,9 @@ public void Parse(BinaryPacker.Element meta) {
meta.AttrIf("AnimatedTiles", v => AnimatedTiles = v);
meta.AttrIf("Sprites", v => Sprites = v);
meta.AttrIf("Portraits", v => Portraits = v);

meta.AttrIf("SceneryTiles", v => SceneryTiles = v);

meta.AttrIfBool("OverrideASideMeta", v => OverrideASideMeta = v);

BinaryPacker.Element child;
Expand Down Expand Up @@ -224,6 +229,9 @@ public void ApplyTo(patch_AreaData area) {
if (!string.IsNullOrEmpty(Portraits))
meta.Portraits = Portraits;

if (!string.IsNullOrEmpty(SceneryTiles))
meta.SceneryTiles = SceneryTiles;

if (OverrideASideMeta != null)
meta.OverrideASideMeta = OverrideASideMeta;

Expand Down
23 changes: 23 additions & 0 deletions Celeste.Mod.mm/Patches/Level.cs
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ public static void PatchLevelLoader(ILContext context, CustomAttribute attrib) {
FieldReference f_currentEntityId = context.Method.DeclaringType.FindField("_currentEntityId")!;
MethodReference m_IsInDoNotLoadIncreased = context.Method.DeclaringType.FindMethod("_IsInDoNotLoadIncreased")!;

TypeDefinition t_GFX = MonoModRule.Modder.FindType("Celeste.GFX").Resolve();
FieldDefinition f_GFX_SceneryTiles = t_GFX.FindField("SceneryTiles");

ILCursor cursor = new ILCursor(context);

// Insert our custom entity loader and use it for levelData.Entities and levelData.Triggers
Expand Down Expand Up @@ -882,6 +885,26 @@ public static void PatchLevelLoader(ILContext context, CustomAttribute attrib) {
cursor.Next.OpCode = OpCodes.Call;
cursor.Next.Operand = m_LoadNewPlayer;

// Reset to apply patch for Scenery Tiles
cursor.Index = 0;

// Patch this bit of code to use GFX.SceneryTiles instead of creating the same tileset again
// before: Tileset tileset = new Tileset(GFX.Game["tilesets/scenery"], 8, 8);
// after: Tileset tileset = GFX.SceneryTiles;
cursor.GotoNext(MoveType.AfterLabel,
instr => instr.MatchLdsfld("Celeste.GFX", "Game"),
instr => instr.MatchLdstr("tilesets/scenery")
);
// to remove:
// - ldsfld Celeste.GFX::Game
// - ldstr "tilesets/scenery"
// - callvirt Monocle.Atlas::get_Item(string)
// - ldc.i4.8
// - ldc.i4.8
// - newobj Monocle.Tileset::.ctor(class Monocle.MTexture, int32, int32)
cursor.RemoveRange(6);
cursor.Emit(OpCodes.Ldsfld, f_GFX_SceneryTiles);

// Reset to apply static constructor patch
cursor.Index = 0;

Expand Down
6 changes: 6 additions & 0 deletions Celeste.Mod.mm/Patches/LevelLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ public void ctor(Session session, Vector2? startPosition = default) {
if (string.IsNullOrEmpty(path))
path = Path.Combine("Graphics", "Portraits.xml");
GFX.PortraitsSpriteBank = new SpriteBank(GFX.Portraits, path);

path = meta?.SceneryTiles;
if (string.IsNullOrEmpty(path))
path = "tilesets/scenery";
GFX.SceneryTiles = new Tileset(GFX.Game[path], 8, 8);

} catch (Exception e) {
if (patch_LevelEnter.ErrorMessage == null) {
if (e is XmlException) {
Expand Down
Loading