Modding:Preparing For Code Mods: Difference between revisions

From Vintage Story Wiki
m
m (Env Variable)
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
<languages/>
<languages/>
{{GameVersion|1.19.8}}
{{GameVersion|1.19.8}}
<translate>
__TOC__
__FORCETOC__


<translate><!--T:1-->
There is a small number of steps that must be followed before you can create a code mod. These steps only have to be done once - If you have completed this tutorial before, you may start from [[Modding:Creating A Code Mod|Creating a Code Mod]]. For more information on what can be achieved with a code mod, see [[Modding:Code Mods|Code Mods]].
There is a small number of steps that must be followed before you can create a code mod. These steps only have to be done once - If you have completed this tutorial before, you may start from [[Modding:Creating A Code Mod|Creating a Code Mod]]. For more information on what can be achieved with a code mod, see [[Modding:Code Mods|Code Mods]].


<!--T:2-->
'''This tutorial is suitable for Windows users'''. If you are using a differing operating system, please view the older [[Modding:Setting up your Development Environment|Setting up your Development Environment]] tutorial page.
'''This tutorial is suitable for Windows users'''. If you are using a differing operating system, please view the older [[Modding:Setting up your Development Environment|Setting up your Development Environment]] tutorial page.


== Installing an IDE ==
== Installing an IDE == <!--T:3-->
When developing a code mod, it is extremely important to choose a suitable IDE. For Vintage Story, it is highly recommended that you use [https://visualstudio.microsoft.com/vs/community/ Visual Studio Community] - A free and powerful development environment that is used by the Vintage Story team to develop the game. When installing Visual Studio, you should also install the '''.NET desktop development''' workload, which can be done during installation or by following [https://learn.microsoft.com/en-us/visualstudio/install/modify-visual-studio?view=vs-2022 these steps].   
When developing a code mod, it is extremely important to choose a suitable IDE. For Vintage Story, it is highly recommended that you use [https://visualstudio.microsoft.com/vs/community/ Visual Studio Community] - A free and powerful development environment that is used by the Vintage Story team to develop the game. When installing Visual Studio, you should also install the '''.NET desktop development''' workload, which can be done during installation or by following [https://learn.microsoft.com/en-us/visualstudio/install/modify-visual-studio?view=vs-2022 these steps].   


<!--T:4-->
Although some other IDEs are suitable, this tutorial will assume you are using Visual Studio. If you cannot use Visual Studio, please view the older [[Modding:Setting up your Development Environment|Setting up your Development Environment]] tutorial page.
Although some other IDEs are suitable, this tutorial will assume you are using Visual Studio. If you cannot use Visual Studio, please view the older [[Modding:Setting up your Development Environment|Setting up your Development Environment]] tutorial page.


== Installing .NET 7.0 SDK ==
== Installing .NET 7.0 SDK == <!--T:5-->
An '''SDK''' (Software Development Kit) is used to help you develop programs and code for specific platforms. Since Vintage Story relies on the '''.NET 7.0 SDK''', it is important that you download and install this too. This SDK is sometimes referred to as ''dotnet.''
An '''SDK''' (Software Development Kit) is used to help you develop programs and code for specific platforms. Since Vintage Story relies on the '''.NET 7.0 SDK''', it is important that you download and install this too. This SDK is sometimes referred to as ''dotnet.''


<!--T:6-->
Download and install the latest [https://dotnet.microsoft.com/en-us/download/dotnet/7.0 .NET 7.0 SDK], ensuring you select the version that is correct for you. This will likely be the ''Windows x64'' version.
Download and install the latest [https://dotnet.microsoft.com/en-us/download/dotnet/7.0 .NET 7.0 SDK], ensuring you select the version that is correct for you. This will likely be the ''Windows x64'' version.


When the SDK has finished installing, it is recommended to check it has installed. Launch a command prompt in Windows, either by searching for '<nowiki/>''cmd''<nowiki/>' or '''powershell''<nowiki/>' in Windows' search bar, and enter the following command:<syntaxhighlight lang="powershell">
<!--T:7-->
When the SDK has finished installing, it is recommended to check it has been configured correctly. Launch a command prompt in Windows, either by searching for '<nowiki/>''cmd''<nowiki/>' or '''powershell''<nowiki/>' in Windows' search bar, and enter the following command:<syntaxhighlight lang="powershell">
dotnet --list-sdks
dotnet --list-sdks
</syntaxhighlight>This should give you a list of installed SDKs. If there is an entry that starts with ''7.0.,'' then you may continue.
</syntaxhighlight>This should give you a list of installed SDKs. If there is an entry that starts with ''7.0.,'' then you may continue.
Line 27: Line 31:
|}
|}


== Creating an Environment Variable ==
== Creating an Environment Variable == <!--T:8-->
An '''Environment Variable''' is a value that can be used by numerous applications across your PC. Because the modding environment is separate to the game itself, you need to create a new environment variable that links to the path of your game.
An '''Environment Variable''' is a value that can be used by numerous applications across your PC. Because the modding environment is separate to the game itself, you need to create a new environment variable that links to the path of your game.


Firstly, you need to open your Vintage Story in your file explorer. If you have a shortcut to Vintage Story on your Desktop, you can right-click it and select '''Open file location''<nowiki/>'. If you do not have a shortcut, and have installed Vintage Story to the default install location, it will be found in your appdata folder. You can find this folder by using [https://www.minitool.com/data-recovery/how-find-appdata-folder.html#:~:text=You%20can%20directly%20open%20the,%25appdata%25%20and%20press%20Enter. this method]. If you have installed it elsewhere, you will need to find this folder in the file explorer.
<!--T:9-->
Firstly, you need to open Vintage Story in your file explorer. If you have a shortcut to Vintage Story on your Desktop, you can right-click it and select '''Open file location''<nowiki/>'. If you do not have a shortcut, but have installed Vintage Story to the default install location, it will be found in your appdata folder. You can find this folder by using [https://www.minitool.com/data-recovery/how-find-appdata-folder.html#:~:text=You%20can%20directly%20open%20the,%25appdata%25%20and%20press%20Enter. this method]. If you have installed it elsewhere, you will need to find this folder in the file explorer.


The opened folder should contain the '<nowiki/>''assets''<nowiki/>', '<nowiki/>''mods''<nowiki/>', and '''lib''<nowiki/>' folders.
<!--T:10-->
The opened folder should contain the '<nowiki/>''assets''<nowiki/>', '<nowiki/>''mods''<nowiki/>', and '<nowiki/>''lib''<nowiki/>' folders. Ensure you are '''not''' in the '''VintageStoryData''<nowiki/>' folder.


<!--T:11-->
When you have your game folder open in Windows file explorer, you need to open this folder in powershell. '''Ensure you do not have a file or folder selected,''' and click 'File' in the menu bar, then click 'Open Windows PowerShell'.
When you have your game folder open in Windows file explorer, you need to open this folder in powershell. '''Ensure you do not have a file or folder selected,''' and click 'File' in the menu bar, then click 'Open Windows PowerShell'.
[[File:OpenVintageStoryFolderInPowershell.png|center|frameless|388x388px]]
[[File:OpenVintageStoryFolderInPowershell.png|center|frameless|388x388px]]
Powershell will open with your file path. Ensure that the file path stated does not include the '<nowiki/>''assets''<nowiki/>', '<nowiki/>''mods''<nowiki/>', or '''lib''<nowiki/>' folders. Paste the following line into powershell, and press enter to run it.<syntaxhighlight lang="powershell">
Powershell will open with your current file path. Ensure that the file path stated does not include the '<nowiki/>''assets''<nowiki/>', '<nowiki/>''mods''<nowiki/>', or '''lib''<nowiki/>' folders. Paste the following line into powershell, and press enter to run it.<syntaxhighlight lang="powershell">
[Environment]::SetEnvironmentVariable("VINTAGE_STORY", ($pwd.path), "User")
[Environment]::SetEnvironmentVariable("VINTAGE_STORY", ($pwd.path), "User")
</syntaxhighlight>This will create the environment variable called "VINTAGE_STORY", and set its value to be the current working directory (the Vintage Story folder). The "user" parameter simply stores this variable as a user-only environment variable, meaning other users on your PC will not be able to use this variable.
</syntaxhighlight>This will create the environment variable called "VINTAGE_STORY", and set its value to be the current working directory (the Vintage Story folder). The "user" parameter simply stores this variable as a user-only environment variable, meaning other users on your PC will not be able to use this variable.
Line 42: Line 49:
|Test your environment variable
|Test your environment variable
|-
|-
|To ensure your environment variable has been created correctly, in the opened powershell, run the following command:<syntaxhighlight lang="powershell">
|To ensure your environment variable has been created correctly, run the following command in the opened powershell:<syntaxhighlight lang="powershell">
echo $env:VINTAGE_STORY
echo $env:VINTAGE_STORY
</syntaxhighlight>This should print the direct path to your vintage story directory. If it does not, then repeat this section.
</syntaxhighlight>This should print the full path to your vintage story directory. If it does not, then repeat this section.
|}
|}
When you have set a new environment variable, it is recommended to restart your PC. This will ensure that all programs are using your updated environment variables.
== Installing Modding Templates == <!--T:12-->
The final step is to install the mod templates. These mod templates will automatically setup your mod for you in Visual Studio, automatically adding any libraries and code that is needed to get your mods up and running.\
<!--T:13-->
Open a powershell command line, paste the following, and press enter to run it. This execution should only take a few seconds, as it is a very small file.<syntaxhighlight lang="powershell">
dotnet new install VintageStory.Mod.Templates
</syntaxhighlight>This is where everything comes together. Your dotnet installation will download the Vintage Story mod templates from NuGet (an online package manager for .NET), and install the templates to be used with Visual Studio.
=== Test your template installation === <!--T:14-->
To ensure that the template has installed correctly, launch Visual Studio and select 'Create a new project'. In the furthest-right drop down list ('<nowiki/>''All project types'''), find 'Vintage Story' in the list.
[[File:VintageStoryTemplatesInVisualStudio.png|center|frameless|571x571px]]
<!--T:15-->
If it exists, and displays two projects, then your template has successfully installed and you are ready to start making code mods. Congratulations!
<!--T:16-->
If 'Vintage Story' does not exist in the project types, or there are no projects listed under this category, try restarting your PC and looking again. If there is still nothing, run the above command again.
== Next Steps == <!--T:17-->
Now that you have completed this tutorial, you can begin creating as many code mods as you wish. Move on to [[Modding:Creating A Code Mod|Creating a Code Mod]] to setup and customize your first mod!
</translate>
</translate>
{{Navbox/codemodding}}
{{Navbox/codemodding}}
Confirmedusers
637

edits