Skip to content

Commit

Permalink
Merge pull request #81 from dewiniaid/feature/deathlink
Browse files Browse the repository at this point in the history
Deathlink, first pass.
  • Loading branch information
dewiniaid authored Jun 22, 2022
2 parents 7b7bdc3 + be7034e commit 5ff10af
Show file tree
Hide file tree
Showing 7 changed files with 490 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Archipelago.HollowKnight/Archipelago.HollowKnight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@
<None Remove="Resources\Icon.png" />
<None Remove="Resources\IconBig.png" />
<None Remove="Resources\IconSmall.png" />
<None Remove="Resources\DeathLinkIcon.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Icon.png" />
<EmbeddedResource Include="Resources\IconBig.png" />
<EmbeddedResource Include="Resources\IconSmall.png" />
<EmbeddedResource Include="Resources\DeathLinkIcon.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Archipelago.MultiClient.Net" Version="3.0.1" />
Expand Down
48 changes: 45 additions & 3 deletions Archipelago.HollowKnight/Archipelago.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Reflection;
using Archipelago.HollowKnight.IC;
using Archipelago.HollowKnight.MC;
using Archipelago.HollowKnight.Placements;
using Archipelago.HollowKnight.SlotData;
using Archipelago.MultiClient.Net;
using Archipelago.MultiClient.Net.Enums;
Expand Down Expand Up @@ -34,10 +33,12 @@ public class Archipelago : Mod, IGlobalSettings<ConnectionDetails>, ILocalSettin
public SlotOptions SlotOptions { get; set; }
public bool ArchipelagoEnabled { get; set; }

public int Slot { get => slot; }
public int Slot => slot;
public string Player => session.Players.GetPlayerName(slot);

public static Sprite Sprite;
public static Sprite SmallSprite;
public static Sprite DeathLinkSprite;
internal static FieldInfo obtainStateFieldInfo;

internal SpriteManager spriteManager;
Expand Down Expand Up @@ -104,6 +105,7 @@ public override void Initialize(Dictionary<string, Dictionary<string, GameObject
spriteManager = new SpriteManager(typeof(Archipelago).Assembly, "Archipelago.HollowKnight.Resources.");
Sprite = spriteManager.GetSprite("Icon");
SmallSprite = spriteManager.GetSprite("IconSmall");
DeathLinkSprite = spriteManager.GetSprite("DeathLinkIcon");
obtainStateFieldInfo = typeof(AbstractItem).GetField("obtainState", BindingFlags.NonPublic | BindingFlags.Instance);

MenuChanger.ModeMenu.AddMode(new ArchipelagoModeMenuConstructor());
Expand Down Expand Up @@ -176,7 +178,7 @@ private bool ReceiveNextItem()

private void ModHooks_HeroUpdateHook()
{
if(deferringLocationChecks)
if (deferringLocationChecks)
{
StopDeferringLocationChecks();
}
Expand All @@ -189,6 +191,7 @@ private void ModHooks_HeroUpdateHook()

public void EndGame()
{
LogDebug("Ending Archipelago game");
try
{
OnArchipelagoGameEnded?.Invoke();
Expand All @@ -204,6 +207,7 @@ public void EndGame()

ItemChanger.Events.OnItemChangerUnhook -= EndGame;
ModHooks.HeroUpdateHook -= ModHooks_HeroUpdateHook;
ModHooks.AfterPlayerDeadHook -= ModHooks_AfterPlayerDeadHook;
On.HeroController.Start -= HeroController_Start;

if (goal != null)
Expand All @@ -227,7 +231,9 @@ public void StartOrResumeGame(bool randomize)

ItemChanger.Events.OnItemChangerUnhook += EndGame;
ModHooks.HeroUpdateHook += ModHooks_HeroUpdateHook;
ModHooks.AfterPlayerDeadHook += ModHooks_AfterPlayerDeadHook;
On.HeroController.Start += HeroController_Start;

LoginSuccessful loginResult = ConnectToArchipelago() as LoginSuccessful;
DeferLocationChecks();
if (randomize)
Expand Down Expand Up @@ -299,6 +305,17 @@ private LoginResult ConnectToArchipelago()
// Read slot data.
slot = success.Slot;
SlotOptions = SlotDataExtract.ExtractObjectFromSlotData<SlotOptions>(success.SlotData["options"]);
LogDebug($"Deathlink type: {SlotOptions.DeathLink}");

// Enable Deathlink
if(SlotOptions.DeathLink != DeathLinkType.None)
{
DeathLinkSupport.Instance.Enable();
}
else
{
DeathLinkSupport.Instance.Disable();
}
return loginResult;
}
else
Expand All @@ -308,6 +325,12 @@ private LoginResult ConnectToArchipelago()
}
}

private System.Collections.IEnumerator HeroController_Respawn(On.HeroController.orig_Respawn orig, HeroController self)
{
On.HeroController.Respawn -= HeroController_Respawn;
return orig(self);
}

public void MarkLocationAsChecked(long locationID)
{
// Called when marking a location as checked remotely (i.e. through ReceiveItem, etc.)
Expand Down Expand Up @@ -428,8 +451,27 @@ private void ModHooks_SavegameLoadHook(int obj)
StartOrResumeGame(false); // No-op if AP disabled.
}

private void ModHooks_AfterPlayerDeadHook()
{
// Fixes up some bad shade placement by vanilla HK.
PlayerData pd = PlayerData.instance;
switch (pd.shadeScene)
{
case "Abyss_08":
pd.shadePositionX = 90;
pd.shadePositionY = 90;
break;
case "Room_Colosseum_Spectate":
pd.shadePositionX = 124;
pd.shadePositionY = 10;
break;
// noop on default
}
}

public void DisconnectArchipelago()
{
DeathLinkSupport.Instance.Disable();
slot = 0;

if (session?.Socket != null && session.Socket.Connected)
Expand Down
Loading

0 comments on commit 5ff10af

Please sign in to comment.