Yinigma / EnemySkinKit

Tools for creating Lethal Company Enemy skins compatible with the Enemy Skin Registry
0 stars 0 forks source link

Enemy Skin Kit

This mod provides tools for creating vanilla enemy skins for lethal company from within the unity editor. Most end users will see this as a dependency for other skin mods.

Features

Prerequisites

It's recommended that you also use Evaisa's starter project which can be found here: https://github.com/EvaisaDev/LethalCompanyUnityTemplate

Use of Thunderkit is also an optional recommendation: https://github.com/PassivePicasso/ThunderKit

Setup with Thunderkit

1.Create up a new 3D (HDRP) project in Unity (or get a project template like this one https://github.com/EvaisaDev/LethalCompanyUnityTemplate). If your project still has HDRP starter assets, you should delete them. This will be the the "TutorialInfo" folder, the "ReadMe" asset, and the "Outdoor Scene." The "TutorialInfo" folder is the most important, as this contains scripts that will conflict with what we're going to try and import from the game data later.

2.Now, we're going to get ThunderKit. ThunderKit is a package manager for making mods in the unity editor. Go to Window > Package Manager to open up the package manager window.

Location of the package manager in Unity's GUI

3.From the ThunderKit github page, click the "code " in the input field and click the "add" button.

The location of the ThunderKit URL on ThunderKit's github page

4.Click the plus dropdown in the upper left hand corner, and from that menu select "Add package from git url" and paste the url you copied into the input field that appears.

Unity package manager add button

Pasting the Thunderkit url into the input field

5.Unity will take a minute to download and install ThunderKit. Once the the ThunderKit package is installed, a new option will be added to the menu bar. Navigate to Tools > Thunderkit > Settings to open the Thunderkit settings menu.

Location of ThunderKit Settings Menu in Unity's GUI

6.We're going to use this menu to make a package out of Lethal Company's code. Go to "ThunderKit Settings" and in the "Locate and Load game files for project" section, click browse and navigate to your Lethal Company.exe (probably in your steamapps folder).

Inputting Lethal Company's exe in ThunderKit's settings menu

7.Click "import" and let Thunderkit do its thing. It'll ask you to restart your project a couple of times. After it's done, you'll have the necessary game code that this and other mods depend on.

ThunderKit will not import the Assembly-CSharp.dll from Lethal Company if you didn't properly dispose of the unneeded HDRP starter files. If this is the case, navigate to the same folder you found your Lethal Company.exe in, go to "Lethal Company_Data"/Managed and copy (DO NOT MOVE) Assembly-CSharp.dll to /Packages/LethalCompany.

8.At this point we're nearly done with the setup. Now we're gonna get this mod's code, along with its dependencies. Go back to the Thunderstore Settings menu and navigate to "Package Source Settings." Click "Add" and from the dropdown select "Thunderstore Source." This will add a new entry to the package source list called "ThunderStoreSource."

9.Select the new entry and name it to whatever pleases you in the "Package Source" field. I just call it "Lethal Company Mods." In the url field, paste this url:

https://thunderstore.io/c/lethal-company

ThunderKit's GUI for adding Community-specific package sources, configured to get mods from the Lethal Company page

10.Give unity a minute to connect to ThunderStore. Once it's done, navigate to Tools > ThunderKit > Packages. If the package source you named has a silly number next to it**, you've successfully connected to Thunderstore and can now download mods.

Location of ThunderKit's package manager in Unity's GUI

The ThunderKit package manager populated with mods from ThunderStore

** If you make modpacks and post them to ThunderStore when you could've just shared a ThunderStore profile code, I really don't care for you.

11.In the search bar in the top right, type in "EnemySkinKit" and look for this mod. Once you've found it, click "install" in the top right.

EnemySkinKit in the ThunderKit package manager

12.An annoying extra step we need to take is getting rid of some BepInEx libraries that I guess Unity doesn't agree with. Navigate to /Packages/BepInExPack/BepInExPack/BepInEx/core and delete 0Harmony20.dll and BepInEx.Harmony.dll

The files that must be deleted

13.Verify that the mod has been installed by right clicking anywhere in the project window (the little file explorer at the bottom of unity's default layout) and go to Create. If you find options for "EnemySkinKit" it's installed and you should be good to go.

Code-Free Method

Now you should have all the stuff you need to start making skins.

1.Right click anywhere in the assets window and select Create > Enemy Skin Kit > Skins > Enemy-You-Want-To-Skin

Location of the Skin Creation option in the Project Window's context menu

2.Name your skin file, then set the label, guid, and icon fields in the inspector. This is what a completed skin object might look like

Inspector view of the Skin

3.In the inspector, fill out the remaining fields for your skin. These fields come in the form of several "Action" types that will let you replace, hide, or keep sound effects, materials, and meshes.

Material Action - Operates on a material

Static Mesh Action - Operates on one of the enemy's static meshes (like the spider's fangs or the jester's skull)

Skinned Mesh Action - Operates on one of the enemy's skinned meshes (normally the one "body" mesh)

Visual example of setting the skinned mesh action fields, since this one is a little more complicated

Audio Action - Operates on one of the enemy's sounds

Audio List Action - Operates on a set of sounds the enemy picks from

Attachments

You can also specify "Attachments" that will let you attach a prefab as a child of a bone in the vanilla enemy's armature. So you could attach a watch to a wrist or a mask to a face without having to replace anything. You have to match the name of the bone exactly for it to attach.

The mod in the inspector with the attachment field highlighted

The location, rotation, and scale describe the transform of your prefab relative to the bone you're attaching it to. You can figure out what you want the values to be by attaching your prefab in the scene to the same desired bone on one of the example FBX files provided. Get it positioned correctly, then copy the values of your prefab's transform in the inspector. You could also use the Unity Explorer mod to do something similar in the game's runtime.

Just don't be a dope like me and leave the scale at zero in your example image.

4.Right click anywhere in the assets window and select Create > Enemy Skin Kit > Mod

Location of the create mod option in the project window's context menu

5.Fill out the different fields of your mod. The only optional one is the mod GUID. The others are required.

Adding a skin to a mod in the inspector

5.Click the "Create Mod" button.

6.If successful, your mod files and the generated code will be saved to a zip file located in a folder called "EnemySkinKit" in the unity project folder (the same level as the assets folder).

The location of the exports folder in the

The exported mod in the file explorer

7.Install your mod in whatever way that pleases you and verify that it works as intended. You can pretty easily test your mod with the ThunderStore mod manager by using its "Import Local Mod" feature. Just search for it in the settings menu.

The mod in the EnemySkinRegistry's config menu

The mod as it appears in game

8.Once you've verified and tested your mod, you can go to Thunderstore and upload your zip file.

Additional Logic Method

If you want to take advantage of the ease of using the scriptable objects, but want to use them in a larger mod, then all you have to do is load your skin scriptable object from an asset bundle and register it with the EnemySkinRegistry.

//whatever you're doing to retrieve your skin scriptable object from your asset bundle
EnemySkinRegistry.RegisterSkin(mySkin);

The BaseSkin and BaseSkinner classes implement the necessary interfaces to register with the EnemySkinRegistry.

You're also free to add child classes to the existing Skin and Skinner types to extend them with whatever is to your liking. Permissions for these classes are pretty lax. If a member isn't public in one of these classes, it's protected. Don't you do nothing crazy though.

If you'd prefer something leaner or want something more custom, consider looking at the developer section of the EnemySkinRegistry mod page.

*So About Those Armature Maps...

Lethal Company skinned meshes have proven difficult to work with, at least for me. Reskinning a mesh in the usual way is probably possible, but it seems no matter what I try, when I go to replace a skinned mesh in a skinned mesh component, it ends up a scrambled mess. Get in touch with me if you've got this figured out. Until then, my solution is "Armature Maps," which copy the animation from the vanilla mesh over to your modded mesh at runtime. These were a planned feature anyway, because they have the benefit of allowing you to adjust the proportions of your model. They're just more expensive computationally. To get an armature map set up, right click in the Project Window, and select Create > EnemySkinKit > Animation > Armature Mapping.

Location of the Armature Map creation option in the context menu

This Scriptable Object will first display two fields: a "source" hierarchy and a "destination" hierarchy. "Source" is the hierarchy of the vanilla enemy armature. I've included a prefab for each one of these in the mods package. You should be able to find the prefab you need in /Packages/EnemySkinKit/EnemyRigs/.

You'll probably want to lock the inspector so you don't accitdentally take focus off of it while browsing to enemy armature prefab. Just click the little lock at the top.

Armature map locked in the inspector

Location of the included enemy armature hierarchies in the project explorer

For destination, drag in the part of your prefab object that has the skinned mesh component.

Dragging the Skinned Mesh to the Armature Map's destination field

Once both of those fields have been added, the ArmatureMap in the inspector should expand and show the mapping of source bones to destination bones. If a source bone name matches a destination bone name, the ArmatureMap will automatically map them. At runtime, a source bone will have its animation copied by whatever destination bone has been mapped to it. Once your ArmatureMap is set up in this way, you can add it to the SkinnedMeshAction.

Expanded Armature Map in the inspector

Don't forget to unlock the inspector if you locked it.

That's about as hairy as it gets. For actually creating the Skinned Meshes, I'd recommend getting one of the FBX files that come packaged with this mod. The folder for that is in the same folder as the EnemyRigs folder. You can get a rigged model in the correct position and import it to blender or your poison of choice and work from there. Teaching how to create and rig a skeletal mesh is a little beyond the scope of this little ReadMe. But there are plenty of resources out there for you to get started if you're new. Good luck!

Tips

"To Do"s