This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
/
Mod.cs
211 lines (175 loc) · 8.47 KB
/
Mod.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
using AlexejheroYTB.Common;
using Harmony;
using QModManager.API.ModLoading;
using SMLHelper.V2.Assets;
using SMLHelper.V2.Crafting;
using SMLHelper.V2.Handlers;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using UnityEngine;
namespace MoreModifiedItems
{
[QModCore]
public static class QMod
{
[QModPatch]
public static void Patch()
{
HarmonyHelper.Patch();
new LightweightUltraHighCapacityTank().Patch();
new UltraGlideSwimChargeFins().Patch();
new ReinforcedStillsuit().Patch();
AlexejheroYTB.Common.Logger.Log("Patched");
}
}
public class LightweightUltraHighCapacityTank : Craftable
{
public LightweightUltraHighCapacityTank() : base("lwuhtank", "Lightweight Ultra High Capacity Tank", "Has the same amount of oxygen as the Ultra High Capacity Tank, but has the no speed penalty bonus of the Lightweight High Capacity Tank.")
{
base.OnFinishedPatching += OnFinishedPatching;
}
public new void OnFinishedPatching()
{
CraftDataHandler.RemoveFromGroup(TechGroup.Workbench, TechCategory.Workbench, this.TechType);
CraftDataHandler.AddToGroup(TechGroup.Workbench, TechCategory.Workbench, this.TechType, TechType.HighCapacityTank);
SpriteHandler.RegisterSprite(this.TechType, SpriteManager.Get(TechType.HighCapacityTank));
CraftDataHandler.SetEquipmentType(this.TechType, EquipmentType.Tank);
CraftDataHandler.SetItemSize(this.TechType, 3, 4);
CraftDataHandler.SetCraftingTime(this.TechType, 5);
}
public override TechGroup GroupForPDA => TechGroup.Workbench;
public override TechCategory CategoryForPDA => TechCategory.Workbench;
protected override TechData GetBlueprintRecipe() => new TechData(
new Ingredient(TechType.HighCapacityTank, 1),
new Ingredient(TechType.PlasteelTank, 1),
new Ingredient(TechType.Lubricant, 2),
new Ingredient(TechType.HydrochloricAcid, 1)
)
{
craftAmount = 1,
};
public override CraftTree.Type FabricatorType => CraftTree.Type.Workbench;
public override string[] StepsToFabricatorTab => "TankMenu".Split('/');
public override GameObject GetGameObject()
{
GameObject obj = GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.PlasteelTank));
obj.GetAllComponentsInChildren<Oxygen>().Do(o => o.oxygenCapacity = 180);
return obj;
}
}
public class UltraGlideSwimChargeFins : Craftable
{
public static TechType techType;
public UltraGlideSwimChargeFins() : base("ugscfins", "Ultra Glide Swim Charge Fins", "Has the same speed increase as the Ultra Glide Fins, but also has the tool recharge ability of the Swim Charge Fins.")
{
base.OnFinishedPatching += OnFinishedPatching;
}
public new void OnFinishedPatching()
{
CraftDataHandler.RemoveFromGroup(TechGroup.Workbench, TechCategory.Workbench, this.TechType);
CraftDataHandler.AddToGroup(TechGroup.Workbench, TechCategory.Workbench, this.TechType, TechType.SwimChargeFins);
SpriteHandler.RegisterSprite(this.TechType, SpriteManager.Get(TechType.SwimChargeFins));
CraftDataHandler.SetEquipmentType(this.TechType, EquipmentType.Foots);
CraftDataHandler.SetItemSize(this.TechType, 2, 3);
CraftDataHandler.SetCraftingTime(this.TechType, 5);
techType = TechType;
}
public override TechGroup GroupForPDA => TechGroup.Workbench;
public override TechCategory CategoryForPDA => TechCategory.Workbench;
protected override TechData GetBlueprintRecipe() => new TechData(
new Ingredient(TechType.UltraGlideFins, 1),
new Ingredient(TechType.SwimChargeFins, 1),
new Ingredient(TechType.Lubricant, 2),
new Ingredient(TechType.HydrochloricAcid, 1)
)
{
craftAmount = 1,
};
public override CraftTree.Type FabricatorType => CraftTree.Type.Workbench;
public override string[] StepsToFabricatorTab => "FinsMenu".Split('/');
public override GameObject GetGameObject()
{
return GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.UltraGlideFins));
}
[HarmonyPatch(typeof(UpdateSwimCharge), nameof(UpdateSwimCharge.FixedUpdate))]
public static class UpdateSwimCharge_FixedUpdate_Patch
{
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> c = instructions.ToList();
int index = c.FindIndex(o => o.opcode == OpCodes.Ldc_I4_0);
c.InsertRange(index, new List<CodeInstruction>()
{
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Inventory), nameof(Inventory.Get))),
new CodeInstruction(OpCodes.Callvirt, AccessTools.Property(typeof(Inventory), nameof(Inventory.equipment)).GetGetMethod()),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(UltraGlideSwimChargeFins), nameof(UltraGlideSwimChargeFins.techType))),
new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Equipment), nameof(Equipment.GetCount))),
new CodeInstruction(OpCodes.Add),
});
return c;
}
}
[HarmonyPatch(typeof(UnderwaterMotor), nameof(UnderwaterMotor.AlterMaxSpeed))]
public static class UnderwaterMotor_AlterMaxSpeed_Patch
{
public static void Postfix(UnderwaterMotor __instance, ref float __result)
{
if (Inventory.Get().equipment.GetCount(techType) > 0)
{
__result += 2.5f * __instance.currentWreckSpeedMultiplier;
}
}
}
}
public class ReinforcedStillsuit : Craftable
{
public static TechType techType;
public ReinforcedStillsuit() : base("rssuit", "Reinforced Stillsuit", "Offers the same protection as the Reinforced Dive Suit, and also has the water recycling feature of the Stillsuit")
{
base.OnStartedPatching += OnStartedPatching;
base.OnFinishedPatching += OnFinishedPatching;
}
public new void OnStartedPatching()
{
CraftTreeHandler.AddTabNode(CraftTree.Type.Workbench, "BodyMenu", "Suit Upgrades", SpriteManager.Get(TechType.Stillsuit));
}
public new void OnFinishedPatching()
{
CraftDataHandler.RemoveFromGroup(TechGroup.Workbench, TechCategory.Workbench, this.TechType);
CraftDataHandler.AddToGroup(TechGroup.Workbench, TechCategory.Workbench, this.TechType, TechType.Stillsuit);
SpriteHandler.RegisterSprite(this.TechType, SpriteManager.Get(TechType.Stillsuit));
CraftDataHandler.SetEquipmentType(this.TechType, EquipmentType.Body);
CraftDataHandler.SetItemSize(this.TechType, 2, 3);
CraftDataHandler.SetCraftingTime(this.TechType, 5);
techType = TechType;
}
public override TechGroup GroupForPDA => TechGroup.Workbench;
public override TechCategory CategoryForPDA => TechCategory.Workbench;
protected override TechData GetBlueprintRecipe() => new TechData(
new Ingredient(TechType.ReinforcedDiveSuit, 1),
new Ingredient(TechType.Stillsuit, 1),
new Ingredient(TechType.Lubricant, 2),
new Ingredient(TechType.HydrochloricAcid, 1)
)
{
craftAmount = 1,
};
public override CraftTree.Type FabricatorType => CraftTree.Type.Workbench;
public override string[] StepsToFabricatorTab => "BodyMenu".Split('/');
public override GameObject GetGameObject()
{
return GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.Stillsuit));
}
[HarmonyPatch(typeof(Player), nameof(Player.HasReinforcedSuit))]
public static class Player_HasReinforcedSuit_Patch
{
[HarmonyPostfix]
public static void Postfix(ref bool __result)
{
__result = __result || Inventory.main.equipment.GetTechTypeInSlot("Body") == techType;
}
}
}
}