Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions src/Watson.CLI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Spectre.Console;
using AssetsTools.NET.Extra;
using Spectre.Console;
using Watson.Lib.Game.AI_TheSomniumFiles2.Enums;
using Watson.Lib.IO;
using Watson.Program.Utils;

AnsiConsole.Markup("[purple]Welcome to Watson![/] - [yellow]v1.1.0[/]\n");
Expand All @@ -9,11 +11,11 @@
{
case HandlerArgs.Mode.SVS:
AnsiConsole.Progress()
.Start(ctx =>
.Start(ctx =>
{
var svs = new Watson.Lib.Game.neptunia_sisters_vs_sisters.Game(arg.GamePath, ctx);
svs.Proccess();

// Extract to Po
if (arg.extract)
{
Expand All @@ -25,15 +27,15 @@
AnsiConsole.MarkupLine("[green]Juego - AI: The Somnium Files - Nirvana Initiative[/]");
AnsiConsole.Status()
.AutoRefresh(true)
.Start("Iniciando...", ctx =>
.Start("Iniciando...", ctx =>
{
// Simulate some work
ctx.Status("Leyendo carpeta del juego...");
ctx.Spinner(Spinner.Known.Circle);
ctx.SpinnerStyle(Style.Parse("yellow"));
var psync2 = new Watson.Lib.Game.AI_TheSomniumFiles2.Game(arg.GamePath, LanguageType.en, ctx);


// Update the status and spinner
ctx.Status("Procesando Archivos...");
psync2.Load();
Expand All @@ -47,8 +49,39 @@
}
});
break;
case HandlerArgs.Mode.Unity3D:
AnsiConsole.MarkupLine("[green]Modo - Unity3D[/]");
AnsiConsole.Status()
.AutoRefresh(true)
.Start("Iniciando...", ctx =>
{
ctx.Status("Leyendo archivo...");
ctx.Spinner(Spinner.Known.Circle);
ctx.SpinnerStyle(Style.Parse("yellow"));
UnityAssetFile.LoadAndExtractUnity3D(arg.filePath);
});
break;
case HandlerArgs.Mode.CocoDrilo:
AnsiConsole.MarkupLine("[green]Juego - Later Alligator[/]");
AnsiConsole.Status()
.AutoRefresh(true)
.Start("Iniciando...", ctx =>
{
ctx.Spinner(Spinner.Known.Circle);
ctx.SpinnerStyle(Style.Parse("yellow"));
var cocodrilo = new Watson.Lib.Game.LaterAlligator.Game(arg.GamePath, ctx);

if (arg.extract)
{
cocodrilo.Proccess();
cocodrilo.Export(arg.OutPut);
}

cocodrilo.Import(arg.PoPath);
});
break;
case HandlerArgs.Mode.Help:
default:
HandlerArgs.PrintInfo();
break;
}
}
32 changes: 15 additions & 17 deletions src/Watson.CLI/Utils/HandlerArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public enum Mode
HoloError,
Windose,
SVS,
Psync2
Psync2,
CocoDrilo,
Unity3D
}

public HandlerArgs(string[] raw_args)
Expand All @@ -24,11 +26,15 @@ public HandlerArgs(string[] raw_args)
new( new[] { "--windose" }, () => OperationMode = Mode.Windose),
new( new[] { "--NeptuniaSVS", "-svs" }, () => OperationMode = Mode.SVS),
new( new[] { "--AI2", "-ai2" }, () => OperationMode = Mode.Psync2),
new( new[] { "--coco" }, () => OperationMode = Mode.CocoDrilo),
new( new[] { "--unity" }, () => OperationMode = Mode.Unity3D),

// Args
new(new[] { "--gamepath" }, x => GamePath = x),
new(new[] { "--output", "-o" }, x => OutPut = x),
new(new[] { "--extract", "-x" }, () => extract = true)
new(new[] { "--extract", "-x" }, () => extract = true),
new(new[] { "--import", "-i" }, x => PoPath = x),
new(new[] { "--file", "-f" }, x => filePath = x)
};

for (var i = 0; i < raw_args.Length; ++i)
Expand All @@ -40,30 +46,22 @@ public HandlerArgs(string[] raw_args)
else
handler.Invoke(handler.RequiresArg ? raw_args[++i] : null!);
}

if (import && string.IsNullOrEmpty(PoPath))
throw new Exception("Import requires a Po file path");
}

public Mode? OperationMode { get; private set; }
public string? GamePath { get; private set; }
public string? filePath { get; private set; }
public string? OutPut { get; private set; } = "out";
public string? PoPath { get; private set; }
public bool extract { get; private set; }
public bool import { get; private set; }

