Kitty Corp Meow Mix Forums

Super Smash Bros. Brawl Hacking => Programming => Topic started by: libertyernie on February 24, 2017, 01:36:36 PM



Title: BrawlBox plugins (v0.78) - updated 2017-03-23
Post by: libertyernie on February 24, 2017, 01:36:36 PM
This is a thread for BrawlBox plugin scripts. v0.78 has a system that lets you write plugins in Python.

Just copy the text into Notepad and save it as a file with a .py extension in the Plugins folder alongside BrawlBox. Then you'll see it in BrawlBox under Plugins in the menu bar.

Batch convert files (pac <-> pcs)

To .pcs
Code:
from BrawlBox.API import bboxapi
from BrawlLib.SSBB.ResourceNodes import *

import os

dir = bboxapi.OpenFolderDialog()
if dir is not "":
include_subfolders = bboxapi.ShowYesNoPrompt("Include subfolders?", "Batch conversion")

from_ext = ".pac"
to_ext = ".pcs"

if not from_ext.startswith("."):
from_ext = "." + from_ext;

if not to_ext.startswith("."):
to_ext = "." + to_ext;

for root, dirs, files in os.walk(dir):
for file in files:
if file.lower().endswith(from_ext):
no_ext, ext = os.path.splitext(file)
node = NodeFactory.FromFile(None, os.path.join(root, file))
try:
node.Export(os.path.join(root, no_ext + to_ext))
node.Dispose()
except:
bboxapi.ShowMessage("Cannot export " + file + " as format " + to_ext, "Error")
if not include_subfolders:
break
To .pac
Code:
from BrawlBox.API import bboxapi
from BrawlLib.SSBB.ResourceNodes import *

import os

dir = bboxapi.OpenFolderDialog()
if dir is not "":
include_subfolders = bboxapi.ShowYesNoPrompt("Include subfolders?", "Batch conversion")

from_ext = ".pcs"
to_ext = ".pac"

if not from_ext.startswith("."):
from_ext = "." + from_ext;

if not to_ext.startswith("."):
to_ext = "." + to_ext;

for root, dirs, files in os.walk(dir):
for file in files:
if file.lower().endswith(from_ext):
no_ext, ext = os.path.splitext(file)
node = NodeFactory.FromFile(None, os.path.join(root, file))
try:
node.Compression = "None"
node.Export(os.path.join(root, no_ext + to_ext))
node.Dispose()
except:
bboxapi.ShowMessage("Cannot export " + file + " as format " + to_ext, "Error")
if not include_subfolders:
break

LZ77 to ExtendedLZ77 (2017-3-23 - now supports subnodes)
Code:
from BrawlBox.API import bboxapi
from BrawlLib.SSBB.ResourceNodes import *

import os
import shutil

def haslz77(node):
if node.Compression == "LZ77":
return True
if node.GetType().Name == "ARCNode":
for child in node.Children:
if haslz77(child):
return True
return False

def modifylz77(node):
if node.Compression == "LZ77":
node.Compression = "ExtendedLZ77"
if node.GetType().Name == "ARCNode":
for child in node.Children:
modifylz77(child)
return

dir = bboxapi.OpenFolderDialog()
if dir is not "":
include_subfolders = bboxapi.ShowYesNoPrompt("Include subfolders?", "Batch conversion")

ignore_ext = ".original-lz77"

for root, dirs, files in os.walk(dir):
for file in files:
if not file.lower().endswith(ignore_ext):
try:
node = NodeFactory.FromFile(None, os.path.join(root, file))
if node is None:
continue

if haslz77(node):
shutil.copyfile(os.path.join(root, file), os.path.join(root, file + ignore_ext))
node.Dispose()

node = NodeFactory.FromFile(None, os.path.join(root, file + ignore_ext));
modifylz77(node)
node.Export(os.path.join(root, file))
node.Dispose()
except:
bboxapi.ShowMessage("Cannot export " + file, "Error")
if not include_subfolders:
break


Title: Re: BrawlBox plugins (v0.78)
Post by: E-scope12 on February 24, 2017, 02:15:10 PM
Nice