Recently I came across a game called 心流小筑 (Chill Pulse). It's essentially a game designed to help you focus, with music playback, a Pomodoro timer, and other features, but as of this writing it still doesn't let you add your own music. It can only play a few built-in tracks, which is pretty inconvenient for me, so I decided to try reverse engineering it.
Researching relevant tools
First I skimmed the game directory. Besides a bunch of music .ogg files, there was a data.win file. A quick search showed it was part of the GameMaker engine, which confirmed the game was made with GameMaker.
Then I did a rough search online for GameMaker modding projects and found these:
Looking into it further, UndertaleModTool is mainly built to support Undertale modding, but in theory it works with any GameMaker game.
GS2ML is a GameMaker Studio 2 modding framework based on UndertaleModTool. It mainly uses UndertaleModTool's decompiler and compiler.
The GML language
With UndertaleModTool's GUI, you can easily unpack data.win and extract its resources. Here I'm mainly interested in the game's GML scripts.

As you can see, the game's music is all defined in this function. album_list holds the .ogg filenames (GameMaker audio resource names), and album_name_list holds the names actually shown in-game.
Adding custom music
In theory, all we need to do is use GS2ML to load our own .ogg audio resources before the game starts, then add them to this list. Luckily, GS2ML has extensive hook support and an AddSound function, which handles exactly what we need.
Example code:
data.HookFunction("all_music", "#orig#()\narray_push(album_list[0], mymusic)\narray_push(album_name_list[0], \"My Music\")");
Adding a separate category for custom music
The code above appends the custom music to the first category (the Lofi category). Since I'm a perfectionist, I wanted to add another music category.
After more digging, I found that the music categories are defined in a _music_genre list, and it isn't in a separate function. It's inside the script for the object gml_Object_obj_controller_Draw_64. That script decompiles to 3000 lines, which makes things tricky.
I tried copying the decompiled code directly into the hook code, but maybe because UndertaleModTool's compiler and decompiler have some flaws, the game became unstable. Using certain features would crash it outright, so I had to take another route.
GML compiles to bytecode, so I thought of inserting bytecode directly into the original function to modify _music_genre.
Here's the bytecode for the original _music_genre definition:

In theory, I just needed to add a few push.v bytecode instructions and change the argc after call.i.
There was a small hiccup here: after my changes, the game would crash immediately. I later found out that some goto bytecode instructions in the function had their JumpOffset thrown off after the insertion, so they needed extra correction.
Here's part of the code that implements this:
var newGenres = new List<string>();
newGenres.Add("Example");
var draw = "gml_Object_obj_controller_Draw_64";
var code = data.Code.ByName(draw);
var codeLocals = data.CodeLocals.ByName(draw);
AsmCursor cursor = new AsmCursor(data, code, codeLocals);
cursor.GotoNext("pop.v.v local._music_genre"))
cursor.index -= 1;
cursor.Replace($"call.i @@NewGMLArray@@(argc={6+newGenres.Count})");
cursor.index -= 6;
foreach( var genre in newGenres)
{
cursor.Emit($"push.v self.{genre}");
}
var cur = cursor.GetCurrent().Address;
for ( int k = 0; k < code.Instructions.Count; k++)
{
var inst = code.Instructions.ElementAt(k);
if (UndertaleInstruction.GetInstructionType(inst.Kind) == UndertaleInstruction.InstructionType.GotoInstruction)
{
if (inst.Address < cur && inst.Address + inst.JumpOffset >= cur)
{
inst.JumpOffset += 2 * newGenres.Count();
}
if (inst.Address >= cur && inst.Address + inst.JumpOffset < cur)
{
inst.JumpOffset -= 2 * newGenres.Count();
}
}
}
The result

