Skip to content

Instantly share code, notes, and snippets.

@Cyphs
Forked from ToeKneeRED/TrimPak.bat
Last active March 13, 2025 06:09
Show Gist options
  • Save Cyphs/adbee4788b4649d2587977cd402aef06 to your computer and use it in GitHub Desktop.
Save Cyphs/adbee4788b4649d2587977cd402aef06 to your computer and use it in GitHub Desktop.
Yeet DevelopmentAssetRegistry.bin from a single .pak file or a directory for bulk processing
:: REQUIRES REPAK https://github.com/trumank/repak/
:: Process a single .pak file or all .pak files in a directory
@echo off
setlocal enabledelayedexpansion
cls
title TrimPak
echo Select an option:
echo 1. Process a single .pak file
echo 2. Process all .pak files in a directory (Bulk)
set /p "choice=Enter your choice (1 or 2): "
if "%choice%"=="1" goto :PROCESS_SINGLE
if "%choice%"=="2" goto :PROCESS_BULK
echo Invalid choice. Exiting...
goto EXIT
:PROCESS_SINGLE
set "pakPath="
set /p "pakPath=Enter path to .pak file: "
set "pakPath=%pakPath:"=%"
if not exist "%pakPath%" (
echo Invalid file path.
goto EXIT
)
for %%I in ("%pakPath%") do (
set "fileName=%%~nxI"
set "pakDirectory=%%~dpI"
set "modName=%%~nI"
)
set "modIndex=1"
set "modCount=1"
set "logFile=TrimPak.log"
echo Processing started at %date% %time% > "%logFile%"
echo Pak file: %pakPath% >> "%logFile%"
call :ProcessMod "%pakPath%" "%fileName%" "%pakDirectory%" "%modName%" "%modIndex%" "%modCount%"
goto DONE_PROCESSING_SINGLE
:PROCESS_BULK
set "modRootPath="
set /p "modRootPath=Enter path to folder: "
set "modRootPath=%modRootPath:"=%"
if not exist "%modRootPath%" (
echo Invalid directory.
goto EXIT
)
set "logFile=TrimPakBulk.log"
echo Processing started at %date% %time% > "%logFile%"
echo Root directory: %modRootPath% >> "%logFile%"
echo Detecting mods...
set "modCount=0"
if exist modsList.txt del modsList.txt
for /r "%modRootPath%" %%F in ("*pakchunk0-WindowsNoEditor.pak") do (
if exist "%%F" (
set /A modCount+=1
echo Detected pak file: %%F
echo %%F >> modsList.txt
)
)
if %modCount%==0 (
echo No mods found in the specified directory.
echo No mods found in the specified directory. >> "%logFile%"
goto EXIT
)
echo %modCount% mods detected.
echo %modCount% mods detected. >> "%logFile%"
set /p "proceed=Do you wish to proceed with processing? (y/n): "
if /I "%proceed%" neq "y" goto EXIT
set "modIndex=0"
for /F "delims=" %%F in (modsList.txt) do (
set /A modIndex+=1
set "pakPath=%%F"
set "fileName=%%~nxF"
set "pakDirectory=%%~dpF"
call :ProcessMod "!pakPath!" "!fileName!" "!pakDirectory!" "!modIndex!" "%modCount%"
)
goto DONE_PROCESSING_BULK
:ProcessMod
setlocal
set "pakPath=%~1"
set "fileName=%~2"
set "pakDirectory=%~3"
set "modIndex=%~4"
set "modCount=%~5"
echo Processing mod "%fileName%" (%modIndex%/%modCount%)
echo Pak path: "%pakPath%"
echo Processing mod "%fileName%" (%modIndex%/%modCount%) >> "%logFile%"
echo Pak path: "%pakPath%" >> "%logFile%"
for /f "tokens=1,2 delims=~" %%a in ("%fileName:pakchunk=~%") do set "modName=%%a"
for %%N in ("%fileName%") do set "folderName=%%~nN"
echo Unpacking "%modName%"...
echo Unpacking "%modName%" >> "%logFile%"
call repak unpack "%pakPath%"
if errorlevel 1 (
echo Failed to unpack "%pakPath%".
echo Failed to unpack "%pakPath%". >> "%logFile%"
set /p "continue=Continue processing other mods? (y/n): "
if /I "%continue%" neq "y" goto EXIT
goto :EOF
)
set "devBin=%pakDirectory%%folderName%\Phoenix\Mods\%modName%\Metadata\DevelopmentAssetRegistry.bin"
if exist "%devBin%" (
del "%devBin%"
echo Removed problem file
echo Removed DevelopmentAssetRegistry.bin from %devBin% >> "%logFile%"
) else (
echo DevelopmentAssetRegistry.bin not found - may already be deleted
echo DevelopmentAssetRegistry.bin not found - may already be deleted >> "%logFile%"
)
echo Repacking "%modName%"...
echo Repacking "%modName%" >> "%logFile%"
call repak pack "%pakDirectory%%folderName%"
if errorlevel 1 (
echo Failed to repack "%pakPath%".
echo Failed to repack "%pakPath%". >> "%logFile%"
set /p "continue=Continue processing other mods? (y/n): "
if /I "%continue%" neq "y" goto EXIT
goto :EOF
)
if exist "%pakDirectory%%folderName%" (
rmdir /S /Q "%pakDirectory%%folderName%"
echo Removed unpacked folder "%pakDirectory%%folderName%" >> "%logFile%"
)
echo Successfully processed "%modName%".
echo Successfully processed "%modName%". >> "%logFile%"
endlocal
goto :EOF
:DONE_PROCESSING_SINGLE
echo Processing completed.
goto EXIT
:DONE_PROCESSING_BULK
echo Processing completed at %date% %time% >> "%logFile%"
echo Processing completed.
goto EXIT
:EXIT
if exist modsList.txt del modsList.txt
echo Press any key to exit...
pause >nul
@Cyphs
Copy link
Author

