Skip to content

Commit

Permalink
Fixed issues caused by recent Game Update
Browse files Browse the repository at this point in the history
  • Loading branch information
HerpDerpinstine committed Oct 1, 2024
1 parent 346a247 commit eec8373
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 37 deletions.
2 changes: 1 addition & 1 deletion DDSS.ModHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<PackageReference Include="Il2CppInterop.Runtime" Version="1.4.5">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="LavaGang.MelonLoader" Version="0.6.4">
<PackageReference Include="LavaGang.MelonLoader" Version="0.6.5">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3">
Expand Down
2 changes: 1 addition & 1 deletion Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override void OnInitializeMelon()
ApplyPatch<Patch_ConsoleController>();
ApplyPatch<Patch_KeyBindingObject>();
ApplyPatch<Patch_LobbyBrowserTab>();
ApplyPatch<Patch_LocalizedText>();
ApplyPatch<Patch_LocalizationManager>();
ApplyPatch<Patch_NetworkIdentity>();
ApplyPatch<Patch_SettingObject>();
ApplyPatch<Patch_SettingsManager>();
Expand Down
17 changes: 17 additions & 0 deletions Patches/Patch_LobbyBrowserTab.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using DDSS_ModHelper.Utils;
using HarmonyLib;
using Il2Cpp;
using Il2CppLocalization;
using Il2CppSteamworks;
using Il2CppTMPro;
using System.Collections;
using UnityEngine;

Expand All @@ -16,6 +18,21 @@ private static bool UpdateTab_Prefix(LobbyBrowserTab __instance)
// Apply Grid Layout Height
__instance.SetGridlayoutHeight();

// Get Header Text
Transform titleTrans = __instance.transform.Find("Tab/LobbyList/TopBar/Title");
if (titleTrans != null)
{
// Apply Header Text
TextMeshProUGUI titleText = titleTrans.GetComponentInChildren<TextMeshProUGUI>();
if (titleText != null)
titleText.text = "Modded Lobby Browser";

// Remove Localization
LocalizedText localized = titleTrans.GetComponentInChildren<LocalizedText>();
if (localized != null)
UnityEngine.Object.Destroy(localized);
}

// Run new Coroutine
__instance.StartCoroutine(UpdateLobbyList(__instance));

Expand Down
33 changes: 33 additions & 0 deletions Patches/Patch_LocalizationManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppInterop.Runtime.InteropTypes.Arrays;

namespace DDSS_ModHelper.Patches
{
internal class Patch_LocalizationManager
{
[HarmonyPrefix]
[HarmonyPatch(typeof(LocalizationManager), nameof(LocalizationManager.GetLocalizedValue), typeof(string))]
private static bool GetLocalizedValue_1_Prefix(string __0)
{
// Validate Key
if (string.IsNullOrEmpty(__0))
return false;

// Run Original
return true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(LocalizationManager), nameof(LocalizationManager.GetLocalizedValue), typeof(string), typeof(Il2CppStringArray))]
private static bool GetLocalizedValue_2_Prefix(string __0)
{
// Validate Key
if (string.IsNullOrEmpty(__0))
return false;

// Run Original
return true;
}
}
}
23 changes: 0 additions & 23 deletions Patches/Patch_LocalizedText.cs

This file was deleted.

13 changes: 8 additions & 5 deletions Patches/Patch_SettingObject.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DDSS_ModHelper.Settings;
using DDSS_ModHelper.Settings.Internal;
using DDSS_ModHelper.Utils;
using HarmonyLib;
using Il2Cpp;
using Il2CppUI.Tabs.SettingsTab;
Expand Down Expand Up @@ -48,8 +49,8 @@ private static bool ChangeMultiChoice_Prefix(SettingObject __instance, int __0)
entry.GetReflectedType(),
__0,
__instance.setting.Value,
__instance.setting.alternatives[1],
__instance.setting.alternatives[2]);
__instance.setting.alternatives[1].key,
__instance.setting.alternatives[2].key);
__instance.UpdateMultiChoice();

// Prevent Original
Expand Down Expand Up @@ -80,15 +81,17 @@ private static void SetSetting_Prefix(Setting __0)
if (__0.Key == "Max players")
{
// Change Max Value to 99
__0.alternatives[1] = "99";
__0.alternatives[1].key = "99";
__0.alternatives[1].label = "99";
}

// Check for Frame Rate
if (__0.Key == "Frame Rate")
{
// Add Unlimited Frame Rate
if (!__0.alternatives.Contains("Unlimited"))
__0.alternatives.Add("Unlimited");
SettingAlternative alt = __0.FindAlternativeByKey("Unlimited");
if (alt == null)
__0.alternatives.Add(new("Unlimited", "Unlimited"));
}
}

