- Статус
- Оффлайн
- Регистрация
- 26 Авг 2023
- Сообщения
- 587
- Реакции
- 60
хотел сделать консоль для своего проекта, столкнулся с данной проблемой, если кто шарит прошу помочь :)
проблема в том что консоль с нужным title создается, но текст hello world просто напросто не появляется
C++:
void MainConsole() {
// Выделяем новую консоль
AllocConsole();
// Перенаправляем стандартный вывод в новую консоль
FILE* stream;
freopen_s(&stream, "CONOUT$", "w", stdout);
// Устанавливаем заголовок окна консоли
SetConsoleTitleA("test");
// Выводим сообщение в консоль
std::cout << "Hello, World!" << std::endl;
// Ожидаем нажатия клавиши перед закрытием программы
system("pause");
}
C++:
BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
///инициализация консоли
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)MainConsole, NULL, NULL, NULL);
///основной код (не касается вопроса)
if (const auto tier0 = GetModuleHandleA("tier0.dll"); tier0)
{
if (const auto ConMsgExport = GetProcAddress(tier0, "?ConMsg@@YAXPEBDZZ"); ConMsgExport)
{
_ConMsg = reinterpret_cast<T_ConMsg>(ConMsgExport);
CMSG("Hello world!\n");
std::cout << "Hello, World!" << std::endl;
if (const auto client_dll = GetModuleHandleA("client.dll"); client_dll)
{
MODULEINFO out_modinfo{};
if (!K32GetModuleInformation(GetCurrentProcess(), client_dll, &out_modinfo, sizeof(MODULEINFO)))
CMSG("K32GetModuleInformation fail: %u\n", GetLastError());
else
{
const char masks[]{ "xxx????xx????xxx????xxx" };
const auto entitysystem_xref =
sigscan_naive((const std::uint8_t*)client_dll, out_modinfo.SizeOfImage,
(const std::uint8_t*)"\x48\x8d\x0d????\xff\x15????\x48\x8b\x0d????\x33\xd2\xe8",
std::size(masks) - 1,
masks);
if (!entitysystem_xref)
CMSG("entitysystem_xref not found!\n");
else
{
const auto mov_insn_ptr = entitysystem_xref + 0xD;
const auto rel32 = *(std::int32_t*)(mov_insn_ptr + 0x3);
const auto entity_system_ptr = (void**)(mov_insn_ptr + 0x7 + rel32);
const auto entitysystem = *entity_system_ptr;
if (!entitysystem)
CMSG("entitysystem not created yet\n");
else
{
CMSG("entitysystem: 0x%p\n", entitysystem);
if (const auto engine_dll = GetModuleHandleA("engine2.dll"); engine_dll)
{
if (const auto Engine_CIProc = GetProcAddress(engine_dll, "CreateInterface"); Engine_CIProc)
{
const auto engineclient
= CreateInterface(reinterpret_cast<T_CreateInterface>(Engine_CIProc),
"Source2EngineToClient001");
if (engineclient)
{
CMSG("CEngineClient: 0x%p\n", engineclient);
if (const auto engine_vftable = *reinterpret_cast<void***>(engineclient);
engine_vftable)
{
using T_GetLocalPlayerID = void(*)(void* self_engineclient, int* out_result, int splitscreenslot);
const auto GetLocalPlayerID
= reinterpret_cast<T_GetLocalPlayerID>(engine_vftable[29]);
if (GetLocalPlayerID)
{
int playerID = 0;
GetLocalPlayerID(engineclient, &playerID, 0);
if (playerID >= 0)
{
const auto player_controller_entity_ID = playerID + 1;
CMSG("Local player id: %d\n", playerID);
CMSG("Local player entity id: %d\n", player_controller_entity_ID);
constexpr auto ENTITY_SYSTEM_LIST_SIZE = 512;
constexpr auto ENTITY_SYSTEM_LIST_COUNT = 64;
constexpr auto indexMask = (ENTITY_SYSTEM_LIST_COUNT * ENTITY_SYSTEM_LIST_SIZE) - 1;
const auto _GetEntityByIndex = [entitysystem](std::size_t index) -> void*
{
const auto entitysystem_lists = (const void**)((char*)entitysystem + 0x10);
const auto list =
entitysystem_lists[index / ENTITY_SYSTEM_LIST_SIZE];
if (list)
{
const auto entry_index = index % ENTITY_SYSTEM_LIST_SIZE;
constexpr auto sizeof_CEntityIdentity = 0x78;
const auto identity = (char*)list + entry_index * sizeof_CEntityIdentity;
if (identity)
{
return *(void**)identity;
}
}
return nullptr;
};
const auto local_player_controller = _GetEntityByIndex(player_controller_entity_ID);
CMSG("local_player_controller: 0x%p\n", local_player_controller);
if (local_player_controller)
{
const auto handle_m_hAssignedHero = *(std::uint32_t*)
((char*)local_player_controller + offset_m_hAssignedHero);
const auto index_m_hAssignedHero = handle_m_hAssignedHero & indexMask;
CMSG("index_m_hAssignedHero: %u\n", index_m_hAssignedHero);
const auto local_hero = _GetEntityByIndex(index_m_hAssignedHero);
CMSG("local_hero: 0x%p\n", local_hero);
if (local_hero)
{
CMSG("hp: %d\n", *(int*)((char*)local_hero + offset_m_iHealth));
CMSG("team num: %d\n", *(int*)((char*)local_hero + offset_m_iTeamNum));
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return TRUE;
}
проблема в том что консоль с нужным title создается, но текст hello world просто напросто не появляется
Последнее редактирование: