Skip to content

Commit 73cbcb8

Browse files
committed
initial code commit
1 parent f0dbd71 commit 73cbcb8

79 files changed

Lines changed: 6304 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[submodule "vendor/fmt"]
2+
path = vendor/fmt
3+
url = https://github.com/fmtlib/fmt.git
4+
[submodule "vendor/imgui"]
5+
path = vendor/imgui
6+
url = https://github.com/ocornut/imgui.git
7+
[submodule "vendor/minhook"]
8+
path = vendor/minhook
9+
url = https://github.com/TsudaKageyu/minhook.git

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1.0.0
2+
- Initial Version

CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(ts-extra-utilities VERSION 1.0.0)
3+
4+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
5+
6+
file(GLOB_RECURSE ${CMAKE_PROJECT_NAME}-src src/*.hpp src/*.cpp)
7+
8+
set(PLUGIN_VERSION_MAJOR 1)
9+
set(PLUGIN_VERSION_MINOR 0)
10+
set(PLUGIN_VERSION_PATCH 0)
11+
12+
configure_file(
13+
${CMAKE_CURRENT_SOURCE_DIR}/version.hpp.in
14+
${CMAKE_CURRENT_SOURCE_DIR}/src/version.hpp
15+
)
16+
17+
configure_file(
18+
${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in
19+
${CMAKE_CURRENT_BINARY_DIR}/version.rc
20+
)
21+
22+
foreach(_source IN ITEMS ${${CMAKE_PROJECT_NAME}-src})
23+
get_filename_component(_source_path "${_source}" PATH)
24+
string(REPLACE "${CMAKE_SOURCE_DIR}" "" _group_path "${_source_path}")
25+
string(REPLACE "/" "\\" _group_path "${_group_path}")
26+
source_group("${_group_path}" FILES "${_source}")
27+
endforeach()
28+
29+
add_library(${CMAKE_PROJECT_NAME} SHARED ${${CMAKE_PROJECT_NAME}-src} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
30+
31+
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE TS_EXTRA_UTILITIES_DLL_EXPORTS UNICODE _UNICODE)
32+
33+
target_compile_features(${CMAKE_PROJECT_NAME} PUBLIC cxx_std_17)
34+
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
35+
36+
add_subdirectory(vendor)
37+
38+
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE src vendor/scs_sdk/include vendor/imgui vendor/minhook/include)
39+
40+
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE fmt::fmt-header-only imgui minhook)

CMakeSettings.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "x64-Debug",
5+
"generator": "Visual Studio 17 2022 Win64",
6+
"configurationType": "Debug",
7+
"inheritEnvironments": [
8+
"msvc_x64_x64"
9+
],
10+
"buildRoot": "${projectDir}\\build\\${name}"
11+
},
12+
{
13+
"name": "x64-Release",
14+
"generator": "Visual Studio 17 2022 Win64",
15+
"configurationType": "Release",
16+
"inheritEnvironments": [
17+
"msvc_x64_x64"
18+
],
19+
"buildRoot": "${projectDir}\\build\\${name}"
20+
}
21+
]
22+
}

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# ts-extra-utilities
2+
3+
> [!WARNING]
4+
> This is more of a PoC(Proof of Concept) and very much WIP(Work In Progress), it is not extensively tested or in any way a stable finished product.
5+
> If you decide to use this, expect possible issues / crashes (especially after game updates)
6+
7+
A plugin for ATS/ETS2 to add some experimental extra functionality.
8+
9+
## Current features
10+
11+
- Manually steerable trailer wheels
12+
- Abilty to take control of the steerable wheels on a trailer
13+
14+
[Preview video](https://youtu.be/0kRavShaXy0)
15+
16+
- Individually detachable trailers
17+
- Ability to disconnect and connect trailers individually and out of order
18+
- Still has multiple issues when trailers are disconnected, trailer cables, 3rd person camera, ...
19+
20+
[Preview video](https://youtu.be/Nu6YvKKSL2g)
21+
22+
- Lockable trailer joints (PhysX only, `-physx` as a game launch parameter in Steam)
23+
- Ability to lock the joints between vehicle and trailers so you can stop them from pivoting
24+
25+
[Preview video](https://youtu.be/zXtlzMVNEXM)
26+
27+
## How to use
28+
29+
Currently only works with DirectX11.
30+
31+
Made for singleplayer, **NOT** recommended in multiplayer.
32+
33+
34+
Download the [latest release](https://github.com/dariowouters/ts-extra-utilities/releases/latest), copy the `ts-extra-utilities.dll` to `<game_install_location>/bin/win_x64/plugins`
35+
(if the plugins folder does not exists, you can create one)
36+
37+
Then in-game you can toggle the UI with `delete` and `insert` to toggle the cursor.
38+
(Keybinds are currently hardcoded, will make it changable at some point.)

src/consts.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#include "version.hpp"
4+
5+
namespace ts_extra_utilities
6+
{
7+
}

src/core.cpp

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
#include "core.hpp"
2+
3+
#include <MinHook.h>
4+
5+
#include "consts.hpp"
6+
7+
#include "backends/imgui_impl_dx11.h"
8+
#include "backends/imgui_impl_win32.h"
9+
#include "memory/memory_utils.hpp"
10+
11+
#include "managers/window_manager.hpp"
12+
#include "windows/trailer_manipulation.hpp"
13+
14+
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler( HWND, UINT, WPARAM, LPARAM );
15+
16+
namespace ts_extra_utilities
17+
{
18+
CCore* CCore::g_instance = nullptr;
19+
20+
CCore::CCore( const scs_telemetry_init_params_v101_t* init_params ) : init_params_( init_params )
21+
{
22+
this->hooks_manager_ = new CHooksManager();
23+
this->window_manager_ = new CWindowManager();
24+
scs_log_ = init_params->common.log;
25+
g_instance = this;
26+
}
27+
28+
CCore::~CCore()
29+
{
30+
this->destroy();
31+
MH_RemoveHook( nullptr );
32+
}
33+
34+
bool CCore::init()
35+
{
36+
MH_Initialize();
37+
this->info( "Initializing {}", VERSION );
38+
truckersmp_ = GetModuleHandle( L"core_ets2mp.dll" ) != nullptr || GetModuleHandle( L"core_atsmp.dll" ) != nullptr;
39+
40+
this->dx11_hook = new CDirectX11Hook();
41+
if ( !this->dx11_hook->hook_present() )
42+
{
43+
return false;
44+
}
45+
this->di8_hook = new CDirectInput8Hook();
46+
if ( !this->di8_hook->hook() )
47+
{
48+
return false;
49+
}
50+
51+
const auto trailer_manipulation = this->window_manager_->register_window( std::make_shared< CTrailerManipulation >() );
52+
53+
if ( !trailer_manipulation->init() )
54+
{
55+
g_instance->error( "Could not initialize the trailer manipulation module" );
56+
}
57+
58+
return true;
59+
}
60+
61+
void CCore::destroy()
62+
{
63+
delete this->dx11_hook;
64+
delete this->di8_hook;
65+
delete this->hooks_manager_;
66+
delete this->window_manager_;
67+
}
68+
69+
bool CCore::on_mouse_input( LPDIDEVICEOBJECTDATA rgdod )
70+
{
71+
if ( !this->disable_in_game_mouse ) return false;
72+
73+
auto& io = ImGui::GetIO();
74+
if ( rgdod->dwOfs == DIMOFS_X )
75+
{
76+
io.MousePos.x += static_cast< float >( static_cast< int >( rgdod->dwData ) );
77+
}
78+
else if ( rgdod->dwOfs == DIMOFS_Y )
79+
{
80+
io.MousePos.y += static_cast< float >( static_cast< int >( rgdod->dwData ) );
81+
}
82+
83+
return true;
84+
}
85+
86+
bool CCore::render()
87+
{
88+
ImGui_ImplDX11_NewFrame();
89+
ImGui_ImplWin32_NewFrame();
90+
ImGui::NewFrame();
91+
92+
if ( this->render_ui )
93+
{
94+
#ifdef _DEBUG
95+
bool s = true;
96+
ImGui::ShowDemoWindow( &s );
97+
#endif
98+
this->window_manager_->render();
99+
}
100+
ImGui::EndFrame();
101+
ImGui::Render();
102+
ImGui_ImplDX11_RenderDrawData( ImGui::GetDrawData() );
103+
return true;
104+
}
105+
106+
void CCore::toggle_input_hook()
107+
{
108+
this->disable_in_game_mouse = !this->disable_in_game_mouse;
109+
auto& io = ImGui::GetIO();
110+
if ( this->disable_in_game_mouse )
111+
{
112+
io.MousePos.x = last_mouse_pos_x_;
113+
io.MousePos.y = last_mouse_pos_y_;
114+
}
115+
else
116+
{
117+
last_mouse_pos_x_ = io.MousePos.x;
118+
last_mouse_pos_y_ = io.MousePos.y;
119+
}
120+
121+
io.MouseDrawCursor = this->disable_in_game_mouse;
122+
123+
this->debug( "Mouse hook is now {}", this->disable_in_game_mouse ? "active" : "disabled" );
124+
}
125+
126+
void CCore::toggle_ui()
127+
{
128+
this->render_ui = !this->render_ui;
129+
}
130+
131+
// TODO: add keybind settings
132+
bool CCore::on_wnd_proc( HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam )
133+
{
134+
if ( umsg == WM_KEYDOWN )
135+
{
136+
if ( wparam == VK_INSERT )
137+
{
138+
toggle_input_hook();
139+
return true;
140+
}
141+
if ( wparam == VK_DELETE )
142+
{
143+
toggle_ui();
144+
return true;
145+
}
146+
}
147+
else if ( umsg == WM_MOUSEMOVE )
148+
{
149+
if ( this->disable_in_game_mouse )
150+
{
151+
return true;
152+
}
153+
}
154+
155+
if ( ImGui_ImplWin32_WndProcHandler( hwnd, umsg, wparam, lparam ) )
156+
{
157+
return true;
158+
}
159+
return false;
160+
}
161+
162+
prism::base_ctrl_u* CCore::get_base_ctrl_instance()
163+
{
164+
if ( this->base_ctrl_instance_ptr_address != 0 ) return *reinterpret_cast< prism::base_ctrl_u** >( this->base_ctrl_instance_ptr_address );
165+
166+
const auto addr = memory::get_address_for_pattern( "48 8b 05 ? ? ? ? 48 8b 4b ? 48 8b 80 ? ? ? ? 48 8b b9" );
167+
168+
if ( addr == 0 ) return nullptr;
169+
this->base_ctrl_instance_ptr_address = addr + *reinterpret_cast< int32_t* >( addr + 3 ) + 7;
170+
this->game_actor_offset_in_base_ctrl = *reinterpret_cast< int32_t* >( addr + 14 );
171+
172+
this->info( "Found base_ctrl @ +{:x}", memory::as_offset( this->base_ctrl_instance_ptr_address ) );
173+
174+
return *reinterpret_cast< prism::base_ctrl_u** >( this->base_ctrl_instance_ptr_address );
175+
}
176+
177+
prism::game_actor_u* CCore::get_game_actor()
178+
{
179+
auto* base_ctrl = this->get_base_ctrl_instance();
180+
181+
if ( base_ctrl == nullptr || this->game_actor_offset_in_base_ctrl == 0 )
182+
{
183+
return nullptr;
184+
}
185+
186+
return *reinterpret_cast< prism::game_actor_u** >( reinterpret_cast< uint64_t >( base_ctrl ) + this->game_actor_offset_in_base_ctrl );
187+
}
188+
}

0 commit comments

Comments
 (0)