Skip to content

Commit

Permalink
Organized some stuff, fixed a logic bug
Browse files Browse the repository at this point in the history
  • Loading branch information
b1scoito committed Dec 29, 2021
1 parent 772e170 commit 3549395
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 61 deletions.
12 changes: 6 additions & 6 deletions cozinha_loader/cozinha_loader.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ini.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<ClCompile Include="inih\ini.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="inih.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="inih\inih.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="injection.cpp" />
<ClCompile Include="main.cpp" />
Expand All @@ -134,8 +134,8 @@
<ClCompile Include="utils.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ini.h" />
<ClInclude Include="inih.hpp" />
<ClInclude Include="inih\ini.h" />
<ClInclude Include="inih\inih.hpp" />
<ClInclude Include="vac3_data.hpp" />
<ClInclude Include="injection.hpp" />
<ClInclude Include="console.hpp" />
Expand Down
8 changes: 4 additions & 4 deletions cozinha_loader/cozinha_loader.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
<ClCompile Include="memory.cpp">
<Filter>utils\memory</Filter>
</ClCompile>
<ClCompile Include="inih.cpp">
<ClCompile Include="inih\inih.cpp">
<Filter>utils\inih</Filter>
</ClCompile>
<ClCompile Include="ini.c">
<ClCompile Include="inih\ini.c">
<Filter>utils\inih</Filter>
</ClCompile>
</ItemGroup>
Expand All @@ -72,10 +72,10 @@
<ClInclude Include="vars.hpp">
<Filter>utils\global</Filter>
</ClInclude>
<ClInclude Include="inih.hpp">
<ClInclude Include="inih\inih.hpp">
<Filter>utils\inih</Filter>
</ClInclude>
<ClInclude Include="ini.h">
<ClInclude Include="inih\ini.h">
<Filter>utils\inih</Filter>
</ClInclude>
</ItemGroup>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 23 additions & 24 deletions cozinha_loader/injection.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
#include "pch.hpp"
#include "injection.hpp"

