Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
Added new entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Razmoth committed Oct 28, 2023
1 parent fabdaec commit e863310
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
3 changes: 3 additions & 0 deletions AssetStudio/FileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ public static FileReader PreProcessing(this FileReader reader, Game game)
break;
case GameType.GirlsFrontline:
reader = DecryptGirlsFrontline(reader);
break;
case GameType.Reverse1999:
reader = DecryptReverse1999(reader);
break;
}
}
Expand Down
4 changes: 3 additions & 1 deletion AssetStudio/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static GameManager()
Games.Add(index++, new Game(GameType.ProjectSekai));
Games.Add(index++, new Game(GameType.CodenameJump));
Games.Add(index++, new Game(GameType.GirlsFrontline));
Games.Add(index++, new Game(GameType.Reverse1999));
}
public static Game GetGame(GameType gameType) => GetGame((int)gameType);
public static Game GetGame(int index)
Expand Down Expand Up @@ -150,7 +151,8 @@ public enum GameType
AliceGearAegis,
ProjectSekai,
CodenameJump,
GirlsFrontline
GirlsFrontline,
Reverse1999
}

public static class GameTypes
Expand Down
52 changes: 52 additions & 0 deletions AssetStudio/ImportHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -898,5 +898,57 @@ public static FileReader DecryptGirlsFrontline(FileReader reader)
ms.Position = 0;
return new FileReader(reader.FullPath, ms);
}

public static FileReader DecryptReverse1999(FileReader reader)
{
Logger.Verbose($"Attempting to decrypt file {reader.FileName} with Reverse: 1999 encryption");

var signatureBytes = reader.ReadBytes(8);
var signature = Encoding.UTF8.GetString(signatureBytes[..7]);
if (signature == "UnityFS")
{
Logger.Verbose("Found UnityFS signature, file might not be encrypted");
reader.Position = 0;
return reader;
}

var key = GetAbEncryptKey(Path.GetFileNameWithoutExtension(reader.FileName));
for (int i = 0; i < signatureBytes.Length; i++)
{
signatureBytes[i] ^= key;
}

signature = Encoding.UTF8.GetString(signatureBytes[..7]);
if (signature == "UnityFS")
{
Logger.Verbose($"Found UnityFS signature, key 0x{key:X2} is valid, decrypting the rest of the stream");
var remaining = reader.ReadBytes((int)reader.Remaining);
for (int i = 0; i < remaining.Length; i++)
{
remaining[i] ^= key;
}

Logger.Verbose("Decrypted Reverse: 1999 file successfully !!");
var stream = new MemoryStream();
stream.Write(signatureBytes);
stream.Write(remaining);
stream.Position = 0;
return new FileReader(reader.FullPath, stream);
}

Logger.Verbose("File doesn't match any of the encryption types");
reader.Position = 0;
return reader;

static byte GetAbEncryptKey(string md5Name)
{
byte key = 0;
foreach (var c in md5Name)
{
key += (byte)c;
}
return (byte)(key + (byte)(2 * ((key & 1) + 1)));
}
}
}
}

0 comments on commit e863310

Please sign in to comment.