local OldLoadBuffer = slua.loadbuffer
slua.loadbuffer = function(buf, name, ...)
    return OldLoadBuffer(buf, name, ...)
end

_G.CHECK_LUA_SIGN = false
_G.ENABLE_LUA_VERIFY = false
_G.SKIP_BYTECODE_CHECK = true

if UEPak then
    UEPak.VerifySignature = function() return true end
    UEPak.CheckMD5 = function() return true end
    UEPak.IsPakValid = function() return true end
end

if SkinManager then
    SkinManager.CheckSkinValid = function() return true end
    SkinManager.IsSkinBanned = function() return false end
    SkinManager.ReportIllegalSkin = function() end
end

if FileChecker then
    FileChecker.ScanLocalFile = function() end
    FileChecker.ReportAbnormalFile = function() end
    FileChecker.CheckFileIntegrity = function() return true end
end

if TLog then
    TLog.Report = function() end
    TLog.Log = function() end
    TLog.Error = function() end
    TLog.Warn = function() end
end

if CrashSight then
    CrashSight.ReportException = function() end
    CrashSight.SetUserId = function() end
    CrashSight.Log = function() end
end

_G.print = function() end
_G.Log = function() end
_G.DebugLog = function() end

if ScreenShot then
    ScreenShot.Capture = function() return nil end
    ScreenShot.TakeScreenShot = function() return "" end
    ScreenShot.GetScreenShotData = function() return "" end
end

if Telemetry then
    Telemetry.Send = function() end
    Telemetry.Report = function() end
end

if Firebase then
    Firebase.Analytics.LogEvent = function() end
end

if GameAnalytics then
    GameAnalytics.SendEvent = function() end
    GameAnalytics.Report = function() end
end

if HiggsBosonComponent then
    HiggsBosonComponent.ControlMHActive = function(self, val) end
    HiggsBosonComponent.StartDetection = function() end
    HiggsBosonComponent.ScanMemory = function() end
    HiggsBosonComponent.CheckSpeed = function() end
    HiggsBosonComponent.CheckWallHack = function() end
    HiggsBosonComponent.CheckAimbot = function() end
    HiggsBosonComponent.ReportSuspicious = function() end
    HiggsBosonComponent.VerifyIntegrity = function() return true end
    HiggsBosonComponent.GetDetectionResult = function() return 0 end
    HiggsBosonComponent.IsCheatDetected = function() return false end
    HiggsBosonComponent.Blacklist = {}
    HiggsBosonComponent.SuspiciousList = {}
end

if PlayerPrefs then
    PlayerPrefs.DeleteKey("CheatBlacklist")
    PlayerPrefs.DeleteKey("SuspiciousPlayers")
    PlayerPrefs.DeleteKey("DetectionLog")
end

if SubsystemMgr then
    local toDisable = {
        "AFKDetector",
        "ClientStatistics",
        "ShootVerification",
        "MemoryScanner",
        "SpeedCheck",
        "WallHackCheck",
        "FileIntegrityCheck",
        "BehaviorScore",
        "AbnormalDataReport",
        "AntiCheatSubsystem"
    }
    for _, name in ipairs(toDisable) do
        local sub = SubsystemMgr:GetSubsystem(name)
        if sub then
            sub.Enable = false
            sub.Active = false
            sub.Scan = function() end
            sub.Check = function() return true end
            sub.Report = function() end
            sub.Execute = function() end
        end
    end
end

local OldOnGameStateChange = GameState.OnGameStateChange
GameState.OnGameStateChange = function(self, oldState, newState)
    if newState == "CheatDetected" or newState == "AntiCheatFlag" then
        return
    end
    return OldOnGameStateChange(self, oldState, newState)
end

if ReportFlow then
    ReportFlow.ReportAttackFlow = function() end
    ReportFlow.ReportPlayerKillFlow = function() end
    ReportFlow.ReportHeadshotFlow = function() end
    ReportFlow.ReportAbnormalData = function() end
    ReportFlow.ReportSuspiciousBehavior = function() end
end

if NetUtil then
    local OldSendPacket = NetUtil.SendPacket
    
    NetUtil.SendPacket = function(self, packet)
        local blockedTypes = {
            "AntiCheat",
            "BehaviorReport", 
            "HeartBeatLog",
            "SwiftHawk",
            "DetectionData",
            "SuspiciousAction",
            "AbnormalKill",
            "SpeedCheck",
            "WallHackData",
            "AimbotData"
        }
        
        if packet and packet.Type then
            for _, blocked in ipairs(blockedTypes) do
                if string.find(packet.Type, blocked) then
                    return
                end
            end
        end
        
        return OldSendPacket(self, packet)
    end
end

if MemoryScanner then
    MemoryScanner.ScanRegion = function() return {} end
    MemoryScanner.FindCheat = function() return nil end
    MemoryScanner.DetectInjection = function() return false end
end

if GameServer then
    GameServer.OnCheatFlagReceived = function() end
    GameServer.OnKickRequest = function(self, reason)
        if string.find(reason, "cheat") or string.find(reason, "AntiCheat") then
            return
        end
    end
end
