Update template

This commit is contained in:
2024-09-27 21:04:18 +02:00
parent 11492b09a9
commit aa64f89781
4 changed files with 47 additions and 105 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*/obj
*/bin
**/.idea

View File

@@ -1,103 +1,40 @@
using System; using System.Linq;
using System.Linq; using MelonLoader;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using HarmonyLib.Tools;
namespace TavernDave { namespace MelonTemplate {
[BepInPlugin(pluginGuid, pluginName, pluginVersion)] public class MelonTemplateMod : MelonMod {
public class Main : BaseUnityPlugin { public override void OnInitializeMelon() {
private const string pluginGuid = "TavernDave"; LoggerInstance.Msg("Phat Melon mod loaded");
private const string pluginName = "TavernDave"; HarmonyLib.Harmony harmony = HarmonyInstance;
private const string pluginVersion = "1.0.0";
public static ConfigEntry<bool> debug;
public static ConfigEntry<float> moneyMultiplier;
public static ConfigEntry<int> fastSpeed;
public static ConfigEntry<float> staffXpMultiplier;
public static ConfigEntry<float> peoplePerMinuteMultiplier;
public static ConfigEntry<float> peoplePerMinuteOffset;
public static ConfigEntry<float> prestigeMultiplier;
public void Awake() {
debug = Config.Bind("General", "Debug", false);
moneyMultiplier = Config.Bind("General", "MoneyMultiplier", 1f);
fastSpeed = Config.Bind("General", "FastSpeed", 1);
staffXpMultiplier = Config.Bind("General", "StaffXpMultiplier", 1f);
peoplePerMinuteMultiplier = Config.Bind("General", "PeoplePerMinuteMultiplier", 1f);
peoplePerMinuteOffset = Config.Bind("General", "PeoplePerMinuteOffset", 0f);
prestigeMultiplier = Config.Bind("General", "PrestigeMultiplier", 1f);
Logger.LogInfo("Cyka mod loaded");
HarmonyFileLog.Enabled = true;
Harmony harmony = new Harmony(pluginGuid);
harmony.PatchAll(); harmony.PatchAll();
var originalMethods = harmony.GetPatchedMethods(); var originalMethods = harmony.GetPatchedMethods();
Logger.LogInfo("Patched " + originalMethods.Count() + " methods"); var methodBases = originalMethods.ToList();
foreach (var method in originalMethods) { LoggerInstance.Msg("Patched " + methodBases.Count() + " methods");
Logger.LogInfo("Patched " + method.Name); foreach (var method in methodBases) {
LoggerInstance.Msg("Patched " + method.Name);
} }
} }
} }
[HarmonyPatch] [HarmonyLib.HarmonyPatch]
public class Patches { public class Patches {
[HarmonyPrefix] // [HarmonyLib.HarmonyPrefix]
[HarmonyPatch(typeof(TavernModel), "ChangeMoney")] // [HarmonyLib.HarmonyPatch(typeof(TavernModel), "ChangeMoney")]
public static void PrefixMoney(ref int value) { // public static void PrefixMoney(ref int value) {
if (Main.debug.Value) // if (Main.debug.Value)
Console.WriteLine($"Money is {value}"); // Console.WriteLine($"Money is {value}");
if (value > 0) { // if (value > 0) {
value = (int)(value * Main.moneyMultiplier.Value); // value = (int)(value * Main.moneyMultiplier.Value);
if (Main.debug.Value) // if (Main.debug.Value)
Console.WriteLine($"Money modified to {value}"); // Console.WriteLine($"Money modified to {value}");
} // }
} // }
[HarmonyPrefix]
[HarmonyPatch(typeof(UiController), "ChangeGameSpeed")]
public static void PrefixSpeed(ref int gameSpeed) {
if (Main.debug.Value)
Console.WriteLine($"Game speed is {gameSpeed}");
if (gameSpeed > 1) {
gameSpeed = Main.fastSpeed.Value;
if (Main.debug.Value)
Console.WriteLine($"Game speed modified to {gameSpeed}");
}
}
[HarmonyPrefix] // [HarmonyLib.HarmonyPostfix]
[HarmonyPatch(typeof(StaffModel), "UpdateXp")] // [HarmonyLib.HarmonyPatch(typeof(TechTreeModel), nameof(TechTreeModel.GetBonusPeoplePerMinute))]
public static void PrefixXp(ref int id, ref int amount) { // public static void PostfixPeoplePerMinute(ref float __result) {
if (Main.debug.Value) // __result *= Main.peoplePerMinuteMultiplier.Value;
Console.WriteLine($"Staff xp is {amount}"); // __result += Main.peoplePerMinuteOffset.Value;
if (amount > 0) { // }
amount = (int)(amount * Main.staffXpMultiplier.Value);
if (Main.debug.Value)
Console.WriteLine($"Staff xp modified to {amount}");
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(TechTreeModel), nameof(TechTreeModel.GetBonusPeoplePerMinute))]
public static void PostfixPeoplePerMinute(ref float __result) {
__result *= Main.peoplePerMinuteMultiplier.Value;
__result += Main.peoplePerMinuteOffset.Value;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(TavernModel), nameof(TavernModel.GetQuality))]
public static void PostfixQuality(ref int __result) {
if (Main.debug.Value)
Console.WriteLine($"Quality is {__result}");
if (__result > 0) {
__result = (int)(__result * Main.prestigeMultiplier.Value);
if (Main.debug.Value)
Console.WriteLine($"Quality modified to {__result}");
}
}
} }
} }

