Browse Source

[ItemLevelExtension] [2.0.2.2] init

Zariteis 4 years ago
parent
commit
d169f80d41

+ 16 - 0
ItemLevelExtension/Core.cs

@@ -0,0 +1,16 @@
+using GadgetCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using UnityEngine;
+
+namespace ItemLevelExtension
+{
+  internal static class Core
+  {
+    public static GadgetLogger logger;
+
+    public static int settingMaxItemLevel = 12;
+  }
+}

+ 27 - 0
ItemLevelExtension/ItemLevelExtension.cs

@@ -0,0 +1,27 @@
+using UnityEngine;
+using GadgetCore.API;
+using GadgetCore.API.ConfigMenu;
+
+namespace ItemLevelExtension
+{
+  [Gadget("ItemLevelExtension")]
+  public class ItemLevelExtension : Gadget<ItemLevelExtension>
+  {
+    public const string MOD_VERSION = "0.1"; // Set this to the version of your mod.
+    public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
+
+    public override IGadgetConfigMenu GetConfigMenu() { return null; }
+
+    public override string GetModDescription()
+    {
+      return "Raises the MAX item level to 100.";
+    }
+
+    protected override void Initialize()
+    {
+      Logger.Log("Item Level Extension v" + Info.Mod.Version);
+      Core.logger = Logger;
+      Core.settingMaxItemLevel = 100;
+    }
+  }
+}

+ 143 - 0
ItemLevelExtension/ItemLevelExtension.csproj

@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project Sdk="Microsoft.NET.Sdk">
+  <ImportGroup>
+    <Import Project="../GamePaths.xml" />
+  </ImportGroup>
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProjectGuid>{91AB81DE-EAEE-47D1-93DD-541179208219}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>ItemLevelExtension</RootNamespace>
+    <AssemblyName>ItemLevelExtension</AssemblyName>
+    <TargetFrameworks>net35</TargetFrameworks>
+    <FileAlignment>512</FileAlignment>
+    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
+    <Configurations>Release</Configurations>
+    <Authors>Zariteis</Authors>
+    <ApplicationIcon />
+    <StartupObject />
+    <Platforms>x86</Platforms>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugType>none</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net35|x86'">
+    <NoWarn>1701;1702</NoWarn>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="0Harmony">
+      <HintPath>$(GamePath)$(ManagedFolder)0Harmony.dll</HintPath>
+      <Private>false</Private>
+    </Reference>
+    <Reference Include="Assembly-CSharp">
+      <HintPath>$(GamePath)$(ManagedFolder)Assembly-CSharp.dll</HintPath>
+      <Private>false</Private>
+    </Reference>
+    <Reference Include="GadgetCore">
+      <HintPath>$(GamePath)$(ManagedFolder)GadgetCore.dll</HintPath>
+      <Private>false</Private>
+    </Reference>
+    <Reference Include="UnityEngine">
+      <HintPath>$(GamePath)$(ManagedFolder)UnityEngine.dll</HintPath>
+      <Private>false</Private>
+    </Reference>
+    <Reference Include="WindowsBase" />
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="ModInfo.txt">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
+  <UsingTask TaskName="GetFileVersion" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
+    <ParameterGroup>
+      <AssemblyPath ParameterType="System.String" Required="true" />
+      <Version ParameterType="System.String" Output="true" />
+      <TrimmedVersion ParameterType="System.String" Output="true" />
+    </ParameterGroup>
+    <Task>
+      <Using Namespace="System.Diagnostics" />
+      <Using Namespace="System.Text" />
+      <Using Namespace="System.Linq" />
+      <Code Type="Fragment" Language="cs">
+        <![CDATA[
+      this.Version = FileVersionInfo.GetVersionInfo(this.AssemblyPath).FileVersion;  
+      this.TrimmedVersion = this.Version.Split('.').TakeWhile(x => !x.Equals("0")).Aggregate(new StringBuilder(), (a, b) => { if (a.Length > 0) a.Append("."); a.Append(b); return a; }).ToString();
+      if (this.TrimmedVersion.IndexOf('.') == -1) this.TrimmedVersion += ".0";
+    ]]>
+      </Code>
+    </Task>
+  </UsingTask>
+  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
+    <GetFileVersion AssemblyPath="$(TargetPath)">
+      <Output TaskParameter="Version" PropertyName="ModFullVersion" />
+      <Output TaskParameter="TrimmedVersion" PropertyName="AssemblyFileVersion" />
+    </GetFileVersion>
+    <ItemGroup>
+      <OldZip Include="$(TargetDir)$(AssemblyName)_v*.zip" />
+      <OldZip Include="$(GamePath)GadgetCore\Mods\$(AssemblyName)_v*.zip" />
+    </ItemGroup>
+    <Delete Files="@(OldZip)" />
+    <MakeDir Directories="$(TargetDir)..\BuildCache\" />
+    <ZipDirectory SourceDirectory="$(TargetDir)" DestinationFile="$(TargetDir)..\BuildCache\$(AssemblyName)_v$(AssemblyFileVersion).zip" />
+    <Copy SourceFiles="$(TargetDir)..\BuildCache\$(AssemblyName)_v$(AssemblyFileVersion).zip" DestinationFiles="$(TargetDir)$(AssemblyName)_v$(AssemblyFileVersion).zip" />
+    <RemoveDir Directories="$(TargetDir)..\BuildCache\" />
+    <MakeDir Directories="$(GamePath)GadgetCore\Mods\" />
+    <Copy SourceFiles="$(TargetDir)$(AssemblyName)_v$(AssemblyFileVersion).zip" DestinationFiles="$(GamePath)GadgetCore\Mods\$(AssemblyName)_v$(AssemblyFileVersion).zip" />
+    <Message Importance="High" Text="Mod Exported to $(GamePath)GadgetCore\Mods\$(AssemblyName)_v$(AssemblyFileVersion).zip" />
+  </Target>
+  <ItemGroup>
+    <None Update="Manifest.ini">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+  <ItemGroup>
+    <Reference Update="System">
+      <Private>false</Private>
+      <SpecificVersion>true</SpecificVersion>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Reference Update="System.Data">
+      <EmbedInteropTypes>false</EmbedInteropTypes>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Reference Update="System.Drawing">
+      <EmbedInteropTypes>false</EmbedInteropTypes>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Reference Update="System.IO.Compression.FileSystem">
+      <EmbedInteropTypes>false</EmbedInteropTypes>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Reference Update="System.Numerics">
+      <EmbedInteropTypes>false</EmbedInteropTypes>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Reference Update="System.Runtime.Serialization">
+      <EmbedInteropTypes>false</EmbedInteropTypes>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Reference Update="System.Xml">
+      <EmbedInteropTypes>false</EmbedInteropTypes>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Reference Update="System.Xml.Linq">
+      <EmbedInteropTypes>false</EmbedInteropTypes>
+    </Reference>
+  </ItemGroup>
+</Project>

