Preface
Today I was playing around in Feed and Grow Fish and noticed that the Bibos has a Gang feature that can be toggled to make other Bibos work as a group to attack things.
Naturally my first question is "How can we take that to the EXTREME?", let's investigate!
Can I see it in action?
Of course! We've made a companion video that shows the mod in action, and exactly what it does, the video also walks through the tutorial from below, so you can see exactly how this all works.
Lets go exploring
Let's load Feed and Grow Fish into dnSpy so that we can begin to search for gangs and see what we can find.My first step was to try and find the gang ability, and find it I did:
It's called "CallOfBrotherhood" internally.
Let's take a look at the code for when this ability is equipped:
Looks like exactly what we want, we can see there is a "Group" property on your player which gets created if you're part of a group, and then it sets your fish to be the "Leader" and configures the "PermanentLeader" property to true, and then shows a nice little notification (That's cool, we can use that notification code elsewhere).
Our past mods that we've made on on our YouTube channel have added extra key binds by editing the PlayerController class -- This is where all the logic for when you're doing stuff as a Fish is actually housed, there is also a SpectatorController, but we don't care too much about that for our use cases.
Let's build a mod
I've written a chunk of code that can be directly copy and pasted into the PlayerController so that we can have custom binds for adding every single fish into our gang, and a custom bind for spawning new fish and placing those into our gang.
I've put a bunch of comments (the green lines) in there for you, they start with a "//" which means they are a comment in C#, so you can just paste that directly in, exactly as it is, and dnSpy will just ignore the comments.
It's easy enough to change the key bindings, if you just delete the letter (e.g. P) and then delete the "dot" before it, you can type a dot, and then dnSpy will automatically try to help you and autocomplete, showing you a range of other options, allowing you to see all the keys that are available.
I've put a bunch of comments (the green lines) in there for you, they start with a "//" which means they are a comment in C#, so you can just paste that directly in, exactly as it is, and dnSpy will just ignore the comments.
It's easy enough to change the key bindings, if you just delete the letter (e.g. P) and then delete the "dot" before it, you can type a dot, and then dnSpy will automatically try to help you and autocomplete, showing you a range of other options, allowing you to see all the keys that are available.
// Did we just press the letter "P"? if (Input.GetKeyDown(KeyCode.P)) { // Are we in a group? if (this.CurrentLivingEntity.Group == null) { // We are not in a group, better create one! LivingEntityGroup.CreateGroup(this.CurrentLivingEntity, this.CurrentLivingEntity); } // Loop over every single LivingEntity (fish, whales, sharks, crabs, EVERYTHING) foreach (LivingEntity thisEnt in UnityEngine.Object.FindObjectsOfType<LivingEntity>()){ // Add this LivingEntity to our new group this.CurrentLivingEntity.Group.AddLivingEntity(thisEnt); } // Set the intensity (how close everything is) to be really low this.CurrentLivingEntity.Group.DensityIntensity = 0.1f; // Make it so there is a leader, and make the leader us this.CurrentLivingEntity.Group.PermanentLeader = true; this.CurrentLivingEntity.Group.Leader = this.CurrentLivingEntity; // Tell everything who falls behind to come catch up this.CurrentLivingEntity.Group.DontLeaveBehind = true; // Show a pretty message NotifyDialogue.ShowNotify("Super Gang Updated", 1.5f); } // Are we currently holding the letter "O" if (Input.GetKey(KeyCode.O)) { // Are we in a group? if (this.CurrentLivingEntity.Group == null) { // We are not in a group, better create one! LivingEntityGroup.CreateGroup(this.CurrentLivingEntity, this.CurrentLivingEntity); } // Grab a list of EVERY template fish in the entire game LivingEntity[] array2 = Resources.LoadAll<LivingEntity>("NPCS"); // Loop over every template, we are looking for one that matches our fish LivingEntity foundEnt = null; foreach (LivingEntity anEnt in array2) { // Is the name of this template the same as the name of our fish? if (anEnt.name == this.CurrentLivingEntity.name) { // Woot, we found the right template! foundEnt = anEnt; // Exit the loop, no need to continue break; } } // Did we manage to find the template for our fish? if (foundEnt != null) { // We found the template! // Create a copy of that template, and spawn it at the same position as our fish LivingEntity newEnt = (LivingEntity)NpcGenerator.Instance.Spawn(foundEnt, this.CurrentLivingEntity.Position, false); newEnt.IsMyPlayer = false; // Add that new fish we created to our group this.CurrentLivingEntity.Group.AddLivingEntity(newEnt); // Set the intensity (how close everything is) to be really low this.CurrentLivingEntity.Group.DensityIntensity = 0.1f; // Make it so there is a leader, and make the leader us this.CurrentLivingEntity.Group.PermanentLeader = true; this.CurrentLivingEntity.Group.Leader = this.CurrentLivingEntity; // Tell everything who falls behind to come catch up this.CurrentLivingEntity.Group.DontLeaveBehind = true; } }
Pretty cool, but what do we do with that chunk?
Find the "Assets.Code.PlayerController" class (see the screenshot) and click on it to load the code for that class.
Clicking on the "PlayerController" class will load up the code for the class, we need to scroll down to find the "Update" method. The "Update" method is run every single frame of the game, and its where we do the logic for checking what controls are pressed, and it's where we will inject our code block.
We're looking for a block that starts with "protected void Update()" and then within there, a few lines below, there is a line that reads "if (this.CurrentLivingEntity != null)". We need to add our code just AFTER the curly bracket.
Right click anywhere in there, and select "Edit Method C#", this will pop open a code editor which will let us actually change the code.
Here's the position we're looking at:
And here's what it looks like after we added the code block within the editor:
You can see that our code begin on line 37 with "// Did we just press the letter P?". You'll also notice that the information lines have turned green, indicating that they are a comment, and don't actually do anything.
With our code change in place, we need to tell it to recompile, this could cause the code to change a fair bit due to the compiling making optimisations, however, the meaning will still be the same.
Press the "Compile" button in the bottom right hand corner of the screen.
Everything should be updated now, however, we need to tell dnSpy to write the changes to the DLL we are editing, so let's tell it to save.
Access the "File" menu and select "Save All...", you should get a popup with a bunch of options, simply select "OK" to confirm and it will override the original DLL, and the code changes will be saved.
That's it!The mod is now installed!
How do I use the mod?
Well! Assuming you've followed the tutorial from above, you should now have the mod installed :)
You can press the letter "P" to make every single fish in the entire map that is currently spawned join your gang and head towards you.
You can hold the letter "O" and clones of your current fish will spawn on top of you and head towards you.
cool mod
ReplyDeleteThanks mate, all our mods these days are on https://beta.AzzaMods.com
Delete