Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dhkatz authored Nov 28, 2023
0 parents commit 8a3c287
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Pack and publish nuget

on:
push:
branches: [main]
workflow_dispatch:

jobs:
build:
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
- uses: NuGet/setup-nuget@v1.0.5
- name: Pack nuget
run: nuget pack package -OutputFileNamesWithoutVersion -OutputDirectory build -Properties "git=https://github.com/${{ github.repository }}.git;name=${{ github.event.repository.name }};author=${{ github.repository_owner }};description=${{ github.event.repository.description }}"
- name: Publish nuget
run: |
nuget push "build/${{ github.event.repository.name }}.nupkg" -ApiKey ${{ secrets.NUGET_KEY }} -Source https://api.nuget.org/v3/index.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Unity Game Libs Nuget Creator

Creates nugets with stripped and publicized libraries for Unity game modding.

If the game gets updated, this package needs to get updated too.

`strip-assembiles.bat` does two things:

- Strips game assembiles using [NStrip](https://github.com/BepInEx/NStrip). This removes game code and leaves only API definitions.
- Publicizes `Assembly.CSharp.dll` and `AAssembly-CSharp-firstpass.dll`. This makes all types, methods, properties and fields public, to make modding easier.

## Usage

### Nuget account

- Go to [nuget.org](https://nuget.org/).
- Either log in, or create a new account.
- [Create a new API key](https://www.nuget.org/account/apikeys) with permissions to push new packages.

### Prepare your repository

- [Create a new repository based on this template](https://github.com/Raicuparta/unity-libs-nuget/generate).
- Add a secret called `NUGET_KEY` to this repository. Give it the value of the API key you created earlier.
- Update the repository's name. This will be used as your Nuget ID, so it can't clash with another nuget package on [nuget.org](https://nuget.org/).
- Update the repository's description. This will be used as the nuget's description too.

### Generate the stripped libraries

- Make sure you start off with a clean version of the game files, with no extra/modified dlls.
- Drag the game's exe and drop it on `strip-assembiles.bat`.
- Dlls are stripped, publicized, and placed in `package\lib`.

### Updating the Nuget

- Edit the `.nuspec` file, make `<version>` match the game version where these assemblies come from.
- Push to the default branch.
- Updating the default branch will trigger a workflow that will pack the dlls and update the NuGet package.

### Publicized assemblies

By default, only `Assembly-CSharp.dll` and `Assembly-CSharp-firstpass.dll` are publicized. All other dlls are stripped only. To publicize other dlls, edit `strip-assemblies.bat` and add the dll names to the `toPublicize` variable.

### Untouched assemblies

By default, every game assembly gets stripped. If there's any assembly you wish to keep in the package in their original state, add the dll names to the `dontTouch` variable.
16 changes: 16 additions & 0 deletions package/GameLibs.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<requireLicenseAcceptance>false</requireLicenseAcceptance>

<!-- Version of your nuget package. Should reflect the game version where the libs come from. -->
<version>1.0.0</version>

<!-- The GitHub workflow will automatically populate these. -->
<id>$name$</id>
<title>$name$</title>
<authors>$author$</authors>
<description>$description$</description>
<repository type="git" url="$git$" />
</metadata>
</package>
Empty file added package/lib/.dlls-here
Empty file.
37 changes: 37 additions & 0 deletions strip-assembiles.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@echo off

@REM Add all the assemblies you want to publicize in this list
set toPublicize=Assembly-CSharp.dll Assembly-CSharp-firstpass.dll

@REM Add all the assemblies you want to copy as-is to the package in this list
set dontTouch=

set exePath=%1
echo exePath: %exePath%

@REM Remove quotes
set exePath=%exePath:"=%

set managedPath=%exePath:.exe=_Data\Managed%
echo managedPath: %managedPath%

set outPath=%~dp0\package\lib

@REM Strip all assembiles, but keep them private.
%~dp0\tools\NStrip.exe "%managedPath%" -o %outPath%

@REM Strip and publicize assemblies from toPublicize.
(for %%a in (%toPublicize%) do (
echo a: %%a

%~dp0\tools\NStrip.exe "%managedPath%\%%a" -o "%outPath%\%%a" -cg -p --cg-exclude-events
))

@REM Copy over original assemblies for ones we don't want to touch.
(for %%a in (%dontTouch%) do (
echo a: %%a

xcopy "%managedPath%\%%a" "%outPath%\%%a" /y /v
))

pause
21 changes: 21 additions & 0 deletions tools/NStrip-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 BepInEx

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file added tools/NStrip.exe
Binary file not shown.

0 comments on commit 8a3c287

Please sign in to comment.