Extract g7 wild dump to pk3ds.core

This commit is contained in:
Kurt 2020-10-10 17:48:18 -07:00
parent f11e91b55c
commit b6bea36fac
6 changed files with 112 additions and 89 deletions

View File

@ -1,11 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using pk3DS.Core;
using pk3DS.Core.CTR;
using pk3DS.Core.Structures;
namespace pk3DS
namespace pk3DS.Core
{
public class Area7
{

View File

@ -1,6 +1,6 @@
using System.Text;
namespace pk3DS
namespace pk3DS.Core
{
public class Encounter7
{
@ -22,5 +22,7 @@ public string GetSummary(string[] speciesList)
sb.Append($" (Forme {Forme})");
return sb.ToString();
}
public uint Dump(EncounterTable t) => RawValue | (uint)(t.MinLevel << 16) | (uint)(t.MaxLevel << 24);
}
}

View File

@ -3,7 +3,7 @@
using System.Linq;
using System.Text;
namespace pk3DS
namespace pk3DS.Core
{
public class EncounterTable
{

View File

@ -0,0 +1,105 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using pk3DS.Core.Structures.PersonalInfo;
namespace pk3DS.Core
{
public static class Gen7SlotDumper
{
public static byte[][] GetRegularBinary(Area7[] areas)
{
var dict = DumpAreas(areas);
return GetLocationDump(dict).ToArray();
}
public static byte[][] GetSOSBinary(Area7[] areas, PersonalTable personal)
{
var dict = DumpAreas(areas, personal);
return GetLocationDump(dict).ToArray();
}
private static Dictionary<int, List<uint>> DumpAreas(Area7[] areas, PersonalTable personal)
{
var dict = new Dictionary<int, List<uint>>();
for (var areaIndex = 0; areaIndex < areas.Length; areaIndex++)
{
var area = areas[areaIndex];
for (var zoneIndex = 0; zoneIndex < area.Zones.Length; zoneIndex++)
{
var z = area.Zones[zoneIndex];
int loc = z.ParentMap;
if (!dict.ContainsKey(loc))
dict.Add(loc, new List<uint>());
var table = dict[loc];
for (var x = 0; x < area.Tables.Count; x++)
{
var t = area.Tables[x];
var first = t.Encounter7s[0];
for (int i = 0; i < first.Length; i++)
{
// Only add the column SOS slots if the wild slot can SOS for help.
var wild = first[i];
if (personal[(int)wild.Species].EscapeRate == 0)
continue;
for (int j = 1; j < t.Encounter7s.Length - 1; j++)
table.Add(t.Encounter7s[j][i].Dump(t));
}
foreach (var s in t.AdditionalSOS)
table.Add(s.Dump(t));
}
}
}
return dict;
}
private static Dictionary<int, List<uint>> DumpAreas(Area7[] areas)
{
var dict = new Dictionary<int, List<uint>>();
for (var areaIndex = 0; areaIndex < areas.Length; areaIndex++)
{
var area = areas[areaIndex];
for (var zoneIndex = 0; zoneIndex < area.Zones.Length; zoneIndex++)
{
var z = area.Zones[zoneIndex];
int loc = z.ParentMap;
if (!dict.ContainsKey(loc))
dict.Add(loc, new List<uint>());
var table = dict[loc];
for (var tableIndex = 0; tableIndex < area.Tables.Count; tableIndex++)
{
var t = area.Tables[tableIndex];
var first = t.Encounter7s[0];
for (int i = 0; i < first.Length; i++)
{
// Only add the column SOS slots if the wild slot can SOS for help.
var wild = first[i];
table.Add(wild.Dump(t));
}
}
}
}
return dict;
}
private static IEnumerable<byte[]> GetLocationDump(Dictionary<int, List<uint>> dict)
{
foreach (var z in dict.OrderBy(z => z.Key))
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
bw.Write((ushort)z.Key);
foreach (var s in z.Value.Distinct())
bw.Write(s);
yield return ms.ToArray();
}
}
}
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
@ -493,92 +492,13 @@ public static string[] GetGoodLocationList(string[] list)
private void ExportEncounters(string gameID, string ident)
{
var reg = DumpRegular();
var sos = DumpSOS();
var reg = Gen7SlotDumper.GetRegularBinary(Areas);
var sos = Gen7SlotDumper.GetSOSBinary(Areas, Main.Config.Personal);
File.WriteAllBytes($"encounter_{gameID}.pkl", Mini.PackMini(reg, ident));
File.WriteAllBytes($"encounter_{gameID}_sos.pkl", Mini.PackMini(sos, ident));
}
private byte[][] DumpRegular()
{
var dict = new Dictionary<int, List<uint>>();
foreach (var area in Areas)
{
foreach (var z in area.Zones)
{
int loc = z.ParentMap;
if (!dict.ContainsKey(loc))
dict.Add(loc, new List<uint>());
var table = dict[loc];
table.AddRange(from t in area.Tables
from s in t.Encounter7s.Take(1)
from e in s
select e.RawValue | (uint)(t.MinLevel << 16) | (uint)(t.MaxLevel << 24));
}
}
return GetLocationDump(dict).ToArray();
}
private byte[][] DumpSOS()
{
var personal = Main.Config.Personal;
var dict = new Dictionary<int, List<uint>>();
foreach (var area in Areas)
{
foreach (var z in area.Zones)
{
int loc = z.ParentMap;
if (!dict.ContainsKey(loc))
dict.Add(loc, new List<uint>());
var table = dict[loc];
foreach (var t in area.Tables)
{
var first = t.Encounter7s[0];
for (int i = 0; i < first.Length; i++)
{
// Only add the column SOS slots if the wild slot can SOS for help.
var wild = first[i];
if (personal[(int)wild.Species].EscapeRate == 0)
continue;
for (int j = 1; j < t.Encounter7s.Length - 1; j++)
{
var e = t.Encounter7s[j][i];
var val = e.RawValue | (uint) (t.MinLevel << 16) | (uint) (t.MaxLevel << 24);
table.Add(val);
}
}
}
table.AddRange(from t in area.Tables
from e in t.AdditionalSOS
select e.RawValue | (uint) (t.MinLevel << 16) | (uint) (t.MaxLevel << 24));
}
}
return GetLocationDump(dict).ToArray();
}
private static IEnumerable<byte[]> GetLocationDump(Dictionary<int, List<uint>> dict)
{
foreach (var z in dict.OrderBy(z => z.Key))
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
bw.Write((ushort)z.Key);
foreach (var s in z.Value.Distinct())
bw.Write(s);
yield return ms.ToArray();
}
}
}
private void SMWE_FormClosing(object sender, FormClosingEventArgs e)
{
RandSettings.SetFormSettings(this, GB_Tweak.Controls);

View File

@ -86,9 +86,6 @@
<Compile Include="Subforms\Gen7\TutorEditor7.Designer.cs">
<DependentUpon>TutorEditor7.cs</DependentUpon>
</Compile>
<Compile Include="Subforms\Gen7\Wild\Area7.cs" />
<Compile Include="Subforms\Gen7\Wild\Encounter7.cs" />
<Compile Include="Subforms\Gen7\Wild\EncounterTable.cs" />
<Compile Include="Subforms\Gen7\Wild\Wild7Randomizer.cs" />
<Compile Include="Tools\RandSettings.cs" />
<Compile Include="WinFormsUtil.cs" />