aboutsummaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/zora-rs/Cargo.toml5
l---------libs/zora-rs/LICENSE1
-rw-r--r--libs/zora-rs/README.md12
-rw-r--r--libs/zora-rs/src/enums.rs89
-rw-r--r--libs/zora-rs/src/lib.rs77
-rw-r--r--libs/zora-rs/tests/web.rs3
6 files changed, 159 insertions, 28 deletions
diff --git a/libs/zora-rs/Cargo.toml b/libs/zora-rs/Cargo.toml
index c11df29..5535a13 100644
--- a/libs/zora-rs/Cargo.toml
+++ b/libs/zora-rs/Cargo.toml
@@ -13,12 +13,15 @@ crate-type = ["cdylib", "rlib"]
[features]
default = ["console_error_panic_hook"]
+
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
-specta = { version = "1.0.5", features = ["typescript"] }
+
+[target.'cfg(target_family = "wasm")'.dependencies]
wasm-bindgen = "0.2.84"
+
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
diff --git a/libs/zora-rs/LICENSE b/libs/zora-rs/LICENSE
new file mode 120000
index 0000000..30cff74
--- /dev/null
+++ b/libs/zora-rs/LICENSE
@@ -0,0 +1 @@
+../../LICENSE \ No newline at end of file
diff --git a/libs/zora-rs/README.md b/libs/zora-rs/README.md
index e69de29..bce0ffe 100644
--- a/libs/zora-rs/README.md
+++ b/libs/zora-rs/README.md
@@ -0,0 +1,12 @@
+# zora-rs
+
+`zora-rs` is a Rust implementation of The Legend of Zelda Oracle of Ages and Oracle of Seasons password system.
+It is heavily inspired by the C# implementation [zora-sharp](https://github.com/kabili207/zora-sharp).
+
+## Usage
+
+TODO
+
+## License
+
+MIT
diff --git a/libs/zora-rs/src/enums.rs b/libs/zora-rs/src/enums.rs
index a16718b..62cb8ac 100644
--- a/libs/zora-rs/src/enums.rs
+++ b/libs/zora-rs/src/enums.rs
@@ -1,33 +1,84 @@
-use serde::{Serialize, Deserialize};
-use specta::Type;
-mod utils;
+use serde::{Deserialize, Serialize};
+#[cfg(target_family = "wasm")]
+use wasm_bindgen::prelude::*;
/// The region of the game.
-#[derive(Debug, Clone, Type, Serialize, Deserialize)]
+///
+/// Currently only the US version is supported, though the EU version will probably work too.
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum Region {
- US,
- EU,
- JP,
+ US,
+ // EU,
+ // JP,
}
/// Which game
-#[derive(Debug, Clone, Type, Serialize, Deserialize)]
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum Game {
- Ages,
- Seasons,
+ Ages,
+ Seasons,
}
-#[derive(Debug, Clone, Type, Serialize, Deserialize)]
+/// The choice of animal companion
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum Animal {
- Ricky = 0x0b,
- Dimitri = 0x0c,
- Moosh = 0x0d,
+ Ricky = 0x0b,
+ Dimitri = 0x0c,
+ Moosh = 0x0d,
}
-#[derive(Debug, Clone, Type, Serialize, Deserialize)]
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub enum RupeesGiven {
+ /// One Rupee
+ One = 0,
+ /// Ten Rupees
+ Ten = 2,
+ /// Fifty Rupees
+ Fifty = 5,
+ // 150 Rupees
+ OneFifty = 8,
+}
+
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub enum SleepMethod {
+ Sing = 0,
+ Play = 10,
+}
+
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum Child {
- None,
- Curious,
- Shy,
- Hyperactive
+ None,
+ Curious,
+ Shy,
+ Hyperactive,
+}
+
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub enum AnimalChoice {
+ None = 0,
+ Ricky = 0x0b,
+ Dimitri = 0x0c,
+ Moosh = 0x0d,
+}
+
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub enum ChildQuestion {
+ NoEgg = 0,
+ YesChicken = 4,
} \ No newline at end of file
diff --git a/libs/zora-rs/src/lib.rs b/libs/zora-rs/src/lib.rs
index 239f3af..8a06dd5 100644
--- a/libs/zora-rs/src/lib.rs
+++ b/libs/zora-rs/src/lib.rs
@@ -1,13 +1,76 @@
-mod utils;
+use std::fmt;
+use serde::{Deserialize, Serialize};
+#[cfg(target_family = "wasm")]
use wasm_bindgen::prelude::*;
-#[wasm_bindgen]
-extern "C" {
- fn alert(s: &str);
+use enums::*;
+
+/// Enumerations for the various choices in the games.
+pub mod enums;
+
+/// The structure that holds the save information.
+///
+/// This is the main struct that is used to hold all the information about the save.
+/// This is used to serialize and deserialize the save data to and from a file.
+///
+/// # Example
+///
+/// ```rust
+/// use zora_rs::Save;
+///
+/// let save = Save {
+/// region: Region::US,
+/// game: Game::OcarinaOfTime,
+/// animal: Animal::Pony,
+/// rupees_given: RupeesGiven::No,
+/// sleep_method: SleepMethod::No,
+/// child: Child::No,
+/// animal_choice: AnimalChoice::No,
+/// child_question: ChildQuestion::No,
+/// hero: "Link".to_string(),
+/// child_name: "Child".to_string(),
+/// is_linked: false,
+/// is_hero_quest: false,
+/// };
+/// ```
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub struct Save {
+ region: Region,
+ game: Game,
+ animal: Animal,
+ rupees_given: RupeesGiven,
+ sleep_method: SleepMethod,
+ child: Child,
+ animal_choice: AnimalChoice,
+ child_question: ChildQuestion,
+ hero: String,
+ child_name: String,
+ is_linked: bool,
+ is_hero_quest: bool,
}
-#[wasm_bindgen]
-pub fn greet() {
- alert("Hello, zora-rs!");
+impl Save {
+ pub fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "")
+ }
}
+
+/// The cipher used by the non-Japanese versions of the game.
+/// "EN" is a misnomer, as it is used by all non-Japanese versions of the game.
+///
+/// Stolen (with love) from https://github.com/kabili207/zora-sharp/blob/master/src/Secret.cs#L53
+pub static EN_CIPHER: [u8; 48] = [
+ 21, 35, 46, 4, 13, 63, 26, 16, 58, 47, 30, 32, 15, 62, 54, 55, 9, 41, 59, 49, 2, 22, 61, 56,
+ 40, 19, 52, 50, 1, 11, 10, 53, 14, 27, 18, 44, 33, 45, 37, 48, 25, 42, 6, 57, 60, 23, 51, 24,
+];
+
+/// The cipher used by the Japanese version of the game.
+///
+/// Stolen (lovingly :)) from https://github.com/kabili207/zora-sharp/blob/master/src/Secret.cs#L45
+pub static JP_CIPHER: [u8; 48] = [
+ 0x31, 0x09, 0x29, 0x3b, 0x18, 0x3c, 0x17, 0x33, 0x35, 0x01, 0x0b, 0x0a, 0x30, 0x21, 0x2d, 0x25,
+ 0x20, 0x3a, 0x2f, 0x1e, 0x39, 0x19, 0x2a, 0x06, 0x04, 0x15, 0x23, 0x2e, 0x32, 0x28, 0x13, 0x34,
+ 0x10, 0x0d, 0x3f, 0x1a, 0x37, 0x0f, 0x3e, 0x36, 0x38, 0x02, 0x16, 0x3d, 0x2c, 0x0e, 0x1b, 0x12,
+];
diff --git a/libs/zora-rs/tests/web.rs b/libs/zora-rs/tests/web.rs
index de5c1da..9bed16c 100644
--- a/libs/zora-rs/tests/web.rs
+++ b/libs/zora-rs/tests/web.rs
@@ -1,9 +1,10 @@
//! Test suite for the Web and headless browsers.
-#![cfg(target_arch = "wasm32")]
+#![cfg(target_family = "wasm")]
extern crate wasm_bindgen_test;
use wasm_bindgen_test::*;
+use zora_rs::*;
wasm_bindgen_test_configure!(run_in_browser);