Skip to content

Commit

Permalink
Merge pull request NebulaModTeam#703 from starfi5h/pr-bugfix
Browse files Browse the repository at this point in the history
Nebula DSP 0.10.30.23430 Update
  • Loading branch information
starfi5h authored Aug 31, 2024
2 parents e4dde47 + 8b596cd commit c03e3e5
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/thunderstore_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function generateManifest() {
BEPINEX_DEPENDENCY,
`nebula-${apiPluginInfo.name}-${apiPluginInfo.version}`,
"PhantomGamers-IlLine-1.0.0",
"starfi5h-BulletTime-1.4.8",
"starfi5h-BulletTime-1.5.1",
],
website_url: "https://github.com/hubastard/nebula"
};
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog

0.9.9:
- @starfi5h: Fix multiplayer tab in the option window for DSP v0.10.30.23430
- @starfi5h: Separate error close button (x) and copy button
- @starfi5h: Sync WarningBroadcastData: LandingRelay, ApproachingSeed, BuildingDestroyed and 3 more

0.9.8:
- @AlienXAXS: Added Online Player UI (Backtick key by default)
- @AlienXAXS: Updated Nebula to be compatible with Dyson Sphere Program v0.10.30.23292
Expand Down
8 changes: 5 additions & 3 deletions NebulaPatcher/NebulaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using NebulaPatcher.Logger;
using NebulaPatcher.MonoBehaviours;
using NebulaPatcher.Patches.Dynamic;
using NebulaPatcher.Patches.Misc;
using NebulaWorld;
using NebulaWorld.GameStates;
using NebulaWorld.SocialIntegration;
Expand Down Expand Up @@ -156,7 +157,7 @@ private void Awake()
}
else if (newgameArgExists)
{
Log.Error(">> New game parameters incorrect! Exiting...\nExpect: -newgame seed starCount resourceMltiplier");
Log.Error(">> New game parameters incorrect! Exiting...\nExpect: -newgame seed starCount resourceMultiplier");
}
else
{
Expand Down Expand Up @@ -264,7 +265,7 @@ public static void SetGameDescFromConfigFile(GameDesc gameDesc)
}

