Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lcdr committed Dec 12, 2020
0 parents commit bc73e2e
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
target = "i686-pc-windows-msvc"
rustflags = ["-C", "link-args=/debug:none"]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/*
30 changes: 30 additions & 0 deletions Cargo.lock

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

18 changes: 18 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "mod"
version = "0.1.0"
authors = ["lcdr"]
edition = "2018"
description = "A mod to change LU's UI scale."
readme = "README.md"
license = "AGPL-3.0-or-later"
repository = "https://github.com/lcdr/ui_scaler/"

[dependencies]
winapi = { version = "0.3.9", features = ["libloaderapi", "memoryapi"] }

[lib]
crate-type = ["cdylib"]

[profile.release]
lto = true
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
A mod to change LU's UI scale.

# Installation:

If you haven't installed my modloader yet, install it from https://github.com/lcdr/mod_loader/releases/, following the instructions there.

Download this mod from https://github.com/lcdr/ui_scaler/releases/, following the instructions there.

# Usage:

Open your client's boot.cfg file and add a new config entry named `UI_SCALE` with type 3 (float) and the scaling factor as the value, e.g. append `,UI_SCALE=3:2.0` to the file for x2 scaling.
30 changes: 30 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
mod patch;
mod scale_ui;
use scale_ui::patch_ui_scale;

use winapi::{
shared::minwindef::{BOOL, DWORD, HINSTANCE, LPVOID, TRUE},
um::libloaderapi::GetModuleHandleA,
};

static mut BASE: usize = 0;

#[no_mangle]
pub extern "system" fn DllMain(
_dll_module: HINSTANCE,
call_reason: DWORD,
_reserved: LPVOID)
-> BOOL {
const DLL_PROCESS_ATTACH: DWORD = 1;

match call_reason {
DLL_PROCESS_ATTACH => init(),
_ => TRUE
}
}

fn init() -> BOOL {
unsafe { BASE = GetModuleHandleA(std::ptr::null()) as usize; }
patch_ui_scale();
TRUE
}
15 changes: 15 additions & 0 deletions src/patch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use winapi::shared::minwindef::{DWORD, LPVOID};
use winapi::um::memoryapi::VirtualProtect;
use winapi::um::winnt::PAGE_EXECUTE_READWRITE;

use crate::BASE;

pub fn patch<T>(dst: usize, new: T) {
unsafe {
let dst = (dst + BASE) as LPVOID;
let mut old_protect: DWORD = PAGE_EXECUTE_READWRITE;
VirtualProtect(dst, std::mem::size_of::<T>(), PAGE_EXECUTE_READWRITE, &mut old_protect);
*(dst as *mut T) = new;
VirtualProtect(dst, std::mem::size_of::<T>(), old_protect, &mut old_protect);
}
}
22 changes: 22 additions & 0 deletions src/scale_ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::fs::read_to_string;

use crate::patch::patch;

const VIEWPORT_HEIGHT_OFFSET: usize = 0x7939ce;
const VIEWPORT_HEIGHT_VALUE: usize = 0x7939d2;

pub fn patch_ui_scale() {
let lnv = read_to_string("boot.cfg").expect("could not open boot.cfg");

for name_value in lnv.split(",") {
let name_value = name_value.trim();
let (name, value) = name_value.split_at(name_value.find(":").expect(&format!("malformed boot.cfg entry, colon missing: {}", name_value))+1);

if name == "UI_SCALE=3:" {
let scale: f32 = value.parse().expect(&format!("could not parse boot.cfg UI_SCALE value as float: {}", value));
let scale = 1.0 / scale;
patch(VIEWPORT_HEIGHT_OFFSET, 0x00_00_01_50_u32);
patch(VIEWPORT_HEIGHT_VALUE, scale);
}
}
}

0 comments on commit bc73e2e

Please sign in to comment.