Skip to content

Commit c15e345

Browse files
committed
make Chovy-Sign-CLI and GUI version run on linux
1 parent 5aa3452 commit c15e345

18 files changed

+288
-88
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<_LastSelectedProfileId>C:\Users\Li\Documents\git\Chovy-Sign-v2\ChovySign-CLI\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
4+
<_LastSelectedProfileId>C:\Users\Li\Documents\git\Chovy-Sign-v2\ChovySign-CLI\Properties\PublishProfiles\Win64.pubxml</_LastSelectedProfileId>
55
</PropertyGroup>
66
</Project>

ChovySign-CLI/Program.cs

+90-25
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,38 @@
44
using LibChovy;
55
using LibChovy.VersionKey;
66
using System.Text;
7+
using Vita.ContentManager;
8+
using PspCrypto;
79

810
namespace ChovySign_CLI
911
{
1012
internal class Program
1113
{
1214
private static ArgumentParsingMode mode = ArgumentParsingMode.ARG;
1315
private static List<string> parameters = new List<string>();
14-
private static string[] discs;
16+
private static string[] discs = new string[] { };
1517
private static bool pspCompress = false;
16-
private static bool devKit = false;
1718
private static string? popsDiscName;
18-
private static string? popsIcon0File;
19-
private static string? popsPic0File;
19+
private static byte[]? popsIcon0File;
20+
private static byte[]? popsPic0File;
2021
private static PbpMode? pbpMode = null;
2122
private static NpDrmRif? rifFile = null;
2223
private static NpDrmInfo? drmInfo = null;
2324

25+
// cma
26+
private static bool devKit = false;
27+
private static bool packagePsvImg = true;
28+
private static string? outputFolder = null;
29+
30+
// --vkey-gen
2431
private static byte[]? actDat = null;
2532
private static byte[]? idps = null;
2633
private static string? rifFolder = null;
34+
35+
// --pops-eboot-sign
36+
private static byte[]? ebootElf = null;
37+
private static byte[]? configBin = null;
38+
2739
enum PbpMode
2840
{
2941
PSP = 0,
@@ -33,15 +45,23 @@ enum PbpMode
3345
}
3446
enum ArgumentParsingMode
3547
{
36-
ARG = 0,
37-
POPS_DISC = 1,
38-
PSP_UMD = 2,
39-
VERSIONKEY = 3,
40-
VERSIONKEY_EXTRACT = 4,
41-
VERSIONKEY_GENERATOR = 5,
42-
POPS_INFO = 6,
43-
KEYS_TXT_GEN = 7,
44-
RIF = 8
48+
ARG,
49+
POPS_DISC,
50+
PSP_UMD,
51+
52+
VERSIONKEY,
53+
VERSIONKEY_EXTRACT,
54+
VERSIONKEY_GENERATOR,
55+
56+
CMA_DEVKIT,
57+
CMA_OUTPUT_FOLDER,
58+
CMA_PACKAGE_PSVIMG,
59+
60+
POPS_INFO,
61+
POPS_EBOOT,
62+
63+
KEYS_TXT_GEN,
64+
RIF
4565
}
4666
public static int Error(string errorMsg, int ret)
4767
{
@@ -102,13 +122,13 @@ private static int complete()
102122
switch (mode)
103123
{
104124
case ArgumentParsingMode.POPS_DISC:
105-
if (parameters.Count > 5) return Error("--pops: no more than 5 disc images allowed in a single game (sony's rules, not mine)", 5);
106-
if (parameters.Count < 1) return Error("--pops: at least 1 disc image file is required.", 5);
125+
if (parameters.Count > 5) return Error("--pops: no more than 5 disc images allowed in a single game (sony's rules, not mine)", 4);
126+
if (parameters.Count < 1) return Error("--pops: at least 1 disc image file is required.", 4);
107127
discs = parameters.ToArray();
108128
break;
109129
case ArgumentParsingMode.PSP_UMD:
110-
if (parameters.Count < 1) return Error("--psp: a path to a disc image is required", 5);
111-
if (parameters.Count > 2) return Error("--psp: no more than 2 arguments. ("+parameters.Count+" given)", 5);
130+
if (parameters.Count < 1) return Error("--psp: a path to a disc image is required", 4);
131+
if (parameters.Count > 2) return Error("--psp: no more than 2 arguments. ("+parameters.Count+" given)", 4);
112132
discs = new string[1];
113133
discs[0] = parameters[0];
114134

@@ -134,17 +154,34 @@ private static int complete()
134154
if (parameters.Count < 2) return Error("--pops-info takes at least 1 arguments ("+parameters.Count+" given)", 4);
135155
if (parameters.Count > 3) return Error("--pops-info takes no more than 3 arguments("+parameters.Count+" given)", 4);
136156
popsDiscName = parameters[0];
137-
if (parameters.Count > 1)
138-
popsIcon0File = parameters[1];
139-
if (parameters.Count > 2)
140-
popsPic0File = parameters[2];
157+
if (parameters.Count > 1 && File.Exists(parameters[1]))
158+
popsIcon0File = File.ReadAllBytes(parameters[1]);
159+
if (parameters.Count > 2 && File.Exists(parameters[2]))
160+
popsPic0File = File.ReadAllBytes(parameters[2]);
141161
break;
142162
case ArgumentParsingMode.KEYS_TXT_GEN:
143163
if (parameters.Count != 3) return Error("--keys-txt-gen takes 3 arguments, (" + parameters.Count + " given)", 4);
144164
actDat = File.ReadAllBytes(parameters[0]);
145165
idps = StringToByteArray(parameters[1]);
146166
rifFolder = parameters[2];
147167
break;
168+
case ArgumentParsingMode.POPS_EBOOT:
169+
if (parameters.Count < 1) return Error("--pops-eboot-sign expects at most 1 arguments", 4);
170+
if (!File.Exists(parameters[0])) return Error("--pops-eboot-sign: file not found", 4);
171+
ebootElf = File.ReadAllBytes(parameters[0]);
172+
173+
if (parameters.Count >= 2 && File.Exists(parameters[1]))
174+
configBin = File.ReadAllBytes(parameters[1]);
175+
else
176+
configBin = GameBuilder.Resources.DATAPSPSDCFG;
177+
178+
break;
179+
case ArgumentParsingMode.CMA_OUTPUT_FOLDER:
180+
if (parameters.Count < 1) return Error("--output-folder expects 1 output", 4);
181+
if (!Directory.Exists(parameters[0])) return Error("--output-folder: directory not found", 4);
182+
183+
SettingsReader.BackupsFolder = parameters[0];
184+
break;
148185
case ArgumentParsingMode.RIF:
149186
if (parameters.Count != 1) return Error("--rif expects only 1 argument,", 4);
150187
rifFile = new NpDrmRif(File.ReadAllBytes(parameters[0]));
@@ -163,12 +200,20 @@ public static int Main(string[] args)
163200
Console.WriteLine("Chovy-Sign v2 (CLI)");
164201
Console.WriteLine("--pops [disc1.cue] [disc2.cue] [disc3.cue] ... (up to 5)");
165202
Console.WriteLine("--pops-info [game title] [icon0.png] (optional) [pic1.png] (optional)");
203+
Console.WriteLine("--pops-eboot [eboot.elf] [config.bin] (optional)");
204+
166205
Console.WriteLine("--psp [umd.iso] [compress; true/false] (optional)");
206+
167207
Console.WriteLine("--rif [GAME.RIF]");
208+
168209
Console.WriteLine("--devkit (Use 000000000000 account id)");
210+
Console.WriteLine("--no-psvimg (Disable creating a .psvimg file)");
211+
Console.WriteLine("--output-folder [output_folder]");
212+
169213
Console.WriteLine("--vkey [versionkey] [contentid] [key_index]");
170214
Console.WriteLine("--vkey-extract [eboot.pbp]");
171215
Console.WriteLine("--vkey-gen [act.dat] [license.rif] [console_id] [key_index]");
216+
172217
Console.WriteLine("--keys-txt-gen [act.dat] [console_id] [psp_license_folder]");
173218
}
174219

@@ -236,6 +281,17 @@ public static int Main(string[] args)
236281
return Error("rif is already set", 3);
237282

238283
break;
284+
case "--pops-eboot":
285+
mode = ArgumentParsingMode.POPS_EBOOT;
286+
break;
287+
case "--output-folder":
288+
mode = ArgumentParsingMode.CMA_OUTPUT_FOLDER;
289+
break;
290+
291+
case "--no-psvimg":
292+
packagePsvImg = false;
293+
break;
294+
239295
case "--devkit":
240296
devKit = true;
241297
break;
@@ -248,6 +304,7 @@ public static int Main(string[] args)
248304
case ArgumentParsingMode.VERSIONKEY_EXTRACT:
249305
case ArgumentParsingMode.PSP_UMD:
250306
case ArgumentParsingMode.POPS_DISC:
307+
case ArgumentParsingMode.POPS_EBOOT:
251308
case ArgumentParsingMode.POPS_INFO:
252309
case ArgumentParsingMode.RIF:
253310
default:
@@ -267,14 +324,14 @@ public static int Main(string[] args)
267324
if (pbpMode is null) return Error("no pbp mode was set, exiting", 7);
268325

269326
if (pbpMode == PbpMode.PSP && drmInfo.KeyIndex != 2)
270-
return Error("KeyType is "+drmInfo.KeyIndex+", but PBP mode is PSP, you cant do that .. please use a type 1 versionkey.", 8);
327+
return Error("KeyType is "+drmInfo.KeyIndex+", but PBP mode is PSP, you cant do that .. please use a type 2 versionkey.", 8);
271328

272329
if (pbpMode == PbpMode.POPS && drmInfo.KeyIndex != 1)
273330
return Error("KeyType is " + drmInfo.KeyIndex + ", but PBP mode is POPS, you cant do that .. please use a type 1 versionkey.", 8);
274331

275332
if (rifFile is null)
276333
return Error("Rif is not set, use --rif to specify base game RIF", 8);
277-
//if (pbpMode == PbpMode.POPS && (popsDiscName is null || popsIcon0File is null)) return Error("pbp mode is POPS, but you have not specified a disc title or icon file using --pops-info.", 9);
334+
278335
ChovySign csign = new ChovySign();
279336
csign.RegisterCallback(onProgress);
280337
if (pbpMode == PbpMode.POPS)
@@ -287,18 +344,26 @@ public static int Main(string[] args)
287344
if(popsDiscName is not null)
288345
popsParameters.Name = popsDiscName;
289346

290-
if(File.Exists(popsIcon0File))
291-
popsParameters.Icon0 = File.ReadAllBytes(popsIcon0File);
347+
if(popsIcon0File is not null)
348+
popsParameters.Icon0 = popsIcon0File;
349+
292350

351+
popsParameters.CreatePsvImg = packagePsvImg;
293352
popsParameters.Account.Devkit = devKit;
294353

354+
// Allow for custom eboot.elf and configs
355+
popsParameters.ConfigBinOverride = configBin;
356+
popsParameters.EbootElfOverride = ebootElf;
357+
295358
csign.Go(popsParameters);
296359

297360
}
298361
else if(pbpMode == PbpMode.PSP)
299362
{
300363
PspParameters pspParameters = new PspParameters(drmInfo, rifFile);
301364
pspParameters.Account.Devkit = devKit;
365+
pspParameters.CreatePsvImg = packagePsvImg;
366+
302367
pspParameters.Compress = pspCompress;
303368
pspParameters.Umd = new UmdInfo(discs.First());
304369

ChovySign-CLI/Properties/PublishProfiles/FolderProfile.pubxml.user

-10
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project>
6+
<PropertyGroup>
7+
<Configuration>Release</Configuration>
8+
<Platform>Any CPU</Platform>
9+
<PublishDir>bin\Release\Linux</PublishDir>
10+
<PublishProtocol>FileSystem</PublishProtocol>
11+
<_TargetId>Folder</_TargetId>
12+
<TargetFramework>net6.0</TargetFramework>
13+
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
14+
<SelfContained>true</SelfContained>
15+
<PublishSingleFile>true</PublishSingleFile>
16+
<PublishReadyToRun>true</PublishReadyToRun>
17+
<PublishTrimmed>true</PublishTrimmed>
18+
</PropertyGroup>
19+
</Project>

ChovySign-CLI/Properties/PublishProfiles/FolderProfile.pubxml ChovySign-CLI/Properties/PublishProfiles/Win64.pubxml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
66
<PropertyGroup>
77
<Configuration>Release</Configuration>
88
<Platform>Any CPU</Platform>
9-
<PublishDir>bin\Release\</PublishDir>
9+
<PublishDir>bin\Release\Windows</PublishDir>
1010
<PublishProtocol>FileSystem</PublishProtocol>
1111
<_TargetId>Folder</_TargetId>
1212
<TargetFramework>net6.0</TargetFramework>

ChovySign-GUI/Global/ProgressStatus.axaml.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,21 @@ private async void goClick(object sender, RoutedEventArgs e)
4242
if (currentWindow is not Window) throw new Exception("could not find current window");
4343

4444
this.goButton.IsEnabled = false;
45-
45+
4646
OnBeforeStart(new EventArgs());
4747

4848
if(Parameters is null) { await MessageBox.Show(currentWindow, "ChovySignParameters was null, cannot start!", "Invalid Parameters", MessageBoxButtons.Ok); return; }
4949

50-
await Task.Run(() => { chovySign.Go(Parameters); });
50+
await Task.Run(() => {
51+
try
52+
{
53+
chovySign.Go(Parameters);
54+
}
55+
catch (Exception e)
56+
{
57+
Dispatcher.UIThread.Post(() => { _ = MessageBox.Show(currentWindow, "Error building: " + e.Message + "\n\nSTACKTRACE: " + e.StackTrace, "ERROR", MessageBoxButtons.Ok); });
58+
}
59+
});
5160

5261
OnFinished(new EventArgs());
5362

ChovySign-GUI/MainWindow.axaml.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Avalonia;
12
using Avalonia.Controls;
23

34
namespace ChovySign_GUI

ChovySign-GUI/Ps1/GameInfoSelector.axaml.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ public async Task GetGameInfo(string cueFile)
103103
loadIcon(newCover);
104104
iconCache = newCover;
105105
}
106-
catch (Exception) { }
106+
catch (Exception e) {
107+
Window? currentWindow = this.VisualRoot as Window;
108+
if (currentWindow is not Window) throw new Exception("could not find current window");
109+
110+
await MessageBox.Show(currentWindow, "unable to read cue sheet: " + Path.GetFileName(cueFile) + "\n" + e.Message + "\n\nSTACKTRACE: " + e.StackTrace, "cannot load cue sheet", MessageBox.MessageBoxButtons.Ok);
111+
}
107112
}
108113

109114
private async Task<byte[]?> doLoad(BrowseButton imgFile, int width, int height)

ChovySign-GUI/Psp/PspTab.axaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private async void onProcessFinished(object? sender, EventArgs e)
3838
{
3939
keySelector.IsEnabled = true;
4040
isoSelector.IsEnabled = true;
41-
SettingsTab.Settings.IsEnabled = false;
41+
SettingsTab.Settings.IsEnabled = true;
4242

4343
Window? currentWindow = this.VisualRoot as Window;
4444
if (currentWindow is not Window) throw new Exception("could not find current window");

GameBuilder/Atrac3/Atrac3ToolEncoder.cs

+19
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Diagnostics;
55
using System.Linq;
6+
using System.Runtime.InteropServices;
67
using System.Text;
78
using System.Threading.Channels;
89
using System.Threading.Tasks;
@@ -12,13 +13,17 @@ namespace GameBuilder.Atrac3
1213
{
1314
public class Atrac3ToolEncoder : IAtracEncoderBase
1415
{
16+
[DllImport("libc")]
17+
private static extern int setenv(string name, string value, bool overwrite);
18+
1519
private static Random rng = new Random();
1620
private static string TOOLS_DIRECTORY = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tools");
1721

1822
private static string AT3TOOL_WIN = Path.Combine(TOOLS_DIRECTORY, "at3tool.exe");
1923
private static string AT3TOOL_LINUX = Path.Combine(TOOLS_DIRECTORY, "at3tool.elf");
2024

2125
private static string TEMP_DIRECTORY = Path.Combine(Path.GetTempPath(), "at3tool_tmp");
26+
private static string LD_LIBRARY_PATH = "LD_LIBRARY_PATH";
2227

2328
// random name so that can generate multiple at once if wanted ..
2429
private string TEMP_WAV;
@@ -45,10 +50,24 @@ private static string AT3TOOL_LOCATION
4550
}
4651
}
4752

53+
private string setupLibaryPath()
54+
{
55+
string? libaryPath = Environment.GetEnvironmentVariable(LD_LIBRARY_PATH);
56+
if (libaryPath is null) libaryPath = TOOLS_DIRECTORY;
57+
else libaryPath += ";" + TOOLS_DIRECTORY;
58+
59+
Environment.SetEnvironmentVariable(libaryPath, libaryPath);
60+
setenv(LD_LIBRARY_PATH, libaryPath, true);
61+
62+
return libaryPath;
63+
}
4864
private void runAtrac3Tool()
4965
{
5066
using(Process proc = new Process())
5167
{
68+
if (OperatingSystem.IsLinux())
69+
proc.StartInfo.Environment.Add(LD_LIBRARY_PATH, setupLibaryPath());
70+
5271
proc.StartInfo.FileName = AT3TOOL_LOCATION;
5372
proc.StartInfo.Arguments = "-br 132 -e \"" + TEMP_WAV + "\" \"" + TEMP_AT3 + "\"";
5473

0 commit comments

Comments
 (0)