Skip to content

Latest commit

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

TrainerKit

Sponsor

TrainerKit is an extract of the Feature-system developed for EscapeFromTarkov-Trainer for games compiled with the Mono backend. For the Il2Cpp backend, you can use TrainerKit-Il2Cpp.

TrainerKit simplifies the development of internal Unity trainers by handling:

  • UI rendering of features (everything is done automatically through reflection). Support for Color, Float, Int, String, Bool, KeyCode types.
  • Load/save of settings.
  • Runtime execution of Features.
  • Injection into target process.

Example with Unity's FPS Microgame

Starting with TrainerKit codebase, simply write the following code:

usingTrainerKit.Features;usingTrainerKit.Properties;usingUnity.FPS.Game;namespaceTrainerKit.DemoFPS;internalclassGodMode:ToggleFeature{publicoverridestringName=>Strings.FeatureGodModeName;publicoverridestringDescription=>Strings.FeatureGodModeDescription;protectedoverridevoidUpdateWhenEnabled(){varhealth=Object.FindFirstObjectByType<Health>();health?.Invincible=true;}protectedoverridevoidUpdateWhenDisabled(){varhealth=Object.FindFirstObjectByType<Health>();health?.Invincible= false;}}

and

usingTrainerKit.Configuration;usingTrainerKit.Features;usingTrainerKit.Properties;usingUnity.FPS.Game;usingUnityEngine;namespaceTrainerKit.DemoFPS;internalclassUnlimitedAmmo:ToggleFeature{publicoverridestringName=>Strings.FeatureUnlimitedAmmoName;publicoverridestringDescription=>Strings.FeatureUnlimitedAmmoDescription;[ConfigurationProperty]publicintDemoInt{get;set;}=999;[ConfigurationProperty]publicColorDemoColor{get;set;}=Color.red;[ConfigurationProperty]publicstringDemoText{get;set;}="Text";[ConfigurationProperty]publicKeyCodeDemoKey{get;set;}=KeyCode.Alpha0;[ConfigurationProperty]publicfloatDemoFloat{get;set;}=3.14f;protectedoverridevoidUpdateWhenEnabled(){varweapon=Object.FindFirstObjectByType<WeaponController>();weapon?.MaxAmmo=int.MaxValue;}protectedoverridevoidUpdateWhenDisabled(){varweapon=Object.FindFirstObjectByType<WeaponController>();weapon?.MaxAmmo=8;}}

and the system will automatically generate the following window after injecting into the target process (use RightAlt by default to display the menu):

TrainerKit Demo

Note that the system displays names like !! [Id] !! because it couldn't find the corresponding entries in the resource file (for example PropertyDemoInt for DemoInt):

Resources

The following configuration file can be automatically generated (and reloaded on next execution):

; Be careful when updating this file :); For keys, use https://docs.unity3d.com/ScriptReference/KeyCode.html; Colors are stored as an array of 'RGBA' floatsTrainerKit.DemoFPS.GodMode.Enabled=true
TrainerKit.DemoFPS.GodMode.Key="None"TrainerKit.DemoFPS.UnlimitedAmmo.Enabled=true
TrainerKit.DemoFPS.UnlimitedAmmo.Key="None"TrainerKit.DemoFPS.UnlimitedAmmo.DemoColor=[1.0,0.0,0.0,1.0]
TrainerKit.DemoFPS.UnlimitedAmmo.DemoFloat=3.14
TrainerKit.DemoFPS.UnlimitedAmmo.DemoInt=999
TrainerKit.DemoFPS.UnlimitedAmmo.DemoKey="Alpha0"TrainerKit.DemoFPS.UnlimitedAmmo.DemoText="Text"TrainerKit.Features.Commands.Key="RightAlt"TrainerKit.Features.Commands.ConsoleColor=[1.0,1.0,1.0,1.0]
TrainerKit.Features.Commands.X=462.0
TrainerKit.Features.Commands.Y=10.0

How to Use

1- Starting from the source code, add the necessary references to the game you want to mod. You need at least:

UnityEngine
UnityEngine.CoreModule
UnityEngine.IMGUIModule
UnityEngine.InputLegacyModule
UnityEngine.TextRenderingModule

