Merge pull request #11 from MelonSpeedruns/melon-file-select-fixes

added direct3d drag support
This commit is contained in:
briaguya 2022-05-29 13:43:44 -04:00 committed by GitHub
commit f2f1fc70d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 242 additions and 135 deletions

View file

@ -117,7 +117,8 @@ static void run_as_dpi_aware(Fun f) {
DPI_AWARENESS_CONTEXT old_awareness_context = nullptr; DPI_AWARENESS_CONTEXT old_awareness_context = nullptr;
if (SetThreadDpiAwarenessContext != nullptr) { if (SetThreadDpiAwarenessContext != nullptr) {
old_awareness_context = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); old_awareness_context = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
} else { }
else {
// Solution for Windows 8.1 and newer, but before Windows 10 1607. // Solution for Windows 8.1 and newer, but before Windows 10 1607.
// SetProcessDpiAwareness must be called before any drawing related API is called. // SetProcessDpiAwareness must be called before any drawing related API is called.
if (!dxgi.process_dpi_awareness_done) { if (!dxgi.process_dpi_awareness_done) {
@ -162,13 +163,15 @@ static void toggle_borderless_window_full_screen(bool enable, bool call_callback
if (dxgi.last_maximized_state) { if (dxgi.last_maximized_state) {
SetWindowPos(dxgi.h_wnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE); SetWindowPos(dxgi.h_wnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
ShowWindow(dxgi.h_wnd, SW_MAXIMIZE); ShowWindow(dxgi.h_wnd, SW_MAXIMIZE);
} else { }
else {
SetWindowPos(dxgi.h_wnd, NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_FRAMECHANGED); SetWindowPos(dxgi.h_wnd, NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_FRAMECHANGED);
ShowWindow(dxgi.h_wnd, SW_RESTORE); ShowWindow(dxgi.h_wnd, SW_RESTORE);
} }
dxgi.is_full_screen = false; dxgi.is_full_screen = false;
} else { }
else {
// Save if window is maximized or not // Save if window is maximized or not
WINDOWPLACEMENT window_placement; WINDOWPLACEMENT window_placement;
window_placement.length = sizeof(WINDOWPLACEMENT); window_placement.length = sizeof(WINDOWPLACEMENT);
@ -212,6 +215,8 @@ static void onkeyup(WPARAM w_param, LPARAM l_param) {
} }
} }
extern "C" void LoadItemLocations(const char* spoilerFileName);
static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_param, LPARAM l_param) { static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_param, LPARAM l_param) {
SohImGui::EventImpl event_impl; SohImGui::EventImpl event_impl;
event_impl.win32 = { h_wnd, static_cast<int>(message), static_cast<int>(w_param), static_cast<int>(l_param) }; event_impl.win32 = { h_wnd, static_cast<int>(message), static_cast<int>(w_param), static_cast<int>(l_param) };
@ -227,7 +232,8 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par
if (dxgi.in_paint) { if (dxgi.in_paint) {
dxgi.recursive_paint_detected = true; dxgi.recursive_paint_detected = true;
return DefWindowProcW(h_wnd, message, w_param, l_param); return DefWindowProcW(h_wnd, message, w_param, l_param);
} else { }
else {
if (dxgi.run_one_game_iter != nullptr) { if (dxgi.run_one_game_iter != nullptr) {
dxgi.in_paint = true; dxgi.in_paint = true;
dxgi.run_one_game_iter(); dxgi.run_one_game_iter();
@ -251,11 +257,17 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par
case WM_KEYUP: case WM_KEYUP:
onkeyup(w_param, l_param); onkeyup(w_param, l_param);
break; break;
case WM_DROPFILES:
char fileName[256];
DragQueryFileA((HDROP)w_param, 0, fileName, 256);
LoadItemLocations(fileName);
break;
case WM_SYSKEYDOWN: case WM_SYSKEYDOWN:
if ((w_param == VK_RETURN) && ((l_param & 1 << 30) == 0)) { if ((w_param == VK_RETURN) && ((l_param & 1 << 30) == 0)) {
toggle_borderless_window_full_screen(!dxgi.is_full_screen, true); toggle_borderless_window_full_screen(!dxgi.is_full_screen, true);
break; break;
} else { }
else {
return DefWindowProcW(h_wnd, message, w_param, l_param); return DefWindowProcW(h_wnd, message, w_param, l_param);
} }
default: default:
@ -319,6 +331,8 @@ void gfx_dxgi_init(const char *game_name, bool start_in_fullscreen) {
if (start_in_fullscreen) { if (start_in_fullscreen) {
toggle_borderless_window_full_screen(true, false); toggle_borderless_window_full_screen(true, false);
} }
DragAcceptFiles(dxgi.h_wnd, TRUE);
} }
static void gfx_dxgi_set_fullscreen_changed_callback(void (*on_fullscreen_changed)(bool is_now_fullscreen)) { static void gfx_dxgi_set_fullscreen_changed_callback(void (*on_fullscreen_changed)(bool is_now_fullscreen)) {
@ -455,7 +469,8 @@ static bool gfx_dxgi_start_frame(void) {
vsyncs_to_wait = 1; vsyncs_to_wait = 1;
} }
dxgi.frame_timestamp = FRAME_INTERVAL_US_DENOMINATOR * (last_end_us + vsyncs_to_wait * estimated_vsync_interval_us); dxgi.frame_timestamp = FRAME_INTERVAL_US_DENOMINATOR * (last_end_us + vsyncs_to_wait * estimated_vsync_interval_us);
} else { }
else {
// Drop frame // Drop frame
//printf("Dropping frame\n"); //printf("Dropping frame\n");
dxgi.dropped_frame = true; dxgi.dropped_frame = true;
@ -477,7 +492,8 @@ static bool gfx_dxgi_start_frame(void) {
} }
if (diff_left < diff_right) { if (diff_left < diff_right) {
vsyncs_to_wait = floor(vsyncs_to_wait); vsyncs_to_wait = floor(vsyncs_to_wait);
} else { }
else {
vsyncs_to_wait = ceil(vsyncs_to_wait); vsyncs_to_wait = ceil(vsyncs_to_wait);
} }
if (vsyncs_to_wait == 0) { if (vsyncs_to_wait == 0) {
@ -493,7 +509,8 @@ static bool gfx_dxgi_start_frame(void) {
dxgi.use_timer = true; dxgi.use_timer = true;
} }
dxgi.length_in_vsync_frames = vsyncs_to_wait; dxgi.length_in_vsync_frames = vsyncs_to_wait;
} else { }
else {
dxgi.length_in_vsync_frames = 1; dxgi.length_in_vsync_frames = 1;
dxgi.use_timer = true; dxgi.use_timer = true;
} }
@ -561,7 +578,8 @@ static void gfx_dxgi_set_frame_divisor(int divisor) {
void gfx_dxgi_create_factory_and_device(bool debug, int d3d_version, bool (*create_device_fn)(IDXGIAdapter1* adapter, bool test_only)) { void gfx_dxgi_create_factory_and_device(bool debug, int d3d_version, bool (*create_device_fn)(IDXGIAdapter1* adapter, bool test_only)) {
if (dxgi.CreateDXGIFactory2 != nullptr) { if (dxgi.CreateDXGIFactory2 != nullptr) {
ThrowIfFailed(dxgi.CreateDXGIFactory2(debug ? DXGI_CREATE_FACTORY_DEBUG : 0, __uuidof(IDXGIFactory2), &dxgi.factory)); ThrowIfFailed(dxgi.CreateDXGIFactory2(debug ? DXGI_CREATE_FACTORY_DEBUG : 0, __uuidof(IDXGIFactory2), &dxgi.factory));
} else { }
else {
ThrowIfFailed(dxgi.CreateDXGIFactory1(__uuidof(IDXGIFactory2), &dxgi.factory)); ThrowIfFailed(dxgi.CreateDXGIFactory1(__uuidof(IDXGIFactory2), &dxgi.factory));
} }
@ -622,7 +640,8 @@ ComPtr<IDXGISwapChain1> gfx_dxgi_create_swap_chain(IUnknown *device) {
ThrowIfFailed(swap_chain2->SetMaximumFrameLatency(1)); ThrowIfFailed(swap_chain2->SetMaximumFrameLatency(1));
dxgi.waitable_object = swap_chain2->GetFrameLatencyWaitableObject(); dxgi.waitable_object = swap_chain2->GetFrameLatencyWaitableObject();
WaitForSingleObject(dxgi.waitable_object, INFINITE); WaitForSingleObject(dxgi.waitable_object, INFINITE);
} else { }
else {
ComPtr<IDXGIDevice1> device1; ComPtr<IDXGIDevice1> device1;
ThrowIfFailed(device->QueryInterface(IID_PPV_ARGS(&device1))); ThrowIfFailed(device->QueryInterface(IID_PPV_ARGS(&device1)));
ThrowIfFailed(device1->SetMaximumFrameLatency(1)); ThrowIfFailed(device1->SetMaximumFrameLatency(1));

View file

@ -105,7 +105,8 @@ static void set_fullscreen(bool on, bool call_callback) {
window_width = mode.w; window_width = mode.w;
window_height = mode.h; window_height = mode.h;
SDL_ShowCursor(false); SDL_ShowCursor(false);
} else { }
else {
window_width = DESIRED_SCREEN_WIDTH; window_width = DESIRED_SCREEN_WIDTH;
window_height = DESIRED_SCREEN_HEIGHT; window_height = DESIRED_SCREEN_HEIGHT;
} }
@ -210,7 +211,8 @@ static void gfx_sdl_get_dimensions(uint32_t *width, uint32_t *height) {
static int translate_scancode(int scancode) { static int translate_scancode(int scancode) {
if (scancode < 512) { if (scancode < 512) {
return inverted_scancode_table[scancode]; return inverted_scancode_table[scancode];
} else { }
else {
return 0; return 0;
} }
} }
@ -256,9 +258,7 @@ static void gfx_sdl_handle_events(void) {
break; break;
case SDL_DROPFILE: case SDL_DROPFILE:
{ {
#ifndef __linux__
LoadItemLocations(event.drop.file); LoadItemLocations(event.drop.file);
#endif
break; break;
} }
case SDL_QUIT: case SDL_QUIT:

View file

@ -179,7 +179,7 @@ typedef struct {
/* 0x1420 */ s16 worldMapArea; /* 0x1420 */ s16 worldMapArea;
/* 0x1422 */ s16 sunsSongState; // controls the effects of suns song /* 0x1422 */ s16 sunsSongState; // controls the effects of suns song
/* 0x1424 */ s16 healthAccumulator; /* 0x1424 */ s16 healthAccumulator;
ItemLocation itemLocations[512]; ItemLocation itemLocations[266];
Sprite seedIcons[5]; Sprite seedIcons[5];
} SaveContext; // size = 0x1428 } SaveContext; // size = 0x1428

View file

@ -713,12 +713,21 @@ s16 Randomizer::GetItemModelFromId(s16 itemId) {
} }
void Randomizer::LoadItemLocations(const char* spoilerFileName) { void Randomizer::LoadItemLocations(const char* spoilerFileName) {
if (strcmp(spoilerFileName, "") != 0) {
// bandaid until new save stuff happens // bandaid until new save stuff happens
ParseItemLocations(spoilerFileName); ParseItemLocations(spoilerFileName);
for (auto itemLocation : gSaveContext.itemLocations) { for (auto itemLocation : gSaveContext.itemLocations) {
this->itemLocations[itemLocation.check] = itemLocation.get; this->itemLocations[itemLocation.check] = itemLocation.get;
} }
} else {
u16 index = 0;
for (auto itemLocation : this->itemLocations) {
gSaveContext.itemLocations[index].check = itemLocation.first;
gSaveContext.itemLocations[index].get = itemLocation.second;
index++;
}
}
} }
void Randomizer::ParseItemLocations(const char* spoilerFileName) { void Randomizer::ParseItemLocations(const char* spoilerFileName) {
@ -1013,6 +1022,11 @@ RandomizerCheck Randomizer::GetCheckFromSceneAndParams(s16 sceneNum, s16 actorPa
} }
switch(sceneNum) { switch(sceneNum) {
case 17:
switch (actorParams) {
case 0x1F:
return DEKU_TREE_QUEEN_GOHMA_HEART;
}
case 40: case 40:
switch(actorParams) { switch(actorParams) {
case 22944: case 22944:
@ -1026,7 +1040,7 @@ RandomizerCheck Randomizer::GetCheckFromSceneAndParams(s16 sceneNum, s16 actorPa
} }
case 84: case 84:
switch (actorParams) { switch (actorParams) {
case 0x0406: case 1030:
return ZR_NEAR_OPEN_GROTTO_FREESTANDING_POH; return ZR_NEAR_OPEN_GROTTO_FREESTANDING_POH;
case 2822: case 2822:
return ZR_NEAR_DOMAIN_FREESTANDING_POH; return ZR_NEAR_DOMAIN_FREESTANDING_POH;

View file

@ -4,7 +4,7 @@ void TitleSetup_InitImpl(GameState* gameState) {
osSyncPrintf("ゼルダ共通データ初期化\n"); // "Zelda common data initalization" osSyncPrintf("ゼルダ共通データ初期化\n"); // "Zelda common data initalization"
SaveContext_Init(); SaveContext_Init();
gameState->running = false; gameState->running = false;
SET_NEXT_GAMESTATE(gameState, FileChoose_Init, TitleContext); SET_NEXT_GAMESTATE(gameState, Title_Init, TitleContext);
} }
void TitleSetup_Destroy(GameState* gameState) { void TitleSetup_Destroy(GameState* gameState) {

View file

@ -193,6 +193,62 @@ void Gameplay_Destroy(GameState* thisx) {
gGlobalCtx = NULL; gGlobalCtx = NULL;
} }
void GiveLinksPocketMedallion(GlobalContext* globalCtx) {
if (gSaveContext.n64ddFlag) {
RandomizerGet get = gSaveContext.itemLocations[LINKS_POCKET].get;
s16 item;
u8 medallion = 0;
switch (get) {
case FOREST_MEDALLION:
item = ITEM_MEDALLION_FOREST;
medallion = 1;
break;
case FIRE_MEDALLION:
item = ITEM_MEDALLION_FIRE;
medallion = 1;
break;
case WATER_MEDALLION:
item = ITEM_MEDALLION_WATER;
medallion = 1;
break;
case SHADOW_MEDALLION:
item = ITEM_MEDALLION_SHADOW;
medallion = 1;
break;
case SPIRIT_MEDALLION:
item = ITEM_MEDALLION_SPIRIT;
medallion = 1;
break;
case LIGHT_MEDALLION:
item = ITEM_MEDALLION_LIGHT;
medallion = 1;
break;
case KOKIRI_EMERALD:
item = ITEM_KOKIRI_EMERALD;
break;
case GORON_RUBY:
item = ITEM_GORON_RUBY;
break;
case ZORA_SAPPHIRE:
item = ITEM_ZORA_SAPPHIRE;
break;
}
if (medallion == 1) {
gSaveContext.inventory.questItems |= gBitFlags[item - ITEM_MEDALLION_FOREST + QUEST_MEDALLION_FOREST];
if (item == ITEM_MEDALLION_WATER) {
func_8006D0AC(globalCtx);
}
} else {
gSaveContext.inventory.questItems |= gBitFlags[item - ITEM_KOKIRI_EMERALD + QUEST_KOKIRI_EMERALD];
}
}
}
void Gameplay_Init(GameState* thisx) { void Gameplay_Init(GameState* thisx) {
GlobalContext* globalCtx = (GlobalContext*)thisx; GlobalContext* globalCtx = (GlobalContext*)thisx;
GraphicsContext* gfxCtx = globalCtx->state.gfxCtx; GraphicsContext* gfxCtx = globalCtx->state.gfxCtx;
@ -207,6 +263,8 @@ void Gameplay_Init(GameState* thisx) {
u8 tempSetupIndex; u8 tempSetupIndex;
s32 pad[2]; s32 pad[2];
GiveLinksPocketMedallion(globalCtx);
if (gSaveContext.entranceIndex == -1) { if (gSaveContext.entranceIndex == -1) {
gSaveContext.entranceIndex = 0; gSaveContext.entranceIndex = 0;
globalCtx->state.running = false; globalCtx->state.running = false;

View file

@ -515,8 +515,13 @@ void DoorWarp1_ChildWarpOut(DoorWarp1* this, GlobalContext* globalCtx) {
Flags_SetEventChkInf(7); Flags_SetEventChkInf(7);
Flags_SetEventChkInf(9); Flags_SetEventChkInf(9);
Item_Give(globalCtx, ITEM_KOKIRI_EMERALD); Item_Give(globalCtx, ITEM_KOKIRI_EMERALD);
if (gSaveContext.n64ddFlag) {
globalCtx->nextEntranceIndex = 0x0457;
gSaveContext.nextCutsceneIndex = 0;
} else {
globalCtx->nextEntranceIndex = 0xEE; globalCtx->nextEntranceIndex = 0xEE;
gSaveContext.nextCutsceneIndex = 0xFFF1; gSaveContext.nextCutsceneIndex = 0xFFF1;
}
} else { } else {
globalCtx->nextEntranceIndex = 0x457; globalCtx->nextEntranceIndex = 0x457;
gSaveContext.nextCutsceneIndex = 0; gSaveContext.nextCutsceneIndex = 0;

View file

@ -58,10 +58,15 @@ void ItemBHeart_Update(Actor* thisx, GlobalContext* globalCtx) {
if (Actor_HasParent(&this->actor, globalCtx)) { if (Actor_HasParent(&this->actor, globalCtx)) {
Flags_SetCollectible(globalCtx, 0x1F); Flags_SetCollectible(globalCtx, 0x1F);
Actor_Kill(&this->actor); Actor_Kill(&this->actor);
} else {
if (gSaveContext.n64ddFlag) {
s16 getItemId = GetRandomizedItemId(GI_HEART_CONTAINER_2, globalCtx->sceneNum, 0x1F);
func_8002F434(&this->actor, globalCtx, getItemId, 30.0f, 40.0f);
} else { } else {
func_8002F434(&this->actor, globalCtx, GI_HEART_CONTAINER_2, 30.0f, 40.0f); func_8002F434(&this->actor, globalCtx, GI_HEART_CONTAINER_2, 30.0f, 40.0f);
} }
} }
}
void func_80B85264(ItemBHeart* this, GlobalContext* globalCtx) { void func_80B85264(ItemBHeart* this, GlobalContext* globalCtx) {
f32 yOffset; f32 yOffset;
@ -93,6 +98,10 @@ void ItemBHeart_Draw(Actor* thisx, GlobalContext* globalCtx) {
actorIt = actorIt->next; actorIt = actorIt->next;
} }
if (gSaveContext.n64ddFlag) {
GetItem_Draw(globalCtx,
GetItemModelFromId(GetRandomizedItemId(GI_HEART_CONTAINER_2, globalCtx->sceneNum, 0x1F)));
} else {
if (flag) { if (flag) {
func_80093D84(globalCtx->state.gfxCtx); func_80093D84(globalCtx->state.gfxCtx);
gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_item_b_heart.c", 551), gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_item_b_heart.c", 551),
@ -106,6 +115,7 @@ void ItemBHeart_Draw(Actor* thisx, GlobalContext* globalCtx) {
gSPDisplayList(POLY_OPA_DISP++, gGiHeartBorderDL); gSPDisplayList(POLY_OPA_DISP++, gGiHeartBorderDL);
gSPDisplayList(POLY_OPA_DISP++, gGiHeartContainerDL); gSPDisplayList(POLY_OPA_DISP++, gGiHeartContainerDL);
} }
}
CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_item_b_heart.c", 561); CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_item_b_heart.c", 561);
} }

View file

@ -1519,7 +1519,6 @@ void FileChoose_LoadGame(GameState* thisx) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
gSaveContext.fileNum = this->buttonIndex; gSaveContext.fileNum = this->buttonIndex;
Sram_OpenSave(&this->sramCtx); Sram_OpenSave(&this->sramCtx);
// LoadItemLocations();
gSaveContext.gameMode = 0; gSaveContext.gameMode = 0;
SET_NEXT_GAMESTATE(&this->state, Select_Init, SelectContext); SET_NEXT_GAMESTATE(&this->state, Select_Init, SelectContext);
this->state.running = false; this->state.running = false;
@ -1527,12 +1526,14 @@ void FileChoose_LoadGame(GameState* thisx) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
gSaveContext.fileNum = this->buttonIndex; gSaveContext.fileNum = this->buttonIndex;
Sram_OpenSave(&this->sramCtx); Sram_OpenSave(&this->sramCtx);
// LoadItemLocations();
gSaveContext.gameMode = 0; gSaveContext.gameMode = 0;
SET_NEXT_GAMESTATE(&this->state, Gameplay_Init, GlobalContext); SET_NEXT_GAMESTATE(&this->state, Gameplay_Init, GlobalContext);
this->state.running = false; this->state.running = false;
} }
LoadItemLocations("");
gSaveContext.respawn[0].entranceIndex = -1; gSaveContext.respawn[0].entranceIndex = -1;
gSaveContext.respawnFlag = 0; gSaveContext.respawnFlag = 0;
gSaveContext.seqId = (u8)NA_BGM_DISABLED; gSaveContext.seqId = (u8)NA_BGM_DISABLED;