Cyphs commented Mar 7, 2025

This batch script uses repak to remove the useless ~ 250 MB DevelopmentAssetRegistry.bin file inside of the .pak file from Hogwarts Legacy mods packaged from CurseForge's cloud cooking system. This file is in nearly every mod because of the packaging configuration used, needlessly increasing storage space and bandwidth used. This is mainly just the files that have pakchunk0-WindowsNoEditor.pak in the name.

It's safe to delete and repackage as a workaround in the meantime, in order to reduce the file size of Mods. Mods will still function correctly afterwards if it was done successfully. This batch script automates the process of deleting DevelopmentAssetRegistry.bin and repacking the Mod.

This bulk version was made as a quick way to reduce the size of all (around time of posting) 351 Hogwarts Legacy Mods from CurseForge to see the impact of the size difference. It might have other useful purposes as well until the cloud cooking system issue is resolved.

Original size of the 351 Mods = 92 GB | Updated size after trimming = < 7 GB

Before After

How to use:

Install

  • Download and extract repak anywhere to a folder from here. You should select repak_cli-x86_64-pc-windows-msvc.zip
  • Save TrimPak.bat. You can right-click on this link and Save Link As... to download. Change Save as type to All files (.) before clicking Save to ensure it downloads as a .bat file.
  • Copy or move the saved TrimPak.bat file to the same folder that contains repak.exe