+ 3 - 0
ItemLevelExtension/Manifest.ini

@@ -0,0 +1,3 @@
+[Metadata]
+Name=Item Level Extension
+Assembly=ItemLevelExtension.dll

+ 1 - 0
ItemLevelExtension/ModInfo.txt

@@ -0,0 +1 @@
+Raises the MAX item level to 100.

+ 41 - 0
ItemLevelExtension/Patches/Patch_GameScript_GetGearLevel.cs

@@ -0,0 +1,41 @@
+using GadgetCore.API;
+using GadgetCore.Util;
+using HarmonyLib;
+using System;
+using System.Reflection;
+
+namespace ItemLevelExtension.Patches
+{
+
+  [HarmonyPatch(typeof(GadgetCoreAPI))]
+  [HarmonyPatch("GetGearLevel")]
+  [HarmonyGadget("ItemLevelExtension")]
+  public static class Patch_GameScript_GetGearLevel
+	{
+    [HarmonyPrefix]
+    public static bool Prefix(Item item, ref int __result)
+		{
+			int exp = item.exp;
+			int level = 1;
+			int nextLevelPrice = 100;
+			int i = 0;
+			while (exp > nextLevelPrice)
+			{
+				exp -= nextLevelPrice;
+				i++;
+				nextLevelPrice += 75 + i * 100;
+				level++;
+				if (level == Core.settingMaxItemLevel)
+				{
+					break;
+				}
+			}
+
+			if (level > Core.settingMaxItemLevel)
+				level = Core.settingMaxItemLevel;
+
+			__result = level;
+      return false;
+    }
+  }
+}

+ 41 - 0
ItemLevelExtension/Patches/Patch_GameScript_GetItemLevel.cs

@@ -0,0 +1,41 @@
+using GadgetCore.API;
+using GadgetCore.Util;
+using HarmonyLib;
+using System;
+using System.Reflection;
+
+namespace ItemLevelExtension.Patches
+{
+
+  [HarmonyPatch(typeof(GameScript))]
+  [HarmonyPatch("GetItemLevel")]
+  [HarmonyGadget("ItemLevelExtension")]
+  public static class Patch_GameScript_GetItemLevel
+  {
+    [HarmonyPrefix]
+    public static bool Prefix(GameScript __instance, int exp, ref int __result, ref int ___pastCap)
+		{
+			int level = 1;
+			int nextLevelPrice = 100;
+			int i = 0;
+			while (exp > nextLevelPrice)
+			{
+				___pastCap = nextLevelPrice;
+				exp -= nextLevelPrice;
+				i++;
+				nextLevelPrice += 75 + i * 100;
+				level++;
+				if (level == Core.settingMaxItemLevel)
+				{
+					break;
+				}
+			}
+
+			if (level > Core.settingMaxItemLevel)
+				level = Core.settingMaxItemLevel;
+
+			__result = level;
+      return false;
+    }
+  }
+}

+ 46 - 0
ItemLevelExtension/Patches/Patch_GameScript_GetItemLevel2.cs

@@ -0,0 +1,46 @@
+using GadgetCore.API;
+using GadgetCore.Util;
+using HarmonyLib;
+using System;
+using System.Reflection;
+
+namespace ItemLevelExtension.Patches
+{
+
+  [HarmonyPatch(typeof(GameScript))]
+  [HarmonyPatch("GetItemLevel2")]
+  [HarmonyGadget("ItemLevelExtension")]
+  public static class Patch_GameScript_GetItemLevel2
+  {
+    [HarmonyPrefix]
+    public static bool Prefix(GameScript __instance, int exp, ref float[] __result)
+    {
+      int level = 1;
+      int nextLevelPrice = 100;
+      int i = 0;
+      while (exp > nextLevelPrice)
+      {
+        exp -= nextLevelPrice;
+        i++;
+        nextLevelPrice += 75 + i * 100;
+        level++;
+        if (level == Core.settingMaxItemLevel)
+        {
+          break;
+        }
+      }
+
+      if (level > Core.settingMaxItemLevel)
+        level = Core.settingMaxItemLevel;
+
+      float progress;
+      if (level == Core.settingMaxItemLevel)
+        progress = 1.75f;
+      else
+        progress = ((float)exp) / nextLevelPrice * 1.75f;
+
+      __result = new float[] { level, progress };
+      return false;
+    }
+  }
+}

+ 37 - 0
ItemLevelExtension/Patches/Patch_GameScript_HoverItem.cs

@@ -0,0 +1,37 @@
+using GadgetCore;
+using GadgetCore.API;
+using GadgetCore.Util;
+using HarmonyLib;
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Reflection.Emit;
+
+namespace ItemLevelExtension.Patches
+{
+
+  internal class MaxLevelGetter
+  {
+    public static int MaxLevel { get => Core.settingMaxItemLevel; }
+  }
+
+  [HarmonyPatch(typeof(PatchMethods))]
+  [HarmonyPatch("HoverItem")]
+  [HarmonyGadget("ItemLevelExtension")]
+  public static class Patch_PatchMethods_HoverItem
+  {
+    [HarmonyTranspiler]
+    public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator gen)
+    {
+      var p = TranspilerHelper.CreateProcessor(instructions, gen);
+      var ilRefs = p.FindAllRefsByInsn(new CodeInstruction(OpCodes.Ldc_I4_S, 10));
+      MethodInfo getValue = typeof(MaxLevelGetter).GetProperty("MaxLevel").GetGetMethod();
+      foreach (var ilRef in ilRefs)
+      {
+        //p.InjectInsn(ilRef, new CodeInstruction(OpCodes.Ldc_I4_S, 12), false);
+        p.InjectInsn(ilRef, new CodeInstruction(OpCodes.Call, getValue), false);
+      }
+      return p.Insns;
+    }
+  }
+}

+ 10 - 0
ItemLevelExtension/Properties/AssemblyInfo.cs

@@ -0,0 +1,10 @@
+using System.Reflection;
+using static ItemLevelExtension.ItemLevelExtension;
+
+[assembly: AssemblyProduct("ItemLevelExtension")] //Set this to the full name of the mod including spaces.
+[assembly: AssemblyTitle("ItemLevelExtension")] //This is only used when mousing over a dll file in Windows explorer.
+[assembly: AssemblyDescription("Raises the MAX item level to 100.")] //This is a short description for your mod's assembly.
+[assembly: AssemblyCompany("")] //Set this to your name/nickname and/or website
+[assembly: AssemblyCopyright("© 2021 Zariteis. All rights reserved.")] //Set this to your copyright name.
+[assembly: AssemblyVersion(MOD_VERSION)]
+[assembly: AssemblyFileVersion(MOD_VERSION)]

+ 8 - 0
ItemLevelExtension/Properties/launchSettings.json

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "ItemLevelExtension": {
+      "commandName": "Executable",
+      "executablePath": "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Roguelands\\Roguelands.exe"
+    }
+  }
+}

+ 15 - 0
ItemLevelExtension/README.txt

@@ -0,0 +1,15 @@
+In addition to changing all references to "Template" this and that to a more appropriate name,
+you need to add a file called "GamePaths.xml" to the folder ABOVE where you put this template, with the following content:
+
+<?xml version="1.0" encoding="utf-8"?>
+<Project>
+  <PropertyGroup>
+    <!-- Set this full path to your game folder. Must contain a slash at the end. -->
+    <GamePath>C:\Program Files (x86)\Steam\steamapps\common\Roguelands\</GamePath>
+
+    <!-- Set this partial path to the game's Managed folder. Must contain a slash at the end. -->
+    <ManagedFolder>Roguelands_Data\Managed\</ManagedFolder>
+  </PropertyGroup>
+</Project>
+
+Note that `GamePath` may need to be changed, depending on the nature of your installation.