From 986488726387d8d130a6fe4815951bffa5d87e29 Mon Sep 17 00:00:00 2001 From: OptimShi Date: Tue, 20 Aug 2024 16:26:08 -0700 Subject: [PATCH] DatReader - ActionMap (#4217) * Added ActionMap Dat reading 0x26000000 * Removed debug code from startup --- Source/ACE.DatLoader.Tests/DatTests.cs | 1 - Source/ACE.DatLoader/Entity/ActionMapValue.cs | 23 ++++++++ .../Entity/InputMapConflictsValue.cs | 17 ++++++ Source/ACE.DatLoader/FileTypes/ActionMap.cs | 56 +++++++++++++++++++ .../FileTypes/UserBindingValue.cs | 22 ++++++++ Source/ACE.Server/Program.cs | 6 +- 6 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 Source/ACE.DatLoader/Entity/ActionMapValue.cs create mode 100644 Source/ACE.DatLoader/Entity/InputMapConflictsValue.cs create mode 100644 Source/ACE.DatLoader/FileTypes/ActionMap.cs create mode 100644 Source/ACE.DatLoader/FileTypes/UserBindingValue.cs diff --git a/Source/ACE.DatLoader.Tests/DatTests.cs b/Source/ACE.DatLoader.Tests/DatTests.cs index d86228040d..ccf686ae68 100644 --- a/Source/ACE.DatLoader.Tests/DatTests.cs +++ b/Source/ACE.DatLoader.Tests/DatTests.cs @@ -144,7 +144,6 @@ public void UnpackPortalDatFiles_NoExceptions() if (fileType == DatFileType.RenderMaterial) continue; // 0x16, 1 file if (fileType == DatFileType.MaterialModifier) continue; // 0x17, 1 file if (fileType == DatFileType.MaterialInstance) continue; // 0x18, 1 file - if (fileType == DatFileType.ActionMap) continue; // 0x26, 1 file var type = types .SelectMany(m => m.GetCustomAttributes(typeof(DatFileTypeAttribute), false), (m, a) => new { m, a }) diff --git a/Source/ACE.DatLoader/Entity/ActionMapValue.cs b/Source/ACE.DatLoader/Entity/ActionMapValue.cs new file mode 100644 index 0000000000..6f4184f048 --- /dev/null +++ b/Source/ACE.DatLoader/Entity/ActionMapValue.cs @@ -0,0 +1,23 @@ +using System.IO; + +namespace ACE.DatLoader.Entity +{ + public class ActionMapValue : IUnpackable + { + public byte UnknownByte { get; private set; } + public uint UnknownInt { get; private set; } + public uint UnknownInt2 { get; private set; } + public uint ToggleType { get; private set; } + public UserBindingValue UserBindingData { get; private set; } + + public void Unpack(BinaryReader reader) + { + UnknownByte = reader.ReadByte(); + UnknownInt = reader.ReadUInt32(); + UnknownInt2 = reader.ReadUInt32(); + ToggleType = reader.ReadUInt32(); + UserBindingData = new UserBindingValue(); + UserBindingData.Unpack(reader); + } + } +} diff --git a/Source/ACE.DatLoader/Entity/InputMapConflictsValue.cs b/Source/ACE.DatLoader/Entity/InputMapConflictsValue.cs new file mode 100644 index 0000000000..6209f54355 --- /dev/null +++ b/Source/ACE.DatLoader/Entity/InputMapConflictsValue.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.IO; + +namespace ACE.DatLoader.Entity +{ + public class InputMapConflictsValue : IUnpackable + { + public uint InputMap { get; private set; } + public List ConflictingInputMaps { get; private set; } = new List(); + + public void Unpack(BinaryReader reader) + { + InputMap = reader.ReadUInt32(); + ConflictingInputMaps.Unpack(reader); + } + } +} diff --git a/Source/ACE.DatLoader/FileTypes/ActionMap.cs b/Source/ACE.DatLoader/FileTypes/ActionMap.cs new file mode 100644 index 0000000000..2feaac1453 --- /dev/null +++ b/Source/ACE.DatLoader/FileTypes/ActionMap.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using System.IO; + +using ACE.DatLoader.Entity; +using ACE.Entity.Enum; +using static System.Net.Mime.MediaTypeNames; + +namespace ACE.DatLoader.FileTypes +{ + /// + /// This is the client_portal.dat file 0x26000000; It's related to keyboard configuration. + /// + [DatFileType(DatFileType.ActionMap)] + public class ActionMap : FileType + { + public Dictionary> InputMaps { get; } = new Dictionary>(); + public uint StringTable { get; set; } // DID Value to lookup all the hashes in -- will be 0x23000005 + public Dictionary ConflictingMaps { get; } = new Dictionary(); + + public override void Unpack(BinaryReader reader) + { + Id = reader.ReadUInt32(); + + reader.ReadByte(); // bucket/size + byte count = reader.ReadByte(); + for (var i = 0; i < count; i++) + { + var key = reader.ReadUInt32(); + reader.ReadByte(); // bucket/size + byte valuesCount = reader.ReadByte(); + Dictionary values = new Dictionary(); + for (var j = 0; j < valuesCount; j++) + { + uint valuesKey = reader.ReadUInt32(); + ActionMapValue value = new ActionMapValue(); + value.Unpack(reader); + values.Add(valuesKey, value); + } + InputMaps.Add(key, values); + } + + StringTable = reader.ReadUInt32(); // Will be 0x23000005 + + reader.ReadByte(); // bucket/size + byte conflictCount = reader.ReadByte(); + for (var i = 0; i < conflictCount; i++) { + var key = reader.ReadUInt32(); + InputMapConflictsValue conflictValue = new InputMapConflictsValue(); + conflictValue.Unpack(reader); + ConflictingMaps.Add(key, conflictValue); + } + } + + + } +} diff --git a/Source/ACE.DatLoader/FileTypes/UserBindingValue.cs b/Source/ACE.DatLoader/FileTypes/UserBindingValue.cs new file mode 100644 index 0000000000..0e52b0da1f --- /dev/null +++ b/Source/ACE.DatLoader/FileTypes/UserBindingValue.cs @@ -0,0 +1,22 @@ +using System.IO; + +namespace ACE.DatLoader.Entity +{ + public class UserBindingValue : IUnpackable + { + public uint ActionClass { get; private set; } + + // String hash from the StringTable + public uint ActionName { get; private set; } + + // String hash from the StringTable + public uint Description { get; private set; } + + public void Unpack(BinaryReader reader) + { + ActionClass = reader.ReadUInt32(); + ActionName = reader.ReadUInt32(); + Description = reader.ReadUInt32(); + } + } +} diff --git a/Source/ACE.Server/Program.cs b/Source/ACE.Server/Program.cs index 01e41aac8b..884b68507c 100644 --- a/Source/ACE.Server/Program.cs +++ b/Source/ACE.Server/Program.cs @@ -26,7 +26,7 @@ partial class Program /// https://docs.microsoft.com/en-us/windows/desktop/api/timeapi/nf-timeapi-timebeginperiod /// Important note: This function affects a global Windows setting. Windows uses the lowest value (that is, highest resolution) requested by any process. /// - [DllImport("winmm.dll", EntryPoint="timeBeginPeriod")] + [DllImport("winmm.dll", EntryPoint = "timeBeginPeriod")] public static extern uint MM_BeginPeriod(uint uMilliseconds); /// @@ -86,7 +86,7 @@ public static void Main(string[] args) File.Copy(log4netConfigExample, log4netConfig); } else - { + { if (!File.Exists(log4netConfigContainer)) { Console.WriteLine("log4net Configuration file is missing, ACEmulator is running in a container, cloning from docker file."); @@ -127,7 +127,7 @@ public static void Main(string[] args) if (IsRunningInContainer) log.Info("ACEmulator is running in a container..."); - + var configFile = Path.Combine(exeLocation, "Config.js"); var configConfigContainer = Path.Combine(containerConfigDirectory, "Config.js");