I believe I’ve set up gamma correction correctly in modDirectX, but I keep getting this Automation Error -2005532447 whenever I load the Client. Here’s how I added it in:

modDirectX
In the declarations under Option Explicit:

Public GammaControler As DirectDrawGammaControl
Public GammaRamp As DDGAMMARAMP
Public OriginalRamp As DDGAMMARAMP

Public BackBuffer As DirectDrawSurface7
Public StatsBackBuffer As DDSURFACEDESC2

Public RedAmount As Integer
Public GreenAmount As Integer
Public BlueAmount As Integer

At the bottom of InitSurfaces:

' Gamma correction
    StatsBackBuffer.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
    StatsBackBuffer.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX
    StatsBackBuffer.lBackBufferCount = 1
    Set BackBuffer = DD.CreateSurface(StatsBackBuffer)

    Set GammaControler = BackBuffer.GetDirectDrawGammaControl
    GammaControler.GetGammaRamp DDSGR_DEFAULT, OriginalRamp

    RedAmount = 0
    GreenAmount = 0
    BlueAmount = 0

Added at the bottom of modDirectX:

Public Function MakeSigned(lngValue As Long) As Integer
    If lngValue <= 32767 Then
        MakeSigned = CInt(lngValue)
        Exit Function
    End If

    MakeSigned = CInt(lngValue - 65535)
End Function
Public Function MakeUnsigned(intValue As Integer) As Long
    If intValue >= 0 Then
        MakeUnsigned = intValue
        Exit Function
    End If

    MakeUnsigned = intValue + 65535
End Function
Public Sub SetGamma(Red As Integer, Green As Integer, Blue As Integer)
    Dim i As Integer

    For i = 0 To 255
        If Red < 0 Then GammaRamp.Red(i) = MakeSigned(MakeUnsigned(OriginalRamp.Red(i)) * (100 - Abs(Red)) / 100)
        If Red = 0 Then GammaRamp.Red(i) = OriginalRamp.Red(i)
        If Red > 0 Then GammaRamp.Red(i) = MakeSigned(65535 - ((65535 - MakeUnsigned(OriginalRamp.Red(i))) * (100 - Red) / 100))
        If Green < 0 Then GammaRamp.Green(i) = MakeSigned(MakeUnsigned(OriginalRamp.Green(i)) * (100 - Abs(Green)) / 100)
        If Green = 0 Then GammaRamp.Green(i) = OriginalRamp.Green(i)
        If Green > 0 Then GammaRamp.Green(i) = MakeSigned(65535 - ((65535 - MakeUnsigned(OriginalRamp.Green(i))) * (100 - Green) / 100))
        If Blue < 0 Then GammaRamp.Blue(i) = MakeSigned(MakeUnsigned(OriginalRamp.Blue(i)) * (100 - Abs(Blue)) / 100)
        If Blue = 0 Then GammaRamp.Blue(i) = OriginalRamp.Blue(i)
        If Blue > 0 Then GammaRamp.Blue(i) = MakeSigned(65535 - ((65535 - MakeUnsigned(OriginalRamp.Blue(i))) * (100 - Blue) / 100))
    Next

    GammaControler.SetGammaRamp DDSGR_DEFAULT, GammaRamp
End Sub

Now, I’ve changed my Sub Night from this:

Sub Night()
    Dim x As Long, y As Long

    If TileFile(10) = 0 Then
        Exit Sub
    End If

    For y = ScreenY To ScreenY2
        For x = ScreenX To ScreenX2
            If Map(GetPlayerMap(MyIndex)).Tile(x, y).light <= 0 Then
                DisplayFx DD_TileSurf(10), (x - NewPlayerX) * PIC_X + sx - NewXOffset, (y - NewPlayerY) * PIC_Y + sx - NewYOffset, 32, 32, vbSrcAnd, DDBLT_ROP Or DDBLT_WAIT, 31
            Else
                DisplayFx DD_TileSurf(10), (x - NewPlayerX) * PIC_X + sx - NewXOffset, (y - NewPlayerY) * PIC_Y + sx - NewYOffset, 32, 32, vbSrcAnd, DDBLT_ROP Or DDBLT_WAIT, CLng(Map(GetPlayerMap(MyIndex)).Tile(x, y).light)
            End If
        Next x
    Next y
End Sub

To this:

Sub Night()
    Dim x As Long, y As Long

    For y = ScreenY To ScreenY2
        For x = ScreenX To ScreenX2
            If Map(GetPlayerMap(MyIndex)).Tile(x, y).light <= 0 Then
                SetGamma 230, 230, 230
            End If
        Next x
    Next y
End Sub

I’m not sure if I did all of this correctly, so I could use some help. Can someone please check over it and tell me what I have to change in order to get it to work properly? Any help would be greatly appreciated.