Skip to content

Commit 0e6821d

Browse files
authored
Level Completion + Upload Support from dev Branch to stable
Level Completion + Upload Support View past commits to see changes
2 parents f1443e4 + 9a2dc1b commit 0e6821d

13 files changed

+1033
-18
lines changed

CustomLevels/CustomLevels.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
</Reference>
8181
<Reference Include="com.rlabrecque.steamworks.net">
8282
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Quadrata\Quadrata_Data\Managed\com.rlabrecque.steamworks.net.dll</HintPath>
83-
<Private>False</Private>
8483
</Reference>
8584
<Reference Include="DOTween">
8685
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Quadrata\Quadrata_Data\Managed\DOTween.dll</HintPath>
@@ -146,6 +145,13 @@
146145
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Quadrata\MelonLoader\net35\Newtonsoft.Json.dll</HintPath>
147146
<Private>False</Private>
148147
</Reference>
148+
<Reference Include="Steamworks.NET, Version=20.2.0.0, Culture=neutral, processorArchitecture=AMD64">
149+
<SpecificVersion>False</SpecificVersion>
150+
<HintPath>..\..\..\..\..\..\GlobalReference\Steamworks.NET.dll</HintPath>
151+
<EmbedInteropTypes>False</EmbedInteropTypes>
152+
<Private>False</Private>
153+
<Aliases>SteamworksNetUnstripped</Aliases>
154+
</Reference>
149155
<Reference Include="System" />
150156
<Reference Include="System.Configuration">
151157
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Quadrata\Quadrata_Data\Managed\System.Configuration.dll</HintPath>
@@ -309,6 +315,10 @@
309315
</Reference>
310316
</ItemGroup>
311317
<ItemGroup>
318+
<Compile Include="data\CustomLevelCompleteUI.cs" />
319+
<Compile Include="data\CustomSaveManager.cs" />
320+
<Compile Include="data\SteamworksManager.cs" />
321+
<Compile Include="data\UIController.cs" />
312322
<Compile Include="Extensions\LevelManagerExtension.cs" />
313323
<Compile Include="Patches\AchievementPatches.cs" />
314324
<Compile Include="Extensions\DirectorExtensions.cs" />

CustomLevels/Data/GameLevelData.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
using System;
22
using UnityEngine;
33

4-
namespace QuadrataPatcher
4+
[Serializable]
5+
public class SerializableVector2
56
{
6-
[Serializable]
7-
public class GameLevelData
7+
public float x;
8+
public float y;
9+
10+
public SerializableVector2() { }
11+
12+
public SerializableVector2(Vector2 v)
813
{
9-
public Vector2[] characterPositions = new Vector2[2];
10-
public string entityData = "";
11-
public int moveCount = 5;
12-
public bool reversed;
14+
x = v.x;
15+
y = v.y;
1316
}
1417
}
18+
19+
[Serializable]
20+
public class GameLevelData
21+
{
22+
public Vector2[] characterPositions;
23+
public string entityData;
24+
public int moveCount;
25+
public bool reversed;
26+
}

