-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreativeMode.cs
66 lines (60 loc) · 2.27 KB
/
CreativeMode.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
using HarmonyLib;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CreativeMode : Mod
{
private const string ModName = "creativemode";
private const string HarmonyId = "com.wisnoski.greenhell." + ModName;
Harmony instance;
public void Start()
{
instance = new Harmony(HarmonyId);
instance.PatchAll(Assembly.GetExecutingAssembly());
Debug.Log(string.Format("Mod {0} has been loaded!", ModName));
}
public void OnModUnload()
{
GameObject InGameMenu = GameObject.Find("InGameMenu");
if (InGameMenu != null && InGameMenu.transform.Find("MenuInGame").Find("Buttons").Find("Build") != null)
{
Destroy(InGameMenu.transform.Find("MenuInGame").Find("Buttons").Find("Build").gameObject);
}
instance.UnpatchAll(HarmonyId);
Debug.Log(string.Format("Mod {0} has been unloaded!", ModName));
}
public static void build()
{
(Traverse.Create(ConstructionGhostManager.Get()).Field("m_AllGhosts").GetValue() as List<ConstructionGhost>).ForEach((b) => Traverse.Create(b).Field("m_CurrentStep").SetValue(999));
}
}
[HarmonyPatch(typeof(ConstructionGhost))]
[HarmonyPatch("UpdateState")]
internal class Patch_ConstructionGhost_UpdateState
{
static void Prefix(ConstructionGhost __instance)
{
if((int) Traverse.Create(__instance).Field("m_State").GetValue() == 1){
Traverse.Create(__instance).Field("m_CurrentStep").SetValue(999);
}
}
}
[HarmonyPatch(typeof(MenuInGame))]
[HarmonyPatch("OnShow")]
internal class Patch_MenuInGame_AddButton
{
public static void Prefix(MenuInGame __instance)
{
GameObject InGameMenu = GameObject.Find("InGameMenu");
if (InGameMenu.transform.Find("MenuInGame").Find("Buttons").Find("Build") == null)
{
GameObject btn = GameObject.Instantiate(InGameMenu.transform.Find("MenuInGame").Find("Buttons").Find("Resume").gameObject, InGameMenu.transform.Find("MenuInGame").Find("Buttons"));
btn.name = "Build";
btn.GetComponent<UIButtonEx>().onClick.AddListener(CreativeMode.build);
InGameMenu.transform.Find("MenuInGame").GetComponent<MenuInGame>().AddMenuButton(btn.GetComponent<UIButtonEx>(), "Build All");
btn.GetComponentInChildren<Text>().text = "Build All";
}
}
}