Model Swap Lib is an abstraction originally based on this Asset Swap Template for the game Jump Space.
This library is intended for use by mod developers and will have no effect if installed alone.
ModelSwapLib.dll as a project reference[assembly: MelonAdditionalDependencies("ModelSwapLib")] in your core fileObjectActionManager.GetInstance().RegisterSwapper(swapper); - This will return a populated Guid if this succeeded, or a Guid.Empty if ModelSwapLib was unable to validate the Swapper structureThere are 2 ways to create a swapper:
Swapper swapper = new SwapperBuilder("Optional ModName")
.SetModName("YourModName")
.SetSwapperName("Any Name You Want")
.SetBundleName("YourBundle.bundle")
.AddObjectName("ObjectName")
.AddAssetModule(new MeshModule("Path/To/Your/Model.fbx"))
.AddAssetModule(new Texture2DModule("Path/To/Your/Texture.png"))
.AddTransformModule(new MoveMeshModule(0f, 0f, 0f))
.AddTransformModule(new RotateMeshModule(0f, 0f, 0f))
.AddTransformModule(new ScaleMeshModule(0f, 0f, 0f))
.AddDeactivation("ObjectYouWantDeactivated")
.Build();
new Swapper() - The string parameter for ModName is optional here but is required at some point
SetModName(string) - ModName is a required parameter for a Swapper
SetSwapperName(string) - SwapperName is not required and will default to "Unnamed Swapper", this is mainly for logging
SetBundleName(string) - BundleName is only required if you use an IAssetModule
AddObjectName(string) - Swapper must contain at least 1 object name, otherwise it will not apply to anything and will be rejected
AddAssetModule(IAssetModule) - List of modules that use an asset from a provided AssetBundle
AddTransformModule(ITransformModule) - List of modules that manipulate the transform of a mesh
AddDeactivation(string) - List of object names to be deactivated
Additional methods include:
Build() - Returns the swapper object, or null if the configuration is not valid
Swapper swapper = new Swapper
{
ModName = "YourModName",
SwapperName = "Any Name You Want",
ObjectNames = new List<string>([
"ObjectName1",
"ObjectName2"
]),
BundleName = "YourBundle.bundle",
AssetModules = new List<IAssetModule>
{
new MeshModule("Path/To/Your/Model.fbx"),
new Texture2DModule("Path/To/Your/Texture.png")
},
TransformModules = new List<ITransformModule>
{
new MoveMeshModule(0f, 0f, 0f),
new RotateMeshModule(0f, 0f, 0f),
new ScaleMeshModule(0f, 0f, 0f)
},
Deactivations = new List<string>
{
"ObjectYouWantDeactivated"
}
};
[assembly: MelonAdditionalDependencies("ModelSwapLib")]
namespace YourMod
{
public class Core : MelonMod
{
public override void OnInitializeMelon()
{
Swapper swapper = new SwapperBuilder()
.SetModName("YourModName")
.SetSwapperName("Any Name You Want")
.AddObjectNames(["ObjectName1", "ObjectName2"])
.SetBundleName("YourBundle.bundle")
.AddAssetModule(new MeshModule("Path/To/Your/Model.fbx"))
.AddAssetModule(new Texture2DModule("Path/To/Your/Texture.png"))
.AddTransformModule(new MoveMeshModule(0f, 0f, 0f))
.AddTransformModule(new RotateMeshModule(0f, 0f, 0f))
.AddTransformModule(new ScaleMeshModule(0f, 0f, 0f))
.AddDeactivation("ObjectYouWantDeactivated")
.Build();
if(swapper == null)
{
Melon<Core>.Logger.Warning($"Invalid swapper");
}else{
Guid guid = ObjectActionManager.GetInstance().RegisterSwapper(swapper);
if(guid == Guid.Empty) // If you receive a Guid.Empty then the Swapper.Validate() failed
{
Melon<Core>.Logger.Warning($"Failed to register swapper: {swapper.SwapperName}");
} else
{
Melon<Core>.Logger.Msg($"Successfully registered swapper: {swapper.SwapperName} with guid: {swapper.SwapperGuid}");
}
}
Melon<Core>.Logger.Msg($"YourMod Initialized");
}
}
}
ModName
At least 1 ObjectName
At least 1 IAssetModule, ITransformModule OR Deactivation
BundleName if you use an IAssetModule
Many thanks to GraciousCub5622 @graciouscub5622 on discord for his Asset Swap Template, upon which this entire project is based.
Many thanks to ScribbleTAS for MeshUtils and also for his help in debugging and brainstorming.