Skip to content

Commit

Permalink
Add Chatter Editor (#4101)
Browse files Browse the repository at this point in the history
* Add Chatter accessors

* Add Chatter Editor

* Update translations
  • Loading branch information
abcboy101 authored Dec 18, 2023
1 parent 30f3354 commit 69cd345
Show file tree
Hide file tree
Showing 26 changed files with 879 additions and 20 deletions.
3 changes: 2 additions & 1 deletion PKHeX.Core/Saves/Access/ISaveBlock5BW.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace PKHeX.Core;
namespace PKHeX.Core;

/// <summary>
/// Interface for Accessing named blocks within a Generation 5 save file.
Expand All @@ -9,6 +9,7 @@ public interface ISaveBlock5BW
Zukan5 Zukan { get; }
Misc5 Misc { get; }
MysteryBlock5 Mystery { get; }
Chatter5 Chatter { get; }
Daycare5 Daycare { get; }
BoxLayout5 BoxLayout { get; }
PlayerData5 PlayerData { get; }
Expand Down
1 change: 1 addition & 0 deletions PKHeX.Core/Saves/Access/SaveBlockAccessor5B2W2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public sealed class SaveBlockAccessor5B2W2(SAV5B2W2 sav)
public MyItem Items { get; } = new MyItem5B2W2(sav, 0x18400);
public UnityTower5 UnityTower { get; } = new(sav, 0x19600);
public MysteryBlock5 Mystery { get; } = new(sav, 0x1C800);
public Chatter5 Chatter { get; } = new(sav, 0x1D500);
public Musical5 Musical { get; } = new(sav, 0x1F700);
public Daycare5 Daycare { get; } = new(sav, 0x20D00);
public Misc5 Misc { get; } = new Misc5B2W2(sav, 0x21100);
Expand Down
1 change: 1 addition & 0 deletions PKHeX.Core/Saves/Access/SaveBlockAccessor5BW.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public sealed class SaveBlockAccessor5BW(SAV5BW sav) : ISaveBlockAccessor<BlockI
public PlayerData5 PlayerData { get; } = new(sav, 0x19400);
public UnityTower5 UnityTower { get; } = new(sav, 0x19600);
public MysteryBlock5 Mystery { get; } = new(sav, 0x1C800);
public Chatter5 Chatter { get; } = new(sav, 0x1D500);
public Musical5 Musical { get; } = new(sav, 0x1F700);
public Daycare5 Daycare { get; } = new(sav, 0x20E00);
public Misc5 Misc { get; } = new Misc5BW(sav, 0x21200);
Expand Down
3 changes: 2 additions & 1 deletion PKHeX.Core/Saves/SAV4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ private int GetActiveExtraBlock(BlockInfo4 block)
protected int WondercardFlags = int.MinValue;
protected int AdventureInfo = int.MinValue;
protected int Seal = int.MinValue;
public int Geonet = int.MinValue;
public int Chatter { get; protected set; } = int.MinValue;
public int Geonet { get; protected set; } = int.MinValue;
protected int Extra = int.MinValue;
protected int Trainer1;
public int GTS { get; protected set; } = int.MinValue;
Expand Down
1 change: 1 addition & 0 deletions PKHeX.Core/Saves/SAV4DP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private void GetSAVOffsets()
Trainer1 = 0x64;
Party = 0x98;
PokeDex = 0x12DC;
Chatter = 0x61CC;
Geonet = 0x96D8;
WondercardFlags = 0xA6D0;
WondercardData = 0xA7fC;
Expand Down
1 change: 1 addition & 0 deletions PKHeX.Core/Saves/SAV4HGSS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private void GetSAVOffsets()
Party = 0x98;
PokeDex = 0x12B8;
Extra = 0x230C;
Chatter = 0x4E74;
Geonet = 0x8D44;
WondercardFlags = 0x9D3C;
WondercardData = 0x9E3C;
Expand Down
1 change: 1 addition & 0 deletions PKHeX.Core/Saves/SAV4Pt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private void GetSAVOffsets()
Party = 0xA0;
PokeDex = 0x1328;
Extra = 0x2820;
Chatter = 0x64EC;
Geonet = 0xA4C4;
WondercardFlags = 0xB4C0;
WondercardData = 0xB5C0;
Expand Down
1 change: 1 addition & 0 deletions PKHeX.Core/Saves/SAV5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public EntreeForest EntreeData
public abstract Zukan5 Zukan { get; }
public abstract Misc5 Misc { get; }
public abstract MysteryBlock5 Mystery { get; }
public abstract Chatter5 Chatter { get; }
public abstract Daycare5 Daycare { get; }
public abstract BoxLayout5 BoxLayout { get; }
public abstract PlayerData5 PlayerData { get; }
Expand Down
1 change: 1 addition & 0 deletions PKHeX.Core/Saves/SAV5B2W2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private void Initialize()
public override Zukan5 Zukan => Blocks.Zukan;
public override Misc5 Misc => Blocks.Misc;
public override MysteryBlock5 Mystery => Blocks.Mystery;
public override Chatter5 Chatter => Blocks.Chatter;
public override Daycare5 Daycare => Blocks.Daycare;
public override BoxLayout5 BoxLayout => Blocks.BoxLayout;
public override PlayerData5 PlayerData => Blocks.PlayerData;
Expand Down
1 change: 1 addition & 0 deletions PKHeX.Core/Saves/SAV5BW.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private void Initialize()
public override Zukan5 Zukan => Blocks.Zukan;
public override Misc5 Misc => Blocks.Misc;
public override MysteryBlock5 Mystery => Blocks.Mystery;
public override Chatter5 Chatter => Blocks.Chatter;
public override Daycare5 Daycare => Blocks.Daycare;
public override BoxLayout5 BoxLayout => Blocks.BoxLayout;
public override PlayerData5 PlayerData => Blocks.PlayerData;
Expand Down
37 changes: 37 additions & 0 deletions PKHeX.Core/Saves/Substructures/Gen4/Chatter4.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using static System.Buffers.Binary.BinaryPrimitives;

namespace PKHeX.Core;

/// <summary>
/// Generation 4 Chatter Recording
/// </summary>
public sealed class Chatter4: IChatter
{
private readonly SAV4 SAV;
private readonly int Offset;

public Chatter4(SaveFile sav)
{
SAV = (SAV4)sav;
Offset = SAV.Chatter;
}

public bool Initialized
{
get => ReadUInt32LittleEndian(SAV.General[Offset..]) == 1u;
set => WriteUInt32LittleEndian(SAV.General[Offset..], value ? 1u : 0u);
}

public Span<byte> Recording => SAV.General.Slice(Offset + sizeof(uint), IChatter.SIZE_PCM);

public int ConfusionChance
{
get => !Initialized ? 1 : (sbyte)Recording[15] switch
{
< -30 => 11,
>= 30 => 31,
_ => 1,
};
}
}
29 changes: 29 additions & 0 deletions PKHeX.Core/Saves/Substructures/Gen5/Chatter5.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using static System.Buffers.Binary.BinaryPrimitives;

namespace PKHeX.Core;

/// <summary>
/// Generation 5 Chatter Recording
/// </summary>
public sealed class Chatter5 : SaveBlock<SAV5>, IChatter
{
public Chatter5(SAV5 SAV, int offset) : base(SAV) => Offset = offset;

public bool Initialized
{
get => ReadUInt32LittleEndian(Data.AsSpan(Offset)) == 1u;
set => WriteUInt32LittleEndian(Data.AsSpan(Offset), value ? 1u : 0u);
}

public Span<byte> Recording => Data.AsSpan(Offset + sizeof(uint), IChatter.SIZE_PCM);

public int ConfusionChance
{
get => !Initialized ? 0 : (Recording[99] ^ Recording[499] ^ Recording[699]) switch
{
< 100 or >= 150 => 10,
_ => 0,
};
}
}
15 changes: 15 additions & 0 deletions PKHeX.Core/Saves/Substructures/Misc/IChatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Reflection.Metadata;

namespace PKHeX.Core;

/// <summary>
/// Generation 4/5 Chatter Recording
/// </summary>
public interface IChatter
{
public const int SIZE_PCM = 1000; // 0x3E8
public bool Initialized { get; set; }
public Span<byte> Recording { get; }
public int ConfusionChance { get; }
}
14 changes: 14 additions & 0 deletions PKHeX.WinForms/Controls/SAV Editor/SAVEditor.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ private static void OpenDialog(Form f)
private void B_OpenHoneyTreeEditor_Click(object sender, EventArgs e) => OpenDialog(new SAV_HoneyTree((SAV4Sinnoh)SAV));
private void B_OpenGeonetEditor_Click(object sender, EventArgs e) => OpenDialog(new SAV_Geonet4((SAV4)SAV));
private void B_OpenUnityTowerEditor_Click(object sender, EventArgs e) => OpenDialog(new SAV_UnityTower((SAV5)SAV));
private void B_OpenChatterEditor_Click(object sender, EventArgs e) => OpenDialog(new SAV_Chatter(SAV));

private void B_Roamer_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -1157,6 +1158,7 @@ private void ToggleViewSubEditors(SaveFile sav)
B_OpenUGSEditor.Visible = sav is SAV4Sinnoh or SAV8BS;
B_OpenGeonetEditor.Visible = sav is SAV4;
B_OpenUnityTowerEditor.Visible = sav is SAV5;
B_OpenChatterEditor.Visible = sav is SAV4 or SAV5;
B_OpenSealStickers.Visible = B_Poffins.Visible = sav is SAV8BS;
B_OpenApricorn.Visible = sav is SAV4HGSS;
B_OpenRTCEditor.Visible = sav.Generation == 2 || sav is IGen3Hoenn;
Expand Down
Loading

0 comments on commit 69cd345

Please sign in to comment.