From a1c1a608d77e6c1f7989127d472c655d3159df62 Mon Sep 17 00:00:00 2001 From: Joshua de Reeper Date: Tue, 23 Jul 2024 02:18:48 +0100 Subject: [PATCH] nsyshid: Emulate Infinity Base (#1246) --- src/Cafe/CMakeLists.txt | 2 + src/Cafe/OS/libs/nsyshid/BackendEmulated.cpp | 8 + src/Cafe/OS/libs/nsyshid/Infinity.cpp | 1102 +++++++++++++++++ src/Cafe/OS/libs/nsyshid/Infinity.h | 105 ++ src/Cafe/OS/libs/nsyshid/Skylander.cpp | 2 +- src/Cafe/OS/libs/nsyshid/Skylander.h | 8 +- src/config/CemuConfig.cpp | 2 + src/config/CemuConfig.h | 1 + .../EmulatedUSBDeviceFrame.cpp | 252 +++- .../EmulatedUSBDeviceFrame.h | 18 + 10 files changed, 1478 insertions(+), 22 deletions(-) create mode 100644 src/Cafe/OS/libs/nsyshid/Infinity.cpp create mode 100644 src/Cafe/OS/libs/nsyshid/Infinity.h diff --git a/src/Cafe/CMakeLists.txt b/src/Cafe/CMakeLists.txt index 1583bdd7..0fb7a44b 100644 --- a/src/Cafe/CMakeLists.txt +++ b/src/Cafe/CMakeLists.txt @@ -463,6 +463,8 @@ add_library(CemuCafe OS/libs/nsyshid/BackendLibusb.h OS/libs/nsyshid/BackendWindowsHID.cpp OS/libs/nsyshid/BackendWindowsHID.h + OS/libs/nsyshid/Infinity.cpp + OS/libs/nsyshid/Infinity.h OS/libs/nsyshid/Skylander.cpp OS/libs/nsyshid/Skylander.h OS/libs/nsyskbd/nsyskbd.cpp diff --git a/src/Cafe/OS/libs/nsyshid/BackendEmulated.cpp b/src/Cafe/OS/libs/nsyshid/BackendEmulated.cpp index 11a299ed..95eaf06a 100644 --- a/src/Cafe/OS/libs/nsyshid/BackendEmulated.cpp +++ b/src/Cafe/OS/libs/nsyshid/BackendEmulated.cpp @@ -1,4 +1,5 @@ #include "BackendEmulated.h" +#include "Infinity.h" #include "Skylander.h" #include "config/CemuConfig.h" @@ -25,5 +26,12 @@ namespace nsyshid::backend::emulated auto device = std::make_shared(); AttachDevice(device); } + if (GetConfig().emulated_usb_devices.emulate_infinity_base && !FindDeviceById(0x0E6F, 0x0129)) + { + cemuLog_logDebug(LogType::Force, "Attaching Emulated Base"); + // Add Infinity Base + auto device = std::make_shared(); + AttachDevice(device); + } } } // namespace nsyshid::backend::emulated \ No newline at end of file diff --git a/src/Cafe/OS/libs/nsyshid/Infinity.cpp b/src/Cafe/OS/libs/nsyshid/Infinity.cpp new file mode 100644 index 00000000..ab44ef4a --- /dev/null +++ b/src/Cafe/OS/libs/nsyshid/Infinity.cpp @@ -0,0 +1,1102 @@ +#include "Infinity.h" + +#include + +#include "nsyshid.h" +#include "Backend.h" + +#include "util/crypto/aes128.h" + +#include +#include "openssl/sha.h" + +namespace nsyshid +{ + static constexpr std::array SHA1_CONSTANT = { + 0xAF, 0x62, 0xD2, 0xEC, 0x04, 0x91, 0x96, 0x8C, 0xC5, 0x2A, 0x1A, 0x71, 0x65, 0xF8, 0x65, 0xFE, + 0x28, 0x63, 0x29, 0x20, 0x44, 0x69, 0x73, 0x6e, 0x65, 0x79, 0x20, 0x32, 0x30, 0x31, 0x33}; + + InfinityUSB g_infinitybase; + + const std::map> s_listFigures = { + {0x0F4241, {1, "Mr. Incredible"}}, + {0x0F4242, {1, "Sulley"}}, + {0x0F4243, {1, "Jack Sparrow"}}, + {0x0F4244, {1, "Lone Ranger"}}, + {0x0F4245, {1, "Tonto"}}, + {0x0F4246, {1, "Lightning McQueen"}}, + {0x0F4247, {1, "Holley Shiftwell"}}, + {0x0F4248, {1, "Buzz Lightyear"}}, + {0x0F4249, {1, "Jessie"}}, + {0x0F424A, {1, "Mike"}}, + {0x0F424B, {1, "Mrs. Incredible"}}, + {0x0F424C, {1, "Hector Barbossa"}}, + {0x0F424D, {1, "Davy Jones"}}, + {0x0F424E, {1, "Randy"}}, + {0x0F424F, {1, "Syndrome"}}, + {0x0F4250, {1, "Woody"}}, + {0x0F4251, {1, "Mater"}}, + {0x0F4252, {1, "Dash"}}, + {0x0F4253, {1, "Violet"}}, + {0x0F4254, {1, "Francesco Bernoulli"}}, + {0x0F4255, {1, "Sorcerer's Apprentice Mickey"}}, + {0x0F4256, {1, "Jack Skellington"}}, + {0x0F4257, {1, "Rapunzel"}}, + {0x0F4258, {1, "Anna"}}, + {0x0F4259, {1, "Elsa"}}, + {0x0F425A, {1, "Phineas"}}, + {0x0F425B, {1, "Agent P"}}, + {0x0F425C, {1, "Wreck-It Ralph"}}, + {0x0F425D, {1, "Vanellope"}}, + {0x0F425E, {1, "Mr. Incredible (Crystal)"}}, + {0x0F425F, {1, "Jack Sparrow (Crystal)"}}, + {0x0F4260, {1, "Sulley (Crystal)"}}, + {0x0F4261, {1, "Lightning McQueen (Crystal)"}}, + {0x0F4262, {1, "Lone Ranger (Crystal)"}}, + {0x0F4263, {1, "Buzz Lightyear (Crystal)"}}, + {0x0F4264, {1, "Agent P (Crystal)"}}, + {0x0F4265, {1, "Sorcerer's Apprentice Mickey (Crystal)"}}, + {0x0F4266, {1, "Buzz Lightyear (Glowing)"}}, + {0x0F42A4, {2, "Captain America"}}, + {0x0F42A5, {2, "Hulk"}}, + {0x0F42A6, {2, "Iron Man"}}, + {0x0F42A7, {2, "Thor"}}, + {0x0F42A8, {2, "Groot"}}, + {0x0F42A9, {2, "Rocket Raccoon"}}, + {0x0F42AA, {2, "Star-Lord"}}, + {0x0F42AB, {2, "Spider-Man"}}, + {0x0F42AC, {2, "Nick Fury"}}, + {0x0F42AD, {2, "Black Widow"}}, + {0x0F42AE, {2, "Hawkeye"}}, + {0x0F42AF, {2, "Drax"}}, + {0x0F42B0, {2, "Gamora"}}, + {0x0F42B1, {2, "Iron Fist"}}, + {0x0F42B2, {2, "Nova"}}, + {0x0F42B3, {2, "Venom"}}, + {0x0F42B4, {2, "Donald Duck"}}, + {0x0F42B5, {2, "Aladdin"}}, + {0x0F42B6, {2, "Stitch"}}, + {0x0F42B7, {2, "Merida"}}, + {0x0F42B8, {2, "Tinker Bell"}}, + {0x0F42B9, {2, "Maleficent"}}, + {0x0F42BA, {2, "Hiro"}}, + {0x0F42BB, {2, "Baymax"}}, + {0x0F42BC, {2, "Loki"}}, + {0x0F42BD, {2, "Ronan"}}, + {0x0F42BE, {2, "Green Goblin"}}, + {0x0F42BF, {2, "Falcon"}}, + {0x0F42C0, {2, "Yondu"}}, + {0x0F42C1, {2, "Jasmine"}}, + {0x0F42C6, {2, "Black Suit Spider-Man"}}, + {0x0F42D6, {3, "Sam Flynn"}}, + {0x0F42D7, {3, "Quorra"}}, + {0x0F4308, {3, "Anakin Skywalker"}}, + {0x0F4309, {3, "Obi-Wan Kenobi"}}, + {0x0F430A, {3, "Yoda"}}, + {0x0F430B, {3, "Ahsoka Tano"}}, + {0x0F430C, {3, "Darth Maul"}}, + {0x0F430E, {3, "Luke Skywalker"}}, + {0x0F430F, {3, "Han Solo"}}, + {0x0F4310, {3, "Princess Leia"}}, + {0x0F4311, {3, "Chewbacca"}}, + {0x0F4312, {3, "Darth Vader"}}, + {0x0F4313, {3, "Boba Fett"}}, + {0x0F4314, {3, "Ezra Bridger"}}, + {0x0F4315, {3, "Kanan Jarrus"}}, + {0x0F4316, {3, "Sabine Wren"}}, + {0x0F4317, {3, "Zeb Orrelios"}}, + {0x0F4318, {3, "Joy"}}, + {0x0F4319, {3, "Anger"}}, + {0x0F431A, {3, "Fear"}}, + {0x0F431B, {3, "Sadness"}}, + {0x0F431C, {3, "Disgust"}}, + {0x0F431D, {3, "Mickey Mouse"}}, + {0x0F431E, {3, "Minnie Mouse"}}, + {0x0F431F, {3, "Mulan"}}, + {0x0F4320, {3, "Olaf"}}, + {0x0F4321, {3, "Vision"}}, + {0x0F4322, {3, "Ultron"}}, + {0x0F4323, {3, "Ant-Man"}}, + {0x0F4325, {3, "Captain America - The First Avenger"}}, + {0x0F4326, {3, "Finn"}}, + {0x0F4327, {3, "Kylo Ren"}}, + {0x0F4328, {3, "Poe Dameron"}}, + {0x0F4329, {3, "Rey"}}, + {0x0F432B, {3, "Spot"}}, + {0x0F432C, {3, "Nick Wilde"}}, + {0x0F432D, {3, "Judy Hopps"}}, + {0x0F432E, {3, "Hulkbuster"}}, + {0x0F432F, {3, "Anakin Skywalker (Light FX)"}}, + {0x0F4330, {3, "Obi-Wan Kenobi (Light FX)"}}, + {0x0F4331, {3, "Yoda (Light FX)"}}, + {0x0F4332, {3, "Luke Skywalker (Light FX)"}}, + {0x0F4333, {3, "Darth Vader (Light FX)"}}, + {0x0F4334, {3, "Kanan Jarrus (Light FX)"}}, + {0x0F4335, {3, "Kylo Ren (Light FX)"}}, + {0x0F4336, {3, "Black Panther"}}, + {0x0F436C, {3, "Nemo"}}, + {0x0F436D, {3, "Dory"}}, + {0x0F436E, {3, "Baloo"}}, + {0x0F436F, {3, "Alice"}}, + {0x0F4370, {3, "Mad Hatter"}}, + {0x0F4371, {3, "Time"}}, + {0x0F4372, {3, "Peter Pan"}}, + {0x1E8481, {1, "Starter Play Set"}}, + {0x1E8482, {1, "Lone Ranger Play Set"}}, + {0x1E8483, {1, "Cars Play Set"}}, + {0x1E8484, {1, "Toy Story in Space Play Set"}}, + {0x1E84E4, {2, "Marvel's The Avengers Play Set"}}, + {0x1E84E5, {2, "Marvel's Spider-Man Play Set"}}, + {0x1E84E6, {2, "Marvel's Guardians of the Galaxy Play Set"}}, + {0x1E84E7, {2, "Assault on Asgard"}}, + {0x1E84E8, {2, "Escape from the Kyln"}}, + {0x1E84E9, {2, "Stitch's Tropical Rescue"}}, + {0x1E84EA, {2, "Brave Forest Siege"}}, + {0x1E8548, {3, "Inside Out Play Set"}}, + {0x1E8549, {3, "Star Wars: Twilight of the Republic Play Set"}}, + {0x1E854A, {3, "Star Wars: Rise Against the Empire Play Set"}}, + {0x1E854B, {3, "Star Wars: The Force Awakens Play Set"}}, + {0x1E854C, {3, "Marvel Battlegrounds Play Set"}}, + {0x1E854D, {3, "Toy Box Speedway"}}, + {0x1E854E, {3, "Toy Box Takeover"}}, + {0x1E85AC, {3, "Finding Dory Play Set"}}, + {0x2DC6C3, {1, "Bolt's Super Strength"}}, + {0x2DC6C4, {1, "Ralph's Power of Destruction"}}, + {0x2DC6C5, {1, "Chernabog's Power"}}, + {0x2DC6C6, {1, "C.H.R.O.M.E. Damage Increaser"}}, + {0x2DC6C7, {1, "Dr. Doofenshmirtz's Damage-Inator!"}}, + {0x2DC6C8, {1, "Electro-Charge"}}, + {0x2DC6C9, {1, "Fix-It Felix's Repair Power"}}, + {0x2DC6CA, {1, "Rapunzel's Healing"}}, + {0x2DC6CB, {1, "C.H.R.O.M.E. Armor Shield"}}, + {0x2DC6CC, {1, "Star Command Shield"}}, + {0x2DC6CD, {1, "Violet's Force Field"}}, + {0x2DC6CE, {1, "Pieces of Eight"}}, + {0x2DC6CF, {1, "Scrooge McDuck's Lucky Dime"}}, + {0x2DC6D0, {1, "User Control"}}, + {0x2DC6D1, {1, "Sorcerer Mickey's Hat"}}, + {0x2DC6FE, {1, "Emperor Zurg's Wrath"}}, + {0x2DC6FF, {1, "Merlin's Summon"}}, + {0x2DC765, {2, "Enchanted Rose"}}, + {0x2DC766, {2, "Mulan's Training Uniform"}}, + {0x2DC767, {2, "Flubber"}}, + {0x2DC768, {2, "S.H.I.E.L.D. Helicarrier Strike"}}, + {0x2DC769, {2, "Zeus' Thunderbolts"}}, + {0x2DC76A, {2, "King Louie's Monkeys"}}, + {0x2DC76B, {2, "Infinity Gauntlet"}}, + {0x2DC76D, {2, "Sorcerer Supreme"}}, + {0x2DC76E, {2, "Maleficent's Spell Cast"}}, + {0x2DC76F, {2, "Chernabog's Spirit Cyclone"}}, + {0x2DC770, {2, "Marvel Team-Up: Capt. Marvel"}}, + {0x2DC771, {2, "Marvel Team-Up: Iron Patriot"}}, + {0x2DC772, {2, "Marvel Team-Up: Ant-Man"}}, + {0x2DC773, {2, "Marvel Team-Up: White Tiger"}}, + {0x2DC774, {2, "Marvel Team-Up: Yondu"}}, + {0x2DC775, {2, "Marvel Team-Up: Winter Soldier"}}, + {0x2DC776, {2, "Stark Arc Reactor"}}, + {0x2DC777, {2, "Gamma Rays"}}, + {0x2DC778, {2, "Alien Symbiote"}}, + {0x2DC779, {2, "All for One"}}, + {0x2DC77A, {2, "Sandy Claws Surprise"}}, + {0x2DC77B, {2, "Glory Days"}}, + {0x2DC77C, {2, "Cursed Pirate Gold"}}, + {0x2DC77D, {2, "Sentinel of Liberty"}}, + {0x2DC77E, {2, "The Immortal Iron Fist"}}, + {0x2DC77F, {2, "Space Armor"}}, + {0x2DC780, {2, "Rags to Riches"}}, + {0x2DC781, {2, "Ultimate Falcon"}}, + {0x2DC788, {3, "Tomorrowland Time Bomb"}}, + {0x2DC78E, {3, "Galactic Team-Up: Mace Windu"}}, + {0x2DC791, {3, "Luke's Rebel Alliance Flight Suit Costume"}}, + {0x2DC798, {3, "Finn's Stormtrooper Costume"}}, + {0x2DC799, {3, "Poe's Resistance Jacket"}}, + {0x2DC79A, {3, "Resistance Tactical Strike"}}, + {0x2DC79E, {3, "Officer Nick Wilde"}}, + {0x2DC79F, {3, "Meter Maid Judy"}}, + {0x2DC7A2, {3, "Darkhawk's Blast"}}, + {0x2DC7A3, {3, "Cosmic Cube Blast"}}, + {0x2DC7A4, {3, "Princess Leia's Boushh Disguise"}}, + {0x2DC7A6, {3, "Nova Corps Strike"}}, + {0x2DC7A7, {3, "King Mickey"}}, + {0x3D0912, {1, "Mickey's Car"}}, + {0x3D0913, {1, "Cinderella's Coach"}}, + {0x3D0914, {1, "Electric Mayhem Bus"}}, + {0x3D0915, {1, "Cruella De Vil's Car"}}, + {0x3D0916, {1, "Pizza Planet Delivery Truck"}}, + {0x3D0917, {1, "Mike's New Car"}}, + {0x3D0919, {1, "Parking Lot Tram"}}, + {0x3D091A, {1, "Captain Hook's Ship"}}, + {0x3D091B, {1, "Dumbo"}}, + {0x3D091C, {1, "Calico Helicopter"}}, + {0x3D091D, {1, "Maximus"}}, + {0x3D091E, {1, "Angus"}}, + {0x3D091F, {1, "Abu the Elephant"}}, + {0x3D0920, {1, "Headless Horseman's Horse"}}, + {0x3D0921, {1, "Phillipe"}}, + {0x3D0922, {1, "Khan"}}, + {0x3D0923, {1, "Tantor"}}, + {0x3D0924, {1, "Dragon Firework Cannon"}}, + {0x3D0925, {1, "Stitch's Blaster"}}, + {0x3D0926, {1, "Toy Story Mania Blaster"}}, + {0x3D0927, {1, "Flamingo Croquet Mallet"}}, + {0x3D0928, {1, "Carl Fredricksen's Cane"}}, + {0x3D0929, {1, "Hangin' Ten Stitch With Surfboard"}}, + {0x3D092A, {1, "Condorman Glider"}}, + {0x3D092B, {1, "WALL-E's Fire Extinguisher"}}, + {0x3D092C, {1, "On the Grid"}}, + {0x3D092D, {1, "WALL-E's Collection"}}, + {0x3D092E, {1, "King Candy's Dessert Toppings"}}, + {0x3D0930, {1, "Victor's Experiments"}}, + {0x3D0931, {1, "Jack's Scary Decorations"}}, + {0x3D0933, {1, "Frozen Flourish"}}, + {0x3D0934, {1, "Rapunzel's Kingdom"}}, + {0x3D0935, {1, "TRON Interface"}}, + {0x3D0936, {1, "Buy N Large Atmosphere"}}, + {0x3D0937, {1, "Sugar Rush Sky"}}, + {0x3D0939, {1, "New Holland Skyline"}}, + {0x3D093A, {1, "Halloween Town Sky"}}, + {0x3D093C, {1, "Chill in the Air"}}, + {0x3D093D, {1, "Rapunzel's Birthday Sky"}}, + {0x3D0940, {1, "Astro Blasters Space Cruiser"}}, + {0x3D0941, {1, "Marlin's Reef"}}, + {0x3D0942, {1, "Nemo's Seascape"}}, + {0x3D0943, {1, "Alice's Wonderland"}}, + {0x3D0944, {1, "Tulgey Wood"}}, + {0x3D0945, {1, "Tri-State Area Terrain"}}, + {0x3D0946, {1, "Danville Sky"}}, + {0x3D0965, {2, "Stark Tech"}}, + {0x3D0966, {2, "Spider-Streets"}}, + {0x3D0967, {2, "World War Hulk"}}, + {0x3D0968, {2, "Gravity Falls Forest"}}, + {0x3D0969, {2, "Neverland"}}, + {0x3D096A, {2, "Simba's Pridelands"}}, + {0x3D096C, {2, "Calhoun's Command"}}, + {0x3D096D, {2, "Star-Lord's Galaxy"}}, + {0x3D096E, {2, "Dinosaur World"}}, + {0x3D096F, {2, "Groot's Roots"}}, + {0x3D0970, {2, "Mulan's Countryside"}}, + {0x3D0971, {2, "The Sands of Agrabah"}}, + {0x3D0974, {2, "A Small World"}}, + {0x3D0975, {2, "View from the Suit"}}, + {0x3D0976, {2, "Spider-Sky"}}, + {0x3D0977, {2, "World War Hulk Sky"}}, + {0x3D0978, {2, "Gravity Falls Sky"}}, + {0x3D0979, {2, "Second Star to the Right"}}, + {0x3D097A, {2, "The King's Domain"}}, + {0x3D097C, {2, "CyBug Swarm"}}, + {0x3D097D, {2, "The Rip"}}, + {0x3D097E, {2, "Forgotten Skies"}}, + {0x3D097F, {2, "Groot's View"}}, + {0x3D0980, {2, "The Middle Kingdom"}}, + {0x3D0984, {2, "Skies of the World"}}, + {0x3D0985, {2, "S.H.I.E.L.D. Containment Truck"}}, + {0x3D0986, {2, "Main Street Electrical Parade Float"}}, + {0x3D0987, {2, "Mr. Toad's Motorcar"}}, + {0x3D0988, {2, "Le Maximum"}}, + {0x3D0989, {2, "Alice in Wonderland's Caterpillar"}}, + {0x3D098A, {2, "Eglantine's Motorcycle"}}, + {0x3D098B, {2, "Medusa's Swamp Mobile"}}, + {0x3D098C, {2, "Hydra Motorcycle"}}, + {0x3D098D, {2, "Darkwing Duck's Ratcatcher"}}, + {0x3D098F, {2, "The USS Swinetrek"}}, + {0x3D0991, {2, "Spider-Copter"}}, + {0x3D0992, {2, "Aerial Area Rug"}}, + {0x3D0993, {2, "Jack-O-Lantern's Glider"}}, + {0x3D0994, {2, "Spider-Buggy"}}, + {0x3D0995, {2, "Jack Skellington's Reindeer"}}, + {0x3D0996, {2, "Fantasyland Carousel Horse"}}, + {0x3D0997, {2, "Odin's Horse"}}, + {0x3D0998, {2, "Gus the Mule"}}, + {0x3D099A, {2, "Darkwing Duck's Grappling Gun"}}, + {0x3D099C, {2, "Ghost Rider's Chain Whip"}}, + {0x3D099D, {2, "Lew Zealand's Boomerang Fish"}}, + {0x3D099E, {2, "Sergeant Calhoun's Blaster"}}, + {0x3D09A0, {2, "Falcon's Wings"}}, + {0x3D09A1, {2, "Mabel's Kittens for Fists"}}, + {0x3D09A2, {2, "Jim Hawkins' Solar Board"}}, + {0x3D09A3, {2, "Black Panther's Vibranium Knives"}}, + {0x3D09A4, {2, "Cloak of Levitation"}}, + {0x3D09A5, {2, "Aladdin's Magic Carpet"}}, + {0x3D09A6, {2, "Honey Lemon's Ice Capsules"}}, + {0x3D09A7, {2, "Jasmine's Palace View"}}, + {0x3D09C1, {2, "Lola"}}, + {0x3D09C2, {2, "Spider-Cycle"}}, + {0x3D09C3, {2, "The Avenjet"}}, + {0x3D09C4, {2, "Spider-Glider"}}, + {0x3D09C5, {2, "Light Cycle"}}, + {0x3D09C6, {2, "Light Jet"}}, + {0x3D09C9, {3, "Retro Ray Gun"}}, + {0x3D09CA, {3, "Tomorrowland Futurescape"}}, + {0x3D09CB, {3, "Tomorrowland Stratosphere"}}, + {0x3D09CC, {3, "Skies Over Felucia"}}, + {0x3D09CD, {3, "Forests of Felucia"}}, + {0x3D09CF, {3, "General Grievous' Wheel Bike"}}, + {0x3D09D2, {3, "Slave I Flyer"}}, + {0x3D09D3, {3, "Y-Wing Fighter"}}, + {0x3D09D4, {3, "Arlo"}}, + {0x3D09D5, {3, "Nash"}}, + {0x3D09D6, {3, "Butch"}}, + {0x3D09D7, {3, "Ramsey"}}, + {0x3D09DC, {3, "Stars Over Sahara Square"}}, + {0x3D09DD, {3, "Sahara Square Sands"}}, + {0x3D09E0, {3, "Ghost Rider's Motorcycle"}}, + {0x3D09E5, {3, "Quad Jumper"}}}; + + InfinityBaseDevice::InfinityBaseDevice() + : Device(0x0E6F, 0x0129, 1, 2, 0) + { + m_IsOpened = false; + } + + bool InfinityBaseDevice::Open() + { + if (!IsOpened()) + { + m_IsOpened = true; + } + return true; + } + + void InfinityBaseDevice::Close() + { + if (IsOpened()) + { + m_IsOpened = false; + } + } + + bool InfinityBaseDevice::IsOpened() + { + return m_IsOpened; + } + + Device::ReadResult InfinityBaseDevice::Read(ReadMessage* message) + { + memcpy(message->data, g_infinitybase.GetStatus().data(), message->length); + message->bytesRead = message->length; + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + return Device::ReadResult::Success; + } + + Device::WriteResult InfinityBaseDevice::Write(WriteMessage* message) + { + g_infinitybase.SendCommand(message->data, message->length); + message->bytesWritten = message->length; + return Device::WriteResult::Success; + } + + bool InfinityBaseDevice::GetDescriptor(uint8 descType, + uint8 descIndex, + uint8 lang, + uint8* output, + uint32 outputMaxLength) + { + uint8 configurationDescriptor[0x29]; + + uint8* currentWritePtr; + + // configuration descriptor + currentWritePtr = configurationDescriptor + 0; + *(uint8*)(currentWritePtr + 0) = 9; // bLength + *(uint8*)(currentWritePtr + 1) = 2; // bDescriptorType + *(uint16be*)(currentWritePtr + 2) = 0x0029; // wTotalLength + *(uint8*)(currentWritePtr + 4) = 1; // bNumInterfaces + *(uint8*)(currentWritePtr + 5) = 1; // bConfigurationValue + *(uint8*)(currentWritePtr + 6) = 0; // iConfiguration + *(uint8*)(currentWritePtr + 7) = 0x80; // bmAttributes + *(uint8*)(currentWritePtr + 8) = 0xFA; // MaxPower + currentWritePtr = currentWritePtr + 9; + // configuration descriptor + *(uint8*)(currentWritePtr + 0) = 9; // bLength + *(uint8*)(currentWritePtr + 1) = 0x04; // bDescriptorType + *(uint8*)(currentWritePtr + 2) = 0; // bInterfaceNumber + *(uint8*)(currentWritePtr + 3) = 0; // bAlternateSetting + *(uint8*)(currentWritePtr + 4) = 2; // bNumEndpoints + *(uint8*)(currentWritePtr + 5) = 3; // bInterfaceClass + *(uint8*)(currentWritePtr + 6) = 0; // bInterfaceSubClass + *(uint8*)(currentWritePtr + 7) = 0; // bInterfaceProtocol + *(uint8*)(currentWritePtr + 8) = 0; // iInterface + currentWritePtr = currentWritePtr + 9; + // configuration descriptor + *(uint8*)(currentWritePtr + 0) = 9; // bLength + *(uint8*)(currentWritePtr + 1) = 0x21; // bDescriptorType + *(uint16be*)(currentWritePtr + 2) = 0x0111; // bcdHID + *(uint8*)(currentWritePtr + 4) = 0x00; // bCountryCode + *(uint8*)(currentWritePtr + 5) = 0x01; // bNumDescriptors + *(uint8*)(currentWritePtr + 6) = 0x22; // bDescriptorType + *(uint16be*)(currentWritePtr + 7) = 0x001D; // wDescriptorLength + currentWritePtr = currentWritePtr + 9; + // endpoint descriptor 1 + *(uint8*)(currentWritePtr + 0) = 7; // bLength + *(uint8*)(currentWritePtr + 1) = 0x05; // bDescriptorType + *(uint8*)(currentWritePtr + 2) = 0x81; // bEndpointAddress + *(uint8*)(currentWritePtr + 3) = 0x03; // bmAttributes + *(uint16be*)(currentWritePtr + 4) = 0x40; // wMaxPacketSize + *(uint8*)(currentWritePtr + 6) = 0x01; // bInterval + currentWritePtr = currentWritePtr + 7; + // endpoint descriptor 2 + *(uint8*)(currentWritePtr + 0) = 7; // bLength + *(uint8*)(currentWritePtr + 1) = 0x05; // bDescriptorType + *(uint8*)(currentWritePtr + 1) = 0x02; // bEndpointAddress + *(uint8*)(currentWritePtr + 2) = 0x03; // bmAttributes + *(uint16be*)(currentWritePtr + 3) = 0x40; // wMaxPacketSize + *(uint8*)(currentWritePtr + 5) = 0x01; // bInterval + currentWritePtr = currentWritePtr + 7; + + cemu_assert_debug((currentWritePtr - configurationDescriptor) == 0x29); + + memcpy(output, configurationDescriptor, + std::min(outputMaxLength, sizeof(configurationDescriptor))); + return true; + } + + bool InfinityBaseDevice::SetProtocol(uint8 ifIndex, uint8 protocol) + { + return true; + } + + bool InfinityBaseDevice::SetReport(ReportMessage* message) + { + return true; + } + + std::array InfinityUSB::GetStatus() + { + std::array response = {}; + + bool responded = false; + + do + { + if (!m_figureAddedRemovedResponses.empty()) + { + memcpy(response.data(), m_figureAddedRemovedResponses.front().data(), + 0x20); + m_figureAddedRemovedResponses.pop(); + responded = true; + } + else if (!m_queries.empty()) + { + memcpy(response.data(), m_queries.front().data(), 0x20); + m_queries.pop(); + responded = true; + } + else + { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + /* code */ + } + while (!responded); + + return response; + } + + void InfinityUSB::SendCommand(uint8* buf, sint32 originalLength) + { + const uint8 command = buf[2]; + const uint8 sequence = buf[3]; + + std::array q_result{}; + + switch (command) + { + case 0x80: + { + q_result = {0xaa, 0x15, 0x00, 0x00, 0x0f, 0x01, 0x00, 0x03, + 0x02, 0x09, 0x09, 0x43, 0x20, 0x32, 0x62, 0x36, + 0x36, 0x4b, 0x34, 0x99, 0x67, 0x31, 0x93, 0x8c}; + break; + } + case 0x81: + { + // Initiate Challenge + g_infinitybase.DescrambleAndSeed(buf, sequence, q_result); + break; + } + case 0x83: + { + // Challenge Response + g_infinitybase.GetNextAndScramble(sequence, q_result); + break; + } + case 0x90: + case 0x92: + case 0x93: + case 0x95: + case 0x96: + { + // Color commands + g_infinitybase.GetBlankResponse(sequence, q_result); + break; + } + case 0xA1: + { + // Get Present Figures + g_infinitybase.GetPresentFigures(sequence, q_result); + break; + } + case 0xA2: + { + // Read Block from Figure + g_infinitybase.QueryBlock(buf[4], buf[5], q_result, sequence); + break; + } + case 0xA3: + { + // Write block to figure + g_infinitybase.WriteBlock(buf[4], buf[5], &buf[7], q_result, sequence); + break; + } + case 0xB4: + { + // Get figure ID + g_infinitybase.GetFigureIdentifier(buf[4], sequence, q_result); + break; + } + case 0xB5: + { + // Get status? + g_infinitybase.GetBlankResponse(sequence, q_result); + break; + } + default: + cemu_assert_error(); + break; + } + + m_queries.push(q_result); + } + + uint8 InfinityUSB::GenerateChecksum(const std::array& data, + int numOfBytes) const + { + int checksum = 0; + for (int i = 0; i < numOfBytes; i++) + { + checksum += data[i]; + } + return (checksum & 0xFF); + } + + void InfinityUSB::GetBlankResponse(uint8 sequence, + std::array& replyBuf) + { + replyBuf[0] = 0xaa; + replyBuf[1] = 0x01; + replyBuf[2] = sequence; + replyBuf[3] = GenerateChecksum(replyBuf, 3); + } + + void InfinityUSB::DescrambleAndSeed(uint8* buf, uint8 sequence, + std::array& replyBuf) + { + uint64 value = uint64(buf[4]) << 56 | uint64(buf[5]) << 48 | + uint64(buf[6]) << 40 | uint64(buf[7]) << 32 | + uint64(buf[8]) << 24 | uint64(buf[9]) << 16 | + uint64(buf[10]) << 8 | uint64(buf[11]); + uint32 seed = Descramble(value); + GenerateSeed(seed); + GetBlankResponse(sequence, replyBuf); + } + + void InfinityUSB::GetNextAndScramble(uint8 sequence, + std::array& replyBuf) + { + const uint32 nextRandom = GetNext(); + const uint64 scrambledNextRandom = Scramble(nextRandom, 0); + replyBuf = {0xAA, 0x09, sequence}; + replyBuf[3] = uint8((scrambledNextRandom >> 56) & 0xFF); + replyBuf[4] = uint8((scrambledNextRandom >> 48) & 0xFF); + replyBuf[5] = uint8((scrambledNextRandom >> 40) & 0xFF); + replyBuf[6] = uint8((scrambledNextRandom >> 32) & 0xFF); + replyBuf[7] = uint8((scrambledNextRandom >> 24) & 0xFF); + replyBuf[8] = uint8((scrambledNextRandom >> 16) & 0xFF); + replyBuf[9] = uint8((scrambledNextRandom >> 8) & 0xFF); + replyBuf[10] = uint8(scrambledNextRandom & 0xFF); + replyBuf[11] = GenerateChecksum(replyBuf, 11); + } + + uint32 InfinityUSB::Descramble(uint64 numToDescramble) + { + uint64 mask = 0x8E55AA1B3999E8AA; + uint32 ret = 0; + + for (int i = 0; i < 64; i++) + { + if (mask & 0x8000000000000000) + { + ret = (ret << 1) | (numToDescramble & 0x01); + } + + numToDescramble >>= 1; + mask <<= 1; + } + + return ret; + } + + uint64 InfinityUSB::Scramble(uint32 numToScramble, uint32 garbage) + { + uint64 mask = 0x8E55AA1B3999E8AA; + uint64 ret = 0; + + for (int i = 0; i < 64; i++) + { + ret <<= 1; + + if ((mask & 1) != 0) + { + ret |= (numToScramble & 1); + numToScramble >>= 1; + } + else + { + ret |= (garbage & 1); + garbage >>= 1; + } + + mask >>= 1; + } + + return ret; + } + + void InfinityUSB::GenerateSeed(uint32 seed) + { + m_randomA = 0xF1EA5EED; + m_randomB = seed; + m_randomC = seed; + m_randomD = seed; + + for (int i = 0; i < 23; i++) + { + GetNext(); + } + } + + uint32 InfinityUSB::GetNext() + { + uint32 a = m_randomA; + uint32 b = m_randomB; + uint32 c = m_randomC; + uint32 ret = std::rotl(m_randomB, 27); + + const uint32 temp = (a + ((ret ^ 0xFFFFFFFF) + 1)); + b ^= std::rotl(c, 17); + a = m_randomD; + c += a; + ret = b + temp; + a += temp; + + m_randomC = a; + m_randomA = b; + m_randomB = c; + m_randomD = ret; + + return ret; + } + + void InfinityUSB::GetPresentFigures(uint8 sequence, + std::array& replyBuf) + { + int x = 3; + for (uint8 i = 0; i < m_figures.size(); i++) + { + uint8 slot = i == 0 ? 0x10 : (i < 4) ? 0x20 + : 0x30; + if (m_figures[i].present) + { + replyBuf[x] = slot + m_figures[i].orderAdded; + replyBuf[x + 1] = 0x09; + x += 2; + } + } + replyBuf[0] = 0xaa; + replyBuf[1] = x - 2; + replyBuf[2] = sequence; + replyBuf[x] = GenerateChecksum(replyBuf, x); + } + + InfinityUSB::InfinityFigure& + InfinityUSB::GetFigureByOrder(uint8 orderAdded) + { + for (uint8 i = 0; i < m_figures.size(); i++) + { + if (m_figures[i].orderAdded == orderAdded) + { + return m_figures[i]; + } + } + return m_figures[0]; + } + + void InfinityUSB::QueryBlock(uint8 fig_num, uint8 block, + std::array& replyBuf, + uint8 sequence) + { + std::lock_guard lock(m_infinityMutex); + + InfinityFigure& figure = GetFigureByOrder(fig_num); + + replyBuf[0] = 0xaa; + replyBuf[1] = 0x12; + replyBuf[2] = sequence; + replyBuf[3] = 0x00; + const uint8 file_block = (block == 0) ? 1 : (block * 4); + if (figure.present && file_block < 20) + { + memcpy(&replyBuf[4], figure.data.data() + (16 * file_block), 16); + } + replyBuf[20] = GenerateChecksum(replyBuf, 20); + } + + void InfinityUSB::WriteBlock(uint8 fig_num, uint8 block, + const uint8* to_write_buf, + std::array& replyBuf, + uint8 sequence) + { + std::lock_guard lock(m_infinityMutex); + + InfinityFigure& figure = GetFigureByOrder(fig_num); + + replyBuf[0] = 0xaa; + replyBuf[1] = 0x02; + replyBuf[2] = sequence; + replyBuf[3] = 0x00; + const uint8 file_block = (block == 0) ? 1 : (block * 4); + if (figure.present && file_block < 20) + { + memcpy(figure.data.data() + (file_block * 16), to_write_buf, 16); + figure.Save(); + } + replyBuf[4] = GenerateChecksum(replyBuf, 4); + } + + void InfinityUSB::GetFigureIdentifier(uint8 fig_num, uint8 sequence, + std::array& replyBuf) + { + std::lock_guard lock(m_infinityMutex); + + InfinityFigure& figure = GetFigureByOrder(fig_num); + + replyBuf[0] = 0xaa; + replyBuf[1] = 0x09; + replyBuf[2] = sequence; + replyBuf[3] = 0x00; + + if (figure.present) + { + memcpy(&replyBuf[4], figure.data.data(), 7); + } + replyBuf[11] = GenerateChecksum(replyBuf, 11); + } + + std::pair InfinityUSB::FindFigure(uint32 figNum) + { + for (const auto& it : GetFigureList()) + { + if (it.first == figNum) + { + return it.second; + } + } + return {0, fmt::format("Unknown Figure ({})", figNum)}; + } + + std::map> InfinityUSB::GetFigureList() + { + return s_listFigures; + } + + void InfinityUSB::InfinityFigure::Save() + { + if (!infFile) + return; + + infFile->SetPosition(0); + infFile->writeData(data.data(), data.size()); + } + + bool InfinityUSB::RemoveFigure(uint8 position) + { + std::lock_guard lock(m_infinityMutex); + InfinityFigure& figure = m_figures[position]; + + figure.Save(); + figure.infFile.reset(); + + if (figure.present) + { + figure.present = false; + + position = DeriveFigurePosition(position); + if (position == 0) + { + return false; + } + + std::array figureChangeResponse = {0xab, 0x04, position, 0x09, figure.orderAdded, + 0x01}; + figureChangeResponse[6] = GenerateChecksum(figureChangeResponse, 6); + m_figureAddedRemovedResponses.push(figureChangeResponse); + + return true; + } + return false; + } + + uint32 + InfinityUSB::LoadFigure(const std::array& buf, + std::unique_ptr inFile, uint8 position) + { + std::lock_guard lock(m_infinityMutex); + uint8 orderAdded; + + std::vector sha1Calc = {SHA1_CONSTANT.begin(), SHA1_CONSTANT.end() - 1}; + for (int i = 0; i < 7; i++) + { + sha1Calc.push_back(buf[i]); + } + + std::array key = GenerateInfinityFigureKey(sha1Calc); + + std::array infinity_decrypted_block = {}; + std::array encryptedBlock = {}; + memcpy(encryptedBlock.data(), &buf[16], 16); + + AES128_ECB_decrypt(encryptedBlock.data(), key.data(), infinity_decrypted_block.data()); + + uint32 number = uint32(infinity_decrypted_block[1]) << 16 | uint32(infinity_decrypted_block[2]) << 8 | + uint32(infinity_decrypted_block[3]); + + InfinityFigure& figure = m_figures[position]; + + figure.infFile = std::move(inFile); + memcpy(figure.data.data(), buf.data(), figure.data.size()); + figure.present = true; + if (figure.orderAdded == 255) + { + figure.orderAdded = m_figureOrder; + m_figureOrder++; + } + orderAdded = figure.orderAdded; + + position = DeriveFigurePosition(position); + if (position == 0) + { + return 0; + } + + std::array figureChangeResponse = {0xab, 0x04, position, 0x09, orderAdded, 0x00}; + figureChangeResponse[6] = GenerateChecksum(figureChangeResponse, 6); + m_figureAddedRemovedResponses.push(figureChangeResponse); + + return number; + } + + static uint32 InfinityCRC32(const std::array& buffer) + { + static constexpr std::array CRC32_TABLE{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, + 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, + 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, + 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, + 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, + 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, + 0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, + 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, + 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, + 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, + 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, + 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, + 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, + 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, + 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, + 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, + 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, + 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, + 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, + 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, + 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, + 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, + 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, + 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, + 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d}; + + // Infinity m_figures calculate their CRC32 based on 12 bytes in the block of 16 + uint32 ret = 0; + for (uint32 i = 0; i < 12; ++i) + { + uint8 index = uint8(ret & 0xFF) ^ buffer[i]; + ret = ((ret >> 8) ^ CRC32_TABLE[index]); + } + + return ret; + } + + bool InfinityUSB::CreateFigure(fs::path pathName, uint32 figureNum, uint8 series) + { + FileStream* infFile(FileStream::createFile2(pathName)); + if (!infFile) + { + return false; + } + std::array fileData{}; + uint32 firstBlock = 0x17878E; + uint32 otherBlocks = 0x778788; + for (sint8 i = 2; i >= 0; i--) + { + fileData[0x38 - i] = uint8((firstBlock >> i * 8) & 0xFF); + } + for (uint32 index = 1; index < 0x05; index++) + { + for (sint8 i = 2; i >= 0; i--) + { + fileData[((index * 0x40) + 0x38) - i] = uint8((otherBlocks >> i * 8) & 0xFF); + } + } + // Create the vector to calculate the SHA1 hash with + std::vector sha1Calc = {SHA1_CONSTANT.begin(), SHA1_CONSTANT.end() - 1}; + + // Generate random UID, used for AES encrypt/decrypt + std::random_device rd; + std::mt19937 mt(rd()); + std::uniform_int_distribution dist(0, 255); + std::array uid_data = {0, 0, 0, 0, 0, 0, 0, 0x89, 0x44, 0x00, 0xC2}; + uid_data[0] = dist(mt); + uid_data[1] = dist(mt); + uid_data[2] = dist(mt); + uid_data[3] = dist(mt); + uid_data[4] = dist(mt); + uid_data[5] = dist(mt); + uid_data[6] = dist(mt); + for (sint8 i = 0; i < 7; i++) + { + sha1Calc.push_back(uid_data[i]); + } + std::array figureData = GenerateBlankFigureData(figureNum, series); + if (figureData[1] == 0x00) + return false; + + std::array key = GenerateInfinityFigureKey(sha1Calc); + + std::array encryptedBlock = {}; + std::array blankBlock = {}; + std::array encryptedBlank = {}; + + AES128_ECB_encrypt(figureData.data(), key.data(), encryptedBlock.data()); + AES128_ECB_encrypt(blankBlock.data(), key.data(), encryptedBlank.data()); + + memcpy(&fileData[0], uid_data.data(), uid_data.size()); + memcpy(&fileData[16], encryptedBlock.data(), encryptedBlock.size()); + memcpy(&fileData[16 * 0x04], encryptedBlank.data(), encryptedBlank.size()); + memcpy(&fileData[16 * 0x08], encryptedBlank.data(), encryptedBlank.size()); + memcpy(&fileData[16 * 0x0C], encryptedBlank.data(), encryptedBlank.size()); + memcpy(&fileData[16 * 0x0D], encryptedBlank.data(), encryptedBlank.size()); + + infFile->writeData(fileData.data(), fileData.size()); + + delete infFile; + + return true; + } + + std::array InfinityUSB::GenerateInfinityFigureKey(const std::vector& sha1Data) + { + std::array digest = {}; + SHA_CTX ctx; + SHA1_Init(&ctx); + SHA1_Update(&ctx, sha1Data.data(), sha1Data.size()); + SHA1_Final(digest.data(), &ctx); + OPENSSL_cleanse(&ctx, sizeof(ctx)); + // Infinity AES keys are the first 16 bytes of the SHA1 Digest, every set of 4 bytes need to be + // reversed due to endianness + std::array key = {}; + for (int i = 0; i < 4; i++) + { + for (int x = 3; x >= 0; x--) + { + key[(3 - x) + (i * 4)] = digest[x + (i * 4)]; + } + } + return key; + } + + std::array InfinityUSB::GenerateBlankFigureData(uint32 figureNum, uint8 series) + { + std::array figureData = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0xD1, 0x1F}; + + // Figure Number, input by end user + figureData[1] = uint8((figureNum >> 16) & 0xFF); + figureData[2] = uint8((figureNum >> 8) & 0xFF); + figureData[3] = uint8(figureNum & 0xFF); + + // Manufacture date, formatted as YY/MM/DD. Set to release date of figure's series + if (series == 1) + { + figureData[4] = 0x0D; + figureData[5] = 0x08; + figureData[6] = 0x12; + } + else if (series == 2) + { + figureData[4] = 0x0E; + figureData[5] = 0x09; + figureData[6] = 0x12; + } + else if (series == 3) + { + figureData[4] = 0x0F; + figureData[5] = 0x08; + figureData[6] = 0x1C; + } + + uint32 checksum = InfinityCRC32(figureData); + for (sint8 i = 3; i >= 0; i--) + { + figureData[15 - i] = uint8((checksum >> i * 8) & 0xFF); + } + return figureData; + } + + uint8 InfinityUSB::DeriveFigurePosition(uint8 position) + { + // In the added/removed response, position needs to be 1 for the hexagon, 2 for Player 1 and + // Player 1's abilities, and 3 for Player 2 and Player 2's abilities. In the UI, positions 0, 1 + // and 2 represent the hexagon slot, 3, 4 and 5 represent Player 1's slot and 6, 7 and 8 represent + // Player 2's slot. + + switch (position) + { + case 0: + case 1: + case 2: + return 1; + case 3: + case 4: + case 5: + return 2; + case 6: + case 7: + case 8: + return 3; + + default: + return 0; + } + } +} // namespace nsyshid \ No newline at end of file diff --git a/src/Cafe/OS/libs/nsyshid/Infinity.h b/src/Cafe/OS/libs/nsyshid/Infinity.h new file mode 100644 index 00000000..aa98fd15 --- /dev/null +++ b/src/Cafe/OS/libs/nsyshid/Infinity.h @@ -0,0 +1,105 @@ +#pragma once + +#include + +#include "nsyshid.h" +#include "Backend.h" + +#include "Common/FileStream.h" + +namespace nsyshid +{ + class InfinityBaseDevice final : public Device { + public: + InfinityBaseDevice(); + ~InfinityBaseDevice() = default; + + bool Open() override; + + void Close() override; + + bool IsOpened() override; + + ReadResult Read(ReadMessage* message) override; + + WriteResult Write(WriteMessage* message) override; + + bool GetDescriptor(uint8 descType, + uint8 descIndex, + uint8 lang, + uint8* output, + uint32 outputMaxLength) override; + + bool SetProtocol(uint8 ifIndex, uint8 protocol) override; + + bool SetReport(ReportMessage* message) override; + + private: + bool m_IsOpened; + }; + + constexpr uint16 INF_BLOCK_COUNT = 0x14; + constexpr uint16 INF_BLOCK_SIZE = 0x10; + constexpr uint16 INF_FIGURE_SIZE = INF_BLOCK_COUNT * INF_BLOCK_SIZE; + constexpr uint8 MAX_FIGURES = 9; + class InfinityUSB { + public: + struct InfinityFigure final + { + std::unique_ptr infFile; + std::array data{}; + bool present = false; + uint8 orderAdded = 255; + void Save(); + }; + + void SendCommand(uint8* buf, sint32 originalLength); + std::array GetStatus(); + + void GetBlankResponse(uint8 sequence, std::array& replyBuf); + void DescrambleAndSeed(uint8* buf, uint8 sequence, + std::array& replyBuf); + void GetNextAndScramble(uint8 sequence, std::array& replyBuf); + void GetPresentFigures(uint8 sequence, std::array& replyBuf); + void QueryBlock(uint8 figNum, uint8 block, std::array& replyBuf, + uint8 sequence); + void WriteBlock(uint8 figNum, uint8 block, const uint8* toWriteBuf, + std::array& replyBuf, uint8 sequence); + void GetFigureIdentifier(uint8 figNum, uint8 sequence, + std::array& replyBuf); + + bool RemoveFigure(uint8 position); + uint32 LoadFigure(const std::array& buf, + std::unique_ptr, uint8 position); + bool CreateFigure(fs::path pathName, uint32 figureNum, uint8 series); + static std::map> GetFigureList(); + std::pair FindFigure(uint32 figNum); + + protected: + std::shared_mutex m_infinityMutex; + std::array m_figures; + + private: + uint8 GenerateChecksum(const std::array& data, + int numOfBytes) const; + uint32 Descramble(uint64 numToDescramble); + uint64 Scramble(uint32 numToScramble, uint32 garbage); + void GenerateSeed(uint32 seed); + uint32 GetNext(); + InfinityFigure& GetFigureByOrder(uint8 orderAdded); + uint8 DeriveFigurePosition(uint8 position); + std::array GenerateInfinityFigureKey(const std::vector& sha1Data); + std::array GenerateBlankFigureData(uint32 figureNum, uint8 series); + + uint32 m_randomA; + uint32 m_randomB; + uint32 m_randomC; + uint32 m_randomD; + + uint8 m_figureOrder = 0; + std::queue> m_figureAddedRemovedResponses; + std::queue> m_queries; + }; + extern InfinityUSB g_infinitybase; + +} // namespace nsyshid \ No newline at end of file diff --git a/src/Cafe/OS/libs/nsyshid/Skylander.cpp b/src/Cafe/OS/libs/nsyshid/Skylander.cpp index 7f17f8a3..a9888787 100644 --- a/src/Cafe/OS/libs/nsyshid/Skylander.cpp +++ b/src/Cafe/OS/libs/nsyshid/Skylander.cpp @@ -855,7 +855,7 @@ namespace nsyshid return false; } - std::array data{}; + std::array data{}; uint32 first_block = 0x690F0F0F; uint32 other_blocks = 0x69080F7F; diff --git a/src/Cafe/OS/libs/nsyshid/Skylander.h b/src/Cafe/OS/libs/nsyshid/Skylander.h index ae8b5d92..95eaff0c 100644 --- a/src/Cafe/OS/libs/nsyshid/Skylander.h +++ b/src/Cafe/OS/libs/nsyshid/Skylander.h @@ -38,9 +38,9 @@ namespace nsyshid bool m_IsOpened; }; - constexpr uint16 BLOCK_COUNT = 0x40; - constexpr uint16 BLOCK_SIZE = 0x10; - constexpr uint16 FIGURE_SIZE = BLOCK_COUNT * BLOCK_SIZE; + constexpr uint16 SKY_BLOCK_COUNT = 0x40; + constexpr uint16 SKY_BLOCK_SIZE = 0x10; + constexpr uint16 SKY_FIGURE_SIZE = SKY_BLOCK_COUNT * SKY_BLOCK_SIZE; constexpr uint8 MAX_SKYLANDERS = 16; class SkylanderUSB { @@ -50,7 +50,7 @@ namespace nsyshid std::unique_ptr skyFile; uint8 status = 0; std::queue queuedStatus; - std::array data{}; + std::array data{}; uint32 lastId = 0; void Save(); diff --git a/src/config/CemuConfig.cpp b/src/config/CemuConfig.cpp index 03b12731..338392dd 100644 --- a/src/config/CemuConfig.cpp +++ b/src/config/CemuConfig.cpp @@ -344,6 +344,7 @@ void CemuConfig::Load(XMLConfigParser& parser) // emulatedusbdevices auto usbdevices = parser.get("EmulatedUsbDevices"); emulated_usb_devices.emulate_skylander_portal = usbdevices.get("EmulateSkylanderPortal", emulated_usb_devices.emulate_skylander_portal); + emulated_usb_devices.emulate_infinity_base = usbdevices.get("EmulateInfinityBase", emulated_usb_devices.emulate_infinity_base); } void CemuConfig::Save(XMLConfigParser& parser) @@ -541,6 +542,7 @@ void CemuConfig::Save(XMLConfigParser& parser) // emulated usb devices auto usbdevices = config.set("EmulatedUsbDevices"); usbdevices.set("EmulateSkylanderPortal", emulated_usb_devices.emulate_skylander_portal.GetValue()); + usbdevices.set("EmulateInfinityBase", emulated_usb_devices.emulate_infinity_base.GetValue()); } GameEntry* CemuConfig::GetGameEntryByTitleId(uint64 titleId) diff --git a/src/config/CemuConfig.h b/src/config/CemuConfig.h index 3f3da953..2a1d29cb 100644 --- a/src/config/CemuConfig.h +++ b/src/config/CemuConfig.h @@ -519,6 +519,7 @@ struct CemuConfig struct { ConfigValue emulate_skylander_portal{false}; + ConfigValue emulate_infinity_base{true}; }emulated_usb_devices{}; private: diff --git a/src/gui/EmulatedUSBDevices/EmulatedUSBDeviceFrame.cpp b/src/gui/EmulatedUSBDevices/EmulatedUSBDeviceFrame.cpp index f43c3690..f4784f35 100644 --- a/src/gui/EmulatedUSBDevices/EmulatedUSBDeviceFrame.cpp +++ b/src/gui/EmulatedUSBDevices/EmulatedUSBDeviceFrame.cpp @@ -43,6 +43,7 @@ EmulatedUSBDeviceFrame::EmulatedUSBDeviceFrame(wxWindow* parent) auto* notebook = new wxNotebook(this, wxID_ANY); notebook->AddPage(AddSkylanderPage(notebook), _("Skylanders Portal")); + notebook->AddPage(AddInfinityPage(notebook), _("Infinity Base")); sizer->Add(notebook, 1, wxEXPAND | wxALL, 2); @@ -83,32 +84,98 @@ wxPanel* EmulatedUSBDeviceFrame::AddSkylanderPage(wxNotebook* notebook) return panel; } -wxBoxSizer* EmulatedUSBDeviceFrame::AddSkylanderRow(uint8 row_number, +wxPanel* EmulatedUSBDeviceFrame::AddInfinityPage(wxNotebook* notebook) +{ + auto* panel = new wxPanel(notebook); + auto* panelSizer = new wxBoxSizer(wxBOTH); + auto* box = new wxStaticBox(panel, wxID_ANY, _("Infinity Manager")); + auto* boxSizer = new wxStaticBoxSizer(box, wxBOTH); + + auto* row = new wxBoxSizer(wxHORIZONTAL); + + m_emulateBase = + new wxCheckBox(box, wxID_ANY, _("Emulate Infinity Base")); + m_emulateBase->SetValue( + GetConfig().emulated_usb_devices.emulate_infinity_base); + m_emulateBase->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent&) { + GetConfig().emulated_usb_devices.emulate_infinity_base = + m_emulateBase->IsChecked(); + g_config.Save(); + }); + row->Add(m_emulateBase, 1, wxEXPAND | wxALL, 2); + boxSizer->Add(row, 1, wxEXPAND | wxALL, 2); + boxSizer->Add(AddInfinityRow("Play Set/Power Disc", 0, box), 1, wxEXPAND | wxALL, 2); + boxSizer->Add(AddInfinityRow("Power Disc Two", 1, box), 1, wxEXPAND | wxALL, 2); + boxSizer->Add(AddInfinityRow("Power Disc Three", 2, box), 1, wxEXPAND | wxALL, 2); + boxSizer->Add(AddInfinityRow("Player One", 3, box), 1, wxEXPAND | wxALL, 2); + boxSizer->Add(AddInfinityRow("Player One Ability One", 4, box), 1, wxEXPAND | wxALL, 2); + boxSizer->Add(AddInfinityRow("Player One Ability Two", 5, box), 1, wxEXPAND | wxALL, 2); + boxSizer->Add(AddInfinityRow("Player Two", 6, box), 1, wxEXPAND | wxALL, 2); + boxSizer->Add(AddInfinityRow("Player Two Ability One", 7, box), 1, wxEXPAND | wxALL, 2); + boxSizer->Add(AddInfinityRow("Player Two Ability Two", 8, box), 1, wxEXPAND | wxALL, 2); + + panelSizer->Add(boxSizer, 1, wxEXPAND | wxALL, 2); + panel->SetSizerAndFit(panelSizer); + + return panel; +} + +wxBoxSizer* EmulatedUSBDeviceFrame::AddSkylanderRow(uint8 rowNumber, wxStaticBox* box) { auto* row = new wxBoxSizer(wxHORIZONTAL); row->Add(new wxStaticText(box, wxID_ANY, fmt::format("{} {}", _("Skylander").ToStdString(), - (row_number + 1))), + (rowNumber + 1))), 1, wxEXPAND | wxALL, 2); - m_skylanderSlots[row_number] = + m_skylanderSlots[rowNumber] = new wxTextCtrl(box, wxID_ANY, _("None"), wxDefaultPosition, wxDefaultSize, wxTE_READONLY); - m_skylanderSlots[row_number]->SetMinSize(wxSize(150, -1)); - m_skylanderSlots[row_number]->Disable(); - row->Add(m_skylanderSlots[row_number], 1, wxEXPAND | wxALL, 2); + m_skylanderSlots[rowNumber]->SetMinSize(wxSize(150, -1)); + m_skylanderSlots[rowNumber]->Disable(); + row->Add(m_skylanderSlots[rowNumber], 1, wxEXPAND | wxALL, 2); auto* loadButton = new wxButton(box, wxID_ANY, _("Load")); - loadButton->Bind(wxEVT_BUTTON, [row_number, this](wxCommandEvent&) { - LoadSkylander(row_number); + loadButton->Bind(wxEVT_BUTTON, [rowNumber, this](wxCommandEvent&) { + LoadSkylander(rowNumber); }); auto* createButton = new wxButton(box, wxID_ANY, _("Create")); - createButton->Bind(wxEVT_BUTTON, [row_number, this](wxCommandEvent&) { - CreateSkylander(row_number); + createButton->Bind(wxEVT_BUTTON, [rowNumber, this](wxCommandEvent&) { + CreateSkylander(rowNumber); }); auto* clearButton = new wxButton(box, wxID_ANY, _("Clear")); - clearButton->Bind(wxEVT_BUTTON, [row_number, this](wxCommandEvent&) { - ClearSkylander(row_number); + clearButton->Bind(wxEVT_BUTTON, [rowNumber, this](wxCommandEvent&) { + ClearSkylander(rowNumber); + }); + row->Add(loadButton, 1, wxEXPAND | wxALL, 2); + row->Add(createButton, 1, wxEXPAND | wxALL, 2); + row->Add(clearButton, 1, wxEXPAND | wxALL, 2); + + return row; +} + +wxBoxSizer* EmulatedUSBDeviceFrame::AddInfinityRow(wxString name, uint8 rowNumber, wxStaticBox* box) +{ + auto* row = new wxBoxSizer(wxHORIZONTAL); + + row->Add(new wxStaticText(box, wxID_ANY, name), 1, wxEXPAND | wxALL, 2); + m_infinitySlots[rowNumber] = + new wxTextCtrl(box, wxID_ANY, _("None"), wxDefaultPosition, wxDefaultSize, + wxTE_READONLY); + m_infinitySlots[rowNumber]->SetMinSize(wxSize(150, -1)); + m_infinitySlots[rowNumber]->Disable(); + row->Add(m_infinitySlots[rowNumber], 1, wxALL | wxEXPAND, 5); + auto* loadButton = new wxButton(box, wxID_ANY, _("Load")); + loadButton->Bind(wxEVT_BUTTON, [rowNumber, this](wxCommandEvent&) { + LoadFigure(rowNumber); + }); + auto* createButton = new wxButton(box, wxID_ANY, _("Create")); + createButton->Bind(wxEVT_BUTTON, [rowNumber, this](wxCommandEvent&) { + CreateFigure(rowNumber); + }); + auto* clearButton = new wxButton(box, wxID_ANY, _("Clear")); + clearButton->Bind(wxEVT_BUTTON, [rowNumber, this](wxCommandEvent&) { + ClearFigure(rowNumber); }); row->Add(loadButton, 1, wxEXPAND | wxALL, 2); row->Add(createButton, 1, wxEXPAND | wxALL, 2); @@ -138,7 +205,7 @@ void EmulatedUSBDeviceFrame::LoadSkylanderPath(uint8 slot, wxString path) return; } - std::array fileData; + std::array fileData; if (skyFile->readData(fileData.data(), fileData.size()) != fileData.size()) { wxMessageDialog open_error(this, "Failed to read file! File was too small"); @@ -218,15 +285,15 @@ CreateSkylanderDialog::CreateSkylanderDialog(wxWindow* parent, uint8 slot) long longSkyId; if (!editId->GetValue().ToLong(&longSkyId) || longSkyId > 0xFFFF) { - wxMessageDialog id_error(this, "Error Converting ID!", "ID Entered is Invalid"); - id_error.ShowModal(); + wxMessageDialog idError(this, "Error Converting ID!", "ID Entered is Invalid"); + idError.ShowModal(); return; } long longSkyVar; if (!editVar->GetValue().ToLong(&longSkyVar) || longSkyVar > 0xFFFF) { - wxMessageDialog id_error(this, "Error Converting Variant!", "Variant Entered is Invalid"); - id_error.ShowModal(); + wxMessageDialog idError(this, "Error Converting Variant!", "Variant Entered is Invalid"); + idError.ShowModal(); return; } uint16 skyId = longSkyId & 0xFFFF; @@ -284,6 +351,157 @@ wxString CreateSkylanderDialog::GetFilePath() const return m_filePath; } +CreateInfinityFigureDialog::CreateInfinityFigureDialog(wxWindow* parent, uint8 slot) + : wxDialog(parent, wxID_ANY, _("Infinity Figure Creator"), wxDefaultPosition, wxSize(500, 150)) +{ + auto* sizer = new wxBoxSizer(wxVERTICAL); + + auto* comboRow = new wxBoxSizer(wxHORIZONTAL); + + auto* comboBox = new wxComboBox(this, wxID_ANY); + comboBox->Append("---Select---", reinterpret_cast(0xFFFFFF)); + wxArrayString filterlist; + for (const auto& it : nsyshid::g_infinitybase.GetFigureList()) + { + const uint32 figure = it.first; + if ((slot == 0 && + ((figure > 0x1E8480 && figure < 0x2DC6BF) || (figure > 0x3D0900 && figure < 0x4C4B3F))) || + ((slot == 1 || slot == 2) && (figure > 0x3D0900 && figure < 0x4C4B3F)) || + ((slot == 3 || slot == 6) && figure < 0x1E847F) || + ((slot == 4 || slot == 5 || slot == 7 || slot == 8) && + (figure > 0x2DC6C0 && figure < 0x3D08FF))) + { + comboBox->Append(it.second.second, reinterpret_cast(figure)); + filterlist.Add(it.second.second); + } + } + comboBox->SetSelection(0); + bool enabled = comboBox->AutoComplete(filterlist); + comboRow->Add(comboBox, 1, wxEXPAND | wxALL, 2); + + auto* figNumRow = new wxBoxSizer(wxHORIZONTAL); + + wxIntegerValidator validator; + + auto* labelFigNum = new wxStaticText(this, wxID_ANY, "Figure Number:"); + auto* editFigNum = new wxTextCtrl(this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0, validator); + + figNumRow->Add(labelFigNum, 1, wxALL, 5); + figNumRow->Add(editFigNum, 1, wxALL, 5); + + auto* buttonRow = new wxBoxSizer(wxHORIZONTAL); + + auto* createButton = new wxButton(this, wxID_ANY, _("Create")); + createButton->Bind(wxEVT_BUTTON, [editFigNum, this](wxCommandEvent&) { + long longFigNum; + if (!editFigNum->GetValue().ToLong(&longFigNum)) + { + wxMessageDialog idError(this, "Error Converting Figure Number!", "Number Entered is Invalid"); + idError.ShowModal(); + this->EndModal(0);; + } + uint32 figNum = longFigNum & 0xFFFFFFFF; + auto figure = nsyshid::g_infinitybase.FindFigure(figNum); + wxString predefName = figure.second + ".bin"; + wxFileDialog + saveFileDialog(this, _("Create Infinity Figure file"), "", predefName, + "BIN files (*.bin)|*.bin", wxFD_SAVE | wxFD_OVERWRITE_PROMPT); + + if (saveFileDialog.ShowModal() == wxID_CANCEL) + this->EndModal(0);; + + m_filePath = saveFileDialog.GetPath(); + + nsyshid::g_infinitybase.CreateFigure(_utf8ToPath(m_filePath.utf8_string()), figNum, figure.first); + + this->EndModal(1); + }); + auto* cancelButton = new wxButton(this, wxID_ANY, _("Cancel")); + cancelButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { + this->EndModal(0); + }); + + comboBox->Bind(wxEVT_COMBOBOX, [comboBox, editFigNum, this](wxCommandEvent&) { + const uint64 fig_info = reinterpret_cast(comboBox->GetClientData(comboBox->GetSelection())); + if (fig_info != 0xFFFFFF) + { + const uint32 figNum = fig_info & 0xFFFFFFFF; + + editFigNum->SetValue(wxString::Format(wxT("%i"), figNum)); + } + }); + + buttonRow->Add(createButton, 1, wxALL, 5); + buttonRow->Add(cancelButton, 1, wxALL, 5); + + sizer->Add(comboRow, 1, wxEXPAND | wxALL, 2); + sizer->Add(figNumRow, 1, wxEXPAND | wxALL, 2); + sizer->Add(buttonRow, 1, wxEXPAND | wxALL, 2); + + this->SetSizer(sizer); + this->Centre(wxBOTH); +} + +wxString CreateInfinityFigureDialog::GetFilePath() const +{ + return m_filePath; +} + +void EmulatedUSBDeviceFrame::LoadFigure(uint8 slot) +{ + wxFileDialog openFileDialog(this, _("Open Infinity Figure dump"), "", "", + "BIN files (*.bin)|*.bin", + wxFD_OPEN | wxFD_FILE_MUST_EXIST); + if (openFileDialog.ShowModal() != wxID_OK || openFileDialog.GetPath().empty()) + { + wxMessageDialog errorMessage(this, "File Okay Error"); + errorMessage.ShowModal(); + return; + } + + LoadFigurePath(slot, openFileDialog.GetPath()); +} + +void EmulatedUSBDeviceFrame::LoadFigurePath(uint8 slot, wxString path) +{ + std::unique_ptr infFile(FileStream::openFile2(_utf8ToPath(path.utf8_string()), true)); + if (!infFile) + { + wxMessageDialog errorMessage(this, "File Open Error"); + errorMessage.ShowModal(); + return; + } + + std::array fileData; + if (infFile->readData(fileData.data(), fileData.size()) != fileData.size()) + { + wxMessageDialog open_error(this, "Failed to read file! File was too small"); + open_error.ShowModal(); + return; + } + ClearFigure(slot); + + uint32 number = nsyshid::g_infinitybase.LoadFigure(fileData, std::move(infFile), slot); + m_infinitySlots[slot]->ChangeValue(nsyshid::g_infinitybase.FindFigure(number).second); +} + +void EmulatedUSBDeviceFrame::CreateFigure(uint8 slot) +{ + cemuLog_log(LogType::Force, "Create Figure: {}", slot); + CreateInfinityFigureDialog create_dlg(this, slot); + create_dlg.ShowModal(); + if (create_dlg.GetReturnCode() == 1) + { + LoadFigurePath(slot, create_dlg.GetFilePath()); + } +} + +void EmulatedUSBDeviceFrame::ClearFigure(uint8 slot) +{ + m_infinitySlots[slot]->ChangeValue("None"); + nsyshid::g_infinitybase.RemoveFigure(slot); +} + void EmulatedUSBDeviceFrame::UpdateSkylanderEdits() { for (auto i = 0; i < nsyshid::MAX_SKYLANDERS; i++) diff --git a/src/gui/EmulatedUSBDevices/EmulatedUSBDeviceFrame.h b/src/gui/EmulatedUSBDevices/EmulatedUSBDeviceFrame.h index 8988cb8a..ae29a036 100644 --- a/src/gui/EmulatedUSBDevices/EmulatedUSBDeviceFrame.h +++ b/src/gui/EmulatedUSBDevices/EmulatedUSBDeviceFrame.h @@ -5,6 +5,7 @@ #include #include +#include "Cafe/OS/libs/nsyshid/Infinity.h" #include "Cafe/OS/libs/nsyshid/Skylander.h" class wxBoxSizer; @@ -23,15 +24,23 @@ class EmulatedUSBDeviceFrame : public wxFrame { private: wxCheckBox* m_emulatePortal; + wxCheckBox* m_emulateBase; std::array m_skylanderSlots; + std::array m_infinitySlots; std::array>, nsyshid::MAX_SKYLANDERS> m_skySlots; wxPanel* AddSkylanderPage(wxNotebook* notebook); + wxPanel* AddInfinityPage(wxNotebook* notebook); wxBoxSizer* AddSkylanderRow(uint8 row_number, wxStaticBox* box); + wxBoxSizer* AddInfinityRow(wxString name, uint8 row_number, wxStaticBox* box); void LoadSkylander(uint8 slot); void LoadSkylanderPath(uint8 slot, wxString path); void CreateSkylander(uint8 slot); void ClearSkylander(uint8 slot); + void LoadFigure(uint8 slot); + void LoadFigurePath(uint8 slot, wxString path); + void CreateFigure(uint8 slot); + void ClearFigure(uint8 slot); void UpdateSkylanderEdits(); }; class CreateSkylanderDialog : public wxDialog { @@ -39,6 +48,15 @@ class CreateSkylanderDialog : public wxDialog { explicit CreateSkylanderDialog(wxWindow* parent, uint8 slot); wxString GetFilePath() const; + protected: + wxString m_filePath; +}; + +class CreateInfinityFigureDialog : public wxDialog { + public: + explicit CreateInfinityFigureDialog(wxWindow* parent, uint8 slot); + wxString GetFilePath() const; + protected: wxString m_filePath; }; \ No newline at end of file