Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Get ready for thunderstore
Browse files Browse the repository at this point in the history
Add bool for if the current UMM build is a dev build
Change UltraModManager to look for mods mods from the bepinex root dir instead of a bepinex dir inside of ultrakill
Change version handler to only notify of an outdated UMM build if UMM is outdated
Change version handler to display a message in the title screen if a dev build is loaded
Add more logs
Improve Logging
  • Loading branch information
Temperz87 committed Jan 19, 2023
1 parent ed41517 commit a6948ba
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
45 changes: 32 additions & 13 deletions UK Mod Manager/API/UKAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using UnityEngine.UI;
using System.Linq;
using UnityEngine.Events;
using System.Diagnostics;

namespace UMM
{
Expand Down Expand Up @@ -50,20 +51,24 @@ internal static IEnumerator InitializeAPI()
if (triedLoadingBundle)
yield break;
SaveFileHandler.LoadData();
Plugin.logger.LogInfo("Trying to load common asset bundle from " + Environment.CurrentDirectory + "\\ULTRAKILL_Data\\StreamingAssets\\common");
AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(Environment.CurrentDirectory + "\\ULTRAKILL_Data\\StreamingAssets\\common");
Stopwatch watch = new Stopwatch();
watch.Start();

string commonAssetBundlePath = Path.Combine(BepInEx.Paths.GameRootPath, "ULTRAKILL_Data\\StreamingAssets\\common");
Plugin.logger.LogInfo("Trying to load common asset bundle from " + commonAssetBundlePath + "\\");
AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(commonAssetBundlePath);
yield return request;
int attempts = 1;
while (request.assetBundle == null)
{
yield return new WaitForSeconds(0.2f); // why 0.2? I dunno I just chose it man
if (attempts >= 5)
{
Plugin.logger.LogInfo("Could not load common asset bundle");
Plugin.logger.LogInfo("Could not load the common asset bundle, not starting UMM.");
triedLoadingBundle = true;
yield break;
}
request = AssetBundle.LoadFromFileAsync(Environment.CurrentDirectory + "\\ULTRAKILL_Data\\StreamingAssets\\common");
request = AssetBundle.LoadFromFileAsync(commonAssetBundlePath);
yield return request;
attempts++;
}
Expand All @@ -84,12 +89,26 @@ internal static IEnumerator InitializeAPI()
SceneManager.sceneLoaded += OnSceneLoad;
string[] arr = Environment.GetCommandLineArgs(); // This is here to ensure that the common asset bundle is loaded correctly before loading a level
if (arr != null)
{
foreach (string str in arr)
{
if (str != null && (str.Contains("sandbox") || str.Contains("uk_construct")))
{
Plugin.logger.LogMessage("Launch argument detected: " + str + ", loading into the sandbox!");
SceneManager.LoadScene("uk_construct");
}
else
{
Plugin.logger.LogMessage("Launch argument detected: " + str + ", but is has no use with UKAPI!");
}
}
}

watch.Stop();
Plugin.logger.LogInfo("UMM startup completed successfully in " + (watch.ElapsedMilliseconds/1000).ToString("0.00") + " seconds"); // Why does C# have to be different in how it formats floats? Why can't I just do %.2f like C?
}