CustomLevels/Extensions/DirectorExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private static void ExecuteLoadCustomLevel(object directorInstance, string Level
5151

5252
object gameLevel;
5353
levelBuilder.InitCustomLevelFromCode(LevelCode, out gameLevel);
54+
CustomLevelCompleteUI.gameLevelUpload = JsonUtility.ToJson(gameLevel);
5455

5556
if (gameLevel == null)
5657
{

CustomLevels/Extensions/LayerMenuExtension.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
public static class LayerMenuExtensions
1313
{
14+
15+
public static GameObject loadButtonObj;
16+
public static InputField inputField;
17+
public static GameObject versionTextObj;
18+
public static GameObject borderObj;
19+
1420
private static IEnumerator WaitAndChangeSprite(MenuButtonSandbox sandboxBtn, Sprite sprite)
1521
{
1622
yield return new WaitWhile(() => UIManager.isMenuMoving);
@@ -155,7 +161,7 @@ public static void CalculateMenuExtended(this object layerMenuInstance)
155161

156162
if (!alreadyExists)
157163
{
158-
GameObject loadButtonObj = new GameObject("MenuLoadButton", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button));
164+
loadButtonObj = new GameObject("MenuLoadButton", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button));
159165
RectTransform loadButtonRect = loadButtonObj.GetComponent<RectTransform>();
160166
loadButtonObj.transform.SetParent(menuParent, false);
161167
loadButtonRect.sizeDelta = new Vector2(70, 60);
@@ -186,7 +192,7 @@ public static void CalculateMenuExtended(this object layerMenuInstance)
186192
wrapperRect.pivot = new Vector2(1f, 1f);
187193
wrapperRect.anchoredPosition = new Vector2(-140f, -30f);
188194

189-
GameObject borderObj = new GameObject("Border", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image));
195+
borderObj = new GameObject("Border", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image));
190196
RectTransform borderRect = borderObj.GetComponent<RectTransform>();
191197
borderObj.transform.SetParent(inputWrapper.transform, false);
192198
borderRect.anchorMin = new Vector2(0.5f, 0.5f);
@@ -226,11 +232,11 @@ public static void CalculateMenuExtended(this object layerMenuInstance)
226232
inputText.color = Color.black;
227233
inputText.fontSize = 30;
228234

229-
InputField inputField = inputObj.GetComponent<InputField>();
235+
inputField = inputObj.GetComponent<InputField>();
230236
inputField.textComponent = inputText;
231237
inputField.text = "3MPYMS";
232238

233-
GameObject versionTextObj = new GameObject("ModVersionText", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text));
239+
versionTextObj = new GameObject("ModVersionText", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text));
234240
RectTransform versionTextRect = versionTextObj.GetComponent<RectTransform>();
235241
versionTextObj.transform.SetParent(menuParent, false);
236242
versionTextRect.sizeDelta = new Vector2(200, 30);

CustomLevels/Extensions/LevelManagerExtension.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ public static IEnumerator HandleGameModeLevelLoad(
4343
if (Director.gameMode == GameMode.SandboxPlay)
4444
{
4545
Debug.Log("Finished Custom Level");
46+
Character leftCharacter = Finder.allCharacters.FirstOrDefault(c => c.transform.position.x < 0f);
47+
Character rightCharacter = Finder.allCharacters.FirstOrDefault(c => c.transform.position.x > 0f);
48+
49+
if (leftCharacter != null && rightCharacter != null)
50+
{
51+
yield return new WaitWhile(() => leftCharacter.moving || rightCharacter.moving);
52+
yield return new WaitForSecondsRealtime(0.1f);
53+
yield return new WaitWhile(() => leftCharacter.moving || rightCharacter.moving);
54+
yield return new WaitForSecondsRealtime(0.2f);
55+
}
56+
if(SteamworksManager.IsCool) { CustomLevelCompleteUI.Show(); }
4657
}
4758
if (Director.gameMode == GameMode.Game || Director.gameMode.ToString() == "3")
4859
{

CustomLevels/Patches/DirectorPatches.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public static void ApplyPatch(HarmonyLib.Harmony harmony)
2929
var prefixVisuals = AccessTools.Method(typeof(DirectorPatches), nameof(InitVisualsPrefix));
3030
harmony.Patch(originalVisuals, prefix: new HarmonyMethod(prefixVisuals));
3131

32+
var originalSandboxPlay = AccessTools.Method(typeof(Director), "InitSandboxPlay");
33+
var postfixSandboxPlay = AccessTools.Method(typeof(DirectorPatches), nameof(PostfixInitSandboxPlay));
34+
harmony.Patch(originalSandboxPlay, postfix: new HarmonyMethod(postfixSandboxPlay));
35+
3236
}
3337

3438
private static void ParseCommandLineArgs()
@@ -133,10 +137,25 @@ public static void PreInitSetGameMode()
133137
if (!string.IsNullOrEmpty(customLevelCode))
134138
{
135139
Director.gameMode = (GameMode)3;
136-
Debug.Log("[Patch] Custom GameMode set to 3 via Postfix in Director.Init");
140+
Debug.Log("[Patch] Custom GameMode set to 3 via Postfix in Director.Init");
137141
}
138142
}
139143

144+
[HarmonyPostfix]
145+
[HarmonyPatch(typeof(Director), "InitSandboxPlay")]
146+
public static void PostfixInitSandboxPlay(Director __instance)
147+
{
148+
if (__instance.editingGameLevel != null)
149+
{
150+
CustomLevelCompleteUI.gameLevelUpload = JsonUtility.ToJson(__instance.editingGameLevel);
151+
}
152+
else
153+
{
154+
Debug.LogWarning("[Patch] editingGameLevel is null; cannot serialize.");
155+
}
156+
}
157+
158+
140159

