Skip to content

Commit

Permalink
replace libc-stdhandle and fix Pastel on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
RinLovesYou committed Jan 7, 2024
1 parent 74e3380 commit 1c8b9ff
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 33 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion MelonLoader/MelonLoader.Shared/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public static void Startup(string engineModulePath)
MelonEnvironment.Initialize();
MelonLaunchOptions.Load();

Pastel.ConsoleExtensions.Disable();
if (MelonUtils.IsUnderWineOrSteamProton())
Pastel.ConsoleExtensions.Disable();

MelonDebug.Msg("MelonLoader.Core.Startup");

Expand Down
1 change: 0 additions & 1 deletion Rust/MelonBootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ lazy_static = "1.4.0"
libloading = "0.8.1"
dobby-rs = { git = "https://github.com/RinLovesYou/dobby-rs" }
libc = "0.2.150"
libc-stdhandle = "0.1.0"
utf16string = "0.2.0"

[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
31 changes: 12 additions & 19 deletions Rust/MelonBootstrap/src/console/os/windows/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Windows Console Module.
use std::error::Error;
use std::os::windows::io::AsRawHandle;
use std::sync::Mutex;

use lazy_static::lazy_static;
Expand All @@ -16,9 +17,9 @@ use windows::{
use crate::{
console_on_top,
constants::{IS_ALPHA, MELON_VERSION},
debug_enabled,
debug, debug_enabled,
errors::conerr::ConsoleError,
should_set_title, win_str, debug,
should_set_title, win_str,
};

lazy_static! {
Expand Down Expand Up @@ -48,21 +49,14 @@ pub unsafe fn init() -> Result<(), Box<dyn Error>> {
SetWindowPos(*window, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE)?;
}

let _ = libc::freopen(
win_str!(b"CONIN$\0"),
win_str!(b"r\0"),
libc_stdhandle::stdin(),
);
let _ = libc::freopen(
win_str!(b"CONOUT$\0"),
win_str!(b"w\0"),
libc_stdhandle::stdout(),
);
let _ = libc::freopen(
win_str!(b"CONOUT$\0"),
win_str!(b"w\0"),
libc_stdhandle::stderr(),
);
let stdout = std::io::stdout();
let out_handle = stdout.as_raw_handle();
let out_handle = out_handle as isize;
SetStdHandle(STD_OUTPUT_HANDLE, HANDLE(out_handle));
let stderr = std::io::stderr();
let err_handle = stderr.as_raw_handle();
let err_handle = err_handle as isize;
SetStdHandle(STD_ERROR_HANDLE, HANDLE(err_handle));

// needs to be in its own scope to drop the lock
{
Expand All @@ -77,10 +71,9 @@ pub unsafe fn init() -> Result<(), Box<dyn Error>> {
let mut mode = CONSOLE_MODE(0);
let _ = GetConsoleMode(*output_handle, &mut mode);


mode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;

if SetConsoleMode(*output_handle, mode).is_err() {
if SetConsoleMode(*output_handle, mode).is_err() {
mode &= !(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
} else {
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
Expand Down
6 changes: 5 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ def build(target: str):
command = CargoCommand
command = command.replace("--target=", "--target={}".format(targets[target]))
if xwin:
command = command.replace("cargo", "cargo-xwin")
command = command.replace("cargo", "cargo xwin")
if target == "win32":
os.environ["XWIN_ARCH"] = "x86"
os.environ["XWIN_VERSION"] = "17"

print(command)


Expand Down

0 comments on commit 1c8b9ff

Please sign in to comment.