From 092b17870bf9b683c05350deb0f2307683079bea Mon Sep 17 00:00:00 2001 From: rushiiMachine <33725716+rushiiMachine@users.noreply.github.com> Date: Sun, 24 Mar 2024 18:53:11 -0700 Subject: [PATCH] wip: setup c# rust ffi --- .gitignore | 1 + Osu.Patcher.Hook/Hook.cs | 2 + Osu.Patcher.Hook/Osu.Patcher.Hook.csproj | 3 + .../Osu.Patcher.Injector.csproj | 2 +- Osu.Performance.ROsu/.cargo/config.toml | 3 + Osu.Performance.ROsu/Cargo.lock | 16 ++++++ Osu.Performance.ROsu/Cargo.toml | 10 ++++ .../Osu.Performance.ROsu.csproj | 32 +++++++++++ Osu.Performance.ROsu/Test.cs | 11 ++++ Osu.Performance.ROsu/src/lib.rs | 56 +++++++++++++++++++ Osu.Performance/Osu.Performance.csproj | 33 +++++++++++ osu-patcher.sln | 12 ++++ 12 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 Osu.Performance.ROsu/.cargo/config.toml create mode 100644 Osu.Performance.ROsu/Cargo.lock create mode 100644 Osu.Performance.ROsu/Cargo.toml create mode 100644 Osu.Performance.ROsu/Osu.Performance.ROsu.csproj create mode 100644 Osu.Performance.ROsu/Test.cs create mode 100644 Osu.Performance.ROsu/src/lib.rs create mode 100644 Osu.Performance/Osu.Performance.csproj diff --git a/.gitignore b/.gitignore index b190414..604086d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ bin/ obj/ +target/ /packages/ /_ReSharper.Caches/ *.idea diff --git a/Osu.Patcher.Hook/Hook.cs b/Osu.Patcher.Hook/Hook.cs index 37cfc11..8439fa4 100644 --- a/Osu.Patcher.Hook/Hook.cs +++ b/Osu.Patcher.Hook/Hook.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using HarmonyLib; using JetBrains.Annotations; +using Osu.Performance.ROsu; using Osu.Utils; namespace Osu.Patcher.Hook; @@ -22,6 +23,7 @@ public static int Initialize(string _) try { + Console.WriteLine(Test.test()); _harmony = new Harmony("osu!patcher"); InitializePatches(_harmony); diff --git a/Osu.Patcher.Hook/Osu.Patcher.Hook.csproj b/Osu.Patcher.Hook/Osu.Patcher.Hook.csproj index 6e36d73..c3cae83 100644 --- a/Osu.Patcher.Hook/Osu.Patcher.Hook.csproj +++ b/Osu.Patcher.Hook/Osu.Patcher.Hook.csproj @@ -26,6 +26,9 @@ + + TargetFramework=net452 + TargetFramework=net452 diff --git a/Osu.Patcher.Injector/Osu.Patcher.Injector.csproj b/Osu.Patcher.Injector/Osu.Patcher.Injector.csproj index 965c7e6..c9a152a 100644 --- a/Osu.Patcher.Injector/Osu.Patcher.Injector.csproj +++ b/Osu.Patcher.Injector/Osu.Patcher.Injector.csproj @@ -6,7 +6,7 @@ 1.0.0 osu!.patcher Osu.Patcher.Injector - net6.0 + net8.0 12 enable $(NoWarn);NU1702 diff --git a/Osu.Performance.ROsu/.cargo/config.toml b/Osu.Performance.ROsu/.cargo/config.toml new file mode 100644 index 0000000..ddcec02 --- /dev/null +++ b/Osu.Performance.ROsu/.cargo/config.toml @@ -0,0 +1,3 @@ +[build] +# osu! is a 32 bit process and we only support windows +target = "i686-pc-windows-msvc" diff --git a/Osu.Performance.ROsu/Cargo.lock b/Osu.Performance.ROsu/Cargo.lock new file mode 100644 index 0000000..b2f9fbb --- /dev/null +++ b/Osu.Performance.ROsu/Cargo.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "rosu" +version = "0.1.0" +dependencies = [ + "rosu-pp", +] + +[[package]] +name = "rosu-pp" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40f365961f000e9506345a6c57071c23ff983587f24187c0d624bf56a66c1e91" diff --git a/Osu.Performance.ROsu/Cargo.toml b/Osu.Performance.ROsu/Cargo.toml new file mode 100644 index 0000000..b8fb3d3 --- /dev/null +++ b/Osu.Performance.ROsu/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "rosu" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["dylib"] + +[dependencies] +rosu-pp = "0.10.0" diff --git a/Osu.Performance.ROsu/Osu.Performance.ROsu.csproj b/Osu.Performance.ROsu/Osu.Performance.ROsu.csproj new file mode 100644 index 0000000..855cc3e --- /dev/null +++ b/Osu.Performance.ROsu/Osu.Performance.ROsu.csproj @@ -0,0 +1,32 @@ + + + + Library + net452 + + + none + + + + + + + i686-pc-windows-msvc + + + + + + + + + %(Filename)%(Extension) + PreserveNewest + + + + diff --git a/Osu.Performance.ROsu/Test.cs b/Osu.Performance.ROsu/Test.cs new file mode 100644 index 0000000..df5af63 --- /dev/null +++ b/Osu.Performance.ROsu/Test.cs @@ -0,0 +1,11 @@ +using System; +using System.Runtime.InteropServices; + +namespace Osu.Performance.ROsu +{ + public class Test + { + [DllImport("rosu.dll")] + public static extern int test(); + } +} \ No newline at end of file diff --git a/Osu.Performance.ROsu/src/lib.rs b/Osu.Performance.ROsu/src/lib.rs new file mode 100644 index 0000000..aa33412 --- /dev/null +++ b/Osu.Performance.ROsu/src/lib.rs @@ -0,0 +1,56 @@ +use rosu_pp::{Beatmap, OsuPP}; +use rosu_pp::osu::OsuDifficultyAttributes; + +#[repr(C)] +struct _OsuDifficultyAttributes { + aim: f64, + speed: f64, + flashlight: f64, + slider_factor: f64, + speed_note_count: f64, + ar: f64, + od: f64, + hp: f64, + circles: usize, + sliders: usize, + spinners: usize, + stars: f64, + max_combo: usize, +} + +impl From<&_OsuDifficultyAttributes> for OsuDifficultyAttributes { + fn from(value: &_OsuDifficultyAttributes) -> Self { + OsuDifficultyAttributes { + aim: value.aim, + speed: value.speed, + flashlight: value.flashlight, + slider_factor: value.slider_factor, + speed_note_count: value.speed_note_count, + ar: value.ar, + od: value.od, + hp: value.hp, + n_circles: value.circles, + n_sliders: value.sliders, + n_spinners: value.spinners, + stars: value.stars, + max_combo: value.max_combo, + } + } +} + +#[no_mangle] +extern "C" fn test() -> i32 { + 727 +} + +#[no_mangle] +extern "C" fn calculate_osu(difficulty: &_OsuDifficultyAttributes) -> f64 { + let diff: OsuDifficultyAttributes = difficulty.into(); + + return OsuPP::new(&Beatmap::default()) + // https://github.com/MaxOhn/rosu-pp/issues/28#issuecomment-1871814571 + .passed_objects(diff.n_circles + diff.n_sliders + diff.n_spinners) + .attributes(diff) + .calculate() + .pp(); +} diff --git a/Osu.Performance/Osu.Performance.csproj b/Osu.Performance/Osu.Performance.csproj new file mode 100644 index 0000000..712a463 --- /dev/null +++ b/Osu.Performance/Osu.Performance.csproj @@ -0,0 +1,33 @@ + + + + Library + Osu.Performance + osu!.performance + net452 + 12 + enable + + + true + full + false + DEBUG;TRACE + prompt + 4 + + + none + true + TRACE + prompt + 4 + + + + + + TargetFramework=net452 + + + diff --git a/osu-patcher.sln b/osu-patcher.sln index 00b8eaf..e5aaade 100644 --- a/osu-patcher.sln +++ b/osu-patcher.sln @@ -7,6 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Osu.Stubs", "Osu.Stubs\Osu. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Osu.Utils", "Osu.Utils\Osu.Utils.csproj", "{9FA3B15D-8421-4E04-BA84-85331845A01D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Osu.Performance", "Osu.Performance\Osu.Performance.csproj", "{79B81600-142A-4DF7-B1B1-09D18ABE4537}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Osu.Performance.ROsu", "Osu.Performance.ROsu\Osu.Performance.ROsu.csproj", "{E97D5D8F-81D5-4E37-8BE8-5B1DCEDE9A14}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -29,5 +33,13 @@ Global {9FA3B15D-8421-4E04-BA84-85331845A01D}.Debug|x86.Build.0 = Debug|Any CPU {9FA3B15D-8421-4E04-BA84-85331845A01D}.Release|x86.ActiveCfg = Release|Any CPU {9FA3B15D-8421-4E04-BA84-85331845A01D}.Release|x86.Build.0 = Release|Any CPU + {79B81600-142A-4DF7-B1B1-09D18ABE4537}.Debug|x86.ActiveCfg = Debug|Any CPU + {79B81600-142A-4DF7-B1B1-09D18ABE4537}.Debug|x86.Build.0 = Debug|Any CPU + {79B81600-142A-4DF7-B1B1-09D18ABE4537}.Release|x86.ActiveCfg = Release|Any CPU + {79B81600-142A-4DF7-B1B1-09D18ABE4537}.Release|x86.Build.0 = Release|Any CPU + {E97D5D8F-81D5-4E37-8BE8-5B1DCEDE9A14}.Debug|x86.ActiveCfg = Debug|Any CPU + {E97D5D8F-81D5-4E37-8BE8-5B1DCEDE9A14}.Debug|x86.Build.0 = Debug|Any CPU + {E97D5D8F-81D5-4E37-8BE8-5B1DCEDE9A14}.Release|x86.ActiveCfg = Release|Any CPU + {E97D5D8F-81D5-4E37-8BE8-5B1DCEDE9A14}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection EndGlobal