Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deathlink, first pass. #81

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -286,6 +292,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 @@ -295,6 +312,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 @@ -415,8 +438,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