Skip to content
Dan Gerendasy edited this page Feb 9, 2017 · 2 revisions

Contents


What

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

  • 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.

New Project

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.

Project Setup

In order to get debugging to work correctly you've got to do a few things.

  1. Consider making a copy of your Ty installation just for testing purposes
  2. Set the TY_1_DIR system environment variable to the path of that copy (or the original Ty installation)
  3. Install the Mod Manager
  4. 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.

  1. Right-click Resource Files and select Add -> New Item... -> Visual C++ -> Web -> XML File
  2. Name the XML file after your Project name
  3. 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.

Debugging

Setting up debugging can greatly help development. To get started, right-click your Project in the Solution Explorer and select Properties.

  1. Ensure the Configuration on the top right is Debug
  2. Under Configuration Properties -> General set the Output Directory to $(TY_1_DIR)Mods\
  3. Under Configuration Properties -> Debugging set the Command to $(TY_1_DIR)TY.exe
  4. Under Configuration Properties -> Debugging set the Working Directory to $(TY_1_DIR)
  5. 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.

Main

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) {
  
}

Exporting Main

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) {
  
}

Arguments

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

Next Steps

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.