Skip to content

Commit

Permalink
Remove teleporter lock - it's just too buggy
Browse files Browse the repository at this point in the history
  • Loading branch information
JustDerb committed Jul 8, 2024
1 parent dd8dee8 commit 6c91e2b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 111 deletions.
2 changes: 1 addition & 1 deletion Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Configuration(BaseUnityPlugin plugin, UnityAction reloadChannelPoints)
{
// Twitch
TwitchChannel = plugin.Config.Bind("Twitch", "Channel", "", "Your Twitch channel name. The channel to monitor Twitch chat.");
TwitchClientID = TwitchUsername = plugin.Config.Bind("Twitch", "ClientID", "q6batx0epp608isickayubi39itsckt", "Client ID used to get ImplicitOAuth value");
TwitchClientID = plugin.Config.Bind("Twitch", "ClientID", "q6batx0epp608isickayubi39itsckt", "Client ID used to get ImplicitOAuth value");
TwitchUsername = plugin.Config.Bind("Twitch", "Username", "", "Your Twitch username. The username to use when calling Twitch APIs. If you aren't using a secondary account, this should be the same as 'Channel'.");
TwitchOAuth = plugin.Config.Bind("Twitch", "ImplicitOAuth", "", "Implicit OAuth code (this is not your password - it's a generated password!). See the README/Mod Description in the thunderstore to see how to get it.");
TwitchDebugLogs = plugin.Config.Bind("Twitch", "DebugLogs", false, "Enable debug logging for Twitch - will spam to the console!");
Expand Down
99 changes: 0 additions & 99 deletions Events/EventDirector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class EventDirector : MonoBehaviour
{
private BlockingCollection<Func<EventDirector, IEnumerator>> eventQueue;
private bool previousState;
private int forceChargingCount;

/// <summary>
/// Event that fires when the event director changes states between processing events, to pausing processing events.
Expand All @@ -31,7 +30,6 @@ public void Awake()
{
eventQueue = new BlockingCollection<Func<EventDirector, IEnumerator>>();
previousState = false;
forceChargingCount = 0;

//Stage.onServerStageBegin += Stage_onServerStageBegin;
//Stage.onServerStageComplete += Stage_onServerStageComplete;
Expand All @@ -43,11 +41,6 @@ public void OnDestroy()
//Stage.onServerStageBegin -= Stage_onServerStageBegin;
//Stage.onServerStageComplete -= Stage_onServerStageComplete;
//TeleporterInteraction.onTeleporterFinishGlobal -= TeleporterInteraction_onTeleporterFinishGlobal;

if (Interlocked.Exchange(ref forceChargingCount, 0) > 0)
{
On.RoR2.TeleporterInteraction.UpdateMonstersClear -= TeleporterInteraction_UpdateMonstersClear;
}
}

public void Update()
Expand Down Expand Up @@ -96,51 +89,6 @@ public void ClearEvents()
while(eventQueue.TryTake(out _)) {}
}

private void SetTeleporterCrystals(bool enabled)
{
if (TeleporterInteraction.instance)
{
ChildLocator component = TeleporterInteraction.instance.GetComponent<ModelLocator>().modelTransform.GetComponent<ChildLocator>();
if (component)
{
if (enabled)
{
// Only enable, never disable
component.FindChild("TimeCrystalProps").gameObject.SetActive(true);
}

Transform transform = component.FindChild("TimeCrystalBeaconBlocker");
EffectManager.SpawnEffect(LegacyResourcesAPI.Load<GameObject>("Prefabs/Effects/TimeCrystalDeath"), new EffectData
{
origin = transform.transform.position
}, true);
transform.gameObject.SetActive(enabled);
}
}
}

/// <summary>
/// Force the current stages teleporter to not fully charge until the returned handle is disposed.
/// <br/>
/// <b>Important:</b> You must ensure the returned <c>IDisposable</c> is invoked to not risk locking the player into a stage,
/// because the teleporter is set to never fully charge.
/// </summary>
/// <returns>A handle to the state. Call the <c>IDisposable.Dispose()</c> when you are done.</returns>
public IDisposable CreateOpenTeleporterObjectiveHandle()
{
int newValue = Interlocked.Increment(ref forceChargingCount);

Log.Error($"EventDirector::ForceChargingState::Count = {newValue}");
if (newValue == 1)
{
Log.Error("EventDirector::ForceChargingState::Enabled = true");
On.RoR2.TeleporterInteraction.UpdateMonstersClear += TeleporterInteraction_UpdateMonstersClear;
SetTeleporterCrystals(true);
}

return new ForceChargingHandle(this);
}

private IEnumerator Wrap(IEnumerator coroutine)
{
while (true)
Expand All @@ -159,15 +107,6 @@ private IEnumerator Wrap(IEnumerator coroutine)
}
}

