61 lines
2.8 KiB
Python
61 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Prepare the three decoded enUS native chat members for the existing content composer."""
|
|
import argparse
|
|
import hashlib
|
|
from pathlib import Path
|
|
|
|
# From Octo patch-5.mpq, Interface/FrameXML/ChatFrame.lua, OctoStaffChatFlag.
|
|
# All staff use the same authoritative chat flag. Only the message's outer color names the role.
|
|
BADGE = '''local octoStaffRoles = { ["10"] = "GM", ["11"] = "CM", ["12"] = "DJ", ["13"] = "DEV" };
|
|
|
|
function ChatFrameUtil.GetOctoStaffBadge(specialFlag, message)
|
|
if specialFlag ~= "GM" or type(message) ~= "string" or (issecretvalue and issecretvalue(message)) then
|
|
return nil;
|
|
end
|
|
local code, rgb = message:match("^|c(%x%x)(%x%x%x%x%x%x)");
|
|
local role = octoStaffRoles[code];
|
|
if role then
|
|
return "|cff" .. rgb .. "<" .. role .. ">|r";
|
|
end
|
|
end
|
|
|
|
'''
|
|
GET_FLAG = "function ChatFrameUtil.GetPFlag(specialFlag, zoneChannelID, localChannelID)"
|
|
GET_WHISPER = "CHAT_WHISPER_GET:format(pflag..gmLink)"
|
|
GET_CHAT = "local pflag = ChatFrameUtil.GetPFlag(arg6, arg7, arg8);"
|
|
MEMBERS = {
|
|
7208189: ("blizzard_chatframebase/shared/chatframeutil.lua", GET_FLAG, BADGE + GET_FLAG),
|
|
7208188: ("blizzard_chatframebase/mainline/chatframeoverrides.lua", GET_CHAT,
|
|
"local pflag = ChatFrameUtil.GetOctoStaffBadge(arg6, msg) or ChatFrameUtil.GetPFlag(arg6, arg7, arg8);"),
|
|
803980: ("blizzard_gmchatui/blizzard_gmchatui.lua", GET_WHISPER,
|
|
"CHAT_WHISPER_GET:format((ChatFrameUtil.GetOctoStaffBadge(arg6, arg1) or pflag)..gmLink)"),
|
|
}
|
|
|
|
|
|
def prepare(source, output):
|
|
if source.resolve() == output.resolve():
|
|
raise ValueError("Use a separate output directory")
|
|
changes = {}
|
|
for fid, (name, anchor, replacement) in MEMBERS.items():
|
|
relative = Path("interface/addons") / name
|
|
before = (source / relative).read_bytes()
|
|
old = anchor.encode()
|
|
if before.count(old) != 1 or b"GetOctoStaffBadge" in before:
|
|
raise ValueError(f"Unexpected native formatter in {relative}")
|
|
newline = b"\r\n" if b"\r\n" in before else b"\n"
|
|
after = before.replace(old, replacement.encode().replace(b"\n", newline))
|
|
changes[fid] = (relative, before, after)
|
|
for fid, (relative, before, after) in changes.items():
|
|
destination = output / relative
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
destination.write_bytes(after)
|
|
print(fid, hashlib.sha256(before).hexdigest(), hashlib.sha256(after).hexdigest(), relative)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("source", type=Path, help="root of the decoded enUS parent")
|
|
parser.add_argument("output", type=Path, help="destination for the three decoded replacements")
|
|
args = parser.parse_args()
|
|
prepare(args.source, args.output)
|