aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Horizon/Sdk/Settings/LanguageCode.cs
blob: dc9712692482a03e7ac0a91b160f945b4f153248 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Ryujinx.Common.Memory;
using System;
using System.Runtime.InteropServices;
using System.Text;

namespace Ryujinx.Horizon.Sdk.Settings
{
    [StructLayout(LayoutKind.Sequential, Size = 0x8, Pack = 0x1)]
    struct LanguageCode
    {
        private static readonly string[] _languageCodes = new string[]
        {
            "ja",
            "en-US",
            "fr",
            "de",
            "it",
            "es",
            "zh-CN",
            "ko",
            "nl",
            "pt",
            "ru",
            "zh-TW",
            "en-GB",
            "fr-CA",
            "es-419",
            "zh-Hans",
            "zh-Hant",
            "pt-BR"
        };

        public Array8<byte> Value;

        public bool IsValid()
        {
            int length = Value.AsSpan().IndexOf((byte)0);
            if (length < 0)
            {
                return false;
            }

            string str = Encoding.ASCII.GetString(Value.AsSpan()[..length]);

            return _languageCodes.AsSpan().Contains(str);
        }

        public LanguageCode(Language language)
        {
            if ((uint)language >= _languageCodes.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(language));
            }

            Value = new LanguageCode(_languageCodes[(int)language]).Value;
        }

        public LanguageCode(string strCode)
        {
            Encoding.ASCII.GetBytes(strCode, Value.AsSpan());
        }
    }
}