mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
Set BGM via function
This commit is contained in:
parent
92f8ad0fd8
commit
4bcdf6caef
5 changed files with 41 additions and 32 deletions
|
|
@ -440,7 +440,7 @@ namespace Dalamud {
|
||||||
|
|
||||||
private void OnBgmSetCommand(string command, string arguments)
|
private void OnBgmSetCommand(string command, string arguments)
|
||||||
{
|
{
|
||||||
Framework.Network.InjectBgmTest(int.Parse(arguments));
|
Framework.Gui.SetBgm(ushort.Parse(arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnItemLinkCommand(string command, string arguments) {
|
private void OnItemLinkCommand(string command, string arguments) {
|
||||||
|
|
@ -474,26 +474,5 @@ namespace Dalamud {
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] StringToByteArray(String value)
|
|
||||||
{
|
|
||||||
byte[] bytes = new byte[value.Length * sizeof(char)];
|
|
||||||
Buffer.BlockCopy(value.ToCharArray(), 0, bytes, 0, bytes.Length);
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String ByteArrayToString(byte[] value)
|
|
||||||
{
|
|
||||||
var chars = new char[value.Length / sizeof(char)];
|
|
||||||
|
|
||||||
var atValue = 0;
|
|
||||||
for (var i = 0; i < chars.Length; i++) {
|
|
||||||
chars[i] = BitConverter.ToChar(value, atValue);
|
|
||||||
|
|
||||||
atValue += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new string(chars);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Dalamud.Game.Chat;
|
||||||
|
using Dalamud.Hooking;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
namespace Dalamud.Game.Internal.Gui {
|
namespace Dalamud.Game.Internal.Gui {
|
||||||
|
|
@ -7,21 +10,46 @@ namespace Dalamud.Game.Internal.Gui {
|
||||||
|
|
||||||
public ChatGui Chat { get; private set; }
|
public ChatGui Chat { get; private set; }
|
||||||
|
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
|
private delegate IntPtr SetGlobalBgmDelegate(UInt16 bgmKey, byte a2, UInt32 a3, UInt32 a4, UInt32 a5, byte a6);
|
||||||
|
|
||||||
|
private readonly Hook<SetGlobalBgmDelegate> setGlobalBgmHook;
|
||||||
|
|
||||||
public GameGui(IntPtr baseAddress, SigScanner scanner, Dalamud dalamud) {
|
public GameGui(IntPtr baseAddress, SigScanner scanner, Dalamud dalamud) {
|
||||||
Address = new GameGuiAddressResolver(baseAddress);
|
Address = new GameGuiAddressResolver(baseAddress);
|
||||||
Address.Setup(scanner);
|
Address.Setup(scanner);
|
||||||
|
|
||||||
|
Log.Verbose("===== G A M E G U I =====");
|
||||||
|
|
||||||
Log.Verbose("GameGuiManager address {Address}", Address.BaseAddress);
|
Log.Verbose("GameGuiManager address {Address}", Address.BaseAddress);
|
||||||
|
Log.Verbose("SetGlobalBgm address {Address}", Address.SetGlobalBgm);
|
||||||
|
|
||||||
Chat = new ChatGui(Address.ChatManager, scanner, dalamud);
|
Chat = new ChatGui(Address.ChatManager, scanner, dalamud);
|
||||||
|
|
||||||
|
this.setGlobalBgmHook =
|
||||||
|
new Hook<SetGlobalBgmDelegate>(Address.SetGlobalBgm,
|
||||||
|
new SetGlobalBgmDelegate(HandleSetGlobalBgmDetour),
|
||||||
|
this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IntPtr HandleSetGlobalBgmDetour(UInt16 bgmKey, byte a2, UInt32 a3, UInt32 a4, UInt32 a5, byte a6) {
|
||||||
|
var retVal = this.setGlobalBgmHook.Original(bgmKey, a2, a3, a4, a5, a6);
|
||||||
|
|
||||||
|
Log.Verbose("SetGlobalBgm: {0} {1} {2} {3} {4} {5} -> {6}", bgmKey, a2, a3, a4, a5, a6, retVal);
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetBgm(ushort bgmKey) => this.setGlobalBgmHook.Original(bgmKey, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
public void Enable() {
|
public void Enable() {
|
||||||
Chat.Enable();
|
Chat.Enable();
|
||||||
|
this.setGlobalBgmHook.Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
Chat.Dispose();
|
Chat.Dispose();
|
||||||
|
this.setGlobalBgmHook.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace Dalamud.Game.Internal.Gui {
|
namespace Dalamud.Game.Internal.Gui {
|
||||||
public sealed class GameGuiAddressResolver : BaseAddressResolver {
|
public sealed class GameGuiAddressResolver : BaseAddressResolver {
|
||||||
|
|
@ -7,6 +8,8 @@ namespace Dalamud.Game.Internal.Gui {
|
||||||
|
|
||||||
public IntPtr ChatManager { get; private set; }
|
public IntPtr ChatManager { get; private set; }
|
||||||
|
|
||||||
|
public IntPtr SetGlobalBgm { get; private set; }
|
||||||
|
|
||||||
public GameGuiAddressResolver(IntPtr baseAddress) {
|
public GameGuiAddressResolver(IntPtr baseAddress) {
|
||||||
BaseAddress = baseAddress;
|
BaseAddress = baseAddress;
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +24,8 @@ namespace Dalamud.Game.Internal.Gui {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Setup64Bit(SigScanner sig) {
|
protected override void Setup64Bit(SigScanner sig) {
|
||||||
// Do nothing, still required.
|
//SetGlobalBgm = sig.ScanText("4C 8B 15 ?? ?? ?? ?? 4D 85 D2 74 58 41 83 7A ?? ?? 76 51 4D 8B 92 ?? ?? ?? ?? 0F B6 44 24 ?? 49 81 C2 ?? ?? ?? ?? 66 41 89 4A ?? 33 C9 41 88 52 30 41 89 4A 14 66 41 89 4A ?? 41 88 42 12 49 89 4A 38 41 89 4A 40 49 89 4A 48 41 38 4A 30 74 14 8B 44 24 28 41 89 42 40 45 89 42 38");
|
||||||
|
SetGlobalBgm = sig.ScanText("4C 8B 15 ?? ?? ?? ?? 4D 85 D2 74 58");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ namespace Dalamud.Game.Internal.Gui {
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
this.iconHook.Dispose();
|
this.iconHook.Dispose();
|
||||||
this.checkerHook.Dispose();
|
this.checkerHook.Dispose();
|
||||||
|
Log.Verbose("IconReplacer unhooked");
|
||||||
}
|
}
|
||||||
|
|
||||||
// I hate this function. This is the dumbest function to exist in the game. Just return 1.
|
// I hate this function. This is the dumbest function to exist in the game. Just return 1.
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ namespace Dalamud.Game.Internal.Network {
|
||||||
Address = new GameNetworkAddressResolver();
|
Address = new GameNetworkAddressResolver();
|
||||||
Address.Setup(scanner);
|
Address.Setup(scanner);
|
||||||
|
|
||||||
|
Log.Verbose("===== G A M E N E T W O R K =====");
|
||||||
Log.Verbose("ProcessZonePacket address {ProcessZonePacket}", Address.ProcessZonePacket);
|
Log.Verbose("ProcessZonePacket address {ProcessZonePacket}", Address.ProcessZonePacket);
|
||||||
|
|
||||||
this.processZonePacketHook =
|
this.processZonePacketHook =
|
||||||
|
|
@ -86,10 +87,6 @@ namespace Dalamud.Game.Internal.Network {
|
||||||
InjectZoneProtoPacket(packetData);
|
InjectZoneProtoPacket(packetData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InjectBgmTest(int key) {
|
|
||||||
InjectActorControl(0xa1, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Process a chat queue.
|
/// Process a chat queue.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue