mirror of
https://github.com/AdAstra-LD/DS-Pokemon-Rom-Editor.git
synced 2026-05-09 12:51:54 -05:00
110 lines
3.6 KiB
C#
110 lines
3.6 KiB
C#
using DSPRE.ROMFiles;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
using static DSPRE.RomInfo;
|
|
|
|
namespace DSPRE {
|
|
public enum EvolutionMethod : ushort {
|
|
None = 0,
|
|
Friendship220 = 1,
|
|
Friendship220_Day = 2,
|
|
Friendship220_Night = 3,
|
|
LevelingUp = 4,
|
|
Trade = 5,
|
|
Trade_HeldItem = 6,
|
|
Item = 7,
|
|
Atk_Greater_Def = 8,
|
|
Atk_Equal_Def = 9,
|
|
Def_Greater_Atk = 10,
|
|
Personality1 = 11,
|
|
Personality2 = 12,
|
|
FreeSpaceCheck = 13,
|
|
Shedinja = 14,
|
|
BeautyThreshold = 15,
|
|
ItemMale = 16,
|
|
ItemFemale = 17,
|
|
HeldItem_Day = 18,
|
|
HeldItem_Night = 19,
|
|
KnowsMove = 20,
|
|
PartyPokemonPresence = 21,
|
|
LevelingUp_Male = 22,
|
|
LevelingUp_Female = 23,
|
|
|
|
Loc_MtCoronet = LevelingUp_Female + 1,
|
|
Loc_EternaForest = LevelingUp_Female + 2,
|
|
Loc_Route217 = LevelingUp_Female + 3
|
|
}
|
|
public struct EvolutionData {
|
|
public EvolutionMethod method;
|
|
public ushort param;
|
|
public ushort target;
|
|
|
|
public bool isValid() {
|
|
if (method == EvolutionMethod.None) {
|
|
return false;
|
|
}
|
|
|
|
if (method == EvolutionMethod.LevelingUp ||
|
|
method == EvolutionMethod.LevelingUp_Male ||
|
|
method == EvolutionMethod.LevelingUp_Female) {
|
|
|
|
return param > 0 && param <= 100;
|
|
}
|
|
|
|
if (target == 0) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
public class EvolutionFile : RomFile {
|
|
public const int numEvolutions = 7;
|
|
|
|
public EvolutionData[] data;
|
|
|
|
public EvolutionFile(Stream stream) {
|
|
data = new EvolutionData[numEvolutions];
|
|
|
|
using (BinaryReader reader = new BinaryReader(stream)) {
|
|
for (int i = 0; i < numEvolutions; i++) {
|
|
data[i].method = (EvolutionMethod)reader.ReadUInt16();
|
|
data[i].param = reader.ReadUInt16();
|
|
data[i].target = reader.ReadUInt16();
|
|
}
|
|
}
|
|
}
|
|
|
|
public EvolutionFile(int ID) : this(new FileStream(RomInfo.gameDirs[DirNames.evolutions].unpackedDir + "\\" + ID.ToString("D4"), FileMode.Open)) { }
|
|
|
|
public override byte[] ToByteArray() {
|
|
using (MemoryStream memoryStream = new MemoryStream()) {
|
|
using (BinaryWriter writer = new BinaryWriter(memoryStream)) {
|
|
foreach (EvolutionData evData in data) {
|
|
if (evData.isValid()) {
|
|
writer.Write((ushort)evData.method);
|
|
writer.Write(evData.param);
|
|
writer.Write(evData.target);
|
|
}
|
|
}
|
|
|
|
//If the file is smaller than the minimum size, pad it with 00
|
|
int size = Marshal.SizeOf(typeof(EvolutionData));
|
|
int minSize = numEvolutions * size + 2; //2B pad
|
|
if (memoryStream.Length < minSize) {
|
|
memoryStream.SetLength(minSize);
|
|
}
|
|
|
|
}
|
|
return memoryStream.ToArray();
|
|
}
|
|
}
|
|
|
|
public void SaveToFileDefaultDir(int IDtoReplace, bool showSuccessMessage = true) {
|
|
SaveToFileDefaultDir(DirNames.evolutions, IDtoReplace, showSuccessMessage);
|
|
}
|
|
public void SaveToFileExplorePath(string suggestedFileName, bool showSuccessMessage = true) {
|
|
SaveToFileExplorePath("Gen IV Evolution data", "bin", suggestedFileName, showSuccessMessage);
|
|
}
|
|
}
|
|
} |