Мой код который делает Chams почему-то не работает с видеокартами AMD, помоги пожалуйста починить код. Покажи полный изменный код. Я очень плохо разбираюсь в DirectX.

```Hook.cpp
#include "Hook.hpp"

#ifdef _DEBUG
#include <cstdio>
#define DEBUG_PRINT(format, ...) printf(format, __VA_ARGS__)
#else
#define DEBUG_PRINT(format, ...) (void)0
#endif

#include "minhook/include/MinHook.h"
#include "FindPattern/FindPattern.h"
#include "Models.hpp"

namespace Hook
{
    // Safely releases a COM object and sets the pointer to nullptr
    inline void SafeRelease(IUnknown* dxObject)
    {
        if (dxObject)
        {
            dxObject->Release();
            dxObject = nullptr;
        }
    }

    // Safely releases an array of shader resource views
    inline void SafeReleaseSRVs(ID3D11ShaderResourceView* SRVs[])
    {
        for (size_t i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
        {
            if (SRVs[i] == nullptr)
            {
                break;
            }
            SafeRelease(SRVs[i]);
        }
    }

    // Counts the number of valid shader resource views in the array
    inline size_t CountSRVs(ID3D11ShaderResourceView* SRVs[])
    {
        size_t count = 0;
        while (count < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT && SRVs[count] != nullptr)
        {
            ++count;
        }
        return count;
    }

    // Original function pointers
    typedef void(__stdcall* DrawIndexedInstanced_t)(ID3D11DeviceContext*, UINT, UINT, UINT, INT, UINT);
    DrawIndexedInstanced_t OriginalDrawIndexedInstanced = nullptr;

    // Address for the DrawIndexedInstanced function
    LPVOID DrawIndexedInstancedAddress = nullptr;

    // Initialization function to set up hooks
    DWORD WINAPI Init()
    {
        // Initialize MinHook
        MH_STATUS mhStatus = MH_Initialize();
        if (mhStatus != MH_OK)
        {
            DEBUG_PRINT("Error: Failed to initialize MinHook! Status: %d\n", mhStatus);
            return FALSE;
        }

        // Get the module handle for d3d11.dll
        HMODULE d3d11Module = GetModuleHandleW(L"d3d11.dll");
        if (!d3d11Module)
        {
            DEBUG_PRINT("Error: Failed to get d3d11.dll module handle. LastError: %lu\n", GetLastError());
            return FALSE;
        }
        DEBUG_PRINT("d3d11.dll module handle: %p\n", static_cast<void*>(d3d11Module));

        // Define search offsets and ranges
        constexpr size_t SEARCH_OFFSET = 0x100000;
        constexpr size_t SEARCH_RANGE = 0x200000;
        uintptr_t moduleBase = reinterpret_cast<uintptr_t>(d3d11Module);
        uintptr_t searchStart = moduleBase + SEARCH_OFFSET;
        size_t searchLength = SEARCH_RANGE - SEARCH_OFFSET;

        // Attempt to find the DrawIndexedInstanced function using pattern scanning
        uintptr_t functionAddress = IgroWidgets::FindPattern(
            searchStart,
            searchLength,
            reinterpret_cast<const unsigned char*>("\x48\x89\x5C\x24\x08\x48\x89\x74\x24\x10\x57\x48\x83\xEC\x00\x41\x8B\xF0\x48\x8B\xDA\x48\x8D\xB9\x00\x00\x00\xFF\x48\x8B\xCF\xE8\x00\x00\x00\x00\x84\xC0\x74\x00\x48\x85\xDB\x74\x00\x8B\x8B\x00\x00\x00\x00\x8B\x93"),
            "xxxxxxxxxxxxxx?xxxxxxxxx???xxxxx????xxx?xxxx?xx????xx"
        );

        if (functionAddress == 0)
        {
            DEBUG_PRINT("Error: Couldn't find DrawIndexedInstanced function!\n");
            return FALSE;
        }
        DEBUG_PRINT("Found DrawIndexedInstanced function at: 0x%llX\n", functionAddress);

        // Cast the function address to LPVOID
        DrawIndexedInstancedAddress = reinterpret_cast<LPVOID>(functionAddress);

        // Create the hook for DrawIndexedInstanced
        mhStatus = MH_CreateHook(
            DrawIndexedInstancedAddress,
            &DetourDrawIndexedInstanced,
            reinterpret_cast<LPVOID*>(&OriginalDrawIndexedInstanced)
        );
        if (mhStatus != MH_OK)
        {
            DEBUG_PRINT("Error: Failed MH_CreateHook for DrawIndexedInstanced! Status: %d\n", mhStatus);
            return FALSE;
        }

        // Enable the hook
        mhStatus = MH_EnableHook(DrawIndexedInstancedAddress);
        if (mhStatus != MH_OK)
        {
            DEBUG_PRINT("Error: Failed MH_EnableHook for DrawIndexedInstanced! Status: %d\n", mhStatus);
            return FALSE;
        }

        DEBUG_PRINT("DrawIndexedInstanced hook enabled\n");
        return TRUE;
    }

    // Detour function for DrawIndexedInstanced
    void __stdcall DetourDrawIndexedInstanced(
        ID3D11DeviceContext* pContext,
        UINT IndexCountPerInstance,
        UINT InstanceCount,
        UINT StartIndexLocation,
        INT BaseVertexLocation,
        UINT StartInstanceLocation
    )
    {
        DEBUG_PRINT("DetourDrawIndexedInstanced was called.\n");

        // Get Vertex Buffer and Stride
        ID3D11Buffer* veBuffer = nullptr;
        UINT stride = 0;
        UINT veBufferOffset = 0;
        pContext->IAGetVertexBuffers(0, 1, &veBuffer, &stride, &veBufferOffset);
        SafeRelease(veBuffer);

        // Get Constant Buffers and Log Sizes
        ID3D11Buffer* vscBuffer = nullptr;
        D3D11_BUFFER_DESC vscDesc = {};
        UINT vscWidth = 0;
        pContext->VSGetConstantBuffers(0, 1, &vscBuffer);
        if (vscBuffer)
        {
            vscBuffer->GetDesc(&vscDesc);
            vscWidth = vscDesc.ByteWidth;
            SafeRelease(vscBuffer);
        }

        ID3D11Buffer* pscBuffer = nullptr;
        D3D11_BUFFER_DESC pscDesc = {};
        UINT pscWidth = 0;
        pContext->PSGetConstantBuffers(0, 1, &pscBuffer);
        if (pscBuffer)
        {
            pscBuffer->GetDesc(&pscDesc);
            pscWidth = pscDesc.ByteWidth;
            SafeRelease(pscBuffer);
        }

        // Log stride and constant buffer widths
        DEBUG_PRINT("Stride: %u, VSC Width: %u, PSC Width: %u\n", stride, vscWidth, pscWidth);

        // Call the original function
        OriginalDrawIndexedInstanced(pContext, IndexCountPerInstance, InstanceCount, StartIndexLocation, BaseVertexLocation, StartInstanceLocation);
    }

    // Cleanup function to disable hooks and release resources
    void Unload()
    {
        if (DrawIndexedInstancedAddress)
        {
            MH_DisableHook(DrawIndexedInstancedAddress);
        }

        SafeRelease(wallHackDSS);
        SafeRelease(redSRV);
        SafeRelease(greenSRV);
    }

    // Creates a shader resource view (SRV) with a solid color
    void CreateColorSRV(ID3D11Device* device, const RGBA& color, ID3D11ShaderResourceView** shaderResourceView)
    {
        if (!device || !shaderResourceView)
            return;

        D3D11_SUBRESOURCE_DATA initData = {};
        initData.pSysMem = &color;
        initData.SysMemPitch = sizeof(color);
        initData.SysMemSlicePitch = 0;

        ID3D11Texture2D* texture = nullptr;
        D3D11_TEXTURE2D_DESC desc = {};
        desc.Width = 1;
        desc.Height = 1;
        desc.MipLevels = 1;
        desc.ArraySize = 1;
        desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
        desc.SampleDesc.Count = 1;
        desc.Usage = D3D11_USAGE_DEFAULT;
        desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;

        HRESULT hr = device->CreateTexture2D(&desc, &initData, &texture);
        if (SUCCEEDED(hr) && texture)
        {
            D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {};
            SRVDesc.Format = desc.Format;
            SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
            SRVDesc.Texture2D.MipLevels = 1;

            hr = device->CreateShaderResourceView(texture, &SRVDesc, shaderResourceView);
            if (FAILED(hr))
            {
                DEBUG_PRINT("Error: Failed to create shader resource view. HRESULT: 0x%X\n", hr);
            }

            SafeRelease(texture);
        }
        else
        {
            DEBUG_PRINT("Error: Failed to create texture2D. HRESULT: 0x%X\n", hr);
        }
    }

    // Creates red and green SRVs if they haven't been created yet
    void CreateColorSRVs(ID3D11Device* device)
    {
        if (!device || (greenSRV && redSRV))
            return;

        const RGBA red(255, 0, 0, 255);
        const RGBA green(0, 255, 0, 255);

        CreateColorSRV(device, red, &redSRV);
        CreateColorSRV(device, green, &greenSRV);
    }

    // Creates a Depth Stencil State (DSS) for wall hacks
    void CreateDepthStencilStates(ID3D11Device* device)
    {
        if (!device || wallHackDSS)
            return;

        D3D11_DEPTH_STENCIL_DESC depthStencilDesc = {};
        depthStencilDesc.DepthEnable = FALSE;
        depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
        depthStencilDesc.DepthFunc = D3D11_COMPARISON_GREATER_EQUAL;
        depthStencilDesc.StencilEnable = FALSE;
        depthStencilDesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
        depthStencilDesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;

        // Front face stencil operations
        depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
        depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
        depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
        depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

        // Back face stencil operations
        depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
        depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
        depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
        depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

        HRESULT hr = device->CreateDepthStencilState(&depthStencilDesc, &wallHackDSS);
        if (FAILED(hr))
        {
            DEBUG_PRINT("Error: Failed to create DepthStencilState. HRESULT: 0x%X\n", hr);
        }
    }

    // Draws chams (colored models) based on visibility
    bool DrawChams(
        ID3D11DeviceContext* pContext,
        ID3D11Buffer* pBufferForArgs,
        UINT AlignedByteOffsetForArgs,
        ID3D11ShaderResourceView* SRVs[],
        ID3D11ShaderResourceView* srvWhenInvisible,
        ID3D11ShaderResourceView* srvWhenVisible
    )
    {
        if (!pContext || !pBufferForArgs || !SRVs)
            return false;

        const size_t srvCount = CountSRVs(SRVs);
        if (srvWhenInvisible)
        {
            ID3D11DepthStencilState* originalDSS = nullptr;
            UINT originalStencilRef = 0;
            pContext->OMGetDepthStencilState(&originalDSS, &originalStencilRef);

            for (size_t i = 0; i < srvCount; ++i)
            {
                pContext->PSSetShaderResources(static_cast<UINT>(i), 1, &srvWhenInvisible);
            }

            pContext->OMSetDepthStencilState(wallHackDSS, originalStencilRef);
            OriginalDrawIndexedInstancedIndirect(pContext, pBufferForArgs, AlignedByteOffsetForArgs);

            pContext->OMSetDepthStencilState(originalDSS, originalStencilRef);
            SafeRelease(originalDSS);
        }

        if (srvWhenVisible)
        {
            for (size_t i = 0; i < srvCount; ++i)
            {
                pContext->PSSetShaderResources(static_cast<UINT>(i), 1, &srvWhenVisible);
            }
            OriginalDrawIndexedInstancedIndirect(pContext, pBufferForArgs, AlignedByteOffsetForArgs);
            return true;
        }

        return false;
    }
}
```

