From 43367fd363057f34746344a4e6869fce85ba2deb Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 3 Jul 2024 19:39:56 +0100 Subject: [PATCH] Added `RandomDialog` - Added `RCF` library --- Randomiser/CustomFiles.lua | 1 + Randomiser/Meta.ini | 90 ++++++++ Randomiser/Resources/Modules/Audio/Dialog.lua | 204 ++++++++++++++++++ Randomiser/Resources/lib/RCF.lua | 122 +++++++++++ 4 files changed, 417 insertions(+) create mode 100644 Randomiser/Resources/Modules/Audio/Dialog.lua create mode 100644 Randomiser/Resources/lib/RCF.lua diff --git a/Randomiser/CustomFiles.lua b/Randomiser/CustomFiles.lua index e55b4b1..e85d824 100644 --- a/Randomiser/CustomFiles.lua +++ b/Randomiser/CustomFiles.lua @@ -10,6 +10,7 @@ P3D.LoadChunks(Paths.Lib .. "/P3DChunks") dofile(Paths.Lib .. "/P3DUtils.lua") dofile(Paths.Lib .. "/MFKLexer.lua") dofile(Paths.Lib .. "/SPTParser.lua") +dofile(Paths.Lib .. "/RCF.lua") dofile(Paths.Lib .. "/ModuleLoader.lua") diff --git a/Randomiser/Meta.ini b/Randomiser/Meta.ini index 0703ad9..d63d881 100644 --- a/Randomiser/Meta.ini +++ b/Randomiser/Meta.ini @@ -391,6 +391,96 @@ ConditionSetting=RandomMusic Operator=EqualTo Value=1 +[Setting] +Name=RandomDialog +Title=Random Dialog +Type=TickBox +Default=0 +Tooltip=Randomises all game dialog. +Page=Randomisations +Group=Audio + +[Setting] +Name=RandomDialogMode +Title=Mode +Type=MultipleChoice +Option=Normal Random +Option=Super Random +Option=Mixed +Page=Randomisations +Group=Audio + +[SettingCondition] +Type=Setting +Setting=RandomDialogMode +ConditionSetting=RandomDialog +Operator=EqualTo +Value=1 + +[Setting] +Name=RandomDialogEnglish +Title=Include English +Type=TickBox +Default=1 +Tooltip=Include English dialog - requires dialog.rcf +Page=Randomisations +Group=Audio + +[SettingCondition] +Type=Setting +Setting=RandomDialogEnglish +ConditionSetting=RandomDialog +Operator=EqualTo +Value=1 + +[Setting] +Name=RandomDialogFrench +Title=Include French +Type=TickBox +Default=0 +Tooltip=Include French dialog - requires dialogf.rcf +Page=Randomisations +Group=Audio + +[SettingCondition] +Type=Setting +Setting=RandomDialogFrench +ConditionSetting=RandomDialog +Operator=EqualTo +Value=1 + +[Setting] +Name=RandomDialogGerman +Title=Include German +Type=TickBox +Default=0 +Tooltip=Include German dialog - requires dialogg.rcf +Page=Randomisations +Group=Audio + +[SettingCondition] +Type=Setting +Setting=RandomDialogGerman +ConditionSetting=RandomDialog +Operator=EqualTo +Value=1 + +[Setting] +Name=RandomDialogSpanish +Title=Include Spanish +Type=TickBox +Default=0 +Tooltip=Include Spanish dialog - requires dialogs.rcf +Page=Randomisations +Group=Audio + +[SettingCondition] +Type=Setting +Setting=RandomDialogSpanish +ConditionSetting=RandomDialog +Operator=EqualTo +Value=1 + [Setting] Name=RandomText Title=Random Text diff --git a/Randomiser/Resources/Modules/Audio/Dialog.lua b/Randomiser/Resources/Modules/Audio/Dialog.lua new file mode 100644 index 0000000..2c2fa02 --- /dev/null +++ b/Randomiser/Resources/Modules/Audio/Dialog.lua @@ -0,0 +1,204 @@ +local math_min = math.min +local math_random = math.random +local string_format = string.format +local string_lower = string.lower +local string_pack = string.pack +local string_rep = string.rep +local string_sub = string.sub +local string_unpack = string.unpack +local table_concat = table.concat + +local GetFileExtension = GetFileExtension + +local RandomDialog = Module("Random Dialog", "RandomDialog") + +local RandomDialogMode = Settings.RandomDialogMode + +local RSDFiles = {} +local RSDFilesN = 0 + +local RSDSignature = "RSD4RADP" +local function LoadRSDsFromRCF(Path) + local RCFFile = RCF.RCFFile(Path) + + local loaded = 0 + for i=1,#RCFFile.Files do + local file = RCFFile.Files[i] + if string_lower(GetFileExtension(file.Name)) == ".rsd" then + local Signature, Channels, Bits, SampleRate = string_unpack("" or "<" + + local headerStartPos + Data.Alignment, Data.PadNetSize, headerStartPos, pos = string_unpack(endian .. "III", contents, pos) + + local numFiles, detailedFileInfoStartPos, firstFileStartPos, hashedFileEntriesPointer, pos = string_unpack(endian .. "III