Skip to content

Commit

Permalink
raindrop fixes; SAMP fixes; moon phase
Browse files Browse the repository at this point in the history
  • Loading branch information
aap committed Sep 21, 2017
1 parent 5566d42 commit ce04ed7
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 53 deletions.
5 changes: 3 additions & 2 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ workspace "skygfx"

defines { "rsc_CompanyName=\"aap\"" }
defines { "rsc_LegalCopyright=\"\""}
defines { "rsc_FileVersion=\"3.2.0.0\"", "rsc_ProductVersion=\"3.2.0.0\"" }
defines { "rsc_InternalName=\"%{prj.name}\"", "rsc_ProductName=\"%{prj.name}\"", "rsc_OriginalFilename=\"%{prj.name}.asi\"" }
defines { "rsc_FileVersion=\"3.6.0.0\"", "rsc_ProductVersion=\"3.6.0.0\"" }
defines { "rsc_InternalName=\"%{prj.name}\"", "rsc_ProductName=\"%{prj.name}\"", "rsc_OriginalFilename=\"%{prj.name}.dll\"" }
defines { "rsc_FileDescription=\"https://github.com/aap\"" }
defines { "rsc_UpdateUrl=\"https://github.com/aap/skygfx\"" }

Expand Down Expand Up @@ -36,6 +36,7 @@ project "skygfx"
filter "configurations:Debug"
defines { "DEBUG" }
symbols "On"
flags { "StaticRuntime" }
debugdir "C:/Users/aap/games/gtasa"
debugcommand "C:/Users/aap/games/gtasa/gta_sa.exe"
postbuildcommands "copy /y \"$(TargetPath)\" \"C:\\Users\\aap\\games\\gtasa\\dlls\\skygfx.dll\""
Expand Down
Binary file modified resources/VersionInfo.rc
Binary file not shown.
7 changes: 7 additions & 0 deletions src/buildingPipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RxPipeline *buildingPipeline, *buildingDNPipeline;

float &CWeather__WetRoads = *(float*)0xC81308;


enum {
// common
REG_transform = 0,
Expand Down Expand Up @@ -127,6 +128,8 @@ CCustomBuildingDNPipeline__CustomPipeRenderCB_PS2(RwResEntry *repEntry, void *ob
RwMatrix envmat;
float transform[16];

_rwD3D9EnableClippingIfNeeded(object, type);

atomic = (RpAtomic*)object;

pipeGetComposedTransformMatrix(atomic, transform);
Expand Down Expand Up @@ -248,6 +251,8 @@ CCustomBuildingDNPipeline__CustomPipeRenderCB_PC(RwResEntry *repEntry, void *obj

atomic = (RpAtomic*)object;

_rwD3D9EnableClippingIfNeeded(object, type);

colorScale = 1.0f;
RwD3D9SetPixelShaderConstant(0, &colorScale, 1);

Expand Down Expand Up @@ -335,6 +340,7 @@ CCustomBuildingDNPipeline__CustomPipeRenderCB_PC(RwResEntry *repEntry, void *obj
RwD3D9SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
RwD3D9SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
RwD3D9SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);

}

void
Expand All @@ -348,6 +354,7 @@ CCustomBuildingDNPipeline__CustomPipeRenderCB_Switch(RwResEntry *repEntry, void
CCustomBuildingDNPipeline__CustomPipeRenderCB_PC(repEntry, object, type, flags);
else
CCustomBuildingDNPipeline__CustomPipeRenderCB_PS2(repEntry, object, type, flags);
fixSAMP();
}

static RwBool
Expand Down
4 changes: 3 additions & 1 deletion src/gta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@ WRAPPER RwFrame *RwFrameUpdateObjects(RwFrame*) { EAXJMP(0x7F0910); }
WRAPPER RwFrame *RwFrameSetIdentity(RwFrame*) { EAXJMP(0x7F10B0); }
WRAPPER RwMatrix *RwMatrixOrthoNormalize(RwMatrix*, const RwMatrix*) { EAXJMP(0x7F1920); }
WRAPPER RwMatrix *RwMatrixTransform(RwMatrix*, const RwMatrix*, RwOpCombineType) { EAXJMP(0x7F25A0); }
WRAPPER RwMatrix *RwMatrixOptimize(RwMatrix*, const RwMatrixTolerance*) { EAXJMP(0x7F17E0); }
WRAPPER RwMatrix *RwMatrixOptimize(RwMatrix*, const RwMatrixTolerance*) { EAXJMP(0x7F17E0); }

WRAPPER void _rwD3D9EnableClippingIfNeeded(void *object, RwUInt32 type) { EAXJMP(0x756D90); }
126 changes: 114 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ bool iCanHasbuildingPipe = true;
bool iCanHasvehiclePipe = true;
bool iCanHasSunGlare = true;

int fixingSAMP;

int numConfigs;
int currentConfig;
Config *config, configs[10];
Expand All @@ -26,7 +28,6 @@ int original_bRadiosity = 0;
void *grassPixelShader;
void *simplePS;
void *gpCurrentShaderForDefaultCallbacks;
//void (*TimecycInit)(void) = (void (*)(void))0x5BBAC0;

float *gfLaRiotsLightMult = (float*)0x8CD060;
float *ambientColors = (float*)0xB7C4A0;
Expand Down Expand Up @@ -68,11 +69,41 @@ getpath(char *path)
return NULL;
}

WRAPPER void _rwD3D9RenderStateFlushCache(void) { EAXJMP(0x7FC200); }

// SAMP fucks with the render states directly instead of using RW. Synching the fog states
// before and after rendering and using SAMP graphics restore seems to make things work.
void
fixSAMP(void)
{
static D3DCAPS9 *Caps=(D3DCAPS9*)0xC9BF00;
static int *FogConvTable=(int*)0x8848FC;
if(fixingSAMP){
int fog, fogtype;
RwRenderStateGet(rwRENDERSTATEFOGENABLE, &fog);
RwRenderStateGet(rwRENDERSTATEFOGTYPE, &fogtype);
_rwD3D9RenderStateFlushCache();
RwD3D9SetRenderState(D3DRS_FOGENABLE, fog);
d3d9device->SetRenderState(D3DRS_FOGENABLE, fog);
int table, vertex;
if((Caps->RasterCaps & D3DPRASTERCAPS_FOGTABLE) && (Caps->RasterCaps & D3DPRASTERCAPS_WFOG)){
table = FogConvTable[fogtype];
vertex = D3DFOG_NONE;
}else{
table = D3DFOG_NONE;
vertex = FogConvTable[fogtype];
}
RwD3D9SetRenderState(D3DRS_FOGTABLEMODE, table);
RwD3D9SetRenderState(D3DRS_FOGVERTEXMODE, vertex);
d3d9device->SetRenderState(D3DRS_FOGTABLEMODE, table);
d3d9device->SetRenderState(D3DRS_FOGVERTEXMODE, vertex);
}
}

void
D3D9Render(RxD3D9ResEntryHeader *resEntryHeader, RxD3D9InstanceData *instanceData)
{
fixSAMP();
if(resEntryHeader->indexBuffer)
RwD3D9DrawIndexedPrimitive(resEntryHeader->primType, instanceData->baseIndex, 0, instanceData->numVertices, instanceData->startIndex, instanceData->numPrimitives);
else
Expand All @@ -91,7 +122,7 @@ D3D9RenderDual(int dual, RxD3D9ResEntryHeader *resEntryHeader, RxD3D9InstanceDat
RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTION, &alphafunc);
if(dual && hasAlpha && zwrite){
RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &alpharef);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, (void*)128);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, (void*)config->zwriteThreshold);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, (void*)rwALPHATESTFUNCTIONGREATEREQUAL);
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
D3D9Render(resEntryHeader, instanceData);
Expand Down Expand Up @@ -224,7 +255,7 @@ grassRenderCallback(RpAtomic *atomic)
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTION, (void*)&alphatest);
RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, (void*)&alpharef);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, (void*)128);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, (void*)config->zwriteThreshold);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, (void*)rwALPHATESTFUNCTIONGREATEREQUAL);
RxPipelineExecute(pipe, atomic, 1);
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE);
Expand Down Expand Up @@ -263,7 +294,7 @@ myDefaultCallback(RpAtomic *atomic)
if(dodual){
RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTION, (void*)&alphatest);
RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, (void*)&alpharef);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, (void*)128);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, (void*)config->zwriteThreshold);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, (void*)rwALPHATESTFUNCTIONGREATEREQUAL);
RxPipelineExecute(pipe, atomic, 1);
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE);
Expand Down Expand Up @@ -521,6 +552,32 @@ CWaterLevel__CalculateWavesForCoordinate_hook(int x, int y, float a3, float a4,
}
*/

static int alphafunc;
static void setMoonAlphaBlendStates(void){
RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTION, &alphafunc);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, (void*)rwALPHATESTFUNCTIONALWAYS);
RwD3D9SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, 1);
RwD3D9SetRenderState(D3DRS_BLENDOPALPHA, D3DBLENDOP_ADD);
RwD3D9SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_SRCALPHA);
RwD3D9SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_ZERO);
}
static void restoreMoonAlphaBlendStates(void){
RwD3D9SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, 0);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, (void*)alphafunc);
}
void __declspec(naked) renderMoonMask(void)
{
_asm {
call setMoonAlphaBlendStates
mov eax,0x70D000
call eax
call restoreMoonAlphaBlendStates
push 0x713C51
retn
}
}


void (*CSkidmarks__Render_orig)(void);
void CSkidmarks__Render(void)
{
Expand All @@ -540,6 +597,20 @@ InitialiseGame_hook(void)
InitialiseGame();
}

void __declspec(naked) selectVM(void)
{
_asm {
test [esp+0x20],1
jz window

push 0x7463B8
retn

window:
push 0x7462C5
retn
}
}



Expand Down Expand Up @@ -780,6 +851,10 @@ readIni(int n)
c->neoBloodDrops = readint(cfg.get("SkyGfx", "neoBloodDrops", ""), 0);
fixPcCarLight = readint(cfg.get("SkyGfx", "fixPcCarLight", ""), 0);

c->zwriteThreshold = readint(cfg.get("SkyGfx", "zwriteThreshold", ""), 128);
if(c->zwriteThreshold < 0) c->zwriteThreshold = 0;
if(c->zwriteThreshold > 255) c->zwriteThreshold = 255;

c->bYCbCrFilter = readint(cfg.get("SkyGfx", "YCbCrCorrection", ""), 0);
c->lumaScale = readfloat(cfg.get("SkyGfx", "lumaScale", ""), 219.0f/255.0f);
c->lumaOffset = readfloat(cfg.get("SkyGfx", "lumaOffset", ""), 16.0f/255.0f);
Expand Down Expand Up @@ -865,7 +940,15 @@ afterStreamIni(void)
X(offBottom) \
X(radiosityFilterPasses) \
X(radiosityRenderPasses) \
X(radiosityIntensity)
X(radiosityIntensity) \
X(zwriteThreshold) \
X(bYCbCrFilter) \
X(lumaScale) \
X(lumaOffset) \
X(cbScale) \
X(cbOffset) \
X(crScale) \
X(crOffset)

struct SkyGfxMenu
{
Expand Down Expand Up @@ -943,6 +1026,10 @@ installMenu(void)
if(iCanHasNeoDrops){
menu.neoWaterDrops = DebugMenuAddVarBool32("SkyGFX", "Neo Water drops", &config->neoWaterDrops, nil);
menu.neoBloodDrops = DebugMenuAddVarBool32("SkyGFX", "Neo-style Blood drops", &config->neoBloodDrops, nil);
#ifdef DEBUG
DebugMenuAddVarBool8("SkyGFX", "Spray Water drops", (int8*)&WaterDrops::sprayWater, nil);
DebugMenuAddVarBool8("SkyGFX", "Spray Blood drops", (int8*)&WaterDrops::sprayBlood, nil);
#endif
}

DebugMenuAddVarBool8("SkyGFX|Misc", "Blur PS2 Colour Filter", (int8_t*)&CPostEffects::m_bBlurColourFilter, nil);
Expand All @@ -959,6 +1046,7 @@ installMenu(void)
menu.dualPassVehicle = DebugMenuAddVarBool32("SkyGFX|Advanced", "Dual-pass Vehicles", &config->dualPassVehicle, nil);
menu.dualPassPed = DebugMenuAddVarBool32("SkyGFX|Advanced", "Dual-pass Peds", &config->dualPassPed, nil);
menu.dualPassGrass = DebugMenuAddVarBool32("SkyGFX|Advanced", "Dual-pass Grass", &config->dualPassGrass, nil);
menu.zwriteThreshold = DebugMenuAddVar("SkyGFX|Advanced", "Dual-pass Alpha Threshold", &config->zwriteThreshold, nil, 1, 0, 255, nil);
menu.ps2ModulateBuilding = DebugMenuAddVarBool32("SkyGFX|Advanced", "PS2-modulate Buildings", &config->ps2ModulateBuilding, nil);
menu.ps2ModulateGrass = DebugMenuAddVarBool32("SkyGFX|Advanced", "PS2-modulate Grass", &config->ps2ModulateGrass, nil);
menu.infraredVision = DebugMenuAddVar("SkyGFX|Advanced", "Infrared vision", &config->infraredVision, nil, 1, 0, 1, ps2pcStr);
Expand All @@ -968,13 +1056,13 @@ installMenu(void)
menu.grainFilter = DebugMenuAddVar("SkyGFX|Advanced", "Grain filter", &config->grainFilter, resetValues, 1, 0, 1, ps2pcStr);
DebugMenuEntrySetWrap(menu.grainFilter, true);

DebugMenuAddVarBool8("SkyGFX|ScreenFX", "Enable YCbCr tweak", (int8_t*)&config->bYCbCrFilter, resetValues);
DebugMenuAddVar("SkyGFX|ScreenFX", "Y scale", &config->lumaScale, resetValues, 0.004f, 0.0f, 10.0f);
DebugMenuAddVar("SkyGFX|ScreenFX", "Y offset", &config->lumaOffset, resetValues, 0.004f, -1.0f, 1.0f);
DebugMenuAddVar("SkyGFX|ScreenFX", "Cb scale", &config->cbScale, resetValues, 0.004f, 0.0f, 10.0f);
DebugMenuAddVar("SkyGFX|ScreenFX", "Cb offset", &config->cbOffset, resetValues, 0.004f, -1.0f, 1.0f);
DebugMenuAddVar("SkyGFX|ScreenFX", "Cr scale", &config->crScale, resetValues, 0.004f, 0.0f, 10.0f);
DebugMenuAddVar("SkyGFX|ScreenFX", "Cr offset", &config->crOffset, resetValues, 0.004f, -1.0f, 1.0f);
menu.bYCbCrFilter = DebugMenuAddVarBool8("SkyGFX|ScreenFX", "Enable YCbCr tweak", (int8_t*)&config->bYCbCrFilter, resetValues);
menu.lumaScale = DebugMenuAddVar("SkyGFX|ScreenFX", "Y scale", &config->lumaScale, resetValues, 0.004f, 0.0f, 10.0f);
menu.lumaOffset = DebugMenuAddVar("SkyGFX|ScreenFX", "Y offset", &config->lumaOffset, resetValues, 0.004f, -1.0f, 1.0f);
menu.cbScale = DebugMenuAddVar("SkyGFX|ScreenFX", "Cb scale", &config->cbScale, resetValues, 0.004f, 0.0f, 10.0f);
menu.cbOffset = DebugMenuAddVar("SkyGFX|ScreenFX", "Cb offset", &config->cbOffset, resetValues, 0.004f, -1.0f, 1.0f);
menu.crScale = DebugMenuAddVar("SkyGFX|ScreenFX", "Cr scale", &config->crScale, resetValues, 0.004f, 0.0f, 10.0f);
menu.crOffset = DebugMenuAddVar("SkyGFX|ScreenFX", "Cr offset", &config->crOffset, resetValues, 0.004f, -1.0f, 1.0f);

hasMenu = true;
//void privatepatches(void);
Expand All @@ -997,6 +1085,8 @@ InjectDelayedPatches()
readIni(1);
// only load one ini for now, others are loaded later by readInis()

fixingSAMP = GetModuleHandle("samp") != 0 || GetModuleHandle("SAMPGraphicRestore") != 0 || GetModuleHandle("SAMPGraphicRestore.asi") != 0;

InterceptCall(&InitialiseGame, InitialiseGame_hook, 0x748CFB);

// Stop timecycle from converting colour filter alphas
Expand Down Expand Up @@ -1095,6 +1185,7 @@ DllMain(HINSTANCE hInst, DWORD reason, LPVOID)
freopen("CONOUT$", "w", stderr);
}