internal static void Update()
{
foreach (UKKeyBind bind in KeyBindHandler.moddedKeyBinds.Values.ToList())
Expand Down Expand Up @@ -151,7 +170,7 @@ public static object LoadCommonAsset(string name)
/// <summary>
/// Enumerated version of the Ultrakill scene types
/// </summary>
public enum UKLevelType { Intro, MainMenu, Level, Endless, Sandbox, Custom, Intermission, Unknown}
public enum UKLevelType { Intro, MainMenu, Level, Endless, Sandbox, Custom, Intermission, Unknown }

/// <summary>
/// Returns the current level type
Expand All @@ -174,7 +193,7 @@ public enum UKLevelType { Intro, MainMenu, Level, Endless, Sandbox, Custom, Inte
private static void OnSceneLoad(Scene scene, LoadSceneMode loadSceneMode)
{
string sceneName = scene.name;
UKLevelType newScene = GetUKLevelType(sceneName);
UKLevelType newScene = GetUKLevelType(sceneName);

if (newScene != CurrentLevelType)
{
Expand All @@ -194,9 +213,9 @@ private static void OnSceneLoad(Scene scene, LoadSceneMode loadSceneMode)
/// <returns></returns>
public static UKLevelType GetUKLevelType(string sceneName)
{
sceneName = (sceneName.Contains("Level")) ? "Level": (sceneName.Contains("Intermission")) ? "Intermission" : sceneName;
sceneName = (sceneName.Contains("Level")) ? "Level" : (sceneName.Contains("Intermission")) ? "Intermission" : sceneName;

switch(sceneName)
switch (sceneName)
{
case "Main Menu":
return UKLevelType.MainMenu;
Expand Down Expand Up @@ -243,7 +262,7 @@ public static UKKeyBind GetKeyBind(string key, KeyCode fallback = KeyCode.None)
}
return bind;
}

/// <summary>
/// Ensures that a <see cref="UKKeyBind"/> exists given a key, if it doesn't exist it won't be created
/// </summary>
Expand All @@ -253,7 +272,7 @@ public static bool EnsureKeyBindExists(string key)
{
return KeyBindHandler.moddedKeyBinds.ContainsKey(key);
}

[Obsolete("Use AllModInfoClone instead.")]
public static Dictionary<string, ModInformation> GetAllModInformation() => AllModInfoClone;

Expand Down Expand Up @@ -301,7 +320,7 @@ internal static void LoadData()
{
path = Assembly.GetExecutingAssembly().Location;
path = path.Substring(0, path.LastIndexOf("\\")) + "\\persistent mod data.json";
Plugin.logger.LogInfo("Trying to mod persistent data file from " + path);
Plugin.logger.LogInfo("Trying to load persistent mod data.json from " + path);
FileInfo fInfo = new FileInfo(path);
if (fInfo.Exists)
{
Expand Down Expand Up @@ -406,7 +425,7 @@ internal static void LoadKeyBinds() // Copilot basically wrote this code
string[] keyBindData = keyBind.Split(':');
if (keyBindData.Length == 2)
{
Debug.Log("Loading keybind" + keyBindData[0] + " : " + keyBindData[1]);
Plugin.logger.LogMessage("Loading keybind" + keyBindData[0] + " : " + keyBindData[1]);
UKKeyBind bind = new UKKeyBind(new InputAction(keyBindData[0], InputActionType.Value, null, null, null, null), keyBindData[0], (KeyCode)Enum.Parse(typeof(KeyCode), keyBindData[1]));
moddedKeyBinds.Add(keyBindData[0], bind);
}
Expand Down
10 changes: 9 additions & 1 deletion UK Mod Manager/Harmony Patches/Mod UI Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ void Halve(Transform tf, bool left)
outDatedButton.GetComponentInChildren<Image>().color = new Color32(69, 0, 69, 255);
outDatedButton.GetComponentInChildren<WebButton>().url = "https://github.com/Temperz87/ultra-mod-manager/releases/tag/" + UltraModManager.newLoaderVersion;
}
else if (UltraModManager.devBuild)
{
GameObject devBuildButton = GameObject.Instantiate(discordButton, discordButton.transform.parent);
devBuildButton.GetComponent<RectTransform>().anchoredPosition = new Vector2(492f, -461f);
devBuildButton.GetComponentInChildren<Text>().text = "DEV BUILD: " + UltraModManager.newLoaderVersion.Trim();
devBuildButton.GetComponentInChildren<Image>().color = new Color32(69, 0, 69, 255);
devBuildButton.GetComponentInChildren<WebButton>().url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ" + UltraModManager.newLoaderVersion;
}
GameObject modsMenu = GameObject.Instantiate(__instance.optionsMenu, __instance.transform);
modsMenu.SetActive(false);
for (int i = 0; i < modsMenu.transform.childCount; i++)
Expand Down Expand Up @@ -181,7 +189,7 @@ void Halve(Transform tf, bool left)
hoverText.SetActive(true);
hoverText.transform.localPosition += new Vector3(0f, 260f, 0f);
Text hText = hoverText.GetComponentInChildren<Text>();
hText.text = "NO MODS FOUND\n" + Environment.CurrentDirectory + @"\BepInEx\UMM Mods\";
hText.text = "NO MODS FOUND\n" + UltraModManager.modsDirectory;
hText.horizontalOverflow = HorizontalWrapMode.Wrap;
hText.verticalOverflow = VerticalWrapMode.Overflow;
hText.fontSize /= 2;
Expand Down
5 changes: 3 additions & 2 deletions UK Mod Manager/UltraModManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ namespace UMM.Loader
{
public static class UltraModManager
{
public static DirectoryInfo modsDirectory = new DirectoryInfo(Path.Combine(BepInEx.Paths.BepInExRootPath, "UMM Mods\\"));
public static Dictionary<string, ModInformation> foundMods = new Dictionary<string, ModInformation>();
public static Dictionary<string, ModInformation> allLoadedMods = new Dictionary<string, ModInformation>();
public static bool outdated { get; internal set; } = false;
public static bool devBuild { get; internal set; } = false;
public static string newLoaderVersion { get; internal set; } = "";
private static bool initialized = false;
private static Dictionary<ModInformation, GameObject> modObjects = new Dictionary<ModInformation, GameObject>();
Expand All @@ -30,12 +32,11 @@ internal static void InitializeManager()

private static void CollectAssemblies()
{
DirectoryInfo modsDirectory = new DirectoryInfo(Environment.CurrentDirectory + @"\BepInEx\UMM Mods\");
if (modsDirectory.Exists)
foreach (FileInfo info in modsDirectory.GetFiles("*.dll", SearchOption.AllDirectories))
LoadFromAssembly(info);
else
Directory.CreateDirectory(Environment.CurrentDirectory + @"\BepInEx\UMM Mods\");
modsDirectory.Create(); // TODO: Test this to make sure it works, because I don't know if it does
Plugin.logger.LogInfo("Found " + foundMods.Count + " mods that can be loaded.");
}

Expand Down
14 changes: 12 additions & 2 deletions UK Mod Manager/VersionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,18 @@ public static IEnumerator CheckVersion()
string latestVersion = jObjects[0].Value<string>("name");
if (latestVersion != VERSION)
{
Plugin.logger.LogWarning("New UMM version found: " + latestVersion + " while the current version is " + VERSION);
UltraModManager.outdated = true;
// Check current version string against the newer one
if (VERSION.CompareTo(latestVersion) < 0)
{

Plugin.logger.LogWarning("New UMM version found: " + latestVersion + " while the current version is: " + VERSION + ", consider upgrading to the new version.");
UltraModManager.outdated = true;
}
else
{
Plugin.logger.LogWarning("Latest available UMM build is: " + latestVersion + " while the current version is: " + VERSION + ", be warned that in a dev build mods, or UMM itself, can break.");
UltraModManager.devBuild = true;
}
UltraModManager.newLoaderVersion = latestVersion;
}
else
Expand Down

0 comments on commit a6948ba

Please sign in to comment.