Browse Source

[AncientReassembler] [2.0.3.3] init

Zariteis 4 years ago
parent
commit
bb86fbdea9

+ 46 - 0
AncientReassembler/AncientReassembler.cs

@@ -0,0 +1,46 @@
+using GadgetCore.API;
+using GadgetCore.API.ConfigMenu;
+using System;
+using UnityEngine;
+using UnityEngine.SceneManagement;
+
+namespace AncientReassembler
+{
+  [Gadget("AncientReassembler")]
+  public class AncientReassembler : Gadget<AncientReassembler>
+  {
+    public const string MOD_VERSION = "1.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; }
+    protected override void LoadConfig() { Config.Reset(); Config.Save(); }
+
+    public override string GetModDescription()
+    {
+      return "A mod that adds an Ancient Reassembler which can be used to upgrade items to a higher rarity.";
+    }
+
+    protected override void Initialize()
+    {
+      Logger.Log("Ancient Reassembler v" + Info.Mod.Version);
+      Core.logger = Logger;
+
+      var tile = ItemUtil.CreatePlacableItem("cAncientReassembler.png", "iAncientReassembler.png", "Ancient Reassembler");
+      Core.itemAncientReassemblerId = tile.Item.GetID();
+
+      Core.npcID = tile.GetID();
+
+      var asset = GadgetCoreAPI.LoadAssetBundle("menuancientreassembler");
+
+      var menuAncient = UnityEngine.Object.Instantiate((GameObject)asset.LoadAsset("assets/resources/menuancientreassembler.prefab"));
+      menuAncient.transform.localPosition = new Vector3(7.75f, 0, -2);
+
+      menuAncient.transform.GetChild(5).GetChild(0).gameObject.AddComponent<CraftButtonScript>();
+
+      menuAncient.AddComponent<MenuOpenCloseEventScript>();
+
+      Core.menu = new MenuInfo(MenuType.SIMPLE, menuAncient, tile);
+      Core.menu.Register("Ancient Reassembler");
+    }
+  }
+}

+ 236 - 0
AncientReassembler/AncientReassembler.csproj

@@ -0,0 +1,236 @@
+<?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>AncientReassembler</RootNamespace>
+    <AssemblyName>AncientReassembler</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="Assets\bAncientReassembler0.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\bAncientReassembler1.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\bAncientReassembler2.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\cAncientReassembler.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\cCombatSimulator.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\cGreenLamp.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\charBG.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\cOrangeLamp.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\cPlatform.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\cPurpleLamp.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\cWhiteLamp.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\cYellowLamp.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\First\one">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\iAirCore.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\iAncientReassembler.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\iCombatSimulator.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\iCore.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\iEarthCore.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\iFireCore.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\iGreenLamp.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\iOrangeLamp.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\iPlatform.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\iPurpleLamp.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\iWaterCore.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\iWhiteLamp.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\iYellowLamp.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\menuancientreassembler">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\menuAncientReassemblerBase.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\menuCombatSimulator.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\one">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="Assets\slotAncientReassembler.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <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>

BIN
AncientReassembler/Assets/bAncientReassembler0.png


BIN
AncientReassembler/Assets/bAncientReassembler1.png


BIN
AncientReassembler/Assets/bAncientReassembler2.png


BIN
AncientReassembler/Assets/cAncientReassembler.png


BIN
AncientReassembler/Assets/iAncientReassembler.png


BIN
AncientReassembler/Assets/menuAncientReassemblerBase.png


BIN
AncientReassembler/Assets/menuancientreassembler


BIN
AncientReassembler/Assets/slotAncientReassembler.png


+ 21 - 0
AncientReassembler/Core.cs

@@ -0,0 +1,21 @@
+using GadgetCore;
+using GadgetCore.API;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using UnityEngine;
+
+namespace AncientReassembler
+{
+  internal static class Core
+  {
+    public static int itemAncientReassemblerId = -1;
+    public static int npcID = -1;
+    public static MenuInfo menu = null;
+
+    public static ItemStore itemStore = new ItemStore(3);
+
+    public static GadgetLogger logger;
+  }
+}

+ 43 - 0
AncientReassembler/CraftButtonScript.cs

