2018-11-16 01:36:29 +00:00
|
|
|
|
using System;
|
2018-11-15 03:34:21 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-11-15 06:02:01 +00:00
|
|
|
|
using System.Text;
|
2018-11-15 03:34:21 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2018-11-16 01:36:29 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Go Park Entity transferred to <see cref="GameVersion.GG"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class GP1
|
2018-11-15 03:34:21 +00:00
|
|
|
|
{
|
|
|
|
|
public const int SIZE = 0x1B0;
|
2018-11-15 06:02:01 +00:00
|
|
|
|
public byte[] Data { get; }
|
2018-11-16 01:36:29 +00:00
|
|
|
|
public GP1() => Data = (byte[])Blank.Clone();
|
2018-11-15 03:34:21 +00:00
|
|
|
|
public void WriteTo(byte[] data, int offset) => Data.CopyTo(data, offset);
|
|
|
|
|
|
2018-11-22 04:48:55 +00:00
|
|
|
|
public GP1(byte[] data) => Data = data;
|
|
|
|
|
|
2018-11-16 01:36:29 +00:00
|
|
|
|
public static GP1 FromData(byte[] data, int offset)
|
2018-11-15 03:34:21 +00:00
|
|
|
|
{
|
2018-11-16 01:36:29 +00:00
|
|
|
|
var gpkm = new GP1();
|
2018-11-15 03:34:21 +00:00
|
|
|
|
Array.Copy(data, offset, gpkm.Data, 0, SIZE);
|
|
|
|
|
return gpkm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static readonly byte[] Blank20 =
|
|
|
|
|
{
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x80, 0x3F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F,
|
|
|
|
|
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x85, 0xEC, 0x33, 0x01,
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-15 06:02:01 +00:00
|
|
|
|
public static readonly byte[] Blank = GetBlank();
|
|
|
|
|
|
2018-11-15 03:34:21 +00:00
|
|
|
|
public static byte[] GetBlank()
|
|
|
|
|
{
|
|
|
|
|
byte[] data = new byte[SIZE];
|
|
|
|
|
Blank20.CopyTo(data, 0x20);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
2018-11-15 06:02:01 +00:00
|
|
|
|
|
|
|
|
|
public string Username1 => Util.TrimFromZero(Encoding.ASCII.GetString(Data, 0x00, 0x10));
|
|
|
|
|
public string Username2 => Util.TrimFromZero(Encoding.ASCII.GetString(Data, 0x10, 0x20));
|
|
|
|
|
|
2018-11-18 21:54:47 +00:00
|
|
|
|
public int Species => BitConverter.ToInt32(Data, 0x28);
|
2018-11-21 23:25:50 +00:00
|
|
|
|
public int CP => BitConverter.ToInt32(Data, 0x2C);
|
2018-11-15 06:02:01 +00:00
|
|
|
|
public float LevelF => BitConverter.ToSingle(Data, 0x30);
|
|
|
|
|
public int Level => Math.Max(1, (int)Math.Round(LevelF));
|
|
|
|
|
|
|
|
|
|
public int IV1 => BitConverter.ToInt32(Data, 0x50);
|
|
|
|
|
public int IV2 => BitConverter.ToInt32(Data, 0x54);
|
|
|
|
|
public int IV3 => BitConverter.ToInt32(Data, 0x58);
|
2018-11-21 23:25:50 +00:00
|
|
|
|
public int Date => BitConverter.ToInt32(Data, 0x5C); // ####.##.## YYYY.MM.DD
|
|
|
|
|
public int Year => Date / 1_00_00;
|
|
|
|
|
public int Month => (Date / 1_00) % 1_00;
|
|
|
|
|
public int Day => Date % 1_00;
|
2018-11-15 06:02:01 +00:00
|
|
|
|
|
|
|
|
|
public int Gender => Data[0x70] - 1; // M=1, F=2, G=3 ;; shift down by 1.
|
|
|
|
|
|
2018-11-18 21:54:47 +00:00
|
|
|
|
public int AltForm => Data[0x72];
|
2018-11-16 01:36:29 +00:00
|
|
|
|
public bool IsShiny => Data[0x73] == 1;
|
2018-11-15 06:02:01 +00:00
|
|
|
|
|
|
|
|
|
// https://bulbapedia.bulbagarden.net/wiki/List_of_moves_in_Pok%C3%A9mon_GO
|
|
|
|
|
public int Move1 => BitConverter.ToInt32(Data, 0x74); // uses Go Indexes
|
|
|
|
|
public int Move2 => BitConverter.ToInt32(Data, 0x78); // uses Go Indexes
|
|
|
|
|
|
|
|
|
|
public string GeoCityName => Util.TrimFromZero(Encoding.ASCII.GetString(Data, 0x7C, 0x60)); // dunno length
|
|
|
|
|
|
|
|
|
|
public string Nickname => Util.TrimFromZero(Encoding.ASCII.GetString(Data, 0x12D, 0x20)); // dunno length
|
|
|
|
|
|
|
|
|
|
public static readonly string[] Genders = {"M", "F", "-"};
|
|
|
|
|
public string GenderString => (uint) Gender >= Genders.Length ? string.Empty : Genders[Gender];
|
2018-11-16 01:36:29 +00:00
|
|
|
|
public string ShinyString => IsShiny ? "★ " : string.Empty;
|
2018-11-21 23:25:50 +00:00
|
|
|
|
public string FileName => $"{ShinyString}{Nickname} lv{Level} - {IV1:00}.{IV2:00}.{IV3:00}, Move1 {Move1}, Move2 {Move2} (CP {CP}).gp1";
|
2018-11-18 21:54:47 +00:00
|
|
|
|
public string FormString => AltForm != 0 ? $"-{AltForm}" : string.Empty;
|
2018-11-16 01:36:29 +00:00
|
|
|
|
|
2018-11-21 23:25:50 +00:00
|
|
|
|
public string GeoTime => $"Captured in {GeoCityName} by {Username1} on {Year}/{Month}/{Day}";
|
|
|
|
|
public string StatMove => $"{IV1:00}/{IV2:00}/{IV3:00}, Move1 {Move1}, Move2 {Move2}, CP={CP}";
|
|
|
|
|
public string Dump(IReadOnlyList<string> speciesNames, int index) => $"{index:000} {Nickname} ({speciesNames[Species]}{FormString} {ShinyString}[{GenderString}]) @ lv{Level} - {StatMove}, {GeoTime}.";
|
2018-11-22 04:48:55 +00:00
|
|
|
|
|
|
|
|
|
public PB7 ConvertToPB7(ITrainerInfo sav)
|
|
|
|
|
{
|
|
|
|
|
var pk = new PB7
|
|
|
|
|
{
|
|
|
|
|
Version = (int) GameVersion.GO,
|
|
|
|
|
Species = Species,
|
|
|
|
|
AltForm = AltForm,
|
|
|
|
|
Gender = Gender,
|
|
|
|
|
Met_Location = 50, // Go complex
|
|
|
|
|
Met_Year = Year - 2000,
|
|
|
|
|
Met_Month = Month,
|
|
|
|
|
Met_Day = Day,
|
|
|
|
|
Nickname = Nickname,
|
|
|
|
|
CurrentLevel = Level,
|
|
|
|
|
Met_Level = Level,
|
|
|
|
|
TID = sav.TID,
|
|
|
|
|
SID = sav.SID,
|
|
|
|
|
OT_Name = sav.OT,
|
|
|
|
|
Ball = 4,
|
|
|
|
|
Language = sav.Language,
|
|
|
|
|
Nature = Util.Rand.Next(25),
|
|
|
|
|
PID = Util.Rand32(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var nick = PKX.GetSpeciesNameGeneration(Species, sav.Language, 7);
|
|
|
|
|
if (nick != Nickname)
|
|
|
|
|
pk.IsNicknamed = true;
|
|
|
|
|
|
|
|
|
|
pk.IV_DEF = pk.IV_SPD = (IV3 * 2) + 1;
|
|
|
|
|
pk.IV_ATK = pk.IV_SPA = (IV2 * 2) + 1;
|
|
|
|
|
pk.IV_HP = (IV1 * 2) + 1;
|
|
|
|
|
pk.IV_SPE = Util.Rand.Next(32);
|
|
|
|
|
|
|
|
|
|
pk.RefreshAbility(Util.Rand.Next(2));
|
|
|
|
|
if (IsShiny)
|
|
|
|
|
pk.SetShiny();
|
|
|
|
|
|
|
|
|
|
var moves = MoveLevelUp.GetEncounterMoves(pk, Level, GameVersion.GO);
|
|
|
|
|
pk.Moves = moves;
|
|
|
|
|
pk.SetMaximumPPCurrent(moves);
|
|
|
|
|
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
|
|
|
|
|
|
|
|
|
pk.HeightScalar = Util.Rand.Next(0x100);
|
|
|
|
|
pk.WeightScalar = Util.Rand.Next(0x100);
|
|
|
|
|
|
|
|
|
|
pk.AwakeningSetAllTo(2);
|
|
|
|
|
pk.ResetCalculatedValues();
|
|
|
|
|
|
|
|
|
|
pk.SetRandomEC();
|
|
|
|
|
return pk;
|
|
|
|
|
}
|
2018-11-15 03:34:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|