# Xbox 360 avatars in Xbox 360 homebrew

To show Xbox 360 avatars in your own Xbox 360 homebrew, download the SDK with `xbox360` as the platform, link
`libsona.a` into an xsdk title and include `sona_xsdk.h`, and a few calls put the signed-in player on the TV in their
own avatar. The titles build and run in Xenia Canary; none has been run on a console.

![sona-plaza in Xenia: the player, found by gamertag, with six of the cast walking round](../img/xbox360-plaza.webp)

## Steps

1. Build [xsdk](https://github.com/xenosworks/xsdk), the MIT homebrew SDK for the console's retail kernel, and its
   toolchain, as its own getting started says. You need Linux (Debian on its own or in WSL), CMake 3.25 or later and
   Ninja.
2. Download the SDK for your app with `xbox360` as the platform ([install](../install.md)), and unzip it.
3. Build the sample titles from the download's folder with CMake and xsdk's toolchain file
   ([building](../guides/xbox360.md#building)). The build puts your `sona-licence.json` inside every `.xex`.
4. Copy the `.xex` to the console's hard drive, into a folder of its own, and launch it from Aurora's file browser.

It needs an RGH or JTAG console with a dashboard that launches unsigned titles (Aurora, FreeStyle Dash or XeXMenu).
Every item streams from 360sona over HTTPS, so your title carries no Microsoft files.

## Your first title

The heart of `samples/x360/hello.c`, which builds `sona-hello`:

```c
int main(void) {
  sona_xsdk_config c;
  sona_xsdk *sx;
  sona_avatar *me;
  sona_view view;
  sona_emote wave;
  int shown = 0, shot = SONA_PRESET_FULL;

  sona_xsdk_defaults(&c);
  if (sona_xsdk_open(&c, &sx) != SONA_OK) return 1;
  if (sona_xsdk_add_player(sx, 0, NULL, &me) != SONA_OK) return 1;
  sona_xsdk_view(sx, &view);
  sona_emote_from_text("wave", &wave);
  while (sona_xsdk_frame(sx, &view)) {
    uint16_t pressed = sona_xsdk_pressed(sx);
    if (pressed & INPUT_GAMEPAD_A) sona_avatar_emote(me, &wave, 0.2f);
    if ((pressed & INPUT_GAMEPAD_DPAD_UP) && shot < SONA_PRESET_FACE) shot++;
    if ((pressed & INPUT_GAMEPAD_DPAD_DOWN) && shot > SONA_PRESET_FULL) shot--;
    if (sona_avatar_state_of(me) == SONA_AVATAR_READY) sona_camera_preset(me, (sona_preset)shot, &view);
```

`sona_xsdk_add_player` reads the avatar stored in the player's profile on the console first, and looks their gamertag
up on 360sona if it has none. Everything under these calls is `sona.h`, the same C API as on every platform.

## More

- [Xbox 360 homebrew](../guides/xbox360.md): every sample title, running in Xenia, memory and what the log says.
- If you run a title on your console, its log, `<title>.log` beside the `.xex`, says what happened; we'd like to see it.
- Credit: the library draws a small "Powered by 360sona" badge in a corner. If you turn it off, credit 360sona in
  your credits or about screen.
- 360sona is not affiliated with or endorsed by Microsoft.
