#include <cstdio>
#include <iostream>
#include <string>
#include <windows.h>
#include "IL2CPP_Resolver.hpp"
#include "includes.h"
#include <fcntl.h>
extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

Present oPresent;
HWND window = NULL;
WNDPROC oWndProc;
ID3D11Device* pDevice = NULL;
ID3D11DeviceContext* pContext = NULL;
ID3D11RenderTargetView* mainRenderTargetView;
#define WIN32_LEAN_AND_MEAN

void InitImGui()
{
    ImGui::CreateContext();
    ImGuiIO& io = ImGui::GetIO();
    io.ConfigFlags = ImGuiConfigFlags_NoMouseCursorChange;
    ImGui_ImplWin32_Init(window);
    ImGui_ImplDX11_Init(pDevice, pContext);
}

void CreateConsole()
{
    if (!AllocConsole()) {
        // Add some error handling here.
        // You can call GetLastError() to get more info about the error.
        return;
    }

    // std::cout, std::clog, std::cerr, std::cin
    FILE* fDummy;
    freopen_s(&fDummy, "CONOUT$", "w", stdout);
    freopen_s(&fDummy, "CONOUT$", "w", stderr);
    freopen_s(&fDummy, "CONIN$", "r", stdin);
    std::cout.clear();
    std::clog.clear();
    std::cerr.clear();
    std::cin.clear();
};

bool opened_menu = false;
LPVOID crMd = NULL;


float HandPosX = 0;
float HandPosY = 0;
float HandPosZ = 0;

float HandRotX = 0;
float HandRotY = 0;
float HandRotZ = 0;

float HandSclX = 1;
float HandSclY = 1;
float HandSclZ = 1;

void ExitLib()
{
    FreeLibraryAndExitThread((HMODULE)crMd, 0);
}




LRESULT __stdcall WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {

    if (true && ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam))
        return true;

    return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam);
}

int currentTab = 0;
bool init = false;

static bool alpha_preview = true;
static bool alpha_half_preview = false;
static bool drag_and_drop = true;
static bool options_menu = true;
static bool hdr = false;
ImGuiColorEditFlags misc_flags = (hdr ? ImGuiColorEditFlags_HDR : 0) | (drag_and_drop ? 0 : ImGuiColorEditFlags_NoDragDrop) | (alpha_half_preview ? ImGuiColorEditFlags_AlphaPreviewHalf : (alpha_preview ? ImGuiColorEditFlags_AlphaPreview : 0)) | (options_menu ? 0 : ImGuiColorEditFlags_NoOptions);

bool IsUnlocked = false;

const ImVec4 color = ImVec4(255.0f, 255.0f, 255.0f, 255.0f);

bool ColorPicker = false;


Unity::CGameObject* local_player;
Unity::CGameObject* _FOG;

//noflash
Unity::CGameObject* _FLASH;
Unity::CGameObject* _BLUR;
//noHpGain
Unity::CGameObject* _BLOODBLUR;

//gloves
Unity::CGameObject* _CHAOSHANDS;
Unity::CGameObject* _GUARDHANDS;
Unity::CGameObject* _NTFHANDS;
Unity::CGameObject* _OTHERHANDS;
//viewmodel hands
Unity::CTransform* HandsTransform;
Unity::CTransform* ViewModelCam;
//cameras
Unity::CGameObject* _VIEWMODEL;
Unity::CGameObject* _CameraPivot;
//exploit spectracker
Unity::CGameObject* _spectracker;

bool bigstep = false;
bool nofog = false;
bool noflash = false;
bool nobloodblur = false;

bool ImguiRendering = true;
bool AutoUpdate = true;

float cameraOffset = 3;

bool IsAltPressed() {
    // GetAsyncKeyState возвращает состояние клавиши
    // VK_MENU - это виртуальный код клавиши Alt
    return GetAsyncKeyState(VK_MENU) & 0x8000;
}

