pixeltris / YgoMaster

Offline Yu-Gi-Oh! Master Duel
MIT License
886 stars 127 forks source link

[Feature Request] Custom audio files #311

Closed pixeltris closed 10 months ago

pixeltris commented 10 months ago

Requested by @Merik2013

YgoMaster supports user made content without having to create Unity asset bundles. Audio currently isn't supported.

There are two ways of loading custom audio files from disk using Unity:

There is a project which does what we want using AudioClip.Create / AudioClip.SetData https://github.com/Hello-Meow/AudioImporter

The necessary functions are missing from il2cpp code. This means it isn't possible to use the il2cpp API to create audio clips. The functions still exist in UnityPlayer.dll and Unity provides symbols (the current PDB for Master Duel 1.8.0 can be found here http://symbolserver.unity3d.com/UnityPlayer_Win64_il2cpp_x64.pdb/C65FD8ED2D17402EB0FE3F3231AD253E1/).

The relevant reference source for the C# side:

https://github.com/Unity-Technologies/UnityCsReference/blob/7c95a72366b5ed9b6d9e804de8b5e869c962f5a9/Modules/Audio/Public/ScriptBindings/Audio.bindings.cs#L513-L598

This shows the following C++ functions need to be called:

The relationship is between the underlying C++ classes and the il2cpp/C# classes isn't immediately clear. Some more investigation would be needed to call the C++ functions and get back an il2cpp/C# AudioClip object. The noted functions would need to be obtained every time Unity makes an engine update using something like the DIA SDK PDB symbol reader and these function addresses would need to be saved into ClientSettings.json.

This might not be very performant compared to creating Unity asset bundles as audio conversion would need to take place before SetData could be called. This could result in a noticeable delay when BGMs / sounds are played. A more performant solution (at the cost of disk space) might be to store the converted samples alongside the original audio file.