Difference between revisions of "SKSE Plugin Development"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>3Nd R1m
m (...)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
The Skyrim Script Extender (SKSE) is a tool that expands scriptings capabilities and adds additional functionality to the game, as well as allowing modders to create plugins to further extend Skyrim's scripting capabilities. SKSE plugins take form as DLLs files that implement new functions into Papyrus, Creation Kit's scripting language. As you may guess, making an SKSE plugin is more difficult than a standard mod but the benefits of doing one are far greater. This guide focus on implementing new functions into Papyrus Scripting and debugging them.
[SKSE64 2.2.6 Revision]


This page is actually '''incompleted''' as it doesn't actually provide a complete tutorial on how to make an SKSE plugin project. We try to figure out how to do it ourselves before guiding others, with our only sources being closed threads, incomplete guides and tutorials who never saw any updates. With any progression on our side will come further upgrade, until this guide is completed. Until then, be assured that everything that has already been laid out is correct and up-to-date.
The Skyrim Script Extender (SKSE) is a tool that enhances the capabilities of [[Papyrus]] scripts and adds additional functionality to the game, as well as allowing modders to create plugins to further extend Skyrim's scripting capacities. SKSE plugins take form as .DLL files that usually implement new functions into Papyrus, Creation Kit's scripting language. As you may guess, making an SKSE plugin is more difficult than using Papyrus, but you are free of many limitations that Papyrus has, and using C++ might improve performance dramatically where comparable.


== Sources ==
== Requirements ==
These are related sources that have inspired this guide. Please note that the instructions may differ from one source to another and that some might simply be completely wrong/outdated.
* Skyrim Special Edition
* [https://skse.silverlock.org/ SKSE for Skyrim SE] (Also referred to as SKSE64), which you should already have installed.
* [https://visualstudio.microsoft.com/ Visual Studio 2022 Build Tools]. You don't need to install the entire IDE if you won't use it.
*An IDE like Visual Studio, VS Code or CLion. [[User:Xieve|xieve]] recommends using CLion if you have not used Visual Studio before, as it will manage installation of vcpkg automatically, among other things.
 
Ensure that your Windows and SKSE installations are up-to-date. If Skyrim Special Edition has not received an update in the previous week or so, you will want that up-to-date too. See the official SKSE page to see which version is currently supported. Please keep in mind that this guide does not guarantee backward/forward compatibility, and things keep breaking in unforeseen ways.


* [http://forums.bethsoft.com/topic/1496168-wipz-skyrim-script-extender-skse/page-4#entry23595441 Zartar's "noob tutorial" on Bethesda's old forum.]  The whole discussion may contain other helpful information too.
== Setup ==
*[https://github.com/Ryan-rsm-McKenzie/CommonLibSSE/wiki Ryan-rsm-McKenzie's Tutorial on GitHub]. However, his tutorial doesn't work for many users which led to believe it might be outdated.
The easiest and recommended approach is to use a template plugin. [https://github.com/Monitor221hz/CommonLibSSE-NG-Template-Plugin This one] is currently (as of 2024-11-16) recommended for CommonLibSSE-NG. [https://commonlib.dev/ See here] for a comparison of the different CommonLibSSE versions.
*[https://www.reddit.com/r/skyrimmods/comments/bmg1z7/finally_aiming_for_my_first_skse_plugin_been/ This Reddit discussion]
*[https://github.com/xanderdunn This GitHub page]


Credit goes to Bethesda, the SKSE Team, Ryan/Fuggyduff and every contributor of this page:  Dienes, ThighNookNoodel and 3Nd_R1m.
Follow the documentation that the template plugin of your choice provides, it will be more up-to-date and applicable than any external resource.


== Requirements ==
* Skyrim Special Edition
* [https://skse.silverlock.org/ SKSE for Skyrim SE] (Also referred as SKSE64)
* SKSE64 source code which is included in the SKSE64 distribution
* SKSE64 example plugin which ''should'' be included with the source code but actually isn't. A replacement one will be provided as soon as possible.
*[https://visualstudio.microsoft.com/vs/ Visual Studio 2019], but you can use an earlier version if you wish.
*And most importantly, you need to know C++ programming.


To eliminate any potential trouble, be sure to have the most up-to-date versions of Windows, Skyrim Special Edition and any other toolset specified in this guide. Please keep in mind that this guide does not guarantee Backward/forward compatibility.
Should you want to, you can set environment variables inside <code>CMakeLists.txt</code> like so:
set(ENV{VARIABLE_NAME} "Variable value")
For example:
set(ENV{SKYRIM_MODS_FOLDER} "C:\\Games\\MO2\\mods")


== Setups ==
== Making a plugin ==
Before making a plugin, you need to set up the environment.
As of 2024-11-16, there is no definitive resource on SKSE plugin modding.  


=== Building SKSE ===
These are related sources that have inspired this guide. Please note that the instructions may differ from one source to another and that some might simply be completely wrong/outdated.
To make a plugin we'll first need SKSE's source code. However, SKSE was made with an earlier version of Visual Studio and still use outdated toolsets that aren't available within VS2019. Therefore additional setups must be performed.
* [https://github.com/Ryan-rsm-McKenzie/CommonLibSSE/wiki Ryan-rsm-McKenzie's Tutorial on GitHub]. Most notably, includes documentation for debugging setup and CommonLibSSE's Papyrus API.
#Within the SKSE zip files obtained from [https://skse.silverlock.org/ the official website] locate and extract the '''src/''' directory.
*[https://github.com/ianpatt/skse64 The original SKSE64 source code on GitHub], which, in contrast to CommonLibSSE, '''has comments'''! You should definitely check this out as it is probably the best documentation you will find. I recommend cloning (downloading) this repository and checking it out in your IDE so you can search it more easily.
#Open the SKSE64 solution '''src\skse64\skse64.sln''' with Visual Studio 2019. VS2019 should already be associated with the .sln file type.
*[https://skyrim.dev/skse Skyrim.dev - SKSE]
#Upon loading, you'll be prompted with the option to "Permanently remove source control association bindings". The SKSE team uses what is called "Source control", which is a way to share, update and checkout codes coming from multiple users. We won't (and can't) use their source control so we can permanently remove any source control association. [https://imgur.com/95b5KXK (image)]
*[https://commonlib.dev/ Unofficial auto-generated documentation for CommonLibSSE, CommonLibVR and CommonLibSSE-NG]
#Just after that, a new window will appear and suggest to Retarget the Projects. The default options should be good enough and you can press '''"Ok"'''. [https://imgur.com/jnyPSWk (image)]
*[https://discord.gg/d96UKrKead MrowrPurr's Discord]. You can ask SKSE- or Papyrus-related questions here.
#; Why is that?
*[http://forums.bethsoft.com/topic/1496168-wipz-skyrim-script-extender-skse/page-4#entry23595441 Zartar's "noob tutorial" on Bethesda's old forum.]  The whole discussion may contain other helpful information too.
#: The SKSE project is made with an earlier version of the Visual C++ platform toolset (The 2015 version, there for two major versions behind). It's good development practice to keep your project's component up-to-date and, hopefully, Visual Studio can take care of that itself. However, some more configuration will be needed to successfully build the solution.
* [https://www.reddit.com/r/skyrimmods/comments/bmg1z7/finally_aiming_for_my_first_skse_plugin_been/ This Reddit discussion on weird errors while trying to set up a plugin template]
#Open the Property Pages for all projects.
#: We're gonna tweak some options within the Configuration Properties.
#: You can do so by selecting all projects within the solution explorer (Tip: select the first element and then the last one while holding '''SHIFT''' ) and press '''ALT'''+'''ENTER''' to open the Property Pages.
#: Also make sure that the '''Configuration''' field is set to '''All Configuration''', as we want them to apply for Debbug+ing as well as releasing.
## Disable post-build events
##: The project files include post-build events that we don't want (Such as automatically moving files into Skyrim's directory).
##: To disable post-build events, navigate to '''Build Events => Post-Build Event''' and change the '''Use in build''' field to '''No'''.
## Set C++ Language Standard
##: Navigate to '''C/C++ => Language''' and set '''C++ Language Standard''' to '''ISO C++17 Standard (/std:c++17)'''.
## Force-include <string>
#: At this point, any attempt to build the solution will fail and there will be many errors [https://imgur.com/9jpNjtK 3275 (image)], with the most predominant one being <q>C2039: 'string' is not a member of 'std'</q>. In other words, many files are using the 'string' class without including the required header to do so.
#: You can fix this without manually adding #include directives by instead navigating to '''C/C++ => Advanced''' and adding "string" (without quotation) in the '''Force Include File''' field. This will automatically include the string header whenever it's required.
# Click "Apply" and then "Ok". [https://imgur.com/4DWpnzP (Image)]


SKSE should be ready to build. To test that, build the solution with the Release configuration. If no error occurs, congratulation! We can move on to the next section.


==== Testing the build ====
Generally, SKSE plugin development heavily depends on a good IDE that allows you to browse the SKSE and CommonLibSSE sources, and on reading other people's source code on GitHub.  
This section is optional and aims to further validate our home-built SKSE by testing it.
Assuming you already have SKSE installed, go ahead and replace the original files from the Skyrim SE directory with the new ones located in '''src/skse64/x64/Release'''. The files to replace are '''skse_(version).dll''', '''skse_loader.exe''' and '''skse64_steam_loader.dll'''.
After replacing them, try to run '''skse_loader.exe'''. Skyrim should launch without any issues.


Note: Hypothetically, an SKSE built with updated configurations may give better performance than the default one provided by the SKSE team, but the opposite may also be true.
If you chose to use CLion, navigate to <code><Project Directory>\build\debug-msvc\vcpkg_install\vcpkg\pkgs\commonlibsse-ng_x64-windows-skse</code>, right-click it and select <code>Mark directory as</code>→ <code>Library Files</code>. Now, when you hit shift twice to invoke Search Everywhere, all the CommonLibSSE symbols will show up in your search!


== What next? ==
=== Implementing new methods ===
At this point, we should start making a plugin from the SKSE example plugin. However, the project isn't present in the downloaded files, unlike what it's being said in readme.txt and PluginApi.h. In the meantime, you can take a look at our sources and look for guides who do have plugin examples.
SKSE Plugin cannot override or extend already existing Form classes. In other words, consider an ''"ObjectReference"'' object and a ''"newMethod(<parameters>)"'' function you want to implement as an interaction of ''ObjectReference''. You won't be able to implement ''ObjectReference.newMethod(<parameters>)''. Instead, you can create a new ''"MyScript"'' object and implement ''MyScript.newMethod(ObjectReference, <parameters>)''.
[[Category:SKSE]]

Latest revision as of 13:47, 16 November 2024

[SKSE64 2.2.6 Revision]

The Skyrim Script Extender (SKSE) is a tool that enhances the capabilities of Papyrus scripts and adds additional functionality to the game, as well as allowing modders to create plugins to further extend Skyrim's scripting capacities. SKSE plugins take form as .DLL files that usually implement new functions into Papyrus, Creation Kit's scripting language. As you may guess, making an SKSE plugin is more difficult than using Papyrus, but you are free of many limitations that Papyrus has, and using C++ might improve performance dramatically where comparable.

Requirements[edit | edit source]

  • Skyrim Special Edition
  • SKSE for Skyrim SE (Also referred to as SKSE64), which you should already have installed.
  • Visual Studio 2022 Build Tools. You don't need to install the entire IDE if you won't use it.
  • An IDE like Visual Studio, VS Code or CLion. xieve recommends using CLion if you have not used Visual Studio before, as it will manage installation of vcpkg automatically, among other things.

Ensure that your Windows and SKSE installations are up-to-date. If Skyrim Special Edition has not received an update in the previous week or so, you will want that up-to-date too. See the official SKSE page to see which version is currently supported. Please keep in mind that this guide does not guarantee backward/forward compatibility, and things keep breaking in unforeseen ways.

Setup[edit | edit source]

The easiest and recommended approach is to use a template plugin. This one is currently (as of 2024-11-16) recommended for CommonLibSSE-NG. See here for a comparison of the different CommonLibSSE versions.

Follow the documentation that the template plugin of your choice provides, it will be more up-to-date and applicable than any external resource.


Should you want to, you can set environment variables inside CMakeLists.txt like so:

set(ENV{VARIABLE_NAME} "Variable value")

For example:

set(ENV{SKYRIM_MODS_FOLDER} "C:\\Games\\MO2\\mods")

Making a plugin[edit | edit source]

As of 2024-11-16, there is no definitive resource on SKSE plugin modding.

These are related sources that have inspired this guide. Please note that the instructions may differ from one source to another and that some might simply be completely wrong/outdated.


Generally, SKSE plugin development heavily depends on a good IDE that allows you to browse the SKSE and CommonLibSSE sources, and on reading other people's source code on GitHub.

If you chose to use CLion, navigate to <Project Directory>\build\debug-msvc\vcpkg_install\vcpkg\pkgs\commonlibsse-ng_x64-windows-skse, right-click it and select Mark directory asLibrary Files. Now, when you hit shift twice to invoke Search Everywhere, all the CommonLibSSE symbols will show up in your search!

Implementing new methods[edit | edit source]

SKSE Plugin cannot override or extend already existing Form classes. In other words, consider an "ObjectReference" object and a "newMethod(<parameters>)" function you want to implement as an interaction of ObjectReference. You won't be able to implement ObjectReference.newMethod(<parameters>). Instead, you can create a new "MyScript" object and implement MyScript.newMethod(ObjectReference, <parameters>).