Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed hp & anju #9

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <WTypesbase.h>
#endif
#include <time.h>
#include "../../Cvar.h"

#define GFX_API_NAME "SDL2 - OpenGL"

Expand Down Expand Up @@ -132,6 +133,8 @@ static int frameDivisor = 1;
static void gfx_sdl_init(const char *game_name, bool start_in_fullscreen) {
SDL_Init(SDL_INIT_VIDEO);

SDL_EventState(SDL_DROPFILE, SDL_ENABLE);

SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

Expand Down Expand Up @@ -227,8 +230,11 @@ static void gfx_sdl_onkeyup(int scancode) {
}
}

extern "C" void LoadItemLocations(const char* spoilerFileName);

static void gfx_sdl_handle_events(void) {
SDL_Event event;
char* dropped_filedir;
while (SDL_PollEvent(&event)) {
SohImGui::EventImpl event_impl;
event_impl.sdl = { &event };
Expand All @@ -249,6 +255,11 @@ static void gfx_sdl_handle_events(void) {
window_height = event.window.data2;
}
break;
case SDL_DROPFILE:
{
LoadItemLocations(event.drop.file);
break;
}
case SDL_QUIT:
exit(0);
}
Expand Down
6 changes: 0 additions & 6 deletions libultraship/libultraship/SohImGuiImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,12 +813,6 @@ namespace SohImGui {
ImGui::EndMenu();
}

if (ImGui::BeginMenu("Randomizer"))
{
EnhancementCheckbox("Enable Randomizer", "gRandomizer");
ImGui::EndMenu();
}

if (ImGui::BeginMenu("Developer Tools"))
{
EnhancementCheckbox("OoT Debug Mode", "gDebugEnabled");
Expand Down
1 change: 0 additions & 1 deletion soh/randomizerTypes.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once


typedef enum {
LINKS_POCKET,
QUEEN_GOHMA,
Expand Down
105 changes: 83 additions & 22 deletions soh/soh/Enhancements/randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,56 @@
#include <variables.h>
#include <macros.h>
#include <objects/gameplay_keep/gameplay_keep.h>
#include <objects/object_gi_bomb_1/object_gi_bomb_1.h>
#include <objects/object_gi_letter/object_gi_letter.h>
#include <functions.h>
#include <Cvar.h>
#include <textures/icon_item_static/icon_item_static.h>
#include <textures/icon_item_24_static/icon_item_24_static.h>

using json = nlohmann::json;

Randomizer::Randomizer() {
//todo something?
}

Randomizer::~Randomizer() {
this->itemLocations.clear();
}

/* std::unordered_map<std::string, Sprite> gSeedTextures = {
{ "Deku Stick", { gHookshotIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Deku Nut", { gDekuNutIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Bow", { gFairyBowIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Slingshot", { gFairySlingshotIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Fairy Ocarina", { gFairyOcarinaIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Bombchu", { gBombchuIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Longshot", { gLongshotIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Boomerang", { gBoomerangIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Lens of Truth", { gLensofTruthIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Beans", { gMagicBeansIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Megaton Hammer", { gMegatonHammerIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Bottled Fish", { gFishIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Bottled Milk", { gMilkFullIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Mask of Truth", { gMaskofTruthIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "SOLD OUT", { gSoldOutIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Cucco", { gCuccoIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Mushroom", { gOddMushroomIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Saw", { gPoachersSawIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Frog", { gEyeBallFrogIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Master Sword", { gMasterSwordIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Mirror Shield", { gMirrorShieldIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Kokiri Tunic", { gKokiriTunicIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Hover Boots", { gHoverBootsIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Silver Gauntlets", { gSilverGauntletsIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Gold Scale", { gGoldenScaleIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Stone of Agony", { gStoneOfAgonyIconTex, 24, 24, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Skull Token", { gGoldSkulltulaIconTex, 24, 24, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Heart Container", { gHeartContainerIconTex, 24, 24, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Boss Key", { gBossKeyIconTex, 24, 24, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Compass", { gCompassIconTex, 24, 24, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Map", { gDungeonMapIconTex, 24, 24, G_IM_FMT_RGBA, G_IM_SIZ_32b } },
{ "Big Magic", { gBigMagicJarIconTex, 24, 24, G_IM_FMT_RGBA, G_IM_SIZ_32b } }
};*/

std::unordered_map<std::string, RandomizerCheck> SpoilerfileCheckNameToEnum = {
{"Links Pocket", LINKS_POCKET},
{"Queen Gohma", QUEEN_GOHMA},
Expand Down Expand Up @@ -643,41 +681,64 @@ s16 Randomizer::GetItemModelFromId(s16 itemId) {
return itemIdToModel[itemId];
}

void Randomizer::LoadItemLocations() {
void Randomizer::LoadItemLocations(const char* spoilerFileName) {
// bandaid until new save stuff happens
ParseItemLocations("");
ParseItemLocations(spoilerFileName);

for(auto itemLocation : gSaveContext.itemLocations) {
this->itemLocations[itemLocation.check] = itemLocation.get;
}
}

void Randomizer::ParseItemLocations(std::string spoilerFileName) {
void Randomizer::ParseItemLocations(const char* spoilerFileName) {
// todo pull this in from cvar or something
std::ifstream spoilerFileStream("spoiler.json");
std::ifstream spoilerFileStream(spoilerFileName);
if (!spoilerFileStream)
return;
json spoilerFileJson;
spoilerFileStream >> spoilerFileJson;
json locationsJson = spoilerFileJson["locations"];
int index = 0;
for (auto it = locationsJson.begin(); it != locationsJson.end(); ++it) {
if (it->is_structured()) {
json itemJson = *it;
for (auto itemit = itemJson.begin(); itemit != itemJson.end(); ++itemit) {
// todo handle prices
if (itemit.key() == "item") {

gSaveContext.itemLocations[index].check = SpoilerfileCheckNameToEnum[it.key()];
gSaveContext.itemLocations[index].get = SpoilerfileGetNameToEnum[itemit.value()];
bool success = false;

try {
json spoilerFileJson;
spoilerFileStream >> spoilerFileJson;
json locationsJson = spoilerFileJson["locations"];
json hashJson = spoilerFileJson["file_hash"];

int index = 0;
for (auto it = hashJson.begin(); it != hashJson.end(); ++it) {
//gSaveContext.seedIcons[index] = gSeedTextures[it.value()];
index++;
}

index = 0;
for (auto it = locationsJson.begin(); it != locationsJson.end(); ++it) {
if (it->is_structured()) {
json itemJson = *it;
for (auto itemit = itemJson.begin(); itemit != itemJson.end(); ++itemit) {
// todo handle prices
if (itemit.key() == "item") {

gSaveContext.itemLocations[index].check = SpoilerfileCheckNameToEnum[it.key()];
gSaveContext.itemLocations[index].get = SpoilerfileGetNameToEnum[itemit.value()];
}
}
} else {
gSaveContext.itemLocations[index].check = SpoilerfileCheckNameToEnum[it.key()];
gSaveContext.itemLocations[index].get = SpoilerfileGetNameToEnum[it.value()];
}
} else {
gSaveContext.itemLocations[index].check = SpoilerfileCheckNameToEnum[it.key()];
gSaveContext.itemLocations[index].get = SpoilerfileGetNameToEnum[it.value()];

index++;
}

index++;
Audio_PlaySoundGeneral(NA_SE_SY_CORRECT_CHIME, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
success = true;
} catch (const std::exception& e) {
Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
return;
}

if (success) {
CVar_SetS32("gRandomizer", 1);
}
}

Expand Down
9 changes: 4 additions & 5 deletions soh/soh/Enhancements/randomizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
#define RANDOMIZER_H

#include <unordered_map>
#include <string>
#include "../../include/ultra64.h"
#include "../../include/z64item.h"
#include <randomizerTypes.h>
#include <z64item.h>
#include <z64math.h>

class Randomizer {
private:
Expand All @@ -19,8 +18,8 @@ class Randomizer {
~Randomizer();

s16 GetItemModelFromId(s16 itemId);
void LoadItemLocations();
void ParseItemLocations(std::string spoilerfilename);
void LoadItemLocations(const char* spoilerFileName);
void ParseItemLocations(const char* spoilerFileName);
GetItemID GetItemFromActor(s16 actorId, GetItemID ogItemId);
GetItemID GetItemFromSceneAndParams(s16 sceneNum, s16 actorParams, GetItemID ogItemId);
GetItemID GetItemFromSceneParamsAndHomePos(s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ, GetItemID ogItemId);
Expand Down
8 changes: 4 additions & 4 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,12 +1000,12 @@ extern "C" s16 GetItemModelFromId(s16 itemId) {
return OTRGlobals::Instance->gRandomizer->GetItemModelFromId(itemId);
}

extern "C" void LoadItemLocations() {
OTRGlobals::Instance->gRandomizer->LoadItemLocations();
extern "C" void LoadItemLocations(const char* spoilerFileName) {
OTRGlobals::Instance->gRandomizer->LoadItemLocations(spoilerFileName);
}

extern "C" void ParseItemLocations(const char* spoilerfilename) {
OTRGlobals::Instance->gRandomizer->ParseItemLocations(spoilerfilename);
extern "C" void ParseItemLocations(const char* spoilerFileName) {
OTRGlobals::Instance->gRandomizer->ParseItemLocations(spoilerFileName);
}

extern "C" GetItemID GetItemFromActor(s16 actorId, GetItemID ogItemId) {
Expand Down
1 change: 1 addition & 0 deletions soh/soh/OTRGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ int AudioPlayer_GetDesiredBuffered(void);
void AudioPlayer_Play(const uint8_t* buf, uint32_t len);
void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples);
int Controller_ShouldRumble(size_t i);
void LoadItemLocations((const char* spoilerFileName);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

((

if that's what was causing the issue this whole time that's really silly

void ParseItemLocations(const char* spoilerfilename);
GetItemID GetItemFromActor(s16 actorId, GetItemID ogItemId);
GetItemID GetItemFromSceneAndParams(s16 sceneNum, s16 actorParams, GetItemID ogItemId);
Expand Down
11 changes: 3 additions & 8 deletions soh/src/code/z_en_item00.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,6 @@ void EnItem00_SetupAction(EnItem00* this, EnItem00ActionFunc actionFunc) {
this->actionFunc = actionFunc;
}

s32 Item00_GetRandomizedItemId(EnItem00* this, s16 sceneNum, s16 actorParams) {
s32 itemId = GetItemFromSceneAndParams(sceneNum, this->actor.params, this->getItemId);
return itemId;
}

void EnItem00_Init(Actor* thisx, GlobalContext* globalCtx) {
EnItem00* this = (EnItem00*)thisx;
s32 pad;
Expand Down Expand Up @@ -697,7 +692,7 @@ void EnItem00_Init(Actor* thisx, GlobalContext* globalCtx) {
}

if ((getItemId != GI_NONE) && !Actor_HasParent(&this->actor, globalCtx)) {
getItemId = Item00_GetRandomizedItemId(this, globalCtx->sceneNum, this->ogParams);
getItemId = GetItemFromSceneAndParams(this, globalCtx->sceneNum, this->ogParams);
func_8002F554(&this->actor, globalCtx, getItemId);
}

Expand Down Expand Up @@ -1058,7 +1053,7 @@ void EnItem00_Update(Actor* thisx, GlobalContext* globalCtx) {

if ((getItemId != GI_NONE) && !Actor_HasParent(&this->actor, globalCtx)) {
if (gSaveContext.n64ddFlag) {
getItemId = Item00_GetRandomizedItemId(this, globalCtx->sceneNum, this->ogParams);
getItemId = GetItemFromSceneAndParams(globalCtx->sceneNum, this->ogParams, getItemId);
}
func_8002F554(&this->actor, globalCtx, getItemId);
}
Expand Down Expand Up @@ -1330,7 +1325,7 @@ void EnItem00_DrawHeartPiece(EnItem00* this, GlobalContext* globalCtx) {
if (gSaveContext.n64ddFlag) {
f32 mtxScale = 16.0f;
Matrix_Scale(mtxScale, mtxScale, mtxScale, MTXMODE_APPLY);
GetItem_Draw(globalCtx, GetItemModelFromId(Item00_GetRandomizedItemId(this, gGlobalCtx->sceneNum, this->actor.params)));
GetItem_Draw(globalCtx, GetItemModelFromId(GetItemFromSceneAndParams(gGlobalCtx->sceneNum, this->ogParams, GI_HEART_PIECE)));
} else {
s32 pad;

Expand Down
14 changes: 4 additions & 10 deletions soh/src/overlays/actors/ovl_En_Niw_Lady/z_en_niw_lady.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,6 @@ void func_80ABA244(EnNiwLady* this, GlobalContext* globalCtx) {
}
}

s32 NiwLady_GetRandomizedItemId(EnNiwLady* this, GetItemID ogId) {
s32 itemId = GetItemFromActor(this->actor.id, ogId);
return itemId;
}

void func_80ABA654(EnNiwLady* this, GlobalContext* globalCtx) {
if (this->unk_262 == Message_GetState(&globalCtx->msgCtx) && Message_ShouldAdvance(globalCtx)) {
Message_CloseTextbox(globalCtx);
Expand All @@ -309,9 +304,9 @@ void func_80ABA654(EnNiwLady* this, GlobalContext* globalCtx) {
if (!(gSaveContext.itemGetInf[0] & 0x1000)) {
this->actor.parent = NULL;

this->getItemId = NiwLady_GetRandomizedItemId(this, GI_BOTTLE);
this->getItemId = GetItemFromActor(this->actor.id, GI_BOTTLE);

func_8002F434(&this->actor, globalCtx, NiwLady_GetRandomizedItemId(this, GI_BOTTLE), 100.0f, 50.0f);
func_8002F434(&this->actor, globalCtx, this->getItemId, 100.0f, 50.0f);
this->actionFunc = func_80ABAC00;
return;
}
Expand Down Expand Up @@ -393,7 +388,7 @@ void func_80ABA9B8(EnNiwLady* this, GlobalContext* globalCtx) {
case 0:
Message_CloseTextbox(globalCtx);
this->actor.parent = NULL;
func_8002F434(&this->actor, globalCtx, NiwLady_GetRandomizedItemId(this, GI_POCKET_EGG), 200.0f,
func_8002F434(&this->actor, globalCtx, GetItemFromActor(this->actor.id, GI_POCKET_EGG), 200.0f,
100.0f);
this->actionFunc = func_80ABAC00;
break;
Expand Down Expand Up @@ -446,8 +441,7 @@ void func_80ABAC00(EnNiwLady* this, GlobalContext* globalCtx) {
} else {
getItemId = this->getItemId;
if (LINK_IS_ADULT) {
getItemId =
!(gSaveContext.itemGetInf[2] & 0x1000) ? NiwLady_GetRandomizedItemId(this, GI_POCKET_EGG) : GI_COJIRO;
getItemId = !(gSaveContext.itemGetInf[2] & 0x1000) ? GetItemFromActor(this->actor.id, GI_POCKET_EGG) : GI_COJIRO;
}
func_8002F434(&this->actor, globalCtx, getItemId, 200.0f, 100.0f);
}
Expand Down
Loading