aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/Utilities
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.HLE/Utilities')
-rw-r--r--Ryujinx.HLE/Utilities/FontUtils.cs37
-rw-r--r--Ryujinx.HLE/Utilities/StringUtils.cs27
2 files changed, 63 insertions, 1 deletions
diff --git a/Ryujinx.HLE/Utilities/FontUtils.cs b/Ryujinx.HLE/Utilities/FontUtils.cs
new file mode 100644
index 00000000..efe7560c
--- /dev/null
+++ b/Ryujinx.HLE/Utilities/FontUtils.cs
@@ -0,0 +1,37 @@
+using System.IO;
+
+namespace Ryujinx.HLE.Utilities
+{
+ public static class FontUtils
+ {
+ private static readonly uint FontKey = 0x06186249;
+
+ public static byte[] DecryptFont(Stream BFTTFStream)
+ {
+ uint KXor(uint In) => In ^ 0x06186249;
+
+ using (BinaryReader Reader = new BinaryReader(BFTTFStream))
+ {
+ using (MemoryStream TTFStream = new MemoryStream())
+ {
+ using (BinaryWriter Output = new BinaryWriter(TTFStream))
+ {
+ if (KXor(Reader.ReadUInt32()) != 0x18029a7f)
+ {
+ throw new InvalidDataException("Error: Input file is not in BFTTF format!");
+ }
+
+ BFTTFStream.Position += 4;
+
+ for (int i = 0; i < (BFTTFStream.Length - 8) / 4; i++)
+ {
+ Output.Write(KXor(Reader.ReadUInt32()));
+ }
+
+ return TTFStream.ToArray();
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/Ryujinx.HLE/Utilities/StringUtils.cs b/Ryujinx.HLE/Utilities/StringUtils.cs
index e8d6550a..a10273ee 100644
--- a/Ryujinx.HLE/Utilities/StringUtils.cs
+++ b/Ryujinx.HLE/Utilities/StringUtils.cs
@@ -1,5 +1,7 @@
-using System;
+using Ryujinx.HLE.HOS;
+using System;
using System.Globalization;
+using System.IO;
using System.Linq;
using System.Text;
@@ -47,5 +49,28 @@ namespace Ryujinx.HLE.Utilities
return Output;
}
+
+ public static string ReadUtf8String(ServiceCtx Context, int Index = 0)
+ {
+ long Position = Context.Request.PtrBuff[Index].Position;
+ long Size = Context.Request.PtrBuff[Index].Size;
+
+ using (MemoryStream MS = new MemoryStream())
+ {
+ while (Size-- > 0)
+ {
+ byte Value = Context.Memory.ReadByte(Position++);
+
+ if (Value == 0)
+ {
+ break;
+ }
+
+ MS.WriteByte(Value);
+ }
+
+ return Encoding.UTF8.GetString(MS.ToArray());
+ }
+ }
}
}