From b2f5081c59a613ca19f455a8fe04e28afb9d880c Mon Sep 17 00:00:00 2001 From: Juangui <80857657+justjuangui@users.noreply.github.com> Date: Sun, 21 Jul 2024 14:55:41 -0500 Subject: [PATCH] QoL Enums Data file was added, Trade Data relative was added (#7275) * QoL Enums Data file was added, Trade Data relative was added * COmmentas was added, Unused variable was removed * Method was renamed * Tooltips was added * Enum indentation was fixed * Enum indentation was fixed v2 --------- Co-authored-by: justjuangui --- src/Export/Classes/Dat64File.lua | 8 +- src/Export/Classes/GGPKData.lua | 16 +++ src/Export/Main.lua | 33 +++++- src/Export/Scripts/enums.lua | 69 ++++++++++++ src/Export/spec.lua | 187 ++++++++++++++++++++++++++++++- 5 files changed, 307 insertions(+), 6 deletions(-) create mode 100644 src/Export/Scripts/enums.lua diff --git a/src/Export/Classes/Dat64File.lua b/src/Export/Classes/Dat64File.lua index 756c3b33b8..4c52187fb6 100644 --- a/src/Export/Classes/Dat64File.lua +++ b/src/Export/Classes/Dat64File.lua @@ -274,9 +274,13 @@ function Dat64FileClass:ReadValueText(spec, offset) end local other = main.datFileByName[spec.refTo:lower()] if other then - local otherRow = other.rows[val + ((spec.type == "Enum" and spec.refTo:lower() ~= self.name) and 0 or 1)] + local newVal = val + ((spec.type == "Enum" and spec.refTo:lower() ~= self.name) and 0 or 1) + if (spec.enumBase and spec.enumBase > 0) then + newVal = newVal + spec.enumBase + end + local otherRow = other.rows[newVal] if not otherRow then - return "" + return "" end if other.spec[1] then return other:ReadValueText(other.spec[1], otherRow) diff --git a/src/Export/Classes/GGPKData.lua b/src/Export/Classes/GGPKData.lua index 29148ba254..22f5456bad 100644 --- a/src/Export/Classes/GGPKData.lua +++ b/src/Export/Classes/GGPKData.lua @@ -71,6 +71,12 @@ function GGPKClass:ExtractFiles() local cmd = 'cd ' .. self.oozPath .. ' && bun_extract_file.exe extract-files "' .. self.path .. '" . ' .. fileList ConPrintf(cmd) os.execute(cmd) + + -- Overwrite Enums + local errMsg = PLoadModule("Scripts/enums.lua") + if errMsg then + print(errMsg) + end end function GGPKClass:AddDatFiles() @@ -228,6 +234,16 @@ function GGPKClass:GetNeededFiles() "Data/weaponclasses.dat", "Data/monsterconditions.dat", "Data/rarity.dat", + "Data/trademarketcategory.dat", + "Data/trademarketcategorygroups.dat", + "Data/PlayerTradeWhisperFormats.dat", + "Data/TradeMarketCategoryListAllClass.dat", + "Data/TradeMarketIndexItemAs.dat", + "Data/TradeMarketImplicitModDisplay.dat", + "Data/Commands.dat", + "Data/ModEquivalencies.dat", + "Data/InfluenceTags.dat", + "Data/InfluenceTypes.dat" } local txtFiles = { "Metadata/StatDescriptions/passive_skill_aura_stat_descriptions.txt", diff --git a/src/Export/Main.lua b/src/Export/Main.lua index 35029cda5e..31f9deaa88 100644 --- a/src/Export/Main.lua +++ b/src/Export/Main.lua @@ -235,6 +235,10 @@ function main:Init() end) { shown = function() return self.curSpecCol + end, + tooltipFunc = function(tooltip) + tooltip:Clear() + tooltip:AddLine(16, "^7Field name in the dat file") end } @@ -242,7 +246,7 @@ function main:Init() self.curSpecCol.type = value self.curDatFile:OnSpecChanged() self:UpdateCol() - end) + end, "^7Field type in the dat file") self.controls.colIsList = new("CheckBoxControl", {"TOPLEFT",self.controls.colType,"BOTTOMLEFT"}, 30, 4, 18, "List:", function(state) self.curSpecCol.list = state @@ -253,12 +257,34 @@ function main:Init() self.controls.colRefTo = new("EditControl", {"TOPLEFT",self.controls.colType,"BOTTOMLEFT"}, 0, 26, 150, 18, nil, nil, nil, nil, function(buf) self.curSpecCol.refTo = buf self.curDatFile:OnSpecChanged() - end) + end) { + tooltipFunc = function(tooltip) + tooltip:Clear() + tooltip:AddLine(16, "^7Reference to another dat file") + end + } self.controls.colWidth = new("EditControl", {"TOPLEFT",self.controls.colRefTo,"BOTTOMLEFT"}, 0, 4, 100, 18, nil, nil, "%D", nil, function(buf) self.curSpecCol.width = m_max(tonumber(buf) or 150, 20) self.controls.rowList:BuildColumns() - end) { numberInc = 10 } + end) { + numberInc = 10, + tooltipFunc = function(tooltip) + tooltip:Clear() + tooltip:AddLine(16, "^7Column width in the grid") + end + } + + self.controls.enumBase = new("EditControl", {"TOPLEFT",self.controls.colWidth,"BOTTOMLEFT"}, 0, 4, 100, 18, nil, nil, "%D", nil, function(buf) + self.curSpecCol.enumBase = tonumber(buf) or 0 + self.curDatFile:OnSpecChanged() + end) { + numberInc = 1, + tooltipFunc = function(tooltip) + tooltip:Clear() + tooltip:AddLine(16, "^7Base value for enum types") + end + } self.controls.colDelete = new("ButtonControl", {"BOTTOMRIGHT",self.controls.colName,"TOPRIGHT"}, 0, -4, 18, 18, "x", function() t_remove(self.curDatFile.spec, self.curSpecColIndex) @@ -468,6 +494,7 @@ function main:UpdateCol() self.controls.colRefTo.enabled = self.curDatFile.cols[self.curSpecColIndex].isRef self.controls.colRefTo:SetText(self.curSpecCol.refTo) self.controls.colWidth:SetText(self.curSpecCol.width) + self.controls.enumBase:SetText(self.curSpecCol.enumBase or 0) self.controls.rowList:BuildColumns() end diff --git a/src/Export/Scripts/enums.lua b/src/Export/Scripts/enums.lua new file mode 100644 index 0000000000..9ba27487d7 --- /dev/null +++ b/src/Export/Scripts/enums.lua @@ -0,0 +1,69 @@ +local band = bit.band +local rshift = bit.rshift +local push = table.insert +local schar = string.char + +local function writeNum(n, c) + local bytes = {} + for i = 1, c do + push(bytes, schar(band(n, 0xFF))) + n = rshift(n, 8) + end + return table.concat(bytes) +end + +function len(t) + local count = 0 + for _ in pairs(t) do count = count + 1 end + return count +end + +local function writeEnum(filename, enumTable) + local filenameAbs = "./ggpk/data/" .. filename + local out = io.open(filenameAbs, "wb") + local size = len(enumTable) + + out:write(writeNum(size,4)) + + -- Write fields + local stringIndex = 8 + for v, s in ipairs(enumTable) do + out:write(writeNum(stringIndex,8)) + local utf16 = convertUTF8to16(s) + stringIndex = stringIndex + utf16:len() + 2 + end + + -- data offset mark + for i = 1, 8 do + out:write(schar(0xBB)) + end + + -- strings in utf16 + for _, s in ipairs(enumTable) do + out:write(convertUTF8to16(s) .. "\0\0") + end + + out:close() + print("Wrote " .. size .. " enum types to " .. filename) +end + + +-- influenced types +local influenceTypes = { + "Shaper", + "Elder", + "Crusader", + "Eyrie", + "Basilisk", + "Adjudicator", + "None" +} + +writeEnum("influenceTypes.dat64", influenceTypes) + +-- passive Skills types +local passiveSkillTypes = { + "Passive Tree", + "Atlas Tree" +} +writeEnum("passiveSkillTypes.dat64", passiveSkillTypes) diff --git a/src/Export/spec.lua b/src/Export/spec.lua index ff6cb80774..83b8b1803f 100644 --- a/src/Export/spec.lua +++ b/src/Export/spec.lua @@ -2965,6 +2965,48 @@ return { colours={ }, commands={ + [1]={ + list=false, + name="Id", + refTo="", + type="String", + width=300 + }, + [2]={ + list=false, + name="Command", + refTo="", + type="String", + width=150 + }, + [3]={ + list=false, + name="", + refTo="", + type="Bool", + width=150 + }, + [4]={ + list=false, + name="EnglishCommand", + refTo="", + type="String", + width=150 + }, + [5]={ + list=false, + name="Description", + refTo="", + type="String", + width=600 + }, + [6]={ + list=false, + name="", + refTo="", + type="Bool", + width=150 + } }, componentarmour={ [1]={ @@ -5528,8 +5570,38 @@ return { influencemodupgrades={ }, influencetags={ + [1]={ + list=false, + name="ItemClass", + refTo="ItemClasses", + type="Key", + width=150 + }, + [2]={ + enumBase=1, + list=false, + name="InfluenceType", + refTo="influencetypes", + type="Enum", + width=150 + }, + [3]={ + list=false, + name="tags", + refTo="Tags", + type="Key", + width=150 + } }, influencetypes={ + [1]={ + enumBase=0, + list=false, + name="Name", + refTo="", + type="String", + width=150 + } }, invasionmonstergroups={ }, @@ -9311,10 +9383,11 @@ return { width=60 }, [30]={ + enumBase=1, list=false, name="Type", refTo="PassiveSkillTypes", - type="Int", + type="Enum", width=80 }, [31]={ @@ -9508,6 +9581,13 @@ return { passiveskilltreeuiart={ }, passiveskilltypes={ + [1]={ + list=false, + name="Name", + refTo="", + type="String", + width=150 + } }, passivetreeexpansionjewels={ [1]={ @@ -11238,16 +11318,121 @@ return { tormentspirits={ }, trademarketcategory={ + [1]={ + list=false, + name="Id", + refTo="", + type="String", + width=200 + }, + [2]={ + list=false, + name="Name", + refTo="", + type="String", + width=300 + }, + [3]={ + list=false, + name="StyleFlag", + refTo="", + type="Enum", + width=150 + }, + [4]={ + list=false, + name="Group", + refTo="TradeMarketCategoryGroups", + type="Key", + width=200 + }, + [5]={ + list=false, + name="", + refTo="", + type="Int", + width=150 + }, + [6]={ + list=false, + name="", + refTo="", + type="Bool", + width=150 + }, + [7]={ + list=false, + name="IsDisabled", + refTo="", + type="Bool", + width=150 + } }, trademarketcategorygroups={ + [1]={ + list=false, + name="Id", + refTo="", + type="String", + width=200 + }, + [2]={ + list=false, + name="Name", + refTo="", + type="String", + width=200 + } }, trademarketcategorylistallclass={ + [1]={ + list=false, + name="TradeCategory", + refTo="TradeMarketCategory", + type="Key", + width=200 + }, + [2]={ + list=false, + name="ItemClass", + refTo="ItemClasses", + type="Key", + width=200 + } }, trademarketcategorystyleflag={ }, trademarketimplicitmoddisplay={ + [1]={ + list=false, + name="", + refTo="", + type="Key", + width=150 + }, + [2]={ + list=false, + name="", + refTo="", + type="String", + width=200 + } }, trademarketindexitemas={ + [1]={ + list=false, + name="Item", + refTo="", + type="Key", + width=150 + }, + [2]={ + list=false, + name="IndexAs", + refTo="", + type="Key", + width=150 + } }, treasurehuntermissions={ },