Skip to content

Commit 9d79540

Browse files
committed
add console, fix menu raycast block
1 parent aedd954 commit 9d79540

File tree

4 files changed

+147
-5
lines changed

4 files changed

+147
-5
lines changed

Main.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
using System.Threading.Tasks;
66
using MelonLoader;
77
using UnityEngine;
8-
[assembly: MelonInfo(typeof(SuperliminalPracticeMod.Main), "Superliminal Practice Mod", "0.1.4", "Micrologist#2351")]
9-
[assembly: MelonGame("PillowCastle", null)]
8+
[assembly: MelonInfo(typeof(SuperliminalPracticeMod.Main), "Superliminal Practice Mod", "0.2.0", "Micrologist#2351")]
9+
[assembly: MelonGame("PillowCastle", "Superliminal")]
10+
[assembly: MelonGame("PillowCastle", "SuperliminalSteam")]
1011

1112
namespace SuperliminalPracticeMod
1213
{

PracticeModManager.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class PracticeModManager : MonoBehaviour
2323
public ResizeScript resizeScript;
2424
public Text playerText;
2525
public Text grabbedObejctText;
26+
public PauseMenu pauseMenu;
2627

2728

2829
Vector3 storedPosition;
@@ -51,13 +52,17 @@ void Awake()
5152
debugFunctions = false;
5253
GameManager.GM.GetComponent<LevelInformation>().LevelInfo.RandomLoadingScreens = new SceneReference[1] { GameManager.GM.GetComponent<LevelInformation>().LevelInfo.NormalLoadingScreen };
5354

55+
base.gameObject.AddComponent<SLPMod_Console>();
56+
5457
}
5558

5659

5760

5861

5962
void Update()
6063
{
64+
if (Input.GetKeyDown(KeyCode.F11))
65+
SLPMod_Console.instance.Toggle();
6166

6267
if (Input.GetKeyDown(KeyCode.F12))
6368
{
@@ -66,6 +71,8 @@ void Update()
6671
performanceGraph.gameObject.SetActive(!performanceGraph.gameObject.activeSelf);
6772
}
6873

74+
GameManager.GM.enableDebugFunctions = debugFunctions;
75+
6976
if (GameManager.GM.player == null)
7077
return;
7178

@@ -75,6 +82,7 @@ void Update()
7582
playerMotor = player.GetComponent<CharacterMotor>();
7683
playerCamera = player.GetComponentInChildren<Camera>();
7784
resizeScript = playerCamera.GetComponent<ResizeScript>();
85+
pauseMenu = GameObject.Find("UI_PAUSE_MENU").GetComponentInChildren<PauseMenu>(true);
7886
defaultFarClipPlane = playerCamera.farClipPlane;
7987
if(player.transform.Find("Flashlight") == null)
8088
{
@@ -101,7 +109,7 @@ void Update()
101109
grabbedObejctText = NewGrabbedObjectText();
102110
}
103111

104-
GameManager.GM.enableDebugFunctions = debugFunctions;
112+
SLPMod_Console.instance.active = false;
105113
}
106114

107115

@@ -210,7 +218,9 @@ Text NewPlayerText()
210218
Text newText;
211219
GameObject gameObject = new GameObject("PlayerText");
212220
gameObject.transform.parent = GameObject.Find("UI_PAUSE_MENU").transform.Find("Canvas");
213-
gameObject.AddComponent<CanvasGroup>().interactable = false;
221+
CanvasGroup cg = gameObject.AddComponent<CanvasGroup>();
222+
cg.interactable = false;
223+
cg.blocksRaycasts = false;
214224
newText = gameObject.AddComponent<Text>();
215225
RectTransform component = newText.GetComponent<RectTransform>();
216226
component.sizeDelta = new Vector2((float)(Screen.currentResolution.width / 3), (float)(Screen.currentResolution.height / 3));
@@ -236,7 +246,9 @@ Text NewGrabbedObjectText()
236246
Text newText;
237247
GameObject gameObject = new GameObject("GrabbedObjectText");
238248
gameObject.transform.parent = GameObject.Find("UI_PAUSE_MENU").transform.Find("Canvas");
239-
gameObject.AddComponent<CanvasGroup>().interactable = false;
249+
CanvasGroup cg = gameObject.AddComponent<CanvasGroup>();
250+
cg.interactable = false;
251+
cg.blocksRaycasts = false;
240252
newText = gameObject.AddComponent<Text>();
241253
RectTransform component = newText.GetComponent<RectTransform>();
242254
component.sizeDelta = new Vector2((float)(Screen.currentResolution.width / 3), (float)(Screen.currentResolution.height / 3));
@@ -362,5 +374,19 @@ void RestartMap()
362374
GameManager.GM.GetComponent<SaveAndCheckpointManager>().RestartLevel();
363375
}
364376