var resourceMultiplier = customFile.Bind("Basic", "resourceMultiplier", -1f,
"Resource Multiplier. Infinte = 100. Negative value: Default(1.0f) or remain the same.").Value;
"Resource Multiplier. Infinite = 100. Negative value: Default(1.0f) or remain the same.").Value;
if (resourceMultiplier >= 0f)
{
gameDesc.resourceMultiplier = resourceMultiplier;
Expand Down Expand Up @@ -375,10 +376,11 @@ private static void InitPatches()
}
#endif
var harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), PluginInfo.PLUGIN_ID);
harmony.PatchAll(typeof(Fix_Patches));
if (Multiplayer.IsDedicated)
{
Log.Info("Patching for headless mode...");
harmony.PatchAll(typeof(Dedicated_Server_Patch));
harmony.PatchAll(typeof(Dedicated_Server_Patches));
}
#if DEBUG
Environment.SetEnvironmentVariable("MONOMOD_DMD_DUMP", "");
Expand Down
117 changes: 89 additions & 28 deletions NebulaPatcher/Patches/Dynamic/UIFatalErrorTip_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ namespace NebulaPatcher.Patches.Dynamic;
[HarmonyPatch(typeof(UIFatalErrorTip))]
internal class UIFatalErrorTip_Patch
{
private static GameObject button;
private static UIButton btnClose;
private static UIButton btnCopy;

[HarmonyPostfix]
[HarmonyPatch(nameof(UIFatalErrorTip._OnRegEvent))]
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")]
public static void _OnRegEvent_Postfix()
{
// If there is errer message before game begin, we will show to user here
// If there is error message before game begin, we will show to user here
if (Log.LastErrorMsg == null)
{
return;
Expand All @@ -36,33 +37,19 @@ public static void _OnRegEvent_Postfix()
Log.LastErrorMsg = null;
}

[HarmonyPostfix]
[HarmonyPostfix, HarmonyAfter("aaa.dsp.plugin.ErrorAnalyzer")]
[HarmonyPatch(nameof(UIFatalErrorTip._OnOpen))]
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")]
public static void _OnOpen_Postfix()
public static void _OnOpen_Postfix(UIFatalErrorTip __instance)
{
try
{
if (button == null)
{
button = GameObject.Find(
"UI Root/Overlay Canvas/In Game/Windows/Dyson Sphere Editor/Dyson Editor Control Panel/hierarchy/layers/blueprint-group/blueprint-2/copy-button");
var errorPanel = GameObject.Find("UI Root/Overlay Canvas/Fatal Error/errored-panel/");
errorPanel.transform.Find("tip-text-0").GetComponent<Text>().text = Title();
Object.Destroy(errorPanel.transform.Find("tip-text-0").GetComponent<Localizer>());
errorPanel.transform.Find("tip-text-1").GetComponent<Text>().text = Title();
Object.Destroy(errorPanel.transform.Find("tip-text-1").GetComponent<Localizer>());
button = Object.Instantiate(button, errorPanel.transform);
button.name = "Copy & Close button";
button.transform.localPosition =
errorPanel.transform.Find("icon").localPosition + new Vector3(30, -35, 0); //-885 -30 //-855 -60
button.GetComponent<Image>().color = new Color(0.3113f, 0f, 0.0097f, 0.6f);
button.GetComponent<UIButton>().BindOnClickSafe(OnClick);
ref var tips = ref button.GetComponent<UIButton>().tips;
tips.tipTitle = "Copy & Close Error";
tips.tipText = "Copy the message to clipboard and close error.";
tips.corner = 1;
}
TryCreateButton(() => CreateCloseBtn(__instance), "Close Button");
TryCreateButton(() => CreateCopyBtn(__instance), "Copy Button");
__instance.transform.Find("tip-text-0").GetComponent<Text>().text = Title();
__instance.transform.Find("tip-text-1").GetComponent<Text>().text = Title();
Object.Destroy(__instance.transform.Find("tip-text-0").GetComponent<Localizer>());
Object.Destroy(__instance.transform.Find("tip-text-1").GetComponent<Localizer>());

DedicatedServerReportError();
}
Expand All @@ -72,6 +59,78 @@ public static void _OnOpen_Postfix()
}
}

[HarmonyPostfix]
[HarmonyPatch(nameof(UIFatalErrorTip._OnClose))]
public static void _OnClose_Postfix()
{
if (btnClose != null)
{
Object.Destroy(btnClose.gameObject);
btnClose = null;
}
if (btnCopy != null)
{
Object.Destroy(btnCopy.gameObject);
btnCopy = null;
}
}

private static void TryCreateButton(Action createAction, string buttonName)
{
try
{
createAction();
}
catch (Exception e)
{
Log.Warn($"{buttonName} did not patch!\n{e}");
}
}

private static UIButton CreateButton(string path, Transform parent, Vector3 positionOffset, Action<int> onClickAction)
{
var go = GameObject.Find(path);
return CreateButton(go, parent, positionOffset, onClickAction);
}

private static UIButton CreateButton(GameObject originalGo, Transform parent, Vector3 positionOffset, Action<int> onClickAction)
{
if (originalGo != null)
{
var go = Object.Instantiate(originalGo, parent);
var rect = (RectTransform)go.transform;
rect.anchorMin = Vector2.up;
rect.anchorMax = Vector2.up;
rect.pivot = Vector2.up;
rect.anchoredPosition = positionOffset;
go.SetActive(true);

var button = go.GetComponent<UIButton>();
button.onClick += onClickAction;
button.tips.corner = 1;
return button;
}
return null;
}

private static void CreateCloseBtn(UIFatalErrorTip __instance)
{
if (btnClose != null) return;

const string PATH = "UI Root/Overlay Canvas/In Game/Windows/Window Template/panel-bg/btn-box/close-btn";
btnClose = CreateButton(PATH, __instance.transform, new Vector3(-5, 0, 0), OnCloseClick);
}

private static void CreateCopyBtn(UIFatalErrorTip __instance)
{
if (btnCopy != null) return;

const string PATH = "UI Root/Overlay Canvas/In Game/Windows/Dyson Sphere Editor/Dyson Editor Control Panel/hierarchy/layers/blueprint-group/blueprint-2/copy-button";
btnCopy = CreateButton(PATH, __instance.transform, new Vector3(5, -55, 0), OnCopyClick);
btnCopy.tips.tipTitle = "Copy Error".Translate();
btnCopy.tips.tipText = "Copy the message to clipboard".Translate();
}

private static void DedicatedServerReportError()
{
// OnOpen only run once for the first error report
Expand Down Expand Up @@ -108,7 +167,12 @@ private static string Title()
return stringBuilder.ToString();
}

private static void OnClick(int id)
private static void OnCloseClick(int _)
{
UIFatalErrorTip.ClearError();
}

private static void OnCopyClick(int id)
{
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine("```ini");
Expand Down Expand Up @@ -146,8 +210,5 @@ private static void OnClick(int id)

// Copy string to clipboard
GUIUtility.systemCopyBuffer = stringBuilder.ToString();
UIFatalErrorTip.ClearError();
Object.Destroy(button);
button = null;
}
}
27 changes: 14 additions & 13 deletions NebulaPatcher/Patches/Dynamic/UIOptionWindow_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace NebulaPatcher.Patches.Dynamic;
[HarmonyPatch(typeof(UIOptionWindow))]
internal class UIOptionWindow_Patch
{
private const float subtabOffest = 160f;
private const float SubtabOffset = 160f;

// Templates
private static RectTransform checkboxTemplate;
Expand All @@ -51,8 +51,8 @@ internal class UIOptionWindow_Patch
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")]
public static void _OnCreate_Postfix(UIOptionWindow __instance)
{
tempToUICallbacks = new Dictionary<string, Action>();
tempMultiplayerOptions = new MultiplayerOptions();
tempToUICallbacks = new();
tempMultiplayerOptions = new();

// Add multiplayer tab button
var tabButtons = __instance.tabButtons;
Expand All @@ -76,9 +76,10 @@ public static void _OnCreate_Postfix(UIOptionWindow __instance)
__instance.tabTexts = newTabTexts;

// Add multiplayer tab content
// Instantiate from "Miscellaneous" tab which has no scroll elements (yet)
var tabTweeners = __instance.tabTweeners;
var contentTemplate = tabTweeners[0].GetComponent<RectTransform>();
multiplayerContent = Object.Instantiate(contentTemplate, contentTemplate.parent, true);
var contentRectTransform = tabTweeners[4].GetComponent<RectTransform>();
multiplayerContent = Object.Instantiate(contentRectTransform, contentRectTransform.parent, true);
multiplayerContent.name = "multiplayer-content";
multiplayerContent.localPosition += new Vector3(0, -65, 0);

Expand All @@ -99,7 +100,7 @@ public static void _OnCreate_Postfix(UIOptionWindow __instance)
}
}

