├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── Templates ├── ItemTemplates │ └── C# │ │ ├── Unity Mod BepInEx Plugin Class │ │ ├── MyTemplate.vstemplate │ │ ├── PluginClass1.cs │ │ └── __TemplateIcon.png │ │ ├── Unity Mod Harmony Patch Class │ │ ├── MyTemplate.vstemplate │ │ ├── PatchClass1.cs │ │ └── __TemplateIcon.png │ │ ├── Unity Mod MonoBehaviour Class │ │ ├── MonobehaviourClass1.cs │ │ ├── MyTemplate.vstemplate │ │ └── __TemplateIcon.png │ │ └── Unity Mod Utils Class │ │ ├── MyTemplate.vstemplate │ │ ├── UtilsClass1.cs │ │ └── __TemplateIcon.png └── ProjectTemplates │ └── C# │ └── Unity Mod (BepInEx) │ ├── MONOBEHAVIOURS │ └── MonobehaviourClass1.cs │ ├── MyTemplate.vstemplate │ ├── PATCHES │ └── PatchClass1.cs │ ├── PROPERTIES │ └── AssemblyInfo.cs │ ├── PluginClass1.cs │ ├── UTILS │ └── UtilsClass1.cs │ ├── UnityModTemplate.csproj │ └── __TemplateIcon.png ├── build.bat ├── config.bat ├── deploy.bat └── media ├── monobehaviourclasstemplate.png ├── newitemtemplates.png ├── newprojectemplate.png ├── patchclasstemplate.png ├── pluginclasstemplate.png ├── projecttemplate.png ├── runcommandprompt.png ├── templatefolderstructure.png └── utilsclasstemplate.png /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.zip -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 mroshaw 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity Mod Templates 2 | 3 | A collection of Project and Item templates to speed up the process of creating Unity game mods using the BepInEx patcher and plugin framework. 4 | 5 | I have created a [full video guide to downloading, installing, and using the templates](https://youtu.be/KopYonyplXs). You can find that and more mod related videos on my [Daft Apple Games YouTube channe](https://www.youtube.com/channel/UCp_VeVuW3yY7DjRTC9ZH7jQ)l. 6 | 7 | ## Overview 8 | 9 | The template pack comes with the following: 10 | 11 | ### Unity Mod Project Template 12 | 13 | The project template contains a suggested folder structure, references and boilerplate starter classes for a new BepInEx based Unity mod. 14 | 15 | ![](https://github.com/mroshaw/UnityModVSTemplate/blob/main/media/newprojectemplate.png?raw=true) 16 | 17 | ![](https://github.com/mroshaw/UnityModVSTemplate/blob/main/media/projecttemplate.png?raw=true) 18 | 19 | ### Item Templates 20 | 21 | Four item templates are included that provide boiler plate code for a number of core mod class types, that you might want to add to your project. 22 | 23 | ![](https://github.com/mroshaw/UnityModVSTemplate/blob/main/media/newitemtemplates.png?raw=true) 24 | 25 | #### BepInEx Plugin Class Item Template 26 | 27 | This contains a suggested structure for a "plugin" class for use with the BepInEx framework. 28 | 29 | ![](https://github.com/mroshaw/UnityModVSTemplate/blob/main/media/pluginclasstemplate.png?raw=true) 30 | 31 | #### MonoBehaviour Class Item Template 32 | 33 | This contains a suggested structure for a "monobehaviour" class, for introducing new components and behaviours. 34 | 35 | ![](https://github.com/mroshaw/UnityModVSTemplate/blob/main/media/monobehaviourclasstemplate.png?raw=true) 36 | 37 | #### Static Utils Class Item Template 38 | 39 | This contains a suggested structure for a static "utils" class, for creating static helper methods. 40 | 41 | ![](https://github.com/mroshaw/UnityModVSTemplate/blob/main/media/utilsclasstemplate.png?raw=true) 42 | 43 | #### Harmony Patch Class Item Template 44 | 45 | This contains a suggested structure for a "patch" class, for building Harmony patch classes and methods. 46 | 47 | ![](https://github.com/mroshaw/UnityModVSTemplate/blob/main/media/patchclasstemplate.png?raw=true) 48 | 49 | ## Installation 50 | 51 | The template pack comes as a single ZIP file and the latest version for you to use can be found here under [Releases](https://github.com/mroshaw/UnityModVSTemplate/releases). 52 | 53 | To install the latest release: 54 | 55 | 1. Unzip the download file to a location on your machine. 56 | 57 | 2. You should have a folder structure as follows: 58 | 59 | ![](https://github.com/mroshaw/UnityModVSTemplate/blob/main/media/templatefolderstructure.png?raw=true) 60 | 61 | 3. In Windows Explorer, navigate to this location. Note that the physical location of "Documents" may change depending on a number of factors, including whether or not you have OneDrive installed: 62 | 63 | ```Documents\Visual Studio 2022\``` 64 | 65 | 4. Copy the unzipped Templates folder into the Visual Studio 2022 folder on top of the existing Templates folder. This will add the appropriate ZIP files to the Visual Studio template folder. 66 | 67 | 5. Restart Visual Studio. 68 | 69 | The templates should now be available for use. 70 | 71 | ## Usage 72 | 73 | Once you've installed the templates, you can create a new project using the Project template. 74 | 75 | 1. Create a new project by selecting the "Unity Mod (BepInEx)" project template. 76 | 2. Enter a name for the new project. This name will be used in both the default plugin class and in the default namespace for the project. 77 | 3. Click create. 78 | 4. The project structure will be created with boilerplate code class files in place for your to amend. 79 | 80 | ### IMPORTANT - Configuring the new project 81 | 82 | There are a number of things you must now change to suit your needs. It is VERY IMPORTANT that you do this, or your mod will not compile or deploy properly, and may behave in ways you do not expect. 83 | 84 | You need to review and amend the following: 85 | 86 | #### References 87 | 88 | You will need to modify the following references to point to your installed game location: 89 | 90 | - 0Harmony 91 | - Assembly-CSharp-firstpass_publicized 92 | - Assembly-CSharp_publicized 93 | - BepInEx 94 | - UnityEngine 95 | - UnityEngine.CoreModule 96 | 97 | #### Post-build scripts 98 | 99 | Review and edit the post-build scripts to include the path to your target game BepInEx plugin folder. 100 | 101 | #### Boilerplate code 102 | 103 | Review and edit the boilerplate code to your needs. Review, remove, or update the following: 104 | 105 | - Plugin.cs 106 | - Patches\\PlayerPatches.cs 107 | - MonoBehaviours\\Component.cs 108 | - Utils\ModUtils.cs 109 | 110 | ## Refreshing the Templates 111 | 112 | If you download and apply an update to the templates, you may have to run this process to make the updated templates available in Visual Studio: 113 | 114 | 1. From the Start menu, open Visual Studio 2022, right click Developer Command Prompt for VS2022 and select More > Run as administrator: 115 | 116 | ![](https://github.com/mroshaw/UnityModVSTemplate/blob/main/media/runcommandprompt.png?raw=true) 117 | 118 | 2. Enter and execute the following command: 119 | 120 | ``` 121 | devenv /installvstemplates 122 | devenv /updateconfiguration 123 | ``` 124 | 125 | 3. Restart Visual Studio. 126 | 127 | The updated templates should now be available for use. 128 | 129 | ## Building the Templates 130 | 131 | All source is available in the Templates folder. To build and deploy changes to the templates, you can use the included batch files. 132 | 133 | 1. Amend ```config.bat``` and set the path to 7-zip, Visual Studio Documents folder and the Visual Studio IDE folder. You need to set all of these parameters correctly. Do not include double quotes and do not include trailing slash characters on folder paths. For example: 134 | 135 | ``` 136 | set zip=C:\Program Files\7-Zip\7z.exe 137 | set vsdocs=C:\Users\MyUser\Documents\Visual Studio 2022 138 | set vsbin=C:\Program Files\Microsoft Visual Studio\VS2022\Community\Common7\IDE 139 | ``` 140 | 2. Run ```build.bat``` to build a new release ZIP in the Releases folder. 141 | 3. Run ```build.bat Y``` to build and deploy to your local Visual Studio installation. 142 | 143 | A ZIP file for release and deployment can be found in the Releases folder, postfixed with the build date and time. -------------------------------------------------------------------------------- /Templates/ItemTemplates/C#/Unity Mod BepInEx Plugin Class/MyTemplate.vstemplate: -------------------------------------------------------------------------------- 1 | 2 | 3 | PluginClass.cs 4 | Unity Mod BepInEx Plugin Class 5 | A Unity mod template for new BepInEx Plugin classes. 6 | CSharp 7 | 10 8 | __TemplateIcon.png 9 | 10 | 11 | 12 | 13 | Assembly-CSharp_publicized 14 | 15 | 16 | Assembly-CSharp-firstpass_publicized 17 | 18 | 19 | BepInEx 20 | 21 | 22 | 0Harmony 23 | 24 | 25 | PluginClass1.cs 26 | 27 | -------------------------------------------------------------------------------- /Templates/ItemTemplates/C#/Unity Mod BepInEx Plugin Class/PluginClass1.cs: -------------------------------------------------------------------------------- 1 | using BepInEx; 2 | using BepInEx.Configuration; 3 | using BepInEx.Logging; 4 | using HarmonyLib; 5 | using UnityEngine; 6 | 7 | namespace $rootnamespace$ 8 | { 9 | // TODO Review this file and update to your own requirements. 10 | 11 | [BepInPlugin(MyGUID, PluginName, VersionString)] 12 | public class $safeitemname$ : BaseUnityPlugin 13 | { 14 | // Mod specific details. MyGUID should be unique, and follow the reverse domain pattern 15 | // e.g. 16 | // com.mynameororg.pluginname 17 | // Version should be a valid version string. 18 | // e.g. 19 | // 1.0.0 20 | private const string MyGUID = "MYGUID"; 21 | private const string PluginName = "PLUGINNAME"; 22 | private const string VersionString = "1.0.0"; 23 | 24 | // Config entry key strings 25 | // These will appear in the config file created by BepInEx and can also be used 26 | // by the OnSettingsChange event to determine which setting has changed. 27 | public static string FloatExampleKey = "Float Example Key"; 28 | public static string IntExampleKey = "Int Example Key"; 29 | public static string KeyboardShortcutExampleKey = "Recall Keyboard Shortcut"; 30 | 31 | // Configuration entries. Static, so can be accessed directly elsewhere in code via 32 | // e.g. 33 | // float myFloat = PLUGINCLASS.FloatExample.Value; 34 | // TODO Change this code or remove the code if not required. 35 | public static ConfigEntry FloatExample; 36 | public static ConfigEntry IntExample; 37 | public static ConfigEntry KeyboardShortcutExample; 38 | 39 | private static readonly Harmony Harmony = new Harmony(MyGUID); 40 | public static ManualLogSource Log = new ManualLogSource(PluginName); 41 | 42 | /// 43 | /// Initialise the configuration settings and patch methods 44 | /// 45 | private void Awake() 46 | { 47 | // Float configuration setting example 48 | // TODO Change this code or remove the code if not required. 49 | FloatExample = Config.Bind("General", // The section under which the option is shown 50 | FloatExampleKey, // The key of the configuration option 51 | 1.0f, // The default value 52 | new ConfigDescription("Example float configuration setting.", // Description that appears in Configuration Manager 53 | new AcceptableValueRange(0.0f, 10.0f))); // Acceptable range, enabled slider and validation in Configuration Manager 54 | 55 | // Int setting example 56 | // TODO Change this code or remove the code if not required. 57 | IntExample = Config.Bind("General", 58 | IntExampleKey, 59 | 1, 60 | new ConfigDescription("Example int configuration setting.", 61 | new AcceptableValueRange(0, 10))); 62 | 63 | // Keyboard shortcut setting example 64 | // TODO Change this code or remove the code if not required. 65 | KeyboardShortcutExample = Config.Bind("General", 66 | KeyboardShortcutExampleKey, 67 | new KeyboardShortcut(KeyCode.A, KeyCode.LeftControl)); 68 | 69 | // Add listeners methods to run if and when settings are changed by the player. 70 | // TODO Change this code or remove the code if not required. 71 | FloatExample.SettingChanged += ConfigSettingChanged; 72 | IntExample.SettingChanged += ConfigSettingChanged; 73 | KeyboardShortcutExample.SettingChanged += ConfigSettingChanged; 74 | 75 | // Apply all of our patches 76 | Harmony.PatchAll(); 77 | Logger.LogInfo($"PluginName: {PluginName}, VersionString: {VersionString} is loaded."); 78 | 79 | // Sets up our static Log, so it can be used elsewhere in code. 80 | // .e.g. 81 | // PLUGINCLASS.Log.LogDebug("Debug Message to BepInEx log file"); 82 | Log = Logger; 83 | } 84 | 85 | /// 86 | /// Method to handle changes to configuration made by the player 87 | /// 88 | /// 89 | /// 90 | private void ConfigSettingChanged(object sender, System.EventArgs e) 91 | { 92 | SettingChangedEventArgs settingChangedEventArgs = e as SettingChangedEventArgs; 93 | 94 | // Check if null and return 95 | if (settingChangedEventArgs == null) 96 | { 97 | return; 98 | } 99 | 100 | // Example Float Shortcut setting changed handler 101 | if (settingChangedEventArgs.ChangedSetting.Definition.Key == FloatExampleKey) 102 | { 103 | // TODO - Add your code here or remove this section if not required. 104 | // Code here to do something with the new value 105 | } 106 | 107 | // Example Int Shortcut setting changed handler 108 | if (settingChangedEventArgs.ChangedSetting.Definition.Key == IntExampleKey) 109 | { 110 | // TODO - Add your code here or remove this section if not required. 111 | // Code here to do something with the new value 112 | } 113 | 114 | // Example Keyboard Shortcut setting changed handler 115 | if (settingChangedEventArgs.ChangedSetting.Definition.Key == KeyboardShortcutExampleKey) 116 | { 117 | KeyboardShortcut newValue = (KeyboardShortcut)settingChangedEventArgs.ChangedSetting.BoxedValue; 118 | 119 | // TODO - Add your code here or remove this section if not required. 120 | // Code here to do something with the new value 121 | } 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Templates/ItemTemplates/C#/Unity Mod BepInEx Plugin Class/__TemplateIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/Templates/ItemTemplates/C#/Unity Mod BepInEx Plugin Class/__TemplateIcon.png -------------------------------------------------------------------------------- /Templates/ItemTemplates/C#/Unity Mod Harmony Patch Class/MyTemplate.vstemplate: -------------------------------------------------------------------------------- 1 | 2 | 3 | PatchClass.cs 4 | Unity Mod Harmony Patch Class 5 | A Unity mod template for new Harmony Patch classes. 6 | CSharp 7 | 10 8 | __TemplateIcon.png 9 | 10 | 11 | 12 | 13 | Assembly-CSharp_publicized 14 | 15 | 16 | Assembly-CSharp-firstpass_publicized 17 | 18 | 19 | BepInEx 20 | 21 | 22 | 0Harmony 23 | 24 | 25 | UnityEngine.CoreModule 26 | 27 | 28 | UnityEngine 29 | 30 | 31 | PatchClass1.cs 32 | 33 | -------------------------------------------------------------------------------- /Templates/ItemTemplates/C#/Unity Mod Harmony Patch Class/PatchClass1.cs: -------------------------------------------------------------------------------- 1 | using HarmonyLib; 2 | 3 | namespace $rootnamespace$ 4 | { 5 | // TODO Review this file and update to your own requirements, or remove it altogether if not required 6 | 7 | /// 8 | /// Sample Harmony Patch class. Suggestion is to use one file per patched class 9 | /// though you can include multiple patch classes in one file. 10 | /// Below is included as an example, and should be replaced by classes and methods 11 | /// for your mod. 12 | /// 13 | [HarmonyPatch(typeof(Player))] 14 | internal class $safeitemname$ 15 | { 16 | /// 17 | /// Patches the Player Awake method with prefix code. 18 | /// 19 | /// 20 | [HarmonyPatch(nameof(Player.Awake))] 21 | [HarmonyPrefix] 22 | public static bool Awake_Prefix(Player __instance) 23 | { 24 | PluginClass1.Log.LogDebug("In Player Awake method Prefix."); 25 | return true; 26 | } 27 | 28 | /// 29 | /// Patches the Player Awake method with postfix code. 30 | /// 31 | /// 32 | [HarmonyPatch(nameof(Player.Awake))] 33 | [HarmonyPostfix] 34 | public static void Awake_Postfix(Player __instance) 35 | { 36 | PluginClass1.Log.LogDebug("In Player Awake method Postfix."); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Templates/ItemTemplates/C#/Unity Mod Harmony Patch Class/__TemplateIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/Templates/ItemTemplates/C#/Unity Mod Harmony Patch Class/__TemplateIcon.png -------------------------------------------------------------------------------- /Templates/ItemTemplates/C#/Unity Mod MonoBehaviour Class/MonobehaviourClass1.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace $rootnamespace$ 4 | { 5 | // TODO Review this file and update to your own requirements, or remove it altogether if not required 6 | /// 7 | /// Template MonoBehaviour class. Use this to add new functionality and behaviours to 8 | /// the game. 9 | /// 10 | internal class $safeitemname$ : MonoBehaviour 11 | { 12 | /// 13 | /// Unity Awake method. 14 | /// 15 | public void Awake() 16 | { 17 | 18 | } 19 | 20 | /// 21 | /// Unity Start method 22 | /// 23 | public void Start() 24 | { 25 | 26 | } 27 | 28 | /// 29 | /// Unity Awake method. Runs every frame so remove this if not required. 30 | /// Runs frequently, so remove if not required. 31 | /// 32 | public void Update() 33 | { 34 | 35 | } 36 | 37 | /// 38 | /// Unity Physics Update (LateUpdate) method. 39 | /// Runs frequently, so remove if not required. 40 | /// 41 | public void LateUpdate() 42 | { 43 | 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Templates/ItemTemplates/C#/Unity Mod MonoBehaviour Class/MyTemplate.vstemplate: -------------------------------------------------------------------------------- 1 | 2 | 3 | MonoBehaviourClass.cs 4 | Unity Mod MonoBehaviour Class 5 | A Unity mod template for new MonoBehaviour classes. 6 | CSharp 7 | 10 8 | __TemplateIcon.png 9 | 10 | 11 | 12 | 13 | Assembly-CSharp_publicized 14 | 15 | 16 | Assembly-CSharp-firstpass_publicized 17 | 18 | 19 | UnityEngine.CoreModule 20 | 21 | 22 | UnityEngine 23 | 24 | 25 | MonobehaviourClass1.cs 26 | 27 | -------------------------------------------------------------------------------- /Templates/ItemTemplates/C#/Unity Mod MonoBehaviour Class/__TemplateIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/Templates/ItemTemplates/C#/Unity Mod MonoBehaviour Class/__TemplateIcon.png -------------------------------------------------------------------------------- /Templates/ItemTemplates/C#/Unity Mod Utils Class/MyTemplate.vstemplate: -------------------------------------------------------------------------------- 1 | 2 | 3 | UtilsClass.cs 4 | Unity Mod Utils Class 5 | A Unity mod template for new Utils classes. 6 | CSharp 7 | 10 8 | __TemplateIcon.png 9 | 10 | 11 | 12 | 13 | Assembly-CSharp_publicized 14 | 15 | 16 | Assembly-CSharp-firstpass_publicized 17 | 18 | 19 | UnityEngine.CoreModule 20 | 21 | 22 | UnityEngine 23 | 24 | 25 | UtilsClass1.cs 26 | 27 | -------------------------------------------------------------------------------- /Templates/ItemTemplates/C#/Unity Mod Utils Class/UtilsClass1.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace $rootnamespace$ 4 | { 5 | /// 6 | /// Static utilities class for common functions and properties to be used within your mod code 7 | /// 8 | internal static class $safeitemname$ 9 | { 10 | /// 11 | /// Example static method to return Players current location / transform 12 | /// 13 | /// 14 | public static Transform GetPlayerTransform() 15 | { 16 | return Player.main.transform; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Templates/ItemTemplates/C#/Unity Mod Utils Class/__TemplateIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/Templates/ItemTemplates/C#/Unity Mod Utils Class/__TemplateIcon.png -------------------------------------------------------------------------------- /Templates/ProjectTemplates/C#/Unity Mod (BepInEx)/MONOBEHAVIOURS/MonobehaviourClass1.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace $safeprojectname$.MonoBehaviours 4 | { 5 | // TODO Review this file and update to your own requirements, or remove it altogether if not required 6 | /// 7 | /// Template MonoBehaviour class. Use this to add new functionality and behaviours to 8 | /// the game. 9 | /// 10 | internal class $safeprojectname$Component : MonoBehaviour 11 | { 12 | /// 13 | /// Unity Awake method. 14 | /// 15 | public void Awake() 16 | { 17 | 18 | } 19 | 20 | /// 21 | /// Unity Start method 22 | /// 23 | public void Start() 24 | { 25 | 26 | } 27 | 28 | /// 29 | /// Unity Awake method. Runs every frame so remove this if not required. 30 | /// Runs frequently, so remove if not required. 31 | /// 32 | public void Update() 33 | { 34 | 35 | } 36 | 37 | /// 38 | /// Unity Physics Update (LateUpdate) method. 39 | /// Runs frequently, so remove if not required. 40 | /// 41 | public void LateUpdate() 42 | { 43 | 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Templates/ProjectTemplates/C#/Unity Mod (BepInEx)/MyTemplate.vstemplate: -------------------------------------------------------------------------------- 1 | 2 | 3 | Unity Mod (BepInEx) 4 | A Visual Studio template for creating a BepInEx mod for Unity games 5 | CSharp 6 | 7 | 8 | 1000 9 | true 10 | MyUnityGameMod 11 | true 12 | Enabled 13 | true 14 | __TemplateIcon.png 15 | CSharp 16 | Windows 17 | Library 18 | 19 | 20 | 21 | 22 | MonobehaviourClass1.cs 23 | 24 | 25 | PatchClass1.cs 26 | 27 | PluginClass1.cs 28 | 29 | AssemblyInfo.cs 30 | 31 | 32 | UtilsClass1.cs 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Templates/ProjectTemplates/C#/Unity Mod (BepInEx)/PATCHES/PatchClass1.cs: -------------------------------------------------------------------------------- 1 | using HarmonyLib; 2 | 3 | namespace $safeprojectname$.Patches 4 | { 5 | // TODO Review this file and update to your own requirements, or remove it altogether if not required 6 | 7 | /// 8 | /// Sample Harmony Patch class. Suggestion is to use one file per patched class 9 | /// though you can include multiple patch classes in one file. 10 | /// Below is included as an example, and should be replaced by classes and methods 11 | /// for your mod. 12 | /// 13 | [HarmonyPatch(typeof(Player))] 14 | internal class PlayerPatches 15 | { 16 | /// 17 | /// Patches the Player Awake method with prefix code. 18 | /// 19 | /// 20 | [HarmonyPatch(nameof(Player.Awake))] 21 | [HarmonyPrefix] 22 | public static bool Awake_Prefix(Player __instance) 23 | { 24 | $safeprojectname$Plugin.Log.LogInfo("In Player Awake method Prefix."); 25 | return true; 26 | } 27 | 28 | /// 29 | /// Patches the Player Awake method with postfix code. 30 | /// 31 | /// 32 | [HarmonyPatch(nameof(Player.Awake))] 33 | [HarmonyPostfix] 34 | public static void Awake_Postfix(Player __instance) 35 | { 36 | $safeprojectname$Plugin.Log.LogInfo("In Player Awake method Postfix."); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Templates/ProjectTemplates/C#/Unity Mod (BepInEx)/PROPERTIES/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("$safeprojectname$")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("$safeprojectname$")] 13 | [assembly: AssemblyCopyright("Copyright © 2023")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("$guid1$")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Templates/ProjectTemplates/C#/Unity Mod (BepInEx)/PluginClass1.cs: -------------------------------------------------------------------------------- 1 | using BepInEx; 2 | using BepInEx.Configuration; 3 | using BepInEx.Logging; 4 | using HarmonyLib; 5 | using UnityEngine; 6 | 7 | namespace $safeprojectname$ 8 | { 9 | // TODO Review this file and update to your own requirements. 10 | 11 | [BepInPlugin(MyGUID, PluginName, VersionString)] 12 | public class $safeprojectname$Plugin : BaseUnityPlugin 13 | { 14 | // Mod specific details. MyGUID should be unique, and follow the reverse domain pattern 15 | // e.g. 16 | // com.mynameororg.pluginname 17 | // Version should be a valid version string. 18 | // e.g. 19 | // 1.0.0 20 | private const string MyGUID = "com.$username$.$safeprojectname$"; 21 | private const string PluginName = "$safeprojectname$"; 22 | private const string VersionString = "1.0.0"; 23 | 24 | // Config entry key strings 25 | // These will appear in the config file created by BepInEx and can also be used 26 | // by the OnSettingsChange event to determine which setting has changed. 27 | public static string FloatExampleKey = "Float Example Key"; 28 | public static string IntExampleKey = "Int Example Key"; 29 | public static string KeyboardShortcutExampleKey = "Recall Keyboard Shortcut"; 30 | 31 | // Configuration entries. Static, so can be accessed directly elsewhere in code via 32 | // e.g. 33 | // float myFloat = $safeprojectname$Plugin.FloatExample.Value; 34 | // TODO Change this code or remove the code if not required. 35 | public static ConfigEntry FloatExample; 36 | public static ConfigEntry IntExample; 37 | public static ConfigEntry KeyboardShortcutExample; 38 | 39 | private static readonly Harmony Harmony = new Harmony(MyGUID); 40 | public static ManualLogSource Log = new ManualLogSource(PluginName); 41 | 42 | /// 43 | /// Initialise the configuration settings and patch methods 44 | /// 45 | private void Awake() 46 | { 47 | // Float configuration setting example 48 | // TODO Change this code or remove the code if not required. 49 | FloatExample = Config.Bind("General", // The section under which the option is shown 50 | FloatExampleKey, // The key of the configuration option 51 | 1.0f, // The default value 52 | new ConfigDescription("Example float configuration setting.", // Description that appears in Configuration Manager 53 | new AcceptableValueRange(0.0f, 10.0f))); // Acceptable range, enabled slider and validation in Configuration Manager 54 | 55 | // Int setting example 56 | // TODO Change this code or remove the code if not required. 57 | IntExample = Config.Bind("General", 58 | IntExampleKey, 59 | 1, 60 | new ConfigDescription("Example int configuration setting.", 61 | new AcceptableValueRange(0, 10))); 62 | 63 | // Keyboard shortcut setting example 64 | // TODO Change this code or remove the code if not required. 65 | KeyboardShortcutExample = Config.Bind("General", 66 | KeyboardShortcutExampleKey, 67 | new KeyboardShortcut(KeyCode.A, KeyCode.LeftControl)); 68 | 69 | // Add listeners methods to run if and when settings are changed by the player. 70 | // TODO Change this code or remove the code if not required. 71 | FloatExample.SettingChanged += ConfigSettingChanged; 72 | IntExample.SettingChanged += ConfigSettingChanged; 73 | KeyboardShortcutExample.SettingChanged += ConfigSettingChanged; 74 | 75 | // Apply all of our patches 76 | Logger.LogInfo($"PluginName: {PluginName}, VersionString: {VersionString} is loading..."); 77 | Harmony.PatchAll(); 78 | Logger.LogInfo($"PluginName: {PluginName}, VersionString: {VersionString} is loaded."); 79 | 80 | // Sets up our static Log, so it can be used elsewhere in code. 81 | // .e.g. 82 | // $safeprojectname$Plugin.Log.LogDebug("Debug Message to BepInEx log file"); 83 | Log = Logger; 84 | } 85 | 86 | /// 87 | /// Code executed every frame. See below for an example use case 88 | /// to detect keypress via custom configuration. 89 | /// 90 | // TODO - Add your code here or remove this section if not required. 91 | private void Update() 92 | { 93 | if ($safeprojectname$Plugin.KeyboardShortcutExample.Value.IsDown()) 94 | { 95 | // Code here to do something on keypress 96 | Logger.LogInfo("Keypress detected!"); 97 | } 98 | } 99 | 100 | /// 101 | /// Method to handle changes to configuration made by the player 102 | /// 103 | /// 104 | /// 105 | private void ConfigSettingChanged(object sender, System.EventArgs e) 106 | { 107 | SettingChangedEventArgs settingChangedEventArgs = e as SettingChangedEventArgs; 108 | 109 | // Check if null and return 110 | if (settingChangedEventArgs == null) 111 | { 112 | return; 113 | } 114 | 115 | // Example Float Shortcut setting changed handler 116 | if (settingChangedEventArgs.ChangedSetting.Definition.Key == FloatExampleKey) 117 | { 118 | // TODO - Add your code here or remove this section if not required. 119 | // Code here to do something with the new value 120 | } 121 | 122 | // Example Int Shortcut setting changed handler 123 | if (settingChangedEventArgs.ChangedSetting.Definition.Key == IntExampleKey) 124 | { 125 | // TODO - Add your code here or remove this section if not required. 126 | // Code here to do something with the new value 127 | } 128 | 129 | // Example Keyboard Shortcut setting changed handler 130 | if (settingChangedEventArgs.ChangedSetting.Definition.Key == KeyboardShortcutExampleKey) 131 | { 132 | KeyboardShortcut newValue = (KeyboardShortcut)settingChangedEventArgs.ChangedSetting.BoxedValue; 133 | 134 | // TODO - Add your code here or remove this section if not required. 135 | // Code here to do something with the new value 136 | } 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /Templates/ProjectTemplates/C#/Unity Mod (BepInEx)/UTILS/UtilsClass1.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace $safeprojectname$.Utils 4 | { 5 | /// 6 | /// Static utilities class for common functions and properties to be used within your mod code 7 | /// 8 | internal static class ModUtils 9 | { 10 | /// 11 | /// Example static method to return Players current location / transform 12 | /// 13 | /// 14 | public static Transform GetPlayerTransform() 15 | { 16 | return Player.main.transform; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Templates/ProjectTemplates/C#/Unity Mod (BepInEx)/UnityModTemplate.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {$guid1$} 8 | Library 9 | Properties 10 | $safeprojectname$ 11 | $safeprojectname$ 12 | v4.7.2 13 | 512 14 | true 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | mkdir "E:\Games\Steam\steamapps\common\SubnauticaZero\BepInEx\plugins\$(TargetName)" 66 | xcopy /q/y/i "$(TargetPath)" "E:\Games\Steam\steamapps\common\SubnauticaZero\BepInEx\plugins\$(TargetName)" /E /H /C 67 | 68 | -------------------------------------------------------------------------------- /Templates/ProjectTemplates/C#/Unity Mod (BepInEx)/__TemplateIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/Templates/ProjectTemplates/C#/Unity Mod (BepInEx)/__TemplateIcon.png -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | call .\config.bat 3 | if %configstatus%==ERR goto builderror 4 | For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%b-%%a) 5 | For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b) 6 | @echo Clearing build folder... 7 | del .\Build\*.* /Q /F /S >NUL 8 | @echo Building ZIPs... 9 | @echo MonoBehaviour Template... 10 | "%zip%" a ".\Build\Templates\ItemTemplates\C#\Unity Mod MonoBehaviour Class.zip" ".\Templates\ItemTemplates\C#\Unity Mod MonoBehaviour Class\*.*" >NUL 11 | @echo Plugin Template... 12 | "%zip%" a ".\Build\Templates\ItemTemplates\C#\Unity Mod BepInEx Plugin Class.zip" ".\Templates\ItemTemplates\C#\Unity Mod BepInEx Plugin Class\*.*" >NUL 13 | @echo Utils Template... 14 | "%zip%" a ".\Build\Templates\ItemTemplates\C#\Unity Mod Utils Class.zip" ".\Templates\ItemTemplates\C#\Unity Mod Utils Class\*.*" >NUL 15 | @echo Patch Template... 16 | "%zip%" a ".\Build\Templates\ItemTemplates\C#\Unity Mod Harmony Patch Class.zip" ".\Templates\ItemTemplates\C#\Unity Mod Harmony Patch Class\*.*" >NUL 17 | @echo Project Template... 18 | "%zip%" a -r ".\Build\Templates\ProjectTemplates\C#\Unity Mod (BepInEx).zip" ".\Templates\ProjectTemplates\C#\Unity Mod (BepInEx)\*.*" >NUL 19 | @echo ZIP final file... 20 | "%zip%" a ".\Release\UnityModTemplateRelease_%mydate%_%mytime%.zip" ".\Build\Templates" >NUL 21 | @echo Clearing build folder... 22 | del .\Build\*.* /Q /F /S >NUL 23 | @echo Done! 24 | if %1.==. goto builddone 25 | @echo Deploying... 26 | call deploy.bat ".\Release\UnityModTemplateRelease_%mydate%_%mytime%.zip" 27 | @echo All done! 28 | goto builddone 29 | :builderror 30 | @echo Build failed. Check for errors above. 31 | :builddone -------------------------------------------------------------------------------- /config.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem 3 | rem Do NOT include double quotes or trailing slash in paths 4 | rem e.g. good example: 5 | rem set vsdocs=C:\Users\myuser\OneDrive\Documents\Visual Studio 2022 6 | rem 7 | set zip= 8 | set vsdocs= 9 | set vsbin= 10 | rem 11 | if "%zip%"=="" goto configerror 12 | if "%vsdocs%"=="" goto configerror 13 | if "%vsbin%"=="" goto configerror 14 | @echo Expecting 7-Zip at: "%zip%" 15 | @echo Expecting Visual Studio Documents folder at: "%vsdocs%" 16 | @echo Expecting Visual Studio Bin folder at: "%vsbin%" 17 | set configstatus=OK 18 | goto configdone 19 | :configerror 20 | @echo Please check config.bat and set configuration parameters 21 | set configstatus=ERR 22 | :configdone 23 | -------------------------------------------------------------------------------- /deploy.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | if %1.==. goto deployusage 3 | call .\config.bat 4 | if %configstatus%==ERR goto deployerror 5 | @echo Create temp folder... 6 | rmdir %TEMP%\UnityModTemplatesTemp /S /Q 7 | mkdir %TEMP%\UnityModTemplatesTemp 8 | @echo Unzipping to temp... 9 | "%zip%" x %1 -o%TEMP%\UnityModTemplatesTemp >NUL 10 | @echo Copying templates to VS docs folder... 11 | xcopy %TEMP%\UnityModTemplatesTemp\Templates "%vsdocs%\Templates" /E /Y >NUL 12 | @echo Delete temp folder 13 | rem rmdir %TEMP%\UnityModTemplatesTemp /S /Q 14 | @echo Refresh Visual Studio template cache... 15 | "%vsbin%\devenv.exe" /installvstemplates 16 | "%vsbin%\devenv.exe" /updateconfiguration 17 | @echo Done! 18 | goto deploydone 19 | :deployusage 20 | @echo No ZIP file provided to deploy. 21 | goto deploydone 22 | :deployerror 23 | Deploy failed. Check for errors above. 24 | :deploydone 25 | -------------------------------------------------------------------------------- /media/monobehaviourclasstemplate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/media/monobehaviourclasstemplate.png -------------------------------------------------------------------------------- /media/newitemtemplates.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/media/newitemtemplates.png -------------------------------------------------------------------------------- /media/newprojectemplate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/media/newprojectemplate.png -------------------------------------------------------------------------------- /media/patchclasstemplate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/media/patchclasstemplate.png -------------------------------------------------------------------------------- /media/pluginclasstemplate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/media/pluginclasstemplate.png -------------------------------------------------------------------------------- /media/projecttemplate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/media/projecttemplate.png -------------------------------------------------------------------------------- /media/runcommandprompt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/media/runcommandprompt.png -------------------------------------------------------------------------------- /media/templatefolderstructure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/media/templatefolderstructure.png -------------------------------------------------------------------------------- /media/utilsclasstemplate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mroshaw/UnityModVSTemplate/ed9dbca1748c74f88905b69d70e389eb33095891/media/utilsclasstemplate.png --------------------------------------------------------------------------------