physis/
common.rs

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later

use std::fs;
use std::path::Path;

use binrw::binrw;

#[binrw]
#[brw(repr(u8))]
#[repr(u8)]
#[derive(Copy, Clone)]
/// The language the game data is written for. Some of these languages are supported in the Global region.
pub enum Language {
    /// Used for data that is language-agnostic, such as item data.
    None,
    /// Japanese language.
    Japanese,
    /// English language.
    English,
    /// German language.
    German,
    /// French language.
    French,
    /// Chinese (Simplified) language.
    ChineseSimplified,
    /// Chinese (Traditional) language.
    ChineseTraditional,
    /// Korean language.
    Korean,
}

/// Returns the shorthand language code for `language`. For example, English becomes "en".
pub fn get_language_code(lang: &Language) -> &'static str {
    match &lang {
        Language::None => "",
        Language::Japanese => "ja",
        Language::English => "en",
        Language::German => "de",
        Language::French => "fr",
        Language::ChineseSimplified => "chs",
        Language::ChineseTraditional => "cht",
        Language::Korean => "ko",
    }
}

/// The region of the game. Used to denote the region a patch is meant for.
#[binrw]
#[brw(repr = i16)]
#[derive(Debug, PartialEq, Eq)]
pub enum Region {
    /// The global region, used for any region not specified.
    Global = -1,
    /// Korea and China clients.
    KoreaChina = 1,
}

/// Reads a version file.
pub fn read_version(p: &Path) -> Option<String> {
    fs::read_to_string(p).ok()
}

#[binrw]
#[brw(repr = u8)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Platform {
    /// Windows and macOS
    Win32 = 0x0,
    /// Playstation 3
    PS3 = 0x1,
    /// Playstation 4
    PS4 = 0x2,
    /// Playstation 5
    PS5 = 0x3,
    /// Xbox
    Xbox = 0x4,
}

pub fn get_platform_string(id: &Platform) -> &'static str {
    match &id {
        Platform::Win32 => "win32",
        Platform::PS3 => "ps3",
        Platform::PS4 => "ps4",
        Platform::PS5 => "ps5",
        Platform::Xbox => "lys",
    }
}