Skip to content

Commit

Permalink
Merge pull request #602 from LavaGang/alpha-development
Browse files Browse the repository at this point in the history
MelonLoader v0.6.2
  • Loading branch information
RinLovesYou authored Jan 9, 2024
2 parents b2de0ed + ca74c51 commit 18a726e
Show file tree
Hide file tree
Showing 58 changed files with 3,085 additions and 1,218 deletions.
168 changes: 77 additions & 91 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,148 +8,134 @@ on:
workflow_dispatch:

jobs:
build_core_debug:
build_melonloader:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: setup-msbuild
- name: Setup MsBuild
uses: microsoft/setup-msbuild@v1
- name: Build Melonloader Core
shell: cmd
run: msbuild /restore /p:Platform="Windows - x64" # Platform is actually irrelevant for core, it's compiled as AnyCPU either way
- name: Upload core artifact
uses: actions/upload-artifact@v3
with:
name: MLCoreDebug
path: Output/Debug/MelonLoader/
build_core_release:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: setup-msbuild
uses: microsoft/setup-msbuild@v1
- name: Build Melonloader Core
- name: Build Melonloader (Release)
shell: cmd
run: msbuild /restore /p:Configuration=Release /p:Platform="Windows - x64"
- name: Upload core artifact
- name: Build MelonLoader (Debug)
shell: cmd
run: msbuild /restore /p:Platform="Windows - x64"
- name: Upload Release Artifact
uses: actions/upload-artifact@v3
with:
name: MLCoreRelease
path: Output/Release/MelonLoader/
build_rust_windows:
runs-on: windows-latest
- name: Upload Debug Artifact
uses: actions/upload-artifact@v3
with:
name: MLCoreDebug
path: Output/Debug/MelonLoader/
build_rust:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: rust-toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
# Target triple to install for this toolchain
targets: i686-pc-windows-msvc, x86_64-pc-windows-msvc
# Build Rust Release
- name: Build Rust Release | Windows - x86
shell: cmd
run: cargo +nightly build --target i686-pc-windows-msvc --release
- name: Install Rust (nightly)
run:
curl https://sh.rustup.rs -sSf | sh -s -- -y
- name: Make Rust Nightly
shell: bash
run: rustup default nightly
- name: Install Linux target x64
shell: bash
run: rustup target add x86_64-unknown-linux-gnu
- name: Install Windows target x64
shell: bash
run: rustup target add x86_64-pc-windows-msvc
- name: Install Windows target x86
shell: bash
run: rustup target add i686-pc-windows-msvc
- name: Install x-win
shell: bash
run: cargo install cargo-xwin
- name: install dev dependencies
shell: bash
run: sudo apt-get install libgtk-3-dev wine llvm
- name: Build Rust Release | Linux - x64
shell: bash
run: cargo build --target x86_64-unknown-linux-gnu --release
- name: Build Rust Debug | Linux - x64
shell: bash
run: cargo build --target x86_64-unknown-linux-gnu
- name: Build Rust Release | Windows - x64
shell: cmd
run: cargo +nightly build --target x86_64-pc-windows-msvc --release
# Build Rust Debug
- name: Build Rust Debug | Windows - x86
shell: cmd
run: cargo +nightly build --target i686-pc-windows-msvc
shell: bash
run: cargo xwin build --target x86_64-pc-windows-msvc --release
- name: Build Rust Debug | Windows - x64
shell: cmd
run: cargo +nightly build --target x86_64-pc-windows-msvc
# Upload Proxy Release - x86
shell: bash
run: cargo xwin build --target x86_64-pc-windows-msvc
- name: Build Rust Release | Windows - x86
shell: bash
run: XWIN_ARCH=x86 cargo xwin build --target i686-pc-windows-msvc --release
- name: Build Rust Debug | Windows - x86
shell: bash
run: XWIN_ARCH=x86 cargo xwin build --target i686-pc-windows-msvc
- name: Upload Proxy Release | Linux x64
uses: actions/upload-artifact@v3
with:
name: MLProxyX64-Linux-Release
path: target/x86_64-unknown-linux-gnu/release/libversion.so
- name: Upload Bootstrap Release | Linux x64
uses: actions/upload-artifact@v3
with:
name: MLBootstrapX64-Linux-Release
path: target/x86_64-unknown-linux-gnu/release/libBootstrap.so
- name: Upload Proxy Debug | Linux x64
uses: actions/upload-artifact@v3
with:
name: MLProxyX64-Linux-Debug
path: target/x86_64-unknown-linux-gnu/debug/libversion.so
- name: Upload Bootstrap Debug | Linux x64
uses: actions/upload-artifact@v3
with:
name: MLBootstrapX64-Linux-Debug
path: target/x86_64-unknown-linux-gnu/debug/libBootstrap.so
- name: Upload Proxy Release | Windows x86
uses: actions/upload-artifact@v3
with:
name: MLProxyX86-Windows-Release
path: target/i686-pc-windows-msvc/release/version.dll
# Upload Bootstrap Release - x86
- name: Upload Bootstrap Release | Windows x86
uses: actions/upload-artifact@v3
with:
name: MLBootstrapX86-Windows-Release
path: target/i686-pc-windows-msvc/release/Bootstrap.dll
# Upload Proxy Release - x64
- name: Upload Proxy Release | Windows x64
uses: actions/upload-artifact@v3
with:
name: MLProxyX64-Windows-Release
path: target/x86_64-pc-windows-msvc/release/version.dll
# Upload Bootstrap Release - x64
- name: Upload Bootstrap Release | Windows x64
uses: actions/upload-artifact@v3
with:
name: MLBootstrapX64-Windows-Release
path: target/x86_64-pc-windows-msvc/release/Bootstrap.dll
# Upload Proxy Debug - x86
- name: Upload Proxy Debug | Windows x86
uses: actions/upload-artifact@v3
with:
name: MLProxyX86-Windows-Debug
path: target/i686-pc-windows-msvc/debug/version.dll
# Upload Bootstrap Debug - x86
- name: Upload Bootstrap Debug | Windows x86
uses: actions/upload-artifact@v3
with:
name: MLBootstrapX86-Windows-Debug
path: target/i686-pc-windows-msvc/debug/Bootstrap.dll
# Upload Proxy Debug - x64
- name: Upload Proxy Debug | Windows x64
uses: actions/upload-artifact@v3
with:
name: MLProxyX64-Windows-Debug
path: target/x86_64-pc-windows-msvc/debug/version.dll
# Upload Bootstrap Debug - x64
- name: Upload Bootstrap Debug | Windows x64
uses: actions/upload-artifact@v3
with:
name: MLBootstrapX64-Windows-Debug
path: target/x86_64-pc-windows-msvc/debug/Bootstrap.dll
build_rust_linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: rust-toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
# Target triple to install for this toolchain
targets: x86_64-unknown-linux-gnu
- name: install dev dependencies
shell: bash
run: sudo apt-get install libgtk-3-dev
- name: Build Rust Release | Linux - x64
shell: bash
run: cargo +nightly build --target x86_64-unknown-linux-gnu --release
- name: Build Rust Debug | Linux - x64
shell: bash
run: cargo +nightly build --target x86_64-unknown-linux-gnu
- name: Upload Proxy Release | Linux x64
uses: actions/upload-artifact@v3
with:
name: MLProxyX64-Linux-Release
path: target/x86_64-unknown-linux-gnu/release/libversion.so
- name: Upload Bootstrap Release | Linux x64
uses: actions/upload-artifact@v3
with:
name: MLBootstrapX64-Linux-Release
path: target/x86_64-unknown-linux-gnu/release/libBootstrap.so
- name: Upload Proxy Debug | Linux x64
uses: actions/upload-artifact@v3
with:
name: MLProxyX64-Linux-Debug
path: target/x86_64-unknown-linux-gnu/debug/libversion.so
- name: Upload Bootstrap Debug | Linux x64
uses: actions/upload-artifact@v3
with:
name: MLBootstrapX64-Linux-Debug
path: target/x86_64-unknown-linux-gnu/debug/libBootstrap.so
finalize_x64_debug_zip_windows:
runs-on: windows-latest
needs: [build_core_debug, build_rust_windows]
needs: [build_rust, build_melonloader]
steps:
- uses: actions/checkout@v3
- name: Download core artifact
Expand Down Expand Up @@ -191,7 +177,7 @@ jobs:
path: ./Output/Debug/x64/*
finalize_x86_debug_zip_windows:
runs-on: windows-latest
needs: [build_core_debug, build_rust_windows]
needs: [build_rust, build_melonloader]
steps:
- uses: actions/checkout@v3
- name: Download core artifact
Expand Down Expand Up @@ -233,7 +219,7 @@ jobs:
path: ./Output/Debug/x86/*
finalize_x64_release_zip_windows:
runs-on: windows-latest
needs: [build_core_release, build_rust_windows]
needs: [build_rust, build_melonloader]
steps:
- uses: actions/checkout@v3
- name: Download core artifact
Expand Down Expand Up @@ -275,7 +261,7 @@ jobs:
path: ./Output/Release/x64/*
finalize_x86_release_zip_windows:
runs-on: windows-latest
needs: [build_core_release, build_rust_windows]
needs: [build_rust, build_melonloader]
steps:
- uses: actions/checkout@v3
- name: Download core artifact
Expand Down Expand Up @@ -317,7 +303,7 @@ jobs:
path: ./Output/Release/x86/*
finalize_x64_debug_zip_linux:
runs-on: windows-latest
needs: [build_core_debug, build_rust_linux]
needs: [build_rust, build_melonloader]
steps:
- uses: actions/checkout@v3
- name: Download core artifact
Expand Down Expand Up @@ -356,7 +342,7 @@ jobs:
path: ./Output/Debug/x64/*
finalize_x64_release_zip_linux:
runs-on: windows-latest
needs: [build_core_release, build_rust_linux]
needs: [build_rust, build_melonloader]
steps:
- uses: actions/checkout@v3
- name: Download core artifact
Expand Down
Binary file modified BaseLibs/Managed/UnityEngine.Il2CppAssetBundleManager.dll
Binary file not shown.
7 changes: 4 additions & 3 deletions Bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
#unity-rs = { path = "C:/Users/sarah/Documents/rust/Ferrex/unity/" }
unity-rs = { git = "https://github.com/RinLovesYou/Ferrex/", rev = "77d114c" }
ctor = "0.1.26"
ctor = "0.2.6"
chrono = "0.4.23"
colored = "2.0.0"
thiserror = "1.0.39"
Expand All @@ -18,10 +18,11 @@ clap = { git = "https://github.com/RinLovesYou/clap", features = ["derive"] }
libc = "0.2.140"
dobby-rs = { git = "https://github.com/RinLovesYou/dobby-rs" }
libc-stdhandle = "0.1.0"
netcorehost = "0.13.1"
netcorehost = "0.15.1"
exe = "0.5.6"

[target.'cfg(windows)'.dependencies]
windows = { version = "0.46.0", features = [
windows = { version = "0.52.0", features = [
"Win32_Foundation",
"Win32_System_Console",
"Win32_UI_WindowsAndMessaging"
Expand Down
18 changes: 10 additions & 8 deletions Bootstrap/src/base_assembly/mono.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
use std::{ptr::null_mut, sync::Mutex};
use std::{ptr::null_mut, sync::{RwLock, Mutex}};

use lazy_static::lazy_static;
use unity_rs::{
common::{assembly::UnityAssembly, method::UnityMethod},
runtime::FerrexRuntime,
};

use crate::{debug, errors::DynErr, melonenv, runtime};
use crate::{debug, errors::DynErr, melonenv::{self, paths}, runtime};

lazy_static! {
pub static ref MONO_PRESTART: Mutex<UnityMethod> =
Mutex::new(UnityMethod { inner: null_mut() });
pub static ref MONO_START: Mutex<UnityMethod> = Mutex::new(UnityMethod { inner: null_mut() });
pub static ref ASSEMBLYMANAGER_RESOLVE: Mutex<UnityMethod> =
Mutex::new(UnityMethod { inner: null_mut() });
pub static ref ASSEMBLYMANAGER_LOADINFO: Mutex<UnityMethod> =
Mutex::new(UnityMethod { inner: null_mut() });
pub static ref ASSEMBLYMANAGER_RESOLVE: RwLock<UnityMethod> =
RwLock::new(UnityMethod { inner: null_mut() });
pub static ref ASSEMBLYMANAGER_LOADINFO: RwLock<UnityMethod> =
RwLock::new(UnityMethod { inner: null_mut() });
}

pub fn init(runtime: &FerrexRuntime) -> Result<(), DynErr> {
preload(runtime)?;

debug!("Initializing BaseAssembly")?;

let _runtime_dir = paths::runtime_dir()?;

//get MelonLoader.dll's path and confirm it exists
let mut melonloader_dll = melonenv::paths::MELONLOADER_FOLDER.clone();
melonloader_dll.extend(&["net35", "MelonLoader.dll"]);
Expand Down Expand Up @@ -52,8 +54,8 @@ pub fn init(runtime: &FerrexRuntime) -> Result<(), DynErr> {
//store the methods for later, in a thread safe global static.
*MONO_PRESTART.try_lock()? = prestart_method;
*MONO_START.try_lock()? = start_method;
*ASSEMBLYMANAGER_RESOLVE.try_lock()? = resolve_method;
*ASSEMBLYMANAGER_LOADINFO.try_lock()? = loadinfo_method;
*ASSEMBLYMANAGER_RESOLVE.try_write()? = resolve_method;
*ASSEMBLYMANAGER_LOADINFO.try_write()? = loadinfo_method;

//invoke the MelonLoader initialize method.
let _ = initialize_method.invoke(None, None, runtime)?;
Expand Down
10 changes: 4 additions & 6 deletions Bootstrap/src/console/os/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ lazy_static! {

pub unsafe fn init() -> Result<(), DynErr> {
// creates a console window, if one already exists it'll just return true.
if !AllocConsole().as_bool() {
return Err(ConsoleError::FailedToAllocateConsole.into());
}
AllocConsole()?;

// store the console window handle
let mut window = WINDOW.try_lock()?;
Expand All @@ -39,7 +37,7 @@ pub unsafe fn init() -> Result<(), DynErr> {
}

// this lets us hook into console close events, and run some cleanup logic.
if SetConsoleCtrlHandler(Some(ctrl_handler_hook), Foundation::TRUE) == Foundation::FALSE {
if SetConsoleCtrlHandler(Some(ctrl_handler_hook), Foundation::TRUE).is_err() {
return Err(ConsoleError::FailedToSetConsoleCtrlHandler.into());
}

Expand Down Expand Up @@ -80,12 +78,12 @@ pub unsafe fn init() -> Result<(), DynErr> {

mode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;

if SetConsoleMode(*output_handle, mode) != Foundation::TRUE {
if SetConsoleMode(*output_handle, mode).is_err() {
mode &= !(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
} else {
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;

if SetConsoleMode(*output_handle, mode) != Foundation::TRUE {
if SetConsoleMode(*output_handle, mode).is_err() {
mode &= !ENABLE_VIRTUAL_TERMINAL_PROCESSING;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Bootstrap/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub type InvokeFnIl2Cpp = extern "C" fn(
pub type InitFnMono = extern "C" fn(*const c_char, *const c_char) -> *mut MonoDomain;
pub type InitFnIl2Cpp = extern "C" fn(*const c_char) -> *mut Il2CppDomain;

pub const MELON_VERSION: &str = "0.6.1";
pub const MELON_VERSION: &str = "0.6.2";

pub const IS_ALPHA: bool = false;

Expand Down
4 changes: 2 additions & 2 deletions Bootstrap/src/icalls/resolve_internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn assembly_resolve(
) -> Result<*mut MonoAssembly, DynErr> {
let runtime = runtime!()?;

let resolve_method = base_assembly::mono::ASSEMBLYMANAGER_RESOLVE.try_lock()?;
let resolve_method = base_assembly::mono::ASSEMBLYMANAGER_RESOLVE.try_read()?;

if resolve_method.inner.is_null() {
return Err("AssemblyManager.Resolve is null".into());
Expand Down Expand Up @@ -90,7 +90,7 @@ fn load_hook_inner(assembly: *mut MonoAssembly) -> Result<(), DynErr> {
return Ok(());
}

let load_method = base_assembly::mono::ASSEMBLYMANAGER_LOADINFO.try_lock()?;
let load_method = base_assembly::mono::ASSEMBLYMANAGER_LOADINFO.try_read()?;
if load_method.inner.is_null() {
return Ok(());
}
Expand Down
Loading

0 comments on commit 18a726e

Please sign in to comment.