Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature: Emulate Infinity Base #11546

Merged
merged 2 commits into from Apr 30, 2023

Conversation

deReeperJosh
Copy link
Contributor

@deReeperJosh deReeperJosh commented Feb 6, 2023

Description

This PR introduces the ability to emulate the Infinity Base within Dolphin, another Wii peripheral device that can be a hassle to set up, and is currently unavailable for use on MacOS (without sudo) or Android. Where the Skylanders portal was a port from RPCS3, the Infinity code was written from scratch based on reverse engineering done with an Infinity 1.0 Base, and other pieces of research found online. Here's a video of the functionality in action

Tasks

Currently Working:

  • Responding to the challenge sent by the game
  • Reading from .bin files from the UI
  • Ensuring order for reads/write commands
  • Play Sets/Power Discs in Hexagon slot
  • Players in either of the Circular slots
  • Circular "Ability" discs that sit underneath the Character figures
  • The ability to create blank Figures in the UI

Nice to Haves:
Proper Color structures - similar to the Skylander Portal. Requires investigation.

Hopefully this might inspire a developer to look in to seeing how we can optimise Infinity within Dolphin 😄

@deReeperJosh
Copy link
Contributor Author

Looked like bit shifting on Windows wasn't trusted, changed all the instances of unsigned long to u32/u64 depending on their length

@deReeperJosh
Copy link
Contributor Author

deReeperJosh commented Feb 8, 2023

Unsure if the creation will be possible without a bunch of hardcoded "checksums".
The checksums are known now, just needed some brute-force to figure out the CRC32 polynomial :)

For a blank infinity figure file to be able to be used in game, it needs the 7 byte UID (which is known for most figures) and block 1 of the 20 block file (where each block is 16 bytes). This UID can be randomly generated and still work, so the CreateFigure method I have created uses a 7 byte random number when creating blanks.

In the 1st block of the file, there is key information about the figure that the game caches and stores so that it is known what Infinity figure/power disc/play set is in each slot, and this block is read only, so is never written to.

An example of what a block 1 (decrypted) looks like can be seen below:

00 0F 42 4C 10 0C 1E 00 00 01 D1 1F A7 3F 78 60

This block represents Barbosa from the Pirates of the Caribbean, and the byte breakdown is as follows:

The first 2 bytes (00 0F) are the same for every character in the game as far as I can tell. The 3rd and 4th byte (42 4C) is the Id of the character itself, so every Barbosa will be 42 4C etc. The 3rd and 4th bytes are the only ones that need to be included in the list, as a u16.

The next 4 bytes (10 0C 1E 00) appear to be sort of consistent This set of 4 bytes is actually the toy's manufacture date, written YY/MM/DD.

The next 4 bytes (00 01 D1 1F) are consistent across every figure type in the same series, so play sets, power discs, characters and toy box customisations all have this sequence for infinity 1.0. Noting here that this probably stands for 1.0 Disney Infinity or something similar. Series 2 toys are 00 02 D1 1F, and Series 3 are 00 03 D1 1F.

The last 4 bytes are a crc32 checksum of the prior 12 bytes.

@mandar1jn
Copy link
Contributor

The second to last commit says Skylanders

@deReeperJosh
Copy link
Contributor Author

@mandar1jn oops just a typo, should say Infinity Figures

@deReeperJosh deReeperJosh force-pushed the disneyinfinitybase branch 3 times, most recently from 0569594 to bcf844a Compare February 12, 2023 05:35
@leoetlino leoetlino self-requested a review February 21, 2023 09:55
@deReeperJosh deReeperJosh force-pushed the disneyinfinitybase branch 5 times, most recently from 9a3ff20 to dec8c0b Compare March 7, 2023 04:16
@JMC47
Copy link
Contributor

JMC47 commented Mar 7, 2023

@dolphin-emu-bot rebuild

@dolphin-emu-bot
Copy link
Contributor

FifoCI detected that this change impacts graphical rendering. Here are the behavior differences detected by the system:

  • xenoblade-menu on uberogl-lin-radeon: diff

automated-fifoci-reporter

