gzinject & z64compress

This commit is contained in:
Yanis42
2024-01-31 13:42:56 +01:00
parent 5c926fea0f
commit 30c134c55d
209 changed files with 59318 additions and 0 deletions

65
tools/gzinject/.gitattributes vendored Normal file
View File

@@ -0,0 +1,65 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
*.h linguist-language=C
*.c linguist-language=C

279
tools/gzinject/.gitignore vendored Normal file
View File

@@ -0,0 +1,279 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
project.fragment.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Testing File
*.Wad
TestExtract/
*.exe
*.stackdump
/gzinject/Debug
/gzinject.zip
*.bin
Debug/
CppProperties.json
wadextract/
*.o
Makefile
config.*
gzinject
*.zip
autom4te.cache/

12
tools/gzinject/.gitrepo Normal file
View File

@@ -0,0 +1,12 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme
;
[subrepo]
remote = https://github.com/krimtonz/gzinject.git
branch = master
commit = ee44efce5d842e5d4488ee47c16da8b673da5086
parent = 53941daac4bb1482a9125f3595642df1bafb5f6d
method = merge
cmdver = 0.4.5

View File

@@ -0,0 +1,8 @@
## Prerequisites
gcc, make
## Building
Run `./configure` You can use `--prefx=DIR` to specify the output directory, install will install gzinject to `DIR/bin`, then run `make` to build the executable, and `make install` to install it to `DIR/bin`
By default gzinject will use the crypto library provided by OpenSSL, to disable this and use builtin (slower) crypto functions remove `-D_USE_LIBCRYPTO` From the make file, and change SRC = gzinject.c to SRC = *.c

674
tools/gzinject/LICENSE Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
CC = @CC@
LD = @CC@
INSTALL = @INSTALL@
CFLAGS = -Wall -Wno-unused-result @CFLAGS@
CPPFLAGS = @CPPFLAGS@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
PROGNAME = gzinject
LDFLAGS = -s @LDFLAGS@
CFILES = *.c
SRCDIR = src
CSRC := $(foreach s,$(CFILES),$(wildcard $(SRCDIR)/$(s)))
COBJ = $(patsubst $(SRCDIR)/%,$(OBJDIR)/%.o,$(CSRC))
LIBS =
OBJDIR = obj
OUTDIR = $(OBJDIR)
.PHONY : all install clean distclean
all : $(PROGNAME)
clean :
rm -rf $(PROGNAME) obj
distclean : clean
rm -f Makefile
install : $(PROGNAME)
$(INSTALL) -p -D --target-directory=$(DESTDIR)$(bindir) $(PROGNAME)
$(PROGNAME) : $(COBJ)
$(LD) $(LDFLAGS) $^ -o $@ $(LIBS)
$(OUTDIR) :
mkdir -p $@
$(COBJ) : $(OBJDIR)/%.o: $(SRCDIR)/% | $(OBJDIR)
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@

74
tools/gzinject/README.md Normal file
View File

