Skip to content

Commit 2ae1df7

Browse files
authored
Merge pull request #886 from SilverDorian46/tileset-stuff
Add soundParam attribute for the Tileset XMLs + force a NoInlining on Player.DustParticleFromSurfaceIndex
2 parents 2edd40b + 81ebf4d commit 2ae1df7

File tree

5 files changed

+43
-10
lines changed

5 files changed

+43
-10
lines changed

Celeste.Mod.mm/MonoModRules.Game.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ public static void PatchConfigUIUpdate(ILContext il, CustomAttribute attrib) {
308308

309309
private static void PatchPlaySurfaceIndex(ILCursor cursor, string name) {
310310
MethodDefinition m_SurfaceIndex_GetPathFromIndex = cursor.Module.GetType("Celeste.SurfaceIndex").FindMethod("System.String GetPathFromIndex(System.Int32)");
311+
MethodDefinition m_SurfaceIndex_GetSoundParamFromIndex = cursor.Module.GetType("Celeste.SurfaceIndex").FindMethod("System.Int32 GetSoundParamFromIndex(System.Int32)");
311312
MethodReference m_String_Concat = MonoModRule.Modder.Module.ImportReference(
312313
MonoModRule.Modder.FindType("System.String").Resolve()
313314
.FindMethod("System.String Concat(System.String,System.String)")
@@ -326,12 +327,13 @@ private static void PatchPlaySurfaceIndex(ILCursor cursor, string name) {
326327
/* Change:
327328
Play("event:/char/madeline{$name}", "surface_index", platformByPriority.GetStepSoundIndex(this));
328329
to:
329-
Play(SurfaceIndex.GetPathFromIndex(platformByPriority.GetStepSoundIndex(this)) + $name, "surface_index", platformByPriority.GetStepSoundIndex(this));
330+
Play(SurfaceIndex.GetPathFromIndex(platformByPriority.GetStepSoundIndex(this)) + $name, "surface_index",
331+
SurfaceIndex.GetSoundParamFromIndex(platformByPriority.GetStepSoundIndex(this)));
330332
OR Change (for walls):
331333
Play("event:/char/madeline/{$name}", "surface_index", platformByPriority.GetWallSoundIndex(this, (int)Facing));
332334
to:
333335
Play(SurfaceIndex.GetPathFromIndex(platformByPriority.GetWallSoundIndex(this, (int)Facing)) + $name, "surface_index",
334-
platformByPriority.GetWallSoundIndex(this, (int)Facing));
336+
SurfaceIndex.GetSoundParamFromIndex(platformByPriority.GetWallSoundIndex(this, (int)Facing)));
335337
*/
336338

337339
cursor.Emit(OpCodes.Ldloc, loc_Platform);
@@ -350,6 +352,10 @@ OR Change (for walls):
350352
cursor.Emit(OpCodes.Call, m_String_Concat);
351353
// Remove hardcoded event string
352354
cursor.Remove();
355+
356+
// Then jump to after the referenced GetSoundIndex callvirt.
357+
cursor.GotoNext(MoveType.After, instr => instr.MatchCallvirt(m_Platform_GetSoundIndex));
358+
cursor.Emit(OpCodes.Call, m_SurfaceIndex_GetSoundParamFromIndex);
353359
}
354360

355361
public static void PatchMinMaxBlendFunction(ILContext il, CustomAttribute attrib) {

Celeste.Mod.mm/Patches/Autotiler.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ private void ReadInto(patch_TerrainType data, Tileset tileset, XmlElement xml) {
6969
Logger.Debug("Autotiler", $"Reading template for tileset with id '{data.ID}', scan height {data.ScanHeight}, and scan width {data.ScanWidth}.");
7070
ReadIntoCustomTemplate(data, tileset, xml);
7171
}
72-
73-
if (xml.HasAttr("soundPath") && xml.HasAttr("sound")) { // Could accommodate for no sound attr, but requiring it should improve clarity on user's end
74-
SurfaceIndex.TileToIndex[xml.AttrChar("id")] = xml.AttrInt("sound");
75-
patch_SurfaceIndex.IndexToCustomPath[xml.AttrInt("sound")] = (xml.Attr("soundPath").StartsWith("event:/") ? "" : "event:/") + xml.Attr("soundPath");
76-
} else if (xml.HasAttr("sound")) {
72+
73+
if (xml.HasAttr("sound")) {
7774
SurfaceIndex.TileToIndex[xml.AttrChar("id")] = xml.AttrInt("sound");
75+
if (xml.HasAttr("soundPath")) {
76+
patch_SurfaceIndex.IndexToCustomPath[xml.AttrInt("sound")] = (xml.Attr("soundPath").StartsWith("event:/") ? "" : "event:/") + xml.Attr("soundPath");
77+
}
78+
if (xml.HasAttr("soundParam")) {
79+
patch_SurfaceIndex.IndexToSoundParam[xml.AttrInt("sound")] = xml.AttrInt("soundParam");
80+
}
7881
} else if (!SurfaceIndex.TileToIndex.ContainsKey(xml.AttrChar("id"))) {
7982
SurfaceIndex.TileToIndex[xml.AttrChar("id")] = 0; // fall back to no sound
8083
}

Celeste.Mod.mm/Patches/LevelLoader.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public void ctor(Session session, Vector2? startPosition = default) {
8686
// Clear any custom tileset sound paths
8787
patch_SurfaceIndex.IndexToCustomPath.Clear();
8888

89+
// Clear any sound parameter overrides
90+
patch_SurfaceIndex.IndexToSoundParam.Clear();
91+
8992
string path = "";
9093

9194
try {

Celeste.Mod.mm/Patches/Player.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ public override void SceneEnd(Scene scene) {
329329
[MonoModIgnore]
330330
[PatchPlayerApproachMaxMove]
331331
private extern int NormalUpdate();
332+
333+
[MonoModIgnore]
334+
[ForceNoInlining]
335+
private extern ParticleType DustParticleFromSurfaceIndex(int index);
332336
}
333337

334338
public static class PlayerExt {
@@ -475,6 +479,7 @@ public static void PatchPlayerStarFlyReturnToNormalHitbox(ILContext context, Cus
475479

476480
public static void PatchPlayerOnCollideV(ILContext context, CustomAttribute attrib) {
477481
MethodDefinition m_SurfaceIndex_GetPathFromIndex = context.Module.GetType("Celeste.SurfaceIndex").FindMethod("System.String GetPathFromIndex(System.Int32)");
482+
MethodDefinition m_SurfaceIndex_GetSoundParamFromIndex = context.Module.GetType("Celeste.SurfaceIndex").FindMethod("System.Int32 GetSoundParamFromIndex(System.Int32)");
478483
MethodReference m_String_Concat = MonoModRule.Modder.Module.ImportReference(
479484
MonoModRule.Modder.FindType("System.String").Resolve()
480485
.FindMethod("System.String Concat(System.String,System.String)")
@@ -498,7 +503,7 @@ and get the variable index of num2
498503
/* Change
499504
Play((playFootstepOnLand > 0f) ? "event:/char/madeline/footstep" : "event:/char/madeline/landing", "surface_index", num2);
500505
to
501-
Play(SurfaceIndex.GetPathFromIndex(num2) + ((playFootstepOnLand > 0f) ? "/footstep" : "/landing"), "surface_index", num2);
506+
Play(SurfaceIndex.GetPathFromIndex(num2) + ((playFootstepOnLand > 0f) ? "/footstep" : "/landing"), "surface_index", SurfaceIndex.GetSoundParamFromIndex(num2));
502507
*/
503508
cursor.GotoNext(MoveType.AfterLabel, instr => instr.MatchLdarg(0), instr => instr.MatchLdfld("Celeste.Player", "playFootstepOnLand"));
504509
cursor.Emit(OpCodes.Ldloc, loc_landSoundIdx);
@@ -509,6 +514,9 @@ and get the variable index of num2
509514
.Next.Operand = "/footstep";
510515
cursor.GotoNext(MoveType.AfterLabel, instr => instr.MatchLdstr("surface_index"));
511516
cursor.Emit(OpCodes.Call, m_String_Concat);
517+
518+
cursor.GotoNext(MoveType.After, instr => instr.MatchLdloc(loc_landSoundIdx));
519+
cursor.Emit(OpCodes.Call, m_SurfaceIndex_GetSoundParamFromIndex);
512520
}
513521

514522
public static void PatchPlayerClimbBegin(ILContext context, CustomAttribute attrib) {
@@ -519,6 +527,7 @@ public static void PatchPlayerOrigWallJump(ILContext context, CustomAttribute at
519527
// Doesn't use PatchPlaySurfaceIndex because index, not platform, is stored in the local variable
520528

521529
MethodDefinition m_SurfaceIndex_GetPathFromIndex = context.Module.GetType("Celeste.SurfaceIndex").FindMethod("System.String GetPathFromIndex(System.Int32)");
530+
MethodDefinition m_SurfaceIndex_GetSoundParamFromIndex = context.Module.GetType("Celeste.SurfaceIndex").FindMethod("System.Int32 GetSoundParamFromIndex(System.Int32)");
522531
MethodReference m_String_Concat = MonoModRule.Modder.Module.ImportReference(
523532
MonoModRule.Modder.FindType("System.String").Resolve()
524533
.FindMethod("System.String Concat(System.String,System.String)")
@@ -529,14 +538,17 @@ public static void PatchPlayerOrigWallJump(ILContext context, CustomAttribute at
529538
/* Change:
530539
Play("event:/char/madeline/landing", "surface_index", num);
531540
to:
532-
Play(SurfaceIndex.GetPathFromIndex(num) + "/landing", "surface_index", num);
541+
Play(SurfaceIndex.GetPathFromIndex(num) + "/landing", "surface_index", SurfaceIndex.GetSoundParamFromIndex(num));
533542
*/
534543
cursor.GotoNext(MoveType.AfterLabel, instr => instr.MatchLdstr("event:/char/madeline/landing"));
535544
cursor.Emit(OpCodes.Ldloc_0);
536545
cursor.Emit(OpCodes.Call, m_SurfaceIndex_GetPathFromIndex);
537546
cursor.Emit(OpCodes.Ldstr, "/landing");
538547
cursor.Emit(OpCodes.Call, m_String_Concat);
539548
cursor.Remove();
549+
550+
cursor.GotoNext(MoveType.After, instr => instr.MatchLdloc0());
551+
cursor.Emit(OpCodes.Call, m_SurfaceIndex_GetSoundParamFromIndex);
540552
}
541553

542554
public static void PatchPlayerCtor(MethodDefinition method, CustomAttribute attrib) {

Celeste.Mod.mm/Patches/SurfaceIndex.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Celeste {
44
class patch_SurfaceIndex: SurfaceIndex {
55

6-
public static Dictionary<int, string> IndexToCustomPath = new Dictionary<int, string>();
6+
public static Dictionary<int, string> IndexToCustomPath = new Dictionary<int, string>();
7+
8+
public static Dictionary<int, int> IndexToSoundParam = new Dictionary<int, int>();
79

810
public static string GetPathFromIndex(int key) {
911
if (IndexToCustomPath.TryGetValue(key, out string path)) {
@@ -12,5 +14,12 @@ public static string GetPathFromIndex(int key) {
1214
return "event:/char/madeline";
1315
}
1416

17+
public static int GetSoundParamFromIndex(int key) {
18+
if (IndexToSoundParam.TryGetValue(key, out int value)) {
19+
return value;
20+
}
21+
return key;
22+
}
23+
1524
}
1625
}

0 commit comments

Comments
 (0)