public static void PrintInfo()
{
AnsiConsole.Markup("[purple]Watson.CLI.exe[/] [red](MODE)[/] [yellow](OPTIONS)[/]");
/*cmdutils.print("Operation Modes:");
cmdutils.print(" --Hololy Download and decrypt Hololy models.");
cmdutils.print(" --HoloEarth Download HoloEarths.");
cmdutils.print(" --HololiveError Decrypt HololiveError bundles.");
cmdutils.print("General options: ");
cmdutils.print(" --output, -o Set the output folder.");
cmdutils.print("Hololive Error options:");
cmdutils.print(" --input, -i Set the input file to decrypt.");
cmdutils.print(" --hash Set the hash of the bundle");
cmdutils.print("Hololy options:");
cmdutils.print(" --dev Set the dev server");
cmdutils.print(" --list, -l List the models");
cmdutils.print(" --download, -d Download the models");
cmdutils.print(" --model Download the model by name");*/
}

private class Handler
Expand Down Expand Up @@ -95,4 +93,4 @@ public void Invoke(string arg)
Fn!();
}
}
}
}
3 changes: 2 additions & 1 deletion src/Watson.CLI/Watson.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Watson.Lib\Watson.Lib.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Spectre.Console" Version="0.48.1-preview.0.5" />
<PackageReference Include="Spectre.Console.Cli" Version="0.49.2-preview.0.26" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/Watson.Lib/Game/AI_TheSomniumFiles2/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void Proccess()
foreach (var sprite in m_Sprites) sprite.Load();
}

public void Import()
public void Import(string poPath)
{
throw new NotImplementedException();
}
Expand Down Expand Up @@ -148,4 +148,4 @@ public string[] listFonts(string filter = "")

return fonts.ToArray();
}
}
}
4 changes: 2 additions & 2 deletions src/Watson.Lib/Game/IGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public interface IGame

public void Proccess();

public void Import();
public void Import(string poPath = "");

public void Export(string outpath = "out");
}
}
173 changes: 173 additions & 0 deletions src/Watson.Lib/Game/LaterAlligator/Game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
namespace Watson.Lib.Game.LaterAlligator;

using AssetsTools.NET;
using AssetsTools.NET.Extra;
using IO;
using Spectre.Console;
using Utils;
using Yarhl.FileSystem;
using Yarhl.IO;
using Yarhl.Media.Text;