Source/Core/Core/IOS/USB/Emulated/Infinity.cpp Outdated Show resolved Hide resolved
Source/Core/Core/IOS/USB/Emulated/Infinity.cpp Outdated Show resolved Hide resolved
Source/Core/Core/IOS/USB/Emulated/Infinity.cpp Outdated Show resolved Hide resolved
Source/Core/Core/IOS/USB/Emulated/Infinity.h Outdated Show resolved Hide resolved
Source/Core/Core/IOS/USB/Emulated/Infinity.h Outdated Show resolved Hide resolved
Source/Core/DolphinQt/InfinityBase/InfinityBaseWindow.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/InfinityBase/InfinityBaseWindow.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/InfinityBase/InfinityBaseWindow.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/InfinityBase/InfinityBaseWindow.cpp Outdated Show resolved Hide resolved
{
if (!m_infinity_window)
{
m_infinity_window = new InfinityBaseWindow;
Copy link
Member

Choose a reason for hiding this comment

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

Should this not be given a parent, like:

Suggested change
m_infinity_window = new InfinityBaseWindow;
m_infinity_window = new InfinityBaseWindow(this);

otherwise this could leak

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied this from the FIFO Window - which also is not given a parent. Should it also have this referenced? (The Skylander Portal Window has this missing as well)

Copy link
Member

Choose a reason for hiding this comment

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

Qt will automatically reparent widgets in some cases (when you add a widget to a layout for instance). In this case (and for the Skylander window too), you're just creating a window and I don't think there's any automatic reparenting being done here so you should probably give it a parent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I specify (this) as the parent, the window looks like this (on Mac at least):

Screenshot 2023-04-11 at 11 42 38 AM

Is it appropriate to specify the parent as being null?

@deReeperJosh deReeperJosh force-pushed the disneyinfinitybase branch 5 times, most recently from 73a7d3f to f2cc823 Compare March 8, 2023 08:41
@deReeperJosh
Copy link
Contributor Author

Changes made as above - I should note that some of the changes here may also apply to the Skylanders Qt Window, like QStringLiterals, would like to keep it consistent and map that across in a future PR.

@deReeperJosh deReeperJosh force-pushed the disneyinfinitybase branch 5 times, most recently from de6e0ed to e330226 Compare March 14, 2023 01:07
@deReeperJosh deReeperJosh force-pushed the disneyinfinitybase branch 3 times, most recently from c28d544 to a071d26 Compare April 20, 2023 07:52
@deReeperJosh deReeperJosh force-pushed the disneyinfinitybase branch 3 times, most recently from adafb05 to 2610827 Compare April 20, 2023 21:22
@deReeperJosh deReeperJosh force-pushed the disneyinfinitybase branch 3 times, most recently from 3c8af20 to 79f67fe Compare April 23, 2023 10:24
@deReeperJosh
Copy link
Contributor Author

deReeperJosh commented Apr 23, 2023

A little bit more research has meant that there is no need for the 2 structs that I had defined in the header file, just a u32 for the figure number (found here). The bytes that I thought were figure specific were just the manufacture date of the toy, so I have set this to the date Disney Infinity 1.0 was released.

@JMC47
Copy link
Contributor

JMC47 commented Apr 27, 2023

Is there anything left blocking this? Would like to have it in for the progress report.

@deReeperJosh
Copy link
Contributor Author

Nothing from an implementation standpoint - @leoetlino @AdmiralCurtiss any other review comments?

@leoetlino
Copy link
Member

Sorry for the delay, I'll give this another review asap (tonight or tomorrow)

Source/Core/Core/IOS/USB/Emulated/Infinity.h Outdated Show resolved Hide resolved
Source/Core/DolphinQt/InfinityBase/InfinityBaseWindow.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/InfinityBase/InfinityBaseWindow.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/InfinityBase/InfinityBaseWindow.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/InfinityBase/InfinityBaseWindow.cpp Outdated Show resolved Hide resolved
Source/Core/Core/IOS/USB/Emulated/Infinity.cpp Outdated Show resolved Hide resolved
Source/Core/Core/IOS/USB/Emulated/Infinity.cpp Outdated Show resolved Hide resolved
Source/Core/Core/IOS/USB/Emulated/Infinity.cpp Outdated Show resolved Hide resolved
Source/Core/Core/IOS/USB/Emulated/Infinity.cpp Outdated Show resolved Hide resolved
Source/Core/Core/IOS/USB/Emulated/Infinity.cpp Outdated Show resolved Hide resolved
Create, Load and Clear Infinity figures on an emulated base in the UI
@deReeperJosh deReeperJosh force-pushed the disneyinfinitybase branch 2 times, most recently from 0aaec18 to 2725ed1 Compare April 28, 2023 01:11
@deReeperJosh
Copy link
Contributor Author

@leoetlino thanks heaps - hopefully that is everything. Have also slightly modified the Host.cpp file to reflect latest changes with the EmulationKernel(). Fingers crossed I haven't missed anything there!

@AdmiralCurtiss
Copy link
Contributor

Yeah go ahead and push the lint fixes.

@deReeperJosh
Copy link
Contributor Author

Just restored a Qt change with the filepath after testing it and remembering why I had included the change in the first place - still ready for build and test

Copy link
Contributor

@AdmiralCurtiss AdmiralCurtiss left a comment

Choose a reason for hiding this comment

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

Untested and I don't know whether the actual algorithms are correct, but this looks fine to me now.

@leoetlino leoetlino merged commit f36e05a into dolphin-emu:master Apr 30, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
8 participants