Difference between revisions of "SKSE Plugin Development"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Dienes
(Rough start)
 
 
(16 intermediate revisions by 4 users not shown)
Line 1: Line 1:
SKSE supports loading mod dll plugins to extend its abilities. Making a DLL plugin mod is more complicated than a standard skyrim mod with the creation kit and papyrus however it allows much greater control of the game. Since 1.07.0 SKSE has had support for adding papyrus functions in a DLL which is what this page will focus on. It does not support dynamically adding additional functions to existing scripts so you need to make a new script type as a wrapper for the new functions and then call them through that. So instead of SomeObjectReference.newFunction(param1, param2) you do NewWrapperScript.newFunction(SomeObjectReference, param1, param2).
[SKSE64 2.2.6 Revision]


This is a quick placeholder to get things started, hopefully others will help format it and fill it out. Zartar wrote up a good guide in one of the SKSE threads that should be a base. http://forums.bethsoft.com/topic/1496168-wipz-skyrim-script-extender-skse/page-4#entry23595441 which should go here.
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.
There is more discussion before and after that post that would probably be helpful too.


A few other things that I think were talked about in a different version of the thread: SKSE only builds as is in vs2008 (the same version as skyrim was built in which helps compatibility) but plugins should be buildable in newer. Or at the least you can write in 2013+ and switch to compile them. I think you also need to modify the SKSE solution properties to suit your system for it to work but its been a long time. The function flag kFunctionFlag_NoWait in the example means the function is threadsafe so you probably don't want it. When built in debug mode SKSE has hooks to attach a debugger but it happens before the dll mods are loaded so you won't be able to break in your code that way. It is possible to attach the debugger and use breakpoints in your plugin's code but the only way I know of I don't think is appropriate to discuss as its grey area towards piracy stuff. For debugging I suggest you throw print statements in your plugin and then look at the log.
== Requirements ==
* 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.
 
== Setup ==
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.
 
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 <code>CMakeLists.txt</code> like so:
set(ENV{VARIABLE_NAME} "Variable value")
For example:
set(ENV{SKYRIM_MODS_FOLDER} "C:\\Games\\MO2\\mods")
 
== Making a plugin ==
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.
* [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.
*[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.
*[https://skyrim.dev/skse Skyrim.dev - SKSE]
*[https://commonlib.dev/ Unofficial auto-generated documentation for CommonLibSSE, CommonLibVR and CommonLibSSE-NG]
*[https://discord.gg/d96UKrKead MrowrPurr's Discord]. You can ask SKSE- or Papyrus-related questions here.
*[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.
* [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]
 
 
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 <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!
 
=== Implementing new methods ===
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>).