141160

142161

CustomLevels/Patches/DiscordManagerPatches.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,35 @@
66

77
public static class DiscordManagerPatches
88
{
9-
public static string LevelCodeDiscord;
9+
public static string LevelCodeDiscord;
1010
public static void ApplyPatch(HarmonyLib.Harmony harmony)
1111
{
12-
var original = AccessTools.Method(typeof(DiscordManager), "FixedUpdate");
13-
var prefix = AccessTools.Method(typeof(DiscordManagerPatches), nameof(FixedUpdatePrefix));
14-
harmony.Patch(original, prefix: new HarmonyMethod(prefix));
12+
var originalFixedUpdate = AccessTools.Method(typeof(DiscordManager), "FixedUpdate");
13+
var prefixFixedUpdate = AccessTools.Method(typeof(DiscordManagerPatches), nameof(FixedUpdatePrefix));
14+
harmony.Patch(originalFixedUpdate, prefix: new HarmonyMethod(prefixFixedUpdate));
15+
16+
var originalCreatePresence = AccessTools.Method(typeof(DiscordManager), "CreatePresence");
17+
var prefixCreatePresence = AccessTools.Method(typeof(DiscordManagerPatches), nameof(CreatePresencePrefix));
18+
harmony.Patch(originalCreatePresence, prefix: new HarmonyMethod(prefixCreatePresence));
19+
}
20+
21+
public static bool CreatePresencePrefix(DiscordManager __instance)
22+
{
23+
try
24+
{
25+
var discord = new global::Discord.Discord(1431736823100608655, 1uL);
26+
var activityManager = discord.GetActivityManager();
27+
28+
AccessTools.Field(typeof(DiscordManager), "discord").SetValue(__instance, discord);
29+
AccessTools.Field(typeof(DiscordManager), "activityManager").SetValue(__instance, activityManager);
30+
AccessTools.Field(typeof(DiscordManager), "hasStarted").SetValue(__instance, true);
31+
}
32+
catch (ResultException)
33+
{
34+
AccessTools.Field(typeof(DiscordManager), "hasErrored").SetValue(__instance, true);
35+
}
36+
37+
return false;
1538
}
1639

1740
public static bool FixedUpdatePrefix(DiscordManager __instance)

CustomLevels/Patches/LayerMenuPatches.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Reflection.Emit;
66
using System.Reflection;
7+
using UnityEngine.InputSystem;
78

89
namespace QuadrataPatcher
910
{
@@ -26,6 +27,31 @@ public static bool Prefix_LayerMenu_CalculateMenu(object __instance)
2627
return false;
2728
}
2829

30+
[HarmonyPatch(typeof(LayerMenu), "OpenMenu")]
31+
[HarmonyPostfix]
32+
public static void Postfix_LayerMenu_OpenMenu(LayerMenu __instance, InputAction.CallbackContext ctx)
33+
{
34+
Debug.Log("Opening Menu");
35+
UIController.DelayedTweenMenuElements(Director.instance, true, 0.8f, 0.3f,
36+
LayerMenuExtensions.loadButtonObj?.transform,
37+
LayerMenuExtensions.inputField?.transform,
38+
LayerMenuExtensions.versionTextObj?.transform,
39+
LayerMenuExtensions.borderObj?.transform);
40+
}
41+
42+
[HarmonyPatch(typeof(LayerMenu), "CloseMenu")]
43+
[HarmonyPostfix]
44+
public static void Postfix_LayerMenu_CloseMenu(LayerMenu __instance)
45+
{
46+
UIController.DelayedTweenMenuElements(Director.instance, false, 0.2f, 0.3f,
47+
LayerMenuExtensions.loadButtonObj?.transform,
48+
LayerMenuExtensions.inputField?.transform,
49+
LayerMenuExtensions.versionTextObj?.transform,
50+
LayerMenuExtensions.borderObj?.transform);
51+
}
52+
53+
54+
2955
public static void ApplyPatch(HarmonyLib.Harmony harmony)
3056
{
3157
var originalStart = AccessTools.Method(typeof(LayerMenu), "Start");

0 commit comments

Comments
 (0)