private void TeleporterInteraction_UpdateMonstersClear(On.RoR2.TeleporterInteraction.orig_UpdateMonstersClear orig, TeleporterInteraction self)
{
// We don't call the original to keep monstersCleared from flapping between True and False
// orig(self);

FieldInfo monstersCleared = typeof(TeleporterInteraction).GetField("monstersCleared", BindingFlags.NonPublic | BindingFlags.Instance);
monstersCleared.SetValue(self, false);
}

private bool ShouldProcessEvents()
{
if (!enabled)
Expand Down Expand Up @@ -219,43 +158,5 @@ private bool ShouldProcessEvents()

return true;
}

private class ForceChargingHandle : IDisposable
{
private readonly EventDirector eventDirector;
private int disposed;

public ForceChargingHandle(EventDirector eventDirector)
{
this.eventDirector = eventDirector;
this.disposed = 0;
}

public void Dispose()
{
int previouslyDisposed = Interlocked.Exchange(ref disposed, 1);
if (previouslyDisposed == 1)
{
return;
}

int newValue = Interlocked.Decrement(ref eventDirector.forceChargingCount);
if (newValue < 0)
{
Log.Error("Something didn't correctly ref count ForceChargingState!");
Log.Exception(new Exception());
Interlocked.Exchange(ref eventDirector.forceChargingCount, 0);
newValue = 0;
}

Log.Error($"EventDirector::ForceChargingState::Count = {newValue}");
if (newValue == 0)
{
Log.Error("EventDirector::ForceChargingState::Enabled = false");
On.RoR2.TeleporterInteraction.UpdateMonstersClear -= eventDirector.TeleporterInteraction_UpdateMonstersClear;
eventDirector.SetTeleporterCrystals(false);
}
}
}
}
}
7 changes: 0 additions & 7 deletions Events/MonsterSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,10 @@ private CombatSquad SpawnMonstersInternal(
{
CombatSquad group = gameObject.AddComponent<CombatSquad>();

IDisposable chargingHandle = null;
if (director)
{
chargingHandle = director.CreateOpenTeleporterObjectiveHandle();
}
group.onMemberLost += (master) =>
{
if (group.memberCount == 0)
{
chargingHandle?.Dispose();
Destroy(group);
}
};
Expand Down Expand Up @@ -131,7 +125,6 @@ private CombatSquad SpawnMonstersInternal(
if (!spawnedAny)
{
Log.Error("Couldn't spawn any monster!");
chargingHandle?.Dispose();
Destroy(group);
return null;
}
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ To disable an event, simply set the weight to 0. Giving a higher weight increase
|`BountyWeight`|number|1|✔️|Weight for the doppleganger bit event. Your Doppleganger has come to try to stop you!|
|`ShrineOfOrderWeight`|number|1|✔️|Weight for the Shrine of Order bit event. What's this? You see a Shrine that looks rare, and seems to emit a purple hue. You can't help yourself, but you offer a Lunar coin to it...|
|`ShrineOfTheMountainWeight`|number|1|✔️|Weight for the Shrine of the Mountain bit event. You have angered the Twitch Chat gods. Prepare for your final battle at the teleporter.|
|`TitanWeight`|number|1|✔️|Weight for the Aurelionite bit event. Aurelionite comes from the void to try to stop you! **(Until this monster is killed, the teleporter will not fully charge)**|
|`LunarWispWeight`|number|1|✔️|Weight for the Lunar Chimera (Wisp) bit event. Lunar Chimera's come from the void to try to stop you! **(Until these monsters are killed, the teleporter will not fully charge)**|
|`MithrixWeight`|number|1|✔️|Weight for the Mithrix bit event. Twitch Chat decides to enter your stage to stop you a little earlier in the run... **(Until this monster is killed, the teleporter will not fully charge)**|
|`ElderLemurianWeight`|number|1|✔️|Weight for the Elder Lemurian bit event. Elder Lumerian's come from the void to try to stop you! **(Until these monsters are killed, the teleporter will not fully charge)**|
|`TitanWeight`|number|1|✔️|Weight for the Aurelionite bit event. Aurelionite comes from the void to try to stop you!|
|`LunarWispWeight`|number|1|✔️|Weight for the Lunar Chimera (Wisp) bit event. Lunar Chimera's come from the void to try to stop you!|
|`MithrixWeight`|number|1|✔️|Weight for the Mithrix bit event. Twitch Chat decides to enter your stage to stop you a little earlier in the run...|
|`ElderLemurianWeight`|number|1|✔️|Weight for the Elder Lemurian bit event. Elder Lumerian's come from the void to try to stop you!|

## UI

Expand Down
5 changes: 5 additions & 0 deletions VsTwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@ private void GameNetworkManager_onStartHostGlobal()
try
{
Log.Info("Connecting to Twitch...");
if (string.IsNullOrWhiteSpace(configuration.TwitchUsername.Value))
{
configuration.TwitchUsername.Value = configuration.TwitchChannel.Value;
}

twitchManager.Connect(
configuration.TwitchChannel.Value,
configuration.TwitchOAuth.Value,
Expand Down

0 comments on commit 6c91e2b

Please sign in to comment.