Skip to content

Commit

Permalink
some ric fixes (Xeeynamo#1490)
Browse files Browse the repository at this point in the history
This fixes a few RIC crashes, gets it up to the point that the
blueprints need to be loaded
  • Loading branch information
sozud authored Aug 9, 2024
1 parent 2e181ea commit 301f312
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 50 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ set(SOURCE_FILES_RIC
src/ric/d_00000.c
src/ric/d_188F4.c
src/ric/d_194B0.c
src/ric/d_19BE0.c
src/ric/d_19EE0.c
src/ric/spriteparts.c
src/ric/1CB04.c
Expand All @@ -237,7 +236,6 @@ set(SOURCE_FILES_RIC
src/ric/bss.c
src/ric/d_18568.c
src/ric/d_18C40.c
src/ric/d_19B50.c
src/ric/d_19C70.c
)

Expand Down
2 changes: 0 additions & 2 deletions config/splat.us.ric.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ segments:
- [0x18A6C, assets, factory_blueprint, g_RicFactoryBlueprints]
- [0x18C40, .data, d_18C40]
- [0x194B0, .data, d_194B0]
- [0x19B50, .data, d_19B50]
- [0x19BE0, .data, d_19BE0]
- [0x19C70, .data, d_19C70]
- [0x19EE0, .data, d_19EE0]
- [0x1A444, .rodata, 1AC60] #UpdateEntityRichter
Expand Down
4 changes: 4 additions & 0 deletions src/dra/4A538.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,11 @@ void RenderEntities(void) {
spriteData = g_api.o.unk2c[r->spriteSheetIdx];
#endif
} else if ((r->animSet & 0x7FFF) == 16) {
#ifdef VERSION_PC
spriteData = ((u8**)g_PlOvlSpritesheet)[r->spriteSheetIdx];
#else
spriteData = ((u8**)SPRITESHEET_PTR)[r->spriteSheetIdx];
#endif
} else {
// see above note
#ifdef VERSION_PSP
Expand Down
2 changes: 0 additions & 2 deletions src/pc/pl_arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ static u8* sprite_data = NULL;
void InitPlayerArc(const struct FileUseContent* file) {
int i;

g_PlayableCharacter = PLAYER_ALUCARD;

if (sprite_data) {
free(sprite_data);
}
Expand Down
13 changes: 9 additions & 4 deletions src/pc/sim_pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ int readToBuf(const char* filename, char* dest) {
FILE* file = fopen(filename, "rb");

if (file == NULL) {
printf("Failed to open file");
printf("Failed to open file %s\n", filename);
exit(1);
return 1;
}

Expand Down Expand Up @@ -355,7 +356,9 @@ s32 LoadFileSim(s32 fileId, SimFileType type) {
break;
case 5:
InitPlayerRic();
return 0;
sim.path = "BIN/RIC.BIN";
sim.kind = 99;
break;
case 12:
sim.path = "ST/SEL/F_SEL.BIN";
sim.kind = SIM_STAGE_CHR;
Expand Down Expand Up @@ -395,7 +398,8 @@ s32 LoadFileSim(s32 fileId, SimFileType type) {
sim.size = D_800A036C[actualFileId].size;
sim.addr = D_800A036C[actualFileId].addr;
sim.kind = SIM_VH;
return readToBuf(sim.path, sim.addr);
snprintf(buf, sizeof(buf), "disks/us/%s", sim.path);
return readToBuf(buf, sim.addr);
} else {
sim.path = smolbuf;
snprintf(smolbuf, sizeof(smolbuf), "ST/%s/SD_ZK%s.VH",
Expand Down Expand Up @@ -432,7 +436,8 @@ s32 LoadFileSim(s32 fileId, SimFileType type) {
sim.size = D_800A036C[actualFileId].size;
sim.addr = D_800A036C[actualFileId].addr;
sim.kind = SIM_VB;
return readToBuf(sim.path, sim.addr);
snprintf(buf, sizeof(buf), "disks/us/%s", sim.path);
return readToBuf(buf, sim.addr);
} else {
sim.path = smolbuf;
snprintf(smolbuf, sizeof(smolbuf), "ST/%s/SD_ZK%s.VB",
Expand Down
24 changes: 17 additions & 7 deletions src/pc/sotn.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ static bool InitBlueprintData(struct FileAsString* file);

s32 func_800EDB58(u8 primType, s32 count);

extern FactoryBlueprint g_RicFactoryBlueprints[78];

bool InitGame(void) {
if (!InitPlatform()) {
return false;
Expand All @@ -107,7 +109,7 @@ bool InitGame(void) {
api.AllocPrimitives = AllocPrimitives;
api.CheckCollision = CheckCollision;
api.func_80102CD8 = NULL;
api.UpdateAnim = NULL;
api.UpdateAnim = UpdateAnim;
api.SetSpeedX = NULL;
api.GetFreeEntity = NULL;
api.GetEquipProperties = NULL;
Expand Down Expand Up @@ -158,7 +160,7 @@ bool InitGame(void) {
api.func_80133950 = NULL;
api.func_800F27F4 = NULL;
api.func_800FF110 = NULL;
api.func_800FD664 = NULL;
api.func_800FD664 = func_800FD664;
api.func_800FD5BC = NULL;
api.LearnSpell = NULL;
api.DebugInputWait = DebugInputWait;
Expand Down Expand Up @@ -204,10 +206,15 @@ bool InitGame(void) {
return false;
}

// TODO different between RIC and ARC
if (!FileAsString(
InitBlueprintData, "assets/dra/factory_blueprint.json", NULL)) {
ERRORF("failed to init blueprint data");
if (!FileAsString(InitBlueprintData, "assets/dra/factory_blueprint.json",
g_FactoryBlueprints)) {
ERRORF("failed to init dra blueprint data");
return false;
}

if (!FileAsString(InitBlueprintData, "assets/ric/factory_blueprint.json",
g_RicFactoryBlueprints)) {
ERRORF("failed to init ric blueprint data");
return false;
}

Expand Down Expand Up @@ -422,9 +429,12 @@ static bool InitBlueprintData(struct FileAsString* file) {
}

int len = cJSON_GetArraySize(array);

FactoryBlueprint* blueprints = (FactoryBlueprint*)file->param;

for (int i = 0; i < len; i++) {
u32 bits = 0;
FactoryBlueprint* item = &g_FactoryBlueprints[i];
FactoryBlueprint* item = &blueprints[i];
cJSON* jitem = cJSON_GetArrayItem(array, i);
DO_ITEM("childId", jitem, item, item->childId);
DO_ITEM("unk1", jitem, item, item->unk1);
Expand Down
4 changes: 2 additions & 2 deletions src/pc/stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,5 @@ u16* func_80106A28(u32 arg0, u16 kind) {

// ric stubs

SubweaponDef D_80154688[1];
FactoryBlueprint g_RicFactoryBlueprints[1];
SubweaponDef D_80154688[31];
FactoryBlueprint g_RicFactoryBlueprints[78];
4 changes: 4 additions & 0 deletions src/ric/20920.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ void func_8015CD98(s32 velocityX) {
PLAYER.velocityY = 0;
g_Player.unk44 = 0;
RicSetPlayerStep(0);
#ifdef VERSION_PC
// I think this is uninitialized and works by accident
g_CurrentEntity = &PLAYER;
#endif
func_8015C920(&D_801553BC);
}

Expand Down
3 changes: 3 additions & 0 deletions src/ric/24788.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "ric.h"

Entity* RicGetFreeEntity(s16 start, s16 end);
Entity* RicGetFreeEntityReverse(s16 start, s16 end);

// Similar to same function in DRA
void RicEntityEntFactory(Entity* self) {
Entity* newEntity;
Expand Down
24 changes: 24 additions & 0 deletions src/ric/2A060.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ void func_80166784(Entity* self) {
Primitive* prim;
s16 angle;
s32 var_s3;
#ifdef VERSION_PC
// this can still be uninitialized when we get past the D_80155B2C section
// not every combo of directions is covered
s32 var_s4 = 0;
#else
s32 var_s4;
#endif
s32 var_s5;
s32 temp_s6;
s32 var_s7;
Expand Down Expand Up @@ -516,7 +522,16 @@ void func_80166784(Entity* self) {
PLAYER.animFrameDuration == 14)) {
self->palette = 0x813C;
} else {
// animFrameDuration can be -1 apparently.
// todo this should read the previous element out of bounds?
#ifdef VERSION_PC
if (PLAYER.animFrameDuration >= 0) {
self->palette =
D_80155C70[PLAYER.animFrameDuration % 3];
}
#else
self->palette = D_80155C70[PLAYER.animFrameDuration % 3];
#endif
}
}
} else {
Expand Down Expand Up @@ -568,7 +583,16 @@ void func_80166784(Entity* self) {
PLAYER.animFrameDuration == 14) {
self->palette = 0x813C;
} else {
// animFrameDuration can be -1 apparently.
// todo this should read the previous element out of bounds?
#ifdef VERSION_PC
if (PLAYER.animFrameDuration >= 0) {
self->palette =
D_80155C70[PLAYER.animFrameDuration % 3];
}
#else
self->palette = D_80155C70[PLAYER.animFrameDuration % 3];
#endif
}
break;
}
Expand Down
16 changes: 6 additions & 10 deletions src/ric/bss.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "common.h"
#include "game.h"

u32 D_80173B64;
u32 D_80173B68[1280];
Expand All @@ -8,10 +9,7 @@ u32 D_80174F70;
u32 D_80174F74;
u32 D_80174F78;
static u32 g_DebugWaitInfoTimer;
u32 D_80174F80;
u32 D_80174F84;
u32 D_80174F88;
u32 D_80174F8C[8];
u32 D_80174F80[11];
u8 D_80174FAC[4];
u8 D_80174FB0[4];
u8 D_80174FB4[4];
Expand All @@ -22,8 +20,7 @@ u16 D_80174FFC;
u16 D_80174FFE;
u16 D_80175000;
u16 D_80175002[63];
u16 D_80175080;
u16 D_80175082;
u32 D_80175080;
u32 D_80175084;
u32 D_80175088[512];
u32 D_80175888;
Expand All @@ -36,10 +33,9 @@ u32 D_801758AC;
u32 D_801758B0[7];
u32 D_801758CC;
u32 D_801758D0[4];
u16 D_801758E0;
u16 D_801758E2;
u16 D_801758E4;
u16 D_801758E6[53];
ButtonComboState D_801758E0;
ButtonComboState D_801758E4;
u16 D_801758E6[52];
u16 D_80175950;
u16 D_80175952;
u16 D_80175954;
Expand Down
6 changes: 5 additions & 1 deletion src/ric/d_194B0.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,9 @@ Point32 D_80155AE4[] = {
0xFFFE0000, 0xFFFE8000, 0x00008000, 0x00018000, 0x00008000, 0xFFFE8000};

s32 D_80155B2C[][9] = {
1, 1, 5, 6, 0, 1, 1, 0, 0,
{1, 1, 5, 6, 0, 1, 1, 0, 0}, {2, 5, 2, 0, 7, 2, 0, 2, 0},
{3, 6, 0, 3, 8, 0, 3, 0, 3}, {4, 0, 7, 8, 4, 0, 0, 4, 4},
{5, 5, 5, 0, 0, 5, 1, 2, 0}, {6, 6, 0, 6, 0, 1, 6, 0, 3},
{7, 0, 7, 0, 7, 1, 0, 7, 4}, {8, 0, 0, 8, 8, 4, 3, 7, 8},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
};
9 changes: 0 additions & 9 deletions src/ric/d_19B50.c

This file was deleted.

9 changes: 0 additions & 9 deletions src/ric/d_19BE0.c

This file was deleted.

4 changes: 2 additions & 2 deletions src/ric/ric.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ extern s16 D_80155A78[];
extern Point32 D_80155AAC[];
extern Point32 D_80155AE4[];
extern s32 D_80155B2C[][9];
extern s16 D_80155C70[];
extern s16 D_80155C70[4];
extern s16 D_80155C78[];
extern u16 D_80155C98[];
extern s16 D_80155CB8[];
Expand Down Expand Up @@ -260,7 +260,7 @@ extern u8 D_80174FB8;
extern Point16 D_80174FBC[];
extern s32 D_80174FFC;
extern Point16 D_80175000[32];
extern s32 D_80175080;
extern u32 D_80175080;
extern s32 D_80175084;
extern Point16 D_80175088[][128];
extern s32 D_80175888;
Expand Down

0 comments on commit 301f312

Please sign in to comment.