377+
public void Teleport(Vector3 position)
378+
{
379+
if (GameManager.GM.player == null)
380+
return;
381+
382+
playerMotor.transform.position = position;
383+
}
384+
385+
public void Scale(float newScale)
386+
{
387+
if(GameManager.GM.player != null && newScale > 0.0001f)
388+
playerMotor.transform.localScale = new Vector3(newScale, newScale, newScale);
389+
}
390+
365391
}
366392
}

SLPMod_Console.cs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using Rewired;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using UnityEngine;
8+
using MelonLoader;
9+
using UnityEngine.SceneManagement;
10+
11+
namespace SuperliminalPracticeMod
12+
{
13+
class SLPMod_Console : MonoBehaviour
14+
{
15+
public static SLPMod_Console instance;
16+
public bool active;
17+
public bool setFocus;
18+
19+
20+
string input;
21+
22+
23+
private void Awake()
24+
{
25+
instance = this;
26+
active = false;
27+
setFocus = false;
28+
input = "";
29+
}
30+
31+
private void OnGUI()
32+
{
33+
34+
35+
36+
37+
if (GameManager.GM.player != false)
38+
GameManager.GM.PM.canControl = !active;
39+
40+
41+
42+
if (!active)
43+
return;
44+
45+
float y = 0f;
46+
47+
if (Event.current.type == EventType.KeyDown && Event.current.character == '\n')
48+
{
49+
ParseCommand(input);
50+
input = "";
51+
active = false;
52+
return;
53+
}
54+
55+
if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.F11 || Event.current.keyCode == KeyCode.Escape)
56+
{
57+
active = false;
58+
return;
59+
}
60+
61+
62+
GUI.Box(new Rect(0, y, Screen.width, 30), "");
63+
GUI.backgroundColor = new Color(0, 0, 0, 0);
64+
GUI.SetNextControlName("SLP_Console");
65+
input = GUI.TextField(new Rect(10f, y + 5f, Screen.width - 20f, 20f), input);
66+
GUI.FocusControl("SLP_Console");
67+
68+
69+
70+
71+
}
72+
73+
private void ParseCommand(string command)
74+
{
75+
MelonLogger.Log("Trying to parse \"" + command + "\"");
76+
string[] commandArray = command.Split(' ');
77+
if(commandArray[0].ToLower() == "teleport" && commandArray.Length >= 4)
78+
{
79+
float x, y, z;
80+
if (!float.TryParse(commandArray[1], out x) || !float.TryParse(commandArray[2], out y) || !float.TryParse(commandArray[3], out z))
81+
return;
82+
MelonLogger.Log("Trying to teleport to "+x+", "+y+", "+z);
83+
PracticeModManager.Instance.Teleport(new Vector3(x, y, z));
84+
}
85+
else if(commandArray[0].ToLower() == "scale" && commandArray.Length >= 2)
86+
{
87+
float newScale;
88+
if (float.TryParse(commandArray[1], out newScale))
89+
PracticeModManager.Instance.Scale(Math.Abs(newScale));
90+
}
91+
else if(commandArray[0].ToLower() == "load" && commandArray.Length >= 2)
92+
{
93+
int sceneIndex;
94+
if (!int.TryParse(commandArray[1], out sceneIndex))
95+
return;
96+
if(sceneIndex >= 0)
97+
{
98+
SceneManager.LoadScene(sceneIndex % SceneManager.sceneCountInBuildSettings);
99+
}
100+
}
101+
else if(commandArray[0].ToLower() == "noclip")
102+
{
103+
PracticeModManager.Instance.noClip = !PracticeModManager.Instance.noClip;
104+
}
105+
}
106+
107+
public void Toggle()
108+
{
109+
active = !active;
110+
setFocus = active;
111+
}
112+
113+
}
114+
}

SuperliminalPracticeMod.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
</Reference>
8383
</ItemGroup>
8484
<ItemGroup>
85+
<Compile Include="SLPMod_Console.cs" />
8586
<Compile Include="PracticeModManager.cs" />
8687
<Compile Include="Main.cs" />
8788
<Compile Include="Properties\AssemblyInfo.cs" />

0 commit comments

Comments
 (0)