config = &configs[0]; // so GetConfig returns something
for(int i = 0; i < 10; i++)
configs[i].version = VERSION;

Expand All @@ -1103,6 +1194,17 @@ DllMain(HINSTANCE hInst, DWORD reason, LPVOID)
defaultColourTopVOffset = CPostEffects::m_colourTopVOffset;
defaultColourBottomVOffset = CPostEffects::m_colourBottomVOffset;

// nvidia is not the way it's meant to be played
Nop(0x748AA8, 0x748AE7-0x748AA8);

// windowed
// Nop(0x7462FF, 2);
// Nop(0x745B55, 2);
/// InjectHook(0x74639B, selectVM, PATCH_JUMP);

// moon mask
InjectHook(0x713C4C, renderMoonMask, PATCH_JUMP);

IsAlreadyRunning = (BOOL(*)())(*(int*)(0x74872D+1) + 0x74872D + 5);
InjectHook(0x74872D, InjectDelayedPatches);

Expand Down
12 changes: 4 additions & 8 deletions src/neo.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ struct CMatrix
int haveRwMatrix;
};

struct CPlaceable_III
{
void *vmt;
CMatrix matrix;
};

struct VertexTex2
{
RwReal x;
Expand Down Expand Up @@ -177,7 +171,10 @@ class WaterDrops
static RwV3d ms_posDelta;

static int ms_splashDuration;
static CPlaceable_III *ms_splashObject;

// debugging
static bool sprayWater;
static bool sprayBlood;

static void Process(void);
static void CalculateMovement(void);
Expand All @@ -195,7 +192,6 @@ class WaterDrops
static void Clear(void);
static void Reset(void);

static void RegisterSplash(CPlaceable_III *plc, float distance = 20.0f);
static void WaterDrops::RegisterSplash(RwV3d* point, float distance = 20.0f, int duration = 14);
static bool NoDrops(void);
static bool NoRain(void);
Expand Down
Loading

0 comments on commit ce04ed7

Please sign in to comment.