Skip to content

Commit 128f0be

Browse files
committed
use make_cia instead
1 parent 77d6afd commit 128f0be

2 files changed

Lines changed: 16 additions & 36 deletions

File tree

3dsconv.py

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
--nocleanup - don't remove temporary files once finished
2323
--verbose - print more information
2424
25-
- 3dstool and makerom should exist in your PATH
25+
- 3dstool and make_cia should exist in your PATH
2626
- if a rom is encrypted, an ExHeader XORpad
2727
should exist in the working directory
2828
named \"<TITLEID>.Main.exheader.xorpad\"
@@ -90,10 +90,10 @@ def roundup(x):
9090
print(" you can get it from here:")
9191
print(" https://github.com/dnasdw/3dstool")
9292
fail = True
93-
if not testcommand("makerom"):
94-
print("! makerom doesn't appear to be in your PATH.")
93+
if not testcommand("make_cia"):
94+
print("! make_cia doesn't appear to be in your PATH.")
9595
print(" you can get it from here:")
96-
print(" https://github.com/profi200/Project_CTR")
96+
print(" https://github.com/ihaveamac/ctr_toolkit")
9797
fail = True
9898
if fail:
9999
print("- if you want to force the script to run,")
@@ -197,7 +197,8 @@ def roundup(x):
197197
exh.seek(0xD)
198198
exh.write(chr(z))
199199
exh.seek(0x1C0)
200-
savesize = exh.read(4)
200+
# there has to be a better way to do this...
201+
savesize = str(int(binascii.hexlify(exh.read(4)[::-1]), 16) / 1024)
201202
# actually 8 bytes but the TMD only has 4 bytes
202203
#print(binascii.hexlify(savesize[::-1]))
203204
exh.close()
@@ -212,36 +213,15 @@ def roundup(x):
212213
runcommand(cmds)
213214
print_v("- building CIA")
214215
# CIA
215-
cmds = ["makerom", "-f", "cia", "-o", "work/%s-game-conv.cia" % tid, "-content", "work/%s-game-conv.cxi:0:0" % tid]
216-
if os.path.isfile("work/%s-manual.cfa" % tid):
217-
cmds.extend(["-content", "work/%s-manual.cfa:1:1" % tid])
218-
if os.path.isfile("work/%s-dlpchild.cfa" % tid):
219-
cmds.extend(["-content", "work/%s-dlpchild.cfa:2:2" % tid])
216+
# make_cia -o game-conv-make_cia.cia --savesize=128 --content0=game-conv.cxi --id_0=0 --index_0=0
217+
os.chdir("work") # not doing this breaks make_cia's ability to properly include Manual/DLP Child for some reason
218+
cmds = ["make_cia", "-o", "%s-game-conv.cia" % tid, "--savesize=%s" % savesize, "--content0=%s-game-conv.cxi" % tid, "--id_0=0", "--index_0=0"]
219+
if os.path.isfile("%s-manual.cfa" % tid):
220+
cmds.extend(["--content1=%s-manual.cfa" % tid, "--id_1=1", "--index_1=1"])
221+
if os.path.isfile("%s-dlpchild.cfa" % tid):
222+
cmds.extend(["--content2=%s-dlpchild.cfa" % tid, "--id_2=2", "--index_2=2"])
220223
runcommand(cmds)
221-
222-
# makerom doesn't accept custom SaveDataSize for some reason
223-
# but make_cia makes a bad CIA that doesn't support the Manual or DLP child
224-
225-
# Archive Header Size
226-
cia = open("work/%s-game-conv.cia" % tid, "r+b")
227-
cia.seek(0x0)
228-
cia_h_ahs = binascii.hexlify(cia.read(0x4)[::-1])
229-
cia_h_ahs_align = roundup(cia_h_ahs)
230-
231-
# Certificate chain size
232-
cia.seek(0x8)
233-
cia_h_cetks = binascii.hexlify(cia.read(0x4)[::-1])
234-
cia_h_cetks_align = roundup(cia_h_cetks)
235-
236-
# Ticket size
237-
cia.seek(0xC)
238-
cia_h_tiks = binascii.hexlify(cia.read(0x4)[::-1])
239-
cia_h_tiks_align = roundup(cia_h_tiks)
240-
241-
tmdoffset = cia_h_ahs_align + cia_h_cetks_align + cia_h_tiks_align
242-
cia.seek(tmdoffset + 0x140 + 0x5a)
243-
cia.write(savesize)
244-
cia.close()
224+
os.chdir("..")
245225

246226
os.rename("work/%s-game-conv.cia" % tid, os.path.join(output_directory, romname+".cia"))
247227
if cleanup:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# 3dsconv
22
`3dsconv.py` is a Python script that "converts" a Nintendo 3DS rom (.3ds, .cci) to an installable CIA.
33

4-
It supports using only an ExHeader XORpad, as well as decrypted roms.
4+
It supports using only an ExHeader XORpad, as well as decrypted roms. The ExHeader XORpad name format is `<TITLEID>.Main.exheader.xorpad`.
55

6-
It requires [3dstool](https://github.com/dnasdw/3dstool) and [makerom](https://github.com/profi200/Project_CTR) in the PATH.
6+
It requires [3dstool](https://github.com/dnasdw/3dstool) and [make_cia](https://github.com/ihaveamac/ctr_toolkit) in the PATH.
77

88
This does not work with Python 3.x.
99

0 commit comments

Comments
 (0)