Run Minecraft: runtime HLE, D3D12.X device on the host GPU, shader IR

Loader: map title-shipped DLLs, patch static TLS loads to slot 0, crash
reporter, title paths for GetModuleFileName*.

HLE: task queue and async, XUser (one offline user), system ids,
title id, features, invites, game events, persistent local storage,
GameInput with no devices, xmem, console audio hardware queues, life
cycle (close suspends, then terminates), and a file layer with virtual
drives rewritten in path-taking imports.

GPU: D3D12.X device, DXGI chain, heaps, resources, fences, queues and
command lists translated onto a host D3D12 device; clears, barriers,
copies, resolves and PresentX into the title's window.

Shaders: SGD5 reader and `victory translate`; SSA IR with node
splitting for irreducible flow; structurisation removing EXEC.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MarvisandClaude Opus 5.5 committed 2026-11-23 14:42:21 +01:00
1 parent 12caefe804
commit 754619f30e
61 files changed
+12775 -88

No files matched your search

+87
View File
@@ -1,5 +1,7 @@
//! Process-wide state the implementations need.
use std::path::{Path, PathBuf};
use std::sync::Mutex;
use std::sync::atomic::{AtomicUsize, Ordering};
static MAIN_IMAGE_BASE: AtomicUsize = AtomicUsize::new(0);
@@ -16,3 +18,88 @@ pub fn main_image() -> Option<usize> {
base => Some(base),
}
}
/// Original file of each title image we mapped, by base address.
static IMAGE_PATHS: Mutex<Vec<(usize, PathBuf)>> = Mutex::new(Vec::new());
/// Records the file a title image was mapped from: the title asks for its
/// own path (`GetModuleFileName`) to find its data, and must not get our
/// cache copy.
pub fn set_image_path(base: usize, path: &Path) {
let path = std::path::absolute(path).unwrap_or_else(|_| path.to_owned());
let mut paths = IMAGE_PATHS.lock().unwrap_or_else(|e| e.into_inner());
paths.retain(|(b, _)| *b != base);
paths.push((base, path));
}
pub fn image_path(base: usize) -> Option<PathBuf> {
let paths = IMAGE_PATHS.lock().unwrap_or_else(|e| e.into_inner());
paths
.iter()
.find(|(b, _)| *b == base)
.map(|(_, p)| p.clone())
}
/// What the title's manifest (`MicrosoftGame.config` beside its executable)
/// says about it, and where its persistent local storage lives.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Title {
pub id: u32,
/// Persistent local storage: our folder for it and the title's quota.
pub storage: PathBuf,
pub storage_bytes: u64,
}
impl Title {
/// Title id and storage quota from the manifest's text (zero where it
/// has none); the storage folder is left for the caller to choose.
// shortcut: finds the two elements by text, not as XML; parse properly
// once more of the manifest is needed.
pub fn from_manifest(text: &str) -> Title {
fn element<'a>(text: &'a str, tag: &str) -> Option<&'a str> {
let start = text.find(&format!("<{tag}>"))? + tag.len() + 2;
let len = text[start..].find('<')?;
Some(text[start..start + len].trim())
}
let id = element(text, "TitleId").and_then(|v| u32::from_str_radix(v, 16).ok());
let storage_mb = text
.find("<PersistentLocalStorage>")
.and_then(|at| element(&text[at..], "SizeMB"))
.and_then(|v| v.parse::<u64>().ok());
Title {
id: id.unwrap_or(0),
storage: PathBuf::new(),
storage_bytes: storage_mb.unwrap_or(0) << 20,
}
}
}
static TITLE: Mutex<Option<Title>> = Mutex::new(None);
pub fn set_title(title: Title) {
*TITLE.lock().unwrap_or_else(|e| e.into_inner()) = Some(title);
}
/// The running title; the default (id 0, no storage) until set.
pub fn title() -> Title {
TITLE
.lock()
.unwrap_or_else(|e| e.into_inner())
.clone()
.unwrap_or_default()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn reads_title_id_and_storage_quota() {
let text = "<Game><Identity Name=\"x\"/>\n <TitleId>639AA8DD</TitleId>\n\
<PersistentLocalStorage>\n <SizeMB>1024</SizeMB> <!-- c -->\n\
</PersistentLocalStorage></Game>";
let t = Title::from_manifest(text);
assert_eq!((t.id, t.storage_bytes), (0x639A_A8DD, 1024 << 20));
assert_eq!(Title::from_manifest("").storage_bytes, 0);
}
}