@@ -5,15 +5,19 @@ use core::{
55 api:: { create_http_client, read_client_identity} ,
66 reqwest:: { Client , Identity } ,
77} ;
8+ use hudhook:: { hooks:: dx9:: ImguiDx9Hooks , Hudhook } ;
89use log:: error;
910use pocket_relay_client_shared as core;
1011use std:: path:: Path ;
1112use ui:: { confirm_message, error_message} ;
1213use windows_sys:: Win32 :: System :: SystemServices :: { DLL_PROCESS_ATTACH , DLL_PROCESS_DETACH } ;
1314
15+ use crate :: overlay:: OverlayRenderLoop ;
16+
1417pub mod config;
1518pub mod game;
1619pub mod hooks;
20+ pub mod overlay;
1721pub mod servers;
1822pub mod threads;
1923pub mod ui;
@@ -23,9 +27,9 @@ pub mod update;
2327pub const APP_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
2428
2529/// Handles the plugin being attached to the game
26- fn attach ( ) {
30+ fn attach ( hmodule : isize ) {
2731 // Suspend all game threads so the user has a chance to connect to a server
28- threads:: suspend_all_threads ( ) ;
32+ // threads::suspend_all_threads();
2933
3034 // Debug allocates a console window to display output
3135 #[ cfg( debug_assertions) ]
@@ -54,10 +58,30 @@ fn attach() {
5458 // Create the internal HTTP client
5559 let client: Client = create_http_client ( identity) . expect ( "Failed to create HTTP client" ) ;
5660
57- std:: thread:: spawn ( || {
58- // Initialize the UI
59- ui:: init ( config, client) ;
61+ std:: thread:: spawn ( move || {
62+ // Create tokio async runtime
63+ let runtime = tokio:: runtime:: Builder :: new_multi_thread ( )
64+ . enable_all ( )
65+ . build ( )
66+ . expect ( "Failed building tokio runtime" ) ;
67+
68+ // Spawn the updating task
69+ runtime. spawn ( update:: update ( client. clone ( ) ) ) ;
70+
71+ if let Err ( e) = Hudhook :: builder ( )
72+ . with :: < ImguiDx9Hooks > ( OverlayRenderLoop :: new ( runtime, config, client) )
73+ . with_hmodule ( hudhook:: windows:: Win32 :: Foundation :: HINSTANCE ( hmodule) )
74+ . build ( )
75+ . apply ( )
76+ {
77+ error ! ( "Couldn't apply hooks: {e:?}" ) ;
78+ }
6079 } ) ;
80+
81+ // std::thread::spawn(|| {
82+ // // Initialize the UI
83+ // ui::init(config, client);
84+ // });
6185}
6286
6387/// Handles the plugin being detached from the game, this handles
@@ -99,10 +123,10 @@ fn load_identity() -> Option<Identity> {
99123/// Windows DLL entrypoint for the plugin
100124#[ no_mangle]
101125#[ allow( non_snake_case) ]
102- extern "stdcall" fn DllMain ( _hmodule : isize , reason : u32 , _: * mut ( ) ) -> bool {
126+ extern "stdcall" fn DllMain ( hmodule : isize , reason : u32 , _: * mut ( ) ) -> bool {
103127 match reason {
104128 // Handle attaching
105- DLL_PROCESS_ATTACH => attach ( ) ,
129+ DLL_PROCESS_ATTACH => attach ( hmodule ) ,
106130 // Handle detaching
107131 DLL_PROCESS_DETACH => detach ( ) ,
108132 _ => { }
0 commit comments