Introduction
Welcome to this modder guide of the Nuclear mod for Nebulous: Fleet Command. This guide is designed for modders with at least intermediate knowledge in coding. We'll explore how the Nuclear mod is constructed and delve into its development process. This will empower you to either create your own mods or incorporate elements of this mod into your projects.
We use Harmony for code patching, and we repurpose some assets from the base game, such as the nuclear explosion VFX and sounds.
This mod leverages custom code, and mods could be written to execute of arbitrary code. It's crucial to mod ethically; harmful mods, or mods that misrepresent what they do, can lead to a ban.
Project Setup
The Nuclear mod is built on a Unity project that involves custom coding with Harmony patching and unique assets. We will use a skeleton explosion asset, repurposed from the game, and shells/warheads using custom classes we define here.
Provided AssetsI'm providing a compressed file[drive.google.com] with essential files for this mod, which you should be able to add to an existing Unity project setup for Neb modding, as outlined in the official guide. Here's what you'll find:
Lib/0Harmony.dll: The Harmony library DLL for code injection.
Scripts: Custom scripts setting up the mod and providing new game methanics.
CustomAOEExplosionEffectModule.cs: Improves blast radius collision detection.
LightweightNuclearShell.cs: Implements a lightweight shell that delivers a nuclear blast.
LookaheadMunitionBaseExtensions.cs: Implements an extension method exposing the shell destruction method.
ModEntryPoint.cs: Mod entry point, sets up the mod upon load and offers reflection methods.
NuclearWarheadDescriptor.cs: Implements an impact nuclear warhead as a modular missile component.
NuclearWarheadProximityDescriptor.cs: Implements a proximity nuclear warhead as a modular missile component.
PatchLookaheadMunitionBase.cs: Updates the after-report damage for nuclear shells to include the blast effects.
ReactorExplosionUtility.cs: Copies art and module assets from the stock assets.
Bundle/Nuclear/ assets: New assets for nuclear shells and warheads.
Resources/warhead_nuclear.png: Icon for warhead components.
Decompiling and Code DivingWhile not mandatory, decompiling the original code can provide valuable insights. I recommend JetBrains' dotPeek[www.jetbrains.com] for this. Remember, use decompiled code ethically and within legal boundaries.
Mod code setupFor a mod with custom code, start by creating an AssemblyDefinitionAsset in the Assets/Scripts directory. Your mod also needs to implement the IModEntryPoint interface for initial setup actions. Here’s a snippet of what your ModEntryPoint class might look like, complete with comments explaining each function:
using Modding; using UnityEngine; using System; using System.Reflection; using System.Collections.Generic; public class ModEntryPoint : IModEntryPoint { public void PreLoad() { // code to execute right before the mod is loaded } public void PostLoad() { // code to execute after the mod loads } // utility methods to read or set private fields and properties... }
HarmonyHarmony[harmony.pardeike.net] is a dynamic patching library. For this mod, we use it to ensure accurate damage reporting from nuclear explosions. Here's how to set it up:
Add `0Harmony.dll` to the Unity project, ideally in the Lib/ folder.
In the mod entry point's post-load hook, create a new Harmony instance:
public void PostLoad() { Harmony harmony = new Harmony("nebulous.nuclear"); harmony.PatchAll(); ... } Update your ModInfo.xml to include Harmony and your custom DLLs.
Nuclear Explosion
In the base game, nuclear explosions are defined as a prefab that gets spawned upon a critical event from a reactor overload. That prefab contains two game objects, a parent object with most modular effects, and a child object with the chessboard effect on the tactical map. Briefly walking through each of the components:
Short Duration Modular Effect: enables this game object to be pooled, such that instances can be reused after an explosion's effect is done
Particle Effect Module: enables a visual effect to be played
Sound Effect Module: enables a sound to be played
Light Effect Module: enables a light to be placed in the scene
AOE Explosion Effect Module: enables damage to be applied to nearby damagable objects
Spawn E War Effect Module: places a temporary jamming prefab in the scene
Chessboard Distortion Effect Module: places a temporary distortion effect on tactical view
Visual Effect: VFX for the blast
Audio Source: audio source for the blast
Light: light information from the point of explosion (providing that beautiful cyan glow on the map and nearby ships)
HD Additional Light Data: Automatically added in HDRP projects due to the Light componentThe child object -- itself placed in layer 17, so it shows up on tactical view -- contains the following components:
Particle Effect Module: enables a visual effect to be played
Visual Effect: VFX to be played in tactical viewWe reproduce the structure of this object in the provided `Reactor Explosion.prefab`, with two changes:
We don't have access to the VFX provided in game, nor the EWar prefab's shader. Since we are going to copy assets anyway, we will also copy the sound, rather than rip it and repackage it.
The AOE Explosion Effect Module in game is sometimes bad at detecting collisions -- a behavior which I think is a minor bug. Since I wanted to fix that, instead I'm using a custom version of this script.The code provided in ReactorExplosionUtility.cs will fill out our skeleton prefab upon load, by identifying the reactor overload debuff, its critical event, and the reactor overload prefab, and then for each shell and warhead, filling in our skeleton prefab.
Nuclear Shells
Nebulous provides 3 basic means of dealing direct damage to your enemy: kinetic shells, missiles, and beams. This mod adds nuclear variants for kinetic shells and for missiles -- and we will first look into the shells.
As of the latest version of the game, shells are typically implemented as subclasses of LightweightMunitionBase. These are assets that work as templates for each fired munition. Some of its subclasses are:
LightweightKineticShell: Used for AP rounds, these munitions do damage via penetration.
LightweightExplosiveShell: Used for HE rounds, these munitions do some penetration damage, and then create an explosion that does further damage.
LightweightProximityShell: Used for RPF rounds, these munitions explode *before* making contact with the target.
LightweightSplashingShell: Used for plasma, these munitions do damage that splashes over the armor upon impact.Rather than using the existing explosive shell logic, we will use the destruction effect of a shell to create a nuclear explosion blast, and place our reaction explosion prefab on the Effect Groups / Surface Groups / Destruction Effects.
The provided script mostly contains code to configure the size of the explosion, based on the properties of each shell.
Nuclear Warheads
The other way this mod helps deliver nuclear explosions is through modular missile warheads. Modular missile components in the base game are split across descriptors, which roughly speaking contain code used during missile setup, and runtime, which contains the code that runs while the skirmish battle is happening. Warheads in game all share the same runtime code in RuntimeMissileWarhead, but each type of warhead has its own implementation:
BaseWarheadDescriptor: base implementation defining the methods expected in a warhead, as well as ideal target weight class and impulse effects
ImpactConeWarheadDescriptor: implementation for HE impact warheads
FragmentationWarheadDescriptor: implementation for fragmentation, anti-munition warheads
KineticPenetratorWarhead: implementation for HEKP warheadsWe provide two of our own implementations:
NuclearWarheadDescriptor: impact nuclear warhead, extending ImpactConeWarheadDescriptor
NuclearWarheadProximityDescriptor: proximity nuclear warhead, directly extending BaseWarheadDescriptorBoth implementations add logic to configure the explosion size based on the warhead parameters and the module size within a missile; the proximity version also includes code to prematurely detonate a warhead based on a fuze, rather than detonate it based on impact.
The warhead assets themselves also need to be setup with the reactor overload prefab as an the destruction effect, under Effects / Surface Groups / Destruction Effects.
Deployment
CouplingThe nuclear mod, as setup, relies on custom assets, and code that relies on those assets:
Custom code defines new types of shells and warheads
Custom shells and warheads are included as assets, in an asset bundle to be packaged with the project
Custom code copies over assets from the reactor overload prefab into our own prefab, and tracer effects into our own shellsPlease experiment with taking it apart and adapting it to your needs, but keep in mind these couplings -- trying to load something that is no longer there, or not populating something new, can lead to your mod behaving incorrectly.
The standard process is used to generate the AssetBundle:
Mark the assets and manifest.xml with the desired AssetBundle name
Use the Tools -> Assets -> Build Assets menu, provided by the ExportAssetBundles.cs script, to generate the asset bundleThe standard process is used to compile the DLL:
Open the build dialog using the File -> Build Settings... menu, and click 'Build'; recommended target location is a subdirectory called Build
When done, copy the generated DLL from the Build folder (inside the *_Data/Managed subdirectory).
Mod Folder SetupRemember to generated DLL and the Harmony DLL on your mod folder, as well as the generated asset bundle:
Here's the ModInfo used for the Nuclear mod; note that it refers to both the generated DLL and the harmony DLL, as well as the packaged AssetBundle:
<?xml version="1.0"?> <ModInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ModName>Nuclear</ModName> <ModDescription>Adds nuclear shells and missile warhead.</ModDescription> <ModVer>0.2</ModVer> <Assemblies> <string>0Harmony.dll</string> <string>nuclear.dll</string> </Assemblies> <AssetBundles> <string>nuclear</string> </AssetBundles> <PreviewImage>C:\Program Files (x86)\Steam\steamapps\common\Nebulous\Mods\Nuclear\title.jpg</PreviewImage> <GameVer>0.3.1</GameVer> </ModInfo>
Source: https://steamcommunity.com/sharedfiles/filedetails/?id=3110915492
More NEBULOUS: Fleet Command guilds
- All Guilds
- NEBULOUS: Fleet Command Guide 427
- Jakub's Guide to Not Dying to ANS Jamming
- A Thorough Guide to OSPN
- Helpful Heuristics to halt Hodgepodges and Half-measures
- Guide to Missiles and Point Defense
- Hardly's Helpful Guide to: What The Heck To Do With Your Spaceships
- Better Battle Report (BBR) User Guide
- How to use ELINT and cosmo MiG-31
- Silent Thunder Gamemode Guide and Rulebook