@@ -0,0 +1,43 @@
+using GadgetCore.API;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using UnityEngine;
+
+namespace AncientReassembler
+{
+  public class CraftButtonScript : MonoBehaviour
+  {
+    private void OnMouseEnter()
+    {
+      var render = gameObject.GetComponent<Renderer>();
+      render.material = texture2;
+      gameObject.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/hover"), Menuu.soundLevel / 10f);
+    }
+
+    private void OnMouseExit()
+    {
+      var render = gameObject.GetComponent<Renderer>();
+      render.material = texture1;
+    }
+
+    private void OnEnable()
+    {
+      var render = gameObject.GetComponent<Renderer>();
+      render.material = texture1;
+    }
+
+    private static Material texture1 = new Material(Shader.Find("Unlit/Transparent"))
+    {
+      mainTexture = GadgetCoreAPI.LoadTexture2D("bAncientReassembler1.png")
+    };
+
+    private static Material texture2 = new Material(Shader.Find("Unlit/Transparent"))
+    {
+      mainTexture = GadgetCoreAPI.LoadTexture2D("bAncientReassembler2.png")
+    };
+
+  }
+
+}

+ 138 - 0
AncientReassembler/ItemStore.cs

@@ -0,0 +1,138 @@
+using GadgetCore.API;
+using System;
+using UnityEngine;
+
+namespace AncientReassembler
+{
+  public class ItemStore
+  {
+    public ItemStore(int size)
+    {
+      m_Items = new Item[size];
+    }
+
+    private Item[] m_Items;
+
+    public Item[] Items
+    {
+      get { return m_Items; }
+      set { m_Items = value; }
+    }
+
+    public void Clear()
+    {
+      for (int i = 0; i < m_Items.Length; i++)
+        m_Items[i] = new Item(0, 0, 0, 0, 0, new int[3], new int[3]);
+    }
+
+    public bool CanUse(Item item)
+    {
+      var type = ItemRegistry.GetTypeByID(item.id);
+      if ((type & ItemType.LEVELING) == ItemType.LEVELING)
+        return
+           true;
+      return false;
+    }
+
+    public bool ConfirmCombine()
+    {
+
+      if ((Items[0]?.id ?? 0) > 0 && (Items[1]?.id ?? 0) > 0 && (Items[2]?.id ?? 0) == 0)
+      {
+        Item item1 = Items[0];
+        Item item2 = Items[1];
+        if (item1.id == item2.id
+          && item1.q == 1 && item2.q == 1
+          && item1.tier == item2.tier
+          && item1.tier < 3)
+          return true;
+      }
+      return false;
+    }
+
+    public void Combine()
+    {
+      if (ConfirmCombine())
+      {
+        Items[2] = Items[0];
+
+        Items[2].corrupted = Max(Items[0].corrupted, Items[1].corrupted);
+        Items[2].exp = Max(Items[0].exp, Items[1].exp);
+        Items[2].tier++;
+
+        Items[0] = new Item(0, 0, 0, 0, 0, new int[3], new int[3]);
+        Items[1] = new Item(0, 0, 0, 0, 0, new int[3], new int[3]);
+
+        InstanceTracker.GameScript.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/create"), Menuu.soundLevel / 10f);
+
+        UpdateLatestUI();
+      }
+    }
+
+    private static int Max(int i1, int i2)
+    {
+      return i1 > i2 ? i1 : i2;
+    }
+
+    public void UpdateLatestUI()
+    {
+      UpdateUI(lastUsed);
+    }
+
+    private static readonly Texture2D textureButton0 = GadgetCoreAPI.LoadTexture2D("bAncientReassembler0.png");
+    private static readonly Texture2D textureButton1 = GadgetCoreAPI.LoadTexture2D("bAncientReassembler1.png");
+    private static readonly Texture2D textureButton2 = GadgetCoreAPI.LoadTexture2D("bAncientReassembler2.png");
+
+    private GameObject lastUsed;
+    public void UpdateUI(GameObject menu)
+    {
+      lastUsed = menu;
+      try
+      {
+        for (int i = 0; i < m_Items.Length; i++)
+        {
+          var obj = menu.transform.GetChild(2 + i).GetChild(0).gameObject;
+          obj.GetComponent<Renderer>().material = (Material)Resources.Load("i/i" + (m_Items[i]?.id ?? 0));
+          var objBack = obj.transform.GetChild(1).gameObject;
+          AnimIcon animIcon = (AnimIcon)objBack.GetComponent("AnimIcon");
+          if ((m_Items[i]?.id ?? 0) > 0)
+          {
+            objBack.GetComponent<Renderer>().material = (Material)Resources.Load("iBack" + m_Items[i].tier);
+            if (m_Items[i].tier == 3)
+              animIcon.anim = 1;
+            else
+              animIcon.anim = 0;
+            objBack.SetActive(true);
+          }
+          else
+          {
+            animIcon.anim = 0;
+            objBack.SetActive(false);
+          }
+        }
+
+        if (ConfirmCombine())
+          menu.transform.GetChild(5).GetChild(0).gameObject.SetActive(true);
+        else
+          menu.transform.GetChild(5).GetChild(0).gameObject.SetActive(false);
+
+        if ((m_Items[2]?.id ?? 0) > 0)
+        {
+          menu.transform.GetChild(2 + 0).gameObject.SetActive(false);
+          menu.transform.GetChild(2 + 1).gameObject.SetActive(false);
+          menu.transform.GetChild(2 + 2).gameObject.SetActive(true);
+        }
+        else
+        {
+          menu.transform.GetChild(2 + 0).gameObject.SetActive(true);
+          menu.transform.GetChild(2 + 1).gameObject.SetActive(true);
+          menu.transform.GetChild(2 + 2).gameObject.SetActive(false);
+        }
+      }
+      catch (Exception e)
+      {
+        Core.logger.LogConsole(e.Message);
+      }
+    }
+  }
+}

