# Mark's Custom Menu Music

A client-only SPT/Fika plugin that replaces Tarkov's main-menu music with MP3
files from a watched folder. If no usable MP3 files are present, Tarkov's
normal menu music plays.

## Target

- SPT 4.0.13
- The BepInEx runtime included with SPT 4.0.13
- Fika 2.3.9 clients; no server component or synchronization is required

## Features in v0.1.19 test 19

- MP3-only custom main-menu playlist
- Sequential filename order
- Shuffle-bag playback with no repeats until every track has played
- Changing Sequential/Shuffle mode preserves the current song and playback
  position; the new mode begins with the following track
- Previous Track and Next Track buttons in the F12 settings
- No custom playback hotkeys
- Automatic folder watching and hot reload
- Post-raid Music-folder rescan and complete MP3 re-decode only after EFT confirms the real main menu has returned
- Live rescans preserve the currently playing track and its playback position
- Automatic fallback to Tarkov's default menu music
- Uses Tarkov's own menu AudioSource, preserving the game's music mixer and
  Music Volume setting
- SoulPlayer-style end-of-track observation: no per-song duration timer
- Sequential and Shuffle playback repeat indefinitely across complete playlist cycles
- Fika lifecycle integration: raid end only arms restoration; `MenuScreen.method_9(false)` performs the actual post-raid reload/start
- Tarkov/Fika raid-entry delayed fade remains in control and is not replaced
- F12/BepInEx configuration

## Install after building

Extract the generated ZIP into the SPT root. The installed paths are:

```text
BepInEx\plugins\MarksCustomMenuMusic\MarksCustomMenuMusic.dll
BepInEx\plugins\MarksCustomMenuMusic\Music\
```

Put MP3 files directly in the `Music` folder. Subfolders are not scanned.

Each Fika player can use a different playlist. The mod does not need to be
installed on the SPT server or headless client unless that installation also
launches a graphical game client whose menu music should be replaced.

## Build

1. Install Visual Studio 2022 with the .NET desktop development workload, or
   install a current .NET SDK.
2. Run `Build Release.bat`.
3. Enter the root of the SPT installation when prompted.
4. The install ZIP is created under `build\output`.

You can also open `MarksCustomMenuMusic.sln` in Visual Studio. Supply the
`SptPath` MSBuild property or edit its fallback value in the project file.

## F12 configuration

- **Enabled**: switches between custom and default Tarkov menu music.
- **Playback Order**: `Sequential` or `Shuffle`. Changing modes does not stop,
  restart, or replace the song currently playing.
- **Previous Track**: immediately plays the previously heard custom track. In
  Sequential mode, pressing it on the first history entry wraps to the prior
  filename. In Shuffle mode with no earlier history, it restarts the current
  track.
- **Next Track**: immediately advances to the next custom track according to
  the current playback mode.
- **Watch Music Folder**: reload after files change.
- **Folder Rescan Delay**: debounce time for copied/replaced files.
- **Verbose Logging**: additional diagnostics.

The Previous and Next controls are buttons inside the existing F12 settings
window. They do not register keyboard shortcuts.

## Test checklist

1. Start with an empty `Music` folder and confirm normal Tarkov menu music.
2. Add two or three MP3 files while on the main menu.
3. Confirm custom music begins after the rescan delay.
4. Change Tarkov's Music Volume slider and confirm the custom track follows it.
5. While a custom song is playing, switch from Sequential to Shuffle. Confirm
   the current song continues from the same position and the next song is
   selected using Shuffle.
6. Switch from Shuffle to Sequential during a song. Confirm the song remains
   uninterrupted and the following filename plays next.
7. Use the F12 Previous Track and Next Track buttons several times in each mode.
8. Add, replace, rename, or remove an MP3 while a custom track is playing.
   Confirm the current track continues without restarting or being interrupted.
9. Let Sequential mode run through every song and confirm it wraps from the final filename back to the first and keeps running through additional cycles.
10. Let Shuffle mode run through a complete shuffle bag and confirm a new shuffled cycle starts automatically without repeating the just-finished track as the first track of the new cycle.
11. Enter a raid and confirm the current song continues through raid preparation/final countdown and fades only when Tarkov/Fika performs its normal delayed stop.
12. Return from the raid and confirm no custom song starts on the intermediate post-raid result screens.
13. When the real main menu appears, confirm the log reports the Music folder rescan/re-decode, EFT audio bootstrap, and one next custom track start.
14. Confirm the post-raid song is the next Sequential/Shuffle selection rather than a resumed fragment of the pre-raid song.
15. Remove all MP3 files while on the menu and confirm default music returns.

## Logs

Relevant messages use the BepInEx source name `Mark's Custom Menu Music` in:

```text
BepInEx\LogOutput.log
```

## Build compatibility notes

This project directly references the installed `Fika.Core.dll` so it can use Fika's public lifecycle event dispatcher and `FikaGlobals.IsInRaid`. It is still client-only and does not install or modify any Fika server component.

This project references both Unity's modular assemblies and the
`UnityEngine.dll` compatibility facade. The facade is required because
`BepInEx.BaseUnityPlugin` inherits from `MonoBehaviour` through that assembly on
SPT 4.0.x.

`UnityEngine.IMGUIModule.dll` is referenced only for the F12 Previous/Next
buttons.

The runtime music directory is derived from the installed DLL location instead
of `BepInEx.Paths.PluginPath`, because the BepInEx build bundled with this SPT
installation does not expose that property.