@@ -0,0 +1,74 @@
## About
gzinject is a wad editing utility, primarily used for patching N64 VC Emulators, and replacing the rom inside. gzinject uses patch files to patch content files within the wad. A description of the patch file format can be seen in the [Patch](#Patch) section.
## Executable
To build your own, run ./configure, then make, and make install. See BUILDING for more instructions
Prebuilt Windows executable is contained under releases (https://github.com/krimtonz/gzinject/releases/latest)
## Usage
```
Usage:
gzinject -a extract -w SOURCEWAD [options]
gzinject -a pack -w DESTWAD [options]
gzinject -a inject -w SOURCEWAD -m ROM [options]
gzinject -a genkey [options]
gzinject --help
gzinject --version
Actions:
extract extracts SOURCEWAD to directory
pack packs directory into DESTWAD
inject injects rom into SOURCEWAD
genkey generates wii common-key
Options:
-i, --channelid=ID New Channel ID For Pack and Inject actions (default: none)
-t, --title=title New Channel name for pack and inject actions (default: none)
-h, --help Prints this help message
-k, --key=keyfile Location of the common-key file (default: common-key.bin)
-r, --region=1-3 Region to use (default: 3)
--verbose Print out verbose program execution information
-d, --directory=directory Directory to extract contents to, or directory to read contents from (default: wadextract)
--cleanup Remove files before performing actions
--version Prints the current version
-m, --rom=rom Rom to inject for inject action (default: none)
-o, --outputwad=outwad The output wad for inject actions (default: SOURCEWAD-inject.wad)
-p, --patch-file=patchfile gzi file to use for applying patches (default: none)
-c, --content=contentfile the primary content file (default: 5)
--dol-inject Binary data to inject into the emulator program, requires --dol-loading
--dol-loading The loading address for the binary specified by --dol-inject
--dol-after After which patch file to inject the dol, default: after all patches
```
## Patch
gzi files are text files with a command on each line. A # starting the line indicates a comment.
line format:
ccss oooooooo dddddddd\
Where c indicates the command, s indicates the data size, o indicates the offset into the current file, and d indicates the data to replace with.
```
Commands:
00: Begin using content file specified by d, offset and size are not used for this command
01: lz77 decompress the current content file. offset, size, and data are not used for this command
02: lz77 compress the current content file. offset, size, and data are not used for this command
03: apply patch to currently selected file. If offset is higher than the file sizes, or a current file has not been selected, the patch is not applied
Sizes:
01: a one byte value. data & 0x000000FF is applied to content + offset
02: a two byte value. data & 0x0000FFFF is applied to content + offset
04: a four byte value. data is applied to content + offset
```
## Thanks/Authors
gzinject was primarily written by me.\n
Thanks to glankk (https://github.com/glankk) for providing memory/controller fixes for OOT as well as debugging, testing, and providing fixes for various errors\
The general workflow of extracting/packing the wad was taken from showmiiwads (https://github.com/dnasdw/showmiiwads/)\
AES encryption/decryption was taken from kokke (https://github.com/kokke/tiny-AES-c)\
SHA1 taken from clibs (https://github.com/clibs/sha1)\
MD5 taken from Alexander Peslyak http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5

4468
tools/gzinject/configure vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
AC_PREREQ([2.69])
AC_INIT
AC_PREFIX_DEFAULT([/usr/local])
AC_PROG_CC
AC_PROG_INSTALL
CFLAGS="-O3"
AC_CHECK_HEADERS([wmmintrin.h],
[
CFLAGS+=" -maes -msse -msse2"
CPPFLAGS="-DFASTAES"
]
)
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

501
tools/gzinject/install-sh Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,6 @@
# default gz patches for NACE
0000 00000000 00000001
# use 8MB memory
0304 00002EB0 60000000
# allocate 32MB for rom
0304 0005BFD4 3C807200

View File

@@ -0,0 +1,6 @@
# default gz patches for NACJ
0000 00000000 00000001
# use 8MB memory
0304 00002EB0 60000000
# allocate 32MB for rom
0304 0005BF44 3C807200

View File

@@ -0,0 +1,16 @@
# NKZE kz-NZSE
0000 00000000 00000001
# decompress content1
0100 00000000 00000000
# apply 12MB fixes
0304 00010B58 3C8000C0
0304 0004BD20 67E47000
0304 0004BC80 3CA00100
# apply controller remappings
0302 00148514 00000800
0302 00148518 00000400
0302 0014851C 00000200
0302 00148520 00000100
0302 00148528 00000020
# compress content1
0200 00000000 00000000

View File

@@ -0,0 +1,16 @@
# NKZJ kz-NZSJ
0000 00000000 00000001
# decompress content1
0100 00000000 00000000
# apply 12MB fixes
0304 00010B58 3C8000C0
0304 0004BD94 67E47000
0304 0004BCF4 3CA00100
# apply controller remappings
0302 0014AA54 00000800
0302 0014AA58 00000400
0302 0014AA5C 00000200
0302 0014AA60 00000100
0302 0014AA68 00000020
# compress content1
0200 00000000 00000000

View File

@@ -0,0 +1,9 @@
# gz standard remapping for NACE and NACJ
0000 00000000 00000001
# apply d-pad remappings
0302 0016BAF0 00000800
0302 0016BAF4 00000400
0302 0016BAF8 00000200
0302 0016BAFC 00000100
# apply c-stick remapping
0302 0016BB04 00000020

View File

@@ -0,0 +1,9 @@
# gz raphnet remapping for NACE and NACJ
0000 00000000 00000001
# apply d-pad remappings
0302 0016BAF0 00000800
0302 0016BAF4 00000400
0302 0016BAF8 00000200
0302 0016BAFC 00000100
# apply z-trigger remapping
0302 0016BAD8 00000020

View File

@@ -0,0 +1,15 @@
# homeboy patches for NACE
0000 00000000 00000001
# resize MEM2 heap for homeboy
0302 00085732 00009010
0304 00085738 60000000
0304 00085744 60000000
# homeboy hook
0304 00002EA8 3c809000
0304 00002EAC 38840800
0304 00002EB0 7c8903a6
0304 00002EB4 80630018
0304 00002EB8 4e800421
# Change iOS to 61
0000 00000000 00000064
0301 0000018B 0000003D

View File

@@ -0,0 +1,15 @@
# homeboy patches for NACJ
0000 00000000 00000001
# resize MEM2 heap for homeboy
0302 00085726 00009010
0304 0008572C 60000000
0304 00085738 60000000
# homeboy hook
0304 00002EA8 3c809000
0304 00002EAC 38840800
0304 00002EB0 7c8903a6
0304 00002EB4 80630018
0304 00002EB8 4e800421
# Change iOS to 61
0000 00000000 00000064
0301 0000018B 0000003D

View File

@@ -0,0 +1,6 @@
# ootr remapping for NACE and NACJ
0000 00000000 00000001
# apply d-pad remappings
0302 0016BAF4 00000400
0302 0016BAF8 00000200
0302 0016BAFC 00000100

567
tools/gzinject/src/aes.c Normal file

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More