+ 29 - 0
AncientReassembler/ItemUtil.cs

@@ -0,0 +1,29 @@
+using UnityEngine;
+using GadgetCore.API;
+
+namespace AncientReassembler
+{
+  public static class ItemUtil
+  {
+    public static TileInfo CreatePlacableItem(string tileImgPath, string itemImgPath, string name)
+    {
+
+      Texture2D textureTile = GadgetCoreAPI.LoadTexture2D(tileImgPath);
+      Texture2D textureItem = GadgetCoreAPI.LoadTexture2D(itemImgPath);
+
+      GameObject gameObject = Object.Instantiate(GadgetCoreAPI.GetPlaceableNPCResource(2100));
+      gameObject.name = name;
+      Renderer renderer = gameObject.GetComponentInChildren<Renderer>();
+      renderer.material = new Material(Shader.Find("Unlit/Transparent"))
+      {
+        mainTexture = textureTile
+      };
+
+      ItemInfo itemInfo = new ItemInfo(ItemType.GENERIC, name, "", textureItem);
+      itemInfo.Register(name);
+      var tile = new TileInfo(TileType.INTERACTIVE, textureTile, gameObject, itemInfo);
+      tile.Register(name);
+      return tile;
+    }
+  }
+}

+ 3 - 0
AncientReassembler/Manifest.ini

@@ -0,0 +1,3 @@
+[Metadata]
+Name=Ancient Reassembler
+Assembly=AncientReassembler.dll

+ 28 - 0
AncientReassembler/MenuOpenCloseEventScript.cs

@@ -0,0 +1,28 @@
+using GadgetCore.API;
+using GadgetCore.Util;
+using HarmonyLib;
+using System;
+using System.Collections;
+using System.Threading;
+using System.Windows.Threading;
+using UnityEngine;
+
+namespace AncientReassembler
+{
+  public class MenuOpenCloseEventScript : MonoBehaviour
+  {
+    void OnEnable()
+    {
+      Core.itemStore.Clear();
+      Core.itemStore.UpdateUI(gameObject);
+    }
+
+    void OnDisable()
+    {
+      foreach (Item item in Core.itemStore.Items)
+        if (item != null && item.id > 0)
+          GadgetCoreAPI.DropItem(MenuScript.player.transform.position, item);
+      Core.itemStore.Clear();
+    }
+  }
+}

+ 1 - 0
AncientReassembler/ModInfo.txt

@@ -0,0 +1 @@
+A mod that adds an Ancient Reassembler which can be used to upgrade items to a higher rarity.

+ 29 - 0
AncientReassembler/Patches/Patch_GameScript_HoverCombatChip.cs

@@ -0,0 +1,29 @@
+using GadgetCore;
+using GadgetCore.API;
+using HarmonyLib;
+using System;
+using System.Reflection;
+using UnityEngine;
+
+namespace AncientReassembler.Patches
+{
+
+  [HarmonyPatch(typeof(GameScript))]
+  [HarmonyPatch("HoverCombatChip")]
+  [HarmonyGadget("AncientReassembler")]
+  public static class Patch_GameScript_HoverCombatChip
+  {
+    [HarmonyPrefix]
+    public static void Prefix(GameScript __instance, int slot , int[] ___combatChips)
+    {
+      try
+      {
+        if (slot <= 5)
+        {
+          //Core.itemStore.UpdateText(___combatChips[slot]);
+        }
+      }
+      catch { }
+    }
+  }
+}

+ 124 - 0
AncientReassembler/Patches/Patch_GameScript_Update.cs

@@ -0,0 +1,124 @@
+using GadgetCore;
+using GadgetCore.API;
+using HarmonyLib;
+using System;
+using System.Reflection;
+using UnityEngine;
+
+namespace AncientReassembler.Patches
+{
+
+  [HarmonyPatch(typeof(GameScript))]
+  [HarmonyPatch("Update")]
+  [HarmonyGadget("AncientReassembler")]
+  public static class Patch_GameScript_Update
+  {
+    [HarmonyPrefix]
+    public static void Prefix(GameScript __instance, ref Item ___holdingItem, ref int ___curhoveringstat, ref bool ___holdingCombatChip, bool ___exitingcombatmode)
+    {
+      try
+      {
+        if (MenuScript.player)
+        {
+          if (!GameScript.pausing && Input.GetMouseButtonDown(0) && GameScript.inventoryOpen)
+          {
+            var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
+            RaycastHit hit;
+            if (Physics.Raycast(ray, out hit, 7f))
+            {
+              if (hit.transform.gameObject.name.StartsWith("ancient_reassembler_"))
+              {
+                var slot = 2;
+                if (hit.transform.gameObject.name.StartsWith("ancient_reassembler_in"))
+                  slot = int.Parse(hit.transform.gameObject.name.Substring("ancient_reassembler_in".Length));
+
+                if (slot >= 0 && slot < 16)
+                {
+                  if (___holdingItem.id != 0)
+                  {
+                    if (Core.itemStore.CanUse(___holdingItem) && slot != 2)
+                    {
+                      if (Core.itemStore.Items[slot].id == 0)
+                      {
+                        Place(__instance, slot, ref ___holdingItem);
+                      }
+                      else
+                      {
+                        Swap(__instance, slot, ref ___holdingItem);
+                      }
+                    }
+                  }
+                  else if (Core.itemStore.Items[slot].id != 0)
+                  {
+                    Select(__instance, slot, ref ___holdingItem);
+                  }
+                }
+              }
+              else if (hit.transform.gameObject.name.StartsWith("button_ancient_reassembler"))
+                Core.itemStore.Combine();
+            }
+          }
+        }
+      }
+      catch (Exception e) { Core.logger.LogConsole(e.Message); }
+    }
+
+
+    [HarmonyPostfix]
+    public static void Postfix()
+    {
+      if (MenuScript.player)
+      {
+        if (GameScript.inventoryOpen)
+        {
+          var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
+          RaycastHit hit;
+          if (Physics.Raycast(ray, out hit, 7f))
+          {
+            if (hit.transform.gameObject.name.StartsWith("ancient_reassembler_"))
+            {
+              var slot = 2;
+              if (hit.transform.gameObject.name.StartsWith("ancient_reassembler_in"))
+                slot = int.Parse(hit.transform.gameObject.name.Substring("ancient_reassembler_in".Length));
+              if ((Core.itemStore.Items[slot]?.id ?? 0) != 0)
+                PatchMethods.HoverItem(Core.itemStore.Items[slot]);
+            }
+          }
+        }
+      }
+    }
+    private static void Swap(GameScript __instance, int slot, ref Item ___holdingItem)
+    {
+      __instance.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/CLICK1"), Menuu.soundLevel / 10f);
+
+      Item item = ___holdingItem;
+      ___holdingItem = Core.itemStore.Items[slot];
+      Core.itemStore.Items[slot] = item;
+
+      Core.itemStore.UpdateLatestUI();
+      __instance.RefreshHoldingSlot();
+    }
+
+    private static void Select(GameScript __instance, int slot, ref Item ___holdingItem)
+    {
+      __instance.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/CLICK1"), Menuu.soundLevel / 10f);
+
+      ___holdingItem = Core.itemStore.Items[slot];
+      Core.itemStore.Items[slot] = __instance.EmptyItem();
+
+      Core.itemStore.UpdateLatestUI();
+      __instance.RefreshHoldingSlot();
+    }
+
+    private static void Place(GameScript __instance, int slot, ref Item ___holdingItem)
+    {
+      __instance.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/CLICK1"), Menuu.soundLevel / 10f);
+
+      Core.itemStore.Items[slot] = ___holdingItem;
+      ___holdingItem = __instance.EmptyItem();
+
+      Core.itemStore.UpdateLatestUI();
+      __instance.RefreshHoldingSlot();
+    }
+  }
+}