HRESULT __stdcall hkPresent(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags)
{
    if (!init)
    {
        if (SUCCEEDED(pSwapChain->GetDevice(__uuidof(ID3D11Device), (void**)& pDevice)))
        {
            pDevice->GetImmediateContext(&pContext);
            DXGI_SWAP_CHAIN_DESC sd;
            pSwapChain->GetDesc(&sd);
            window = sd.OutputWindow;
            ID3D11Texture2D* pBackBuffer;
            pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)& pBackBuffer);
            pDevice->CreateRenderTargetView(pBackBuffer, NULL, &mainRenderTargetView);
            pBackBuffer->Release();
            oWndProc = (WNDPROC)SetWindowLongPtr(window, GWLP_WNDPROC, (LONG_PTR)WndProc);
            InitImGui();
            init = true;
        }

        else
            return oPresent(pSwapChain, SyncInterval, Flags);
    }
    
    ImGui_ImplDX11_NewFrame();
    ImGui_ImplWin32_NewFrame();
    ImGui::NewFrame();
    ImGuiStyle& mStyle = ImGui::GetStyle();
    mStyle.WindowMinSize        = ImVec2( 160, 20 );
    mStyle.FramePadding         = ImVec2( 4, 2 );
    mStyle.ItemSpacing          = ImVec2( 6, 2 );
    mStyle.ItemInnerSpacing     = ImVec2( 6, 4 );
    mStyle.Alpha                = 0.95f;
    mStyle.WindowRounding       = 4.0f;
    mStyle.FrameRounding        = 2.0f;
    mStyle.IndentSpacing        = 6.0f;
    mStyle.ItemInnerSpacing     = ImVec2( 2, 4 );
    mStyle.ColumnsMinSpacing    = 50.0f;
    mStyle.GrabMinSize          = 14.0f;
    mStyle.GrabRounding         = 16.0f;
    mStyle.ScrollbarSize        = 12.0f;
    mStyle.ScrollbarRounding    = 16.0f;
    ImGuiStyle& style = mStyle;
    style.Colors[ImGuiCol_Text]                  = ImVec4(0.86f, 0.93f, 0.89f, 0.78f);
    style.Colors[ImGuiCol_TextDisabled]          = ImVec4(0.86f, 0.93f, 0.89f, 0.28f);
    style.Colors[ImGuiCol_WindowBg]              = ImVec4(0.13f, 0.14f, 0.17f, 1.00f);
    style.Colors[ImGuiCol_Border]                = ImVec4(0.31f, 0.31f, 1.00f, 0.00f);
    style.Colors[ImGuiCol_BorderShadow]          = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
    style.Colors[ImGuiCol_FrameBg]               = ImVec4(0.20f, 0.22f, 0.27f, 1.00f);
    style.Colors[ImGuiCol_FrameBgHovered]        = ImVec4(0.92f, 0.18f, 0.29f, 0.78f);
    style.Colors[ImGuiCol_FrameBgActive]         = ImVec4(0.92f, 0.18f, 0.29f, 1.00f);
    style.Colors[ImGuiCol_TitleBg]               = ImVec4(0.20f, 0.22f, 0.27f, 1.00f);
    style.Colors[ImGuiCol_TitleBgCollapsed]      = ImVec4(0.20f, 0.22f, 0.27f, 0.75f);
    style.Colors[ImGuiCol_TitleBgActive]         = ImVec4(0.92f, 0.18f, 0.29f, 1.00f);
    style.Colors[ImGuiCol_MenuBarBg]             = ImVec4(0.20f, 0.22f, 0.27f, 0.47f);
    style.Colors[ImGuiCol_ScrollbarBg]           = ImVec4(0.20f, 0.22f, 0.27f, 1.00f);
    style.Colors[ImGuiCol_ScrollbarGrab]         = ImVec4(0.09f, 0.15f, 0.16f, 1.00f);
    style.Colors[ImGuiCol_ScrollbarGrabHovered]  = ImVec4(0.92f, 0.18f, 0.29f, 0.78f);
    style.Colors[ImGuiCol_ScrollbarGrabActive]   = ImVec4(0.92f, 0.18f, 0.29f, 1.00f);
    style.Colors[ImGuiCol_CheckMark]             = ImVec4(0.71f, 0.22f, 0.27f, 1.00f);
    style.Colors[ImGuiCol_SliderGrab]            = ImVec4(0.47f, 0.77f, 0.83f, 0.14f);
    style.Colors[ImGuiCol_SliderGrabActive]      = ImVec4(0.92f, 0.18f, 0.29f, 1.00f);
    style.Colors[ImGuiCol_Button]                = ImVec4(0.47f, 0.77f, 0.83f, 0.14f);
    style.Colors[ImGuiCol_ButtonHovered]         = ImVec4(0.92f, 0.18f, 0.29f, 0.86f);
    style.Colors[ImGuiCol_ButtonActive]          = ImVec4(0.92f, 0.18f, 0.29f, 1.00f);
    style.Colors[ImGuiCol_Header]                = ImVec4(0.92f, 0.18f, 0.29f, 0.76f);
    style.Colors[ImGuiCol_HeaderHovered]         = ImVec4(0.92f, 0.18f, 0.29f, 0.86f);
    style.Colors[ImGuiCol_HeaderActive]          = ImVec4(0.92f, 0.18f, 0.29f, 1.00f);
    style.Colors[ImGuiCol_Separator]             = ImVec4(0.14f, 0.16f, 0.19f, 1.00f);
    style.Colors[ImGuiCol_SeparatorHovered]      = ImVec4(0.92f, 0.18f, 0.29f, 0.78f);
    style.Colors[ImGuiCol_SeparatorActive]       = ImVec4(0.92f, 0.18f, 0.29f, 1.00f);
    style.Colors[ImGuiCol_ResizeGrip]            = ImVec4(0.47f, 0.77f, 0.83f, 0.04f);
    style.Colors[ImGuiCol_ResizeGripHovered]     = ImVec4(0.92f, 0.18f, 0.29f, 0.78f);
    style.Colors[ImGuiCol_ResizeGripActive]      = ImVec4(0.92f, 0.18f, 0.29f, 1.00f);
    style.Colors[ImGuiCol_PlotLines]             = ImVec4(0.86f, 0.93f, 0.89f, 0.63f);
    style.Colors[ImGuiCol_PlotLinesHovered]      = ImVec4(0.92f, 0.18f, 0.29f, 1.00f);
    style.Colors[ImGuiCol_PlotHistogram]         = ImVec4(0.86f, 0.93f, 0.89f, 0.63f);
    style.Colors[ImGuiCol_PlotHistogramHovered]  = ImVec4(0.92f, 0.18f, 0.29f, 1.00f);
    style.Colors[ImGuiCol_TextSelectedBg]        = ImVec4(0.92f, 0.18f, 0.29f, 0.43f);
    style.Colors[ImGuiCol_PopupBg]               = ImVec4(0.20f, 0.22f, 0.27f, 0.9f);
    style.Colors[ImGuiCol_ModalWindowDarkening]  = ImVec4(0.20f, 0.22f, 0.27f, 0.73f);

    if (ImguiRendering)
    {
        ImGui::SetNextWindowSize(ImVec2(861, 763));
        ImGui::Begin("SkinChanger" , NULL ,ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar);

        ImGui::SetCursorPos(ImVec2(10,25));
        if(ImGui::Button("Hand Skins", ImVec2(120,40)))
        {
            currentTab = 0;
        }
        ImGui::SetCursorPos(ImVec2(10,25*3));
        if(ImGui::Button("Gun Skins", ImVec2(120,40)))
        {
            currentTab = 1;
        }
        ImGui::SetCursorPos(ImVec2(10,25*5));
        if(ImGui::Button("Effects", ImVec2(120,40)))
        {
            currentTab = 2;
        }
        ImGui::SetCursorPos(ImVec2(10,25*7));
        if(ImGui::Button("Player Model", ImVec2(120,40)))
        {
            currentTab = 3;
        }
        ImGui::SetCursorPos(ImVec2(10,25*9));
        if(ImGui::Button("Camera", ImVec2(120,40)))
        {
            currentTab = 4;
        }
        ImGui::SetCursorPos(ImVec2(10,25*11));
        if(ImGui::Button("Exploits", ImVec2(120,40)))
        {
            currentTab = 5;
        }        
        ImGui::SetCursorPos(ImVec2(10,25*13));
        if(ImGui::Button("Crosshair", ImVec2(120,40)))
        {
            currentTab = 6;
        }
        if (currentTab == 0)
        {
            if (IsUnlocked)
            {
                ImGui::SetCursorPos(ImVec2(135,25));
                ImGui::SliderFloat("Hands Pos X", &HandPosX, -10, 10);
                ImGui::SetCursorPos(ImVec2(135,25*2));
                ImGui::SliderFloat("Hands Pos Y", &HandPosY, -10, 10);
                ImGui::SetCursorPos(ImVec2(135,25*3));
                ImGui::SliderFloat("Hands Pos Z", &HandPosZ, -10, 10);
                ImGui::SetCursorPos(ImVec2(135,25*4));
        
                // ImGui::SetCursorPos(ImVec2(135,25*5));
                // ImGui::SliderFloat("Hands Rot X", &HandRotX, 0, 360);
                // ImGui::SetCursorPos(ImVec2(135,25*6));
                // ImGui::SliderFloat("Hands Rot Y", &HandRotY, 0, 360);
                // ImGui::SetCursorPos(ImVec2(135,25*7));
                // ImGui::SliderFloat("Hands Rot Z", &HandRotZ, 0, 360);
                // ImGui::SetCursorPos(ImVec2(135,25*8));
        
                ImGui::SetCursorPos(ImVec2(135,25*5));
                ImGui::SliderFloat("Hands Scale X", &HandSclX, -10, 10);
                ImGui::SetCursorPos(ImVec2(135,25*6));
                ImGui::SliderFloat("Hands Scale Y", &HandSclY, -10, 10);
                ImGui::SetCursorPos(ImVec2(135,25*7));
                ImGui::SliderFloat("Hands Scale Z", &HandSclZ, -10, 10);
                ImGui::SetCursorPos(ImVec2(135,25*8));
            }
            else
            {
                ImGui::SetCursorPos(ImVec2(135,25));
                ImGui::SliderFloat("Hands Pos X", &HandPosX, -0.2, 0.2);
                ImGui::SetCursorPos(ImVec2(135,25*2));
                ImGui::SliderFloat("Hands Pos Y", &HandPosY, -0.2, 0.2);
                ImGui::SetCursorPos(ImVec2(135,25*3));
                ImGui::SliderFloat("Hands Pos Z", &HandPosZ, -0.2, 0.2);
                ImGui::SetCursorPos(ImVec2(135,25*4));
        
                // ImGui::SetCursorPos(ImVec2(135,25*5));
                // ImGui::SliderFloat("Hands Rot X", &HandRotX, 0, 360);
                // ImGui::SetCursorPos(ImVec2(135,25*6));
                // ImGui::SliderFloat("Hands Rot Y", &HandRotY, 0, 360);
                // ImGui::SetCursorPos(ImVec2(135,25*7));
                // ImGui::SliderFloat("Hands Rot Z", &HandRotZ, 0, 360);
                // ImGui::SetCursorPos(ImVec2(135,25*8));
        
                ImGui::SetCursorPos(ImVec2(135,25*5));
                ImGui::SliderFloat("Hands Scale X", &HandSclX, -1, 1);
                ImGui::SetCursorPos(ImVec2(135,25*6));
                ImGui::SliderFloat("Hands Scale Y", &HandSclY, -1, 1);
                ImGui::SetCursorPos(ImVec2(135,25*7));
                ImGui::SliderFloat("Hands Scale Z", &HandSclZ, -1, 1);
            }
            ImGui::SetCursorPos(ImVec2(135,25*8));
            ImGui::Checkbox("Unlock", &IsUnlocked);
            ImGui::SetCursorPos(ImVec2(135,25*9));
            ImGui::Checkbox("Auto Update", &AutoUpdate);
            ImGui::SetCursorPos(ImVec2(135,25*10));
            if(ImGui::Button("Save Hands", ImVec2(100,20)))
            {
                Unity::CTransform* HandsTransform = Unity::GameObject::Find("Main Camera Controller/Default Camera/All Cameras/ViewmodelCamera/Item Workspace")->GetTransform();
                Unity::CTransform* ViewModelCam = Unity::GameObject::Find("Main Camera Controller/Default Camera/All Cameras/ViewmodelCamera")->GetTransform();
                HandsTransform->SetLocalPosition(Unity::Vector3(HandPosX,HandPosY,HandPosZ));
                // HandsTransform->SetRotation(toQuaternion(HandRotX,HandRotY,HandRotZ));
                ViewModelCam->SetLocalScale(Unity::Vector3(HandSclX,HandSclY,HandSclZ));
            }
            if (AutoUpdate)
            {
                if (Unity::GameObject::FindWithTag("Player")->m_uMaxLength)
                {
                    if (local_player != nullptr) {
                        Unity::GameObject::Find("Main Camera Controller/Default Camera/All Cameras/ViewmodelCamera/Item Workspace")->GetTransform()->SetLocalPosition(Unity::Vector3(HandPosX,HandPosY,HandPosZ));
                        Unity::GameObject::Find("Main Camera Controller/Default Camera/All Cameras/ViewmodelCamera")->GetTransform()->SetLocalScale(Unity::Vector3(HandSclX,HandSclY,HandSclZ));
                    }
                }
            }
        }
        else if (currentTab == 1)
        {
            ImGui::SetCursorPos(ImVec2(135,25));
            if (ImGui::ColorButton("##current", color, ImGuiColorEditFlags_AlphaPreviewHalf, ImVec2(60, 40)))
            {
                ColorPicker = !ColorPicker;
            }
            if (ColorPicker)
            {
                ImGui::BeginChild("##MainChild", ImVec2{ 370.0f, 370.0f }, true); {
                    ImGui::ColorPicker4("##picker", (float*)&color, misc_flags | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoSmallPreview | ImGuiColorEditFlags_PickerHueWheel);
                } ImGui::EndChild();
            }
            
            ImGui::SetCursorPos(ImVec2(135,25*4));
            if(ImGui::Button("Save Colors MkaFl", ImVec2(100,20)))
            {
                Unity::Color UcolorM4 = Unity::Color(color.x,color.y,color.z,1);
                Unity::GameObject::Find("Main Camera Controller/Default Camera/All Cameras/ViewmodelCamera/Item Workspace/E11SR(Clone)/E11SRViewmodel(Clone)/PivotPoint/Anims/Armature/root/main/_Attachments/Flashlight Spot Light")->GetComponent("Light")->SetPropertyValue("color",UcolorM4);
            }
            
        }
        else if (currentTab == 2)
        {
            ImGui::SetCursorPos(ImVec2(135,25*1));
            ImGui::Checkbox("BigStep", &bigstep);
            ImGui::SetCursorPos(ImVec2(135,25*2));
            ImGui::Checkbox("NoFog", &nofog);
            ImGui::SetCursorPos(ImVec2(135,25*3));
            ImGui::Checkbox("NoFlash", &noflash);
            ImGui::SetCursorPos(ImVec2(135,25*4));
            ImGui::Checkbox("Normal Hp Colors", &nobloodblur);
            ImGui::SetCursorPos(ImVec2(135,25*6));
            if(ImGui::Button("SAVE", ImVec2(100,20)))
            {
                if (local_player != nullptr)
                {
                    if (bigstep)
                    {
                        local_player->GetComponent("CharacterController")->SetPropertyValue("stepOffset", static_cast<float>(2));
                    }
                    else
                    {
                        local_player->GetComponent("CharacterController")->SetPropertyValue("stepOffset", static_cast<float>(0.22));
                    }
                    _FOG->SetActive(!nofog);
                    _FLASH->SetActive(!noflash);
                    _BLUR->SetActive(!noflash);
                    _BLOODBLUR->SetActive(!nobloodblur);
                }
            }
        }
        else if (currentTab == 3)
        {
            ImGui::SetCursorPos(ImVec2(135,25));
            if(ImGui::Button("GetPlayer", ImVec2(100,20)))
            {
                if (Unity::GameObject::FindWithTag("Player")->m_uMaxLength) {
                    Unity::il2cppArray<Unity::CGameObject*>* m_pObjects = Unity::GameObject::FindWithTag("Player");
                    Unity::Vector3 CameraPos = Unity::GameObject::Find("Main Camera Controller/Default Camera")->GetTransform()->GetPosition();
                    // Looping through list
                    for (uintptr_t u = 0; m_pObjects->m_uMaxLength > u; ++u)
                    {
                        Unity::CGameObject* m_pObject = m_pObjects->At(u);
                        std::string _name = m_pObject->GetName()->ToString().c_str();
                        Unity::Vector3 _pos = m_pObject->GetTransform()->GetPosition();
                        // printf_s("[*] GM pos finded: %s | %s | %s\n", std::to_string(_pos.x).c_str(), std::to_string(_pos.y).c_str(), std::to_string(_pos.z).c_str());
                        // printf_s("[*] MC pos finded: %s | %s | %s\n", std::to_string(CameraPos.x).c_str(), std::to_string(CameraPos.y).c_str(), std::to_string(CameraPos.z).c_str());
            
                        if (round(_pos.x) == round(CameraPos.x))
                        {
                            if (round(_pos.z) == round(CameraPos.z))
                            {
                                local_player = m_pObject;
                                
                                _FOG = Unity::GameObject::Find("GameManager/Graphics/FogController");
                                _BLOODBLUR = Unity::GameObject::Find("GameManager/Graphics/BloodEffectsSystem");

                                _FLASH = local_player->GetTransform()->GetChild(0)->GetChild(4)->GetPropertyValue<Unity::CGameObject*>("gameObject");
                                _BLUR = local_player->GetTransform()->GetChild(0)->GetChild(14)->GetPropertyValue<Unity::CGameObject*>("gameObject");

                                _VIEWMODEL = Unity::GameObject::Find("Main Camera Controller/Default Camera/All Cameras/ViewmodelCamera/Item Workspace/")->GetTransform()->GetChild(0)->GetPropertyValue<Unity::CGameObject*>("gameObject");
                                _CameraPivot = local_player->GetTransform()->GetChild(1)->GetPropertyValue<Unity::CGameObject*>("gameObject");
                                
                                _CHAOSHANDS = _VIEWMODEL->GetTransform()->GetChild(1)->GetPropertyValue<Unity::CGameObject*>("gameObject");
                                _GUARDHANDS = _VIEWMODEL->GetTransform()->GetChild(2)->GetPropertyValue<Unity::CGameObject*>("gameObject");
                                _NTFHANDS = _VIEWMODEL->GetTransform()->GetChild(3)->GetPropertyValue<Unity::CGameObject*>("gameObject");
                                _OTHERHANDS = _VIEWMODEL->GetTransform()->GetChild(4)->GetPropertyValue<Unity::CGameObject*>("gameObject");
                                
                                printf_s("\n[*] Finded LocalPlayer: %s\n", _name.c_str());
                                printf_s("\n[*] GM pos finded: %s | %s | %s\n", std::to_string(_pos.x).c_str(), std::to_string(_pos.y).c_str(), std::to_string(_pos.z).c_str());
                            }
                        }
                        // printf_s("[*] GM name finded: %s\n", _name.c_str());
                    }
                } else {printf_s(u8"Player models not found");}
            }
            if (Unity::GameObject::FindWithTag("Player")->m_uMaxLength)
            {
                ImGui::SetCursorPos(ImVec2(135,25*2));
                if(ImGui::Button("Chaos Hands", ImVec2(100,20)))
                {
                    _GUARDHANDS->SetActive(false);
                    _NTFHANDS->SetActive(false);
                    _CHAOSHANDS->SetActive(false);
                    _OTHERHANDS->SetActive(false);
                    _CHAOSHANDS->SetActive(!_CHAOSHANDS->GetActive());
                }
                ImGui::SetCursorPos(ImVec2(135,25*3));
                if(ImGui::Button("Guard Hands", ImVec2(100,20)))
                {
                    _GUARDHANDS->SetActive(false);
                    _NTFHANDS->SetActive(false);
                    _CHAOSHANDS->SetActive(false);
                    _OTHERHANDS->SetActive(false);
                    _GUARDHANDS->SetActive(true);
                }
                ImGui::SetCursorPos(ImVec2(135,25*4));
                if(ImGui::Button("NFT Hands", ImVec2(100,20)))
                {
                    _GUARDHANDS->SetActive(false);
                    _NTFHANDS->SetActive(false);
                    _CHAOSHANDS->SetActive(false);
                    _OTHERHANDS->SetActive(false);
                    _NTFHANDS->SetActive(true);
                }
                ImGui::SetCursorPos(ImVec2(135,25*5));
                if(ImGui::Button("No Hands", ImVec2(100,20)))
                {
                    _GUARDHANDS->SetActive(false);
                    _NTFHANDS->SetActive(false);
                    _CHAOSHANDS->SetActive(false);
                    _OTHERHANDS->SetActive(false);
                    _OTHERHANDS->SetActive(true);
                }
            }
        }
        else if (currentTab == 4)
        {
            ImGui::SetCursorPos(ImVec2(135,25));
            ImGui::SliderFloat("Alt Camera Offset", &cameraOffset, -10, 10);
        }
        else if (currentTab == 5)
        {
            ImGui::SetCursorPos(ImVec2(135,25));
            if(ImGui::Button("Find SpecTracker", ImVec2(100,20)))
            {
                _spectracker = Unity::GameObject::Find("Spectator Tracker(Clone)");
            }
            ImGui::SetCursorPos(ImVec2(135,25*2));
            if(ImGui::Button("Swap SpecTracker", ImVec2(100,20)))
            {
                _spectracker->SetActive(!_spectracker->GetActive());
            }
            ImGui::SetCursorPos(ImVec2(135,25*3));
            if(ImGui::Button("Clean Inventory", ImVec2(100,20)))
            {
                local_player->GetComponent("Inventory")->CallMethodSafe<char>("CmdDropItem", 81, false);
            }
        }
        else if (currentTab == 6)
        {
            
        }
    }
    
    
    

    ImGui::End();
    ImGui::Render();
    
    pContext->OMSetRenderTargets(1, &mainRenderTargetView, NULL);
    ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
    return oPresent(pSwapChain, SyncInterval, Flags);
}


