Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 25 additions & 10 deletions cia-unix.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ require "colorize"
LOG = File.new "cia-unix.log", "w"
LOG.puts Time.utc.to_s

dir = "."

if ARGV.size > 0
if Dir.exists?(ARGV[0])
dir = "\"#{File.expand_path(ARGV[0])}\""
else
print "#{File.expand_path(ARGV[0]).colorize(:yellow)} does not exist.\nDefaulting to #{File.expand_path(dir).colorize(:green)}\n\n"
end
end

# dependencies check
tools = ["./ctrtool", "./ctrdecrypt", "./makerom", "seeddb.bin"]
tools.each do |tool|
Expand All @@ -26,11 +36,16 @@ def download_dep
print "Some #{"tools".colorize.mode(:bold)} are missing, do you want to download them? (y/n): "
if ["y", "Y"].includes? gets.to_s
system "./dltools.sh"
end
else
print "No tools were downloaded. Continue? (y/n): "
if (gets.to_s.chomp.downcase == "n")
exit
end
end
end

# roms presence check
if Dir["*.cia"].size.zero? && Dir["*.3ds"].size.zero?
if Dir["#{dir}/*.cia"].size.zero? && Dir["#{dir}/*.3ds"].size.zero?
LOG.delete if File.exists? "cia-unix.log"
abort "No #{"CIA".colorize.mode(:bold)}/#{"3DS".colorize.mode(:bold)} roms were found."
end
Expand Down Expand Up @@ -63,14 +78,14 @@ def gen_args(name : String, part_count : Int32) : Array(String)
end

# cache cleanup
def remove_cache
def remove_cache(dir : String)
puts "Removing cache..."
Dir["*-decfirst.cia"].each do |fname| File.delete(fname) end
Dir["*.ncch"].each do |fname| File.delete(fname) end
Dir["#{dir}/*-decfirst.cia"].each do |fname| File.delete(fname) end
Dir["#{dir}/*.ncch"].each do |fname| File.delete(fname) end
end

# 3ds decrypting
Dir["*.3ds"].each do |ds|
Dir["#{dir}/*.3ds"].each do |ds|
next if ds.includes? "decrypted"

i : UInt8 = 0
Expand Down Expand Up @@ -104,11 +119,11 @@ Dir["*.3ds"].each do |ds|
puts "Building decrypted #{dsn} 3DS..."
run_tool("makerom", args)
check_decrypt(dsn, "3ds")
remove_cache
remove_cache(dir)
end

# cia decrypting
Dir["*.cia"].each do |cia|
Dir["#{dir}/*.cia"].each do |cia|
next if cia.includes? "decrypted"

puts "Decrypting: #{cia.colorize.mode(:bold)}..."
Expand Down Expand Up @@ -153,15 +168,15 @@ Dir["*.cia"].each do |cia|
puts "Unsupported CIA"
end

Dir["*-decfirst.cia"].each do |decfirst|
Dir["#{dir}/*-decfirst.cia"].each do |decfirst|
cutn = decfirst.chomp "-decfirst.cia"

puts "Building decrypted #{cutn} CCI..."
run_tool("makerom", ["-ciatocci", decfirst, "-o", "#{cutn}-decrypted.cci"])
check_decrypt(cutn, "cci")
end

remove_cache
remove_cache(dir)
end

LOG.flush
Expand Down
10 changes: 5 additions & 5 deletions dltools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ MAKEROM_VER=0.18.4
if [[ "$OSTYPE" == "darwin"* ]]; then
# Apple Silicon
echo " * Downloading ${BOLD}ctrdecrypt${NORMAL}"
wget "https://github.com/shijimasoft/ctrdecrypt/releases/download/v${CTRDECRYPT_VER}/ctrdecrypt-macos-universal.zip" -q
curl "https://github.com/shijimasoft/ctrdecrypt/releases/download/v${CTRDECRYPT_VER}/ctrdecrypt-macos-universal.zip" -o .
echo " * Extracting ${BOLD}ctrdecrypt${NORMAL}"
unzip -qq "ctrdecrypt-macos-universal.zip" -d "ctrdecrypt-macos-universal"
mv "ctrdecrypt-macos-universal/ctrdecrypt" "${SCRIPT_DIR}/ctrdecrypt"
if [[ $(uname -m) == 'arm64' ]]; then
echo " * Downloading ${BOLD}ctrtool${NORMAL}"
wget "https://github.com/3DSGuy/Project_CTR/releases/download/ctrtool-v${CTRTOOL_VER}/ctrtool-v${CTRTOOL_VER}-macos_arm64.zip" -q
curl "https://github.com/3DSGuy/Project_CTR/releases/download/ctrtool-v${CTRTOOL_VER}/ctrtool-v${CTRTOOL_VER}-macos_arm64.zip" -o .
echo " * Extracting ${BOLD}ctrtool${NORMAL}"
unzip -qq "ctrtool-v${CTRTOOL_VER}-macos_arm64.zip" -d "ctrtool-v${CTRTOOL_VER}-macos_arm64"
mv "ctrtool-v${CTRTOOL_VER}-macos_arm64/ctrtool" "${SCRIPT_DIR}/ctrtool"
echo " * Downloading ${BOLD}makerom${NORMAL}"
wget "https://github.com/3DSGuy/Project_CTR/releases/download/makerom-v${MAKEROM_VER}/makerom-v${MAKEROM_VER}-macos_arm64.zip" -q
curl "https://github.com/3DSGuy/Project_CTR/releases/download/makerom-v${MAKEROM_VER}/makerom-v${MAKEROM_VER}-macos_arm64.zip" -o .
echo " * Extracting ${BOLD}makerom${NORMAL}"
unzip -qq "makerom-v${MAKEROM_VER}-macos_arm64.zip" -d "makerom-v${MAKEROM_VER}-macos_arm64"
mv "makerom-v${MAKEROM_VER}-macos_arm64/makerom" "${SCRIPT_DIR}/makerom"
# x86_64
else
echo " * Downloading ${BOLD}ctrtool${NORMAL}"
wget "https://github.com/3DSGuy/Project_CTR/releases/download/ctrtool-v${CTRTOOL_VER}/ctrtool-v${CTRTOOL_VER}-macos_x86_64.zip" -q
curl "https://github.com/3DSGuy/Project_CTR/releases/download/ctrtool-v${CTRTOOL_VER}/ctrtool-v${CTRTOOL_VER}-macos_x86_64.zip" -o .
echo " * Extracting ${BOLD}ctrtool${NORMAL}"
unzip -qq "ctrtool-v${CTRTOOL_VER}-macos_x86_64.zip" -d "ctrtool-v${CTRTOOL_VER}-macos_x86_64"
mv "ctrtool-v${CTRTOOL_VER}-macos_x86_64/ctrtool" "${SCRIPT_DIR}/ctrtool"
echo " * Downloading ${BOLD}makerom${NORMAL}"
wget "https://github.com/3DSGuy/Project_CTR/releases/download/makerom-v${MAKEROM_VER}/makerom-v${MAKEROM_VER}-macos_x86_64.zip" -q
curl "https://github.com/3DSGuy/Project_CTR/releases/download/makerom-v${MAKEROM_VER}/makerom-v${MAKEROM_VER}-macos_x86_64.zip" -o .
echo " * Extracting ${BOLD}makerom${NORMAL}"
unzip -qq "makerom-v${MAKEROM_VER}-macos_x86_64.zip" -d "makerom-v${MAKEROM_VER}-macos_x86_64"
mv "makerom-v${MAKEROM_VER}-macos_x86_64/makerom" "${SCRIPT_DIR}/makerom"
Expand Down