diff --git a/Docs/createmods.md b/Docs/createmods.md index 5f2cc97..19e5946 100644 --- a/Docs/createmods.md +++ b/Docs/createmods.md @@ -44,6 +44,8 @@ As an example, here's an instruction on how to change Gomez's house background p 7. In your mod's `Assets` directory, create `background planes` directory and put your XNB file there. 8. From now on Gomez's house should have your modified texture. +A small note regarding music files: since they're normally stored in a separate `.pak` archive (`Music.pak`) and handled by a separate subsystem, music files are organized in a root directory. It is **not** the case for HAT mods, and instead it looks for OGG files (audio format used by music in this game) in `[Your mod]/Assets/Music` directory, then uses a path relative to this directory to identify the music file. For example, in order to replace `villageville\bed` music file, your new music file needs to be located at `[Your mod]/Assets/Music/villageville/bed.ogg`. + ## Creating custom logic mod Mod loader loads library file given in metadata as an assembly, then attempts to create instances of every public class inheriting from game's `IGameComponent` interface before initialization (before any services are created). After the game has been initialized (that is, as soon as all necessary services are initiated), it adds created instances into the list of game's components and initializes them, allowing their `Update` and `Draw` (use `DrawableGameComponent`) to be properly executed within the game's loop. diff --git a/Source/Asset.cs b/Source/Asset.cs index d84734d..631f5a6 100644 --- a/Source/Asset.cs +++ b/Source/Asset.cs @@ -31,14 +31,37 @@ private void TryConvertAsset() { // TODO: special conversion handling for different types, like images or animation + if(Extension == ".ogg" && AssetPath.StartsWith("music\\")) + { + IsMusicFile = true; + AssetPath = AssetPath.Substring("music\\".Length); + } + Converted = false; } public void Inject() { - var cachedAssetsField = typeof(MemoryContentManager).GetField("cachedAssets", BindingFlags.NonPublic | BindingFlags.Static); - var cachedAssets = cachedAssetsField.GetValue(null) as Dictionary; - cachedAssets[AssetPath] = Data; + if (IsMusicFile) + { + // music files are loaded and stored separately in SoundManager service + var soundManager = ServiceHelper.Get(); + + // make sure music assets are already initialized. it can initialize only once so we don't have to worry + soundManager.InitializeLibrary(); + + var musicCacheField = typeof(SoundManager).GetField("MusicCache", BindingFlags.NonPublic | BindingFlags.Instance); + var musicCache = musicCacheField.GetValue(soundManager) as Dictionary; + + musicCache[AssetPath] = Data; + } + else + { + // everything else uses static MemoryContentManager cache array + var cachedAssetsField = typeof(MemoryContentManager).GetField("cachedAssets", BindingFlags.NonPublic | BindingFlags.Static); + var cachedAssets = cachedAssetsField.GetValue(null) as Dictionary; + cachedAssets[AssetPath] = Data; + } } public static List LoadDirectory(string directoryPath)