Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
slotthhy committed Sep 30, 2023
2 parents 6af0e6c + 777ade3 commit 9247674
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 101 deletions.
20 changes: 10 additions & 10 deletions Orchestrion/Audio/BGMManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using CheapLoc;
using Dalamud.Game;
using Dalamud.Logging;
using Dalamud.Plugin.Services;
using Orchestrion.BGMSystem;
using Orchestrion.Ipc;
using Orchestrion.Persistence;
Expand Down Expand Up @@ -47,7 +47,7 @@ private static void IpcUpdate(int oldSong, int newSong, int oldSecondSong, int o
if (playedByOrch) _ipcManager.InvokeOrchSongChanged(newSong);
}

public static void Update(Framework ignored)
public static void Update(IFramework ignored)
{
_bgmController.Update();
}
Expand All @@ -61,10 +61,10 @@ private static void HandleSongChanged(int oldSong, int newSong, int oldSecondSon
var newSecondHasReplacement = Configuration.Instance.SongReplacements.TryGetValue(newSecondSong, out var newSecondSongReplacement);

if (currentChanged)
PluginLog.Debug($"[HandleSongChanged] Current Song ID changed from {_bgmController.OldSongId} to {_bgmController.CurrentSongId}");
DalamudApi.PluginLog.Debug($"[HandleSongChanged] Current Song ID changed from {_bgmController.OldSongId} to {_bgmController.CurrentSongId}");

if (secondChanged)
PluginLog.Debug($"[HandleSongChanged] Second song ID changed from {_bgmController.OldSecondSongId} to {_bgmController.SecondSongId}");
DalamudApi.PluginLog.Debug($"[HandleSongChanged] Second song ID changed from {_bgmController.OldSecondSongId} to {_bgmController.SecondSongId}");

if (PlayingSongId != 0 && DeepDungeonModeActive())
{
Expand All @@ -90,7 +90,7 @@ private static void HandleSongChanged(int oldSong, int newSong, int oldSecondSon

var toPlay = 0;

PluginLog.Debug($"[HandleSongChanged] Song ID {newSong} has a replacement of {newSongReplacement.ReplacementId}");
DalamudApi.PluginLog.Debug($"[HandleSongChanged] Song ID {newSong} has a replacement of {newSongReplacement.ReplacementId}");

// Handle 2nd changing when 1st has replacement of NoChangeId, only time it matters
if (newSongReplacement.ReplacementId == SongReplacementEntry.NoChangeId)
Expand Down Expand Up @@ -121,7 +121,7 @@ public static void Play(int songId, bool isReplacement = false)
var oldSongId = CurrentAudibleSong;
var secondSongId = _bgmController.SecondSongId;

PluginLog.Debug($"[Play] Playing {songId}");
DalamudApi.PluginLog.Debug($"[Play] Playing {songId}");
InvokeSongChanged(oldSongId, songId, secondSongId, oldSongId, oldPlayedByOrch: wasPlaying, playedByOrch: true);
_bgmController.SetSong((ushort)songId);
_isPlayingReplacement = isReplacement;
Expand All @@ -131,18 +131,18 @@ public static void Stop()
{
if (PlaylistManager.IsPlaying)
{
PluginLog.Debug("[Stop] Stopping playlist...");
DalamudApi.PluginLog.Debug("[Stop] Stopping playlist...");
PlaylistManager.Reset();
}

_ddPlaylist = null;

if (PlayingSongId == 0) return;
PluginLog.Debug($"[Stop] Stopping playing {_bgmController.PlayingSongId}...");
DalamudApi.PluginLog.Debug($"[Stop] Stopping playing {_bgmController.PlayingSongId}...");

if (Configuration.Instance.SongReplacements.TryGetValue(_bgmController.CurrentSongId, out var replacement))
{
PluginLog.Debug($"[Stop] Song ID {_bgmController.CurrentSongId} has a replacement of {replacement.ReplacementId}...");
DalamudApi.PluginLog.Debug($"[Stop] Song ID {_bgmController.CurrentSongId} has a replacement of {replacement.ReplacementId}...");

var toPlay = replacement.ReplacementId;

Expand All @@ -163,7 +163,7 @@ public static void Stop()

private static void InvokeSongChanged(int oldSongId, int newSongId, int oldSecondSongId, int newSecondSongId, bool oldPlayedByOrch, bool playedByOrch)
{
PluginLog.Debug($"[InvokeSongChanged] Invoking SongChanged event with {oldSongId} -> {newSongId}, {oldSecondSongId} -> {newSecondSongId} | {oldPlayedByOrch} {playedByOrch}");
DalamudApi.PluginLog.Debug($"[InvokeSongChanged] Invoking SongChanged event with {oldSongId} -> {newSongId}, {oldSecondSongId} -> {newSecondSongId} | {oldPlayedByOrch} {playedByOrch}");
OnSongChanged?.Invoke(oldSongId, newSongId, oldSecondSongId, newSecondSongId, oldPlayedByOrch, playedByOrch);
}

Expand Down
10 changes: 5 additions & 5 deletions Orchestrion/Audio/PlaylistManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using Dalamud.Game;
using Dalamud.Logging;
using Dalamud.Plugin.Services;
using Orchestrion.Persistence;
using Orchestrion.Struct;

Expand Down Expand Up @@ -37,14 +37,14 @@ public static void Dispose()
DalamudApi.Framework.Update -= Update;
}

private static void Update(Framework ignore)
private static void Update(IFramework ignore)
{
if (_currentPlaylist == string.Empty || CurrentPlaylist == null) return;
if (_playlistStartTrackCount != CurrentPlaylist.Songs.Count)
ResetHistory();

if (ElapsedDuration <= Duration) return;
PluginLog.Debug($"{ElapsedDuration} > {Duration}");
DalamudApi.PluginLog.Debug($"{ElapsedDuration} > {Duration}");

Next();
}
Expand Down Expand Up @@ -94,7 +94,7 @@ public static void Next()

private static void BeginTrack(int id)
{
PluginLog.Debug($"[PlaylistManager] [BeginTrack] id: {id} _currentSongIndex {_currentSongIndex}");
DalamudApi.PluginLog.Debug($"[PlaylistManager] [BeginTrack] id: {id} _currentSongIndex {_currentSongIndex}");
if (id == 0)
Stop();
else
Expand Down Expand Up @@ -124,7 +124,7 @@ private static int GetNextSong()
if (_playbackHistory.Count > 0 && _indexInHistory != _playbackHistory.Count - 1)
return CurrentPlaylist.Songs[_playbackHistory[++_indexInHistory]];

PluginLog.Debug($"[PlaylistManager] [GetNextSong] CurrentPlaylist.RepeatMode: {CurrentPlaylist?.RepeatMode} CurrentPlaylist.ShuffleMode: {CurrentPlaylist?.ShuffleMode}");
DalamudApi.PluginLog.Debug($"[PlaylistManager] [GetNextSong] CurrentPlaylist.RepeatMode: {CurrentPlaylist?.RepeatMode} CurrentPlaylist.ShuffleMode: {CurrentPlaylist?.ShuffleMode}");
var nextSong = GenerateNextSongId();
_playbackHistory.Add(_currentSongIndex);
_indexInHistory++;
Expand Down
4 changes: 2 additions & 2 deletions Orchestrion/BGMSystem/BGMAddressResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public static unsafe void Init()
AddRestartId = DalamudApi.SigScanner.ScanText("48 89 5C 24 ?? 57 48 83 EC 30 48 8B 41 20 48 8D 79 18");
GetSpecialMode = DalamudApi.SigScanner.ScanText("48 89 5C 24 ?? 57 48 83 EC 20 8B 41 10 33 DB");

PluginLog.Debug($"[BGMAddressResolver] init: base address at {_baseAddress.ToInt64():X}");
DalamudApi.PluginLog.Debug($"[BGMAddressResolver] init: base address at {_baseAddress.ToInt64():X}");

var musicLoc = DalamudApi.SigScanner.ScanText("48 8B 8F ?? ?? ?? ?? 39 70 20 0F 94 C2 45 33 C0");
var musicOffset= Marshal.ReadInt32(musicLoc + 3);
_musicManager = Marshal.ReadIntPtr(new nint(Framework.Instance()) + musicOffset);
PluginLog.Debug($"[BGMAddressResolver] MusicManager found at {_musicManager.ToInt64():X}");
DalamudApi.PluginLog.Debug($"[BGMAddressResolver] MusicManager found at {_musicManager.ToInt64():X}");
}

public static nint BGMSceneManager
Expand Down
2 changes: 1 addition & 1 deletion Orchestrion/BGMSystem/BGMController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class BGMController
public unsafe BGMController()
{
_addDisableRestartId = Marshal.GetDelegateForFunctionPointer<AddDisableRestartIdPrototype>(BGMAddressResolver.AddRestartId);
_getSpecialModeForSceneHook = Hook<GetSpecialModeByScenePrototype>.FromAddress(BGMAddressResolver.GetSpecialMode, GetSpecialModeBySceneDetour);
_getSpecialModeForSceneHook = DalamudApi.Hooker.HookFromAddress<GetSpecialModeByScenePrototype>(BGMAddressResolver.GetSpecialMode, GetSpecialModeBySceneDetour);
_getSpecialModeForSceneHook.Enable();
}

Expand Down
71 changes: 28 additions & 43 deletions Orchestrion/DalamudApi.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,39 @@
using Dalamud.Data;
using Dalamud.Game;
using Dalamud.Game.ClientState;
using Dalamud.Game.ClientState.Aetherytes;
using Dalamud.Game.ClientState.Buddy;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.ClientState.Fates;
using Dalamud.Game.ClientState.GamePad;
using Dalamud.Game.ClientState.JobGauge;
using Dalamud.Game.ClientState.Keys;
using Dalamud.Game;
using Dalamud.Game.ClientState.Objects;
using Dalamud.Game.ClientState.Party;
using Dalamud.Game.Command;
using Dalamud.Game.Gui;
using Dalamud.Game.Gui.Dtr;
using Dalamud.Game.Gui.FlyText;
using Dalamud.Game.Gui.PartyFinder;
using Dalamud.Game.Gui.Toast;
using Dalamud.Game.Libc;
using Dalamud.Game.Network;
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;

namespace Orchestrion;

public class DalamudApi
{
public static void Initialize(DalamudPluginInterface pluginInterface) => pluginInterface.Create<DalamudApi>();

[PluginService][RequiredVersion("1.0")] public static AetheryteList AetheryteList { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static BuddyList BuddyList { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static ChatGui ChatGui { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static ChatHandlers ChatHandlers { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static ClientState ClientState { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static CommandManager CommandManager { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static Condition Condition { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IAetheryteList AetheryteList { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IBuddyList BuddyList { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IChatGui ChatGui { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IClientState ClientState { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static ICommandManager CommandManager { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static ICondition Condition { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static DalamudPluginInterface PluginInterface { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static DataManager DataManager { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static DtrBar DtrBar { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static FateTable FateTable { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static FlyTextGui FlyTextGui { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static Framework Framework { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static GameGui GameGui { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static GameNetwork GameNetwork { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static GamepadState GamePadState { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static JobGauges JobGauges { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static KeyState KeyState { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static LibcFunction LibcFunction { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static ObjectTable ObjectTable { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static PartyFinderGui PartyFinderGui { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static PartyList PartyList { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static SigScanner SigScanner { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static TargetManager TargetManager { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static ToastGui ToastGui { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IDataManager DataManager { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IDtrBar DtrBar { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IFateTable FateTable { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IFlyTextGui FlyTextGui { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IFramework Framework { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IGameGui GameGui { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IGameNetwork GameNetwork { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IGamepadState GamePadState { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IJobGauges JobGauges { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IKeyState KeyState { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static ILibcFunction LibcFunction { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IObjectTable ObjectTable { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IPartyFinderGui PartyFinderGui { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IPartyList PartyList { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static ISigScanner SigScanner { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static ITargetManager TargetManager { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IToastGui ToastGui { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IGameInteropProvider Hooker { get; private set; } = null;
[PluginService][RequiredVersion("1.0")] public static IPluginLog PluginLog { get; private set; } = null;
}
5 changes: 2 additions & 3 deletions Orchestrion/Ipc/OrchestrionIpcManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Dalamud.Logging;
using Dalamud.Plugin.Ipc;
using Orchestrion.Audio;
using Orchestrion.Game;
using Orchestrion.Persistence;
using Orchestrion.Struct;

Expand Down Expand Up @@ -69,7 +68,7 @@ private void InitForSelf()
_orchSongChangeProvider = DalamudApi.PluginInterface.GetIpcProvider<int, bool>("Orch.OrchSongChange");
_songChangeProvider = DalamudApi.PluginInterface.GetIpcProvider<int, bool>("Orch.SongChange");

PluginLog.Verbose("[InitForSelf] Firing Orch.Available.");
DalamudApi.PluginLog.Verbose("[InitForSelf] Firing Orch.Available.");
var cgAvailable = DalamudApi.PluginInterface.GetIpcProvider<bool>("Orch.Available");
cgAvailable.SendMessage();
}
Expand Down Expand Up @@ -124,7 +123,7 @@ private void InitForWotsit()
_wotsitRandomFavoriteGuid = _wotsitRegister.InvokeFunc(IpcDisplayName, PlayRandomFavorites, PlayRandomFavorites, WotsitIconId);
_wotsitStopGuid = _wotsitRegister.InvokeFunc(IpcDisplayName, Stop, Stop, WotsitIconId);

PluginLog.Debug($"[InitForWotsit] Registered {_wotsitSongIpcs.Count} songs with Wotsit");
DalamudApi.PluginLog.Debug($"[InitForWotsit] Registered {_wotsitSongIpcs.Count} songs with Wotsit");
}

private string GetSearchString(Song song)
Expand Down
2 changes: 1 addition & 1 deletion Orchestrion/Orchestrion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<Private>False</Private>
</Reference>

<PackageReference Include="DalamudPackager" Version="2.1.11" />
<PackageReference Include="DalamudPackager" Version="2.1.12" />
</ItemGroup>
<ItemGroup>
<ContentWithTargetPath Include="Data\xiv_bgm_en.csv">
Expand Down
26 changes: 13 additions & 13 deletions Orchestrion/OrchestrionPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
using System.Linq;
using System.Reflection;
using CheapLoc;
using Dalamud.Game;
using Dalamud.Game.Gui.Dtr;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Interface;
using Dalamud.Interface.GameFonts;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Windowing;
using Dalamud.IoC;
using Dalamud.Logging;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Component.GUI;
using ImGuiNET;
using Orchestrion.Audio;
Expand Down Expand Up @@ -107,7 +107,7 @@ public void Dispose()
BGMManager.Dispose();
}

private void OrchestrionUpdate(Framework ignored)
private void OrchestrionUpdate(IFramework ignored)
{
PerformEcho();
CheckDtr();
Expand All @@ -117,7 +117,7 @@ private void PerformEcho()
{
if (_songEchoMsg == null || IsLoadingScreen()) return;

DalamudApi.ChatGui.PrintChat(new XivChatEntry
DalamudApi.ChatGui.Print(new XivChatEntry
{
Message = _songEchoMsg,
Type = DalamudApi.PluginInterface.GeneralChatType,
Expand All @@ -131,7 +131,7 @@ private void CheckDtr()
_dtrEntry.Shown = Configuration.Instance.ShowSongInNative;
}

private void ClientStateOnLogout(object sender, EventArgs e)
private void ClientStateOnLogout()
{
BGMManager.Stop();
}
Expand All @@ -140,7 +140,7 @@ private void OnSongChanged(int oldSong, int newSong, int oldSecondSong, int oldC
{
if (oldSong == newSong && oldSong == 0) return;
if (oldSong == newSong && oldPlayedByOrch && playedByOrch) return;
PluginLog.Debug($"[OnSongChanged] Changed from {oldSong} to {newSong}, oldPlayedByOrch: {oldPlayedByOrch}, playedByOrch: {playedByOrch}");
DalamudApi.PluginLog.Debug($"[OnSongChanged] Changed from {oldSong} to {newSong}, oldPlayedByOrch: {oldPlayedByOrch}, playedByOrch: {playedByOrch}");
UpdateDtr(newSong, playedByOrch: playedByOrch);
UpdateChat(newSong, playedByOrch: playedByOrch);
}
Expand All @@ -161,16 +161,16 @@ private void OnCommand(string command, string args)
var argLen = argSplit.Length;

// print args to log
PluginLog.Log($"command: {command} args: {args}");
DalamudApi.PluginLog.Information($"command: {command} args: {args}");
var argString = "['" + string.Join("', '", argSplit) + "']";
PluginLog.Log($"argLen: {argLen} argSplit: {argString}");
DalamudApi.PluginLog.Information($"argLen: {argLen} argSplit: {argString}");

var mainArg = argSplit[0].ToLowerInvariant();

switch (argLen)
{
case 1:
PluginLog.Verbose("case 1");
DalamudApi.PluginLog.Verbose("case 1");
switch (mainArg)
{
case "":
Expand Down Expand Up @@ -212,7 +212,7 @@ private void OnCommand(string command, string args)
}
break;
case 2:
PluginLog.Verbose("case 2");
DalamudApi.PluginLog.Verbose("case 2");
var arg2 = argSplit[1].ToLowerInvariant();
switch (mainArg)
{
Expand All @@ -226,7 +226,7 @@ private void OnCommand(string command, string args)
DalamudApi.ChatGui.PrintError(BuildChatMessage(string.Format(Loc.Localize("SongIdNotFound", "Song ID {0} not found."), songId)));
break;
case "play" when !int.TryParse(argSplit[1], out var songId):
PluginLog.Verbose("play by song name");
DalamudApi.PluginLog.Verbose("play by song name");
HandlePlayBySongName(argSplit);
break;
case "shuffle":
Expand Down Expand Up @@ -292,7 +292,7 @@ private void OnCommand(string command, string args)
BGMManager.StartDeepDungeonMode(ddModePlaylist.Name);
break;
case >= 3 when argSplit[1].ToLowerInvariant() == "playlist":
PluginLog.Verbose("case >= 3 when argSplit[1].ToLowerInvariant() == playlist");
DalamudApi.PluginLog.Verbose("case >= 3 when argSplit[1].ToLowerInvariant() == playlist");
var playlistName = argSplit.Skip(2).Aggregate((x, y) => $"{x} {y}");

var playlistExists = Configuration.Instance.TryGetPlaylist(playlistName, out var playlist);
Expand Down Expand Up @@ -321,7 +321,7 @@ private void OnCommand(string command, string args)
}
break;
case >= 2 when argSplit[0].ToLowerInvariant() == "play" && !int.TryParse(argSplit[1], out _):
PluginLog.Verbose("case >= 2 when argSplit[0].ToLowerInvariant() == play && !int.TryParse(argSplit[1], out _)");
DalamudApi.PluginLog.Verbose("case >= 2 when argSplit[0].ToLowerInvariant() == play && !int.TryParse(argSplit[1], out _)");
HandlePlayBySongName(argSplit);
break;
default:
Expand Down
Loading

0 comments on commit 9247674

Please sign in to comment.