Skip to content

C# bindings and Veldrid implementation for FFL, the Wii U Mii renderer.

Notifications You must be signed in to change notification settings

ariankordi/FFLSharp

Repository files navigation

FFLSharp

image

C# bindings for FFL, based on my fork of Abood's decompilation. FFL is the official library for rendering Mii heads and managing Mii data on Wii U.

In this repo, you will find:

  • FFLSharp.VeldridRenderer, which includes routines and classes involved with drawing Mii heads using Veldrid which should work for all of its supported APIs except Metal.
  • FFLSharp.Interop, which are the actual bindings to FFL itself.
    • These are autogenerated by ClangSharp using the GenerateFFL.rsp recipe.
    • ... Using the version of FFL that's latest by the time I generated them.
  • FFLSharp.BasicTests - ignore this, they are so basic they shouldn't even count
  • FFLSharp.FFLManager - Static class that includes helpers for initializing FFL and creating CharModels.
  • FFLSharp.VeldridBasicShaderSample, pictured above. It renders a Mii head spinning, similar to FFL-Testing, and it blinks every few seconds.
  • FFLSharp.VeldridCreateTGASample, which creates an icon of a Mii head and exports it to a TGA image.
  • (No sample using the FFLShader currently.)

I'm hoping that the Veldrid stuff would help if anyone wanted to use Miis in other graphics APIs/game engines, including anything using OpenGL which would be really simple especially if you use my FFL raylib samples to guide you: https://github.com/ariankordi/ffl-raylib-samples

Building

Run the csproj in Visual Studio, or install the relevant .NET SDK and use dotnet run.

The challenge of building this is the native library, FFL. If you don't, you will see something like:

Unhandled exception. System.DllNotFoundException: Unable to load shared library 'ffl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libffl: cannot open shared object file: No such file or directory
   at FFLSharp.Interop.FFL.InitRes(FFLFontRegion fontRegion, FFLResourceDesc* pResDesc)
   at FFLSharp.FFLManager.InitializeFFL(...)

There should be info on how to build FFL in my fork repo but I will give a brief below as well:

Compiling FFL as a library

All you need out of this is ffl.dll/libffl.so.

  1. Pull FFL and its dependencies. For simplicity, you can actually just pull FFL-Testing which has all of them.
git clone --recursive https://github.com/ariankordi/FFL-Testing
  1. Recurse into ffl within FFL-Testing.
cd FFL-Testing/ffl
  1. Build.
cmake -S . -B build -DFFL_BUILD_STATIC=OFF -DFFL_BUILD_SHARED=ON -DCMAKE_BUILD_TYPE=Debug -DFFL_WITH_RIO=../rio/

cmake --build build

(None of the -D arguments are needed here just showing for clarity)

  1. If that worked, find and copy the library.
  • ffl.dll/libffl.so should be sitting in build. You need to build FFLSharp, and then copy it into the binary folder of your sample.
    • Note: If the build drops extra binaries alongside libffl, like for zlib, you need to include those too
  • For example, for me it had to go in: FFLSharp.VeldridBasicShaderSample/bin/Debug/net6.0/
  1. Finally, you will need to copy FFLResHigh.dat into that same folder.
  • See the ffl or FFL-Testing repo to know how to acquire this.

If you run into issues with dependencies here, see the FFL-Testing repo.

TODO!!!!!

  • Come up with an actually good naming scheme for classes, interfaces
    • In other words, rename and decide on final names for everything in FFLSharp.VeldridRenderer.
  • Actually abstract out shaders/interface to provide pipelines???????
    • so that you could legitimately use a custom shader and bind material uniforms
  • Make a sample with the FFLShader
  • Try making a sample with a Mii body..???

lower priority

  • Does not work on Metal/macOS due to some inconspicuous validation error.
    • It only pops up when running through Xcode for some reason
    • ^^^ which I did by setting a fake build command /bin/true, setting the binary path to dotnet and the arguments to run the dll
  • Why does the mask look strange with 16 bit depth? That's unusual.
  • Can there be a less psychotic way to build and distribute the ffl library?
  • Can there be a better method to search for and find FFLResHigh.dat?
  • Currently, FFLResHigh.dat can only be loaded into memory in its entirety, as "cache". It would be nice to support reading it from a file, but this is heavily dependent on RIO filesytem at the time of writing.

Questions/Answers

I don’t like C#, why should I care?

Since this has an implementation of using FFL to draw Miis in a non-C/C++ language, and using a Vulkan-like API (Veldrid), it can be a base to open possibilities for bringing FFL to all sorts of places.

Can I use this in Unity?

Not yet.

It’s totally possible to use everything in this repo to draw Miis in Unity as a managed plugin, and it should work on .NET Standard 2.0 (Unity 2020 and later). However, I haven’t made such a plugin yet. Nothing stopping you from doing it though!

Can I use on 😹 Unity Wii U? 😹

Probably not.

The lowest I could get ClangSharp to generate bindings for is C# 7 and .NET Standard 2.0, both of which are far newer than the last major release of Unity Wii U (I think.)

…However, it may be simpler to use FFL in Unity Wii U as a whole since they are both calling to the same GX2 API. Try Abood’s original version of the decomp.

On Switch?

Maybe! It’s worth a try. You’d have to get the build for libffl working on the NX target, which is cursed as all hell...

Acknowledgements

About

C# bindings and Veldrid implementation for FFL, the Wii U Mii renderer.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages