-
Notifications
You must be signed in to change notification settings - Fork 3
Plugin
A plugin is a native DLL that is loaded when Ty starts. The purpose of a plugin can vary dramatically. Generally, a plugin will write directly to the memory of the Ty process. When writing directly, be conscious memory changes per version and sometimes even per user. Use pattern scanning.
- Developing a plugin requires Visual Studio and the Visual C++ development tools
- For debugging purposes, set the
TY_1_DIR
system environment variable to the path of your Ty installation.
Open Visual Studio and create a new project. Select Win32 Project
under Other Languages -> Visual C++ -> Win32
. This part is critical. Managed assembly will not run. Name the project what you like.
Click Next
in the wizard and then check Empty Project
and select DLL
. Click Finish
.
In order to get debugging to work correctly you've got to do a few things.
- Consider making a copy of your Ty installation just for testing purposes
- Set the
TY_1_DIR
system environment variable to the path of that copy (or the original Ty installation) - Install the Mod Manager
- Setup the debug environment
After that you should create an XML mod you can control directly from Visual Studio that will be outputted with your plugin.
- Right-click
Resource Files
and selectAdd -> New Item... -> Visual C++ -> Web -> XML File
- Name the XML file after your Project name
- Replace the default contents of the XML file with this general XML mod for plugins
<root>
<tymod name="" version="" authors="" tyversion="" description="">
<plugin></plugin>
</tymod>
</root>
Go ahead and fill in the attributes and elements. Refer to here for more information on how to use a plugin edit element.
Finally, enter the project properties again. Under Build Events -> Post-Build Event
set Command Line
to copy /Y "$(ProjectDir)$(ProjectName).xml" "$(OutputPath)$(ProjectName).xml"
. Do this for the Release and Debug configuration.
Setting up debugging can greatly help development. To get started, right-click your Project in the Solution Explorer and select Properties.
- Ensure the Configuration on the top right is
Debug
- Under
Configuration Properties -> General
set theOutput Directory
to$(TY_1_DIR)Mods\
- Under
Configuration Properties -> Debugging
set theCommand
to$(TY_1_DIR)TY.exe
- Under
Configuration Properties -> Debugging
set theWorking Directory
to$(TY_1_DIR)
- Set the Configuration on the top right back to
Active(...)
To get your plugin to actually load, you must load the Mod Manager, enable your mod, and press Play to install. Afterwards, close Ty. Launching the plugin will now start Ty and load your assembly into the application.
Add a main.cpp
to the Source Files
folder. You do not need to make a class for this.
Create a main method that follows this format:
#include <cstdint>
void main(const char * dllPath, uint64_t baseAddress, uint64_t baseEndAddress, uint64_t revision, float version) {
}
In order for this new function to be visible by external application, we must export it. Simply replace the void
with __declspec(dllexport) void __cdecl
:
#include <cstdint>
__declspec(dllexport) void __cdecl main(const char * dllPath, uint64_t baseAddress, uint64_t baseEndAddress, uint64_t revision, float version) {
}
Name | Description | Usage |
---|---|---|
dllPath | Path to your DLL | Can load any resources from the directory of dllPath
|
baseAddress | Start of Ty.exe in memory | For pattern searching |
baseEndAddress | End of Ty.exe in memory | For pattern searching |
revision |
rX version of Ty |
For version specific mods |
version |
vX.XX version of Ty |
For version specific mods |
Adding some code is the next step. You should stay away from running expensive tasks on the main thread. Refer to the example below to learn how to use threading to keep Ty running correctly.
Follow that project for a working example of a plugin.