稳定初版

This commit is contained in:
sin365 2025-04-08 01:30:10 +08:00
parent 51fdabc58d
commit 1a41e8e63f
9 changed files with 88 additions and 212 deletions

13
.gitignore vendored Normal file
View File

@ -0,0 +1,13 @@
/*.vsconfig
/Library/
/Temp/
/UserSettings/
/.vs/
/*.csproj
/*.sln
/obj/
/logs/
/Output/
**/switch_keys/*.keys
**/switch_keys/*.keys.meta
**/NintendoSDKPlugin/

View File

@ -1,7 +1,9 @@
#if UNITY_EDITOR_WIN
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;
@ -37,12 +39,12 @@ namespace AxibugEmuOnline.Editors
}
[MenuItem("Axibug移植工具/Switch/AxibugNSPTools/Build With RepackNSP(打包NSP并重新构建NPS")]
static void BuildWithRepackNSP()
public static void BuildWithRepackNSP()
{
if (!CheckEnvironmentVariable())
return;
if (!EditorUtility.DisplayDialog("횅훰관斤口", $"셨崎댔관?", "셨崎", "혤句"))
if (!EditorUtility.DisplayDialog("打包", $"确认打包NSP?", "继续", "取消"))
return;
var levels = new List<string>();
@ -68,7 +70,7 @@ namespace AxibugEmuOnline.Editors
#endif
string targetName = $"{Application.productName}_{titleid}.nsp";
string _locationPathName = $"Output/NSPBuild/{targetName}";
string _locationPathName = $"Output/NSPBuild/{targetName}";
var options = new BuildPlayerOptions
{
scenes = levels.ToArray(),
@ -81,7 +83,7 @@ namespace AxibugEmuOnline.Editors
{
BuildReport report = BuildPipeline.BuildPlayer(options);
}
catch(Exception ex)
catch (Exception ex)
{
Debug.LogError($"[AxibugNSPTools] Unity Build NSP 错误:{ex.ToString()}");
return;
@ -146,13 +148,13 @@ namespace AxibugEmuOnline.Editors
#region
CleanDirectory(Path.Combine(nspParentDir, "repacker_extract"));
CleanDirectory(Path.Combine(Path.GetTempPath(), "NCA"));
CleanDirectory(Path.Combine(WorkRoot, "hacpack_backup"));
CleanDirectory(Path.Combine(nspParentDir, "hacpack_backup"));
#endregion
EditorUtility.DisplayProgressBar("AxibugNSPTools", $"解包NSP文件", 0.2f);
#region NSP文件
string extractPath = Path.Combine(nspParentDir, "repacker_extract");
ExecuteCommand($"{tools["authoringTool"]} extract -o \"{extractPath}\" \"{nspFilePath}\"");
ExecuteCommand($"{tools["authoringTool"]} extract -o \"{extractPath}\" \"{nspFilePath}\"", nspParentDir);
string controlPath = null;
string programPath = null;
@ -166,19 +168,32 @@ namespace AxibugEmuOnline.Editors
#region NCA/NSP
string tmpPath = Path.Combine(Path.GetTempPath(), "NCA");
EditorUtility.DisplayProgressBar("AxibugNSPTools", $"路쉔NCA", 0.6f);
string programNCA = BuildProgramNCA(tmpPath, titleID, programPath);
EditorUtility.DisplayProgressBar("AxibugNSPTools", $"路쉔NCA", 0.7f);
string controlNCA = BuildControlNCA(tmpPath, titleID, controlPath);
EditorUtility.DisplayProgressBar("AxibugNSPTools", $"路쉔NCA", 0.8f);
BuildMetaNCA(tmpPath, titleID, programNCA, controlNCA);
EditorUtility.DisplayProgressBar("AxibugNSPTools", $"重建 Program NCA", 0.3f);
string programNCA = BuildProgramNCA(tmpPath, titleID, programPath, nspParentDir);
EditorUtility.DisplayProgressBar("AxibugNSPTools", $"重建 Control NCA", 0.4f);
string controlNCA = BuildControlNCA(tmpPath, titleID, controlPath, nspParentDir);
EditorUtility.DisplayProgressBar("AxibugNSPTools", $"重建 Meta NCA", 0.5f);
BuildMetaNCA(tmpPath, titleID, programNCA, controlNCA, nspParentDir);
EditorUtility.DisplayProgressBar("AxibugNSPTools", $"重建NSP", 0.6f);
string outputNSP = BuildFinalNSP(nspFilePath, nspParentDir, tmpPath, titleID, nspParentDir);
EditorUtility.DisplayProgressBar("AxibugNSPTools", $"重建NSP", 0.9f);
string outputNSP = BuildFinalNSP(nspFilePath, nspParentDir, tmpPath, titleID);
EditorUtility.DisplayProgressBar("AxibugNSPTools", $"路쉔NSP", 1f);
Debug.Log($"[AxibugNSPTools]Repacking completed: {outputNSP}");
EditorUtility.ClearProgressBar();
#endregion
}
#endregion
EditorUtility.DisplayProgressBar("AxibugNSPTools", $"清理临时目录", 1);
#region
CleanDirectory(Path.Combine(nspParentDir, "repacker_extract"));
CleanDirectory(Path.Combine(Path.GetTempPath(), "NCA"));
CleanDirectory(Path.Combine(nspParentDir, "hacpack_backup"));
#endregion
System.Diagnostics.Process.Start("explorer", "/select,\"" + outputNSP.Trim() + "\"");
EditorUtility.ClearProgressBar();
}
#region
static string GetUserInput()
@ -186,14 +201,12 @@ namespace AxibugEmuOnline.Editors
Console.Write("Enter the NSP filepath: ");
return Console.ReadLine();
}
static string ExtractTitleID(string path)
{
var match = Regex.Match(path, @"0100[\dA-Fa-f]{12}");
return match.Success ? match.Value : null;
}
static void CleanDirectory(string path)
{
if (Directory.Exists(path))
@ -214,8 +227,9 @@ namespace AxibugEmuOnline.Editors
}
}
static string ExecuteCommand(string command)
static string ExecuteCommand(string command, string workdir)
{
Debug.Log($"调用cmd=>{command}");
var process = new System.Diagnostics.Process()
{
StartInfo = new System.Diagnostics.ProcessStartInfo
@ -227,7 +241,8 @@ namespace AxibugEmuOnline.Editors
UseShellExecute = false,
CreateNoWindow = true,
StandardOutputEncoding = Encoding.UTF8, // 明确指定编码
StandardErrorEncoding = Encoding.UTF8
StandardErrorEncoding = Encoding.UTF8,
WorkingDirectory = workdir
}
};
@ -274,36 +289,36 @@ namespace AxibugEmuOnline.Editors
#endregion
#region NCA构建逻辑
static string BuildProgramNCA(string tmpPath, string titleID, string programDir)
static string BuildProgramNCA(string tmpPath, string titleID, string programDir, string workdir)
{
string args = $"-k \"{prodKeysPath}\" -o \"{tmpPath}\" --titleid {titleID} " +
$"--type nca --ncatype program --exefsdir \"{programDir}/fs0\" " +
$"--romfsdir \"{programDir}/fs1\" --logodir \"{programDir}/fs2\"";
string output = ExecuteCommand($"{tools["hacPack"]} {args}");
string output = ExecuteCommand($"{tools["hacPack"]} {args}", workdir);
return ParseNCAOutput(output, "Program");
}
static string BuildControlNCA(string tmpPath, string titleID, string controlDir)
static string BuildControlNCA(string tmpPath, string titleID, string controlDir, string workdir)
{
string args = $"-k \"{prodKeysPath}\" -o \"{tmpPath}\" --titleid {titleID} " +
$"--type nca --ncatype control --romfsdir \"{controlDir}/fs0\"";
string output = ExecuteCommand($"{tools["hacPack"]} {args}");
string output = ExecuteCommand($"{tools["hacPack"]} {args}", workdir);
return ParseNCAOutput(output, "Control");
}
static void BuildMetaNCA(string tmpPath, string titleID, string programNCA, string controlNCA)
static void BuildMetaNCA(string tmpPath, string titleID, string programNCA, string controlNCA, string workdir)
{
string args = $"-k \"{prodKeysPath}\" -o \"{tmpPath}\" --titleid {titleID} " +
$"--type nca --ncatype meta --titletype application " +
$"--programnca \"{programNCA}\" --controlnca \"{controlNCA}\"";
ExecuteCommand($"{tools["hacPack"]} {args}");
ExecuteCommand($"{tools["hacPack"]} {args}", workdir);
}
static string BuildFinalNSP(string origPath, string parentDir, string tmpPath, string titleID)
static string BuildFinalNSP(string origPath, string parentDir, string tmpPath, string titleID, string workdir)
{
string outputPath = origPath.Replace(".nsp", "_repacked.nsp");
if (File.Exists(outputPath)) File.Delete(outputPath);
@ -311,7 +326,7 @@ namespace AxibugEmuOnline.Editors
string args = $"-k \"{prodKeysPath}\" -o \"{parentDir}\" --titleid {titleID} " +
$"--type nsp --ncadir \"{tmpPath}\"";
ExecuteCommand($"{tools["hacPack"]} {args}");
ExecuteCommand($"{tools["hacPack"]} {args}", workdir);
File.Move(Path.Combine(parentDir, $"{titleID}.nsp"), outputPath);
return outputPath;
}
@ -320,8 +335,11 @@ namespace AxibugEmuOnline.Editors
{
var line = output.Split('\n')
.FirstOrDefault(l => l.Contains($"Created {type} NCA:"));
return line?.Split(':').Last().Trim();
//return line?.Split(':').Last().Trim();
return line?.Substring(line.IndexOf("NCA:") + "NCA:".Length).Trim();
}
#endregion
}
}
#endif

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: b31e2ae7250c09548a777d4dcdfe2d1f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 7be57cd4293e9dc4297ea9b83fe08b18
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: e1252f6d74d67ee48af0a0342aecc981
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,152 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Application>
<Title>
<Language>AmericanEnglish</Language>
<Name>Homebrew Menu</Name>
<Publisher>Yellows8</Publisher>
</Title>
<Title>
<Language>BritishEnglish</Language>
<Name>Homebrew Menu</Name>
<Publisher>Yellows8</Publisher>
</Title>
<Title>
<Language>Japanese</Language>
<Name>Homebrew Menu</Name>
<Publisher>Yellows8</Publisher>
</Title>
<Title>
<Language>French</Language>
<Name>Homebrew Menu</Name>
<Publisher>Yellows8</Publisher>
</Title>
<Title>
<Language>German</Language>
<Name>Homebrew Menu</Name>
<Publisher>Yellows8</Publisher>
</Title>
<Title>
<Language>LatinAmericanSpanish</Language>
<Name>Homebrew Menu</Name>
<Publisher>Yellows8</Publisher>
</Title>
<Title>
<Language>Spanish</Language>
<Name>Homebrew Menu</Name>
<Publisher>Yellows8</Publisher>
</Title>
<Title>
<Language>Italian</Language>
<Name>Homebrew Menu</Name>
<Publisher>Yellows8</Publisher>
</Title>
<Title>
<Language>Dutch</Language>
<Name>Homebrew Menu</Name>
<Publisher>Yellows8</Publisher>
</Title>
<Title>
<Language>CanadianFrench</Language>
<Name>Homebrew Menu</Name>
<Publisher>Yellows8</Publisher>
</Title>
<Title>
<Language>Portuguese</Language>
<Name>Homebrew Menu</Name>
<Publisher>Yellows8</Publisher>
</Title>
<Title>
<Language>Russian</Language>
<Name>Homebrew Menu</Name>
<Publisher>Yellows8</Publisher>
</Title>
<Isbn/>
<StartupUserAccount>Required</StartupUserAccount>
<UserAccountSwitchLock>Disable</UserAccountSwitchLock>
<ParentalControl>None</ParentalControl>
<SupportedLanguage>AmericanEnglish</SupportedLanguage>
<SupportedLanguage>BritishEnglish</SupportedLanguage>
<SupportedLanguage>Japanese</SupportedLanguage>
<SupportedLanguage>French</SupportedLanguage>
<SupportedLanguage>German</SupportedLanguage>
<SupportedLanguage>LatinAmericanSpanish</SupportedLanguage>
<SupportedLanguage>Spanish</SupportedLanguage>
<SupportedLanguage>Italian</SupportedLanguage>
<SupportedLanguage>Dutch</SupportedLanguage>
<SupportedLanguage>CanadianFrench</SupportedLanguage>
<SupportedLanguage>Russian</SupportedLanguage>
<Screenshot>Allow</Screenshot>
<VideoCapture>Disable</VideoCapture>
<PresenceGroupId>0x0104444444441001</PresenceGroupId>
<DisplayVersion>2.0</DisplayVersion>
<Rating>
<Organization>CERO</Organization>
<Age>12</Age>
</Rating>
<Rating>
<Organization>ESRB</Organization>
<Age>10</Age>
</Rating>
<Rating>
<Organization>USK</Organization>
<Age>12</Age>
</Rating>
<Rating>
<Organization>PEGI</Organization>
<Age>12</Age>
</Rating>
<Rating>
<Organization>PEGIPortugal</Organization>
<Age>12</Age>
</Rating>
<Rating>
<Organization>PEGIBBFC</Organization>
<Age>12</Age>
</Rating>
<Rating>
<Organization>Russian</Organization>
<Age>12</Age>
</Rating>
<Rating>
<Organization>ACB</Organization>
<Age>13</Age>
</Rating>
<Rating>
<Organization>OFLC</Organization>
<Age>13</Age>
</Rating>
<DataLossConfirmation>Required</DataLossConfirmation>
<PlayLogPolicy>All</PlayLogPolicy>
<SaveDataOwnerId>0x0104444444441001</SaveDataOwnerId>
<UserAccountSaveDataSize>0x0000000003e00000</UserAccountSaveDataSize>
<UserAccountSaveDataJournalSize>0x0000000000180000</UserAccountSaveDataJournalSize>
<DeviceSaveDataSize>0x0000000000000000</DeviceSaveDataSize>
<DeviceSaveDataJournalSize>0x0000000000000000</DeviceSaveDataJournalSize>
<BcatDeliveryCacheStorageSize>0x0000000000000000</BcatDeliveryCacheStorageSize>
<ApplicationErrorCodeCategory/>
<AddOnContentBaseId>0x0104444444442001</AddOnContentBaseId>
<LogoType>Nintendo</LogoType>
<LocalCommunicationId>0x0104444444441001</LocalCommunicationId>
<LogoHandling>Auto</LogoHandling>
<SeedForPseudoDeviceId>0x0000000000000000</SeedForPseudoDeviceId>
<BcatPassphrase/>
<AddOnContentRegistrationType>AllOnLaunch</AddOnContentRegistrationType>
<UserAccountSaveDataSizeMax>0x0000000000000000</UserAccountSaveDataSizeMax>
<UserAccountSaveDataJournalSizeMax>0x0000000000000000</UserAccountSaveDataJournalSizeMax>
<DeviceSaveDataSizeMax>0x0000000000000000</DeviceSaveDataSizeMax>
<DeviceSaveDataJournalSizeMax>0x0000000000000000</DeviceSaveDataJournalSizeMax>
<TemporaryStorageSize>0x0000000000000000</TemporaryStorageSize>
<CacheStorageSize>0x0000000000000000</CacheStorageSize>
<CacheStorageJournalSize>0x0000000000000000</CacheStorageJournalSize>
<CacheStorageDataAndJournalSizeMax>0x0000000000000000</CacheStorageDataAndJournalSizeMax>
<CacheStorageIndexMax>0x0000000000000000</CacheStorageIndexMax>
<Hdcp>None</Hdcp>
<CrashReport>Deny</CrashReport>
<RuntimeAddOnContentInstall>Deny</RuntimeAddOnContentInstall>
<PlayLogQueryableApplicationId>0x0000000000000000</PlayLogQueryableApplicationId>
<PlayLogQueryCapability>None</PlayLogQueryCapability>
<Repair>None</Repair>
<Attribute>None</Attribute>
<ProgramIndex>0</ProgramIndex>
<RequiredNetworkServiceLicenseOnLaunch>None</RequiredNetworkServiceLicenseOnLaunch>
</Application>

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 42c1295c31de3a948825b9e8e9e8184f
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,5 +1,32 @@
*本文仅作技术研究因为合规原因本文不提供任何法律敏感和版权相关的诸如SDK的文件。
------------
Unity Switch 开发打包移植相关的一系列教程by 皓月狩魂(Sin365) axibug.com
初版分享:
声明:
*文章和开源代码仓库仅作技术研究因为合规原因不包含也提供任何法律敏感和版权相关的诸如SDK的文件。
*请自行获取,建议您使用官方授权的开发套件。
*谢绝讨论任何技术外的诸如NS移植游戏开发的性质等无意义问题我只是技术爱好者。相互尊重相互学习。
文章:
1.Unity Switch 开发/打包/移植教程包含如何重新Repack NSP,让捣鼓后的零售机运行)
http://note.axibug.com/blog/post/akiragatsu/UnitySwitchDev
2.Unity下Switch开发文件存储踩坑以及解决方案范例 Unity Switch下不能用System.IO,只能用nn.fs
http://note.axibug.com/blog/post/akiragatsu/UnitySwitchDevForIO
3.Switch系统错误码方便排查问题 我AxiNSApi中也提供了转换打印方便排查
http://note.axibug.com/blog/post/akiragatsu/SwitchErrCode
4.Switch TitleID规则
http://note.axibug.com/blog/post/akiragatsu/SwitchTitleID
------------
### 1. Nintendo SDK
> 这个我不会提供任何文件,或者建议您使用任天堂官方授权的开发套件(笑)