Skip to content

Commit

Permalink
added GameApi properties: Stats, CurrentCharacter, IsLoading, InTrans…
Browse files Browse the repository at this point in the history
…ition
  • Loading branch information
TalicZealot committed Mar 15, 2021
1 parent 8d9c2de commit baf8456
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# SotN Api
![GitHub release (latest by date)](https://img.shields.io/github/v/release/TalicZealot/SotnApi)

An api for reading and manipulating game entities in ram through the BizHawk API.

## Usage
Download the dll from the release and reference in your project.
Download the dll from the release and put it in the ExternalTools folder. Reference in your project and use.
Create an instance of the api you want to use by passing the IMemoryApi provided by BizHawk to an ExternalTool at runtime.

## Building
Expand Down
1 change: 0 additions & 1 deletion SotnApi/SotnApi/ActorApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class ActorApi : IActorApi
public ActorApi(IMemoryApi? memAPI)
{
if (memAPI == null) { throw new ArgumentNullException("Memory API is null"); }

this.memAPI = memAPI;
}

Expand Down
2 changes: 1 addition & 1 deletion SotnApi/SotnApi/Constants/Addresses/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static class Game
};

public static long Status = 0x03C734;
public static long StatusTransition = 0x03C9A4;
public static long Transition = 0x03C9A4;
public static long Loading = 0x03CF7C;
public static long MapOpen = 0x0974A4;
public static long MenuOpen = 0x0973EC;
Expand Down
2 changes: 1 addition & 1 deletion SotnApi/SotnApi/Constants/Values/Game/Various.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SotnApi.Constants.Values.Game
{
public static class Various
{
public static uint RowOffset = 0x80;
public static long RowOffset = 0x800;
public static uint Prologue = 0x20;
public static uint LibraryWarped = 0x78;

Expand Down
53 changes: 47 additions & 6 deletions SotnApi/SotnApi/GameApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ public GameApi(IMemoryApi? memAPI)
this.memAPI = memAPI;
}

public uint Status
{
get
{
return memAPI.ReadByte(Game.Status);
}
}

public Character CurrentCharacter
{
get
{
uint character = memAPI.ReadByte(Game.Character);
if (character == 0)
{
return Character.Alucard;
}
else
{
return Character.Richter;
}
}
}

public uint SecondCastle
{
get
Expand Down Expand Up @@ -58,16 +82,32 @@ public uint Room
}
}

public bool IsLoading
{
get
{
return memAPI.ReadByte(Game.Loading) == SotnApi.Constants.Values.Game.Status.Loading;
}
}

public bool InTransition
{
get
{
return memAPI.ReadByte(Game.Transition) != SotnApi.Constants.Values.Game.Status.Transition;
}
}

public bool CanMenu()
{
bool notTransition = memAPI.ReadByte(Game.StatusTransition) != Status.Transition;
bool notLoading = memAPI.ReadByte(Game.Loading) != Status.Loading;
bool notTransition = !this.InTransition;
bool notLoading = !this.IsLoading;
return (notTransition && notLoading);
}

public bool IsInMenu()
{
bool menuOpen = memAPI.ReadByte(Game.MenuOpen) == Status.MenuOpen;
bool menuOpen = memAPI.ReadByte(Game.MenuOpen) == SotnApi.Constants.Values.Game.Status.MenuOpen;
return menuOpen;
}

Expand All @@ -81,9 +121,10 @@ public void RespawnBosses()

public bool InAlucardMode()
{
bool inGame = memAPI.ReadByte(Game.Status) == Status.InGame;
bool isAlucard = memAPI.ReadByte(Game.Character) == (int)Character.Alucard;
bool notInPrologue = memAPI.ReadByte(Game.Area) != Various.Prologue;
bool inGame = this.Status == SotnApi.Constants.Values.Game.Status.InGame;
bool isAlucard = this.CurrentCharacter == Character.Alucard;
uint area = memAPI.ReadByte(Game.Area);
bool notInPrologue = area != Various.Prologue && area > 0;
return (inGame && isAlucard && notInPrologue);
}

Expand Down
11 changes: 10 additions & 1 deletion SotnApi/SotnApi/Interfaces/IGameApi.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
namespace SotnApi.Interfaces
using SotnApi.Constants.Values.Game.Enums;

namespace SotnApi.Interfaces
{
public interface IGameApi
{
uint Status { get; }
/// <returns>
/// The current character, but prologue Richter still counts as Alucard.
/// </returns>
Character CurrentCharacter { get; }
uint Area { get; }
uint Room { get; }
uint SecondCastle { get; }
uint Zone { get; }
uint Zone2 { get; }
bool IsLoading { get; }
bool InTransition { get; }

bool CanMenu();
void ClearByte(long address);
Expand Down
1 change: 1 addition & 0 deletions SotnApi/SotnApi/SotnApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<TargetFramework>net48</TargetFramework>
<Version>1.0.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit baf8456

Please sign in to comment.