View File

@@ -2,9 +2,10 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
<PropertyGroup> <PropertyGroup>
<GAME_DIR>{foo/bar}</GAME_DIR> <GAME_DIR>C:/Games/Arms Trade Tycoon Tanks</GAME_DIR>
<GAME_MANAGED>$(GAME_DIR)/{foo/bar}/Managed</GAME_MANAGED> <!--<GAME_MANAGED>$(GAME_DIR)/{foo/bar}}/Managed</GAME_MANAGED>-->
<GAME_BEPINEX>$(GAME_DIR)/BepInEx</GAME_BEPINEX> <GAME_MELON>$(GAME_DIR)/MelonLoader</GAME_MELON>
<GAME_MANAGED>$(GAME_MELON)/Il2CppAssemblies</GAME_MANAGED>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DA9D274E-486F-4F82-84FF-CD9388CB0B09}</ProjectGuid> <ProjectGuid>{DA9D274E-486F-4F82-84FF-CD9388CB0B09}</ProjectGuid>
@@ -35,18 +36,15 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="MelonTemplate.cs" /> <Compile Include="MelonTemplate.cs"/>
<Compile Include="Properties\AssemblyInfo.cs"/> <Compile Include="Properties\AssemblyInfo.cs"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="MelonLoader">
<HintPath>$(GAME_MELON)/net6/MelonLoader.dll</HintPath>
</Reference>
<Reference Include="0Harmony"> <Reference Include="0Harmony">
<HintPath>$(GAME_BEPINEX)/core/0Harmony.dll</HintPath> <HintPath>$(GAME_MELON)/net6/0Harmony.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>$(GAME_BEPINEX)/core/BepInEx.dll</HintPath>
</Reference>
<Reference Include="ConfigurationManager">
<HintPath>$(GAME_BEPINEX)/plugins/ConfigurationManager/ConfigurationManager.dll</HintPath>
</Reference> </Reference>
<Reference Include="Assembly-CSharp"> <Reference Include="Assembly-CSharp">
<HintPath>$(GAME_MANAGED)/Assembly-CSharp.dll</HintPath> <HintPath>$(GAME_MANAGED)/Assembly-CSharp.dll</HintPath>

View File

@@ -1,14 +1,18 @@
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using MelonLoader;
using MelonTemplate;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("DaveCEO")] [assembly: MelonInfo(typeof(MelonTemplateMod), "Phat Melon Mod", "1.0.0", "Phat Phuck Dave")]
[assembly: MelonGame("Game Developer", "Game Name")]
[assembly: AssemblyTitle("Phat Melon Mod")]
[assembly: AssemblyProduct("Phat Melon Mod")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DaveCEO")]
[assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]