Skip to content

Instantly share code, notes, and snippets.

@corrigat
Last active October 2, 2022 00:56
Show Gist options
  • Save corrigat/dcc6ad651d4dcf978a7a8a4801a4d6ef to your computer and use it in GitHub Desktop.
Save corrigat/dcc6ad651d4dcf978a7a8a4801a4d6ef to your computer and use it in GitHub Desktop.
PSO2 NGS casefolding setup for steam deck
#!/bin/bash
# Change to the game directory
gamedir="/run/media/mmcblk0p1/steamapps/common/PHANTASYSTARONLINE2_NA_STEAM"
if [ ! -d "${gamedir}" ]; then
echo "Could not find game directory at ${gamedir}."
echo "It is much easier to follow the instructions at https://bit.ly/3y7HI6V"
echo "to set up the game directory before installing."
echo "If you still want to use this script, be sure to download it to your SD card first."
echo "Download location selection is only available when installing from the store page, and not your library."
echo "Hopefully this is fixed in a SteamOS update soon. https://github.com/ValveSoftware/Proton/issues/4122"
exit 1
fi
# Set some variables to make the script easier to read and write
pso2dir="${gamedir}/pso2_bin"
tmpdir="${gamedir}/temp"
# Rename pso2_bin dir to make way for directories with folding bit set
echo "Renaming ${pso2dir} to ${tmpdir}."
mv "${pso2dir}" "${tmpdir}"
# Create new pso2_bin dir, and set the case insensitivity bit.
# Setting the bit must be done on an empty directory, which is why
# we moved the original and created a new empty dir. Newly created
# directories within this directory will inherit this bit.
echo "Creating new pso2_bin dir."
mkdir "${pso2dir}"
echo "Setting casefold on pso2_bin"
thispid=$(chattr +F "${pso2dir}"; echo $!)
wait $thispid
# stop if we can't set casefolding bit
if ! lsattr -ld "${pso2dir}" | grep Casefold; then
echo "Could not stat ${pso2dir}"
echo "Could not set case folding bit. Your files are not gone, but we can't continue."
echo "We moved files to ${gamedir}/temp. They can be moved back"
exit 1
fi
# Change to renamed original dir.
echo "Switching to ${tmpdir}"
cd "${tmpdir}"
# Create an array of our directories.
echo "Creating indexing directories."
readarray -d '' dirarray < <(find . -type d -not -name '\.' -not -name '\.\.' -not -name "^pso2_bin$" -print0)
# Create new directories, checking that Casefold bit is set along the way.
for i in "${dirarray[@]}"; do
this_dir="${pso2dir}/${i}"
echo "Creating ${this_dir}..."
mkdir "${this_dir}"
if ! lsattr -ld "${this_dir}" | grep Casefold; then
echo "${this_dir} was not created or does not have Casefold bit set. Stopping."
echo "We moved files to ${gamedir}/temp. They can be moved back"
exit 1
fi
done
# Move regular files back into new directories.
# Casefolding bit doesn't get set on files, so we can just send them to their new home.
echo "Moving files back into pso2_bin directory. Please be patient, as the speed of this depends on your SD card."
find . -type f -exec echo "Moving file to ${pso2dir}"/{} \; -exec mv {} "${pso2dir}"/{} \;
if [ -f "${pso2dir}/pso2.exe" ]; then
echo "So long as there were no error messages, we should be all done here. Launch the game and have fun!"
else
echo "I couldn't find pso2.exe. Please investigate the two directories at ${gamedir}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment