Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue #8 #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions arguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import argparse

parser = argparse.ArgumentParser('SWE1R scripts ')
parser.add_argument('--out', description='directory where the output files are written', default='/tmp/swep1r')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we will probably have a lot of windows users, I'd like to get rid of the "/tmp/" folder altogether.
It would be fine with me if it somehow chose the platforms temp folder or output to a subfolder of the current directory by default.

(the scripts also lack the ability to generate the output folder if it doesn't exist yet, but that's probably a seperate issue)

parser.add_argument('input', description='input file')

multiparser = argparse.ArgumentParser('SWE1R scripts ')
multiparser.add_argument('input', nargs='+', description='input files')
6 changes: 5 additions & 1 deletion extract-racer-tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import sys

from arguments import multiparser

strings = {}

for path in sys.argv[1:]:
args = multiparser.parse_args()

for path in args.input:
with open(path, 'rb') as in_file:
data = in_file.read()

Expand Down
16 changes: 12 additions & 4 deletions out_modelblock.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/usr/bin/env python3

import sys
import struct

import os
from PIL import Image

from arguments import parser


def read8(f):
return f.read(1)[0]
def read16(f):
Expand Down Expand Up @@ -121,7 +125,9 @@ def shifter(a1):
# return result;
pass

with open(sys.argv[1], 'rb') as f:
args = parser.parse_args()

with open(args.input, 'rb') as f:
count = read32(f)
for i in range(0, count - 1):
f.seek(4 + 8 * i)
Expand All @@ -136,13 +142,15 @@ def shifter(a1):
f.seek(a)
buf = f.read(length1)

with open("/tmp/swep1r/model-%d-a.bin" % i, 'wb') as t:
model_a = os.path.join(args.out, 'model-%d-a.bin' % i)
with open(model_a, 'wb') as t:
t.write(buf)

f.seek(b)
buf = f.read(length2)

with open("/tmp/swep1r/model-%d-b.bin" % i, 'wb') as t:
model_b = os.path.join(args.out, 'model-%d-b.bin' % i)
with open(model_b, 'wb') as t:
t.write(buf)

f.seek(a)
Expand Down
17 changes: 13 additions & 4 deletions out_splineblock.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/usr/bin/env python3

import sys
import struct

import os
from PIL import Image

from arguments import parser


def read8(f):
return f.read(1)[0]
def read16(f):
Expand All @@ -29,7 +33,10 @@ def shifter(a1):
result = 16
return result

with open(sys.argv[1], 'rb') as f:
args = parser.parse_args()


with open(args.input, 'rb') as f:
count = read32(f)
for i in range(0, count - 1):
f.seek(4 + 4 * i)
Expand All @@ -42,10 +49,12 @@ def shifter(a1):
f.seek(a)
buf = f.read(length)

with open("/tmp/swep1r/spline-%d.bin" % i, 'wb') as t:
spline_bin = os.path.join(args.out, 'spline-%d.bin' % i)
with open(spline_bin, 'wb') as t:
t.write(buf)

t = open("/tmp/swep1r/spline-%d.obj" % i, 'w')
spline_obj = os.path.join(args.out, 'spline-%d.obj' % i)
t = open(spline_obj, 'w')

f.seek(a)

Expand Down
15 changes: 11 additions & 4 deletions out_spriteblock.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env python3

import sys
import os
from PIL import Image

from arguments import parser


def read8(f):
return f.read(1)[0]
def read16(f):
Expand All @@ -26,7 +29,9 @@ def shifter(a1):
result = 16
return result

with open(sys.argv[1], 'rb') as f:
args = parser.parse_args()

with open(args.input, 'rb') as f:
count = read32(f)
for i in range(0, count - 1):
f.seek(4 + 4 * i)
Expand Down Expand Up @@ -174,7 +179,8 @@ def pixel_a8r8g8b8():
reader = pixel_p8
f.seek(section_a + unk4)
buf = f.read(256 * 2)
with open("/tmp/swep1r/sprite-%d-palette.bin" % i, 'wb') as t:
sprite_palette = os.path.join(args.out, "sprite-%d-palette.bin" % i)
with open(sprite_palette, 'wb') as t:
t.write(buf)
f.seek(section_a + unk4)
pixel_palette = []
Expand Down Expand Up @@ -246,4 +252,5 @@ def pixel_a8r8g8b8():
if y == height:
print("Complete")
break
im.save("/tmp/swep1r/sprite-%d.png" % i, 'PNG')
sprite = os.path.join(args.out, 'sprite-%d.png' % i)
im.save(sprite, 'PNG')
17 changes: 13 additions & 4 deletions out_textureblock.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env python3

import sys
import os
from PIL import Image

from arguments import parser


def read8(f):
return f.read(1)[0]
def read16(f):
Expand All @@ -26,7 +29,11 @@ def shifter(a1):
result = 16
return result

with open(sys.argv[1], 'rb') as f:

args = parser.parse_args()


with open(args.input, 'rb') as f:
count = read32(f)
for i in range(0, count - 1):
f.seek(4 + 8 * i)
Expand All @@ -43,7 +50,8 @@ def shifter(a1):
f.seek(a)
buf = f.read(length)

with open("/tmp/swep1r/texture-%d.bin" % i, 'wb') as t:
texture = os.path.join(args.out, "texture-%d.bin" % i)
with open(texture, 'wb') as t:
f.read
t.write(buf)

Expand Down Expand Up @@ -100,7 +108,8 @@ def shifter(a1):
#g = 0 #((pixel >> 5) & 0x1F) * 0xFF // 0x1F
#b = 0 #((pixel >> 10) & 0x1F) * 0xFF // 0x1F
pixels[x, y] = (a, r, g, b)
im.save("/tmp/swep1r/texture-%d.png" % i, 'PNG')
texture = os.path.join(args.out, 'texture-%d.png' % i)
im.save(texture, 'PNG')


if False:
Expand Down
6 changes: 5 additions & 1 deletion parse-racer-tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import sys

from arguments import multiparser

strings = {}

for path in sys.argv[1:]:
args = multiparser.parse_args()

for path in args.input:
with open(path, 'rb') as in_file:
data = in_file.read()

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
argparse
Pillow
7 changes: 5 additions & 2 deletions scr2wav.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
# Basically it's just XOR'd with 0x55, 0x55, 0xEE, 0xEE and the name Caesar shifted.
# This script undoes this mess, but the files will still be suffix'd with ".rbq"

import sys
import os

for path in sys.argv[1:]:
from arguments import multiparser

args = multiparser.parse_args()

for path in args.input:
filename = os.path.basename(path)
real_filename = ''
for s in filename:
Expand Down