Skip to content

Commit

Permalink
Fix for new uk version
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydraxous committed May 16, 2023
1 parent 9f20112 commit 3f144c9
Show file tree
Hide file tree
Showing 15 changed files with 578 additions and 42 deletions.
2 changes: 2 additions & 0 deletions Assets.cs
Expand Up @@ -7,6 +7,7 @@ public static class Assets
public static GameObject BossRushStatsPrefab { get; private set; }
public static GameObject BossRushMenuPrefab { get; private set; }

public static GameObject BossRushDeathScreen { get; private set; }

public static AssetBundle assets;

Expand All @@ -16,6 +17,7 @@ public static void LoadAssets()

BossRushStatsPrefab = assets.LoadAsset<GameObject>("BossRushStatsDisplay");
BossRushMenuPrefab = assets.LoadAsset<GameObject>("BossRushMenu");
BossRushDeathScreen = assets.LoadAsset<GameObject>("BossRushDeathScreen");
}


Expand Down
35 changes: 35 additions & 0 deletions BossRush.cs
@@ -1,14 +1,21 @@
using BepInEx;
using BepInEx.Logging;
using BossRush.UI;
using HarmonyLib;
using HydraDynamics;
using UnityEngine;

namespace BossRush
{
[BepInDependency("Hydraxous.HydraDynamics", BepInDependency.DependencyFlags.HardDependency)]
[HydynamicsInfo(ConstInfo.NAME, ConstInfo.GUID, "Boss Rush Gamdemode")]
[BepInPlugin(ConstInfo.GUID, ConstInfo.NAME, ConstInfo.VERSION)]
public class BossRush : BaseUnityPlugin
{
public static BossRush Instance { get; private set; }
public static ManualLogSource Logr => Instance.Logger;
public static bool LatestVersion { get; private set; }
public static string VersionName { get; private set; }
Harmony harmony;

private bool debug = false;
Expand All @@ -18,6 +25,7 @@ private void Awake()
Instance = this;
BossRushConfig.Bind();
Logger.LogInfo("Boss Rush loaded!");
VersionCheck.CheckVersion(ConstInfo.GITHUB_URL, ConstInfo.VERSION, VersionCheckCallback);
harmony = new Harmony(ConstInfo.GUID + ".harmony");
harmony.PatchAll();
Assets.LoadAssets();
Expand All @@ -27,7 +35,23 @@ private void Awake()
private void Update()
{
CheckDebugInputs();
}

private void VersionCheckCallback(bool onLatest, string versionName)
{
LatestVersion = onLatest;
VersionName = versionName;
if (versionName == "UNKNOWN")
{
LatestVersion = true;
VersionName = ConstInfo.VERSION;
}

if(LatestVersion)
Debug.Log($"BOSSRUSH: You are using the latest version of BossRush ({VersionName}).");
else
Debug.LogWarning($"BOSSRUSH: You are using an outdated version of BossRush ({ConstInfo.VERSION}). Please consider updating to {VersionName}");

}

private void CheckDebugInputs()
Expand Down Expand Up @@ -74,6 +98,17 @@ private void CheckDebugInputs()
BossRushController.Laps = 0;
Debug.Log($"BR: Laps={BossRushController.Laps}");
}

if (Input.GetKeyDown(KeyCode.Alpha8))
{
StatRecords.SubmitRecord(BossRushController.GetCurrentStat());
Debug.Log($"BR: Laps={BossRushController.Laps}");
}
}

private void OnApplicationQuit()
{
StatRecords.Save();
}
}
}
6 changes: 5 additions & 1 deletion BossRush.csproj
Expand Up @@ -17,6 +17,7 @@
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.*" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="UnityEngine.Modules" Version="2019.4.16" IncludeAssets="compile" />
</ItemGroup>

Expand Down Expand Up @@ -84,6 +85,9 @@
<Reference Include="UnityEngine.UnityWebRequestModule">
<HintPath>$(ULTRAKILLPath)\ULTRAKILL_Data\Managed\UnityEngine.UnityWebRequestModule.dll</HintPath>
</Reference>
<Reference Include="HydraDynamics">
<HintPath>$(ULTRAKILLPath)\BepInEx\plugins\HydraDynamics\HydraDynamics.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
Expand All @@ -109,7 +113,7 @@
<Error Condition="!Exists($(ULTRAKILLPath))" Text="ULTRAKILLPath not set, create a .csproj.user file that sets this property to compile" />
</Target>
<Target Name="CopyModDlls" AfterTargets="AfterBuild">
<Copy SourceFiles="$(OutDir)/$(AssemblyName).dll" DestinationFolder="$(ULTRAKILLPath)\BepInEx\Plugins\UFG\" />
<Copy SourceFiles="$(OutDir)/$(AssemblyName).dll" DestinationFolder="$(ULTRAKILLPath)\BepInEx\Plugins\BossRush\" />
</Target>
<Target Name="CopyModDlls2" AfterTargets="AfterBuild">
<Copy SourceFiles="$(OutDir)/$(AssemblyName).dll" DestinationFolder="$(UnityKitPath)" />
Expand Down
12 changes: 11 additions & 1 deletion BossRushController.cs
@@ -1,4 +1,5 @@
using UnityEngine;
using System;
using UnityEngine;

