From f5b7de4afe48c151c54f073d6190448c63323959 Mon Sep 17 00:00:00 2001 From: Felipe Guaycuru Date: Sun, 17 Jul 2022 20:36:02 -0300 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFMerge=20branch=20'develop'=20from=20Ha?= =?UTF-8?q?rbourMasters=20into=20znx=20(#3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add Support for macOS (#441) * Fixed soh filters * add more makefile changes * almost ready * more updates * update * update * Update Makefiles to handle both platforms * Allow for overriding the CXX and CC executables * Restore original structure while supporting custom CXX flags * Remove some platform specific libs * Dynamic target name * Make X11 paths package-agnostic * Remove changes to `gfx_opengl.cpp` * Use OpenGL2 on MacOS instead of OpenGL3 * make it actually render something * render at least the first texture, still need to figure out the second one * Let’s use OpenGL 3 again * maybe this works to get the right texture? link's eyes still look off a bit * did this work? * set the platform to macos * actual numbers are right, but logic is ugly XXX/TODO, i know * add zlib to ldflags for ZAPDUtils * A bit of cleanup * Revert unneeded changes * Remove GL_CHECK * Fix issues with z64 branch * use an std::map instead of a giant array * three point filter fix (#2) * Fix mac compilation * fix audio for 64 bit * revert audio heap size, keep bigger pools * Add more Apple specific checks to our modifications * Add building instructions for macOS * Remove unecessary step from building instructions * Add missing SDL2 & GLEW to Linux LDLIBS * Update BUILDING.md Co-authored-by: BountyChocolate123456 <101743444+BountyChocolate123456@users.noreply.github.com> * Update soh/.gitignore to include other arch binaries Co-authored-by: BountyChocolate123456 <101743444+BountyChocolate123456@users.noreply.github.com> * Use right platform name for debugging window Co-authored-by: BountyChocolate123456 <101743444+BountyChocolate123456@users.noreply.github.com> * Fix stormlib on macos (arm64) * Simplify some of the ifdef checks * Revert an older no longer necessary fix * Remove remaining unecessary deviations * Update building instructions after StormLib changes * Feature: Use OpenGL 4.1 (#1) * Further tweak the BUILDING * Tidy up * reword -j message * Add Jenkins CI Support (#2) * Fix type issues * add target and add makefile targets to create an .app `filledappbundle` creates the target with the .otr included this should perhaps be moved to Application Support though * pull gcc's rpath from otool output * move make target to the end so it's not default * Add Jenkins and make exe in par with other platforms * Actually save build artefacts * Fix artefact path * Remove x11 mentions and linking (not used) * Update building instructions for generating app * use appsupport directory * Add new app icon * Update target to match macOS types * Update more audio types * fix null deref in Audio_PlayFanfare * Remove old import from z64 * address final nit with apple ifdefs Co-authored-by: KiritoDev <36680385+KiritoDv@users.noreply.github.com> Co-authored-by: Jeffrey Crowell Co-authored-by: BountyChocolate123456 <101743444+BountyChocolate123456@users.noreply.github.com> * Move macOS to parallel stage * fix linux crash * Ignore all named saves Necessary after new save format * DPad items * Move UI location arrays from static to global to accomodate customizable UI * FIX: Increased the maximum actor limit for draw distance Fix issue #529 * FIX: Remove duplicates of gNewDrops from the enhancements menu * Get rid of erroneous int casts * casts jya_cobra's shadowTexture pointer to uintptr_t instead of s32. * Fix ability to assign equipment you don't own * Fix title cards for market potion shop and bombchu shop * Invalidate message item icon texture before drawing * Add margins for dpad * Fixed some instances where the original OOT save is erroneously preserved or recreated, leading to another conversion next time you launched the game * Headphones setting in game should now work. Resolves #13 * Map Select name fixes * Change Power to Upgrades * Rename Soh* files * Update names * Add more files * Add more files * Add toggles for disabling heart drops and random drops (#507) * Adds toggles for disabling random drops and fixed heart drops * Changed the "No Fixed Heart Drops" toggle to the more useful "No Random Heart Drops" toggle * Adds an explanation that the no heart drops option is similar to Hero Mode * Moved difficulty options into their own sub-menu Moved time saver options into their own sub-menu Moved clutter reducing options into their own sub-menu * fixed the tag name of mweep speed * Moved Skip Text to Experimental * Fix testing masks of DPad * Fix audio, boot commands, and save staes. * add menu from https://github.com/PurpleHato/Shipwright/tree/ResetMenu * implement reset * Update README.md * command on mac * special char doesn't work with default imgui font * change name based on PR comment * missed a couple spots * change sunset in save editor so dampe is out * Update to latest `docking` imgui (#582) * Update to latest `docking` imgui commit: 67410d53f739b6a0df138e2252f0e5136b42062f * Fix modified import for SDL * Update imgui_impl_sdl.cpp * Add Imgui include path for better imports * Controller Navigation Fix-Up (#544) * Controller Navigation Fix-Up * [MISC] Fix typo * Use Macro for __FILE__ & __LINE__ when possible (#559) * First batch some overlay * Almost all overlay * effect & gamestate * kaleido stuffs * more overlay * more left over from code folder * remaining hardcoded line and file * Open & Close _DISP __FILE__ & __LINE__ clean up * Some if (1) {} remove * LOG_xxxx __FILE__ , __LINE__ cleaned * ASSERT macro __FILE__ __LINE__ * mtx without line/file in functions * " if (1) {} " & "if (0) {}" and tab/white place * LogUtils as macro * GameState_, GameAlloc_, SystemArena_ & ZeldaArena_ * Revert "GameState_, GameAlloc_, SystemArena_ & ZeldaArena_" This reverts commit 0d85caaf7e342648c01a15fe21e93637352dc596. * Like last commit but as macro * Fix matrix not using macros * use function not macro * DebugArena_* functions GameAlloc_MallocDebug BgCheck_PosErrorCheck as macros removed issues with ; in macro file * MM Bunny Hood enhancements: no age restrictions & wear across entrances (#560) * Remove age restriction on MM Bunny Hood * Handle mask slot changing; init Link wearing mask * Reset mask state after selling * Use unordered maps in some hot paths (#566) * Use unordered maps in some hot paths * Address PR comments * Cheat: Infinite Epona Boost (#577) * Cheat: Infinite Epona Boost * Edit for readability * update pulseaudio for 44.1khz audio (#587) * use pulseaudio defaults * spaces/tabs * pulseaudio values tuned for n64 audio at 44.1khz * update tlength * remove one hardcoded samplerate Co-authored-by: briaguya * Restoration Item Sliders (#595) * Allows players to set custom restoration values for potions and milk * Fixed a dumb oversight * implemented fairy sliders * use ini window resolution (#410) * use ini window resolution * use arguments for directx window size * default 640x480 not 320x240 * kick off a build * and revert * default config 640x480 not 320x240 * add todo Co-authored-by: briaguya * 3D Drops & Projectiles update (#548) * Fix remaining rupee and keys * fix tabs -> spaces * more fix about tabs -> spaces * Better up <-> down mouvement for hearts * remove useless comment * Cosmetics menu rework (#589) * - * DPad/some margin fix(left side) * various ImGui stuff and fixes * disabled kaleido menu (non working) * fix win being dumb * same for C btn this time * Fix windows build * Beating hearts fix * Default win size and some placement fix * Fix Dpad Ammo & C notes, Kaleido, white dog * some texts fix and tab move * Add stone of agony, some fixes and build correctly * precise item place with Dpad * Gamecube -> GameCube Co-authored-by: Baoulettes * [CI] Create an Appimage for 64bit builds (#570) * [CI] Create AppImage file * [CI] Updated Jenkinsfile * [MISC] fix indentation * [MISC] Fix indentation * [MISC] Fix indentation * [CI] 7z appimage and readme * [CI] AppImage icon file (#597) * [CI] Add patchelf * [BUILD] Include Hi-Res icon * Fix portability use of std::clamp (#596) * Add N64 weird frames and OOB Bombchus cvars (#602) * Add gN64WeirdFrames and gBombchuOOB cvars * Rename gBombchuOOB to gBombchusOOB * Fix pipeline * [BUILD] Do not strip ZAPD (#598) * [BUILD] Do not strip ZAPD * [BUILD] Reuse Icon Asset * [APPIMAGE] Handle paths with spaces * [macos] Distribute optimized builds (#599) * Cosmetics texts fixes (#604) * branch init + few fixes * Reset button * Several texts fixes and default color to GameCube * space issues * some more extra space that was not needed. * space yes last time ... * Arrows being able to be rainbow some more texts fixes * more texts fixes * c-buttons some plurial fix * Fixes bug in demo effect due to removed display list set. * King dodongo room crash (#613) * first attempt * force camera setting to be at least 0 (dirty!) * - * reverted something to just include fix * Invalidate text box icon before drawing (#607) * [APPIMAGE] Set lib path for ZAPD (#611) * New drop runtime fix (#614) * inital rework * fixed default rotation for 2D sprites * fix tab/space issues * Fix Ganon's Castle title cards (#606) * Checkered room crash workaround (#615) * Increase poly and vertex count for dyna actors * Add TODO * Only apply fix in Forest Temple * Enable globally * Match case of 'Shipwright' in Linux build (#619) * Fix 0xabababab crash (#617) * Unconditionally setup the normal skybox * Only call Skybox_Setup once ever * Equipment upgrade text fix and any pause slot enhancement fix (#620) * Fix upgrade name text not rendering * Use cvar and don't render equip help for empty item slots * Fix rendering logic * Fix incorrect item name rendered for one frame * Reorder comparison * Remove extra indent * Remove accidental changes * ImGui grammer, consistency, and clarity fixes (#625) * ImGui grammer, consistency, and clarity fixes Co-Authored-By: Stormghetti <56653191+Stormghetti@users.noreply.github.com> * Adds more new lines for users on smaller displays Co-Authored-By: Stormghetti <56653191+Stormghetti@users.noreply.github.com> Co-authored-by: Stormghetti <56653191+Stormghetti@users.noreply.github.com> * New drops shadows & rotation fixes (#627) * fixes * forgot to add heart pieces in rotation logic * Dodongo's Cavern blue warp crash fix (#622) * Doodong's Cavern blue warp crash fix * >= not > * Don't waste a line of space * add support for clang compiler (#592) * hacks to align strings for clang... wow just wow * start work to getting built with clang * fix issues with struct constructors, all builds, doesn't link still * fix some narrowing issues that clang complains about * fix compliation of zapd * fix null deref in VersionInfo * builds with clang * make stringbuilding use StringHelper instead of addition * fix linking * add CLANG SHIP overlay on clang built versions * doesn't need to be volatile * mark unknown strings as extern * rename some stuff * can't align extern * hopefully fix compilation for everythign * expandtab * allow setting LD * Revert "allow setting LD" This reverts commit 711aba6db2c41bab476bd34e878af6a37a7f5559. maybe to use lld it should be a LDFLAG? * -Wno-deprecated-declarations is required for newer versions of clang on macOS 13 beta sdk, the version of apple clang requires this * Add jenkins support for clang * Forward CXX flags to stormlib compilation * Move GCC only flags to check * use exports to set multiarch setup * Fix Jenkins forever * use make instead of cmake --build add some flags to build with clang-11 as well * address review coments - rework extraction to allow multi thread - misc readability cleanup * update makefile to add WARN on linux+clang Co-authored-by: David Chavez * Fix develop * Fixes grey screen issue + tooltip for 2 handed shield * Don't close controller after SDL has quit (#642) * Don't close controller after SDL has quit * Don't check if controller can rumble if null * Fixes Barinade's set whenever boss fight is reloaded (#639) * Reimplements unused Barinade reset function. * Removes the Jellyfish from Barinade's body on reset. * add the ability to pull graves during the day (#637) * change max internal res multiplier to 3x, use float and % instead of int (#638) * change max internal res multiplier to 3x, use float and % instead of int * Update libultraship/libultraship/ImGuiImpl.cpp Co-authored-by: Kenix3 Co-authored-by: briaguya Co-authored-by: Kenix3 * Fixes crash on Biggoron trade failure screen wipe Resolves #621 * fixes center docking (#652) * testing out item replacement (#416) * skip learning song of storms * don't set flag when getting goron tunic as child * Initiates prelude check when master sword unloads. Not quite how N64 rando does it but so far it's the only way I've found to make it trigger without also triggering the time travel again. * Stops Shadow Temple lore prompts from appearing in rando. * Skips cutscene of royal tomb explosion in rando. Explosion sound doesn't play correctly and I think the debris appears in the wrong place, but the functionality is here. * Improves visual of exploding gravestone. * Adds some comments explaining the rando differences * Skip ruto text box in jabu blue warp For rando * skip intro cutscene in dodongo's cavern * load spoiler files on boot, fix spoilerfile existing check when making new saves * name entry dropped spoiler logic * make sure to actually init the cvar * no chime on load * uncomment * Skip ganondrof cutscene Skip to scream part of the death animation, skipping the text boxes etc. For rando * Update z_boss_ganondrof.c * skip owl flight cutscenes in rando * Fixes skipped text so it only applies to shadow temple. Earlier fix inadvertently applied to some other text as well, changed logic so that only specified sceneNums and textIds can have this enabled, and text skipped by sceneNum can have the skip overriden by textId if needed. Currently there are no overrides so the textId section of the logic is commented out to avoid compilation errors. * Adds a default to the switch case statements that leaves the randoSkipText variable unchanged, just in case. * TEST: Text for item * Adding ganon flavor text * ADD: AMMO Count * format ganon text/hint text * Autoskip the tower cutscene if settings call for tower collapse. * ganon hint text logic * Improved prelude after time travel fix * swapped the sizes between ganon hint text and ganon text, as they were set to the wrong things. * this is all i did * not the cleanest code ever but it's working * ADD: GS Count * ADD: Wallter (crash for now) * TWEAK: Wallet check * FIX: Use DrawItem instread of DrawUpgrade... b-baka! * Fixes some vanilla bugs introduced by rando code. * Added cutscene skip for zelda escaping Using the debug cutscene skipping function. Also added a conditional so the bridge doesn't spawn closed when cutscene is ready to trigger * ADD: X Spacing + Placeholders for song * ADD: default case for items * TWEAK: Spacing * FIX: Light Arrow * ADD: Ammo Option * use groups instead * ADD: More spacing logic * songs and names * TWEAK: Color on wallet * colors * Added flags cutscene before nabooru fight * ADD: ChromaKey text * First attempt skip cs after nabooru defeat * Better implementation for specific rando cutscene skips * use pulseaudio defaults * spaces/tabs * move color push/pop to stop crash * make the colors work again * the real bottle fix * pulseaudio values tuned for n64 audio at 44.1khz * update tlength * remove one hardcoded samplerate * Cleaned up and fixed zelda escape skip The if statement is a freaking monster, but unless we want to skip more cutscenes in the same way later, this is the most compact way of doing it that I know of. * Revert one line to match original nothing functional * another hint line that breaks autonewline logic * don't autospawn epona if we don't have the song/ocarina * Trying to use iron knuckle death effects not working yet * Streamlined OoT cutscene skip for future additions Also cleaned up if statement in general * Made if statement more readable Also added clarity for what cutscene was skipped * Fixed typo in comment * Janky nabooru defeat cs skip * altar text formatting (gonna need help shortening some of the french ones) * more altar text formatting * english altar text formatting complete * make gtg blocking guard check for card not bridge * FIX: Typo! * FIX: Uppercases * FIX: Typo * TWEAK: Alter + some names * TWEAK: More caps! * ADD: Missing string TWEAK more uppercases and namefixe s * Hide nabooru death by covering her in flames * bandaid fix for death crash issue * Twinrova defeat cs skip Skips the animation and manually calls the function to show the "beam" around the sisters * fix crash * fix caps to match * fix great fairy reward mashing/shielding issue * TWEAK : Typo clé to Clé * TWEAK: Some Altar hints TWEAK: Some capitals * TWEAK: Unmatching text + some cap again * TWEAK: More tweaks * fix build * remove extra json.hpp, add hint * Update randomizer_item_tracker.cpp * TWEAK: Double Defense with RedParticles instead of white * make sure we don't optimize out the check to ensure a spoilerfile exists * vanilla ganon boss key hint formatting * TWEAK: FR- better way of the hero text * fix * and again * Initializes dungeonsDone items in gSaveContext to 0. * Replaces sizeof calculation with a NUM_DUNGEONS constant. * Fixes Saria's Gift on the LW Bridge from getting killed when holding shield. * More airtight fix for Saria's Gift on the Bridge. * Lifts one of the conditions in the if statement a little higher to prevent unnecessary lookups of getItemId. * Invalidate text box icon before drawing * Fixes the case where Saria's gift is an Ice Trap. We still get the Ice Trap once, but never again. This does mean you can now hold R while walking in to avoid the ice trap, but everything else seems to work fine. * Initial commit Might need changing when we change the settings in the future * Fixes Door of Time opening cutscene after warping with prelude. * Initial waterfall skip Very rudimentary way of doing things but it seems to work so :shrug: * inital rework * fixed default rotation for 2D sprites * fix tab/space issues * 3d drops rando merge fix again * Allows Impa to appear in the Lullaby check post drawbridge escape. * Changes Ganon's Trials Count setting to a checkbox The checkbox is whether or not to skip all of them. Leaving the box unchecked will mean doing all of them. Eventually this will be switched back to a slider once we implement the logic for which trials start out completed. * Sets all Ganon's Trials to incomplete in new saves. Fixes https://github.com/briaguya-ai/rando-issue-tracker/issues/131 * fix castle guards when oot throw cutscene has already played in rando * Properly removes the beams when trials are cleared. * Removes Question Mark from Skip Ganon's Trials UI. * Adds a todo comment about when to change back to slider. * make deku seeds check for bullet bag * Various tweaks TWEAK: Altar Text TWEAK: Hint names TWEAK: Replace more problematic œ to oe * upgrade ocarina on both child and adult equips * FIX: Jabu Item * update equipped hookshot/longshot when obtained as other age * add hint * don't give the bgs check without the claim check * Skips Darunia Cutscene in Fire Temple * Added a TODO note about not skipping the cutscene. There is a setting we will want to have eventually that will require this cutscene to not be skipped since it is used during a glitch. * remove todo * restore fast ocarina option in imgui that was lost in merge * Fixes grey screen issue + tooltip for 2 handed shield * update to use dg instead of g for textures in item tracker * TWEAK: Default color for cosmetic RAND button was not the corect one * fix texture crash, remove unused item tracker code * don't open mask shop until we get zelda's letter * Update README.md * Prevents "correct" chime under incorrect conditions. * Fixes typo in conditional and adds "bonk" sound effect. "Bonk" sound is NA_SE_SY_OCARINA_ERROR and it plays when conditions for the Door of Time have not been met after playing Song of Time. This is only possible in rando's "Intended" Door of Time option, in which the Ocarina of Time and all 3 spritual stones are required to open the door, instead of the vanilla requirements of just having the song of time. * remove modify dpad equips toggle, replace with checks for dpad menu * remove extra check * add ability to hold c-up to assign to dpad when dpad menuing is enabled * disable d-pad navigation on item menu when holding c-up to equip * dpad+c-up stuff for equipment menu * ADD: Checbox for songs colors * TWEAK: RandoColors for normal songs * kind of quick and dirty but it works * TWEAK: Clarity of the tooltip Co-authored-by: briaguya Co-authored-by: Christopher Leggett Co-authored-by: aMannus Co-authored-by: PurpleHato Co-authored-by: Dog <5172592+Dog@users.noreply.github.com> Co-authored-by: Vague Rant Co-authored-by: Baoulettes Co-authored-by: Ada <60364512+GreatArgorath@users.noreply.github.com> * Cosmetics hotfixes (#640) * Initial branch creation * Revert Main Game so it do not conflict later * should fix window build, made namespace for Cosmetics * forgot to edit one title * Ability to add hidden window (usefull for Rainbow) Fix building issues * Line break, unused bool remove * add descriptive todo for death crash bandaid (#655) Co-authored-by: briaguya * Removed legacy audio mode and fixed ganon sound bug (#657) * Free Camera (#337) * wip free cam * Almost done, needs collision still * Added free cam behind cvar * added WIP collision * Fixed & implemented "Manual mode" from WW & TP * Fixed camera not rotating when Link is moving * fixed initialized camera rotation * Fixed camera getting stuck + made it smoother * reduced deadzone * fixed epona camera height + added WW z-target free camera * Adjusted player camera height & fixed fov * Fixed camera roll * fixed fov when moving the camera while in z-target * Camera resets to Auto when going through doors or changing maps * Fixed building * touch * more touch work * Added WIP mouse support to the free cam * gui stuff * fixed building * fixed building error * ok fixed building for real this time * oops * Fix compilation issues * removed mouse stuff that magically appeared in this branch * smoothed out stick values & removed remains of mouse support * re-added manual camera when pressing Z * reduced minimum Y position of camera * Addressed dcsv's nitpicks * part 2 * oops Co-authored-by: David Chavez * Rando: Allows Malon's Item Check to be obtained by pulling out the Ocarina. [FIXED PR] (#672) * Fixes using the Ocarina to get the check from Malon. Still some cleanup to do here. For some reason the player can shield before receiving the check. It doesn't set the flag if the player does that so they can still try again, but would prefer a different solution if possible. * Prevents Shielding from blocking the Item_Give from happening. * Code Cleanup and comments explaining the new rando flow. * Removes inventory check when pulling out Ocarina This allows OI to properly give the check, which is important for Glitched logic later down the line. Talking to Malon still requires the Ocarina in your inventory. * Prevents non-malon textboxes from triggering the check. Also adds a comment explaining the condtional for getting the check from talking to Malon since it got pretty long. * Actually fixes checking for text boxes. * Relocates a comment for improved clarity. * Fix Rando Water Temple Softlock (#665) We use 3DS logic to generate item placement, but didn't have this specific door in Water Temple unlocked from the beginning like 3DS does. This meant that if people took specific paths through the temple, they could softlock themselves by missing a key. * Rando: GtG and carpenter prompts skip (#663) * Skip gtg and carpenter prompt For rando. Tested and just works. * Fixed missing break * Hide debug overlay behind gDebugEnabled (#660) * Introduce App Directory Path (#572) * Introduce app directory path concept * macos: Remove hacky way of using applicaiton directory * Update the new SaveManager * Address stack user after return * Remove unecessary property * Use std::string for filepath * Improve clang specific detections * Use new path system for imgui files * Improve helper for getting relative paths * fix hidden wnd (#744) * Split damage multiplication into its own PR (#656) * Split damage multiplication into its own PR * Found a more elegant implementation of the powers char*[] * Fixes Maps, Compasses, and Boss Keys in Vanilla. (#751) * .xiF slebaL * Update Keese labels * Fixed soundfont issues * Skip warp song cutscenes in rando (#664) Does it by skipping to the last part of the cutscene data. Tested on all songs, both adult and child. * don't spawn blocking mido after we've already shown him the sword/shield (#675) Co-authored-by: briaguya * Controller Configuration UI and JSON Config (#760) * Initial controller hud ui * Reverted fbdemo changes * Moved config to json and implemented controller config * fix build on linux, gitignore new config file * fix build * Fix compilation and file directory paths * Call save on cvar save * Fixed cvar loading and added deck slots to the config * Changed control deck port 0 to use a physical device by default * Added gyro and rumble & fixed loading errors * Save config on toggle menubar * fix linux build * Fixed drift calculation * Controller config now saves when pressing F1 * Removed ExitGame hook from ImGuiImpl * Moved mappings to a map * Added GetKeyName * untranslate scancodes * Fixed hud layout on keyboard device * Fixed keyboard read on hud * Fixed crash when reloading controllers * Removed ConfigFile and changed file extension * Changed Dummy to Disconnected and fixed filters * Removed function leftover * Changed ControllerHud to InputEditor Co-authored-by: briaguya Co-authored-by: David Chavez * Enough! My ship sails in the morning. * Fixed menubar items position (#763) * Fixed menubar items position * Reverted tooltip tab position * Fixes macOS randomizer functionality with App Directory (#761) * Fixes macOS randomizer functionality with App Directory * Fix windows build * Update soh/soh/Enhancements/randomizer/3drando/rando_main.cpp * Update soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp * Revert band-aid fix Co-authored-by: Kenix3 * Fix migration cvar deletion path (#765) * Various controller fixes (#771) * Fix controller * Also fix rumble strength being a bool * Remove ControllerHud.cpp * Downgrade platform toolset back to previous version * Fix gyro * Fix bug that makes binding axes difficult and clear buttons before reading * Exaggerate gyro display and adjust stick binding threshold * Initialize drift thresholds * git subrepo push soh subrepo: subdir: "soh" merged: "75ccbade8" upstream: origin: "https://github.com/HarbourMasters/soh.git" branch: "master" commit: "75ccbade8" git-subrepo: version: "0.4.1" origin: "???" commit: "???" * One more change from PR review * Fix some paths * Fix merge conflict messup * More merge conflict fixes * And another conflict fix * And another fix * Remove reference to removed build files * Add full path to switch cmake Co-authored-by: David Chavez Co-authored-by: KiritoDev <36680385+KiritoDv@users.noreply.github.com> Co-authored-by: Jeffrey Crowell Co-authored-by: BountyChocolate123456 <101743444+BountyChocolate123456@users.noreply.github.com> Co-authored-by: sholdee <102821812+sholdee@users.noreply.github.com> Co-authored-by: briaguya Co-authored-by: rozlette Co-authored-by: PurpleHato Co-authored-by: Christopher Leggett Co-authored-by: Kenix3 Co-authored-by: vaguerant Co-authored-by: earthcrafterman Co-authored-by: louist103 <35883445+louist103@users.noreply.github.com> Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com> Co-authored-by: qurious-pixel <62252937+qurious-pixel@users.noreply.github.com> Co-authored-by: Baoulettes Co-authored-by: Sirius902 <10891979+Sirius902@users.noreply.github.com> Co-authored-by: modestposer Co-authored-by: Ada <60364512+GreatArgorath@users.noreply.github.com> Co-authored-by: Stormghetti <56653191+Stormghetti@users.noreply.github.com> Co-authored-by: Sirius902 <3645979-Sirius902@users.noreply.gitlab.com> Co-authored-by: MelonSpeedruns Co-authored-by: aMannus Co-authored-by: Dog <5172592+Dog@users.noreply.github.com> Co-authored-by: Nicholas Estelami Co-authored-by: ChristopherJTrent Co-authored-by: agamache Co-authored-by: M4xw --- .gitignore | 11 +- libultraship/Makefile.switch | 2 - libultraship/libultraship/Cvar.h | 10 +- libultraship/libultraship/GlobalCtx2.cpp | 69 +- libultraship/libultraship/ImGuiImpl.cpp | 546 ++++++---- .../libultraship/Lib/Fast3D/gfx_opengl.cpp | 98 +- libultraship/libultraship/Lib/Fast3D/gfx_pc.h | 26 +- .../libultraship/Lib/Fast3D/gfx_sdl2.cpp | 104 +- .../Lib/ImGui/backends/imgui_impl_opengl3.cpp | 1 + libultraship/libultraship/SohImGuiImpl.cpp | 987 ------------------ libultraship/libultraship/Window.cpp | 242 ++--- soh/include/functions.h | 6 +- soh/soh/Enhancements/bootcommands.c | 23 +- soh/src/code/audio_load.c | 430 ++++---- 14 files changed, 953 insertions(+), 1602 deletions(-) delete mode 100644 libultraship/libultraship/SohImGuiImpl.cpp diff --git a/.gitignore b/.gitignore index 2940b34a7ac..1d41d50aefe 100644 --- a/.gitignore +++ b/.gitignore @@ -401,10 +401,17 @@ ZAPD/BuildInfo.h DebugObj/* ReleaseObj/* +.tags +tags +oot.otr +*.sav +shipofharkinian.ini +shipofharkinian.json -// Switch Stuff +# Switch Stuff *.nro *.nacp ZAPDTR/ZAPDUtils/lib/* -!/soh/icon.jpg \ No newline at end of file +!/soh/icon.jpg + diff --git a/libultraship/Makefile.switch b/libultraship/Makefile.switch index b1e6e9e18b1..d8c93ad043d 100644 --- a/libultraship/Makefile.switch +++ b/libultraship/Makefile.switch @@ -77,8 +77,6 @@ SOURCEFILES_CPP := \ libultraship/Factories/VtxFactory.cpp \ libultraship/Array.cpp \ libultraship/Audio.cpp \ - libultraship/ConfigFile.cpp \ - libultraship/Controller.cpp \ libultraship/Hooks.cpp \ libultraship/Factories/CollisionHeaderFactory.cpp \ libultraship/Factories/DisplayListFactory.cpp \ diff --git a/libultraship/libultraship/Cvar.h b/libultraship/libultraship/Cvar.h index f9583ef0c95..717e21a1355 100644 --- a/libultraship/libultraship/Cvar.h +++ b/libultraship/libultraship/Cvar.h @@ -1,8 +1,6 @@ #ifndef _CVAR_H #define _CVAR_H -#include - typedef enum CVarType { CVAR_TYPE_S32, CVAR_TYPE_FLOAT, CVAR_TYPE_STRING } CVarType; typedef struct CVar { @@ -10,7 +8,7 @@ typedef struct CVar { CVarType type; union { - s32 valueS32; + int valueS32; float valueFloat; const char* valueStr; } value; @@ -23,13 +21,13 @@ extern "C" //#include CVar* CVar_Get(const char* name); -s32 CVar_GetS32(const char* name, s32 defaultValue); +int CVar_GetS32(const char* name, int defaultValue); float CVar_GetFloat(const char* name, float defaultValue); const char* CVar_GetString(const char* name, const char* defaultValue); -void CVar_SetS32(const char* name, s32 value); +void CVar_SetS32(const char* name, int value); void CVar_SetString(const char* name, const char* value); -void CVar_RegisterS32(const char* name, s32 defaultValue); +void CVar_RegisterS32(const char* name, int defaultValue); void CVar_RegisterFloat(const char* name, float defaultValue); void CVar_RegisterString(const char* name, const char* defaultValue); diff --git a/libultraship/libultraship/GlobalCtx2.cpp b/libultraship/libultraship/GlobalCtx2.cpp index fb6219cb654..e44f0de8e20 100644 --- a/libultraship/libultraship/GlobalCtx2.cpp +++ b/libultraship/libultraship/GlobalCtx2.cpp @@ -8,6 +8,9 @@ #include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/sinks/sohconsole_sink.h" #include "ModManager.h" +#ifdef __APPLE__ +#include "OSXFolderManager.h" +#endif namespace Ship { std::weak_ptr GlobalCtx2::Context; @@ -29,7 +32,23 @@ namespace Ship { return GetInstance(); } - GlobalCtx2::GlobalCtx2(const std::string& Name) : Name(Name), MainPath(""), PatchesPath("") { + std::string GlobalCtx2::GetAppDirectoryPath() { + #ifdef __APPLE__ + FolderManager folderManager; + std::string fpath = std::string(folderManager.pathForDirectory(NSApplicationSupportDirectory, NSUserDomainMask)); + fpath.append("/com.shipofharkinian.soh"); + return fpath; + #endif + + return "."; + + } + + std::string GlobalCtx2::GetPathRelativeToAppDirectory(const char* path) { + return GlobalCtx2::GetAppDirectoryPath() + "/" + path; + } + + GlobalCtx2::GlobalCtx2(std::string Name) : Name(std::move(Name)) { } @@ -40,22 +59,19 @@ namespace Ship { void GlobalCtx2::InitWindow() { InitLogging(); - Config = std::make_shared(GlobalCtx2::GetInstance(), "shipofharkinian.ini"); - MainPath = (*Config)["ARCHIVE"]["Main Archive"]; - if (MainPath.empty()) { - MainPath = "oot.otr"; - } - PatchesPath = (*Config)["ARCHIVE"]["Patches Directory"]; - if (PatchesPath.empty()) { - PatchesPath = "./mods"; - } - ResMan = std::make_shared(GlobalCtx2::GetInstance(), MainPath, PatchesPath); - Win = std::make_shared(GlobalCtx2::GetInstance()); + Config = std::make_shared(GetPathRelativeToAppDirectory("shipofharkinian.json")); + Config->reload(); + + MainPath = Config->getString("Game.Main Archive", GetPathRelativeToAppDirectory("oot.otr")); + PatchesPath = Config->getString("Game.Patches Archive", GetAppDirectoryPath() + "/mods"); + + ResMan = std::make_shared(GetInstance(), MainPath, PatchesPath); + Win = std::make_shared(GetInstance()); if (!ResMan->DidLoadSuccessfully()) { #ifdef _WIN32 - MessageBox(NULL, L"Main OTR file not found!", L"Uh oh", MB_OK); + MessageBox(nullptr, L"Main OTR file not found!", L"Uh oh", MB_OK); #elif defined(__SWITCH__) printf("Main OTR file not found!\n"); #else @@ -69,11 +85,13 @@ namespace Ship { void GlobalCtx2::InitLogging() { try { + auto logPath = GetPathRelativeToAppDirectory(("logs/" + GetName() + ".log").c_str()); + // Setup Logging spdlog::init_thread_pool(8192, 1); auto SohConsoleSink = std::make_shared(); auto ConsoleSink = std::make_shared(); - auto FileSink = std::make_shared("logs/" + GetName() + ".log", 1024 * 1024 * 10, 10); + auto FileSink = std::make_shared(logPath, 1024 * 1024 * 10, 10); SohConsoleSink->set_level(spdlog::level::trace); ConsoleSink->set_level(spdlog::level::trace); FileSink->set_level(spdlog::level::trace); @@ -88,4 +106,25 @@ namespace Ship { std::cout << "Log initialization failed: " << ex.what() << std::endl; } } -} \ No newline at end of file + + void GlobalCtx2::WriteSaveFile(const std::filesystem::path& savePath, const uintptr_t addr, void* dramAddr, const size_t size) { + std::ofstream saveFile = std::ofstream(savePath, std::fstream::in | std::fstream::out | std::fstream::binary); + saveFile.seekp(addr); + saveFile.write((char*)dramAddr, size); + saveFile.close(); + } + + void GlobalCtx2::ReadSaveFile(std::filesystem::path savePath, uintptr_t addr, void* dramAddr, size_t size) { + std::ifstream saveFile = std::ifstream(savePath, std::fstream::in | std::fstream::out | std::fstream::binary); + + // If the file doesn't exist, initialize DRAM + if (saveFile.good()) { + saveFile.seekg(addr); + saveFile.read((char*)dramAddr, size); + } else { + memset(dramAddr, 0, size); + } + + saveFile.close(); + } +} diff --git a/libultraship/libultraship/ImGuiImpl.cpp b/libultraship/libultraship/ImGuiImpl.cpp index 153a193e8d3..4d892b27846 100644 --- a/libultraship/libultraship/ImGuiImpl.cpp +++ b/libultraship/libultraship/ImGuiImpl.cpp @@ -26,6 +26,7 @@ #include "Lib/Fast3D/gfx_rendering_api.h" #include "Lib/spdlog/include/spdlog/common.h" #include "Utils/StringHelper.h" +#include "SwitchImpl.h" #ifdef ENABLE_OPENGL #include "Lib/ImGui/backends/imgui_impl_opengl3.h" @@ -47,11 +48,10 @@ bool oldCursorState = true; #define EXPERIMENTAL() \ ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 50, 50, 255)); \ - ImGui::Text("Experimental"); \ - ImGui::PopStyleColor(); \ - ImGui::Separator(); + ImGui::Text("Experimental"); \ + ImGui::PopStyleColor(); \ + ImGui::Separator(); #define TOGGLE_BTN ImGuiKey_F1 -#define TOGGLE_PAD_BTN ImGuiKey_GamepadBack #define HOOK(b) if(b) needs_save = true; OSContPad* pads; @@ -68,6 +68,26 @@ namespace SohImGui { static ImVector s_GroupPanelLabelStack; bool p_open = false; bool needs_save = false; +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp +======== + std::vector CustomTexts; + int SelectedLanguage = CVar_GetS32("gLanguages", 0); //Default Language to 0=English 1=German 2=French + float kokiri_col[3] = { 0.118f, 0.41f, 0.106f }; + float goron_col[3] = { 0.392f, 0.078f, 0.0f }; + float zora_col[3] = { 0.0f, 0.235f, 0.392f }; + + float navi_idle_i_col[3] = { 0.0f, 0.0f, 0.0f }; + float navi_idle_o_col[3] = { 0.0f, 0.0f, 0.0f }; + + float navi_npc_i_col[3] = { 0.0f, 0.0f, 0.0f }; + float navi_npc_o_col[3] = { 0.0f, 0.0f, 0.0f }; + + float navi_enemy_i_col[3] = { 0.0f, 0.0f, 0.0f }; + float navi_enemy_o_col[3] = { 0.0f, 0.0f, 0.0f }; + + float navi_prop_i_col[3] = { 0.0f, 0.0f, 0.0f }; + float navi_prop_o_col[3] = { 0.0f, 0.0f, 0.0f }; +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp const char* filters[3] = { "Three-Point", @@ -91,15 +111,6 @@ namespace SohImGui { std::map> windowCategories; std::map customWindows; - int ClampFloatToInt(float value, int min, int max) { - return fmin(fmax(value, min), max); - } - - void Tooltip(const char* text) { - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("%s", text); - } - void ImGuiWMInit() { switch (impl.backend) { case Backend::SDL: @@ -114,6 +125,50 @@ namespace SohImGui { break; } + // OTRTODO: This gameplay specific stuff should not be in libultraship. This needs to be moved to soh and use sTunicColors + kokiri_col[0] = 30 / 255.0f; + kokiri_col[1] = 105 / 255.0f; + kokiri_col[2] = 27 / 255.0f; + + goron_col[0] = 100 / 255.0f; + goron_col[1] = 20 / 255.0f; + goron_col[2] = 0; + + zora_col[0] = 0; + zora_col[1] = 60 / 255.0f; + zora_col[2] = 100 / 255.0f; + + navi_idle_i_col[0] = 0; + navi_idle_i_col[1] = 0; + navi_idle_i_col[2] = 0; + + navi_idle_o_col[0] = 0; + navi_idle_o_col[1] = 0; + navi_idle_o_col[2] = 0; + + navi_npc_i_col[0] = 0; + navi_npc_i_col[1] = 0; + navi_npc_i_col[2] = 0; + + navi_npc_o_col[0] = 0; + navi_npc_o_col[1] = 0; + navi_npc_o_col[2] = 0; + + navi_enemy_i_col[0] = 0; + navi_enemy_i_col[1] = 0; + navi_enemy_i_col[2] = 0; + + navi_enemy_o_col[0] = 0; + navi_enemy_o_col[1] = 0; + navi_enemy_o_col[2] = 0; + + navi_prop_i_col[0] = 0; + navi_prop_i_col[1] = 0; + navi_prop_i_col[2] = 0; + + navi_prop_o_col[0] = 0; + navi_prop_o_col[1] = 0; + navi_prop_o_col[2] = 0; } void ImGuiBackendInit() { @@ -245,6 +300,7 @@ namespace SohImGui { stbi_image_free(img_data); } +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp void LoadPickersColors(ImVec4& ColorArray, const char* cvarname, const ImVec4& default_colors, bool has_alpha) { std::string Cvar_Red = cvarname; Cvar_Red += "R"; @@ -263,6 +319,8 @@ namespace SohImGui { } } +======== +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp void LoadResource(const std::string& name, const std::string& path, const ImVec4& tint) { GfxRenderingAPI* api = gfx_get_current_rendering_api(); const auto res = static_cast(GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(path).get()); @@ -315,9 +373,6 @@ namespace SohImGui { io = &ImGui::GetIO(); io->ConfigFlags |= ImGuiConfigFlags_DockingEnable; io->Fonts->AddFontDefault(); - if (CVar_GetS32("gOpenMenuBar", 0) != 1) { - SohImGui::overlay->TextDrawNotification(30.0f, true, "Press F1 to access enhancements menu"); - } auto imguiIniPath = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("imgui.ini"); auto imguiLogPath = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("imgui_log.txt"); @@ -332,8 +387,12 @@ namespace SohImGui { controller->Init(); ImGuiWMInit(); ImGuiBackendInit(); + #ifdef __SWITCH__ + ImGui::GetStyle().ScaleAllSizes(Ship::Switch::GetDPI() / 96.0f); + #endif + + ModInternal::registerHookListener({ GFX_INIT, [](const HookEvent ev) { - ModInternal::RegisterHook([] { if (GlobalCtx2::GetInstance()->GetWindow()->IsFullscreen()) ShowCursor(CVar_GetS32("gOpenMenuBar", 0), Dialogues::dLoadSettings); @@ -348,12 +407,27 @@ namespace SohImGui { LoadTexture("C-Right", "assets/ship_of_harkinian/buttons/CRight.png"); LoadTexture("C-Up", "assets/ship_of_harkinian/buttons/CUp.png"); LoadTexture("C-Down", "assets/ship_of_harkinian/buttons/CDown.png"); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp }); ModInternal::RegisterHook([](OSContPad* cont_pad) { pads = cont_pad; }); +======== + } }); + + for (const auto& [i, controllers] : Ship::Window::Controllers) + { + CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftX", i).c_str(), 0); + CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftY", i).c_str(), 0); + needs_save = true; + } + + ModInternal::registerHookListener({ CONTROLLER_READ, [](const HookEvent ev) { + pads = static_cast(ev->baseArgs["cont_pad"]); + }}); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp Game::InitSettings(); CVar_SetS32("gRandoGenerating", 0); @@ -364,6 +438,11 @@ namespace SohImGui { } void Update(EventImpl event) { + #ifdef __SWITCH__ + int xPos, yPos; + Switch::GetTouchPosition(&xPos, &yPos); + io->MousePos = ImVec2(xPos, yPos); + #endif if (needs_save) { Game::SaveSettings(); needs_save = false; @@ -386,29 +465,7 @@ namespace SohImGui { } } - - void EnhancementCombobox(const char* name, const char* ComboArray[], size_t arraySize, uint8_t FirstTimeValue = 0) { - if (FirstTimeValue <= 0) { - FirstTimeValue = 0; - } - uint8_t selected = CVar_GetS32(name, FirstTimeValue); - uint8_t DefaultValue = selected; - std::string comboName = std::string("##") + std::string(name); - if (ImGui::BeginCombo(comboName.c_str(), ComboArray[DefaultValue])) { - for (uint8_t i = 0; i < arraySize; i++) { - if (strlen(ComboArray[i]) > 1) { - if (ImGui::Selectable(ComboArray[i], i == selected)) { - CVar_SetS32(name, i); - selected = i; - needs_save = true; - } - } - } - ImGui::EndCombo(); - } - } - - void EnhancementRadioButton(const char* text, const char* cvarName, int id) { + void EnhancementRadioButton(std::string text, std::string cvarName, int id) { /*Usage : EnhancementRadioButton("My Visible Name","gMyCVarName", MyID); First arg is the visible name of the Radio button @@ -419,147 +476,105 @@ namespace SohImGui { EnhancementRadioButton("German", "gLanguages", 1); EnhancementRadioButton("French", "gLanguages", 2); */ - std::string make_invisible = "##"; - make_invisible += text; - make_invisible += cvarName; - - int val = CVar_GetS32(cvarName, 0); - if (ImGui::RadioButton(make_invisible.c_str(), id == val)) { - CVar_SetS32(cvarName, id); + int val = CVar_GetS32(cvarName.c_str(), 0); + if (ImGui::RadioButton(text.c_str(), id==val)) { + CVar_SetS32(cvarName.c_str(), (int)id); needs_save = true; } - ImGui::SameLine(); - ImGui::Text("%s", text); } - void EnhancementCheckbox(const char* text, const char* cvarName) + void EnhancementCheckbox(std::string text, std::string cvarName) { - bool val = (bool)CVar_GetS32(cvarName, 0); - if (ImGui::Checkbox(text, &val)) { - CVar_SetS32(cvarName, val); + bool val = (bool)CVar_GetS32(cvarName.c_str(), 0); + if (ImGui::Checkbox(text.c_str(), &val)) { + CVar_SetS32(cvarName.c_str(), val); needs_save = true; } } - void EnhancementButton(const char* text, const char* cvarName) + void EnhancementButton(std::string text, std::string cvarName) { - bool val = (bool)CVar_GetS32(cvarName, 0); - if (ImGui::Button(text)) { - CVar_SetS32(cvarName, !val); - CVar_SetS32(cvarName, !val); + bool val = (bool)CVar_GetS32(cvarName.c_str(), 0); + if (ImGui::Button(text.c_str())) { + CVar_SetS32(cvarName.c_str(), !val); needs_save = true; } } +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp void EnhancementSliderInt(const char* text, const char* id, const char* cvarName, int min, int max, const char* format, int defaultValue) { int val = CVar_GetS32(cvarName, defaultValue); +======== + void EnhancementSliderInt(std::string text, std::string id, std::string cvarName, int min, int max, std::string format) + { + int val = CVar_GetS32(cvarName.c_str(), 0); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp - ImGui::Text(text, val); + ImGui::Text(text.c_str(), val); - if (ImGui::SliderInt(id, &val, min, max, format)) + if (ImGui::SliderInt(id.c_str(), &val, min, max, format.c_str())) { - CVar_SetS32(cvarName, val); + CVar_SetS32(cvarName.c_str(), val); needs_save = true; } if (val < min) { val = min; - CVar_SetS32(cvarName, val); + CVar_SetS32(cvarName.c_str(), val); needs_save = true; } if (val > max) { val = max; - CVar_SetS32(cvarName, val); + CVar_SetS32(cvarName.c_str(), val); needs_save = true; } } - void EnhancementSliderFloat(const char* text, const char* id, const char* cvarName, float min, float max, const char* format, float defaultValue, bool isPercentage) + void EnhancementSliderFloat(std::string text, std::string id, std::string cvarName, float min, float max, std::string format, float defaultValue, bool isPercentage) { - float val = CVar_GetFloat(cvarName, defaultValue); + float val = CVar_GetFloat(cvarName.c_str(), defaultValue); if (!isPercentage) - ImGui::Text(text, val); + ImGui::Text(text.c_str(), val); else - ImGui::Text(text, static_cast(100 * val)); + ImGui::Text(text.c_str(), static_cast(100 * val)); - if (ImGui::SliderFloat(id, &val, min, max, format)) + if (ImGui::SliderFloat(id.c_str(), &val, min, max, format.c_str())) { - CVar_SetFloat(cvarName, val); + CVar_SetFloat(cvarName.c_str(), val); needs_save = true; } if (val < min) { val = min; - CVar_SetFloat(cvarName, val); + CVar_SetFloat(cvarName.c_str(), val); needs_save = true; } if (val > max) { val = max; - CVar_SetFloat(cvarName, val); - needs_save = true; - } - } - - void EnhancementCombo(const std::string& name, const char* cvarName, const std::vector& items, int defaultValue) { - - if (ImGui::BeginCombo(name.c_str(), items[static_cast(CVar_GetS32(cvarName, defaultValue))].c_str())) { - for (int settingIndex = 0; settingIndex < (int) items.size(); settingIndex++) { - if (ImGui::Selectable(items[settingIndex].c_str())) { - CVar_SetS32(cvarName, settingIndex); - needs_save = true; - - } - } - ImGui::EndCombo(); - } - } - - void RandomizeColor(const char* cvarName, ImVec4* colors) { - std::string Cvar_Red = cvarName; - Cvar_Red += "R"; - std::string Cvar_Green = cvarName; - Cvar_Green += "G"; - std::string Cvar_Blue = cvarName; - Cvar_Blue += "B"; - std::string Cvar_RBM = cvarName; - Cvar_RBM += "RBM"; - std::string MakeInvisible = "##"; - MakeInvisible += cvarName; - MakeInvisible += "Random"; - std::string FullName = "Random"; - FullName += MakeInvisible; - if (ImGui::Button(FullName.c_str())) { - s16 RND_R = rand() % (255 - 0); - s16 RND_G = rand() % (255 - 0); - s16 RND_B = rand() % (255 - 0); - colors->x = (float)RND_R / 255; - colors->y = (float)RND_G / 255; - colors->z = (float)RND_B / 255; - CVar_SetS32(Cvar_Red.c_str(), ClampFloatToInt(colors->x * 255, 0, 255)); - CVar_SetS32(Cvar_Green.c_str(), ClampFloatToInt(colors->y * 255, 0, 255)); - CVar_SetS32(Cvar_Blue.c_str(), ClampFloatToInt(colors->z * 255, 0, 255)); - CVar_SetS32(Cvar_RBM.c_str(), 0); //On click disable rainbow mode. + CVar_SetFloat(cvarName.c_str(), val); needs_save = true; } +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp Tooltip("Chooses a random color\nOverwrites previously chosen color"); +======== +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp } - void RainbowColor(const char* cvarName, ImVec4* colors) { - std::string Cvar_RBM = cvarName; - Cvar_RBM += "RBM"; - std::string MakeInvisible = "Rainbow"; - MakeInvisible += "##"; - MakeInvisible += cvarName; - MakeInvisible += "Rainbow"; + void EnhancementColor3(std::string text, std::string cvarName, float defaultColors[3]) + { + int r = CVar_GetS32((cvarName + "_Red").c_str(), (defaultColors[0] * 255.0f)); + int g = CVar_GetS32((cvarName + "_Green").c_str(), (defaultColors[1] * 255.0f)); + int b = CVar_GetS32((cvarName + "_Blue").c_str(), (defaultColors[2] * 255.0f)); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp EnhancementCheckbox(MakeInvisible.c_str(), Cvar_RBM.c_str()); Tooltip("Cycles through colors on a timer\nOverwrites previously chosen color"); } @@ -644,9 +659,30 @@ namespace SohImGui { } ImGui::NewLine(); ImGui::PopItemWidth(); +======== + float colors[3]; + colors[0] = r / 255.0f; + colors[1] = g / 255.0f; + colors[2] = b / 255.0f; + + { + if (ImGui::ColorEdit3(text.c_str(), colors)) + { + CVar_SetS32((cvarName + "_Red").c_str(), (int)(colors[0] * 255)); + CVar_SetS32((cvarName + "_Green").c_str(), (int)(colors[1] * 255)); + CVar_SetS32((cvarName + "_Blue").c_str(), (int)(colors[2] * 255)); + needs_save = true; + } + } + } + + void Tooltip(std::string text){ + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("%s", text.c_str()); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp } - void DrawMainMenuAndCalculateGameSize(void) { + void DrawMainMenuAndCalculateGameSize() { console->Update(); ImGuiBackendNewFrame(); ImGuiWMNewFrame(); @@ -660,7 +696,7 @@ namespace SohImGui { const ImGuiViewport* viewport = ImGui::GetMainViewport(); ImGui::SetNextWindowPos(viewport->WorkPos); - ImGui::SetNextWindowSize(ImVec2(wnd->GetCurrentWidth(), wnd->GetCurrentHeight())); + ImGui::SetNextWindowSize(ImVec2((int) wnd->GetCurrentWidth(), (int) wnd->GetCurrentHeight())); ImGui::SetNextWindowViewport(viewport->ID); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); @@ -755,6 +791,7 @@ namespace SohImGui { if (ImGui::BeginMenu("Controller")) { +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp EnhancementCheckbox("Use Controller Navigation", "gControlNav"); Tooltip("Allows controller navigation of the menu bar\nD-pad to move between items, A to select, and X to grab focus on the menu bar"); @@ -777,6 +814,49 @@ namespace SohImGui { EnhancementSliderFloat("Input Scale: %.1f", "##Input", "gInputScale", 1.0f, 3.0f, "", 1.0f, false); Tooltip("Sets the on screen size of the displayed inputs from the Show Inputs setting"); +======== + for (const auto& [i, controllers] : Ship::Window::Controllers) + { + bool hasPad = std::find_if(controllers.begin(), controllers.end(), [](const auto& c) { + return c->HasPadConf() && c->Connected(); + }) != controllers.end(); + + if (!hasPad) continue; + + auto menuLabel = "Controller " + std::to_string(i + 1); + if (ImGui::BeginMenu(menuLabel.c_str())) + { + EnhancementSliderFloat("Gyro Sensitivity: %d %%", "##GYROSCOPE", StringHelper::Sprintf("gCont%i_GyroSensitivity", i), 0.0f, 1.0f, "", 1.0f, true); + + if (ImGui::Button("Recalibrate Gyro")) + { + CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftX", i).c_str(), 0); + CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftY", i).c_str(), 0); + needs_save = true; + } + + ImGui::Separator(); + + EnhancementSliderFloat("Rumble Strength: %d %%", "##RUMBLE", StringHelper::Sprintf("gCont%i_RumbleStrength", i), 0.0f, 1.0f, "", 1.0f, true); + + ImGui::EndMenu(); + } + ImGui::Separator(); + } +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp + + EnhancementCheckbox("Show Inputs", "gInputEnabled"); + Tooltip("Shows currently pressed inputs on the bottom right of the screen"); + EnhancementCheckbox("Rumble Enabled", "gRumbleEnabled"); + + EnhancementSliderFloat("Input Scale: %.1f", "##Input", "gInputScale", 1.0f, 3.0f, "", 1.0f, false); + Tooltip("Sets the on screen size of the displayed inputs from Show Inputs"); + + ImGui::Separator(); + + EnhancementCheckbox("D-pad Support on Pause and File Select", "gDpadPauseName"); + EnhancementCheckbox("D-pad Support in Ocarina and Text Choice", "gDpadOcarinaText"); + EnhancementCheckbox("D-pad Support for Browsing Shop Items", "gDpadShop"); ImGui::EndMenu(); } @@ -785,6 +865,7 @@ namespace SohImGui { if (ImGui::BeginMenu("Graphics")) { +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp EnhancementSliderFloat("Internal Resolution: %d %%", "##IMul", "gInternalResolution", 0.5f, 2.0f, "", 1.0f, true); Tooltip("Multiplies your output resolution by the value inputted,\nas a more intensive but effective form of anti-aliasing"); gfx_current_dimensions.internal_mul = CVar_GetFloat("gInternalResolution", 1); @@ -822,11 +903,31 @@ namespace SohImGui { "to do CPU + GPU work in time."); } +======== + EnhancementSliderInt("Internal Resolution: %dx", "##IMul", "gInternalResolution", 1, 8, ""); + Tooltip("Increases the render resolution of the game, up to 8x your output resolution,\nas a more intensive but effective form of anti-aliasing"); + gfx_current_dimensions.internal_mul = CVar_GetS32("gInternalResolution", 1); + EnhancementSliderInt("MSAA: %d", "##IMSAA", "gMSAAValue", 1, 8, ""); + Tooltip("Activates anti-aliasing when above 1, up to 8x for 8 samples for every pixel"); + gfx_msaa_level = CVar_GetS32("gMSAAValue", 1); + +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp EXPERIMENTAL(); ImGui::Text("Texture Filter (Needs reload)"); - EnhancementCombobox("gTextureFilter", filters, 3, 0); GfxRenderingAPI* gapi = gfx_get_current_rendering_api(); - gapi->set_texture_filter((FilteringMode)CVar_GetS32("gTextureFilter", 0)); + if (ImGui::BeginCombo("##filters", filters[gapi->get_texture_filter()])) { + for (int fId = 0; fId <= FilteringMode::NONE; fId++) { + if (ImGui::Selectable(filters[fId], fId == gapi->get_texture_filter())) { + INFO("New Filter: %s", filters[fId]); + gapi->set_texture_filter((FilteringMode)fId); + + CVar_SetS32("gTextureFilter", (int) fId); + needs_save = true; + } + + } + ImGui::EndCombo(); + } overlay->DrawSettings(); ImGui::EndMenu(); } @@ -844,6 +945,7 @@ namespace SohImGui { if (ImGui::BeginMenu("Enhancements")) { +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp if (ImGui::BeginMenu("Gameplay")) { if (ImGui::BeginMenu("Time Savers")) @@ -1013,47 +1115,15 @@ namespace SohImGui { Tooltip("Allows graves to be pulled when child during the day"); ImGui::EndMenu(); } +======== + ImGui::Text("Gameplay"); + ImGui::Separator(); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp - if (ImGui::BeginMenu("Graphics")) - { - if (ImGui::BeginMenu("Animated Link in Pause Menu")) { - ImGui::Text("Rotation"); - EnhancementRadioButton("Disabled", "gPauseLiveLinkRotation", 0); - EnhancementRadioButton("Rotate Link with D-pad", "gPauseLiveLinkRotation", 1); - Tooltip("Allow you to rotate Link on the Equipment menu with the DPAD\nUse DPAD-Up or DPAD-Down to reset Link's rotation"); - EnhancementRadioButton("Rotate Link with C-buttons", "gPauseLiveLinkRotation", 2); - Tooltip("Allow you to rotate Link on the Equipment menu with the C-buttons\nUse C-Up or C-Down to reset Link's rotation"); - - if (CVar_GetS32("gPauseLiveLinkRotation", 0) != 0) { - EnhancementSliderInt("Rotation Speed: %d", "##MinRotationSpeed", "gPauseLiveLinkRotationSpeed", 1, 20, ""); - } - ImGui::Separator(); - ImGui::Text("Static loop"); - EnhancementRadioButton("Disabled", "gPauseLiveLink", 0); - EnhancementRadioButton("Idle (standing)", "gPauseLiveLink", 1); - EnhancementRadioButton("Idle (look around)", "gPauseLiveLink", 2); - EnhancementRadioButton("Idle (belt)", "gPauseLiveLink", 3); - EnhancementRadioButton("Idle (shield)", "gPauseLiveLink", 4); - EnhancementRadioButton("Idle (test sword)", "gPauseLiveLink", 5); - EnhancementRadioButton("Idle (yawn)", "gPauseLiveLink", 6); - EnhancementRadioButton("Battle Stance", "gPauseLiveLink", 7); - EnhancementRadioButton("Walking (no shield)", "gPauseLiveLink", 8); - EnhancementRadioButton("Walking (holding shield)", "gPauseLiveLink", 9); - EnhancementRadioButton("Running (no shield)", "gPauseLiveLink", 10); - EnhancementRadioButton("Running (holding shield)", "gPauseLiveLink", 11); - EnhancementRadioButton("Hand on hip", "gPauseLiveLink", 12); - EnhancementRadioButton("Spin attack charge", "gPauseLiveLink", 13); - EnhancementRadioButton("Look at hand", "gPauseLiveLink", 14); - ImGui::Separator(); - ImGui::Text("Randomize"); - EnhancementRadioButton("Random", "gPauseLiveLink", 15); - Tooltip("Randomize the animation played each time you open the menu"); - EnhancementRadioButton("Random cycle", "gPauseLiveLink", 16); - Tooltip("Randomize the animation played on the menu after a certain time"); - if (CVar_GetS32("gPauseLiveLink", 0) >= 16) { - EnhancementSliderInt("Frame to wait: %d", "##MinFrameCount", "gMinFrameCount", 1, 1000, ""); - } + EnhancementSliderInt("Text Speed: %dx", "##TEXTSPEED", "gTextSpeed", 1, 5, ""); + EnhancementSliderInt("King Zora Speed: %dx", "##WEEPSPEED", "gMweepSpeed", 1, 5, ""); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp ImGui::EndMenu(); } EnhancementCheckbox("N64 Mode", "gN64Mode"); @@ -1066,10 +1136,21 @@ namespace SohImGui { Tooltip("Changes the rupee in the wallet icon to match the wallet size you currently have"); EnhancementCheckbox("Always show dungeon entrances", "gAlwaysShowDungeonMinimapIcon"); Tooltip("Always shows dungeon entrance icons on the minimap"); +======== + EnhancementCheckbox("Skip Text", "gSkipText"); + Tooltip("Holding down B skips text"); + EnhancementCheckbox("Minimal UI", "gMinimalUI"); + Tooltip("Hides most of the UI when not needed"); + EnhancementCheckbox("MM Bunny Hood", "gMMBunnyHood"); + Tooltip("Wearing the Bunny Hood grants a speed increase like in Majora's Mask"); + EnhancementCheckbox("Visual Stone of Agony", "gVisualAgony"); + Tooltip("Displays an icon and plays a sound when Stone of Agony should be activated, for those without rumble"); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp + + ImGui::Text("Graphics"); + ImGui::Separator(); - ImGui::EndMenu(); - } - +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp if (ImGui::BeginMenu("Fixes")) { EnhancementCheckbox("Fix L&R Pause menu", "gUniformLR"); @@ -1088,10 +1169,20 @@ namespace SohImGui { Tooltip("Correctly centers the Navi text prompt on the HUD's C-Up button"); EnhancementCheckbox("Fix Anubis fireballs", "gAnubisFix"); Tooltip("Make Anubis fireballs do fire damage when reflected\nback at them with the Mirror Shield"); - - ImGui::EndMenu(); - } - +======== + EnhancementCheckbox("N64 Mode", "gN64Mode"); + Tooltip("Sets aspect ratio to 4:3 and lowers resolution to 240p, the N64's native resolution"); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp + + EnhancementCheckbox("Animated Link in Pause Menu", "gPauseLiveLink"); + EnhancementCheckbox("Enable 3D Dropped items", "gNewDrops"); + EnhancementCheckbox("Faster Block Push", "gFasterBlockPush"); + EnhancementCheckbox("Dynamic Wallet Icon", "gDynamicWalletIcon"); + Tooltip("Changes the rupee in the wallet icon to match the wallet size you currently have"); + EnhancementCheckbox("Always show dungeon entrances", "gAlwaysShowDungeonMinimapIcon"); + Tooltip("Always shows dungeon entrance icons on the minimap"); + +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp if (ImGui::BeginMenu("Restoration")) { EnhancementCheckbox("Red Ganon blood", "gRedGanonBlood"); @@ -1163,10 +1254,68 @@ namespace SohImGui { EnhancementCheckbox("Free Camera", "gFreeCamera"); + #ifdef __SWITCH__ + int slot = CVar_GetS32("gSwitchPerfMode", (int)SwitchProfiles::STOCK); + ImGui::Text("Switch performance mode"); + if (ImGui::BeginCombo("##perf", SWITCH_CPU_PROFILES[slot])) { + for (int sId = 0; sId <= SwitchProfiles::POWERSAVINGM3; sId++) { + if (ImGui::Selectable(SWITCH_CPU_PROFILES[sId], sId == slot)) { + INFO("Profile:: %s", SWITCH_CPU_PROFILES[sId]); + CVar_SetS32("gSwitchPerfMode", sId); + needs_save = true; + } + + } + ImGui::EndCombo(); + } + #endif +======== + ImGui::Text("Fixes"); + ImGui::Separator(); + EnhancementCheckbox("Fix L&R Pause menu", "gUniformLR"); + Tooltip("Makes the L and R buttons in the pause menu the same color"); + EnhancementCheckbox("Fix Dungeon entrances", "gFixDungeonMinimapIcon"); + Tooltip("Show dungeon entrances icon only when it should be"); + EnhancementCheckbox("Fix Two Handed idle animations", "gTwoHandedIdle"); + Tooltip("Makes two handed idle animation play, a seemingly finished animation that was disabled on accident in the original game"); + + EXPERIMENTAL(); + + EnhancementCheckbox("60 fps interpolation", "g60FPS"); + EnhancementCheckbox("Disable LOD", "gDisableLOD"); + Tooltip("Turns off the level of detail setting, making models always use their higher poly variants"); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp + ImGui::EndMenu(); } +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp ImGui::SetCursorPosY(0.0f); +======== + if (ImGui::BeginMenu("Cosmetics")) + { + ImGui::Text("Tunics"); + ImGui::Separator(); + + EnhancementColor3("Kokiri Tunic", "gTunic_Kokiri", kokiri_col); + EnhancementColor3("Goron Tunic", "gTunic_Goron", goron_col); + EnhancementColor3("Zora Tunic", "gTunic_Zora", zora_col); + + ImGui::Text("Navi"); + ImGui::Separator(); + + EnhancementColor3("Navi Idle Inner", "gNavi_Idle_Inner", navi_idle_i_col); + EnhancementColor3("Navi Idle Outer", "gNavi_Idle_Outer", navi_idle_o_col); + EnhancementColor3("Navi NPC Inner", "gNavi_NPC_Inner", navi_npc_i_col); + EnhancementColor3("Navi NPC Outer", "gNavi_NPC_Outer", navi_npc_o_col); + EnhancementColor3("Navi Enemy Inner", "gNavi_Enemy_Inner", navi_enemy_i_col); + EnhancementColor3("Navi Enemy Outer", "gNavi_Enemy_Outer", navi_enemy_o_col); + EnhancementColor3("Navi Prop Inner", "gNavi_Prop_Inner", navi_prop_i_col); + EnhancementColor3("Navi Prop Outer", "gNavi_Prop_Outer", navi_prop_o_col); + + ImGui::EndMenu(); + } +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp if (ImGui::BeginMenu("Cheats")) { @@ -1182,18 +1331,23 @@ namespace SohImGui { } EnhancementCheckbox("No Clip", "gNoClip"); - Tooltip("Allows you to walk through walls"); + Tooltip("Allows you to walk through walls"); EnhancementCheckbox("Climb Everything", "gClimbEverything"); - Tooltip("Makes every surface in the game climbable"); + Tooltip("Makes every surface in the game climbable"); EnhancementCheckbox("Moon Jump on L", "gMoonJumpOnL"); - Tooltip("Holding L makes you float into the air"); + Tooltip("Holding L makes you float into the air"); EnhancementCheckbox("Super Tunic", "gSuperTunic"); - Tooltip("Makes every tunic have the effects of every other tunic"); + Tooltip("Makes every tunic have the effects of every other tunic"); EnhancementCheckbox("Easy ISG", "gEzISG"); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp Tooltip("Passive Infinite Sword Glitch\nIt makes your sword's swing effect and hitbox stay active indefinitely"); +======== + Tooltip("Automatically activates the Infinite Sword glitch, making you constantly swing your sword"); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp EnhancementCheckbox("Unrestricted Items", "gNoRestrictItems"); - Tooltip("Allows you to use any item at any location"); + Tooltip("Allows you to use all items at any age"); EnhancementCheckbox("Freeze Time", "gFreezeTime"); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp Tooltip("Freezes the time of day"); EnhancementCheckbox("Drops Don't Despawn", "gDropsDontDie"); Tooltip("Drops from enemies, grass, etc. don't disappear after a set amount of time"); @@ -1201,6 +1355,9 @@ namespace SohImGui { Tooltip("Prevents the Deku Shield from burning on contact with fire"); EnhancementCheckbox("Shield with Two-Handed Weapons", "gShieldTwoHanded"); Tooltip("This allows you to put up your shield with any two-handed weapon in hand\nexcept for Deku Sticks"); +======== + Tooltip("Freezes the time of day"); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp ImGui::EndMenu(); } @@ -1210,6 +1367,7 @@ namespace SohImGui { if (ImGui::BeginMenu("Developer Tools")) { EnhancementCheckbox("OoT Debug Mode", "gDebugEnabled"); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp Tooltip("Enables Debug Mode, allowing you to select maps with L + R + Z, noclip with L + D-pad Right,\nand open the debug menu with L on the pause screen"); EnhancementCheckbox("Fast File Select", "gSkipLogoTitle"); Tooltip("Load the game to the selected slot below upon launch\nUse slot number 4 to load directly into the game's internal Map Select\n(Does not require the Debug Menu, but you will be unable to save there\nYou can also load the Map Select with OoT Debug Mode + slot 0)\nWith slot 0 you can directly go to the File Select menu\nAttention: loading an empty save file will result in a crash"); @@ -1221,6 +1379,14 @@ namespace SohImGui { Tooltip("Shows the stats window, with your FPS and frametimes,\nand the OS you're playing on"); EnhancementCheckbox("Console", "gConsoleEnabled"); Tooltip("Enables the console window, allowing you to input commands,\ntype help for some examples"); +======== + Tooltip("Enables Debug Mode, allowing you to select maps with L + R + Z, noclip with L + D-pad Right,\nand open the debug menu with L on the pause screen"); + ImGui::Separator(); + EnhancementCheckbox("Stats", "gStatsEnabled"); + Tooltip("Shows the stats window, with your FPS and frametimes, and the OS you're playing on"); + EnhancementCheckbox("Console", "gConsoleEnabled"); + Tooltip("Enables the console window, allowing you to input commands, type help for some examples"); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp console->opened = CVar_GetS32("gConsoleEnabled", 0); ImGui::EndMenu(); @@ -1231,10 +1397,14 @@ namespace SohImGui { if (ImGui::BeginMenu(category.first.c_str())) { for (const std::string& name : category.second) { std::string varName(name); +<<<<<<<< HEAD:libultraship/libultraship/ImGuiImpl.cpp varName.erase(std::remove_if(varName.begin(), varName.end(), [](unsigned char x) { return std::isspace(x); }), varName.end()); +======== + varName.erase(std::ranges::remove_if(varName, isspace).begin(), varName.end()); +>>>>>>>> a742feb (Merge branch 'develop' from HarbourMasters into znx (#3)):libultraship/libultraship/SohImGuiImpl.cpp std::string toggleName = "g" + varName + "Enabled"; - EnhancementCheckbox(name.c_str(), toggleName.c_str()); + EnhancementCheckbox(name, toggleName); customWindows[name].enabled = CVar_GetS32(toggleName.c_str(), 0); } ImGui::EndMenu(); @@ -1265,6 +1435,8 @@ namespace SohImGui { ImGui::Text("Platform: Windows"); #elif __APPLE__ ImGui::Text("Platform: macOS"); +#elif defined(__SWITCH__) + ImGui::Text("Platform: Nintendo Switch"); #else ImGui::Text("Platform: Linux"); #endif @@ -1297,19 +1469,19 @@ namespace SohImGui { main_pos.y -= top_left_pos.y; ImVec2 size = ImGui::GetContentRegionAvail(); ImVec2 pos = ImVec2(0, 0); - gfx_current_dimensions.width = (uint32_t)(size.x * gfx_current_dimensions.internal_mul); - gfx_current_dimensions.height = (uint32_t)(size.y * gfx_current_dimensions.internal_mul); - gfx_current_game_window_viewport.x = (int16_t)main_pos.x; - gfx_current_game_window_viewport.y = (int16_t)main_pos.y; - gfx_current_game_window_viewport.width = (int16_t)size.x; - gfx_current_game_window_viewport.height = (int16_t)size.y; + gfx_current_dimensions.width = size.x * gfx_current_dimensions.internal_mul; + gfx_current_dimensions.height = size.y * gfx_current_dimensions.internal_mul; + gfx_current_game_window_viewport.x = main_pos.x; + gfx_current_game_window_viewport.y = main_pos.y; + gfx_current_game_window_viewport.width = size.x; + gfx_current_game_window_viewport.height = size.y; if (CVar_GetS32("gN64Mode", 0)) { gfx_current_dimensions.width = 320; gfx_current_dimensions.height = 240; const int sw = size.y * 320 / 240; - gfx_current_game_window_viewport.x += ((int)size.x - sw) / 2; + gfx_current_game_window_viewport.x += (size.x - sw) / 2; gfx_current_game_window_viewport.width = sw; pos = ImVec2(size.x / 2 - sw / 2, 0); size = ImVec2(sw, size.y); @@ -1318,12 +1490,12 @@ namespace SohImGui { overlay->Draw(); } - void DrawFramebufferAndGameInput(void) { - const ImVec2 main_pos = ImGui::GetWindowPos(); + void DrawFramebufferAndGameInput() { + ImVec2 main_pos = ImGui::GetWindowPos(); ImVec2 size = ImGui::GetContentRegionAvail(); ImVec2 pos = ImVec2(0, 0); if (CVar_GetS32("gN64Mode", 0)) { - const float sw = size.y * 320.0f / 240.0f; + const int sw = size.y * 320 / 240; pos = ImVec2(size.x / 2 - sw / 2, 0); size = ImVec2(sw, size.y); } diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_opengl.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_opengl.cpp index 04a775c5349..1c5e9aa2892 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_opengl.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_opengl.cpp @@ -6,6 +6,7 @@ #include #include +#include #ifndef _LANGUAGE_C #define _LANGUAGE_C @@ -27,6 +28,9 @@ #include "SDL.h" #define GL_GLEXT_PROTOTYPES 1 #include "SDL_opengl.h" +#elif __APPLE__ +#include +#include #elif __SWITCH__ #include #include "glad/glad.h" @@ -41,7 +45,7 @@ #include "gfx_cc.h" #include "gfx_rendering_api.h" -#include "../../SohImGuiImpl.h" +#include "../../ImGuiImpl.h" #include "../../Environment.h" #include "../../GlobalCtx2.h" #include "gfx_pc.h" @@ -72,6 +76,9 @@ struct Framebuffer { static map, struct ShaderProgram> shader_program_pool; static GLuint opengl_vbo; +#ifdef __APPLE__ +static GLuint opengl_vao; +#endif static bool current_depth_mask; static uint32_t frame_count; @@ -79,7 +86,7 @@ static uint32_t frame_count; static vector framebuffers; static size_t current_framebuffer; static float current_noise_scale; -static FilteringMode current_filter_mode = THREE_POINT; +static FilteringMode current_filter_mode = FILTER_THREE_POINT; GLuint pixel_depth_rb, pixel_depth_fb; size_t pixel_depth_rb_size; @@ -225,37 +232,67 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad size_t num_floats = 4; // Vertex shader +#ifdef __APPLE__ + append_line(vs_buf, &vs_len, "#version 410 core"); + append_line(vs_buf, &vs_len, "in vec4 aVtxPos;"); +#else append_line(vs_buf, &vs_len, "#version 110"); append_line(vs_buf, &vs_len, "attribute vec4 aVtxPos;"); +#endif for (int i = 0; i < 2; i++) { if (cc_features.used_textures[i]) { + #ifdef __APPLE__ + vs_len += sprintf(vs_buf + vs_len, "in vec2 aTexCoord%d;\n", i); + vs_len += sprintf(vs_buf + vs_len, "out vec2 vTexCoord%d;\n", i); + #else vs_len += sprintf(vs_buf + vs_len, "attribute vec2 aTexCoord%d;\n", i); vs_len += sprintf(vs_buf + vs_len, "varying vec2 vTexCoord%d;\n", i); + #endif num_floats += 2; for (int j = 0; j < 2; j++) { if (cc_features.clamp[i][j]) { + #ifdef __APPLE__ + vs_len += sprintf(vs_buf + vs_len, "in float aTexClamp%s%d;\n", j == 0 ? "S" : "T", i); + vs_len += sprintf(vs_buf + vs_len, "out float vTexClamp%s%d;\n", j == 0 ? "S" : "T", i); + #else vs_len += sprintf(vs_buf + vs_len, "attribute float aTexClamp%s%d;\n", j == 0 ? "S" : "T", i); vs_len += sprintf(vs_buf + vs_len, "varying float vTexClamp%s%d;\n", j == 0 ? "S" : "T", i); + #endif num_floats += 1; } } } } if (cc_features.opt_fog) { + #ifdef __APPLE__ + append_line(vs_buf, &vs_len, "in vec4 aFog;"); + append_line(vs_buf, &vs_len, "out vec4 vFog;"); + #else append_line(vs_buf, &vs_len, "attribute vec4 aFog;"); append_line(vs_buf, &vs_len, "varying vec4 vFog;"); + #endif num_floats += 4; } if (cc_features.opt_grayscale) { + #ifdef __APPLE__ + append_line(vs_buf, &vs_len, "in vec4 aGrayscaleColor;"); + append_line(vs_buf, &vs_len, "out vec4 vGrayscaleColor;"); + #else append_line(vs_buf, &vs_len, "attribute vec4 aGrayscaleColor;"); append_line(vs_buf, &vs_len, "varying vec4 vGrayscaleColor;"); + #endif num_floats += 4; } for (int i = 0; i < cc_features.num_inputs; i++) { + #ifdef __APPLE__ + vs_len += sprintf(vs_buf + vs_len, "in vec%d aInput%d;\n", cc_features.opt_alpha ? 4 : 3, i + 1); + vs_len += sprintf(vs_buf + vs_len, "out vec%d vInput%d;\n", cc_features.opt_alpha ? 4 : 3, i + 1); + #else vs_len += sprintf(vs_buf + vs_len, "attribute vec%d aInput%d;\n", cc_features.opt_alpha ? 4 : 3, i + 1); vs_len += sprintf(vs_buf + vs_len, "varying vec%d vInput%d;\n", cc_features.opt_alpha ? 4 : 3, i + 1); + #endif num_floats += cc_features.opt_alpha ? 4 : 3; } append_line(vs_buf, &vs_len, "void main() {"); @@ -282,26 +319,50 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad append_line(vs_buf, &vs_len, "}"); // Fragment shader +#ifdef __APPLE__ + append_line(fs_buf, &fs_len, "#version 410 core"); +#else append_line(fs_buf, &fs_len, "#version 130"); +#endif //append_line(fs_buf, &fs_len, "precision mediump float;"); for (int i = 0; i < 2; i++) { if (cc_features.used_textures[i]) { + #ifdef __APPLE__ + fs_len += sprintf(fs_buf + fs_len, "in vec2 vTexCoord%d;\n", i); + #else fs_len += sprintf(fs_buf + fs_len, "varying vec2 vTexCoord%d;\n", i); + #endif for (int j = 0; j < 2; j++) { if (cc_features.clamp[i][j]) { + #ifdef __APPLE__ + fs_len += sprintf(fs_buf + fs_len, "in float vTexClamp%s%d;\n", j == 0 ? "S" : "T", i); + #else fs_len += sprintf(fs_buf + fs_len, "varying float vTexClamp%s%d;\n", j == 0 ? "S" : "T", i); + #endif } } } } if (cc_features.opt_fog) { + #ifdef __APPLE__ + append_line(fs_buf, &fs_len, "in vec4 vFog;"); + #else append_line(fs_buf, &fs_len, "varying vec4 vFog;"); + #endif } if (cc_features.opt_grayscale) { + #ifdef __APPLE__ + append_line(fs_buf, &fs_len, "in vec4 vGrayscaleColor;"); + #else append_line(fs_buf, &fs_len, "varying vec4 vGrayscaleColor;"); + #endif } for (int i = 0; i < cc_features.num_inputs; i++) { + #ifdef __APPLE__ + fs_len += sprintf(fs_buf + fs_len, "in vec%d vInput%d;\n", cc_features.opt_alpha ? 4 : 3, i + 1); + #else fs_len += sprintf(fs_buf + fs_len, "varying vec%d vInput%d;\n", cc_features.opt_alpha ? 4 : 3, i + 1); + #endif } if (cc_features.used_textures[0]) { append_line(fs_buf, &fs_len, "uniform sampler2D uTex0;"); @@ -320,8 +381,12 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad append_line(fs_buf, &fs_len, "}"); } - if (current_filter_mode == THREE_POINT) { + if (current_filter_mode == FILTER_THREE_POINT) { + #if __APPLE__ + append_line(fs_buf, &fs_len, "#define TEX_OFFSET(off) texture(tex, texCoord - (off)/texSize)"); + #else append_line(fs_buf, &fs_len, "#define TEX_OFFSET(off) texture2D(tex, texCoord - (off)/texSize)"); + #endif append_line(fs_buf, &fs_len, "vec4 filter3point(in sampler2D tex, in vec2 texCoord, in vec2 texSize) {"); append_line(fs_buf, &fs_len, " vec2 offset = fract(texCoord*texSize - vec2(0.5));"); append_line(fs_buf, &fs_len, " offset -= step(1.0, offset.x + offset.y);"); @@ -335,10 +400,18 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad append_line(fs_buf, &fs_len, "}"); } else { append_line(fs_buf, &fs_len, "vec4 hookTexture2D(in sampler2D tex, in vec2 uv, in vec2 texSize) {"); + #if __APPLE__ + append_line(fs_buf, &fs_len, " return texture(tex, uv);"); + #else append_line(fs_buf, &fs_len, " return texture2D(tex, uv);"); + #endif append_line(fs_buf, &fs_len, "}"); } +#if __APPLE__ + append_line(fs_buf, &fs_len, "out vec4 outColor;"); +#endif + append_line(fs_buf, &fs_len, "void main() {"); for (int i = 0; i < 2; i++) { @@ -410,9 +483,17 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad if (cc_features.opt_invisible) { append_line(fs_buf, &fs_len, "texel.a = 0.0;"); } + #if __APPLE__ + append_line(fs_buf, &fs_len, "outColor = texel;"); + #else append_line(fs_buf, &fs_len, "gl_FragColor = texel;"); + #endif } else { + #if __APPLE__ + append_line(fs_buf, &fs_len, "outColor = vec4(texel, 1.0);"); + #else append_line(fs_buf, &fs_len, "gl_FragColor = vec4(texel, 1.0);"); + #endif } append_line(fs_buf, &fs_len, "}"); @@ -586,7 +667,7 @@ static uint32_t gfx_cm_to_opengl(uint32_t val) { } static void gfx_opengl_set_sampler_parameters(int tile, bool linear_filter, uint32_t cms, uint32_t cmt) { - const GLint filter = linear_filter && current_filter_mode == LINEAR ? GL_LINEAR : GL_NEAREST; + const GLint filter = linear_filter && current_filter_mode == FILTER_LINEAR ? GL_LINEAR : GL_NEAREST; glActiveTexture(GL_TEXTURE0 + tile); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); @@ -645,6 +726,11 @@ static void gfx_opengl_init(void) { glGenBuffers(1, &opengl_vbo); glBindBuffer(GL_ARRAY_BUFFER, opengl_vbo); +#ifdef __APPLE__ + glGenVertexArrays(1, &opengl_vao); + glBindVertexArray(opengl_vao); +#endif + glEnable(GL_DEPTH_CLAMP); glDepthFunc(GL_LEQUAL); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -797,8 +883,8 @@ void gfx_opengl_select_texture_fb(int fb_id) { glBindTexture(GL_TEXTURE_2D, framebuffers[fb_id].clrbuf); } -static std::map, uint16_t> gfx_opengl_get_pixel_depth(int fb_id, const std::set>& coordinates) { - std::map, uint16_t> res; +static std::unordered_map, uint16_t, hash_pair_ff> gfx_opengl_get_pixel_depth(int fb_id, const std::set>& coordinates) { + std::unordered_map, uint16_t, hash_pair_ff> res; Framebuffer& fb = framebuffers[fb_id]; diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_pc.h b/libultraship/libultraship/Lib/Fast3D/gfx_pc.h index 9085cbdf7c9..4e620ef2d3b 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_pc.h +++ b/libultraship/libultraship/Lib/Fast3D/gfx_pc.h @@ -2,12 +2,17 @@ #define GFX_PC_H #include +#include #include #include #include -#include "U64/PR/ultra64/types.h" #include +#include "U64/PR/ultra64/types.h" + +// TODO figure out why changing these to 640x480 makes the game only render in a quarter of the window +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 struct GfxRenderingAPI; struct GfxWindowManagerAPI; @@ -18,7 +23,7 @@ struct XYWidthHeight { }; struct GfxDimensions { - uint32_t internal_mul; + float internal_mul; uint32_t width, height; float aspect_ratio; }; @@ -47,12 +52,11 @@ struct TextureCacheValue { uint8_t cms, cmt; bool linear_filter; - // Old versions of libstdc++ fail to compile this -#ifdef _MSC_VER - std::list::iterator lru_location; -#else - std::list::iterator lru_location; -#endif + std::list::iterator lru_location; +}; + +struct TextureCacheMapIter { + TextureCacheMap::iterator it; }; extern "C" { @@ -64,12 +68,14 @@ extern uint32_t gfx_msaa_level; } -void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAPI* rapi, const char* game_name, bool start_in_fullscreen); +void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAPI* rapi, const char* game_name, bool start_in_fullscreen, uint32_t width = SCREEN_WIDTH, uint32_t height = SCREEN_HEIGHT); struct GfxRenderingAPI* gfx_get_current_rendering_api(void); void gfx_start_frame(void); void gfx_run(Gfx* commands, const std::unordered_map& mtx_replacements); void gfx_end_frame(void); -void gfx_set_framedivisor(int); +void gfx_set_target_fps(int); +void gfx_set_maximum_frame_latency(int latency); +float gfx_get_detected_hz(void); void gfx_texture_cache_clear(); extern "C" int gfx_create_framebuffer(uint32_t width, uint32_t height); void gfx_get_pixel_depth_prepare(float x, float y); diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp index f9e0b292cec..74cdcf85f85 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp @@ -13,24 +13,30 @@ #include "SDL.h" #define GL_GLEXT_PROTOTYPES 1 #include "SDL_opengl.h" -#elif !defined(__SWITCH__) -#include -#define GL_GLEXT_PROTOTYPES 1 -#include -#else +#elif __APPLE__ +#include +#elif __SWITCH__ #include #include #include "glad/glad.h" +#else +#include +#define GL_GLEXT_PROTOTYPES 1 +#include #endif -#include "../../SohImGuiImpl.h" +#include "../../ImGuiImpl.h" #include "../../SwitchImpl.h" +#include "../../Cvar.h" +#include "../../Hooks.h" + #include "gfx_window_manager_api.h" #include "gfx_screen_config.h" #ifdef _WIN32 #include #endif #include +#include "../../GameSettings.h" #define GFX_API_NAME "SDL2 - OpenGL" @@ -38,8 +44,8 @@ static SDL_Window *wnd; static SDL_GLContext ctx; static int inverted_scancode_table[512]; static int vsync_enabled = 0; -static unsigned int window_width = DESIRED_SCREEN_WIDTH; -static unsigned int window_height = DESIRED_SCREEN_HEIGHT; +static int window_width = DESIRED_SCREEN_WIDTH; +static int window_height = DESIRED_SCREEN_HEIGHT; static bool fullscreen_state; static bool is_running = true; static void (*on_fullscreen_changed_callback)(bool is_now_fullscreen); @@ -128,18 +134,26 @@ static uint64_t previous_time; static HANDLE timer; #endif -static int frameDivisor = 1; +static int target_fps = 60; -#define FRAME_INTERVAL_US_NUMERATOR_ 50000 -#define FRAME_INTERVAL_US_DENOMINATOR 3 -#define FRAME_INTERVAL_US_NUMERATOR (FRAME_INTERVAL_US_NUMERATOR_ * frameDivisor) +#define FRAME_INTERVAL_US_NUMERATOR 1000000 +#define FRAME_INTERVAL_US_DENOMINATOR (target_fps) -static void gfx_sdl_init(const char *game_name, bool start_in_fullscreen) { +static void gfx_sdl_init(const char *game_name, bool start_in_fullscreen, uint32_t width, uint32_t height) { 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); +#if defined(__APPLE__) + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); // Always required on Mac + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); +#endif + #ifdef _WIN32 timer = CreateWaitableTimer(nullptr, false, nullptr); #endif @@ -154,8 +168,12 @@ static void gfx_sdl_init(const char *game_name, bool start_in_fullscreen) { char title[512]; int len = sprintf(title, "%s (%s)", game_name, GFX_API_NAME); + window_width = width; + window_height = height; + wnd = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - window_width, window_height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); + window_width, window_height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + SDL_GL_GetDrawableSize(wnd, &window_width, &window_height); #ifndef __SWITCH__ if (start_in_fullscreen) { @@ -240,6 +258,15 @@ static int translate_scancode(int scancode) { } } +static int untranslate_scancode(int translatedScancode) { + for (int i = 0; i < 512; i++) { + if (inverted_scancode_table[i] == translatedScancode) { + return i; + } + } + return 0; +} + static void gfx_sdl_onkeydown(int scancode) { int key = translate_scancode(scancode); if (on_key_down_callback != NULL) { @@ -275,12 +302,18 @@ static void gfx_sdl_handle_events(void) { #endif case SDL_WINDOWEVENT: if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { - window_width = event.window.data1; - window_height = event.window.data2; + SDL_GL_GetDrawableSize(wnd, &window_width, &window_height); } break; + case SDL_DROPFILE: + CVar_SetString("gDroppedFile", event.drop.file); + CVar_SetS32("gNewFileDropped", 1); + Game::SaveSettings(); + break; case SDL_QUIT: - is_running = false; + ModInternal::ExecuteHooks(); + SDL_Quit(); // bandaid fix for linux window closing issue + exit(0); } } } @@ -296,15 +329,16 @@ static uint64_t qpc_to_100ns(uint64_t qpc) { static inline void sync_framerate_with_timer(void) { uint64_t t; - t = SDL_GetPerformanceCounter(); + t = qpc_to_100ns(SDL_GetPerformanceCounter()); - const int64_t next = qpc_to_100ns(previous_time) + 10 * FRAME_INTERVAL_US_NUMERATOR / FRAME_INTERVAL_US_DENOMINATOR; - const int64_t left = next - qpc_to_100ns(t); + const int64_t next = previous_time + 10 * FRAME_INTERVAL_US_NUMERATOR / FRAME_INTERVAL_US_DENOMINATOR; + const int64_t left = next - t; if (left > 0) { #ifndef _WIN32 const timespec spec = { 0, left * 100 }; nanosleep(&spec, nullptr); #else + // The accuracy of this timer seems to usually be within +- 1.0 ms LARGE_INTEGER li; li.QuadPart = -left; SetWaitableTimer(timer, &li, 0, nullptr, nullptr, false); @@ -312,7 +346,13 @@ static inline void sync_framerate_with_timer(void) { #endif } - t = SDL_GetPerformanceCounter(); + t = qpc_to_100ns(SDL_GetPerformanceCounter()); + if (left > 0 && t - next < 10000) { + // In case it takes some time for the application to wake up after sleep, + // or inaccurate timer, + // don't let that slow down the framerate. + t = next; + } previous_time = t; } @@ -329,9 +369,20 @@ static double gfx_sdl_get_time(void) { return 0.0; } -static void gfx_sdl_set_framedivisor(int divisor) -{ - frameDivisor = divisor; +static void gfx_sdl_set_target_fps(int fps) { + target_fps = fps; +} + +static void gfx_sdl_set_maximum_frame_latency(int latency) { + // Not supported by SDL :( +} + +static float gfx_sdl_get_detected_hz(void) { + return 0; +} + +static const char* gfx_sdl_get_key_name(int scancode) { + return SDL_GetScancodeName((SDL_Scancode) untranslate_scancode(scancode)); } struct GfxWindowManagerAPI gfx_sdl = { @@ -347,7 +398,10 @@ struct GfxWindowManagerAPI gfx_sdl = { gfx_sdl_swap_buffers_begin, gfx_sdl_swap_buffers_end, gfx_sdl_get_time, - gfx_sdl_set_framedivisor + gfx_sdl_set_target_fps, + gfx_sdl_set_maximum_frame_latency, + gfx_sdl_get_detected_hz, + gfx_sdl_get_key_name }; #endif diff --git a/libultraship/libultraship/Lib/ImGui/backends/imgui_impl_opengl3.cpp b/libultraship/libultraship/Lib/ImGui/backends/imgui_impl_opengl3.cpp index ac2d7928db8..d55eb7204e9 100644 --- a/libultraship/libultraship/Lib/ImGui/backends/imgui_impl_opengl3.cpp +++ b/libultraship/libultraship/Lib/ImGui/backends/imgui_impl_opengl3.cpp @@ -357,6 +357,7 @@ void ImGui_ImplOpenGL3_NewFrame() static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object) { ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData(); + // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill glEnable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp deleted file mode 100644 index e5edaa91285..00000000000 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ /dev/null @@ -1,987 +0,0 @@ -#include "SohImGuiImpl.h" - -#include -#include -#include -#include -#include -#include - -#include "Archive.h" -#include "Environment.h" -#include "GameSettings.h" -#include "SohConsole.h" -#include "SohHooks.h" -#include "Lib/ImGui/imgui_internal.h" -#include "GlobalCtx2.h" -#include "ResourceMgr.h" -#include "TextureMod.h" -#include "Window.h" -#include "Cvar.h" -#include "GameOverlay.h" -#include "Texture.h" -#include "../Fast3D/gfx_pc.h" -#include "Lib/stb/stb_image.h" -#include "Lib/Fast3D/gfx_rendering_api.h" -#include "Lib/spdlog/include/spdlog/common.h" -#include "Utils/StringHelper.h" -#include "SwitchImpl.h" - -#ifdef ENABLE_OPENGL -#include "Lib/ImGui/backends/imgui_impl_opengl3.h" -#include "Lib/ImGui/backends/imgui_impl_sdl.h" - -#endif - -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) -#include "Lib/ImGui/backends/imgui_impl_dx11.h" -#include "Lib/ImGui/backends/imgui_impl_win32.h" -#include - -IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); - -#endif - -using namespace Ship; -bool oldCursorState = true; - -#define EXPERIMENTAL() \ - ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 50, 50, 255)); \ - ImGui::Text("Experimental"); \ - ImGui::PopStyleColor(); \ - ImGui::Separator(); -#define TOGGLE_BTN ImGuiKey_F1 -#define HOOK(b) if(b) needs_save = true; -OSContPad* pads; - -std::map DefaultAssets; - -namespace SohImGui { - - WindowImpl impl; - ImGuiIO* io; - Console* console = new Console; - GameOverlay* overlay = new GameOverlay; - bool p_open = false; - bool needs_save = false; - std::vector CustomTexts; - int SelectedLanguage = CVar_GetS32("gLanguages", 0); //Default Language to 0=English 1=German 2=French - float kokiri_col[3] = { 0.118f, 0.41f, 0.106f }; - float goron_col[3] = { 0.392f, 0.078f, 0.0f }; - float zora_col[3] = { 0.0f, 0.235f, 0.392f }; - - float navi_idle_i_col[3] = { 0.0f, 0.0f, 0.0f }; - float navi_idle_o_col[3] = { 0.0f, 0.0f, 0.0f }; - - float navi_npc_i_col[3] = { 0.0f, 0.0f, 0.0f }; - float navi_npc_o_col[3] = { 0.0f, 0.0f, 0.0f }; - - float navi_enemy_i_col[3] = { 0.0f, 0.0f, 0.0f }; - float navi_enemy_o_col[3] = { 0.0f, 0.0f, 0.0f }; - - float navi_prop_i_col[3] = { 0.0f, 0.0f, 0.0f }; - float navi_prop_o_col[3] = { 0.0f, 0.0f, 0.0f }; - - const char* filters[3] = { - "Three-Point", - "Linear", - "None" - }; - - std::map> windowCategories; - std::map customWindows; - - void ImGuiWMInit() { - switch (impl.backend) { - case Backend::SDL: - ImGui_ImplSDL2_InitForOpenGL(static_cast(impl.sdl.window), impl.sdl.context); - break; -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) - case Backend::DX11: - ImGui_ImplWin32_Init(impl.dx11.window); - break; -#endif - default: - break; - } - - // OTRTODO: This gameplay specific stuff should not be in libultraship. This needs to be moved to soh and use sTunicColors - kokiri_col[0] = 30 / 255.0f; - kokiri_col[1] = 105 / 255.0f; - kokiri_col[2] = 27 / 255.0f; - - goron_col[0] = 100 / 255.0f; - goron_col[1] = 20 / 255.0f; - goron_col[2] = 0; - - zora_col[0] = 0; - zora_col[1] = 60 / 255.0f; - zora_col[2] = 100 / 255.0f; - - navi_idle_i_col[0] = 0; - navi_idle_i_col[1] = 0; - navi_idle_i_col[2] = 0; - - navi_idle_o_col[0] = 0; - navi_idle_o_col[1] = 0; - navi_idle_o_col[2] = 0; - - navi_npc_i_col[0] = 0; - navi_npc_i_col[1] = 0; - navi_npc_i_col[2] = 0; - - navi_npc_o_col[0] = 0; - navi_npc_o_col[1] = 0; - navi_npc_o_col[2] = 0; - - navi_enemy_i_col[0] = 0; - navi_enemy_i_col[1] = 0; - navi_enemy_i_col[2] = 0; - - navi_enemy_o_col[0] = 0; - navi_enemy_o_col[1] = 0; - navi_enemy_o_col[2] = 0; - - navi_prop_i_col[0] = 0; - navi_prop_i_col[1] = 0; - navi_prop_i_col[2] = 0; - - navi_prop_o_col[0] = 0; - navi_prop_o_col[1] = 0; - navi_prop_o_col[2] = 0; - } - - void ImGuiBackendInit() { - switch (impl.backend) { - case Backend::SDL: - ImGui_ImplOpenGL3_Init("#version 120"); - break; - -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) - case Backend::DX11: - ImGui_ImplDX11_Init(static_cast(impl.dx11.device), static_cast(impl.dx11.device_context)); - break; -#endif - default: - break; - } - } - - void ImGuiProcessEvent(EventImpl event) { - switch (impl.backend) { - case Backend::SDL: - ImGui_ImplSDL2_ProcessEvent(static_cast(event.sdl.event)); - break; -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) - case Backend::DX11: - ImGui_ImplWin32_WndProcHandler(static_cast(event.win32.handle), event.win32.msg, event.win32.wparam, event.win32.lparam); - break; -#endif - default: - break; - } - } - - void ImGuiWMNewFrame() { - switch (impl.backend) { - case Backend::SDL: - ImGui_ImplSDL2_NewFrame(static_cast(impl.sdl.window)); - break; -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) - case Backend::DX11: - ImGui_ImplWin32_NewFrame(); - break; -#endif - default: - break; - } - } - - void ImGuiBackendNewFrame() { - switch (impl.backend) { - case Backend::SDL: - ImGui_ImplOpenGL3_NewFrame(); - break; -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) - case Backend::DX11: - ImGui_ImplDX11_NewFrame(); - break; -#endif - default: - break; - } - } - - void ImGuiRenderDrawData(ImDrawData* data) { - switch (impl.backend) { - case Backend::SDL: - ImGui_ImplOpenGL3_RenderDrawData(data); - break; -#if defined(ENABLE_DX11) || defined(ENABLE_DX12) - case Backend::DX11: - ImGui_ImplDX11_RenderDrawData(data); - break; -#endif - default: - break; - } - } - - bool UseViewports() { - switch (impl.backend) { - case Backend::DX11: - return true; - default: - return false; - } - } - - void ShowCursor(bool hide, Dialogues d) { - if (d == Dialogues::dLoadSettings) { - GlobalCtx2::GetInstance()->GetWindow()->ShowCursor(hide); - return; - } - - if (d == Dialogues::dConsole && CVar_GetS32("gOpenMenuBar", 0)) { - return; - } - if (!GlobalCtx2::GetInstance()->GetWindow()->IsFullscreen()) { - oldCursorState = false; - return; - } - - if (oldCursorState != hide) { - oldCursorState = hide; - GlobalCtx2::GetInstance()->GetWindow()->ShowCursor(hide); - } - } - - void LoadTexture(const std::string& name, const std::string& path) { - GfxRenderingAPI* api = gfx_get_current_rendering_api(); - const auto res = GlobalCtx2::GetInstance()->GetResourceManager()->LoadFile(path); - - const auto asset = new GameAsset{ api->new_texture() }; - uint8_t* img_data = stbi_load_from_memory(reinterpret_cast(res->buffer.get()), res->dwBufferSize, &asset->width, &asset->height, nullptr, 4); - - if (img_data == nullptr) { - std::cout << "Found error: " << stbi_failure_reason() << std::endl; - return; - } - - api->select_texture(0, asset->textureId); - api->set_sampler_parameters(0, false, 0, 0); - api->upload_texture(img_data, asset->width, asset->height); - - DefaultAssets[name] = asset; - stbi_image_free(img_data); - } - - void LoadResource(const std::string& name, const std::string& path, const ImVec4& tint) { - GfxRenderingAPI* api = gfx_get_current_rendering_api(); - const auto res = static_cast(GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(path).get()); - - std::vector texBuffer; - texBuffer.reserve(res->width * res->height * 4); - - switch (res->texType) { - case Ship::TextureType::RGBA32bpp: - texBuffer.assign(res->imageData, res->imageData + (res->width * res->height * 4)); - break; - case Ship::TextureType::GrayscaleAlpha8bpp: - for (int32_t i = 0; i < res->width * res->height; i++) { - uint8_t ia = res->imageData[i]; - uint8_t color = ((ia >> 4) & 0xF) * 255 / 15; - uint8_t alpha = (ia & 0xF) * 255 / 15; - texBuffer.push_back(color); - texBuffer.push_back(color); - texBuffer.push_back(color); - texBuffer.push_back(alpha); - } - break; - default: - // TODO convert other image types - SPDLOG_WARN("SohImGui::LoadResource: Attempting to load unsupporting image type %s", path.c_str()); - return; - } - - for (size_t pixel = 0; pixel < texBuffer.size() / 4; pixel++) { - texBuffer[pixel * 4 + 0] *= tint.x; - texBuffer[pixel * 4 + 1] *= tint.y; - texBuffer[pixel * 4 + 2] *= tint.z; - texBuffer[pixel * 4 + 3] *= tint.w; - } - - const auto asset = new GameAsset{ api->new_texture() }; - - api->select_texture(0, asset->textureId); - api->set_sampler_parameters(0, false, 0, 0); - api->upload_texture(texBuffer.data(), res->width, res->height); - - DefaultAssets[name] = asset; - } - - void Init(WindowImpl window_impl) { - Game::LoadSettings(); - impl = window_impl; - ImGuiContext* ctx = ImGui::CreateContext(); - ImGui::SetCurrentContext(ctx); - io = &ImGui::GetIO(); - io->ConfigFlags |= ImGuiConfigFlags_DockingEnable; - io->Fonts->AddFontDefault(); - - if (UseViewports()) { - io->ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; - } - console->Init(); - overlay->Init(); - ImGuiWMInit(); - ImGuiBackendInit(); - #ifdef __SWITCH__ - ImGui::GetStyle().ScaleAllSizes(Ship::Switch::GetDPI() / 96.0f); - #endif - - ModInternal::registerHookListener({ GFX_INIT, [](const HookEvent ev) { - - if (GlobalCtx2::GetInstance()->GetWindow()->IsFullscreen()) - ShowCursor(CVar_GetS32("gOpenMenuBar", 0), Dialogues::dLoadSettings); - - LoadTexture("Game_Icon", "assets/ship_of_harkinian/icons/gSohIcon.png"); - LoadTexture("A-Btn", "assets/ship_of_harkinian/buttons/ABtn.png"); - LoadTexture("B-Btn", "assets/ship_of_harkinian/buttons/BBtn.png"); - LoadTexture("L-Btn", "assets/ship_of_harkinian/buttons/LBtn.png"); - LoadTexture("R-Btn", "assets/ship_of_harkinian/buttons/RBtn.png"); - LoadTexture("Z-Btn", "assets/ship_of_harkinian/buttons/ZBtn.png"); - LoadTexture("Start-Btn", "assets/ship_of_harkinian/buttons/StartBtn.png"); - LoadTexture("C-Left", "assets/ship_of_harkinian/buttons/CLeft.png"); - LoadTexture("C-Right", "assets/ship_of_harkinian/buttons/CRight.png"); - LoadTexture("C-Up", "assets/ship_of_harkinian/buttons/CUp.png"); - LoadTexture("C-Down", "assets/ship_of_harkinian/buttons/CDown.png"); - } }); - - for (const auto& [i, controllers] : Ship::Window::Controllers) - { - CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftX", i).c_str(), 0); - CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftY", i).c_str(), 0); - needs_save = true; - } - - ModInternal::registerHookListener({ CONTROLLER_READ, [](const HookEvent ev) { - pads = static_cast(ev->baseArgs["cont_pad"]); - }}); - Game::InitSettings(); - } - - void Update(EventImpl event) { - #ifdef __SWITCH__ - int xPos, yPos; - Switch::GetTouchPosition(&xPos, &yPos); - io->MousePos = ImVec2(xPos, yPos); - #endif - if (needs_save) { - Game::SaveSettings(); - needs_save = false; - } - ImGuiProcessEvent(event); - } - -#define BindButton(btn, status) ImGui::Image(GetTextureByID(DefaultAssets[btn]->textureId), ImVec2(16.0f * scale, 16.0f * scale), ImVec2(0, 0), ImVec2(1.0f, 1.0f), ImVec4(255, 255, 255, (status) ? 255 : 0)); - - void BindAudioSlider(const char* name, const char* key, float defaultValue, SeqPlayers playerId) - { - float value = CVar_GetFloat(key, defaultValue); - - ImGui::Text(name, static_cast(100 * value)); - if (ImGui::SliderFloat((std::string("##") + key).c_str(), &value, 0.0f, 1.0f, "")) { - const float volume = floorf(value * 100) / 100; - CVar_SetFloat(key, volume); - needs_save = true; - Game::SetSeqPlayerVolume(playerId, volume); - } - } - - void EnhancementRadioButton(std::string text, std::string cvarName, int id) { - /*Usage : - EnhancementRadioButton("My Visible Name","gMyCVarName", MyID); - First arg is the visible name of the Radio button - Second is the cvar name where MyID will be saved. - Note: the CVar name should be the same to each Buddies. - Example : - EnhancementRadioButton("English", "gLanguages", 0); - EnhancementRadioButton("German", "gLanguages", 1); - EnhancementRadioButton("French", "gLanguages", 2); - */ - int val = CVar_GetS32(cvarName.c_str(), 0); - if (ImGui::RadioButton(text.c_str(), id==val)) { - CVar_SetS32(cvarName.c_str(), (int)id); - needs_save = true; - } - } - - void EnhancementCheckbox(std::string text, std::string cvarName) - { - bool val = (bool)CVar_GetS32(cvarName.c_str(), 0); - if (ImGui::Checkbox(text.c_str(), &val)) { - CVar_SetS32(cvarName.c_str(), val); - needs_save = true; - } - } - - void EnhancementButton(std::string text, std::string cvarName) - { - bool val = (bool)CVar_GetS32(cvarName.c_str(), 0); - if (ImGui::Button(text.c_str())) { - CVar_SetS32(cvarName.c_str(), !val); - needs_save = true; - } - } - - void EnhancementSliderInt(std::string text, std::string id, std::string cvarName, int min, int max, std::string format) - { - int val = CVar_GetS32(cvarName.c_str(), 0); - - ImGui::Text(text.c_str(), val); - - if (ImGui::SliderInt(id.c_str(), &val, min, max, format.c_str())) - { - CVar_SetS32(cvarName.c_str(), val); - needs_save = true; - } - - if (val < min) - { - val = min; - CVar_SetS32(cvarName.c_str(), val); - needs_save = true; - } - - if (val > max) - { - val = max; - CVar_SetS32(cvarName.c_str(), val); - needs_save = true; - } - } - - void EnhancementSliderFloat(std::string text, std::string id, std::string cvarName, float min, float max, std::string format, float defaultValue, bool isPercentage) - { - float val = CVar_GetFloat(cvarName.c_str(), defaultValue); - - if (!isPercentage) - ImGui::Text(text.c_str(), val); - else - ImGui::Text(text.c_str(), static_cast(100 * val)); - - if (ImGui::SliderFloat(id.c_str(), &val, min, max, format.c_str())) - { - CVar_SetFloat(cvarName.c_str(), val); - needs_save = true; - } - - if (val < min) - { - val = min; - CVar_SetFloat(cvarName.c_str(), val); - needs_save = true; - } - - if (val > max) - { - val = max; - CVar_SetFloat(cvarName.c_str(), val); - needs_save = true; - } - } - - void EnhancementColor3(std::string text, std::string cvarName, float defaultColors[3]) - { - int r = CVar_GetS32((cvarName + "_Red").c_str(), (defaultColors[0] * 255.0f)); - int g = CVar_GetS32((cvarName + "_Green").c_str(), (defaultColors[1] * 255.0f)); - int b = CVar_GetS32((cvarName + "_Blue").c_str(), (defaultColors[2] * 255.0f)); - - float colors[3]; - colors[0] = r / 255.0f; - colors[1] = g / 255.0f; - colors[2] = b / 255.0f; - - { - if (ImGui::ColorEdit3(text.c_str(), colors)) - { - CVar_SetS32((cvarName + "_Red").c_str(), (int)(colors[0] * 255)); - CVar_SetS32((cvarName + "_Green").c_str(), (int)(colors[1] * 255)); - CVar_SetS32((cvarName + "_Blue").c_str(), (int)(colors[2] * 255)); - needs_save = true; - } - } - } - - void Tooltip(std::string text){ - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("%s", text.c_str()); - } - - void DrawMainMenuAndCalculateGameSize() { - console->Update(); - ImGuiBackendNewFrame(); - ImGuiWMNewFrame(); - ImGui::NewFrame(); - - const std::shared_ptr wnd = GlobalCtx2::GetInstance()->GetWindow(); - ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoBackground | - ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | - ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoResize; - if (CVar_GetS32("gOpenMenuBar", 0)) window_flags |= ImGuiWindowFlags_MenuBar; - - const ImGuiViewport* viewport = ImGui::GetMainViewport(); - ImGui::SetNextWindowPos(viewport->WorkPos); - ImGui::SetNextWindowSize(ImVec2((int) wnd->GetCurrentWidth(), (int) wnd->GetCurrentHeight())); - ImGui::SetNextWindowViewport(viewport->ID); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f); - ImGui::Begin("Main - Deck", nullptr, window_flags); - ImGui::PopStyleVar(3); - - ImVec2 top_left_pos = ImGui::GetWindowPos(); - - const ImGuiID dockId = ImGui::GetID("main_dock"); - - if (!ImGui::DockBuilderGetNode(dockId)) { - ImGui::DockBuilderRemoveNode(dockId); - ImGui::DockBuilderAddNode(dockId, ImGuiDockNodeFlags_NoTabBar); - - ImGui::DockBuilderDockWindow("OoT Master Quest", dockId); - - ImGui::DockBuilderFinish(dockId); - } - - ImGui::DockSpace(dockId, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_None); - - if (ImGui::IsKeyPressed(TOGGLE_BTN)) { - bool menu_bar = CVar_GetS32("gOpenMenuBar", 0); - CVar_SetS32("gOpenMenuBar", !menu_bar); - needs_save = true; - GlobalCtx2::GetInstance()->GetWindow()->dwMenubar = menu_bar; - ShowCursor(menu_bar, Dialogues::dMenubar); - } - - if (ImGui::BeginMenuBar()) { - if (DefaultAssets.contains("Game_Icon")) { - ImGui::SetCursorPos(ImVec2(5, 2.5f)); - ImGui::Image(GetTextureByID(DefaultAssets["Game_Icon"]->textureId), ImVec2(16.0f, 16.0f)); - ImGui::SameLine(); - ImGui::SetCursorPos(ImVec2(25, 0)); - } - ImGui::Text("Shipwright"); - ImGui::Separator(); - - if (ImGui::BeginMenu("Audio")) { - EnhancementSliderFloat("Master Volume: %d %%", "##Master_Vol", "gGameMasterVolume", 0.0f, 1.0f, "", 1.0f, true); - - BindAudioSlider("Main Music Volume: %d %%", "gMainMusicVolume", 1.0f, SEQ_BGM_MAIN); - BindAudioSlider("Sub Music Volume: %d %%", "gSubMusicVolume", 1.0f, SEQ_BGM_SUB); - BindAudioSlider("Sound Effects Volume: %d %%", "gSFXMusicVolume", 1.0f, SEQ_SFX); - BindAudioSlider("Fanfare Volume: %d %%", "gFanfareVolume", 1.0f, SEQ_FANFARE); - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Controller")) - { - for (const auto& [i, controllers] : Ship::Window::Controllers) - { - bool hasPad = std::find_if(controllers.begin(), controllers.end(), [](const auto& c) { - return c->HasPadConf() && c->Connected(); - }) != controllers.end(); - - if (!hasPad) continue; - - auto menuLabel = "Controller " + std::to_string(i + 1); - if (ImGui::BeginMenu(menuLabel.c_str())) - { - EnhancementSliderFloat("Gyro Sensitivity: %d %%", "##GYROSCOPE", StringHelper::Sprintf("gCont%i_GyroSensitivity", i), 0.0f, 1.0f, "", 1.0f, true); - - if (ImGui::Button("Recalibrate Gyro")) - { - CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftX", i).c_str(), 0); - CVar_SetFloat(StringHelper::Sprintf("gCont%i_GyroDriftY", i).c_str(), 0); - needs_save = true; - } - - ImGui::Separator(); - - EnhancementSliderFloat("Rumble Strength: %d %%", "##RUMBLE", StringHelper::Sprintf("gCont%i_RumbleStrength", i), 0.0f, 1.0f, "", 1.0f, true); - - ImGui::EndMenu(); - } - ImGui::Separator(); - } - - EnhancementCheckbox("Show Inputs", "gInputEnabled"); - Tooltip("Shows currently pressed inputs on the bottom right of the screen"); - EnhancementCheckbox("Rumble Enabled", "gRumbleEnabled"); - - EnhancementSliderFloat("Input Scale: %.1f", "##Input", "gInputScale", 1.0f, 3.0f, "", 1.0f, false); - Tooltip("Sets the on screen size of the displayed inputs from Show Inputs"); - - ImGui::Separator(); - - EnhancementCheckbox("D-pad Support on Pause and File Select", "gDpadPauseName"); - EnhancementCheckbox("D-pad Support in Ocarina and Text Choice", "gDpadOcarinaText"); - EnhancementCheckbox("D-pad Support for Browsing Shop Items", "gDpadShop"); - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Graphics")) - { - EnhancementSliderInt("Internal Resolution: %dx", "##IMul", "gInternalResolution", 1, 8, ""); - Tooltip("Increases the render resolution of the game, up to 8x your output resolution,\nas a more intensive but effective form of anti-aliasing"); - gfx_current_dimensions.internal_mul = CVar_GetS32("gInternalResolution", 1); - EnhancementSliderInt("MSAA: %d", "##IMSAA", "gMSAAValue", 1, 8, ""); - Tooltip("Activates anti-aliasing when above 1, up to 8x for 8 samples for every pixel"); - gfx_msaa_level = CVar_GetS32("gMSAAValue", 1); - - EXPERIMENTAL(); - ImGui::Text("Texture Filter (Needs reload)"); - GfxRenderingAPI* gapi = gfx_get_current_rendering_api(); - if (ImGui::BeginCombo("##filters", filters[gapi->get_texture_filter()])) { - for (int fId = 0; fId <= FilteringMode::NONE; fId++) { - if (ImGui::Selectable(filters[fId], fId == gapi->get_texture_filter())) { - INFO("New Filter: %s", filters[fId]); - gapi->set_texture_filter((FilteringMode)fId); - - CVar_SetS32("gTextureFilter", (int) fId); - needs_save = true; - } - - } - ImGui::EndCombo(); - } - overlay->DrawSettings(); - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Languages")) { - EnhancementRadioButton("English", "gLanguages", 0); - EnhancementRadioButton("German", "gLanguages", 1); - EnhancementRadioButton("French", "gLanguages", 2); - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Enhancements")) - { - ImGui::Text("Gameplay"); - ImGui::Separator(); - - EnhancementSliderInt("Text Speed: %dx", "##TEXTSPEED", "gTextSpeed", 1, 5, ""); - EnhancementSliderInt("King Zora Speed: %dx", "##WEEPSPEED", "gMweepSpeed", 1, 5, ""); - - EnhancementCheckbox("Skip Text", "gSkipText"); - Tooltip("Holding down B skips text"); - EnhancementCheckbox("Minimal UI", "gMinimalUI"); - Tooltip("Hides most of the UI when not needed"); - EnhancementCheckbox("MM Bunny Hood", "gMMBunnyHood"); - Tooltip("Wearing the Bunny Hood grants a speed increase like in Majora's Mask"); - EnhancementCheckbox("Visual Stone of Agony", "gVisualAgony"); - Tooltip("Displays an icon and plays a sound when Stone of Agony should be activated, for those without rumble"); - - ImGui::Text("Graphics"); - ImGui::Separator(); - - EnhancementCheckbox("N64 Mode", "gN64Mode"); - Tooltip("Sets aspect ratio to 4:3 and lowers resolution to 240p, the N64's native resolution"); - - EnhancementCheckbox("Animated Link in Pause Menu", "gPauseLiveLink"); - EnhancementCheckbox("Enable 3D Dropped items", "gNewDrops"); - EnhancementCheckbox("Faster Block Push", "gFasterBlockPush"); - EnhancementCheckbox("Dynamic Wallet Icon", "gDynamicWalletIcon"); - Tooltip("Changes the rupee in the wallet icon to match the wallet size you currently have"); - EnhancementCheckbox("Always show dungeon entrances", "gAlwaysShowDungeonMinimapIcon"); - Tooltip("Always shows dungeon entrance icons on the minimap"); - - ImGui::Text("Fixes"); - ImGui::Separator(); - EnhancementCheckbox("Fix L&R Pause menu", "gUniformLR"); - Tooltip("Makes the L and R buttons in the pause menu the same color"); - EnhancementCheckbox("Fix Dungeon entrances", "gFixDungeonMinimapIcon"); - Tooltip("Show dungeon entrances icon only when it should be"); - EnhancementCheckbox("Fix Two Handed idle animations", "gTwoHandedIdle"); - Tooltip("Makes two handed idle animation play, a seemingly finished animation that was disabled on accident in the original game"); - - EXPERIMENTAL(); - - EnhancementCheckbox("60 fps interpolation", "g60FPS"); - EnhancementCheckbox("Disable LOD", "gDisableLOD"); - Tooltip("Turns off the level of detail setting, making models always use their higher poly variants"); - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Cosmetics")) - { - ImGui::Text("Tunics"); - ImGui::Separator(); - - EnhancementColor3("Kokiri Tunic", "gTunic_Kokiri", kokiri_col); - EnhancementColor3("Goron Tunic", "gTunic_Goron", goron_col); - EnhancementColor3("Zora Tunic", "gTunic_Zora", zora_col); - - ImGui::Text("Navi"); - ImGui::Separator(); - - EnhancementColor3("Navi Idle Inner", "gNavi_Idle_Inner", navi_idle_i_col); - EnhancementColor3("Navi Idle Outer", "gNavi_Idle_Outer", navi_idle_o_col); - EnhancementColor3("Navi NPC Inner", "gNavi_NPC_Inner", navi_npc_i_col); - EnhancementColor3("Navi NPC Outer", "gNavi_NPC_Outer", navi_npc_o_col); - EnhancementColor3("Navi Enemy Inner", "gNavi_Enemy_Inner", navi_enemy_i_col); - EnhancementColor3("Navi Enemy Outer", "gNavi_Enemy_Outer", navi_enemy_o_col); - EnhancementColor3("Navi Prop Inner", "gNavi_Prop_Inner", navi_prop_i_col); - EnhancementColor3("Navi Prop Outer", "gNavi_Prop_Outer", navi_prop_o_col); - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Cheats")) - { - if (ImGui::BeginMenu("Infinite...")) { - EnhancementCheckbox("Money", "gInfiniteMoney"); - EnhancementCheckbox("Health", "gInfiniteHealth"); - EnhancementCheckbox("Ammo", "gInfiniteAmmo"); - EnhancementCheckbox("Magic", "gInfiniteMagic"); - EnhancementCheckbox("Nayru's Love", "gInfiniteNayru"); - - ImGui::EndMenu(); - } - - EnhancementCheckbox("No Clip", "gNoClip"); - Tooltip("Allows you to walk through walls"); - EnhancementCheckbox("Climb Everything", "gClimbEverything"); - Tooltip("Makes every surface in the game climbable"); - EnhancementCheckbox("Moon Jump on L", "gMoonJumpOnL"); - Tooltip("Holding L makes you float into the air"); - EnhancementCheckbox("Super Tunic", "gSuperTunic"); - Tooltip("Makes every tunic have the effects of every other tunic"); - EnhancementCheckbox("Easy ISG", "gEzISG"); - Tooltip("Automatically activates the Infinite Sword glitch, making you constantly swing your sword"); - EnhancementCheckbox("Unrestricted Items", "gNoRestrictItems"); - Tooltip("Allows you to use all items at any age"); - EnhancementCheckbox("Freeze Time", "gFreezeTime"); - Tooltip("Freezes the time of day"); - - ImGui::EndMenu(); - } - - if (ImGui::BeginMenu("Developer Tools")) - { - EnhancementCheckbox("OoT Debug Mode", "gDebugEnabled"); - Tooltip("Enables Debug Mode, allowing you to select maps with L + R + Z, noclip with L + D-pad Right,\nand open the debug menu with L on the pause screen"); - ImGui::Separator(); - EnhancementCheckbox("Stats", "gStatsEnabled"); - Tooltip("Shows the stats window, with your FPS and frametimes, and the OS you're playing on"); - EnhancementCheckbox("Console", "gConsoleEnabled"); - Tooltip("Enables the console window, allowing you to input commands, type help for some examples"); - console->opened = CVar_GetS32("gConsoleEnabled", 0); - - ImGui::EndMenu(); - } - - for (const auto& category : windowCategories) { - if (ImGui::BeginMenu(category.first.c_str())) { - for (const std::string& name : category.second) { - std::string varName(name); - varName.erase(std::ranges::remove_if(varName, isspace).begin(), varName.end()); - std::string toggleName = "g" + varName + "Enabled"; - - EnhancementCheckbox(name, toggleName); - customWindows[name].enabled = CVar_GetS32(toggleName.c_str(), 0); - } - ImGui::EndMenu(); - } - - } - - ImGui::EndMenuBar(); - } - - ImGui::End(); - - if (CVar_GetS32("gStatsEnabled", 0)) { - const float framerate = ImGui::GetIO().Framerate; - ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0)); - ImGui::Begin("Debug Stats", nullptr, ImGuiWindowFlags_NoFocusOnAppearing); - -#ifdef _WIN32 - ImGui::Text("Platform: Windows"); -#elif defined(__SWITCH__) - ImGui::Text("Platform: Nintendo Switch"); -#else - ImGui::Text("Platform: Linux"); -#endif - ImGui::Text("Status: %.3f ms/frame (%.1f FPS)", 1000.0f / framerate, framerate); - ImGui::End(); - ImGui::PopStyleColor(); - } - - console->Draw(); - - for (auto& windowIter : customWindows) { - CustomWindow& window = windowIter.second; - if (window.drawFunc != nullptr) { - window.drawFunc(window.enabled); - } - } - - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f); - ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.0f, 0.0f, 0.0f, 0.0f)); - ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground; - ImGui::Begin("OoT Master Quest", nullptr, flags); - ImGui::PopStyleVar(3); - ImGui::PopStyleColor(); - - ImVec2 main_pos = ImGui::GetWindowPos(); - main_pos.x -= top_left_pos.x; - main_pos.y -= top_left_pos.y; - ImVec2 size = ImGui::GetContentRegionAvail(); - ImVec2 pos = ImVec2(0, 0); - gfx_current_dimensions.width = size.x * gfx_current_dimensions.internal_mul; - gfx_current_dimensions.height = size.y * gfx_current_dimensions.internal_mul; - gfx_current_game_window_viewport.x = main_pos.x; - gfx_current_game_window_viewport.y = main_pos.y; - gfx_current_game_window_viewport.width = size.x; - gfx_current_game_window_viewport.height = size.y; - - if (CVar_GetS32("gN64Mode", 0)) - { - gfx_current_dimensions.width = 320; - gfx_current_dimensions.height = 240; - const int sw = size.y * 320 / 240; - gfx_current_game_window_viewport.x += (size.x - sw) / 2; - gfx_current_game_window_viewport.width = sw; - pos = ImVec2(size.x / 2 - sw / 2, 0); - size = ImVec2(sw, size.y); - } - - overlay->Draw(); - } - - void DrawFramebufferAndGameInput() { - ImVec2 main_pos = ImGui::GetWindowPos(); - ImVec2 size = ImGui::GetContentRegionAvail(); - ImVec2 pos = ImVec2(0, 0); - if (CVar_GetS32("gN64Mode", 0)) { - const int sw = size.y * 320 / 240; - pos = ImVec2(size.x / 2 - sw / 2, 0); - size = ImVec2(sw, size.y); - } - std::string fb_str = SohUtils::getEnvironmentVar("framebuffer"); - if (!fb_str.empty()) { - uintptr_t fbuf = (uintptr_t)std::stoull(fb_str); - //ImGui::ImageSimple(reinterpret_cast(fbuf), pos, size); - ImGui::SetCursorPos(pos); - ImGui::Image(reinterpret_cast(fbuf), size); - } - - ImGui::End(); - - const float scale = CVar_GetFloat("gInputScale", 1.0f); - ImVec2 BtnPos = ImVec2(160 * scale, 85 * scale); - - if (CVar_GetS32("gInputEnabled", 0)) { - ImGui::SetNextWindowSize(BtnPos); - ImGui::SetNextWindowPos(ImVec2(main_pos.x + size.x - BtnPos.x - 20, main_pos.y + size.y - BtnPos.y - 20)); - - if (pads != nullptr && ImGui::Begin("Game Buttons", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground)) { - ImGui::SetCursorPosY(32 * scale); - - ImGui::BeginGroup(); - const ImVec2 cPos = ImGui::GetCursorPos(); - ImGui::SetCursorPos(ImVec2(cPos.x + 10 * scale, cPos.y - 20 * scale)); - BindButton("L-Btn", pads[0].button & BTN_L); - ImGui::SetCursorPos(ImVec2(cPos.x + 16 * scale, cPos.y)); - BindButton("C-Up", pads[0].button & BTN_CUP); - ImGui::SetCursorPos(ImVec2(cPos.x, cPos.y + 16 * scale)); - BindButton("C-Left", pads[0].button & BTN_CLEFT); - ImGui::SetCursorPos(ImVec2(cPos.x + 32 * scale, cPos.y + 16 * scale)); - BindButton("C-Right", pads[0].button & BTN_CRIGHT); - ImGui::SetCursorPos(ImVec2(cPos.x + 16 * scale, cPos.y + 32 * scale)); - BindButton("C-Down", pads[0].button & BTN_CDOWN); - ImGui::EndGroup(); - - ImGui::SameLine(); - - ImGui::BeginGroup(); - const ImVec2 sPos = ImGui::GetCursorPos(); - ImGui::SetCursorPos(ImVec2(sPos.x + 21, sPos.y - 20 * scale)); - BindButton("Z-Btn", pads[0].button & BTN_Z); - ImGui::SetCursorPos(ImVec2(sPos.x + 22, sPos.y + 16 * scale)); - BindButton("Start-Btn", pads[0].button & BTN_START); - ImGui::EndGroup(); - - ImGui::SameLine(); - - ImGui::BeginGroup(); - const ImVec2 bPos = ImGui::GetCursorPos(); - ImGui::SetCursorPos(ImVec2(bPos.x + 20 * scale, bPos.y - 20 * scale)); - BindButton("R-Btn", pads[0].button & BTN_R); - ImGui::SetCursorPos(ImVec2(bPos.x + 12 * scale, bPos.y + 8 * scale)); - BindButton("B-Btn", pads[0].button & BTN_B); - ImGui::SetCursorPos(ImVec2(bPos.x + 28 * scale, bPos.y + 24 * scale)); - BindButton("A-Btn", pads[0].button & BTN_A); - ImGui::EndGroup(); - - ImGui::End(); - } - } - } - - void Render() { - ImGui::Render(); - ImGuiRenderDrawData(ImGui::GetDrawData()); - if (UseViewports()) { - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); - } - } - - void CancelFrame() { - ImGui::EndFrame(); - if (UseViewports()) { - ImGui::UpdatePlatformWindows(); - } - } - - void BindCmd(const std::string& cmd, CommandEntry entry) { - console->Commands[cmd] = std::move(entry); - } - - void AddWindow(const std::string& category, const std::string& name, WindowDrawFunc drawFunc) { - if (customWindows.contains(name)) { - SPDLOG_ERROR("SohImGui::AddWindow: Attempting to add duplicate window name %s", name.c_str()); - return; - } - - customWindows[name] = { - .enabled = false, - .drawFunc = drawFunc - }; - - windowCategories[category].emplace_back(name); - } - - ImTextureID GetTextureByName(const std::string& name) { - return GetTextureByID(DefaultAssets[name]->textureId); - } - - ImTextureID GetTextureByID(int id) { -#ifdef ENABLE_DX11 - if (impl.backend == Backend::DX11) - { - ImTextureID gfx_d3d11_get_texture_by_id(int id); - return gfx_d3d11_get_texture_by_id(id); - } -#endif - return reinterpret_cast(id); - } -} diff --git a/libultraship/libultraship/Window.cpp b/libultraship/libultraship/Window.cpp index 3a22973af48..8760ae1942f 100644 --- a/libultraship/libultraship/Window.cpp +++ b/libultraship/libultraship/Window.cpp @@ -18,12 +18,16 @@ #include "Lib/Fast3D/gfx_sdl.h" #include "Lib/Fast3D/gfx_opengl.h" #include "stox.h" +#if __APPLE__ +#include +#else #include +#endif #include #include #include -#include "SohHooks.h" -#include "SohConsole.h" +#include "Hooks.h" +#include "Console.h" #include @@ -34,8 +38,7 @@ extern "C" { uint8_t __enableGameInput = 1; int32_t osContInit(OSMesgQueue* mq, uint8_t* controllerBits, OSContStatus* status) { - std::shared_ptr pConf = Ship::GlobalCtx2::GetInstance()->GetConfig(); - Ship::ConfigFile& Conf = *pConf.get(); + *controllerBits = 0; if (SDL_Init(SDL_INIT_GAMECONTROLLER) != 0) { SPDLOG_ERROR("Failed to initialize SDL game controllers ({})", SDL_GetError()); @@ -51,43 +54,8 @@ extern "C" { SPDLOG_ERROR("Failed add SDL game controller mappings from \"{}\" ({})", controllerDb, SDL_GetError()); } #endif - // TODO: This for loop is debug. Burn it with fire. - for (int i = 0; i < SDL_NumJoysticks(); i++) { - if (SDL_IsGameController(i)) { - // Get the GUID from SDL - char buf[33]; - SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i), buf, sizeof(buf)); - auto guid = std::string(buf); - auto name = std::string(SDL_GameControllerNameForIndex(i)); - - SPDLOG_INFO("Found Controller \"{}\" with ID \"{}\"", name, guid); - } - } - for (int32_t i = 0; i < __osMaxControllers; i++) { - std::string ControllerType = Conf["CONTROLLERS"]["CONTROLLER " + std::to_string(i+1)]; - mINI::INIStringUtil::toLower(ControllerType); - - if (ControllerType == "auto") { - Ship::Window::Controllers[i].push_back(std::make_shared(i)); - Ship::Window::Controllers[i].push_back(std::make_shared(i)); - } else if (ControllerType == "keyboard") { - Ship::Window::Controllers[i].push_back(std::make_shared(i)); - } else if (ControllerType == "usb") { - Ship::Window::Controllers[i].push_back(std::make_shared(i)); - } else if (ControllerType == "unplugged") { - // Do nothing for unplugged controllers - } else { - SPDLOG_ERROR("Invalid Controller Type: {}", ControllerType); - } - } - - *controllerBits = 0; - for (size_t i = 0; i < __osMaxControllers; i++) { - if (Ship::Window::Controllers[i].size() > 0) { - *controllerBits |= 1 << i; - } - } + Ship::Window::ControllerApi->Init(controllerBits); return 0; } @@ -100,64 +68,51 @@ extern "C" { pad->button = 0; pad->stick_x = 0; pad->stick_y = 0; + pad->cam_x = 0; + pad->cam_y = 0; pad->err_no = 0; pad->gyro_x = 0; pad->gyro_y = 0; - if (__enableGameInput) - { - for (size_t i = 0; i < __osMaxControllers; i++) { - for (size_t j = 0; j < Ship::Window::Controllers[i].size(); j++) { - Ship::Window::Controllers[i][j]->Read(&pad[i]); - } - } + if (__enableGameInput) { + Ship::Window::ControllerApi->WriteToPad(pad); } - ModInternal::bindHook(CONTROLLER_READ); - ModInternal::initBindHook(1, - HookParameter({ .name = "cont_pad", .parameter = (void*)pad }) - ); - ModInternal::callBindHook(0); + ModInternal::ExecuteHooks(pad); } - char* ResourceMgr_GetNameByCRC(uint64_t crc, char* alloc) { - std::string hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); - strcpy(alloc, hashStr.c_str()); - return (char*)hashStr.c_str(); + const char* ResourceMgr_GetNameByCRC(uint64_t crc) { + const std::string* hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); + return hashStr != nullptr ? hashStr->c_str() : nullptr; } Vtx* ResourceMgr_LoadVtxByCRC(uint64_t crc) { - std::string hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); - - if (hashStr != "") { - auto res = std::static_pointer_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr)); + const std::string* hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); - //if (res != nullptr) - return (Vtx*)res->vertices.data(); - //else - //return (Vtx*)Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadFile(hashStr)->buffer.get(); - } - else { - return nullptr; + if (hashStr != nullptr) { + auto res = std::static_pointer_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr->c_str())); + return (Vtx*)res->vertices.data(); } + + return nullptr; } int32_t* ResourceMgr_LoadMtxByCRC(uint64_t crc) { - std::string hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); + const std::string* hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); - if (hashStr != "") { - auto res = std::static_pointer_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr)); + if (hashStr != nullptr) { + auto res = std::static_pointer_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr->c_str())); return (int32_t*)res->mtx.data(); - } else { - return nullptr; } + + return nullptr; } Gfx* ResourceMgr_LoadGfxByCRC(uint64_t crc) { - std::string hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); + const std::string* hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); - if (hashStr != "") { - auto res = std::static_pointer_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr)); + if (hashStr != nullptr) { + auto res = std::static_pointer_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr->c_str())); return (Gfx*)&res->instructions[0]; } else { return nullptr; @@ -165,17 +120,12 @@ extern "C" { } char* ResourceMgr_LoadTexByCRC(uint64_t crc) { - const std::string hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); + const std::string* hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(crc); - if (!hashStr.empty()) { - const auto res = static_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr).get()); + if (hashStr != nullptr) { + const auto res = static_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr->c_str()).get()); - ModInternal::bindHook(LOAD_TEXTURE); - ModInternal::initBindHook(2, - HookParameter({.name = "path", .parameter = (void*)hashStr.c_str() }), - HookParameter({.name = "texture", .parameter = static_cast(&res->imageData) }) - ); - ModInternal::callBindHook(0); + ModInternal::ExecuteHooks(hashStr->c_str(), &res->imageData); return reinterpret_cast(res->imageData); } else { @@ -185,11 +135,11 @@ extern "C" { void ResourceMgr_RegisterResourcePatch(uint64_t hash, uint32_t instrIndex, uintptr_t origData) { - std::string hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(hash); + const std::string* hashStr = Ship::GlobalCtx2::GetInstance()->GetResourceManager()->HashToString(hash); - if (hashStr != "") + if (hashStr != nullptr) { - auto res = (Ship::Texture*)Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr).get(); + auto res = (Ship::Texture*)Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(hashStr->c_str()).get(); Ship::Patch patch; patch.crc = hash; @@ -202,12 +152,7 @@ extern "C" { char* ResourceMgr_LoadTexByName(char* texPath) { const auto res = static_cast(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(texPath).get()); - ModInternal::bindHook(LOAD_TEXTURE); - ModInternal::initBindHook(2, - HookParameter({ .name = "path", .parameter = (void*)texPath }), - HookParameter({ .name = "texture", .parameter = static_cast(&res->imageData) }) - ); - ModInternal::callBindHook(0); + ModInternal::ExecuteHooks(texPath, &res->imageData); return (char*)res->imageData; } @@ -245,7 +190,7 @@ extern GfxWindowManagerAPI gfx_sdl; void SetWindowManager(GfxWindowManagerAPI** WmApi, GfxRenderingAPI** RenderingApi, const std::string& gfx_backend); namespace Ship { - std::map>> Window::Controllers; + int32_t Window::lastScancode; Window::Window(std::shared_ptr Context) : Context(Context), APlayer(nullptr) { @@ -260,23 +205,49 @@ namespace Ship { SPDLOG_INFO("destruct window"); } + void Window::CreateDefaults() { + const std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); + if (pConf->isNewInstance) { + pConf->setInt("Window.Width", 640); + pConf->setInt("Window.Height", 480); + pConf->setBool("Window.Options", false); + pConf->setString("Window.GfxBackend", ""); + + pConf->setBool("Window.Fullscreen.Enabled", false); + pConf->setInt("Window.Fullscreen.Width", 640); + pConf->setInt("Window.Fullscreen.Height", 480); + + pConf->setString("Game.SaveName", ""); + pConf->setString("Game.Main Archive", ""); + pConf->setString("Game.Patches Archive", ""); + + pConf->setInt("Shortcuts.Fullscreen", 0x044); + pConf->setInt("Shortcuts.Console", 0x029); + pConf->save(); + } + } + void Window::Init() { - std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); - ConfigFile& Conf = *pConf.get(); + std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); + + CreateDefaults(); SetAudioPlayer(); - bIsFullscreen = Ship::stob(Conf["WINDOW"]["FULLSCREEN"]); - dwWidth = Ship::stoi(Conf["WINDOW"]["WINDOW WIDTH"], 320); - dwHeight = Ship::stoi(Conf["WINDOW"]["WINDOW HEIGHT"], 240); - dwWidth = Ship::stoi(Conf["WINDOW"]["FULLSCREEN WIDTH"], 1920); - dwHeight = Ship::stoi(Conf["WINDOW"]["FULLSCREEN HEIGHT"], 1080); - dwMenubar = Ship::stoi(Conf["WINDOW"]["menubar"], 0); - const std::string& gfx_backend = Conf["WINDOW"]["GFX BACKEND"]; + bIsFullscreen = pConf->getBool("Window.Fullscreen.Enabled", false); + + dwWidth = pConf->getInt("Window.Fullscreen.Width", bIsFullscreen ? 1920 : 640); + dwHeight = pConf->getInt("Window.Fullscreen.Height", bIsFullscreen ? 1080 : 480); + dwMenubar = pConf->getBool("Window.Options", false); + const std::string& gfx_backend = pConf->getString("Window.GfxBackend"); SetWindowManager(&WmApi, &RenderingApi, gfx_backend); - gfx_init(WmApi, RenderingApi, GetContext()->GetName().c_str(), bIsFullscreen); - WmApi->set_fullscreen_changed_callback(Window::OnFullscreenChanged); - WmApi->set_keyboard_callbacks(Window::KeyDown, Window::KeyUp, Window::AllKeysUp); + gfx_init(WmApi, RenderingApi, GetContext()->GetName().c_str(), bIsFullscreen, dwWidth, dwHeight); + WmApi->set_fullscreen_changed_callback(OnFullscreenChanged); + WmApi->set_keyboard_callbacks(KeyDown, KeyUp, AllKeysUp); + + ModInternal::RegisterHook([]() { + ControllerApi->SaveControllerSettings(); + }); } void Window::StartFrame() { @@ -288,13 +259,14 @@ namespace Ship { gfx_run(Commands, m); gfx_end_frame(); } - gfx_run(Commands, {}); - gfx_end_frame(); } - void Window::SetFrameDivisor(int divisor) { - gfx_set_framedivisor(divisor); - //gfx_set_framedivisor(0); + void Window::SetTargetFps(int fps) { + gfx_set_target_fps(fps); + } + + void Window::SetMaximumFrameLatency(int latency) { + gfx_set_maximum_frame_latency(latency); } void Window::GetPixelDepthPrepare(float x, float y) { @@ -327,10 +299,9 @@ namespace Ship { WmApi->main_loop(MainFunction); } bool Window::KeyUp(int32_t dwScancode) { - std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); - ConfigFile& Conf = *pConf.get(); + std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); - if (dwScancode == Ship::stoi(Conf["KEYBOARD SHORTCUTS"]["KEY_FULLSCREEN"])) { + if (dwScancode == pConf->getInt("Shortcuts.Fullscreen", 0x044)) { GlobalCtx2::GetInstance()->GetWindow()->ToggleFullscreen(); } @@ -338,16 +309,14 @@ namespace Ship { //if (dwScancode == Ship::stoi(Conf["KEYBOARD SHORTCUTS"]["KEY_CONSOLE"])) { // ToggleConsole(); //} + + lastScancode = -1; bool bIsProcessed = false; - for (size_t i = 0; i < __osMaxControllers; i++) { - for (size_t j = 0; j < Controllers[i].size(); j++) { - KeyboardController* pad = dynamic_cast(Ship::Window::Controllers[i][j].get()); - if (pad != nullptr) { - if (pad->ReleaseButton(dwScancode)) { - bIsProcessed = true; - } - } + const auto pad = dynamic_cast(ControllerApi->physicalDevices[ControllerApi->physicalDevices.size() - 2].get()); + if (pad != nullptr) { + if (pad->ReleaseButton(dwScancode)) { + bIsProcessed = true; } } @@ -356,14 +325,11 @@ namespace Ship { bool Window::KeyDown(int32_t dwScancode) { bool bIsProcessed = false; - for (size_t i = 0; i < __osMaxControllers; i++) { - for (size_t j = 0; j < Controllers[i].size(); j++) { - KeyboardController* pad = dynamic_cast(Ship::Window::Controllers[i][j].get()); - if (pad != nullptr) { - if (pad->PressButton(dwScancode)) { - bIsProcessed = true; - } - } + + const auto pad = dynamic_cast(ControllerApi->physicalDevices[ControllerApi->physicalDevices.size() - 2].get()); + if (pad != nullptr) { + if (pad->PressButton(dwScancode)) { + bIsProcessed = true; } } @@ -374,21 +340,17 @@ namespace Ship { void Window::AllKeysUp(void) { - for (size_t i = 0; i < __osMaxControllers; i++) { - for (size_t j = 0; j < Controllers[i].size(); j++) { - KeyboardController* pad = dynamic_cast(Ship::Window::Controllers[i][j].get()); - if (pad != nullptr) { - pad->ReleaseAllButtons(); - } - } + const auto pad = dynamic_cast(ControllerApi->physicalDevices[ControllerApi->physicalDevices.size() - 2].get()); + if (pad != nullptr) { + pad->ReleaseAllButtons(); } } void Window::OnFullscreenChanged(bool bIsFullscreen) { - std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); - ConfigFile& Conf = *pConf.get(); + std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); + GlobalCtx2::GetInstance()->GetWindow()->bIsFullscreen = bIsFullscreen; - Conf["WINDOW"]["FULLSCREEN"] = std::to_string(bIsFullscreen); + pConf->setBool("Window.Fullscreen.Enabled", bIsFullscreen); GlobalCtx2::GetInstance()->GetWindow()->ShowCursor(!bIsFullscreen); } diff --git a/soh/include/functions.h b/soh/include/functions.h index c0d21049777..c0600929d38 100644 --- a/soh/include/functions.h +++ b/soh/include/functions.h @@ -60,7 +60,7 @@ void Locale_ResetRegion(void); u32 func_80001F48(void); u32 func_80001F8C(void); u32 Locale_IsRegionNative(void); -#ifndef __SWITCH__ +#if !defined(__APPLE__) && !defined(__SWITCH__) void __assert(const char* exp, const char* file, s32 line); #endif void isPrintfInit(void); @@ -448,6 +448,7 @@ u32 Actor_TextboxIsClosing(Actor* actor, GlobalContext* globalCtx); s8 func_8002F368(GlobalContext* globalCtx); void Actor_GetScreenPos(GlobalContext* globalCtx, Actor* actor, s16* x, s16* y); u32 Actor_HasParent(Actor* actor, GlobalContext* globalCtx); +s32 GiveItemWithoutActor(GlobalContext* globalCtx, s32 getItemId); s32 func_8002F434(Actor* actor, GlobalContext* globalCtx, s32 getItemId, f32 xzRange, f32 yRange); void func_8002F554(Actor* actor, GlobalContext* globalCtx, s32 getItemId); void func_8002F580(Actor* actor, GlobalContext* globalCtx); @@ -558,6 +559,7 @@ void ActorOverlayTable_Cleanup(void); u16 DynaSSNodeList_GetNextNodeIdx(DynaSSNodeList*); void func_80038A28(CollisionPoly* poly, f32 tx, f32 ty, f32 tz, MtxF* dest); f32 CollisionPoly_GetPointDistanceFromPlane(CollisionPoly* poly, Vec3f* point); +CollisionHeader* BgCheck_GetCollisionHeader(CollisionContext* colCtx, s32 bgId); void CollisionPoly_GetVerticesByBgId(CollisionPoly* poly, s32 bgId, CollisionContext* colCtx, Vec3f* dest); s32 BgCheck_CheckStaticCeiling(StaticLookup* lookup, u16 xpFlags, CollisionContext* colCtx, f32* outY, Vec3f* pos, f32 checkHeight, CollisionPoly** outPoly); @@ -2406,6 +2408,8 @@ char* SetQuote(); void Heaps_Alloc(void); void Heaps_Free(void); +CollisionHeader* BgCheck_GetCollisionHeader(CollisionContext* colCtx, s32 bgId); + #ifdef __cplusplus #undef this }; diff --git a/soh/soh/Enhancements/bootcommands.c b/soh/soh/Enhancements/bootcommands.c index c43135a215c..e64748d0046 100644 --- a/soh/soh/Enhancements/bootcommands.c +++ b/soh/soh/Enhancements/bootcommands.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -19,22 +20,30 @@ extern BootCommandFunc BootCommands_Command_LoadFileSelect(char** argv, s32 argc static BootCommand sCommands[] = { { "--skiplogo", BootCommands_Command_SkipLogo }, { "--loadfileselect", BootCommands_Command_LoadFileSelect } }; -void BootCommands_Init() +void BootCommands_Init() { CVar_RegisterS32("gDisableLOD", 0); CVar_RegisterS32("gDebugEnabled", 0); CVar_RegisterS32("gPauseLiveLink", 0); CVar_RegisterS32("gMinimalUI", 0); - CVar_RegisterS32("gRumbleEnabled", 0); - CVar_RegisterS32("gUniformLR", 1); + CVar_RegisterS32("gRedGanonBlood", 0); + CVar_RegisterS32("gHoverFishing", 0); + CVar_RegisterS32("gN64WeirdFrames", 0); + CVar_RegisterS32("gBombchusOOB", 0); + CVar_RegisterS32("gUniformLR", 0); CVar_RegisterS32("gTwoHandedIdle", 0); - CVar_RegisterS32("gDekuNutUpgradeFix", 1); + CVar_RegisterS32("gDekuNutUpgradeFix", 0); + CVar_RegisterS32("gNaviTextFix", 0); CVar_RegisterS32("gNewDrops", 0); CVar_RegisterS32("gVisualAgony", 0); CVar_RegisterS32("gLanguages", 0); //0 = English / 1 = German / 2 = French + CVar_RegisterS32("gForgeTime", 3); + CVar_RegisterS32("gGravediggingTourFix", 1); CVar_RegisterS32("gHudColors", 1); //0 = N64 / 1 = NGC / 2 = Custom CVar_RegisterS32("gUseNaviCol", 0); CVar_RegisterS32("gUseTunicsCol", 0); + CVar_RegisterS32("gGuardVision", 0); + CVar_RegisterS32("gTimeFlowFileSelect", 0); } //void BootCommands_ParseBootArgs(char* str) @@ -55,10 +64,10 @@ void BootCommands_ParseBootArgs(s32 argc, char** argv) } } - // for (i = 0; i < argc; i++) - // DebugArena_Free(argv[i]); + //for (i = 0; i < argc; i++) + //DebugArena_Free(argv[i]); - // DebugArena_Free(argv); + //DebugArena_Free(argv); } /* diff --git a/soh/src/code/audio_load.c b/soh/src/code/audio_load.c index 74b1a4bff43..eff3e5f8730 100644 --- a/soh/src/code/audio_load.c +++ b/soh/src/code/audio_load.c @@ -4,6 +4,7 @@ #include "ultra64.h" #include "global.h" +#include "soh/OTRGlobals.h" #define MK_ASYNC_MSG(retData, tableType, id, status) (((retData) << 24) | ((tableType) << 16) | ((id) << 8) | (status)) #define ASYNC_TBLTYPE(v) ((u8)(v >> 16)) @@ -37,11 +38,11 @@ void AudioLoad_ProcessAsyncLoads(s32 resetStatus); void AudioLoad_ProcessAsyncLoadUnkMedium(AudioAsyncLoad* asyncLoad, s32 resetStatus); void AudioLoad_ProcessAsyncLoad(AudioAsyncLoad* asyncLoad, s32 resetStatus); void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo, s32 temporary); -void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo); +void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo, int fontId); void AudioLoad_DiscardFont(s32 fontId); uintptr_t AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 noLoad); uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 tableId, s32* didAllocate); -uintptr_t AudioLoad_GetRealTableIndex(s32 tableType, u32 tableId); +u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 tableId); void* AudioLoad_SearchCaches(s32 tableType, s32 id); AudioTable* AudioLoad_GetLoadTable(s32 tableType); void AudioLoad_SyncDma(uintptr_t devAddr, u8* addr, size_t size, s32 medium); @@ -75,6 +76,12 @@ void* sUnusedHandler = NULL; s32 gAudioContextInitalized = false; +char* sequenceMap[256]; +char* fontMap[256]; + +uintptr_t fontStart; +uint32_t fontOffsets[8192]; + void AudioLoad_DecreaseSampleDmaTtls(void) { u32 i; @@ -279,8 +286,10 @@ void AudioLoad_InitSampleDmaBuffers(s32 arg0) { } s32 AudioLoad_IsFontLoadComplete(s32 fontId) { + return true; if (fontId == 0xFF) { return true; + } else if (gAudioContext.fontLoadStatus[fontId] >= 2) { return true; } else if (gAudioContext.fontLoadStatus[AudioLoad_GetRealTableIndex(FONT_TABLE, fontId)] >= 2) { @@ -353,6 +362,9 @@ void AudioLoad_InitTable(AudioTable* table, uintptr_t romAddr, u16 unkMediumPara for (i = 0; i < table->numEntries; i++) { if ((table->entries[i].size != 0) && (table->entries[i].medium == MEDIUM_CART)) { + if (romAddr == fontStart) + fontOffsets[i] = table->entries[i].romAddr; + table->entries[i].romAddr += romAddr; } } @@ -361,7 +373,7 @@ void AudioLoad_InitTable(AudioTable* table, uintptr_t romAddr, u16 unkMediumPara SoundFontData* AudioLoad_SyncLoadSeqFonts(s32 seqId, u32* outDefaultFontId) { char pad[0x8]; s32 index; - SoundFontData* font; + SoundFontData* font = NULL; s32 numFonts; s32 fontId; s32 i; @@ -376,6 +388,7 @@ SoundFontData* AudioLoad_SyncLoadSeqFonts(s32 seqId, u32* outDefaultFontId) { while (numFonts > 0) { fontId = gAudioContext.sequenceFontTable[index++]; + font = AudioLoad_SyncLoadFont(fontId); numFonts--; } @@ -401,7 +414,8 @@ void AudioLoad_SyncLoadSeqParts(s32 seqId, s32 arg1) { s32 AudioLoad_SyncLoadSample(SoundFontSample* sample, s32 fontId) { void* sampleAddr; - if (sample->unk_bit25 == 1) { + if (sample->unk_bit25 == 1) + { if (sample->medium != MEDIUM_RAM) { sampleAddr = AudioHeap_AllocSampleCache(sample->size, fontId, (void*)sample->sampleAddr, sample->medium, CACHE_PERSISTENT); @@ -448,7 +462,7 @@ s32 AudioLoad_SyncLoadInstrument(s32 fontId, s32 instId, s32 drumId) { void AudioLoad_AsyncLoad(s32 tableType, s32 id, s32 nChunks, s32 retData, OSMesgQueue* retQueue) { if (AudioLoad_AsyncLoadInner(tableType, id, nChunks, retData, retQueue) == NULL) { - osSendMesg(retQueue, 0xFFFFFFFF, OS_MESG_NOBLOCK); + osSendMesg32(retQueue, 0xFFFFFFFF, OS_MESG_NOBLOCK); } } @@ -467,13 +481,15 @@ void AudioLoad_AsyncLoadFont(s32 fontId, s32 arg1, s32 retData, OSMesgQueue* ret u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) { s32 index; - index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; + if (seqId == 255) + return NULL; + + SequenceData sDat = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); - *outNumFonts = gAudioContext.sequenceFontTable[index++]; - if (*outNumFonts == 0) { + if (sDat.numFonts == 0) return NULL; - } - return &gAudioContext.sequenceFontTable[index]; + + return sDat.fonts; } void AudioLoad_DiscardSeqFonts(s32 seqId) { @@ -549,30 +565,31 @@ s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) { s32 numFonts; s32 fontId; - if (seqId >= gAudioContext.numSequences) { - return 0; - } - AudioSeq_SequencePlayerDisable(seqPlayer); fontId = 0xFF; - index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; - numFonts = gAudioContext.sequenceFontTable[index++]; + //index = ((u16*)gAudioContext.sequenceFontTable)[seqId]; + //numFonts = gAudioContext.sequenceFontTable[index++]; - while (numFonts > 0) { - fontId = gAudioContext.sequenceFontTable[index++]; - AudioLoad_SyncLoadFont(fontId); - numFonts--; + SequenceData seqData2 = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); + + for (int i = 0; i < seqData2.numFonts; i++) + { + fontId = seqData2.fonts[i]; + AudioLoad_SyncLoadFont(fontId); // NOTE: If this is commented out, then enemies will play child link sounds... + //numFonts--; } seqData = AudioLoad_SyncLoadSeq(seqId); + if (seqData == NULL) { return 0; } AudioSeq_ResetSequencePlayer(seqPlayer); seqPlayer->seqId = seqId; - seqPlayer->defaultFont = AudioLoad_GetRealTableIndex(FONT_TABLE, fontId); + seqPlayer->defaultFont = fontId; + seqPlayer->seqData = seqData; seqPlayer->enabled = 1; seqPlayer->scriptState.pc = seqData; @@ -615,8 +632,8 @@ uintptr_t AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 return ret; } - cachePolicy = sampleBankTable->entries[sampleBankId].cachePolicy; - if (cachePolicy == 4 || noLoad == true) { + //cachePolicy = sampleBankTable->entries[sampleBankId].cachePolicy; + if (/* cachePolicy == 4 || */ noLoad == true) { *outMedium = sampleBankTable->entries[sampleBankId].medium; return sampleBankTable->entries[realTableId].romAddr; } @@ -642,22 +659,25 @@ SoundFontData* AudioLoad_SyncLoadFont(u32 fontId) { if (gAudioContext.fontLoadStatus[realFontId] == 1) { return NULL; } - sampleBankId1 = gAudioContext.soundFonts[realFontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFonts[realFontId].sampleBankId2; + + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); + + sampleBankId1 = sf->sampleBankId1; + sampleBankId2 = sf->sampleBankId2; relocInfo.sampleBankId1 = sampleBankId1; relocInfo.sampleBankId2 = sampleBankId2; - if (sampleBankId1 != 0xFF) { - relocInfo.baseAddr1 = AudioLoad_TrySyncLoadSampleBank(sampleBankId1, &relocInfo.medium1, false); - } else { + //if (sampleBankId1 != 0xFF) { + //relocInfo.baseAddr1 = AudioLoad_TrySyncLoadSampleBank(sampleBankId1, &relocInfo.medium1, false); + //} else { relocInfo.baseAddr1 = 0; - } + //} - if (sampleBankId2 != 0xFF) { - relocInfo.baseAddr2 = AudioLoad_TrySyncLoadSampleBank(sampleBankId2, &relocInfo.medium2, false); - } else { + //if (sampleBankId2 != 0xFF) { + //relocInfo.baseAddr2 = AudioLoad_TrySyncLoadSampleBank(sampleBankId2, &relocInfo.medium2, false); + //} else { relocInfo.baseAddr2 = 0; - } + //} ret = AudioLoad_SyncLoad(FONT_TABLE, fontId, &didAllocate); if (ret == NULL) { @@ -687,12 +707,36 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { *didAllocate = false; status = 2; } else { - table = AudioLoad_GetLoadTable(tableType); - size = table->entries[realId].size; - size = ALIGN16(size); - medium = table->entries[id].medium; - cachePolicy = table->entries[id].cachePolicy; - romAddr = table->entries[realId].romAddr; + char* seqData = 0; + SoundFont* fnt; + + if (tableType == SEQUENCE_TABLE) + { + SequenceData sData = ResourceMgr_LoadSeqByName(sequenceMap[id]); + seqData = sData.seqData; + size = sData.seqDataSize; + medium = sData.medium; + cachePolicy = sData.cachePolicy; + romAddr = 0; + } + else if (tableType == FONT_TABLE) + { + fnt = ResourceMgr_LoadAudioSoundFont(fontMap[id]); + size = sizeof(SoundFont); + medium = 2; + cachePolicy = 0; + romAddr = 0; + } + else + { + //table = AudioLoad_GetLoadTable(tableType); + //size = table->entries[realId].size; + //size = ALIGN16(size); + //medium = table->entries[id].medium; + //cachePolicy = table->entries[id].cachePolicy; + //romAddr = table->entries[realId].romAddr; + } + switch (cachePolicy) { case 0: ret = AudioHeap_AllocPermanent(tableType, realId, size); @@ -725,7 +769,14 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { if (medium == MEDIUM_UNK) { AudioLoad_SyncDmaUnkMedium(romAddr, ret, size, (s16)table->unkMediumParam); } else { - AudioLoad_SyncDma(romAddr, ret, size, medium); + if (tableType == SEQUENCE_TABLE && seqData != NULL) { + AudioLoad_SyncDma(seqData, ret, size, medium); + } else if (tableType == FONT_TABLE) { + AudioLoad_SyncDma(fnt, ret, size, medium); + } + else { + //AudioLoad_SyncDma(romAddr, ret, size, medium); + } } status = cachePolicy == 0 ? 5 : 2; @@ -748,13 +799,20 @@ uintptr_t AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) { return ret; } -uintptr_t AudioLoad_GetRealTableIndex(s32 tableType, u32 id) { - AudioTable* table = AudioLoad_GetLoadTable(tableType); - - if (table->entries[id].size == 0) { - id = table->entries[id].romAddr; +u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 id) +{ + if ((tableType == SEQUENCE_TABLE || tableType == FONT_TABLE)) { + return id; } + //AudioTable* table = AudioLoad_GetLoadTable(tableType); + + // If the size is 0, then this entry actually redirects to another entry. + // The rom address is actually an index into the same table where the "real" data is. + //if (table->entries[id].size == 0) { + //id = table->entries[id].romAddr; + //} + return id; } @@ -801,46 +859,42 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo Drum* drum; SoundFontSound* sfx; s32 i; - s32 numDrums = gAudioContext.soundFonts[fontId].numDrums; - s32 numInstruments = gAudioContext.soundFonts[fontId].numInstruments; - s32 numSfx = gAudioContext.soundFonts[fontId].numSfx; + SoundFont* sf = NULL; + s32 numDrums = 0; + s32 numInstruments = 0; + s32 numSfx = 0; + + sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); + numDrums = sf->numDrums; + numInstruments = sf->numInstruments; + numSfx = sf->numSfx; + void** ptrs = (void**)mem; -#define BASE_OFFSET(x) (uintptr_t)((uintptr_t)(x) + (uintptr_t)(mem)) +#define BASE_OFFSET(x) (void*)((u32)(x) + (u32)(mem)) reloc2 = ptrs[0]; - if (1) {} - if ((reloc2 != 0) && (numDrums != 0)) { + if ((numDrums != 0)) + { ptrs[0] = BASE_OFFSET(reloc2); - for (i = 0; i < numDrums; i++) { - reloc = ((Drum**)ptrs[0])[i]; - - if (reloc != 0) { - reloc = BASE_OFFSET(reloc); - - ((Drum**)ptrs[0])[i] = drum = reloc; - if (!drum->loaded) { - AudioLoad_RelocateSample(&drum->sound, mem, relocInfo); - reloc = drum->envelope; - drum->envelope = BASE_OFFSET(reloc); - drum->loaded = 1; - } + for (i = 0; i < numDrums; i++) + { + drum = sf->drums[i]; + + if (!drum->loaded) + { + AudioLoad_RelocateSample(&sf->drums[i]->sound, mem, relocInfo, fontOffsets[fontId]); + drum->loaded = 1; } } } reloc2 = ptrs[1]; - if (1) {} - if ((reloc2 != 0) && (numSfx != 0)) { + if (numSfx != 0) { ptrs[1] = BASE_OFFSET(reloc2); for (i = 0; i < numSfx; i++) { reloc = (SoundFontSound*)ptrs[1] + i; - if (reloc != 0) { - sfx = reloc; - if (sfx->sample != NULL) { - AudioLoad_RelocateSample(sfx, mem, relocInfo); - } - } + AudioLoad_RelocateSample(&sf->soundEffects[i].sample, mem, relocInfo, fontOffsets[fontId]); } } @@ -848,38 +902,34 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo numInstruments = 0x7E; } - for (i = 2; i <= 2 + numInstruments - 1; i++) { - if (ptrs[i] != NULL) { - ptrs[i] = BASE_OFFSET(ptrs[i]); + int startI = 0; + int startEC = numInstruments - 1; + for (i = startI; i <= startEC; i++) { + ptrs[i] = BASE_OFFSET(ptrs[i]); + inst = sf->instruments[i]; - inst = ptrs[i]; - if (!inst->loaded) { - if (inst->normalRangeLo != 0) { - AudioLoad_RelocateSample(&inst->lowNotesSound, mem, relocInfo); - } - AudioLoad_RelocateSample(&inst->normalNotesSound, mem, relocInfo); - if (inst->normalRangeHi != 0x7F) { - AudioLoad_RelocateSample(&inst->highNotesSound, mem, relocInfo); - } - - reloc = inst->envelope; - inst->envelope = BASE_OFFSET(reloc); - inst->loaded = 1; + if (inst != NULL && !inst->loaded) { + if (inst->normalRangeLo != 0) + { + AudioLoad_RelocateSample(&inst->lowNotesSound, mem, relocInfo, fontOffsets[fontId]); + } + AudioLoad_RelocateSample(&inst->normalNotesSound, mem, relocInfo, fontOffsets[fontId]); + if (inst->normalRangeHi != 0x7F) { + AudioLoad_RelocateSample(&inst->highNotesSound, mem, relocInfo, fontOffsets[fontId]); } + + reloc = inst->envelope; + inst->loaded = 1; } } #undef BASE_OFFSET - - gAudioContext.soundFonts[fontId].drums = ptrs[0]; - gAudioContext.soundFonts[fontId].soundEffects = ptrs[1]; - gAudioContext.soundFonts[fontId].instruments = (Instrument**)(ptrs + 2); } void AudioLoad_SyncDma(uintptr_t devAddr, u8* addr, size_t size, s32 medium) { OSMesgQueue* msgQueue = &gAudioContext.syncDmaQueue; OSIoMesg* ioMesg = &gAudioContext.syncDmaIoMesg; - size = ALIGN16(size); + //size = ALIGN16(size); Audio_InvalDCache(addr, size); @@ -956,7 +1006,7 @@ void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData, ret = AudioLoad_SearchCaches(tableType, realId); if (ret != NULL) { status = 2; - osSendMesg(retQueue, MK_ASYNC_MSG(retData, 0, 0, 0), OS_MESG_NOBLOCK); + osSendMesg32(retQueue, MK_ASYNC_MSG(retData, 0, 0, 0), OS_MESG_NOBLOCK); } else { sp50 = AudioLoad_GetLoadTable(tableType); size = sp50->entries[realId].size; @@ -1059,25 +1109,6 @@ s32 AudioLoad_AssertValidAddr(uintptr_t ramAddr, uintptr_t startAddr, size_t siz #define BASE_ROM_OFFSET(x) (uintptr_t)((uintptr_t)(x) + (uintptr_t)(romAddr)) void AudioLoad_InitSwapFontSampleHeaders(SoundFontSample* sample, uintptr_t romAddr) { - // OTRTODO: This will be removed when we actually extract the data. - size_t maxSoundFontSize = 0x3AA0; // soundFont 0 is the largest size at 0x3AA0 - AdpcmLoop* loop; - AdpcmBook* book; - - if (((uintptr_t)sample->loop > maxSoundFontSize) || ((uintptr_t)sample->book > maxSoundFontSize) ) { - bswapSoundFontSample(sample); - - loop = (AdpcmLoop*)BASE_ROM_OFFSET(sample->loop); - if ((uint32_t)loop->end > (uint32_t)0xFFFF) { - bswapAdpcmLoop(loop); - } - - book = (AdpcmBook*)BASE_ROM_OFFSET(sample->book); - if (book->order > 0xFFFF) { - bswapAdpcmBook(book); - } - } - return; } void AudioLoad_InitSwapFont(void) { @@ -1124,7 +1155,6 @@ void AudioLoad_InitSwapFont(void) { if (drumList[i] != NULL) { drum = (Drum*)BASE_ROM_OFFSET(drumList[i]); - bswapDrum(drum); sample = (SoundFontSample*)BASE_ROM_OFFSET(drum->sound.sample); AudioLoad_InitSwapFontSampleHeaders(sample, romAddr); @@ -1140,7 +1170,6 @@ void AudioLoad_InitSwapFont(void) { for (i = 0; i < numSfxs; i++) { sfx = &sfxList[i]; - bswapSoundFontSound(sfx); if (sfx->sample != NULL) { SoundFontSample* sample = (SoundFontSample*)BASE_ROM_OFFSET(sfx->sample); @@ -1160,7 +1189,6 @@ void AudioLoad_InitSwapFont(void) { if (instList[i] != NULL) { inst = BASE_ROM_OFFSET(instList[i]); - bswapInstrument(inst); if (inst->normalRangeLo != 0) { sample = (SoundFontSample*)BASE_ROM_OFFSET(inst->lowNotesSound.sample); @@ -1189,19 +1217,12 @@ void AudioLoad_Init(void* heap, size_t heapSize) { void* temp_v0_3; s32 i; u64* heapP; - u8* ctxP; s16* u2974p; D_801755D0 = NULL; gAudioContext.resetTimer = 0; - { - s32 i; - u8* ctxP = (u8*)&gAudioContext; - for (i = sizeof(gAudioContext); i >= 0; i--) { - *ctxP++ = 0; - } - } + memset(&gAudioContext, 0, sizeof(gAudioContext)); switch (osTvType) { case OS_TV_PAL: @@ -1260,41 +1281,59 @@ void AudioLoad_Init(void* heap, size_t heapSize) { gAudioContext.aiBuffers[i] = AudioHeap_AllocZeroed(&gAudioContext.audioInitPool, AIBUF_LEN * sizeof(s16)); } - gAudioContext.sequenceTable = (AudioTable*)gSequenceTable; - gAudioContext.soundFontTable = (AudioTable*)gSoundFontTable; - gAudioContext.sampleBankTable = (AudioTable*)gSampleBankTable; - gAudioContext.sequenceFontTable = gSequenceFontTable; - gAudioContext.numSequences = gAudioContext.sequenceTable->numEntries; + //gAudioContext.sequenceTable = (AudioTable*)gSequenceTable; + //gAudioContext.soundFontTable = (AudioTable*)gSoundFontTable; + //gAudioContext.sampleBankTable = (AudioTable*)gSampleBankTable; + //gAudioContext.sequenceFontTable = gSequenceFontTable; + //gAudioContext.numSequences = gAudioContext.sequenceTable->numEntries; gAudioContext.audioResetSpecIdToLoad = 0; gAudioContext.resetStatus = 1; AudioHeap_ResetStep(); - uintptr_t seqStart = ResourceMgr_LoadFileRaw(_AudioseqSegmentRomStart); - uintptr_t bankStart = ResourceMgr_LoadFileRaw(_AudiobankSegmentRomStart); - uintptr_t tableStart = ResourceMgr_LoadFileRaw(_AudiotableSegmentRomStart); + int seqListSize = 0; + char** seqList = ResourceMgr_ListFiles("audio/sequences*", &seqListSize); - AudioLoad_InitTable(gAudioContext.sequenceTable, seqStart, 0); - AudioLoad_InitTable(gAudioContext.soundFontTable, bankStart, 0); - AudioLoad_InitTable(gAudioContext.sampleBankTable, tableStart, 0); - numFonts = gAudioContext.soundFontTable->numEntries; - gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); + for (size_t i = 0; i < seqListSize; i++) + { + SequenceData sDat = ResourceMgr_LoadSeqByName(seqList[i]); + + char* str = malloc(strlen(seqList[i]) + 1); + strcpy(str, seqList[i]); + + sequenceMap[sDat.seqNumber] = str; + } + + free(seqList); + + int fntListSize = 0; + char** fntList = ResourceMgr_ListFiles("audio/fonts*", &fntListSize); - for (i = 0; i < numFonts; i++) { - AudioLoad_InitSoundFontMeta(i); + for (int i = 0; i < fntListSize; i++) + { + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fntList[i]); + + char* str = malloc(strlen(fntList[i]) + 1); + strcpy(str, fntList[i]); + + fontMap[sf->fntIndex] = str; } - AudioLoad_InitSwapFont(); + numFonts = fntListSize; + + free(fntList); + gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); + if (temp_v0_3 = AudioHeap_Alloc(&gAudioContext.audioInitPool, D_8014A6C4.permanentPoolSize), temp_v0_3 == NULL) { // cast away const from D_8014A6C4 - *((size_t*)&D_8014A6C4.permanentPoolSize) = 0; + // *((u32*)&D_8014A6C4.permanentPoolSize) = 0; } AudioHeap_AllocPoolInit(&gAudioContext.permanentPool, temp_v0_3, D_8014A6C4.permanentPoolSize); gAudioContextInitalized = true; - osSendMesg(gAudioContext.taskStartQueueP, (void*)gAudioContext.totalTaskCnt, OS_MESG_NOBLOCK); + osSendMesg32(gAudioContext.taskStartQueueP, gAudioContext.totalTaskCnt, OS_MESG_NOBLOCK); } void AudioLoad_InitSlowLoads(void) { @@ -1459,11 +1498,6 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* isDone) { AudioTable* seqTable; size_t size; - if (seqId >= gAudioContext.numSequences) { - *isDone = 0; - return -1; - } - seqId = AudioLoad_GetRealTableIndex(SEQUENCE_TABLE, seqId); seqTable = AudioLoad_GetLoadTable(SEQUENCE_TABLE); slowLoad = &gAudioContext.slowLoads[gAudioContext.slowLoadPos]; @@ -1473,14 +1507,17 @@ s32 AudioLoad_SlowLoadSeq(s32 seqId, u8* ramAddr, s8* isDone) { slowLoad->sample.sampleAddr = NULL; slowLoad->isDone = isDone; - size = seqTable->entries[seqId].size; - size = ALIGN16(size); + + SequenceData sData = ResourceMgr_LoadSeqByName(sequenceMap[seqId]); + char* seqData = sData.seqData; + size = sData.seqDataSize; + slowLoad->curDevAddr = seqData; + slowLoad->medium = sData.medium; + slowLoad->curRamAddr = ramAddr; slowLoad->status = LOAD_STATUS_START; slowLoad->bytesRemaining = size; slowLoad->ramAddr = ramAddr; - slowLoad->curDevAddr = seqTable->entries[seqId].romAddr; - slowLoad->medium = seqTable->entries[seqId].medium; slowLoad->seqOrFontId = seqId; if (slowLoad->medium == MEDIUM_UNK) { @@ -1499,8 +1536,8 @@ void AudioLoad_InitAsyncLoads(void) { } } -AudioAsyncLoad* AudioLoad_StartAsyncLoadUnkMedium(s32 unkMediumParam, uintptr_t devAddr, uintptr_t ramAddr, - size_t size, s32 medium, +AudioAsyncLoad* AudioLoad_StartAsyncLoadUnkMedium(s32 unkMediumParam, uintptr_t devAddr, uintptr_t ramAddr, size_t size, + s32 medium, s32 nChunks, OSMesgQueue* retQueue, s32 retMsg) { AudioAsyncLoad* asyncLoad; @@ -1510,7 +1547,7 @@ AudioAsyncLoad* AudioLoad_StartAsyncLoadUnkMedium(s32 unkMediumParam, uintptr_t return NULL; } - osSendMesg(&gAudioContext.asyncLoadUnkMediumQueue, asyncLoad, OS_MESG_NOBLOCK); + osSendMesgPtr(&gAudioContext.asyncLoadUnkMediumQueue, asyncLoad, OS_MESG_NOBLOCK); asyncLoad->unkMediumParam = unkMediumParam; return asyncLoad; } @@ -1603,7 +1640,6 @@ void AudioLoad_FinishAsyncLoad(AudioAsyncLoad* asyncLoad) { u32 sampleBankId2; RelocInfo relocInfo; - if (1) {} switch (ASYNC_TBLTYPE(retMsg)) { case SEQUENCE_TABLE: AudioLoad_SetSeqLoadStatus(ASYNC_ID(retMsg), ASYNC_STATUS(retMsg)); @@ -1626,8 +1662,7 @@ void AudioLoad_FinishAsyncLoad(AudioAsyncLoad* asyncLoad) { break; } - doneMsg = asyncLoad->retMsg; - if (1) {} + doneMsg.data32 = asyncLoad->retMsg; asyncLoad->status = LOAD_STATUS_WAITING; osSendMesg(asyncLoad->retQueue, doneMsg, OS_MESG_NOBLOCK); } @@ -1691,53 +1726,10 @@ void AudioLoad_AsyncDma(AudioAsyncLoad* asyncLoad, size_t size) { void AudioLoad_AsyncDmaUnkMedium(uintptr_t devAddr, uintptr_t ramAddr, size_t size, s16 arg3) { } -#define RELOC(v, base) (reloc = (uintptr_t)((uintptr_t)(v) + (uintptr_t)(base))) - -void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo) { - // OTRTODO: This is hack to detect whether or not the sample has been relocated. - size_t maxSoundBankSize = 0x3EB2A0; // sample bank 0 is largest size at 0x3EB2A0 - if ((uintptr_t)mem <= maxSoundBankSize) { - // OTRTODO: This can be removed once we have properly byteswapped files on the disk. - assert("mem for sound font bank is too low."); - } - - SoundFontSample* sample; - void* reloc; - - // OTRTODO: Seems precarious to assume the RAM is never <= 0x3EB2A0, but it largely works. - if ((uintptr_t)sound->sample < maxSoundBankSize) { - sample = sound->sample = RELOC(sound->sample, mem); - if (sample->size != 0 && sample->unk_bit25 != 1) { - sample->loop = RELOC(sample->loop, mem); - sample->book = RELOC(sample->book, mem); - - // Resolve the sample medium 2-bit bitfield into a real value based on relocInfo. - switch (sample->medium) { - case 0: - sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr1); - sample->medium = relocInfo->medium1; - break; - case 1: - sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr2); - sample->medium = relocInfo->medium2; - break; - case 2: - case 3: - // Invalid? This leaves sample->medium as MEDIUM_CART and MEDIUM_DISK_DRIVE - // respectively, and the sampleAddr unrelocated. - break; - } - - sample->unk_bit25 = 1; - if (sample->unk_bit26 && (sample->medium != MEDIUM_RAM)) { - gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; - } - } - } +void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, RelocInfo* relocInfo, int fontId) +{ } -#undef RELOC - void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo, s32 async) { AudioPreloadReq* preload; AudioPreloadReq* topPreload; @@ -1864,7 +1856,7 @@ s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) { if (preload->isFree == false) { sample = preload->sample; - key = sample->sampleAddr + sample->size + sample->medium; + key = (u32)sample->sampleAddr + sample->size + sample->medium; if (key == preload->endAndMediumKey) { // Change storage for sample to the preloaded version. sample->sampleAddr = preload->ramAddr; @@ -1887,12 +1879,12 @@ s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) { sample = preload->sample; nChunks = (sample->size >> 12) + 1; - key = sample->sampleAddr + sample->size + sample->medium; + key = (u32)sample->sampleAddr + sample->size + sample->medium; if (key != preload->endAndMediumKey) { preload->isFree = true; gAudioContext.preloadSampleStackTop--; } else { - AudioLoad_StartAsyncLoad(sample->sampleAddr, preload->ramAddr, sample->size, sample->medium, + AudioLoad_StartAsyncLoad((u32)sample->sampleAddr, preload->ramAddr, sample->size, sample->medium, nChunks, &gAudioContext.preloadSampleQueue, preload->encodedInfo); break; } @@ -1929,7 +1921,6 @@ s32 AudioLoad_GetSamplesForFont(s32 fontId, SoundFontSample** sampleSet) { for (i = 0; i < numDrums; i++) { Drum* drum = Audio_GetDrum(fontId, i); - if (1) {} if (drum != NULL) { numSamples = AudioLoad_AddToSampleSet(drum->sound.sample, numSamples, sampleSet); } @@ -1955,8 +1946,10 @@ s32 AudioLoad_GetSamplesForFont(s32 fontId, SoundFontSample** sampleSet) { void AudioLoad_AddUsedSample(SoundFontSound* sound) { SoundFontSample* sample = sound->sample; - if ((sample->size != 0) && (sample->unk_bit26) && (sample->medium != MEDIUM_RAM)) { - gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; + if (sample != NULL) { + if ((sample->size != 0) && (sample->unk_bit26) && (sample->medium != MEDIUM_RAM)) { + gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; + } } } @@ -1983,9 +1976,11 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, RelocInfo* relocInfo gAudioContext.numUsedSamples = 0; - numDrums = gAudioContext.soundFonts[fontId].numDrums; - numInstruments = gAudioContext.soundFonts[fontId].numInstruments; - numSfx = gAudioContext.soundFonts[fontId].numSfx; + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); + + numDrums = sf->numDrums; + numInstruments = sf->numInstruments; + numSfx = sf->numSfx; for (i = 0; i < numInstruments; i++) { instrument = Audio_GetInstrumentInner(fontId, i); @@ -2106,11 +2101,16 @@ void AudioLoad_LoadPermanentSamples(void) { for (i = 0; i < gAudioContext.permanentPool.count; i++) { RelocInfo relocInfo; - if (gAudioContext.permanentCache[i].tableType == FONT_TABLE) { + if (gAudioContext.permanentCache[i].tableType == FONT_TABLE) + { fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioContext.permanentCache[i].id); - relocInfo.sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1; - relocInfo.sampleBankId2 = gAudioContext.soundFonts[fontId].sampleBankId2; + //fontId = gAudioContext.permanentCache[i].id; + + SoundFont* sf = ResourceMgr_LoadAudioSoundFont(fontMap[fontId]); + relocInfo.sampleBankId1 = sf->sampleBankId1; + relocInfo.sampleBankId2 = sf->sampleBankId2; + /* if (relocInfo.sampleBankId1 != 0xFF) { relocInfo.sampleBankId1 = AudioLoad_GetRealTableIndex(SAMPLE_TABLE, relocInfo.sampleBankId1); relocInfo.medium1 = sampleBankTable->entries[relocInfo.sampleBankId1].medium; @@ -2120,6 +2120,8 @@ void AudioLoad_LoadPermanentSamples(void) { relocInfo.sampleBankId2 = AudioLoad_GetRealTableIndex(SAMPLE_TABLE, relocInfo.sampleBankId2); relocInfo.medium2 = sampleBankTable->entries[relocInfo.sampleBankId2].medium; } + */ + AudioLoad_PreloadSamplesForFont(fontId, false, &relocInfo); } }