Skip to content

Commit

Permalink
Fixed indexed draws, now working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOfficialFloW committed Sep 19, 2020
1 parent fa025a7 commit 107a98f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This is an experimental plugin for [Adrenaline](https://github.com/TheOfficialFl

Please help testing games and filling out the [spreadsheet](https://docs.google.com/spreadsheets/d/1aZlmKwELcdpCb9ezI5iRfgcX9hoGxgL4tNC-673aKqk/edit#gid=0).

## Changelog v0.17.1

- Fixed indexed draws which caused some games to render at 480x272 only.

## Changelog v0.17

- Fixed artifacts, flickering and black screens in some games.
Expand Down
70 changes: 33 additions & 37 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,46 +459,42 @@ void patchGeList(u32 *list, u32 *stall) {
u16 lower = 0;
u16 upper = count;
if ((state.vertex_type & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
lower = 0;
upper = 0;
GetIndexBounds((void *)state.index_addr, count, state.vertex_type, &lower, &upper);
// Fixes menu rendering of Harvest Moon
upper += 1;
}

// Indexed draws causes glitches in Metal Gear Solid
// Maybe implementation is wrong? Disabling for now
if ((state.vertex_type & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_NONE) {
int pos = (state.vertex_type & GE_VTYPE_POS_MASK) >> GE_VTYPE_POS_SHIFT;
int pos_size = possize[pos] / 3;

// TODO: we may patch the same vertex again and again...
int i;
for (i = lower; i < upper; i++) {
int j;
for (j = 0; j < 2; j++) {
u32 addr = state.vertex_addr + i * vertex_size + pos_off + j * pos_size;
switch (pos_size) {
case 2:
if (*(short *)addr == 480 || *(short *)addr == 960)
*(short *)addr = 960;
else if (*(short *)addr == 272 || *(short *)addr == 544)
*(short *)addr = 544;
else if (*(short *)addr > -2048 && *(short *)addr < 2048)
*(short *)addr *= 2;
break;
case 4:
t.i = *(u32 *)addr;
if (t.f == 480 || t.f == 960) {
t.f = 960;
*(u32 *)addr = t.i;
} else if (t.f == 272 || t.f == 544) {
t.f = 544;
*(u32 *)addr = t.i;
} else if (t.f > -2048 && t.f < 2048) {
t.f *= 2;
*(u32 *)addr = t.i;
}
break;
}
int pos = (state.vertex_type & GE_VTYPE_POS_MASK) >> GE_VTYPE_POS_SHIFT;
int pos_size = possize[pos] / 3;

// TODO: we may patch the same vertex again and again...
int i;
for (i = lower; i < upper; i++) {
int j;
for (j = 0; j < 2; j++) {
u32 addr = state.vertex_addr + i * vertex_size + pos_off + j * pos_size;
switch (pos_size) {
case 2:
if (*(short *)addr == 480 || *(short *)addr == 960)
*(short *)addr = 960;
else if (*(short *)addr == 272 || *(short *)addr == 544)
*(short *)addr = 544;
else if (*(short *)addr > -2048 && *(short *)addr < 2048)
*(short *)addr *= 2;
break;
case 4:
t.i = *(u32 *)addr;
if (t.f == 480 || t.f == 960) {
t.f = 960;
*(u32 *)addr = t.i;
} else if (t.f == 272 || t.f == 544) {
t.f = 544;
*(u32 *)addr = t.i;
} else if (t.f > -2048 && t.f < 2048) {
t.f *= 2;
*(u32 *)addr = t.i;
}
break;
}
}
}
Expand Down

0 comments on commit 107a98f

Please sign in to comment.