```Models.hpp
/*
 *  R6 Chams by Igromanru
 *  Copyright (C) 2024 Igromanru
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 *  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
 *  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#pragma once

#include <d3d11.h>

#pragma warning(disable:4267)

namespace Models
{
    constexpr bool MatchSRVFormat(ID3D11ShaderResourceView* srv, int targetFormat)
    {
        if (srv)
        {
            if (targetFormat > -1)
            {
                D3D11_SHADER_RESOURCE_VIEW_DESC desc;
                srv->GetDesc(&desc);
                return desc.Format == targetFormat;
            }
            return true;
        }
        return false;
    }

    class Model
    {
    public:
        int Stride;
        int VscWidth;
        int PscWidth;
        int SrvFormat;
        int SrvIndex;

        Model(int stride, int vscWidth, int pscWidth, int psSrvFormat = -1, int srvIndex = -1)
            : Stride(stride), VscWidth(vscWidth), PscWidth(pscWidth), SrvFormat(psSrvFormat), SrvIndex(srvIndex)
        {
        }

        bool IsModel(UINT stride, UINT vscWidth, UINT pscWidth, ID3D11ShaderResourceView* SRVs[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT]) const
        {
            auto result = (Stride < 0 || stride == static_cast<unsigned>(Stride)) && (VscWidth < 0 || vscWidth == static_cast<unsigned>(VscWidth)) && (PscWidth < 0 || pscWidth == static_cast<unsigned>(PscWidth));
            if (result)
            {
                if (SRVs && (SrvIndex >= 0 || SrvFormat >= 0))
                {
                    if (SrvIndex < 0)
                    {
                        result = false;
                        for (auto i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; i++)
                        {
                            if (!SRVs[i])
                            {
                                break;
                            }

                            if (MatchSRVFormat(SRVs[i], SrvFormat))
                            {
                                result = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        result = SrvIndex < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT && MatchSRVFormat(SRVs[SrvIndex], SrvFormat);
                    }
                }
            }

            return result;
        }
    };

    inline Model Skin1(8, 62, 4, 77, 2);
    inline Model Skin2(8, 62, 4, 83, 2);
    inline Model Body1(8, 62, 12, 83);
    inline Model Body2(8, 62, 14, 83);

    inline Model DroneWorldOverlay(8, 49, 3);
    inline Model WorldOverlay1(8, 49, 4);
    inline Model WorldOverlay2(8, 49, 12);
    inline Model WorldOverlay3(8, 49, 14);
    inline Model WorldOverlay4(8, 49, 49);

    inline Model Scope(8, 49, 49, 77, 2); // Scope textures
}
```