Skip to content

Commit

Permalink
Add disableRestartPrompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Seeker14491 committed Jul 28, 2018
1 parent 5cfe7d7 commit 287cccc
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Download the plugin from [the releases](https://github.com/Seeker14491/Tweakr/re
| Setting | Description |
| ------------------------------ | ------------------------------------------------------------ |
| enableCheatMenu | Enables a built-in cheat menu that's normally hidden. It's accessible from the options menu. **Warning:** The Monster Truck cheat is buggy and leads to crashes. To prevent this, only turn it on while playing a track, and turn it back off before leaving the level. |
| disableRestartPrompt | Immediately restarts instead of prompting when you press the restart button in single-player. |
| carScreenDeclutter | Hides the large arrow that appears on the back of the car when you go off-track, as well as the placement widget that appears in multiplayer sprint that shows what position you are in the race. The compass is also visible during the initial countdown. |
| disableWingGripControlModifier | Stops the grip button from affecting wing controls. |
| disableWingSelfRightening | Stops wings from leveling out when not pressing a roll input. It disables Flight Landing Assist as a side-effect. |
Expand Down
68 changes: 68 additions & 0 deletions Tweakr/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Spectrum.API.Interfaces.Plugins;
using Spectrum.API.Interfaces.Systems;
using Harmony;
using UnityEngine;

namespace Tweakr
{
Expand Down Expand Up @@ -114,6 +115,7 @@ private static Settings InitializeSettings()
var entries = new[]
{
new SettingsEntry("enableCheatMenu", true),
new SettingsEntry("disableRestartPrompt", true),
new SettingsEntry("carScreenDeclutter", false),
new SettingsEntry("disableWingGripControlModifier", false),
new SettingsEntry("disableWingSelfRightening", false),
Expand Down Expand Up @@ -353,4 +355,70 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
}
}
}

[HarmonyPatch(typeof(PauseMenuLogic), "OnRestartClicked")]
internal class DisableRestartPromptPaused
{
static bool Prepare()
{
return Entry.Settings.GetItem<bool>("disableRestartPrompt");
}

static bool Prefix(PauseMenuLogic __instance)
{
var menuPanelManager = Traverse.Create(__instance).Field("menuPanelManager_").GetValue<MenuPanelManager>();
var restartLevel = new Action(() => Traverse.Create(__instance).Method("RestartLevel").GetValue());

if (ReplayManager.ReplayMode_ && ReplayMenu.IsOpen_)
{
G.Sys.ReplayManager_.ShowReplay();
}
else if (G.Sys.NetworkingManager_.IsServer_)
{
menuPanelManager.ShowOkCancel(
"Are you sure you want to restart? This will restart the level on everyone's machines.",
"Restarting Online Level",
() => restartLevel());
}
else if (G.Sys.NetworkingManager_.IsClient_)
{
menuPanelManager.ShowError("Only the host can restart an online match.", "Can't Restart");
}
else
{
restartLevel();
}

return false;
}
}

[HarmonyPatch(typeof(FinishMenuLogic), "OnRestartClicked")]
internal class DisableRestartPromptFinished
{
static bool Prepare()
{
return Entry.Settings.GetItem<bool>("disableRestartPrompt");
}

static bool Prefix(FinishMenuLogic __instance)
{
var gameManager = Traverse.Create(__instance).Field("gameManager_").GetValue<GameManager>();

if (Traverse.Create(__instance).Field("networkingManager_").GetValue<NetworkingManager>().IsServer_)
{
var message = "Are you sure you want to restart? This will restart the level on everyone's machines." +
Traverse.Create(__instance).Method("GetPreviousNextUnfinishedPlayersText").GetValue();
Traverse.Create(__instance).Field("menuManager_").GetValue<MenuPanelManager>().ShowOkCancel(message,
"Restarting Level", gameManager.RestartLevel);
}
else
{
gameManager.RestartLevel();
}


return false;
}
}
}

0 comments on commit 287cccc

Please sign in to comment.