/// <summary> /// Gets the encounter areas with <see cref="EncounterSlot"/> information from Generation 1 Grass/Water data. /// </summary> /// <param name="data">Input raw data.</param> /// <param name="count">Count of areas in the binary.</param> /// <returns>Array of encounter areas.</returns> public static EncounterArea1[] GetArray1GrassWater(byte[] data, int count) { var areas = new List <EncounterArea1>(count); for (int i = 0; i < count; i++) { int ptr = BitConverter.ToInt16(data, i * 2); var g = new EncounterArea1 { Type = SlotType.Grass, Location = (short)i, }; var gslots = GetSlots1GrassWater(data, g, ref ptr); if (gslots.Length > 0) { areas.Add(g); g.Slots = gslots; } var w = new EncounterArea1 { Type = SlotType.Surf, Location = (short)i, }; var wslots = GetSlots1GrassWater(data, w, ref ptr); if (wslots.Length > 0) { areas.Add(w); w.Slots = wslots; } } return(areas.ToArray()); }
private static EncounterSlot1[] GetSlots1GrassWater(byte[] data, EncounterArea1 a, ref int ofs) { int rate = data[ofs++]; a.Rate = rate; return(rate == 0 ? Array.Empty <EncounterSlot1>() : EncounterSlot1.ReadSlots(data, ref ofs, 10, SlotType.Grass)); }
public static void DumpGen1() { var r = Resources.encounter_red; var b = Resources.encounter_blue; var y = Resources.encounter_yellow; var rbf = Resources.encounter_rb_f; var yf = Resources.encounter_yellow_f; var red_gw = EncounterArea1.GetArray1GrassWater(r, 248); var blu_gw = EncounterArea1.GetArray1GrassWater(b, 248); var ylw_gw = EncounterArea1.GetArray1GrassWater(y, 249); var rb_fish = EncounterArea1.GetArray1Fishing(rbf, 33); var ylw_fish = EncounterArea1.GetArray1FishingYellow(yf); foreach (var area in red_gw) { area.Location = DumpUtil.RBYLocIndexes[area.Location]; } foreach (var area in blu_gw) { area.Location = DumpUtil.RBYLocIndexes[area.Location]; } foreach (var area in ylw_gw) { area.Location = DumpUtil.RBYLocIndexes[area.Location]; } for (var i = 0; i < rb_fish.Length; i++) { rb_fish[i].Location = DumpUtil.RBFishIndexes[i]; } rb_fish = rb_fish.Where(z => z.Location != 0).ToArray(); // remove duplicate locations (cerulean gym same as cerulean city) for (var i = 0; i < ylw_fish.Length; i++) { ylw_fish[i].Location = DumpUtil.YFishIndexes[i]; } var rb = red_gw.Concat(rb_fish).OrderBy(z => z.Location).ThenBy(z => z.Type).ToArray(); var bb = blu_gw.Concat(rb_fish).OrderBy(z => z.Location).ThenBy(z => z.Type).ToArray(); var yb = ylw_gw.Concat(ylw_fish).OrderBy(z => z.Location).ThenBy(z => z.Type).ToArray(); Write(rb, "encounter_red.pkl"); Write(bb, "encounter_blue.pkl"); Write(yb, "encounter_yellow.pkl"); var jp_bu = DumpGen1JPBU(); Write(rb.Concat(bb).Concat(yb), jp_bu, "encounter_blue_jp.pkl"); }
public static byte[] Write(EncounterArea1 area) { using var ms = new MemoryStream(); using var bw = new BinaryWriter(ms); bw.Write(area.Location); bw.Write((byte)area.Type); bw.Write((byte)area.Rate); foreach (var slot in area.Slots.Cast <EncounterSlot1>()) { WriteSlot(bw, slot); } return(ms.ToArray()); }
/// <summary> /// Gets the encounter areas with <see cref="EncounterSlot"/> information from Generation 1 Fishing data. /// </summary> /// <param name="data">Input raw data.</param> /// <param name="count">Count of areas in the binary.</param> /// <returns>Array of encounter areas.</returns> public static EncounterArea1[] GetArray1Fishing(byte[] data, int count) { var areas = new EncounterArea1[count]; for (int i = 0; i < areas.Length; i++) { int loc = data[(i * 3) + 0]; int ptr = BitConverter.ToInt16(data, (i * 3) + 1); areas[i] = new EncounterArea1 { Location = (short)loc, Type = SlotType.Super_Rod, Slots = GetSlots1Fishing(data, ptr) }; } return(areas); }
/// <summary> /// Gets the encounter areas with <see cref="EncounterSlot"/> information from Pokémon Yellow (Generation 1) Fishing data. /// </summary> /// <param name="data">Input raw data.</param> /// <returns>Array of encounter areas.</returns> public static EncounterArea1[] GetArray1FishingYellow(byte[] data) { const int size = 9; int count = data.Length / size; EncounterArea1[] areas = new EncounterArea1[count]; for (int i = 0; i < count; i++) { int ofs = (i * size) + 1; areas[i] = new EncounterArea1 { Location = data[(i * size) + 0], Type = SlotType.Super_Rod, Slots = ReadSlots1FishingYellow(data, ref ofs, 4) }; } return(areas); }
public static IOrderedEnumerable <EncounterArea1> DumpGen1JPBU() { var b = Resources.encounter_blue_jp; var rbf = Resources.encounter_blue_jp_f; var blu_gw = EncounterArea1.GetArray1GrassWater(b, 248); var rb_fish = EncounterArea1.GetArray1Fishing(rbf, 33); foreach (var area in blu_gw) { area.Location = DumpUtil.RBYLocIndexes[area.Location]; } for (var i = 0; i < rb_fish.Length; i++) { rb_fish[i].Location = DumpUtil.RBFishIndexes[i]; } rb_fish = rb_fish.Where(z => z.Location != 0).ToArray(); // remove duplicate locations (cerulean gym same as cerulean city) return(blu_gw.Concat(rb_fish).OrderBy(z => z.Location).ThenBy(z => z.Type)); }