Using

  • Optionally backup your files before using this, just in case.

  • Start it by double clicking on TrimPak.bat

    • If that doesn't work, hold the Shift key on your keyboard and right-click in some empty space of the File Explorer window. Then click on Open PowerShell window here.
    • After the PowerShell window opens, type .\TrimPak.bat and press Enter. Now it's started.
  • Type 1 and press Enter to Process a single .pak file

  • Type 2 and press Enter to Process all .pak files in a directory (Bulk)

  • If you typed 1, it will ask you to Enter path to .pak file:

    • You can right-click on a .pak file located anywhere and click Copy as path, then right-click in the window to paste OR you can simply drag and drop the file into the window and it will automatically have the path inputted.
      For example: "E:\SteamLibrary\steamapps\common\Hogwarts Legacy\Phoenix\Mods\abc\Content\Paks\WindowsNoEditor\abcpakchunk0-WindowsNoEditor.pak"
  • Then press the Enter key. It will immediately process and replace it with the trimmed .pak file.

  • If you typed 2, it will ask you to Enter path to folder:

    • You can right-click on a folder that contains the affected .pak files and click Copy as path, then right-click in the window to paste OR you can simply drag and drop the folder into the window and it will automatically have the path inputted.
      For example: "E:\SteamLibrary\steamapps\common\Hogwarts Legacy\Phoenix\Mods"
  • Then press the Enter key. It will automatically detect and count all mods to prepare for bulk processing. It will automatically search all subfolders as well.

  • After it detects the mods, type Y to start it or N to cancel. If you entered Y, it will automatically process all mods.


Notes:

If you have a big mod list and want to try the bulk processing to trim them follow these steps:

  • Load a normal, unmodded save so that the game will delete all mods from your game folder, if any, then quit.

  • Double check that all the mods in your game folder were actually deleted; For example: "E:\SteamLibrary\steamapps\common\Hogwarts Legacy\Phoenix\Mods" Manually delete them if not.

  • Trim the mods in your Documents folder: "C:\Users\username\Documents\Hogwarts Legacy\Mods". That's the location where Mods are first downloaded to.

  • If you didn't already enable the mods on your Mod Save, do this first. Then apply and try to load the Mod Save. If it worked correctly, the trimmed Mods from the Documents folder would be copied to the game folder (significantly faster than if not trimmed) and the game will load.

You can update mods for future releases and then trim the new files again. If it has trouble loading, try to repeat these steps from loading a normal unmodded save, ensuring the Mods from the game folder get deleted first. You don't have to disable and enable again.

———

If you’re unable to load Mod Saves no matter what you do, try the following steps:

  • Check your Library of installed mods to ensure you didn’t download any Mods that say 0 MB.
  • Load an old, normal unmodded save from the main menu and then Exit to Desktop.
  • Check the game folder at Hogwarts Legacy\Phoenix\Mods and make sure nothing is there. If there’s folders within the Mods folder (in the game folder only), delete them.
  • In File Explorer, go to %localappdata%\Hogwarts Legacy\Saved\SaveGames (Steam) or %localappdata%\HogwartsLegacy\Saved\SaveGames (Epic) and then open the folder with your user ID.
  • In this folder, delete SaveGameList.sav (Doing this is safe and you shouldn’t lose any progress; but it will disable the mods from your Mod Save.)
  • Start the game and then load the normal old unmodded save from the main menu again.
  • Go back to the Play Mods menu and enable the mods on your Mod Save, apply, and then try to load.

The reason I wanted to download all mods in the first place is because a few mods from nathdev on CurseForge were copying text to the clipboard like “true” and “init” during a normal launch of the game for debug purposes. Before finding that out, I thought it was suspicious and wanted to download all mods to narrow it down. This discovery also led to the realization that the game might be attempting to load mods when compiling shaders, before you even load a Mod Save. So there’s currently several flaws in this entire Modding system.


Another script I’ve tried using to copy Mods from Documents to the game folder with the expected folder name structure. Not very useful for everyone since mods need to be enabled from in-game: https://gist.github.com/Cyphs/f5316b8970e21481f98ec2f1ebadb771

@Cyphs
Copy link
Author

Cyphs commented Mar 7, 2025

TrimPak.mp4

Note: This is just an example to demonstrate how Bulk processing works. If you want to actually use it to trim your mod list properly, read the Notes in the above comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment