Skip to content

Commit

Permalink
- Reinstate gamehacks.c; Add fixes for Winback square issue and Pilot…
Browse files Browse the repository at this point in the history
… Wings shadow under glN64
  • Loading branch information
emukidid committed May 4, 2022
1 parent 0d2a10f commit 546144d
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 65 deletions.
39 changes: 34 additions & 5 deletions glN64_GX/RDP.cpp
Expand Up @@ -11,6 +11,9 @@

#ifdef __GX__
#include <gccore.h>
extern "C" {
#include "../main/gamehacks.h"
}
#endif // __GX__

#include "N64.h"
Expand Down Expand Up @@ -248,12 +251,38 @@ void RDP_TexRectFlip( u32 w0, u32 w1 )
}

void RDP_TexRect( u32 w0, u32 w1 )
{
u32 w2 = *(u32*)&RDRAM[RSP.PC[RSP.PCi] + 4];
RSP.PC[RSP.PCi] += 8;

u32 w3 = *(u32*)&RDRAM[RSP.PC[RSP.PCi] + 4];
{
u32 cmd1 = (*(u32*)&RDRAM[RSP.PC[RSP.PCi] + 0]) >> 24;
u32 cmd2 = (*(u32*)&RDRAM[RSP.PC[RSP.PCi] + 8]) >> 24;
u32 w2 = *(u32*)&RDRAM[RSP.PC[RSP.PCi] + 4];
RSP.PC[RSP.PCi] += 8;

u32 w3 = *(u32*)&RDRAM[RSP.PC[RSP.PCi] + 4];
RSP.PC[RSP.PCi] += 8;
#ifdef __GX__
// Winback floating square hack, retrofitted version of https://github.com/gonetz/GLideN64/issues/63
if(GetGameSpecificHack() == &hack_winback) {
enum {
gspTexRect,
gdpTexRect,
halfTexRect
} texRectMode = gdpTexRect;
if (cmd1 == G_RDPHALF_1) {
if (cmd2 == G_RDPHALF_2)
texRectMode = gspTexRect;
} else if (cmd1 == 0xB3) {
if (cmd2 == 0xB2)
texRectMode = gspTexRect;
else
texRectMode = halfTexRect;
} else if (cmd1 == 0xF1)
texRectMode = halfTexRect;

if(texRectMode == gdpTexRect) {
return;
}
}
#endif

gDPTextureRectangle( _FIXED2FLOAT( (u16)_SHIFTR( w1, 12, 12 ), 2 ), // ulx
_FIXED2FLOAT( (u16)_SHIFTR( w1, 0, 12 ), 2 ), // uly
Expand Down
249 changes: 189 additions & 60 deletions main/gamehacks.c
Expand Up @@ -28,126 +28,238 @@
#include "../r4300/r4300.h"

void *game_specific_hack = 0;
/*

void compare_hword_write_hword(u32 compAddr, u32 destAddr, u16 compVal, u16 destVal) {
address = compAddr;
read_hword_in_memory();
if(hword == compVal) {
address = destAddr;
hword = destVal;
write_hword_in_memory();
}
}

void compare_hword_write_byte(u32 compAddr, u32 destAddr, u16 compVal, u8 destVal) {
address = compAddr;
read_hword_in_memory();
if(hword == compVal) {
address = destAddr;
byte = destVal;
write_byte_in_memory();
}
}

void compare_byte_write_byte(u32 addr, u8 compVal, u8 destVal) {
address = addr;
read_byte_in_memory();
if(byte == compVal) {
byte = destVal;
write_byte_in_memory();
}
}

// Pokemon Snap (U)
void hack_pkm_snap_u() {
// Pass 1st Level and Controller Fix
if(read_hword_in_memory(0x80382D1C, 0) == 0x802C) {
write_byte_in_memory(0x80382D0F, 0);
}
compare_hword_write_byte(0x80382D1C, 0x80382D0F, 0x802C, 0);

//Make Picture selectable
if(read_hword_in_memory(0x801E3184, 0) == 0x2881) {
write_hword_in_memory(0x801E3184, 0x2001);
}
if(read_hword_in_memory(0x801E3186, 0) == 0x0098) {
write_hword_in_memory(0x801E3186, 0x0001);
}
compare_hword_write_hword(0x801E3184, 0x801E3184, 0x2881, 0x2001);
compare_hword_write_hword(0x801E3186, 0x801E3186, 0x0098, 0x0001);
}


// Pokemon Snap (A)
void hack_pkm_snap_a() {
// Pass 1st Level and Controller Fix
if(read_hword_in_memory(0x80382D1C, 0) == 0x802C) {
write_byte_in_memory(0x80382D0F, 0);
}
compare_hword_write_byte(0x80382D1C, 0x80382D0F, 0x802C, 0);

//Make Picture selectable
if(read_hword_in_memory(0x801E3C44, 0) == 0x2881) {
write_hword_in_memory(0x801E3C44, 0x2001);
}
if(read_hword_in_memory(0x801E3C46, 0) == 0x0098) {
write_hword_in_memory(0x801E3C46, 0x0001);
}
compare_hword_write_hword(0x801E3C44, 0x801E3C44, 0x2881, 0x2001);
compare_hword_write_hword(0x801E3C46, 0x801E3C46, 0x0098, 0x0001);
}

// Pokemon Snap (E)
void hack_pkm_snap_e() {
// Pass 1st Level and Controller Fix
if(read_hword_in_memory(0x80381BFC, 0) == 0x802C) {
write_byte_in_memory(0x80381BEF, 0);
}
compare_hword_write_byte(0x80381BFC, 0x80381BEF, 0x802C, 0);

//Make Picture selectable
if(read_hword_in_memory(0x801E3824, 0) == 0x2881) {
write_hword_in_memory(0x801E3824, 0x2001);
}
if(read_hword_in_memory(0x801E3826, 0) == 0x0098) {
write_hword_in_memory(0x801E3826, 0x0001);
}
compare_hword_write_hword(0x801E3824, 0x801E3824, 0x2881, 0x2001);
compare_hword_write_hword(0x801E3826, 0x801E3826, 0x0098, 0x0001);
}

// Pocket Monsters Snap (J)
void hack_pkm_snap_j() {
// Pass 1st Level and Controller Fix
if(read_hword_in_memory(0x8036D22C, 0) == 0x802A) {
write_byte_in_memory(0x8036D21F, 0);
}
compare_hword_write_byte(0x8036D22C, 0x8036D21F, 0x802A, 0);

//Make Picture selectable
if(read_hword_in_memory(0x801E1EC4, 0) == 0x2881) {
write_hword_in_memory(0x801E1EC4, 0x2001);
}
if(read_hword_in_memory(0x801E1EC6, 0) == 0x0098) {
write_hword_in_memory(0x801E1EC6, 0x0001);
}
compare_hword_write_hword(0x801E1EC4, 0x801E1EC4, 0x2881, 0x2001);
compare_hword_write_hword(0x801E1EC6, 0x801E1EC6, 0x0098, 0x0001);
}

// Top Gear Hyper-Bike (E)
void hack_topgear_hb_e() {
//Game Playable Fix (Gent)
if(read_hword_in_memory(0x800021EE, 0) == 0x0001) {
write_byte_in_memory(0x800021EE, 0);
}
compare_hword_write_byte(0x800021EE, 0x800021EE, 0x0001, 0);
}

// Top Gear Hyper-Bike (J)
void hack_topgear_hb_j() {
//Game Playable Fix (Gent)
if(read_hword_in_memory(0x8000225A, 0) == 0x0001) {
write_byte_in_memory(0x8000225A, 0);
}
compare_hword_write_byte(0x8000225A, 0x8000225A, 0x0001, 0);
}

// Top Gear Hyper-Bike (U)
void hack_topgear_hb_u() {
//Game Playable Fix (Gent)
if(read_hword_in_memory(0x800021EA, 0) == 0x0001) {
write_byte_in_memory(0x800021EA, 0);
}
compare_hword_write_hword(0x800021EA, 0x800021EA, 0x0001, 0);
}

// Top Gear Overdrive (E)
void hack_topgear_od_e() {
//Game Playable Fix (Gent)
if(read_hword_in_memory(0x80001AB2, 0) == 0x0001) {
write_byte_in_memory(0x80001AB2, 0);
}
compare_hword_write_hword(0x80001AB2, 0x80001AB2, 0x0001, 0);
}

// Top Gear Overdrive (J)
void hack_topgear_od_j() {
//Game Playable Fix (Gent)
if(read_hword_in_memory(0x80001B4E, 0) == 0x0001) {
write_byte_in_memory(0x80001B4E, 0);
}
hword = 0;
address = 0x800F7BD4;
write_hword_in_memory();
address = 0x800F7BD6;
write_hword_in_memory();
address = 0x80001B4E;
write_hword_in_memory();
}

// Top Gear Overdrive (U)
void hack_topgear_od_u() {
//Game Playable Fix (Gent)
if(read_hword_in_memory(0x80001B4E, 0) == 0x0001) {
write_byte_in_memory(0x80001B4E, 0);
}
compare_hword_write_hword(0x80001B4E, 0x80001B4E, 0x0001, 0);
}

void hack_winback() {
//NOP
}

#ifndef RICE_GFX
// Pilot Wings 64 (U)
void hack_pilotwings_u() {
//Removes annoying shadow that appears below planes
compare_byte_write_byte(0x80263B41, 0x12, 0xFF);
compare_byte_write_byte(0x802643C1, 0x12, 0xFF);
compare_byte_write_byte(0x80264581, 0x12, 0xFF);
compare_byte_write_byte(0x80263FC1, 0x12, 0xFF);
compare_byte_write_byte(0x80263E81, 0x12, 0xFF);
compare_byte_write_byte(0x80263E41, 0x12, 0xFF);
compare_byte_write_byte(0x80264181, 0x12, 0xFF);
compare_byte_write_byte(0x80264381, 0x12, 0xFF);
compare_byte_write_byte(0x80264281, 0x12, 0xFF);
compare_byte_write_byte(0x802639C1, 0x20, 0xFF);
compare_byte_write_byte(0x802640C1, 0x20, 0xFF);
compare_byte_write_byte(0x80264541, 0x20, 0xFF);
compare_byte_write_byte(0x80264201, 0x20, 0xFF);
compare_byte_write_byte(0x80263D81, 0x20, 0xFF);
compare_byte_write_byte(0x80263F81, 0x20, 0xFF);
compare_byte_write_byte(0x80263A81, 0x29, 0xFF);
compare_byte_write_byte(0x80264101, 0x29, 0xFF);
compare_byte_write_byte(0x80263E01, 0x29, 0xFF);
compare_byte_write_byte(0x80264201, 0x29, 0xFF);
compare_byte_write_byte(0x80264441, 0x29, 0xFF);
compare_byte_write_byte(0x80263F81, 0x29, 0xFF);
compare_byte_write_byte(0x802647C1, 0x29, 0xFF);
compare_byte_write_byte(0x80264941, 0x29, 0xFF);
compare_byte_write_byte(0x80264281, 0x29, 0xFF);
compare_byte_write_byte(0x802639C1, 0x3D, 0xFF);
compare_byte_write_byte(0x802641C1, 0x3D, 0xFF);
compare_byte_write_byte(0x80263D41, 0x3D, 0xFF);
compare_byte_write_byte(0x80263EC1, 0x3D, 0xFF);
compare_byte_write_byte(0x80263F01, 0x3D, 0xFF);
}
*/

// Pilot Wings 64 (E)
void hack_pilotwings_e() {
//Removes annoying shadow that appears below planes
compare_byte_write_byte(0x80264361, 0x12, 0xFF);
compare_byte_write_byte(0x80264BE1, 0x12, 0xFF);
compare_byte_write_byte(0x80264DA1, 0x12, 0xFF);
compare_byte_write_byte(0x802647E1, 0x12, 0xFF);
compare_byte_write_byte(0x802646A1, 0x12, 0xFF);
compare_byte_write_byte(0x80264661, 0x12, 0xFF);
compare_byte_write_byte(0x802649A1, 0x12, 0xFF);
compare_byte_write_byte(0x80264BA1, 0x12, 0xFF);
compare_byte_write_byte(0x80264AA1, 0x12, 0xFF);
compare_byte_write_byte(0x802641E1, 0x20, 0xFF);
compare_byte_write_byte(0x802648E1, 0x20, 0xFF);
compare_byte_write_byte(0x80264D61, 0x20, 0xFF);
compare_byte_write_byte(0x80264A21, 0x20, 0xFF);
compare_byte_write_byte(0x802645A1, 0x20, 0xFF);
compare_byte_write_byte(0x802647A1, 0x20, 0xFF);
compare_byte_write_byte(0x802642A1, 0x29, 0xFF);
compare_byte_write_byte(0x80264921, 0x29, 0xFF);
compare_byte_write_byte(0x80264621, 0x29, 0xFF);
compare_byte_write_byte(0x80264A21, 0x29, 0xFF);
compare_byte_write_byte(0x80264C61, 0x29, 0xFF);
compare_byte_write_byte(0x802647A1, 0x29, 0xFF);
compare_byte_write_byte(0x80264FE1, 0x29, 0xFF);
compare_byte_write_byte(0x80265161, 0x29, 0xFF);
compare_byte_write_byte(0x80264AA1, 0x29, 0xFF);
compare_byte_write_byte(0x802641E1, 0x3D, 0xFF);
compare_byte_write_byte(0x802649E1, 0x3D, 0xFF);
compare_byte_write_byte(0x80264561, 0x3D, 0xFF);
compare_byte_write_byte(0x802646E1, 0x3D, 0xFF);
compare_byte_write_byte(0x80264721, 0x3D, 0xFF);
}

// Pilot Wings 64 (J)
void hack_pilotwings_j() {
//Removes annoying shadow that appears below planes
compare_byte_write_byte(0x802639B1, 0x12, 0xFF);
compare_byte_write_byte(0x80264231, 0x12, 0xFF);
compare_byte_write_byte(0x802643F1, 0x12, 0xFF);
compare_byte_write_byte(0x80263E31, 0x12, 0xFF);
compare_byte_write_byte(0x80263CF1, 0x12, 0xFF);
compare_byte_write_byte(0x80263CB1, 0x12, 0xFF);
compare_byte_write_byte(0x80263FF1, 0x12, 0xFF);
compare_byte_write_byte(0x802641F1, 0x12, 0xFF);
compare_byte_write_byte(0x802640F1, 0x12, 0xFF);
compare_byte_write_byte(0x80263831, 0x20, 0xFF);
compare_byte_write_byte(0x80263F31, 0x20, 0xFF);
compare_byte_write_byte(0x802643B1, 0x20, 0xFF);
compare_byte_write_byte(0x80264071, 0x20, 0xFF);
compare_byte_write_byte(0x80263BF1, 0x20, 0xFF);
compare_byte_write_byte(0x80263DF1, 0x20, 0xFF);
compare_byte_write_byte(0x802638F1, 0x29, 0xFF);
compare_byte_write_byte(0x80263F71, 0x29, 0xFF);
compare_byte_write_byte(0x80263C71, 0x29, 0xFF);
compare_byte_write_byte(0x80264071, 0x29, 0xFF);
compare_byte_write_byte(0x802642B1, 0x29, 0xFF);
compare_byte_write_byte(0x80263DF1, 0x29, 0xFF);
compare_byte_write_byte(0x80264631, 0x29, 0xFF);
compare_byte_write_byte(0x802647B1, 0x29, 0xFF);
compare_byte_write_byte(0x802640F1, 0x29, 0xFF);
compare_byte_write_byte(0x80263831, 0x3D, 0xFF);
compare_byte_write_byte(0x80264031, 0x3D, 0xFF);
compare_byte_write_byte(0x80263BB1, 0x3D, 0xFF);
compare_byte_write_byte(0x80263D31, 0x3D, 0xFF);
compare_byte_write_byte(0x80263D71, 0x3D, 0xFF);
}
#endif


// Return a pointer to the game specific hack or 0 if there isn't any
void *GetGameSpecificHack() {
return game_specific_hack;
}

// Game specific hack detection via CRC
void GameSpecificHackSetup() {
/*unsigned int curCRC[2];
unsigned int curCRC[2];
ROMCache_read((u8*)&curCRC[0], 0x10, sizeof(unsigned int)*2);
//print_gecko("CRC values %08X %08X\r\n", curCRC[0], curCRC[1]);
if(curCRC[0] == 0xCA12B547 && curCRC[1] == 0x71FA4EE4) {
game_specific_hack = &hack_pkm_snap_u;
}
Expand Down Expand Up @@ -178,7 +290,24 @@ void GameSpecificHackSetup() {
else if(curCRC[0] == 0xD741CD80 && curCRC[1] == 0xACA9B912) {
game_specific_hack = &hack_topgear_od_u;
}
else {*/
#ifndef RICE_GFX
else if((curCRC[0] == 0xED98957E && curCRC[1] == 0x8242DCAC) ||
(curCRC[0] == 0xD5898CAF && curCRC[1] == 0x6007B65B) ||
(curCRC[0] == 0x1FA056E0 && curCRC[1] == 0xA4B9946A)) {
game_specific_hack = &hack_winback;
}
else if(curCRC[0] == 0xC851961C && curCRC[1] == 0x78FCAAFA) {
game_specific_hack = &hack_pilotwings_u;
}
else if(curCRC[0] == 0x09CC4801 && curCRC[1] == 0xE42EE491) {
game_specific_hack = &hack_pilotwings_j;
}
else if(curCRC[0] == 0x1AA05AD5 && curCRC[1] == 0x46F52D80) {
game_specific_hack = &hack_pilotwings_e;
}
#endif
else {
game_specific_hack = 0;
/*}*/
}
//print_gecko("Applied a hack? %s\r\n", game_specific_hack ? "yes" : "no");
}
1 change: 1 addition & 0 deletions main/gamehacks.h
Expand Up @@ -29,4 +29,5 @@ void *GetGameSpecificHack();
// Game specific hack detection via CRC
void GameSpecificHackSetup();

void hack_winback();
#endif

0 comments on commit 546144d

Please sign in to comment.