DWORD WINAPI MainThread(LPVOID lpReserved)
{
    CreateConsole();
    SetConsoleTitleA("SkinChanger SCP:SL");
    printf_s("[*] Allocated Console\n");
    printf_s("[*] Initializing Il2Cpp\n");
    IL2CPP::Initialize();
    printf_s("[*] Ok\n");
    bool init_hook = false;
    do
    {
        if (kiero::init(kiero::RenderType::D3D11) == kiero::Status::Success)
        {
            kiero::bind(8, (void**)& oPresent, hkPresent);
            init_hook = true;
        }
    } while (!init_hook);
    return TRUE;
}

char key;
bool forceMovement = true;
Unity::Vector3 lp_pos;
DWORD WINAPI MenuSwap(LPVOID lpReserved)
{
    while (true) {
        // Проверяем состояние клавиши Insert
        if (GetAsyncKeyState(VK_INSERT) & 0x8000) {
            ImguiRendering = !ImguiRendering;
        }
        if (forceMovement)
        {
            for (key = 8; key <= 255; key++) {
                if (GetAsyncKeyState(key) == -32767) { // Клавиша была нажата
                    switch (key) {
                    case 'u':
                        lp_pos = local_player->GetTransform()->GetPosition();
                        local_player->GetTransform()->SetPosition(Unity::Vector3(lp_pos.x+0.1,lp_pos.y,lp_pos.z));
                        break;
                    case 'h':
                        lp_pos = local_player->GetTransform()->GetPosition();
                        local_player->GetTransform()->SetPosition(Unity::Vector3(lp_pos.x,lp_pos.y,lp_pos.z+0.1));
                        break;
                    case 'j':
                        lp_pos = local_player->GetTransform()->GetPosition();
                        local_player->GetTransform()->SetPosition(Unity::Vector3(lp_pos.x-0.1,lp_pos.y,lp_pos.z));
                        break;
                    case 'k':
                        lp_pos = local_player->GetTransform()->GetPosition();
                        local_player->GetTransform()->SetPosition(Unity::Vector3(lp_pos.x,lp_pos.y,lp_pos.z-0.1));
                        break;
                    }
                }
        }
        Sleep(100); // Добавляем небольшую задержку, чтобы снизить загрузку процессора
    }
    return 0;
}



BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        crMd = hModule;
        CreateThread(nullptr, 0, MenuSwap, hModule, 0, nullptr);
        CreateThread(nullptr, 0, MainThread, hModule, 0, nullptr);
        
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        kiero::shutdown();
        break;
    }
    return TRUE;
}

fix code