2- Write your Features, starting from:

HoldFeature
ToggleFeature
TriggerFeature

Decorate your own properties with ConfigurationPropertyAttribute. This will expose your property to rendering and persistence. You can finetune the behavior by using dedicated settings:

[AttributeUsage(AttributeTargets.Property)]publicclassConfigurationPropertyAttribute:Attribute{// Skip completely (Rendering+Config), useful when overriding propertiespublicboolSkip{get;set;}=false;// Dislay orderpublicintOrder{get;set;}=int.MaxValue;// Link a resource id for generating comment in the ini filepublicstringCommentResourceId{get;set;}=string.Empty;// Enable/Disable renderingpublicboolBrowsable{get;set;}=true;}

3- Compile. If you need extra dependencies, you can either add them in the Managed folder of the target game, or il-merge everything into one unique assembly (we already use ILRepack to add a compatible Newtonsoft.Json assembly).

4- Run the executable, it will handle the injection into the target process (see Program.cs to customize the target):

publicstaticvoidMain(){try{varlocation=Assembly.GetEntryAssembly()!.Location;varbytes=File.ReadAllBytes(location);conststringprocessName="TODO";usingvarinjector=newInjector(processName);varintptr=injector.Inject(bytes,typeof(Context).Namespace,nameof(Context),nameof(Context.Load));Console.WriteLine(Strings.InjectorSuccess,Path.GetFileName(location),processName,injector.Is64Bit?$"0x{intptr.ToInt64():X16}":$"0x{intptr.ToInt32):X8}");}catch(Exceptione){Console.WriteLine(Strings.InjectorFailure,e.Message);}}

Here is the output, but you can still use your preferred Mono injector.

Injected TrainerKit.exe into process FPS: 0x000002B0E9099380

Indeed if we have a look at the TrainerKit.Context.Load method, we can see the registration logic:

publicstaticvoidLoad(){vargo=newGameObject(nameof(Context));UnityEngine.Object.DontDestroyOnLoad(go);FeatureFactory.RegisterAllFeatures(go);varcommands=FeatureFactory.GetFeature<Commands>();if(commands==null)return;AddConsoleLog(Strings.FeatureRendererWelcome+$" ({commands.Key})");}

If you hit any issue while injecting, make sure you are not missing any dependencies.

Trainers using TrainerKit

  • EscapeFromTarkov-Trainer for Escape From Tarkov game. Before switching to IL2CPP.

    • No ILRepacking: specific BepInEx injector, and NewtonSoft.Json types are directly provided by the game assemblies. Compiled for netfx 4.7.1
    • Mono Backend.
    • Using Unity 2022.3.43f1.
  • DiscoElysium-Trainer for Disco Elysium game.

    • Il2Cpp Backend.
    • Using Unity 2020.3.12f1.
  • IronCast-Trainer for IronCast game.

    • No ILRepacking: standalone SharpMonoInjector, and NewtonSoft.Json types are directly provided by the game assemblies.
    • Mono Backend.
    • Using Unity 4.6.1f1, so compiled for netfx 3.5, requiring minor code adaptations.
  • Megabonk-Trainer for Megabonk game.

    • Il2Cpp Backend.
    • Using Unity 2023.2.22f1.
  • MonstersAreComing-Trainer for Monsters Are Coming game.

    • Il2Cpp Backend.
    • New Input System.
    • Using Unity 2022.3.62f2.
  • YAZDHD-Trainer for Yet Another Zombie Defense HD game.

    • ILRepacking to provide SharpMonoInjector as a built-in injector, and NewtonSoft.Json types internalized. Compiled for netfx 4.8.1.
    • Mono Backend.
    • Using Unity 2019.4.13f1.
  • The demo Unity's FPS Microgame used here.

    • With Mono backend, ILRepacking to provide SharpMonoInjector as a built-in injector, and NewtonSoft.Json types internalized. Compiled for netfx 4.8.1.
    • With Il2Cpp backend.
    • Using Unity 2022.3.62f3.

About

TrainerKit simplifies the development of internal Unity trainers using the Mono backend

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages