From 20d296c0b9b68e59f645c36e082de65f6f82e072 Mon Sep 17 00:00:00 2001 From: aap Date: Thu, 21 Sep 2017 23:50:57 +0200 Subject: [PATCH] colorcycle fixed somewhat --- src/main.cpp | 61 ++++++++++++----------- src/postfx.cpp | 132 ++++++++++++++++++++++++++----------------------- 2 files changed, 100 insertions(+), 93 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 458e06f..2701a12 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,8 +21,9 @@ bool iCanHasSunGlare = true; int fixingSAMP; int numConfigs; -int currentConfig; -Config *config, configs[10]; +int currentConfig = 0; +Config configs[10]; +Config *config = &configs[0]; int original_bRadiosity = 0; void *grassPixelShader; @@ -474,6 +475,7 @@ void __declspec(naked) floatbitpattern(void) _asm { fstp [esp-4] mov eax, [esp-4] + sar eax,1 ret } } @@ -597,20 +599,21 @@ InitialiseGame_hook(void) InitialiseGame(); } -void __declspec(naked) selectVM(void) -{ - _asm { - test [esp+0x20],1 - jz window - - push 0x7463B8 - retn - - window: - push 0x7462C5 - retn - } -} +// not working yet +//void __declspec(naked) selectVM(void) +//{ +// _asm { +// test [esp+0x20],1 +// jz window +// +// push 0x7463B8 +// retn +// +// window: +// push 0x7462C5 +// retn +// } +//} @@ -1076,8 +1079,6 @@ InjectDelayedPatches() { if(!IsAlreadyRunning()){ // post init stuff - currentConfig = 0; - config = &configs[0]; findInis(); if(numConfigs == 0) readIni(0); @@ -1185,7 +1186,6 @@ 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; @@ -1197,7 +1197,7 @@ DllMain(HINSTANCE hInst, DWORD reason, LPVOID) // nvidia is not the way it's meant to be played Nop(0x748AA8, 0x748AE7-0x748AA8); - // windowed + // windowed - nor working yet // Nop(0x7462FF, 2); // Nop(0x745B55, 2); /// InjectHook(0x74639B, selectVM, PATCH_JUMP); @@ -1260,16 +1260,17 @@ DllMain(HINSTANCE hInst, DWORD reason, LPVOID) InjectHook(0x53D903, myPluginAttach); - //InjectHook(0x5A3C7D, ps2srand); - //InjectHook(0x5A3DFB, ps2srand); - //InjectHook(0x5A3C75, ps2rand); - //InjectHook(0x5A3CB9, ps2rand); - //InjectHook(0x5A3CDB, ps2rand); - //InjectHook(0x5A3CF2, ps2rand); - //Patch(0x5A3CC8, (float*)&ps2randnormalize); - //Patch(0x5A3CEA, (float*)&ps2randnormalize); - //Patch(0x5A3D05, (float*)&ps2randnormalize); - InjectHook(0x5A3C6E, floatbitpattern); + // projobj placement. Not really broken but whatever + InjectHook(0x5A3C7D, ps2srand); + InjectHook(0x5A3DFB, ps2srand); + InjectHook(0x5A3C75, ps2rand); + InjectHook(0x5A3CB9, ps2rand); + InjectHook(0x5A3CDB, ps2rand); + InjectHook(0x5A3CF2, ps2rand); + Patch(0x5A3CC8, (float*)&ps2randnormalize); + Patch(0x5A3CEA, (float*)&ps2randnormalize); + Patch(0x5A3D05, (float*)&ps2randnormalize); +// InjectHook(0x5A3C6E, floatbitpattern); // increase multipass distance static float multipassMultiplier = 1000.0f; // default 45.0 diff --git a/src/postfx.cpp b/src/postfx.cpp index 7e8ec6a..eb8897c 100644 --- a/src/postfx.cpp +++ b/src/postfx.cpp @@ -148,9 +148,9 @@ struct GradeColorset struct Colorcycle { static bool initialised; - static Grade redGrade[NUMHOURS][NUMWEATHERS]; - static Grade greenGrade[NUMHOURS][NUMWEATHERS]; - static Grade blueGrade[NUMHOURS][NUMWEATHERS]; + static Grade redGrade[24][NUMWEATHERS]; + static Grade greenGrade[24][NUMWEATHERS]; + static Grade blueGrade[24][NUMWEATHERS]; static void Initialise(void); static void Update(GradeColorset *colorset); @@ -772,6 +772,7 @@ CPostEffects::ColourFilter_Mobile(RwRGBA rgba1, RwRGBA rgba2) blue.r = blue.g = blue.a = 0.0f; */ + RwD3D9SetPixelShaderConstant(0, &red, 1); RwD3D9SetPixelShaderConstant(1, &green, 1); RwD3D9SetPixelShaderConstant(2, &blue, 1); @@ -1221,10 +1222,10 @@ static float &CWeather__InTunnelness = *(float*)0xC81334; static int &tunnelWeather = *(int*)0x8CDEE0; - -Grade Colorcycle::redGrade[NUMHOURS][NUMWEATHERS]; -Grade Colorcycle::greenGrade[NUMHOURS][NUMWEATHERS]; -Grade Colorcycle::blueGrade[NUMHOURS][NUMWEATHERS]; +// 24 instead of NUMHOURS because we might be using timecycle_24h with extended extra colour hours +Grade Colorcycle::redGrade[24][NUMWEATHERS]; +Grade Colorcycle::greenGrade[24][NUMWEATHERS]; +Grade Colorcycle::blueGrade[24][NUMWEATHERS]; bool Colorcycle::initialised; GradeColorset::GradeColorset(int h, int w) @@ -1329,65 +1330,70 @@ interpolateColorcycle(Grade *red, Grade *green, Grade *blue) void Colorcycle::Initialise(void) { + int have24h = GetModuleHandle("timecycle24") != 0 || GetModuleHandle("timecycle24.asi") != 0; + for(int i = 0; i < 24; i++) + for(int j = 0; j < NUMHOURS; j++){ + redGrade[j][i].r = 1.0f; + redGrade[j][i].g = 0.0f; + redGrade[j][i].b = 0.0f; + redGrade[j][i].a = 0.0f; + greenGrade[j][i].r = 0.0f; + greenGrade[j][i].g = 1.0f; + greenGrade[j][i].b = 0.0f; + greenGrade[j][i].a = 0.0f; + blueGrade[j][i].r = 0.0f; + blueGrade[j][i].g = 0.0f; + blueGrade[j][i].b = 1.0f; + blueGrade[j][i].a = 0.0f; + } void *f = CFileMgr::OpenFile("data/colorcycle.dat", "r"); - if(f == nil){ - for(int i = 0; i < 23; i++) - for(int j = 0; j < 8; j++){ - redGrade[j][i].r = 1.0f; - redGrade[j][i].g = 0.0f; - redGrade[j][i].b = 0.0f; - redGrade[j][i].a = 0.0f; - greenGrade[j][i].r = 0.0f; - greenGrade[j][i].g = 1.0f; - greenGrade[j][i].b = 0.0f; - greenGrade[j][i].a = 0.0f; - blueGrade[j][i].r = 0.0f; - blueGrade[j][i].g = 0.0f; - blueGrade[j][i].b = 1.0f; - blueGrade[j][i].a = 0.0f; + if(f){ + char *line; + for(int i = 0; i < NUMWEATHERS; i++){ + for(int j = 0; j < NUMHOURS; j++){ + line = CFileLoader::LoadLine(f); + sscanf(line, "%f %f %f %f %f %f %f %f %f %f %f %f", + &redGrade[j][i].r, &redGrade[j][i].g, + &redGrade[j][i].b, &redGrade[j][i].a, + &greenGrade[j][i].r, &greenGrade[j][i].g, + &greenGrade[j][i].b, &greenGrade[j][i].a, + &blueGrade[j][i].r, &blueGrade[j][i].g, + &blueGrade[j][i].b, &blueGrade[j][i].a); + float sum; + sum = redGrade[j][i].r + redGrade[j][i].g + redGrade[j][i].b; + if(sum > 1.7f) + redGrade[j][i].a -= (sum - 1.7f)*0.13f; + sum = greenGrade[j][i].r + greenGrade[j][i].g + greenGrade[j][i].b; + if(sum > 1.7f) + greenGrade[j][i].a -= (sum - 1.7f)*0.13f; + sum = blueGrade[j][i].r + blueGrade[j][i].g + blueGrade[j][i].b; + if(sum > 1.7f) + blueGrade[j][i].a -= (sum - 1.7f)*0.13f; + redGrade[j][i].r *= 0.67f; + redGrade[j][i].g *= 0.67f; + redGrade[j][i].b *= 0.67f; + redGrade[j][i].a *= 0.67f; + greenGrade[j][i].r *= 0.67f; + greenGrade[j][i].g *= 0.67f; + greenGrade[j][i].b *= 0.67f; + greenGrade[j][i].a *= 0.67f; + blueGrade[j][i].r *= 0.67f; + blueGrade[j][i].g *= 0.67f; + blueGrade[j][i].b *= 0.67f; + blueGrade[j][i].a *= 0.67f; + //printf("%f %f %f %f X %f %f %f %f X %f %f %f %f\n", + // redGrade[j][i].r, redGrade[j][i].g, redGrade[j][i].b, redGrade[j][i].a, + // greenGrade[j][i].r, greenGrade[j][i].g, greenGrade[j][i].b, greenGrade[j][i].a, + // blueGrade[j][i].r, blueGrade[j][i].g, blueGrade[j][i].b, blueGrade[j][i].a); } - initialised = true; - return; - } - char *line; - for(int i = 0; i < 23; i++){ - for(int j = 0; j < 8; j++){ - line = CFileLoader::LoadLine(f); - sscanf(line, "%f %f %f %f %f %f %f %f %f %f %f %f", - &redGrade[j][i].r, &redGrade[j][i].g, - &redGrade[j][i].b, &redGrade[j][i].a, - &greenGrade[j][i].r, &greenGrade[j][i].g, - &greenGrade[j][i].b, &greenGrade[j][i].a, - &blueGrade[j][i].r, &blueGrade[j][i].g, - &blueGrade[j][i].b, &blueGrade[j][i].a); - float sum; - sum = redGrade[j][i].r + redGrade[j][i].g + redGrade[j][i].b; - if(sum > 1.7f) - redGrade[j][i].a -= (sum - 1.7f)*0.13f; - sum = greenGrade[j][i].r + greenGrade[j][i].g + greenGrade[j][i].b; - if(sum > 1.7f) - greenGrade[j][i].a -= (sum - 1.7f)*0.13f; - sum = blueGrade[j][i].r + blueGrade[j][i].g + blueGrade[j][i].b; - if(sum > 1.7f) - blueGrade[j][i].a -= (sum - 1.7f)*0.13f; - redGrade[j][i].r *= 0.67f; - redGrade[j][i].g *= 0.67f; - redGrade[j][i].b *= 0.67f; - redGrade[j][i].a *= 0.67f; - greenGrade[j][i].r *= 0.67f; - greenGrade[j][i].g *= 0.67f; - greenGrade[j][i].b *= 0.67f; - greenGrade[j][i].a *= 0.67f; - blueGrade[j][i].r *= 0.67f; - blueGrade[j][i].g *= 0.67f; - blueGrade[j][i].b *= 0.67f; - blueGrade[j][i].a *= 0.67f; - //printf("%f %f %f %f X %f %f %f %f X %f %f %f %f\n", - // redGrade[j][i].r, redGrade[j][i].g, redGrade[j][i].b, redGrade[j][i].a, - // greenGrade[j][i].r, greenGrade[j][i].g, greenGrade[j][i].b, greenGrade[j][i].a, - // blueGrade[j][i].r, blueGrade[j][i].g, blueGrade[j][i].b, blueGrade[j][i].a); } + if(have24h) + for(int j = 0; j < NUMHOURS; j++){ + redGrade[j+8][21] = redGrade[j][22]; + greenGrade[j+8][21] = greenGrade[j][22]; + blueGrade[j+8][21] = blueGrade[j][22]; + } + CFileMgr::CloseFile(f); } - CFileMgr::CloseFile(f); initialised = true; }