Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Worldbox Wiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
How to make mods (native modding system)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Upload file
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Part I. Visual Studio Installation.== #Download [https://visualstudio.microsoft.com/vs/community/ Visual Studio Community 2019]. #Run downloaded file.[[File:Visual Studio Installation.png|alt=Visual Studio Installation|thumb|Visual Studio Installation ]]<br /> #After all preparations have done, you need to select <u>.NET desktop development,</u> and select checkboxes in right side menu: <u>.NET Framework 4.6.1 development tools</u>, <u>.NET Framework 4.6.2 development tools</u>, <u>.NET Framework 4.7 development tools</u>, <u>.NET Framework 4.7.1 development tools</u>, <u>.NET Framework 4.8 development tools</u>. Honestly, you don't need them all, but just in case select them all. After all selecting, you need just to click on <u>Install</u> button in the right down corner. #Wait until Visual Studio will be installed. #Done! Now you have installed <u>Visual Studio Community 2019</u>! ==Part II. Creating new project.== ===Creating project:=== #Open Visual Studio. #Click on <u>Create a new project</u> button. #Now you need to select <u>Class library (.NET Framework)</u>. EXACTLY <u>Class library (.NET Framework)</u>!!! #Fill <u>Project name</u> field with your mod name. Do not use spaces, use [https://ru.wikipedia.org/wiki/CamelCase camel case] instead. #Click <u>Create</u> button in the right down corner. #Done! Project created. ===Preparations before modding:=== #After project will be created, you will see something like this: <syntaxhighlight lang="c#" line="1" start="1"> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public class Class1 { } } </syntaxhighlight> #Now you need to find <u>Solution Explorer</u> in right side, right click on your project name and then click on <u>Open Folder in File Explorer.</u> #In opened folder you need to create new folder with name <u>Libs</u> (or something like this). #Go to your <u>WorldBox</u> folder (where <u>worldbox.exe</u> is), and then go to <u>/worldbox_Data/Managed;</u> #Copy from Managed folder files: <u>Assembly-CSharp.dll</u>, <u>UnityEngine.dll</u> and <u>UnityEngine.CoreModule.dll</u>. Paste them into <u>yourProject/Libs</u> folder #Now go to <u>Visual Studio</u>, in <u>Solution Explorer</u> right click on <u>References</u> > <u>Add Reference...</u>[[File:Add reference....png|alt=Add reference...|thumb|Add reference...]] #Click <u>Browse</u>, and in opened window select files in <u>yourProject/Libs</u> folder, click <u>Add</u>, click <u>Ok</u>. #Now you need to change code of your file. It should looks like it:<syntaxhighlight lang="c#" line="1"> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; namespace ExampleMod { public class WorldBoxMod : MonoBehaviour { static bool initialized = false; void Update() { if (!Config.gameLoaded) return; if (!initialized) { init(); } initialized = true; } void init() { //your code here } } } </syntaxhighlight>There is added <u>using UnityEngine;</u> in the head of file, added <u>initialized</u> boolean variable, which will be true after game will be loaded and all stuff will be initialized, added <u>Update</u> method which calls ~60 times per second, and this is a part of [https://docs.unity3d.com/Manual/ExecutionOrder.html unity game cycle]. All your code, or other methods calls must be inside <u>init</u> method. It is not necessary, and depends of what you want to make it can be other, but in most of cases this is default starter code. Namespace must be the same as mod name as result dll file name. Class name must be <u>WorldBoxMod : MonoBehaviour</u> because it is necessary for <u>WorldBox native modding system</u>. Do not change class name! #All preparations done! Now you can start create your own mod! #To see what you can change, or just to explore game code, you need to disassemble <u>Assembly-CSharp.dll</u>. You can do it using <u>JetBrains dotpeek</u> or <u>dnSpy</u>. You can use google to know how to use them. #Also, i recommend to you to learn c sharp, at least basics before you will start modding, because it can close many questions for you. ==Part III. Modding== ===Example mod:=== Let make new mod, where we will change <u>giant trait</u>, to make creatures that have it much more size and speed then with vanilla <u>giant trait</u>. And we will make that all races will have this trait by default, right from spawning/birth. As i said before, you can explore game code by disassembling <u>Assembly-CSharp.dll</u> using <u>JetBrains dotpeek</u> or <u>dnSpy.</u><br />Example of editing trait:<syntaxhighlight lang="c#" line="1" start="28"> void init() { var giantTrait = AssetManager.traits.get("giant"); giantTrait.baseStats.scale = 0.50f; // default is 0.05f } </syntaxhighlight>There we: #Received trait from asset manager by its id: <u>var giantTrait = AssetManager.traits.get("giant");</u> #Changed scale factor from 0.05 to 0.50 (multiplied by ten times!): <u>giantTrait.baseStats.scale = 0.50f;</u> Yes, we changed our trait, but how we can add it to our creatures(all races at this case)?<syntaxhighlight lang="c#" line="1" start="28"> void init() { var giantTrait = AssetManager.traits.get("giant"); giantTrait.baseStats.scale = 0.50f; // default is 0.05f var human = AssetManager.unitStats.get("unit_human"); human.traits.Add("giant"); human.traits.Add("slow"); var elf = AssetManager.unitStats.get("unit_elf"); elf.traits.Add("giant"); elf.traits.Add("slow"); var orc = AssetManager.unitStats.get("unit_orc"); orc.traits.Add("giant"); orc.traits.Add("slow"); var dwarf = AssetManager.unitStats.get("unit_dwarf"); dwarf.traits.Add("giant"); dwarf.traits.Add("slow"); } </syntaxhighlight>Right after trait changes we also add changes in creatures assets. There we: #Received unit asset using asset manager: var human = AssetManager.unitStats.get("unit_human"); #Added giant trait: <u>human.traits.Add("giant");</u> #Added slow trait, cuz we want to make out giants slow: <u>human.traits.Add("slow");</u> #And we did the same with all four civilized races. Done! Our code ready, but now we want to build a dll and test our mod. #In top panel go to <u>Build</u> > <u>Build Solution</u> (F6 by default). #Go to <u>yourProjectName/bin/Debug</u> <u>(ExampleMod/bin/Debug)</u> in our case, find there <u>yourProjectName.dll</u> (<u>ExampleMod.dll</u> in our case) #Copy <u>yourProjectName.dll</u>, go to <u>WorldBox</u> folder (where worldbox.exe is), go to path <u>/worldbox_Data/StreamingAssets/Mods</u> and paste <u>yourProjectName.dll</u> there. #Run the game #Try to spawn any civilized creatures(humans/elves/orcs/dwarfs);[[File:Very large civilized units.png|alt=Very large civilized units|thumb|188x188px|Very large civilized units]] #Done! Now you will see that they are too big, and a little bit slow. #If you doesnt see any changes, try to run your game as administrator There is full code:<syntaxhighlight lang="c#" line="1"> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; namespace ExampleMod { public class WorldBoxMod : MonoBehaviour { static bool initialized = false; void Update() { if (!Config.gameLoaded) return; if (!initialized) { init(); } initialized = true; } void init() { var giantTrait = AssetManager.traits.get("giant"); giantTrait.baseStats.scale = 0.50f; // default is 0.05f var human = AssetManager.unitStats.get("unit_human"); human.traits.Add("giant"); human.traits.Add("slow"); var elf = AssetManager.unitStats.get("unit_elf"); elf.traits.Add("giant"); elf.traits.Add("slow"); var orc = AssetManager.unitStats.get("unit_orc"); orc.traits.Add("giant"); orc.traits.Add("slow"); var dwarf = AssetManager.unitStats.get("unit_dwarf"); dwarf.traits.Add("giant"); dwarf.traits.Add("slow"); } } } </syntaxhighlight> # [[Category:Technical Help]] [[Category:Modding]]
Summary:
Please note that all contributions to Worldbox Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Worldbox Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width