Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
DmGamepad: a Hades II layout (floating stick + combat keys)
LNPANDY13bac354de54
diff --git a/dm/games/0100A00019DE0000/pad_icons/attack.png b/dm/games/0100A00019DE0000/pad_icons/attack.pngnew file mode 100644index 00000000..e68e03cfBinary files /dev/null and b/dm/games/0100A00019DE0000/pad_icons/attack.png differdiff --git a/dm/games/0100A00019DE0000/pad_icons/cast.png b/dm/games/0100A00019DE0000/pad_icons/cast.pngnew file mode 100644index 00000000..8d182dbfBinary files /dev/null and b/dm/games/0100A00019DE0000/pad_icons/cast.png differdiff --git a/dm/games/0100A00019DE0000/pad_icons/dash.png b/dm/games/0100A00019DE0000/pad_icons/dash.pngnew file mode 100644index 00000000..3301ae83Binary files /dev/null and b/dm/games/0100A00019DE0000/pad_icons/dash.png differdiff --git a/dm/games/0100A00019DE0000/pad_icons/hex.png b/dm/games/0100A00019DE0000/pad_icons/hex.pngnew file mode 100644index 00000000..af2f816cBinary files /dev/null and b/dm/games/0100A00019DE0000/pad_icons/hex.png differdiff --git a/dm/games/0100A00019DE0000/pad_icons/omega.png b/dm/games/0100A00019DE0000/pad_icons/omega.pngnew file mode 100644index 00000000..db0685c4Binary files /dev/null and b/dm/games/0100A00019DE0000/pad_icons/omega.png differdiff --git a/dm/games/0100A00019DE0000/pad_icons/special.png b/dm/games/0100A00019DE0000/pad_icons/special.pngnew file mode 100644index 00000000..3d68fe03Binary files /dev/null and b/dm/games/0100A00019DE0000/pad_icons/special.png differdiff --git a/dm/ios/Sources/DmGamepad.m b/dm/ios/Sources/DmGamepad.mindex d96ff6f1..5eeb6259 100644--- a/dm/ios/Sources/DmGamepad.m+++ b/dm/ios/Sources/DmGamepad.m@@ -1,13 +1,38 @@// Virtual gamepad (Nintendo button positions) + physical controllers (GameController). Both are merged and handed to the host through dm_input_set (hle_hid.c, bit layout in dm_input.h).-// Two layouts; one tap on the layout button at the top centre (labelled with the current layout, "2D" / "3D") switches them, and the choice is kept in NSUserDefaults (each game is its own app, so per game); the first launch uses the game profile's pad_layout (DM_GAME_PAD_FULL).+// Three layouts; one tap on the layout button at the top centre (labelled with the current layout, "2D" / "3D" / "H2") cycles them, and the choice is kept in NSUserDefaults (each game is its own app, so per game); the first launch uses the game profile's pad_layout (DM_GAME_PAD_FULL).// 2D (simple): top corners ZL above L (one column), ZR above R likewise, teardrops with the tip toward the screen corner; − and + side by side at the top centre; the left stick in the bottom-left corner (fixed ring, tilt measured from the ring centre, small dead zone);// the A (right) B (bottom) X (top) Y (left) diamond in the bottom-right corner, sliding a finger between keys switches keys. Each bottom corner holds a single control, so it sits close in (reaching halfway into the side safe-area inset).// 3D (full, Pro Controller style): everything in 2D (left stick and diamond keep their place and size), plus a D-pad (inward of and below the left stick, 8-way), a right stick (inward of and below the diamond, a smaller ring)// and L3 / R3 (small round keys in the top row, inward of ZL / ZR). Breath of the Wild crouches with L3 and uses the scope with R3; 3D World and Breath of the Wild turn the camera with the right stick.+// H2 (Hades II, see the block below): a floating stick on the left (the base starts wherever the+// finger lands) and combat keys on the right, sized by the game's own use frequency, with the+// Ω latch standing in for the pad's hold-ZR modifier.// Touch-down ownership: locked keys first (shoulders, − / +, the layout button, L3 / R3), then whichever of the diamond, the D-pad and the two sticks has the smallest distance / grab radius (the left stick's grab circle borders the D-pad).// Everything hugs the edges and corners to leave the picture room; controls sit over the picture, one CAShapeLayer each: a press only swaps the fill, a stick only moves its knob, nothing redraws the whole screen.// Touches no control takes go to the game's touch screen (pushGame; Super Mario Galaxy's pointer in handheld mode).// The virtual gamepad (layout button included) hides while a physical controller is connected and comes back when it is removed; meanwhile every touch goes to the game. Physical controllers keep every button (D-pad and right stick included) and map by position: bottom = B, right = A, left = Y, top = X (same positions as on a Switch controller).+// ---- Hades II layout ----+// The stick starts wherever the finger lands inside the lower-left start zone (40% of the width,+// from 45% of the height down): the base centre = the touch point, direction and magnitude are+// measured from that point, and dragging any distance keeps working (the base does not follow the+// finger). A touch outside the zone that hits nothing else goes to the game's touch screen, as in+// the other layouts. A stick finger cancelled by the system (notification banner, system gesture)+// resumes when a finger lands near the same place within 2 s, keeping the old base centre so the+// base does not jump.+// The right side holds the combat keys, laid out by the game's own frequency (from the help text:+// Attack 32 hints, Special 25, Dash 17, Cast 8, Hex 9) and the Switch mapping (Y attack, X special,+// B dash, A cast):+// Y attack biggest, rightmost (thumb rest) — holding passes the press duration through, which is the Ω attack+// X special second size, upper-left of Y — the Ω special works the same way+// B dash third size, below, wide hit area (the most救命 key)+// A cast smaller, inner+// ZR omega the Ω moves are "hold ZR then press attack / special" on a pad; here the key is a+// latch: tap once to arm (the ring lights), the next attack / special press carries+// ZR 0.12 s ahead of itself (the game's own "hold ZR first" order), then it disarms.+// Holding the key works as well.+// R hex smallest, innermost: the blue-meter spell (hold-and-release variants pass through)+// Each combat key draws the game's own glyph when the profile ships one+// (dm/games/<id>/pad_icons/<name>.png); without one it falls back to the button letter.#import <UIKit/UIKit.h>#import <GameController/GameController.h>#import <CoreText/CoreText.h>@@ -17,7 +42,24 @@#include "game_profile.h"enum { B_A = 0, B_B, B_X, B_Y, B_LS, B_RS, B_L, B_R, B_ZL, B_ZR, B_PLUS, B_MINUS, B_LEFT, B_UP, B_RIGHT, B_DOWN, B_N };-enum { C_NONE = 0, C_STICK, C_DPAD, C_FACE, C_BTN, C_SWAP, C_GAME }; // which control a touch holds; C_GAME: none, the touch goes to the game's touch screen (finger slot << 8)+enum { C_NONE = 0, C_STICK, C_DPAD, C_FACE, C_BTN, C_SWAP, C_GAME, C_H2KEY }; // C_GAME: none, the touch goes to the game's touch screen (finger slot << 8); C_H2KEY: a Hades II combat key (key << 8)++// ---- Hades II layout constants ----+// Key radii: attack biggest, hex smallest (sized by use frequency, see the header comment).+static const CGFloat KH_Y_R = 40, KH_X_R = 33, KH_B_R = 34, KH_A_R = 26, KH_ZR_R = 25, KH_R_R = 20;+// Key centres from Y (the anchor), in u: X upper-left, B below-left, A inward-down, ZR outward-up, R inward below A.+// Y itself sits KH_FACE_X from the right edge and KH_FACE_Y from the bottom.+static const CGFloat KH_FACE_X = 120, KH_FACE_Y = 96,+ KH_X_DX = -86, KH_X_DY = -50,+ KH_B_DX = -118, KH_B_DY = 34,+ KH_A_DX = 52, KH_A_DY = 118,+ KH_ZR_DX = 132, KH_ZR_DY = -96,+ KH_R_DX = 46, KH_R_DY = 200;+// Floating stick: the start zone's right bound (fraction of the width) and upper bound (fraction of+// the height from the bottom); the base radius, full-tilt fraction, dead zone, the resume window for+// a system-cancelled stick finger, its grab factor, and how long the Ω latch leads the attack key.+static const CGFloat KH_ZONE_R = 0.40, KH_ZONE_T = 0.45, KH_STICK_R = 62, KH_FULL = 0.75,+ KH_DEAD = 0.08, KH_RESUME_S = 2.0, KH_RESUME_K = 1.6, KH_ZR_LEAD = 0.12;static pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER;static uint64_t g_touch_btn, g_pad_btn;@@ -54,13 +96,33 @@ static const CGFloatK_CLICK_X = 102, K_CLICK_R = 17; // L3 / R3: centre from the outer edge (level with ZL / ZR), radiusstatic const int k_btns[] = {B_ZL, B_L, B_ZR, B_R, B_MINUS, B_PLUS, B_LS, B_RS}; // keys locked at touch-down (L3 / R3 only in the 3D layout)static NSString *const k_layout_key = @"DmPadLayout"; // NSUserDefaults: 1 = 3D, 0 = 2D+static NSString *const k_h2_key = @"DmPadH2"; // NSUserDefaults: 1 = Hades II layout (overrides 2D / 3D)++// ---- Hades II combat keys ----+// Each entry: button, centre from Y (the anchor) in u, radius in u, icon name. Y sits at the thumb's+// rest point; the rest fan out by use frequency (attack biggest and under the thumb, hex smallest).+typedef struct { int b; CGFloat dx, dy, r; NSString *icon; } h2key;+static const h2key k_h2[] = {+ { B_Y, 0, 0, KH_Y_R, @"attack" },+ { B_X, KH_X_DX, KH_X_DY, KH_X_R, @"special" },+ { B_B, KH_B_DX, KH_B_DY, KH_B_R, @"dash" },+ { B_A, KH_A_DX, KH_A_DY, KH_A_R, @"cast" },+ { B_ZR, KH_ZR_DX, KH_ZR_DY, KH_ZR_R, @"omega" },+ { B_R, KH_R_DX, KH_R_DY, KH_R_R, @"hex" },+};+enum { KH_N = sizeof k_h2 / sizeof *k_h2 };+static UIImage *h2_icon(NSString *name) { // the game's own glyph from the profile folder, if present+ NSString *p = [[NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"dm/pad_icons"]+ stringByAppendingPathComponent:[name stringByAppendingString:@".png"]];+ return [UIImage imageWithContentsOfFile:p];+}@interface DmGamepad : UIView@endstatic __weak DmGamepad *g_view;@implementation DmGamepad {- NSMapTable<UITouch *, NSNumber *> *_owner; // touch → control (with the key for C_BTN or the stick for C_STICK, << 8)+ NSMapTable<UITouch *, NSNumber *> *_owner; // touch → control (with the key for C_BTN / C_H2KEY or the stick for C_STICK, << 8)UITouch *_stick[2]; CGPoint _stickNow[2]; // the touch holding each stick and where it is now (0 left, 1 right)uint64_t _faceBits, _dpadBits, _btnBits;NSMapTable<UITouch *, NSNumber *> *_faceOf; // which keys each touch on the diamond currently holds@@ -69,9 +131,21 @@ static __weak DmGamepad *g_view;CAShapeLayer *_swap; CATextLayer *_swapLabel; BOOL _swapHeld;BOOL _sticksShown; // a stick was held at the last refreshBOOL _full; // the 3D layout is current+ BOOL _h2; // the Hades II layout is currentCALayer *_controls; // holds every control layer: hidden while a physical controller is connected (the view itself stays, for game touches)BOOL _padOff; // a physical controller is connected: every touch goes to the gameUITouch *_game[16]; // touches on the game's touch screen by finger slot+ // ---- Hades II state ----+ CAShapeLayer *_h2key[KH_N]; CALayer *_h2icon[KH_N]; // combat keys: ring + the game's glyph (or the letter label when no glyph ships)+ CATextLayer *_h2label[KH_N];+ UITouch *_h2stick; // the finger holding the floating stick+ CGPoint _h2origin, _h2now; // the base centre (the touch-down point) and the finger now+ CGPoint _h2lostOrigin; double _h2lostS; // the base centre and time of a cancelled stick finger (for the resume)+ BOOL _h2stickShown; // the floating base was drawn at the last refresh+ BOOL _h2omega; // the Ω latch is armed: the next attack / special carries ZR+ double _h2omegaSince; // when the latch went down (the lead time runs from it)+ double _h2keyDown[KH_N]; // when each key's finger went down (0 = up; Ω needs the duration)+ uint64_t _h2bits; // the combat-key bits as published at the last recompute}static UIColor *k_idle, *k_on, *k_line, *k_ringFill, *k_text, *k_textOn;@@ -111,8 +185,24 @@ static BOOL fullOnly(int b) { return b == B_LS || b == B_RS || b >= B_LEFT; }if (names[b]) _label[b] = label(_key[b], names[b]); // the D-pad arms carry no label}_swap = shape(_controls); _swapLabel = label(_swap, @"");+ // Hades II combat keys: one ring + one content layer each; the content is the game's own+ // glyph when the profile ships one, else the button letter.+ static NSString *const h2names[KH_N] = {@"Y", @"X", @"B", @"A", @"Ω", @"R"};+ for (int i = 0; i < KH_N; i++) {+ _h2key[i] = shape(_controls);+ UIImage *im = h2_icon(k_h2[i].icon);+ if (im) {+ _h2icon[i] = [CALayer layer]; _h2icon[i].contents = (__bridge id)im.CGImage;+ _h2icon[i].contentsGravity = kCAGravityResizeAspect;+ [_h2key[i] addSublayer:_h2icon[i]];+ } else {+ _h2label[i] = label(_h2key[i], h2names[i]);+ }+ }NSNumber *saved = [NSUserDefaults.standardUserDefaults objectForKey:k_layout_key];_full = saved ? saved.boolValue : DM_GAME_PAD_FULL;+ NSNumber *h2saved = [NSUserDefaults.standardUserDefaults objectForKey:k_h2_key];+ _h2 = h2saved ? h2saved.boolValue : NO;[self applyLayout];NSNotificationCenter *nc = NSNotificationCenter.defaultCenter;[nc addObserver:self selector:@selector(padsChanged) name:GCControllerDidConnectNotification object:nil];@@ -123,16 +213,24 @@ static BOOL fullOnly(int b) { return b == B_LS || b == B_RS || b >= B_LEFT; }}- (void)applyLayout { // show / hide the controls for the current layout[CATransaction begin]; [CATransaction setDisableActions:YES];- for (int b = 0; b < B_N; b++) _key[b].hidden = fullOnly(b) && !_full;- _ring[1].hidden = _knob[1].hidden = !_full;- _swapLabel.string = _full ? @"3D" : @"2D";+ for (int b = 0; b < B_N; b++) _key[b].hidden = _h2 || (fullOnly(b) && !_full);+ _ring[1].hidden = _knob[1].hidden = _h2 || !_full;+ _ring[0].hidden = _knob[0].hidden = _h2; // the H2 stick draws its own floating base+ for (int i = 0; i < KH_N; i++) _h2key[i].hidden = !_h2;+ _swapLabel.string = _h2 ? @"H2" : _full ? @"3D" : @"2D";[CATransaction commit];}-- (void)setFull:(BOOL)full { // switch layouts: release every touch first (no key stays held), save, lay out again- if (full == _full) return;- [self reset];- _full = full;- [NSUserDefaults.standardUserDefaults setObject:@(full) forKey:k_layout_key];+- (void)setFull:(BOOL)full { // cycle layouts: 2D → 3D → H2 → 2D. Release every touch first (no key stays held), save, lay out again+ if (full) {+ if (!_full) { [self reset]; _full = YES; _h2 = NO; }+ else if (!_h2) { [self reset]; _h2 = YES; }+ else { [self reset]; _full = NO; _h2 = NO; }+ } else {+ if (!_full && !_h2) { [self reset]; _full = YES; }+ else { [self reset]; _full = NO; _h2 = NO; }+ }+ [NSUserDefaults.standardUserDefaults setObject:@(_full) forKey:k_layout_key];+ [NSUserDefaults.standardUserDefaults setObject:@(_h2) forKey:k_h2_key];[self applyLayout]; [self setNeedsLayout];}@@ -162,6 +260,34 @@ static BOOL isClick(int b) { return b == B_LS || b == B_RS; }return CGRectMake(c.x - w / 2, c.y - h / 2, w, h); }- (CGPoint)swapCenter { CGRect s = self.safe; return CGPointMake(CGRectGetMidX(s), CGRectGetMinY(s) + K_PILL_Y * self.u); }+// ---- Hades II geometry ----+- (CGPoint)h2Anchor { // Y, the anchor every other key is placed from+ CGRect s = self.corner; CGFloat u = self.u;+ return side(s, 1, KH_FACE_X * u, CGRectGetMaxY(s) - KH_FACE_Y * u);+}+- (CGPoint)h2keyCenter:(int)i {+ CGPoint a = self.h2Anchor; CGFloat u = self.u;+ return CGPointMake(a.x + k_h2[i].dx * u, a.y + k_h2[i].dy * u);+}+- (CGFloat)h2keyR:(int)i { return k_h2[i].r * self.u; }+- (int)h2keyAt:(CGPoint)p {+ for (int i = 0; i < KH_N; i++) { CGFloat r = [self h2keyR:i] * 1.18; // a slightly generous hit area: small keys must not need pixel aim+ if (dist(p, [self h2keyCenter:i]) <= r) return i; }+ return -1;+}+- (BOOL)h2inStickZone:(CGPoint)p { // the lower-left zone the floating stick starts in+ return p.x >= 0 && p.y <= self.bounds.size.height+ && p.x < self.bounds.size.width * KH_ZONE_R+ && p.y > self.bounds.size.height * (1 - KH_ZONE_T);+}+// The knob offset from the floating base (clamped to the base edge), the same convention as knobOffset.+- (CGPoint)h2knobOffset {+ if (!_h2stick) return CGPointZero;+ CGFloat dx = _h2now.x - _h2origin.x, dy = _h2now.y - _h2origin.y, d = hypot(dx, dy), R = KH_STICK_R * self.u;+ if (d > R) { dx *= R / d; dy *= R / d; }+ return CGPointMake(dx, dy);+}+static CGFloat dist(CGPoint a, CGPoint b) { return hypot(a.x - b.x, a.y - b.y); }- (int)btnAt:(CGPoint)p { // locked keys (tested on touch-down only, then locked)CGFloat u = self.u;@@ -211,13 +337,36 @@ static CGFloat dist(CGPoint a, CGPoint b) { return hypot(a.x - b.x, a.y - b.y);CGFloat m = fmin((d - dz) / (R * K_FULL - dz), 1) / d; // outside the dead zone: 0 rising to full at the full-tilt radiusax[i * 2] = (int32_t)lrint(o.x * m * 32767); ax[i * 2 + 1] = (int32_t)lrint(-o.y * m * 32767); // host: up is positive; rounded so full tilt is exactly 32767}- BOOL changed = face != _faceBits || dpad != _dpadBits || btn != _btnBits || swap != _swapHeld;+ // Hades II combat keys: the bits from every finger on an H2 key, plus the Ω latch. The latch+ // leads the attack / special by KH_ZR_LEAD: when a key that carries ZR goes down within the+ // lead window of the latch, the published button set waits the remainder before adding it, so+ // a quick tap-Ω-attack still arrives in the game's own "hold ZR first" order. Press durations+ // pass through untouched (the Ω moves are holds; the hex's hold-and-release works as is).+ uint64_t h2 = 0;+ for (UITouch *t in _owner) { uint64_t v = [_owner objectForKey:t].unsignedLongLongValue;+ if ((v & 0xff) == C_H2KEY) h2 |= 1ull << k_h2[(int)(v >> 8)].b; }+ BOOL h2changed = h2 != _h2bits;+ _h2bits = h2;+ if (_h2 && _h2omega) {+ // A ZR-carrying key is down (or comes down): ZR leads it by the remainder of the window.+ BOOL carry = (h2 & ((1ull << B_Y) | (1ull << B_X))) != 0;+ double now = [NSDate timeIntervalSinceReferenceDate];+ if (carry && now - _h2omegaSince < KH_ZR_LEAD) {+ double left = KH_ZR_LEAD - (now - _h2omegaSince);+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(left * NSEC_PER_SEC)),+ dispatch_get_main_queue(), ^{ [self recompute]; });+ } else if (carry || now - _h2omegaSince >= KH_ZR_LEAD) {+ h2 |= 1ull << B_ZR;+ }+ }+ BOOL changed = face != _faceBits || dpad != _dpadBits || btn != _btnBits || swap != _swapHeld || h2changed;_faceBits = face; _dpadBits = dpad; _btnBits = btn; _swapHeld = swap;pthread_mutex_lock(&g_mu);- g_touch_btn = face | dpad | btn; g_touch_lx = ax[0]; g_touch_ly = ax[1]; g_touch_rx = ax[2]; g_touch_ry = ax[3];+ if (_h2) { g_touch_btn = h2 | btn; g_touch_lx = ax[2]; g_touch_ly = ax[3]; g_touch_rx = 0; g_touch_ry = 0; }+ else { g_touch_btn = face | dpad | btn; g_touch_lx = ax[0]; g_touch_ly = ax[1]; g_touch_rx = ax[2]; g_touch_ry = ax[3]; }pthread_mutex_unlock(&g_mu);publish();- BOOL sticks = _stick[0] || _stick[1];+ BOOL sticks = _h2 ? _h2stick != nil : (_stick[0] || _stick[1]);if (changed || sticks || _sticksShown) [self refresh]; // also refresh on the stick release so the knob returns to the centre_sticksShown = sticks;}@@ -239,10 +388,55 @@ static CGFloat dist(CGPoint a, CGPoint b) { return hypot(a.x - b.x, a.y - b.y);for (int i = 0; i < 16; i++) if (!_game[i]) { _game[i] = t; [_owner setObject:@(C_GAME | (uint64_t)i << 8) forKey:t]; return YES; }return NO;}-- (void)touchesBegan:(NSSet<UITouch *> *)ts withEvent:(UIEvent *)e {+- (BOOL)touchesBeganH2:(NSSet<UITouch *> *)ts {+ BOOL game = NO;+ for (UITouch *t in ts) {+ CGPoint p = [t locationInView:self];+ // locked keys first (shoulders, − / +, the layout button), then H2 keys, then the stick zone+ int hit = [self btnAt:p];+ if (hit >= 0) { [_owner setObject:@(C_BTN | (uint64_t)hit << 8) forKey:t]; continue; }+ if ([self inSwap:p]) { [_owner setObject:@(C_SWAP) forKey:t]; continue; }+ int k = [self h2keyAt:p];+ if (k >= 0) {+ [_owner setObject:@(C_H2KEY | (uint64_t)k << 8) forKey:t];+ _h2keyDown[k] = [NSDate timeIntervalSinceReferenceDate];+ if (k_h2[k].b == B_ZR) { _h2omega = YES; _h2omegaSince = _h2keyDown[k]; } // the Ω latch arms+ continue;+ }+ // The floating stick: a touch in the lower-left zone starts it, base centre = the touch+ // point (clamped so the base stays on screen). A finger resuming after a system cancel+ // keeps the old base instead of jumping to the new touch point.+ if (!_h2stick && [self h2inStickZone:p]) {+ BOOL resume = _h2lostS > 0 && [NSDate timeIntervalSinceReferenceDate] - _h2lostS <= KH_RESUME_S+ && dist(p, CGPointMake(_h2lostOrigin.x, _h2lostOrigin.y)) <= KH_RESUME_K * KH_STICK_R * self.u;+ _h2stick = t; _h2now = p;+ if (resume) _h2origin = _h2lostOrigin;+ else {+ CGFloat R = KH_STICK_R * self.u, m = CGRectGetMinX(self.bounds) + R + 8;+ _h2origin = CGPointMake(fmax(p.x, m), fmin(p.y, self.bounds.size.height - R - 8));+ }+ _h2lostS = 0;+ [_owner setObject:@(C_STICK | (uint64_t)2 << 8) forKey:t]; // slot 2 = the H2 floating stick+ continue;+ }+ game |= [self gameBegin:t];+ }+ return game;+}+- (BOOL)touchesMovedH2:(NSSet<UITouch *> *)ts {BOOL game = NO;for (UITouch *t in ts) {- if (_padOff) { game |= [self gameBegin:t]; continue; }+ uint64_t v = [_owner objectForKey:t].unsignedLongLongValue;+ if ((v & 0xff) == C_STICK && (v >> 8) == 2) _h2now = [t locationInView:self];+ else if ((v & 0xff) == C_GAME) game = YES;+ }+ return game;+}+- (void)touchesBegan:(NSSet<UITouch *> *)ts withEvent:(UIEvent *)e {+ BOOL game = NO;+ if (_padOff) { for (UITouch *t in ts) game |= [self gameBegin:t]; }+ else if (_h2) game = [self touchesBeganH2:ts];+ else for (UITouch *t in ts) {CGPoint p = [t locationInView:self]; int hit = [self btnAt:p];if (hit >= 0) { [_owner setObject:@(C_BTN | (uint64_t)hit << 8) forKey:t]; continue; }if ([self inSwap:p]) { [_owner setObject:@(C_SWAP) forKey:t]; continue; }@@ -262,7 +456,8 @@ static CGFloat dist(CGPoint a, CGPoint b) { return hypot(a.x - b.x, a.y - b.y);}- (void)touchesMoved:(NSSet<UITouch *> *)ts withEvent:(UIEvent *)e {BOOL game = NO;- for (UITouch *t in ts) {+ if (_h2) game = [self touchesMovedH2:ts];+ else for (UITouch *t in ts) {uint64_t v = [_owner objectForKey:t].unsignedLongLongValue; int c = (int)(v & 0xff); CGPoint p = [t locationInView:self];if (c == C_FACE) [_faceOf setObject:@([self faceAt:p]) forKey:t];else if (c == C_STICK) _stickNow[v >> 8] = p;@@ -276,16 +471,21 @@ static CGFloat dist(CGPoint a, CGPoint b) { return hypot(a.x - b.x, a.y - b.y);for (UITouch *t in ts) {uint64_t v = [_owner objectForKey:t].unsignedLongLongValue;if (ended && (v & 0xff) == C_SWAP && [self inSwap:[t locationInView:self]]) swap = YES; // layout button: counts only when released on the button+ if ((v & 0xff) == C_STICK && (v >> 8) == 2 && t == _h2stick) { // the floating stick: record for the resume+ _h2stick = nil; _h2lostOrigin = _h2origin; _h2lostS = [NSDate timeIntervalSinceReferenceDate];+ }+ if ((v & 0xff) == C_H2KEY) { int k = (int)(v >> 8); _h2keyDown[k] = 0; if (k_h2[k].b == B_ZR) _h2omega = NO; }if ((v & 0xff) == C_GAME && (v >> 8) < 16) { _game[v >> 8] = nil; game = YES; }[_owner removeObjectForKey:t]; [_faceOf removeObjectForKey:t]; for (int i = 0; i < 2; i++) if (t == _stick[i]) _stick[i] = nil;}if (game) [self pushGame];[self recompute];- if (swap) [self setFull:!_full];+ if (swap) [self setFull:YES]; // cycle 2D → 3D → H2 → 2D}- (void)touchesEnded:(NSSet<UITouch *> *)ts withEvent:(UIEvent *)e { [self endTouches:ts tapped:YES]; }- (void)touchesCancelled:(NSSet<UITouch *> *)ts withEvent:(UIEvent *)e { [self endTouches:ts tapped:NO]; }-- (void)reset { [_owner removeAllObjects]; [_faceOf removeAllObjects]; _stick[0] = _stick[1] = nil; for (int i = 0; i < 16; i++) _game[i] = nil; [self pushGame]; [self recompute]; }+- (void)reset { [_owner removeAllObjects]; [_faceOf removeAllObjects]; _stick[0] = _stick[1] = nil; for (int i = 0; i < 16; i++) _game[i] = nil;+ _h2stick = nil; _h2omega = NO; for (int i = 0; i < KH_N; i++) _h2keyDown[i] = 0; _h2lostS = 0; [self pushGame]; [self recompute]; }// ---- Shapes ----static CGPathRef circlePath(CGPoint c, CGFloat r) { return CGPathCreateWithEllipseInRect(CGRectMake(c.x - r, c.y - r, 2 * r, 2 * r), NULL); }@@ -337,6 +537,17 @@ static void placeLabel(CATextLayer *t, CGPoint c, CGFloat fs) {static const struct { int b; CGFloat angle; } arms[] = {{B_UP, 0}, {B_RIGHT, M_PI_2}, {B_DOWN, M_PI}, {B_LEFT, -M_PI_2}}; // the same arm in 90° stepsfor (int i = 0; i < 4; i++) setPath(_key[arms[i].b], armPath(self.dpadCenter, self.dpadR, K_ARM_W * u, K_ARM_IN * u, arms[i].angle, 6 * u));CGPoint sc = self.swapCenter; setPath(_swap, circlePath(sc, K_SWAP_R * u)); placeLabel(_swapLabel, sc, 12 * u);+ // Hades II combat keys: rings at their centres, the glyph (or letter) centred inside+ for (int i = 0; i < KH_N; i++) {+ CGPoint c = [self h2keyCenter:i]; CGFloat r = [self h2keyR:i];+ setPath(_h2key[i], circlePath(c, r));+ if (_h2icon[i]) {+ CGFloat s = r * 1.1; // the glyph slightly larger than the ring's inner circle+ _h2icon[i].frame = CGRectMake(c.x - s / 2, c.y - s / 2, s, s);+ } else if (_h2label[i]) {+ placeLabel(_h2label[i], c, r * 0.75);+ }+ }for (int i = 0; i < 2; i++) {setPath(_ring[i], circlePath([self stickHome:i], [self stickR:i]));CGFloat k = (i ? K_RKNOB_R : K_KNOB_R) * u; _knob[i].bounds = CGRectMake(0, 0, 2 * k, 2 * k);@@ -349,15 +560,35 @@ static void placeLabel(CATextLayer *t, CGPoint c, CGFloat fs) {}- (void)safeAreaInsetsDidChange { [super safeAreaInsetsDidChange]; [self setNeedsLayout]; }- (void)refresh { // pressed state → fill, sticks → knob position- uint64_t all = _faceBits | _dpadBits | _btnBits;+ uint64_t all = _faceBits | _dpadBits | _btnBits | (_h2 ? _h2bits : 0);[CATransaction begin]; [CATransaction setDisableActions:YES];for (int b = 0; b < B_N; b++) { BOOL on = (all >> b) & 1;_key[b].fillColor = (on ? k_on : k_idle).CGColor; _label[b].foregroundColor = (on ? k_textOn : k_text).CGColor; }_swap.fillColor = (_swapHeld ? k_on : k_idle).CGColor; _swapLabel.foregroundColor = (_swapHeld ? k_textOn : k_text).CGColor;+ for (int i = 0; i < KH_N; i++) {+ BOOL on = (_h2bits >> k_h2[i].b) & 1;+ BOOL armed = _h2 && k_h2[i].b == B_ZR && _h2omega; // the Ω latch glows while armed+ _h2key[i].fillColor = (on || armed ? k_on : k_idle).CGColor;+ if (_h2label[i]) _h2label[i].foregroundColor = (on || armed ? k_textOn : k_text).CGColor;+ }for (int i = 0; i < 2; i++) {CGPoint h = [self stickHome:i], o = [self knobOffset:i];_knob[i].position = CGPointMake(h.x + o.x, h.y + o.y); _knob[i].fillColor = (_stick[i] ? k_on : k_idle).CGColor;}+ // the H2 floating base: hidden with no stick finger, drawn at its origin with the knob when held+ BOOL h2s = _h2 && _h2stick != nil;+ _ring[0].hidden = !h2s; _knob[0].hidden = !h2s;+ if (h2s) {+ CGFloat R = KH_STICK_R * self.u, k = K_KNOB_R * self.u;+ setPath(_ring[0], circlePath(_h2origin, R));+ _knob[0].bounds = CGRectMake(0, 0, 2 * k, 2 * k);+ setPath(_knob[0], circlePath(CGPointMake(k, k), k));+ CAShapeLayer *in = (CAShapeLayer *)_knob[0].sublayers.firstObject; CGPathRef ip = circlePath(CGPointMake(k, k), k * 0.62);+ in.frame = _knob[0].bounds; in.path = ip; CGPathRelease(ip);+ CGPoint o = [self h2knobOffset];+ _knob[0].position = CGPointMake(_h2origin.x + o.x, _h2origin.y + o.y);+ _knob[0].fillColor = k_on.CGColor;+ }[CATransaction commit];}diff --git a/dm/ios/tools/build_ipa.sh b/dm/ios/tools/build_ipa.shindex 349f1256..ab2b032d 100755--- a/dm/ios/tools/build_ipa.sh+++ b/dm/ios/tools/build_ipa.sh@@ -77,6 +77,11 @@ APP=$DD/Build/Products/Release-iphoneos/DmIOS.app; [ -d "$APP" ] || APP=$(grep -# the app sets DM_AOC_DIR at launch, the host reports them as owned and mounts them from it) and the RomFSrm -rf "$APP/msl" "$O/Payload" "$O/out.ipa" # (the last two: what the copy-and-zip packing left behind)P=Payload/DmIOS.app; MAPS=("$P=$APP" "$P/msl/$MSLDIR=$MSL_IOS/$MSLDIR")+# Hades II layout: the virtual pad's combat keys draw the game profile's own glyphs when the+# profile ships them (dm/games/<id>/pad_icons/<name>.png; see DmGamepad.m's H2 block). Copy the+# folder into the app so h2_icon() finds it; without it the keys fall back to letters.+ICONDIR="$DM/games/$GAME/pad_icons"+if [ -d "$ICONDIR" ]; then mkdir -p "$APP/dm/pad_icons" && cp "$ICONDIR"/*.png "$APP/dm/pad_icons/" && t "pad icons: $(ls "$ICONDIR" | wc -l | tr -d ' ') glyphs from $ICONDIR"; fi# Increased Memory Limit: the build is unsigned, so Xcode never merges Sources/DmIOS.entitlements# into a signature. A sideloader reads the entitlements it should keep from the signature it is# replacing — an unsigned binary has none, so the request would be lost. Embed them with an ad-hoc