namespace BossRush
{
Expand All @@ -11,6 +12,8 @@ public static class BossRushController

private static float startTime;

public static long StartTimeEpoc { get; internal set; }

//Returns time since the Boss Rush started.
public static float TimeElapsed
{
Expand Down Expand Up @@ -38,9 +41,16 @@ public static void Reset()
{
BossRushMode = false;
HardcoreMode = false;
StatRecords.HighScoreRun = false;
startTime = Time.time;
StartTimeEpoc = DateTimeOffset.Now.ToUnixTimeSeconds();
Deaths = 0;
Laps = 0;
}

public static BossRushRecord GetCurrentStat()
{
return new BossRushRecord(Laps, TimeElapsed, Deaths, HardcoreMode);
}
}
}
4 changes: 2 additions & 2 deletions ConstInfo.cs
Expand Up @@ -4,7 +4,7 @@ public static class ConstInfo
{
public const string GUID = "Hydraxous.ULTRAKILL.BossRush";
public const string NAME = "BossRush";
public const string VERSION = "1.0.0";
public const string GITHUB_URL = "https://github.com/Hydraxous/BossRush";
public const string VERSION = "1.1.0";
public const string GITHUB_URL = "https://api.github.com/repos/Hydraxous/bossrush/tags";
}
}
51 changes: 51 additions & 0 deletions DiscordRPCPatch.cs
@@ -0,0 +1,51 @@
using BepInEx;
using Discord;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

namespace BossRush
{
[HarmonyPatch(typeof(DiscordController))]
public static class DiscordRPCPatch
{
[HarmonyPrefix]
[HarmonyPatch("SendActivity")]
public static bool Prefix(ref Activity ___cachedActivity)
{
if (!BossRushController.BossRushMode)
return true;

___cachedActivity.Details = $"BOSS RUSH: {ParseDifficultyName(PrefsManager.Instance.GetInt("difficulty"))}";
string deathString = (BossRushController.HardcoreMode) ? "HARDCORE" : $"DEATHS: {BossRushController.Deaths.ToString("000")}";
___cachedActivity.State = $"LAPS: {BossRushController.Laps.ToString("000")} | {deathString}";
___cachedActivity.Timestamps.Start = BossRushController.StartTimeEpoc;

return true;
}

private static string ParseDifficultyName(int diff)
{
switch (diff)
{
case 0:
return "HARMLESS";
case 1:
return "LENIENT";
case 2:
return "STANDARD";
case 3:
return "VIOLENT";
case 4:
return "BRUTAL";
case 5:
return "UKMD";

default:
return "Game Journalist";
}
}
}
}
40 changes: 33 additions & 7 deletions GamePatch.cs
Expand Up @@ -7,7 +7,7 @@

namespace BossRush
{
[HarmonyPatch(typeof(FinalRank), nameof(FinalRank.StartLoadingNextLevel))]
[HarmonyPatch(typeof(FinalRank), nameof(FinalRank.LevelChange))]
public static class FinalRankPatch
{
private static Dictionary<string, string> levelAssociations = new Dictionary<string, string>()
Expand Down Expand Up @@ -35,12 +35,16 @@ public static bool Prefix(FinalRank __instance)
//Gets the next boss level from the dictionary, if its not present, returns original.
public static string ResolveLevelName(string targetLevel)
{

if (levelAssociations.ContainsKey(targetLevel))
{
string nextLevel = levelAssociations[targetLevel];
//Level 0-5 indicates the player has just completed P-2
if (nextLevel == "Level 0-5")
{
++BossRushController.Laps;
StatRecords.SubmitRecord(BossRushController.GetCurrentStat());
}

return nextLevel;
}
Expand Down Expand Up @@ -97,7 +101,7 @@ public static void Postfix()

if (BossRushController.HardcoreMode)
{
BossRushController.StartBossRushMode(true);
BossRushDeathScreen.Instance.Open();
return;
}

Expand All @@ -121,7 +125,14 @@ public static bool Prefix(NewMovement __instance, int damage, bool invincible)
//Restart if hardcore and dead
if (__instance.hp - damage <= 0)
{
BossRushController.StartBossRushMode(true);
try
{
BossRushDeathScreen.Instance.Open();
} catch (System.Exception e)
{
Debug.LogException(e);
return true;
}
return false;
}

Expand Down Expand Up @@ -164,11 +175,13 @@ public static class MainMenuUIPatch
{
public static void Postfix(CanvasController __instance)
{
if (SceneManager.GetActiveScene().name != "Main Menu")
return;
SpawnDeathScreen(__instance);

SpawnMenu(__instance);
SpawnButton(__instance);
if (SceneHelper.CurrentScene == "Main Menu")
{
SpawnMenu(__instance);
SpawnButton(__instance);
}
}

//Instantiates the Boss Rush Menu
Expand All @@ -179,14 +192,27 @@ private static void SpawnMenu(CanvasController __instance)
if (canvasRectTransform == null)
return;

BossRush.Logr.LogInfo("Menu Spawned");
GameObject.Instantiate(Assets.BossRushMenuPrefab, canvasRectTransform);
}

private static void SpawnDeathScreen(CanvasController __instance)
{
RectTransform canvasRectTransform = __instance.GetComponent<RectTransform>();

if (canvasRectTransform == null)
return;

BossRush.Logr.LogInfo("DeathScreen Spawned");
GameObject.Instantiate(Assets.BossRushDeathScreen, canvasRectTransform);
}


//Duplicates sandbox button and configures it to open Boss rush menu
//Kind of icky but it works.
private static void SpawnButton(CanvasController __instance)
{
BossRush.Logr.LogInfo("Spawning Button");
RectTransform canvasRectTransform = __instance.GetComponent<RectTransform>();
GameObject chapterSelectObject = canvasRectTransform.Find("Chapter Select").gameObject;
if (chapterSelectObject == null)
Expand Down

0 comments on commit 3f144c9

Please sign in to comment.