bool c_injector::initiaze( const std::filesystem::path dll_path )
bool c_injector::initalize( const std::filesystem::path dll_path )
{
log_debug( L"Closing processes..." );
if ( vars::b_inject_vac_bypass )
{
log_debug( L"Closing processes..." );

// Closing processes
this->close_processes( { string::to_unicode( vars::str_process_name ), L"steam.exe" } );
// Closing processes
this->close_processes( { string::to_unicode( vars::str_process_name ), L"steam.exe" } );

const auto steam_path = util::get_steam_path();
const auto steam_path = util::get_steam_path();

if ( steam_path.empty() )
return failure( L"Failed to get Steam path!" );
if ( steam_path.empty() )
return failure( L"Failed to get Steam path!" );

std::wstring launch_append = {};
log_debug( L"Opening Steam at - %s", steam_path.data() );

if ( vars::b_open_game_automatically )
{
for ( const auto& it : this->vec_app_ids )
std::wstring launch_append = {};
if ( vars::b_open_game_automatically )
{
if ( it.second.find( string::to_unicode( vars::str_process_name ) ) != std::wstring::npos )
launch_append = string::format( L"-applaunch %d", it.first );
for ( const auto& it : this->vec_app_ids )
{
if ( it.second.find( string::to_unicode( vars::str_process_name ) ) != std::wstring::npos )
launch_append = string::format( L"-applaunch %d", it.first );
}
}
}

log_debug( L"Opening steam at - %s", steam_path.data() );

PROCESS_INFORMATION pi; // Could use the current handle instead of closing it for steam, might do it in the future...
if ( !memory::open_process( steam_path, { L"-console", launch_append }, pi ) )
return failure( L"Failed to open Steam!", { pi.hProcess, pi.hThread } );
PROCESS_INFORMATION pi; // Could use the current handle instead of closing it for steam, might do it in the future...
if ( !memory::open_process( steam_path, { L"-console", launch_append }, pi ) )
return failure( L"Failed to open Steam!", { pi.hProcess, pi.hThread } );

CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );

if ( vars::b_inject_vac_bypass )
{
// This won't take long
std::vector<std::uint8_t> vac_buffer( std::begin( vac3_data ), std::end( vac3_data ) );

Expand Down Expand Up @@ -96,7 +95,7 @@ bool c_injector::map( std::wstring_view str_proc, std::wstring_view wstr_mod_nam
{
const auto patch_nt_open_file = [&]()
{
const auto ntdll_path = string::format( L"%s\\ntdll.dll", get_system_directory().data() );
const auto ntdll_path = string::format( L"%s\\ntdll.dll", util::get_system_directory().data() );
const auto ntdll = LoadLibrary( ntdll_path.data() );

if ( !ntdll )
Expand Down
10 changes: 1 addition & 9 deletions cozinha_loader/injection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ const auto failure = []( std::wstring_view str_err, const std::pair<HANDLE, HAND
return false;
};

const auto get_system_directory = []() -> std::wstring
{
wchar_t buf[MAX_PATH];
GetSystemDirectory( buf, sizeof( buf ) / 4 );

return std::wstring( buf );
};

class c_injector
{
private:
Expand All @@ -47,7 +39,7 @@ class c_injector
~c_injector() = default;

// Initialize routine
bool initiaze( const std::filesystem::path dll_path );
bool initalize( const std::filesystem::path dll_path );
};

inline auto g_injector = std::make_unique<c_injector>();
9 changes: 5 additions & 4 deletions cozinha_loader/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "pch.hpp"
#include "injection.hpp"

INT WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd )
INT WINAPI WinMain( _In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine, _In_ int nShowCmd )
{

std::atexit( [] { std::this_thread::sleep_for( 10s ); } );

std::int32_t argc; auto* const argv = CommandLineToArgvW( GetCommandLineW(), &argc );
Expand All @@ -14,7 +15,7 @@ INT WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
return EXIT_FAILURE;
}

const std::filesystem::path dll_path = argv[1] ? argv[1] : L"cheat.dll";
const std::filesystem::path dll_path = argv[1] ? argv[1] : string::to_unicode( vars::str_dll_name );

if ( !std::filesystem::exists( dll_path ) )
{
Expand All @@ -24,7 +25,7 @@ INT WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,

log_debug( L"DLL Path: %s", std::filesystem::absolute( dll_path ).wstring().data() );

if ( !g_injector->initiaze( dll_path ) )
if ( !g_injector->initalize( dll_path ) )
return EXIT_FAILURE;

log_ok( L"Done." );
Expand Down
16 changes: 16 additions & 0 deletions cozinha_loader/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,20 @@ namespace util

return std::wstring( steam_path_reg ) + L"\"";
}

std::wstring get_system_directory()
{
wchar_t buf[MAX_PATH];
GetSystemDirectory( buf, MAX_PATH );

return std::wstring( buf );
}

std::wstring get_executable_path()
{
wchar_t buf[MAX_PATH];
GetModuleFileName( NULL, buf, MAX_PATH );

return std::wstring( buf );
}
}
6 changes: 6 additions & 0 deletions cozinha_loader/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ namespace util

// Returns the steam path from regedit
std::wstring get_steam_path();

// Returns the system directory
std::wstring get_system_directory();

// Returns the current executable path
std::wstring get_executable_path();
}
25 changes: 11 additions & 14 deletions cozinha_loader/vars.hpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
#pragma once

#include "inih.hpp"

const auto get_executable_path = []()
{
char buf[MAX_PATH];
GetModuleFileNameA( NULL, buf, MAX_PATH );
return std::string( buf );
};
#include "inih/inih.hpp"

namespace vars
{
inline std::string str_process_name { "csgo.exe" };
inline bool b_inject_vac_bypass { true };
inline bool b_open_game_automatically { false };
inline std::string str_dll_name { "cheat.dll" };
inline std::string str_steam_mod_name { "tier0_s.dll" };
inline std::string str_process_mod_name { "serverbrowser.dll" };

inline bool b_inject_vac_bypass { true };
inline bool b_open_game_automatically { false };

inline bool get_global_vars()
{
const auto cur_path = std::filesystem::path( get_executable_path() ).parent_path();
const auto cur_path = std::filesystem::path( util::get_executable_path().data() ).parent_path();
std::filesystem::current_path( cur_path );

if ( !std::filesystem::exists( "cozinha_loader.ini" ) )
{
std::ofstream out( "cozinha_loader.ini" );

std::stringstream ss;

// Wow...
std::stringstream ss;
ss << "[launch_options]" << std::endl;
ss << "process_name = csgo.exe" << std::endl;
ss << "dll_name = cheat.dll ; Remembering that a dll can still be drag'n'dropped into the loader, this is here to facilitate faster injections" << std::endl;
ss << "inject_vac_bypass = true" << std::endl;
ss << "open_game_automatically = false" << std::endl;
ss << std::endl;
ss << "[advanced]" << std::endl;
ss << "steam_mod_name = tier0_s.dll" << std::endl;
ss << "process_mod_name = serverbrowser.dll" << std::endl;

out << ss.str();

out.close();
Expand All @@ -54,6 +48,9 @@ namespace vars
if (reader.HasValue( "launch_options", "process_name" ) )
str_process_name = reader.GetString( "launch_options", "process_name", "csgo.exe" );

if (reader.HasValue( "launch_options", "dll_name" ) )
str_dll_name = reader.GetString( "launch_options", "dll_name", "cheat.dll" );

if ( reader.HasValue( "launch_options", "inject_vac_bypass" ) )
b_inject_vac_bypass = reader.GetBoolean( "launch_options", "inject_vac_bypass", true );

Expand Down

0 comments on commit 3549395

Please sign in to comment.