298 lines
13 KiB
Python
298 lines
13 KiB
Python
"""#113/#114 (owner 2026-11-26: profession abilities "in spellbook as well", "add mounts tab too in spellbook").
|
|
The camelot spellbook makes one tab per visible skill line (General, class trees, Toys) plus Pet/Transmog; profession
|
|
skill lines (Blacksmithing + Weaponsmith/Master smith, Cooking + Basic Campfire, First Aid, Mining's Find Minerals,
|
|
Survival's Find Trees, Fishing...) sit past GetNumSpellBookSkillLines() and had no tab at all. Recipes are not
|
|
spellbook items and stay in the profession window.
|
|
- 5408627 spellbookcategory.lua: the General tab (SpellBookSingleSkillLineCategoryMixin, General index) appends one
|
|
header group per profession skill line, as in 1.12 (owner: "shouldn't the professions appear in general tab?");
|
|
real spellbook slots, so cast/drag/action-bar status stay Blizzard's secure SpellBookItem path; and
|
|
SpellBookOctoMountsCategoryMixin (collected mounts from C_MountJournal, sparse fake slots like Transmog outfits).
|
|
- 5408635 spellbookitem.lua + 5408623 spellbookitem.xml: SpellBookOctoMountItemMixin/Template (outfit-entry clone:
|
|
click summons/dismisses via C_MountJournal, drag picks up the mount spell, mount tooltip).
|
|
- 5484847 spellbookframe.lua: MOUNT element template.
|
|
- 6993216 camelot/blizzard_spellbookframe.lua: Mounts tab after the skill-line tabs.
|
|
The Collections micro button and Shift+P still open Collections > Mounts (unchanged)."""
|
|
import hashlib, json, struct, sys
|
|
from pathlib import Path
|
|
H = Path(__file__).resolve().parent; sys.path.insert(0, str(H))
|
|
import frozen_store as fs
|
|
md5 = lambda b: hashlib.md5(b).hexdigest(); sha = lambda b: hashlib.sha256(b).hexdigest()
|
|
crlf = lambda s: s.replace('\r\n', '\n').replace('\n', '\r\n').encode()
|
|
def once(old, a, b):
|
|
a, b = crlf(a), crlf(b); assert old.count(a) == 1, (a[:60], old.count(a)); return old.replace(a, b)
|
|
CATS = """
|
|
|
|
--------------------------- Octo: Professions --------------------------------
|
|
-- Profession skill lines follow the visible ones (GetNumSpellBookSkillLines) and have no tab of their own. As in 1.12,
|
|
-- their spellbook abilities (not recipes) are listed in the General tab, one header per profession, after the general
|
|
-- spells. Real slots: casting and dragging stay native.
|
|
local OCTO_MAX_PROFESSION_LINES = 16;
|
|
|
|
function SpellBookOctoAppendProfessionGroups(spellGroups, skillLines)
|
|
local first = C_SpellBook.GetNumSpellBookSkillLines() + 1;
|
|
for skillLineIndex = first, first + OCTO_MAX_PROFESSION_LINES - 1 do
|
|
local ok, skillLineInfo = pcall(C_SpellBook.GetSpellBookSkillLineInfo, skillLineIndex);
|
|
if ok and skillLineInfo and skillLineInfo.numSpellBookItems and skillLineInfo.numSpellBookItems > 0 then
|
|
skillLines[skillLineIndex] = true;
|
|
table.insert(spellGroups, {
|
|
displayName = skillLineInfo.name,
|
|
slotIndexOffset = skillLineInfo.itemIndexOffset,
|
|
numSpellBookItems = skillLineInfo.numSpellBookItems,
|
|
showActionBarStatuses = true,
|
|
spellBookItemSlotIndices = {},
|
|
orderedSpellBookItemSlotIndices = {},
|
|
});
|
|
end
|
|
end
|
|
end
|
|
|
|
--------------------------- Octo: Mounts --------------------------------
|
|
-- Collected mounts as spellbook entries (like Transmog outfits: not real spellbook items, sparse fake slots).
|
|
local OCTO_MOUNT_SLOT_OFFSET = 200000;
|
|
|
|
SpellBookOctoMountsCategoryMixin = CreateFromMixins(BaseSpellBookCategoryMixin);
|
|
|
|
function SpellBookOctoMountsCategoryMixin:Init(spellBookFrame)
|
|
self.displayName = MOUNTS;
|
|
self.displayIcon = "Interface\\\\Icons\\\\Ability_Mount_RidingHorse";
|
|
self.spellBank = Enum.SpellBookSpellBank.Player;
|
|
self.categoryEnum = "OctoMounts";
|
|
BaseSpellBookCategoryMixin.Init(self, spellBookFrame);
|
|
end
|
|
|
|
function SpellBookOctoMountsCategoryMixin:GetCollectedMountIDs()
|
|
local mounts = {};
|
|
if not C_MountJournal or not C_MountJournal.GetMountIDs then
|
|
return mounts;
|
|
end
|
|
for _, mountID in ipairs(C_MountJournal.GetMountIDs() or {}) do
|
|
local name, spellID, icon, _, _, _, _, _, _, shouldHideOnChar, isCollected = C_MountJournal.GetMountInfoByID(mountID);
|
|
if name and isCollected and not shouldHideOnChar then
|
|
table.insert(mounts, { mountID = mountID, name = name, spellID = spellID, icon = icon });
|
|
end
|
|
end
|
|
table.sort(mounts, function(a, b) return a.name < b.name; end);
|
|
return mounts;
|
|
end
|
|
|
|
function SpellBookOctoMountsCategoryMixin:GetElementDataForItem(slotIndex)
|
|
local mountID = slotIndex - OCTO_MOUNT_SLOT_OFFSET;
|
|
local name, spellID, icon = C_MountJournal.GetMountInfoByID(mountID);
|
|
if not name then
|
|
return nil;
|
|
end
|
|
return {
|
|
templateKey = "MOUNT",
|
|
mountID = mountID,
|
|
spellID = spellID,
|
|
name = name,
|
|
icon = icon,
|
|
slotIndex = slotIndex,
|
|
spellBank = Enum.SpellBookSpellBank.Player,
|
|
};
|
|
end
|
|
|
|
-- Mount entries are not SpellBookItems: the spellbook item filter (passives, ranks, kiosk) does not apply to them.
|
|
function SpellBookOctoMountsCategoryMixin:GetSpellBookItemData(byDataGroup, _itemFilterFunc, tableToAppendTo)
|
|
return BaseSpellBookCategoryMixin.GetSpellBookItemData(self, byDataGroup, nil, tableToAppendTo);
|
|
end
|
|
|
|
function SpellBookOctoMountsCategoryMixin:UpdateSpellGroups()
|
|
local mounts = self:GetCollectedMountIDs();
|
|
local group = {
|
|
displayName = MOUNTS,
|
|
numSpellBookItems = #mounts,
|
|
spellBookItemSlotIndices = {},
|
|
orderedSpellBookItemSlotIndices = {},
|
|
};
|
|
for index, mount in ipairs(mounts) do
|
|
local slotIndex = OCTO_MOUNT_SLOT_OFFSET + mount.mountID;
|
|
group.spellBookItemSlotIndices[slotIndex] = true;
|
|
group.orderedSpellBookItemSlotIndices[index] = slotIndex;
|
|
end
|
|
local newSpellGroups = { group };
|
|
|
|
local anyChanges = self:DidSpellGroupsChange(self.spellGroups, newSpellGroups, true);
|
|
if anyChanges then
|
|
self.spellGroups = newSpellGroups;
|
|
end
|
|
return anyChanges;
|
|
end
|
|
|
|
function SpellBookOctoMountsCategoryMixin:IsAvailable()
|
|
return self.spellGroups ~= nil and self.spellGroups[1].numSpellBookItems > 0;
|
|
end
|
|
|
|
function SpellBookOctoMountsCategoryMixin:ContainsSkillLine(_skillLineIndex)
|
|
return false;
|
|
end
|
|
"""
|
|
def category(old):
|
|
a = """ displayName = skillLineInfo.name,
|
|
slotIndexOffset = skillLineInfo.itemIndexOffset,
|
|
numSpellBookItems = skillLineInfo.numSpellBookItems,
|
|
showActionBarStatuses = true,
|
|
spellBookItemSlotIndices = {},
|
|
orderedSpellBookItemSlotIndices = {},
|
|
}
|
|
};
|
|
|
|
local compareSpellIndicies = false;
|
|
local anyChanges = self:DidSpellGroupsChange(self.spellGroups, newSpellGroups, compareSpellIndicies);
|
|
"""
|
|
old = once(old, a, """ displayName = skillLineInfo.name,
|
|
slotIndexOffset = skillLineInfo.itemIndexOffset,
|
|
numSpellBookItems = skillLineInfo.numSpellBookItems,
|
|
showActionBarStatuses = true,
|
|
spellBookItemSlotIndices = {},
|
|
orderedSpellBookItemSlotIndices = {},
|
|
}
|
|
};
|
|
-- Octo (Turtle): profession abilities live in the General tab, as in 1.12.
|
|
self.octoProfessionSkillLines = {};
|
|
if self.skillLineIndex == Enum.SpellBookSkillLineIndex.General and SpellBookOctoAppendProfessionGroups then
|
|
SpellBookOctoAppendProfessionGroups(newSpellGroups, self.octoProfessionSkillLines);
|
|
end
|
|
|
|
local compareSpellIndicies = false;
|
|
local anyChanges = self:DidSpellGroupsChange(self.spellGroups, newSpellGroups, compareSpellIndicies);
|
|
""")
|
|
old = once(old, """function SpellBookSingleSkillLineCategoryMixin:ContainsSkillLine(skillLineIndex)
|
|
return self.skillLineIndex == skillLineIndex;
|
|
""", """function SpellBookSingleSkillLineCategoryMixin:ContainsSkillLine(skillLineIndex)
|
|
if self.octoProfessionSkillLines and self.octoProfessionSkillLines[skillLineIndex] then
|
|
return true;
|
|
end
|
|
return self.skillLineIndex == skillLineIndex;
|
|
""")
|
|
return old + crlf(CATS)
|
|
ITEM = """
|
|
|
|
-- Octo: collected mount entry in the spellbook Mounts tab (clone of the outfit entry; not a SpellBookItem).
|
|
SpellBookOctoMountItemMixin = CreateFromMixins(SpellBookOutfitItemMixin);
|
|
|
|
function SpellBookOctoMountItemMixin:Init(elementData)
|
|
self.elementData = elementData;
|
|
self.Button.buttonContext = "ButtonContext_OctoMountButton";
|
|
self:UpdateSpellData(true);
|
|
end
|
|
|
|
function SpellBookOctoMountItemMixin:OnEvent(event, ...)
|
|
if event == "SPELL_UPDATE_COOLDOWN" then
|
|
self:UpdateCooldown();
|
|
end
|
|
end
|
|
|
|
function SpellBookOctoMountItemMixin:GetMountID()
|
|
return self:HasValidData() and self.elementData.mountID;
|
|
end
|
|
|
|
function SpellBookOctoMountItemMixin:OnIconClick(_button)
|
|
local mountID = self:GetMountID();
|
|
if not mountID then
|
|
return;
|
|
end
|
|
local _, _, _, isActive = C_MountJournal.GetMountInfoByID(mountID);
|
|
if isActive then
|
|
C_MountJournal.Dismiss();
|
|
else
|
|
C_MountJournal.SummonByID(mountID);
|
|
end
|
|
end
|
|
|
|
function SpellBookOctoMountItemMixin:OnModifiedIconClick(_button)
|
|
local spellID = self:HasValidData() and self.elementData.spellID;
|
|
if spellID and IsModifiedClick("CHATLINK") then
|
|
local link = C_Spell.GetSpellLink(spellID);
|
|
if link then
|
|
ChatFrameUtil.InsertLink(link);
|
|
end
|
|
end
|
|
end
|
|
|
|
function SpellBookOctoMountItemMixin:OnIconEnter()
|
|
local spellID = self:HasValidData() and self.elementData.spellID;
|
|
if not spellID then
|
|
return;
|
|
end
|
|
local tooltip = GameTooltip;
|
|
tooltip:SetOwner(self.Button, "ANCHOR_RIGHT");
|
|
if tooltip.SetMountBySpellID then
|
|
tooltip:SetMountBySpellID(spellID);
|
|
else
|
|
tooltip:SetSpellByID(spellID);
|
|
end
|
|
tooltip:Show();
|
|
if (InputUtil.IsGamepadUIEnabled()) then
|
|
self:GamepadAdjustTooltipAnchor(tooltip);
|
|
end
|
|
end
|
|
|
|
function SpellBookOctoMountItemMixin:OnIconDragStart()
|
|
local spellID = self:HasValidData() and self.elementData.spellID;
|
|
if spellID then
|
|
C_Spell.PickupSpell(spellID);
|
|
end
|
|
end
|
|
|
|
function SpellBookOctoMountItemMixin:UpdateCooldown()
|
|
CooldownFrame_Clear(self.Button.Cooldown);
|
|
end
|
|
"""
|
|
def item(old):
|
|
return old + crlf(ITEM)
|
|
def itemxml(old):
|
|
a = """ <Frame name="SpellBookOutfitItemTemplate" inherits="SpellBookItemTemplate" mixin="SpellBookOutfitItemMixin" virtual="true"/>
|
|
"""
|
|
return once(old, a, a + """ <Frame name="SpellBookOctoMountItemTemplate" inherits="SpellBookItemTemplate" mixin="SpellBookOctoMountItemMixin" virtual="true"/>
|
|
""")
|
|
def frame(old):
|
|
a = """ ["OUTFIT"] = { template = "SpellBookOutfitItemTemplate", initFunc = SpellBookOutfitItemMixin.Init, resetFunc = SpellBookItemMixin.Reset },
|
|
"""
|
|
return once(old, a, a + """ ["MOUNT"] = { template = "SpellBookOctoMountItemTemplate", initFunc = SpellBookOctoMountItemMixin.Init, resetFunc = SpellBookItemMixin.Reset },
|
|
""")
|
|
def camelot(old):
|
|
a = """ local petCategoryMixin = CreateAndInitFromMixin(SpellBookPetCategoryMixin, self);
|
|
"""
|
|
return once(old, a, """ -- Octo (Turtle): collected mounts get their own tab (profession abilities are in General).
|
|
local mountsCategoryMixin = CreateAndInitFromMixin(SpellBookOctoMountsCategoryMixin, self);
|
|
table.insert(self.categoryMixins, mountsCategoryMixin);
|
|
local mountsTabID = self:AddIconTab(mountsCategoryMixin:GetIcon());
|
|
mountsCategoryMixin:SetTabID(mountsTabID);
|
|
self.CategoryTabSystem:GetTabButton(mountsTabID):SetTooltipText(mountsCategoryMixin:GetName());
|
|
|
|
""" + a)
|
|
FILES = [(5408627, 'interface/addons/blizzard_playerspells/spellbook/blizzard_spellbookcategory.lua', category),
|
|
(5408635, 'interface/addons/blizzard_playerspells/spellbook/blizzard_spellbookitem.lua', item),
|
|
(5408623, 'interface/addons/blizzard_playerspells/spellbook/blizzard_spellbookitem.xml', itemxml),
|
|
(5484847, 'interface/addons/blizzard_playerspells/spellbook/blizzard_spellbookframe.lua', frame),
|
|
(6993216, 'interface/addons/blizzard_playerspells/camelot/spellbook/blizzard_spellbookframe.lua', camelot)]
|
|
WHY = '#113/#114: profession abilities in the spellbook General tab; Mounts tab (collected mounts)'
|
|
store = fs.Store(); root = store.root; lay = store.layout; assert lay['root_md5'] == fs.ROOT
|
|
patched = bytearray(root); pins = []
|
|
for FID, NAME, edit in FILES:
|
|
cells = []
|
|
for g in lay['groups']:
|
|
f = 0
|
|
for i, (d,) in enumerate(struct.iter_unpack('<I', memoryview(root)[g['ids_offset']:g['ckeys_offset']])):
|
|
f += d
|
|
if f == FID: cells.append((g, g['ckeys_offset'] + i * 16))
|
|
f += 1
|
|
en = [(g, at) for g, at in cells if g['locale'] & 2 and not g.get('flags1')]; assert len(en) == 1, len(en)
|
|
g, at = en[0]; ck = root[at:at + 16].hex(); old = store.read(ck)[2]
|
|
new = edit(old)
|
|
(H / 'inputs').mkdir(exist_ok=True)
|
|
(H / 'inputs' / f'{FID}.before.lua').write_bytes(old); (H / 'inputs' / f'{FID}.after.lua').write_bytes(new)
|
|
patched[at:at + 16] = bytes.fromhex(md5(new))
|
|
d = H / 'pins' / str(FID); d.mkdir(parents=True, exist_ok=True)
|
|
(d / 'before.bin').write_bytes(old); (d / 'after.bin').write_bytes(new)
|
|
pin = dict(fdid=FID, table=NAME, parent_root=fs.ROOT, selected_group={}, original_decoded=dict(file='before.bin', md5=ck, sha256=sha(old)),
|
|
encrypted_original=False, after_decoded=dict(file='after.bin', md5=md5(new), sha256=sha(new)), reason=WHY)
|
|
(d / 'pin.json').write_text(json.dumps(pin, indent=1) + '\n')
|
|
pins.append(dict(file=str(d / 'pin.json'), sha256=sha((d / 'pin.json').read_bytes()), type='wdc_enus'))
|
|
print(FID, len(old), len(new))
|
|
(H / 'components.json').write_text(json.dumps(pins, indent=2) + '\n')
|
|
(H / 'selected-root.json').write_text(json.dumps(dict(parent_build=fs.BUILD, parent_root=fs.ROOT,
|
|
decoded_root_sha256=sha(bytes(patched)), parent_root_sha256=sha(root)), indent=2) + '\n')
|
|
print('pins', len(pins))
|