Expand Down
12 changes: 12 additions & 0 deletions Patches/Patch_SettingsTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ private static bool ShowSettings_Prefix(SettingsTab __instance)
return false;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(SettingsTab), nameof(SettingsTab.ShowCategories))]
private static bool ShowCategories_Prefix(SettingsTab __instance)
{
// Check for Mod Settings Tab
if (__instance != ModSettingsManager._tab)
return true;

// Prevent Original
return false;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(SettingsTab), nameof(SettingsTab.ApplyAllSettings))]
private static bool ApplyAllSettings_Prefix(SettingsTab __instance)
Expand Down
2 changes: 1 addition & 1 deletion Properties/BuildInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal static class BuildInfo
public const string Description = "Custom Modding API for Dale & Dawson";
public const string Author = "Herp Derpinstine";
public const string Company = "Lava Gang";
public const string Version = "1.1.0";
public const string Version = "1.1.1";
public const string DownloadLink = "https://github.com/HerpDerpinstine/DDSS.ModHelper";
}
}
19 changes: 13 additions & 6 deletions Settings/Internal/ModSettingsOptionBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Il2Cpp;
using Il2CppLocalization;
using Il2CppUI.Tabs.SettingsTab;
using System;
using UnityEngine;
Expand All @@ -16,6 +17,11 @@ private static SettingObject CreateObject(Setting setting)
ModSettingsManager._tab.settingsParent);
SettingObject settingObj = obj.GetComponent<SettingObject>();
settingObj.SetSetting(setting, GameSettingsManager.instance, true, true);

LocalizedText localizedText = obj.GetComponent<LocalizedText>();
if (localizedText != null)
GameObject.Destroy(localizedText);

return settingObj;
}

Expand All @@ -25,6 +31,7 @@ private static Setting CreateSetting(string name,
{
Setting setting = new();
setting.devOnly = false;
setting.label = name;
setting.Key = name;
setting.presetName = string.Empty;
setting.type = type;
Expand All @@ -49,8 +56,8 @@ internal static SettingObject CreateToggle(string name,
{
Setting setting = CreateSetting(name, description);
setting.alternatives = new();
setting.alternatives.Add("OFF");
setting.alternatives.Add("ON");
setting.alternatives.Add(new("OFF", "OFF"));
setting.alternatives.Add(new("ON", "ON"));
setting.Value = value ? 1f : 0f;
return CreateObject(setting);
}
Expand All @@ -66,9 +73,9 @@ internal static SettingObject CreateNumber<T>(
Setting setting = CreateSetting(name, description);
setting.axisName = "MODDED";
setting.alternatives = new();
setting.alternatives.Add(typeof(float).FullName);
setting.alternatives.Add(minValue.ToString());
setting.alternatives.Add(maxValue.ToString());
setting.alternatives.Add(new(typeof(float).FullName, typeof(float).FullName));
setting.alternatives.Add(new(minValue.ToString(), minValue.ToString()));
setting.alternatives.Add(new(maxValue.ToString(), maxValue.ToString()));

if (typeof(T) == typeof(float))
setting.Value = (float)Math.Round(Convert.ToDouble(value), 1, MidpointRounding.AwayFromZero);
Expand All @@ -88,7 +95,7 @@ internal static SettingObject CreateEnum(string name,

string[] valueNames = Enum.GetNames(enumType);
foreach (string valueName in valueNames)
setting.alternatives.Add(valueName);
setting.alternatives.Add(new(valueName, valueName));

int valueIndex = 0;
Array allValues = Enum.GetValues(enumType);
Expand Down
25 changes: 25 additions & 0 deletions Settings/Internal/ModSettingsPanelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ internal static void Create(ref SettingsTab tab,
tab.scrollRect.verticalScrollbar.value = 1f;
tab.scrollRect.SetDirty();

// Move and Stretch Scroll View
Vector2 scrollViewOffset = tab.scrollRect.rectTransform.offsetMax;
scrollViewOffset.y += 46f;
tab.scrollRect.rectTransform.offsetMax = scrollViewOffset;

// Move and Stretch Viewport
Vector2 viewportOffset = tab.scrollRect.viewRect.offsetMax;
viewportOffset.y += 44f;
tab.scrollRect.viewRect.offsetMax = viewportOffset;

// Change Original Title
Transform titleTrans = comp.transform.Find("Tab/Tasks/TopBar/Title");
if (titleTrans != null)
Expand All @@ -59,6 +69,21 @@ internal static void Create(ref SettingsTab tab,
UnityEngine.Object.Destroy(localized);
}

// Remove Extra Categories Buttons
Transform categoriesGrid = _settingsTabObj.transform.Find("Tab/Tasks/CatagoriesGrid");
if (categoriesGrid != null)
GameObject.Destroy(categoriesGrid.gameObject);

// Move and Stretch Scroll View Background
Transform backgroundTrans = _settingsTabObj.transform.Find("Tab/Tasks/Background");
if (cloneTitleTrans != null)
{
RectTransform rectTrans = backgroundTrans.GetComponent<RectTransform>();
Vector2 rectOffset = rectTrans.offsetMax;
rectOffset.y += 44f;
rectTrans.offsetMax = rectOffset;
}

break;
}
}
Expand Down
11 changes: 11 additions & 0 deletions Utils/ModHelperExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DDSS_ModHelper.Components;
using Il2Cpp;
using System;
using System.Collections;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -43,5 +44,15 @@ public static void RemoveListener(this UnityEvent action,
public static void RemoveListener<T>(this UnityEvent<T> action,
Action<T> listener)
=> action.RemoveListener(listener);

public static SettingAlternative FindAlternativeByKey(this Setting setting, string key)
{
if (setting.alternatives == null)
return null;
foreach (var alternative in setting.alternatives)
if (alternative.key == key)
return alternative;
return null;
}
}
}

0 comments on commit eec8373

Please sign in to comment.