// Add subtab-bar for config catagories
// Add subtab-bar for config categories
var subtabsBar = (RectTransform)Object.Instantiate(multiplayerTab.parent, multiplayerContent);
subtabSlider = Object.Instantiate(__instance.tabSlider, subtabsBar);
subtabsBar.name = "subtab-line";
Expand Down Expand Up @@ -146,15 +147,15 @@ public static void _OnCreate_Postfix(UIOptionWindow __instance)
}
contentContainer = listContent;

// Find control templates
checkboxTemplate = contentTemplate.Find("fullscreen").GetComponent<RectTransform>();
comboBoxTemplate = contentTemplate.Find("resolution").GetComponent<RectTransform>();
sliderTemplate = contentTemplate.Find("dofblur").GetComponent<RectTransform>();
// Find control templates from tab "Video"
checkboxTemplate = __instance.fullscreenComp.transform.parent.GetComponent<RectTransform>();
comboBoxTemplate = __instance.resolutionComp.transform.parent.GetComponent<RectTransform>();
sliderTemplate = __instance.dofComp.transform.parent.GetComponent<RectTransform>();
inputTemplate = Object.Instantiate(checkboxTemplate, listContent, false);
Object.Destroy(inputTemplate.Find("CheckBox").gameObject);
var inputField =
Object.Instantiate(
UIRoot.instance.saveGameWindow.transform.Find("input-filename/InputField").GetComponent<RectTransform>(),
UIRoot.instance.saveGameWindow.nameInput.transform.GetComponent<RectTransform>(),
inputTemplate, false);
var fieldPosition = checkboxTemplate.GetChild(0).GetComponent<RectTransform>().anchoredPosition;
inputField.anchoredPosition = new Vector2(fieldPosition.x + 6, fieldPosition.y);
Expand Down Expand Up @@ -249,7 +250,7 @@ private static void SetSubtabIndex(int index)
}
}
subtabSlider.rectTransform.anchoredPosition =
new Vector2(subtabOffest * index, subtabSlider.rectTransform.anchoredPosition.y);
new Vector2(SubtabOffset * index, subtabSlider.rectTransform.anchoredPosition.y);
}
subtabIndex = index;
}
Expand Down Expand Up @@ -312,7 +313,7 @@ private static void CreateSubtab(string subtabName)
{
var subtab = Object.Instantiate(subtabTemplate, subtabTemplate.parent);
var anchoredPosition = subtabTemplate.anchoredPosition;
subtab.anchoredPosition = new Vector2(anchoredPosition.x + subtabOffest * subtabButtons.Count,
subtab.anchoredPosition = new Vector2(anchoredPosition.x + SubtabOffset * subtabButtons.Count,
anchoredPosition.y);
subtabButtons.Add(subtab.GetComponent<UIButton>());
subtab.name = $"tab-button-{subtabButtons.Count}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#endregion

namespace NebulaPatcher.Patches.Dynamic;
namespace NebulaPatcher.Patches.Misc;

[HarmonyPatch(typeof(EnemyFormation))]
internal class Debug_EnemyFormation_Patch
Expand Down Expand Up @@ -46,7 +46,7 @@ public static void EnqueueTech_Postfix(GameHistoryData __instance, int techId)
{
if (Multiplayer.IsActive && Multiplayer.Session.History.IsIncomingRequest)
{
//Do not run if this was triggered by incomming request
//Do not run if this was triggered by incoming request
return;
}
__instance.UnlockTech(techId);
Expand Down Expand Up @@ -97,21 +97,21 @@ public static void SetForNewGame_Postfix(Mecha __instance)
__instance.player.package.AddItemStacked(1501, 600, 1, out _); //add sails
__instance.player.package.AddItemStacked(1503, 60, 1, out _); //add rockets
__instance.player.package.AddItemStacked(2312, 10, 1, out _); //add launching silo
__instance.player.package.AddItemStacked(2210, 10, 1, out _); //add artifical sun
__instance.player.package.AddItemStacked(2210, 10, 1, out _); //add artificial sun
__instance.player.package.AddItemStacked(2311, 20, 1, out _); //add railgun
__instance.player.package.AddItemStacked(2001, 600, 1, out _); //add MK3 belts
__instance.player.package.AddItemStacked(2002, 600, 1, out _); //add MK3 belts
__instance.player.package.AddItemStacked(2003, 600, 1, out _); //add MK3 belts
__instance.player.package.AddItemStacked(2013, 100, 1, out _); //add MK3 inserters
__instance.player.package.AddItemStacked(2212, 20, 1, out _); //add satelite sub-station
__instance.player.package.AddItemStacked(2212, 20, 1, out _); //add satellite sub-station
__instance.player.package.AddItemStacked(1128, 100, 1, out _); // add combustible unit
__instance.player.package.AddItemStacked(1601, 100, 1, out _); // add magnum ammo box
__instance.player.package.AddItemStacked(1604, 100, 1, out _); // add shell set
__instance.player.package.AddItemStacked(1607, 100, 1, out _); // add plasma capsule
__instance.player.package.AddItemStacked(1609, 100, 1, out _); // add missile set
__instance.player.package.AddItemStacked(1613, 100, 1, out _); // add jammer

// temporay fix before PlayerTechBonuses update
// temporary fix before PlayerTechBonuses update
__instance.energyShieldUnlocked = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

#endregion

namespace NebulaPatcher.Patches.Dynamic;
namespace NebulaPatcher.Patches.Misc;

// Collections of patches that need to make game run in nographics mode
// This part only get patch when Multiplayer.IsDedicated is true
internal class Dedicated_Server_Patch
internal class Dedicated_Server_Patches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(GameMain), nameof(GameMain.Begin))]
Expand Down
Loading

0 comments on commit c03e3e5

Please sign in to comment.