Skip to content

Commit

Permalink
colorcycle fixed somewhat
Browse files Browse the repository at this point in the history
  • Loading branch information
aap committed Sep 21, 2017
1 parent ce04ed7 commit 20d296c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 93 deletions.
61 changes: 31 additions & 30 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -474,6 +475,7 @@ void __declspec(naked) floatbitpattern(void)
_asm {
fstp [esp-4]
mov eax, [esp-4]
sar eax,1
ret
}
}
Expand Down Expand Up @@ -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
// }
//}



Expand Down Expand Up @@ -1076,8 +1079,6 @@ InjectDelayedPatches()
{
if(!IsAlreadyRunning()){
// post init stuff
currentConfig = 0;
config = &configs[0];
findInis();
if(numConfigs == 0)
readIni(0);
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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<float*>(0x5A3CC8, (float*)&ps2randnormalize);
//Patch<float*>(0x5A3CEA, (float*)&ps2randnormalize);
//Patch<float*>(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<float*>(0x5A3CC8, (float*)&ps2randnormalize);
Patch<float*>(0x5A3CEA, (float*)&ps2randnormalize);
Patch<float*>(0x5A3D05, (float*)&ps2randnormalize);
// InjectHook(0x5A3C6E, floatbitpattern);

// increase multipass distance
static float multipassMultiplier = 1000.0f; // default 45.0
Expand Down
132 changes: 69 additions & 63 deletions src/postfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

0 comments on commit 20d296c

Please sign in to comment.