public class Game : IGame
{
public string gamepath { get; set; }
private string gamedatapath { get; set; }
private string assemblyFolder { get; set; }
private string ExtractedAssetsFolder { get; set; }
private StatusContext ctx { get; set; }

private Dictionary<string, string[]> Say = new Dictionary<string, string[]>();
private Dictionary<string, string[]> InvokeNextLineAsync = new Dictionary<string, string[]>();

public Game(string gamepath, StatusContext ctx)
{
this.gamepath = gamepath;
this.ctx = ctx;
Load();
}

public void Load()
{
gamedatapath = Path.Combine(gamepath, "LaterAlligator_Data");
assemblyFolder = Path.Combine(gamedatapath, "Managed");
ExtractedAssetsFolder = TempDirectory.CreateTempDirectory();
ctx.Status("Extrayendo Archivos...");
}

public void Proccess()
{
ctx.Status("Leyendo Archivos...");
foreach (string filePath in Directory.GetFiles(gamedatapath, "*.bundle", SearchOption.AllDirectories)) {
/*if (!filePath.Contains("scenes_scenes_ending-credits.bundle"))
continue;*/

AnsiConsole.MarkupLine("[yellow]Leyendo Archivo:[/] " + Path.GetFileName(filePath));
var m_assetfile = new UnityAssetFile(filePath, gamedatapath);
List<string> storyTexts = new List<string>();
List<string> nextLineAsync = new List<string>();
foreach (AssetFileInfo m_monobehaviour in m_assetfile.GetAssetsOfType(AssetClassID.MonoBehaviour)) {
var deserialized =
m_assetfile.AM.GetBaseField(m_assetfile.Assets, m_monobehaviour);
try
{
if (!deserialized["targetMethod"].IsDummy &&
deserialized["targetMethod"].Value.AsString == "NextLineAsync") {
foreach (AssetTypeValueField objValue in deserialized["methodParameters.Array"]) {
if (objValue["objValue"].IsDummy || objValue["objValue"]["stringValue"].IsDummy)
continue;
nextLineAsync.Add(objValue["objValue"]["stringValue"].Value.AsString);
}
}

if (!deserialized["storyText"].IsDummy)
storyTexts.Add(deserialized.Get("storyText").Value.AsString);
} catch (Exception e) {
#if DEBUG
AnsiConsole.WriteException(e);
#endif
}
}

if (storyTexts.Count > 0)
Say.Add(Path.GetFileName(filePath), storyTexts.ToArray());
if (nextLineAsync.Count > 0)
InvokeNextLineAsync.Add(Path.GetFileName(filePath), nextLineAsync.ToArray());

m_assetfile.Close();
}
}

public void Import(string poPath)
{
ctx.Status("Importando Archivos...");
foreach (string filePath in Directory.GetFiles(gamedatapath, "*.bundle", SearchOption.AllDirectories)) {

if (!File.Exists(Path.Combine(poPath, $"{Path.GetFileName(filePath)}.InvokeNextLineAsync.po")) && !File.Exists(Path.Combine(poPath, $"{Path.GetFileName(filePath)}.Say.po")))
continue;

AnsiConsole.MarkupLine("[yellow]Leyendo Archivo:[/] " + Path.GetFileName(filePath));
UnityAssetFile m_assetfile = new UnityAssetFile(filePath, gamedatapath);

if (File.Exists(Path.Combine(poPath, $"{Path.GetFileName(filePath)}.InvokeNextLineAsync.po"))) {
using var Po = NodeFactory.FromFile(Path.Combine(poPath, $"{Path.GetFileName(filePath)}.InvokeNextLineAsync.po"), FileOpenMode.Read);
Po.TransformWith(new Binary2Po());
var po = Po.GetFormatAs<Po>();
int index = 0;
foreach (AssetFileInfo m_monobehaviour in m_assetfile.GetAssetsOfType(AssetClassID.MonoBehaviour)) {

var deserialized = m_assetfile.AM.GetBaseField(m_assetfile.Assets, m_monobehaviour);

try {
if (!deserialized["targetMethod"].IsDummy &&
deserialized["targetMethod"].Value.AsString == "NextLineAsync") {
foreach (AssetTypeValueField objValue in deserialized["methodParameters.Array"]) {
if (objValue["objValue"].IsDummy || objValue["objValue"]["stringValue"].IsDummy)
continue;

objValue["objValue"]["stringValue"].Value.AsString =
!string.IsNullOrEmpty(po.Entries[index].Translated)
? po.Entries[index].Translated.Replace("\n", "\r\n")
: po.Entries[index].Original.Replace("\n", "\r\n");

m_monobehaviour.SetNewData(objValue);
index++;
}
}
} catch (Exception e) {
// ignored
}
}
}

if (File.Exists(Path.Combine(poPath, $"{Path.GetFileName(filePath)}.Say.po"))) {
using var Po = NodeFactory.FromFile(Path.Combine(poPath, $"{Path.GetFileName(filePath)}.Say.po"), FileOpenMode.Read);
Po.TransformWith(new Binary2Po());
var po = Po.GetFormatAs<Po>();
int index = 0;
foreach (AssetFileInfo m_monobehaviour in m_assetfile.GetAssetsOfType(AssetClassID.MonoBehaviour)) {
try {

var deserialized = m_assetfile.AM.GetBaseField(m_assetfile.Assets, m_monobehaviour);

if (!deserialized["storyText"].IsDummy) {
deserialized.Get("storyText").Value.AsString =
!string.IsNullOrEmpty(po.Entries[index].Translated)
? po.Entries[index].Translated.Replace("\n", "\r\n")
: po.Entries[index].Original.Replace("\n", "\r\n");
m_monobehaviour.SetNewData(deserialized);
index++;
}



} catch (Exception e) {

}
}
}

// Save the file
Utils.Helpers.AssetHelper.Save(m_assetfile);
m_assetfile.Close();
}
}

public void Export(string outputPath = "out")
{
ctx.Status("Exportando Archivos...");
Directory.CreateDirectory(outputPath);
foreach (var (fileName, texts) in Say)
{
AnsiConsole.MarkupLine($"[yellow]Exportando Archivo:[/] {fileName}");
var po = new ArrayString2Po(fileName, "Say").Convert(texts);
new Po2Binary().Convert(po).Stream?.WriteTo(Path.Combine(outputPath, $"{fileName}.Say.po"));
}

foreach (var (fileName, texts) in InvokeNextLineAsync) {
AnsiConsole.MarkupLine($"[yellow]Exportando Archivo:[/] {fileName}");
var po = new ArrayString2Po(fileName, "InvokeNextLineAsync").Convert(texts);
new Po2Binary().Convert(po).Stream?.WriteTo(Path.Combine(outputPath, $"{fileName}.InvokeNextLineAsync.po"));
}
}
}
4 changes: 2 additions & 2 deletions src/Watson.Lib/Game/Windose/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public void Proccess()
}
}

public void Import()
public void Import(string poPath = "")
{
throw new NotImplementedException();
}
Expand Down Expand Up @@ -1127,4 +1127,4 @@ public Po Convert(yakujoMaster.Param[] source)
}

#endregion
}
}
Loading