+ 37 - 0
AncientReassembler/Patches/Patch_KylockeStand_Awake.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Collections;
+using GadgetCore.API;
+using HarmonyLib;
+using UnityEngine;
+
+namespace AncientReassembler.Patches
+{
+  [HarmonyPatch(typeof(KylockeStand))]
+  [HarmonyPatch("Awake")]
+  [HarmonyGadget("AncientReassembler")]
+  public static class Patch_KylockeStand_Awake
+  {
+    [HarmonyPrefix]
+    public static void Prefix(KylockeStand __instance)
+    {
+      __instance.StartCoroutine(Patch_KylockeStand_Awake.WaitAndCreate(__instance));
+    }
+
+    private static IEnumerator WaitAndCreate(KylockeStand instance)
+    {
+      if (instance.itemID == 2403)
+      {
+        while (!Network.isServer && !Network.isClient)
+        {
+          yield return new WaitForSeconds(0f);
+        }
+        if (Network.isServer)
+        {
+          var obj = ((GameObject)Network.Instantiate(Resources.Load("npc/buildStand"), new Vector3(-250f + 4, -5.99f, 0.19f), instance.transform.rotation, 0));
+          obj.GetComponent<KylockeStand>().GetComponent<NetworkView>().RPC("Set", RPCMode.AllBuffered, new object[] { new int[] { Core.itemAncientReassemblerId, 1000 } });
+        }
+      }
+      yield break;
+    }
+  }
+}

+ 42 - 0
AncientReassembler/Patches/Patch_KylockeStand_Set.cs

@@ -0,0 +1,42 @@
+using System;
+using System.Collections;
+using GadgetCore.API;
+using HarmonyLib;
+using UnityEngine;
+
+namespace AncientReassembler.Patches
+{
+	[HarmonyPatch(typeof(KylockeStand))]
+	[HarmonyPatch("Set")]
+	[HarmonyGadget("AncientReassembler")]
+	public static class Patch_KylockeStand_Set
+	{
+
+		[HarmonyPostfix]
+		public static bool Prefix(KylockeStand __instance, int[] p)
+		{
+			if (p[0] == Core.itemAncientReassemblerId)
+			{
+				__instance.itemID = p[0];
+				__instance.cost = p[1];
+				__instance.icon.GetComponent<Renderer>().material = (Material)Resources.Load("i/i" + __instance.itemID.ToString());
+				__instance.txtCost[0].text = string.Empty + __instance.cost.ToString();
+				__instance.txtCost[1].text = __instance.txtCost[0].text;
+				__instance.txtName[0].text = string.Empty + ItemRegistry.GetItem(__instance.itemID).GetName();
+				__instance.txtName[1].text = __instance.txtName[0].text;
+				__instance.StartCoroutine(Patch_KylockeStand_Set.DoUpdatePlatformStand(__instance));
+				return false;
+			}
+			return true;
+		}
+
+		private static IEnumerator DoUpdatePlatformStand(KylockeStand instance)
+		{
+			instance.isBuild = true;
+			instance.isCredits = false;
+			instance.isTrophies = false;
+			instance.currency.GetComponent<Renderer>().material = (Material)Resources.Load("i/i57");
+			yield break;
+		}
+	}
+}

+ 10 - 0
AncientReassembler/Properties/AssemblyInfo.cs

@@ -0,0 +1,10 @@
+using System.Reflection;
+using static AncientReassembler.AncientReassembler;
+
+[assembly: AssemblyProduct("Ancient Reassembler Mod")] //Set this to the full name of the mod including spaces.
+[assembly: AssemblyTitle("Ancient Reassembler")] //This is only used when mousing over a dll file in Windows explorer.
+[assembly: AssemblyDescription("A mod that adds an Ancient Reassembler which can be used to upgrade items to a higher rarity.")] //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
AncientReassembler/Properties/launchSettings.json

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

+ 15 - 0
AncientReassembler/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.