Jump to content

Recommended Posts

Posted (edited)

Ok, I was looking at my save file from Pokemon ultra sun in HxD Hex Editor, Since PKHex has the part HEX in it I assumed the file was in a hex format, yet when I open the file in HxD Hex Editor it is just a garbled mess, So I downloaded the source code for PKHex to see if I could find the C# code that can read the save file. Does anyone know where this decode file is or how I can decode the files, let's say into a set of variables on a text editor? Like this:

PlayerName="Eric"
Pokemon1={
Name="Rockruff"
....
}
.....

What I overall want to use this for is to read the stats of pokemon in my save file and do some calculations with it in a C++ program because I don't want to have to enter in all the stats of the pokemon every time I want to use the program. Also if there is a decoder file for all the type of save files written in C# is there a way I can use that in C++? Sorry about the crazy amount of questions...

EDIT: Ok it seems that the decoded file is here: "D:\Semi_Desktop\PKHeX-master\PKHeX.Core\PKM\PKM.cs" not really sure though.

Edited by Computer Eric
Posted

PKHeX doesn't do full deserialization of the pkm/sav files, it only gets/sets data on demand.

PKM.cs is the base abstraction of the PK* format, with multiple different formats of storing the data across generations (ie PK1/PK2...PK7...).

SaveFile.cs is the base abstraction of save files, with multiple different formats of storing the data across generations (ie SAV1/SAV2...SAV7...).

 

PKHeX.Core.dll is the class library the GUI uses to power most of the pkm/sav data manipulation. If you add it as a reference to a (.NET language) project, you can use its api to automate your edits. PKHeX also offers plugin capability, where you can program your own toolkit and launch various operations.

  • Like 1
Posted

Sorry, I'm sort of new to the C++ and C#  coding languages, Correct me if I'm wrong but your saying 1, PKHex doesn't decrypt the full Sav/Pkm file all at once, just parts and sections, And PKM.cs is used to decrypt and encrypt the PK files for the all the types of generations, same with the SaveFile.cs being it decrypts and encrypts the save files for the all the types of generations as well. I don't know much about .dll files but from what I can tell your saying I can add it to a .NET project, and from google it says .NET is used in C++, so Is there any way to reference this code in a C++ project. I assume I am getting everything wrong here too, but Is there any program or way I can decrypt the whole save file at once? And from what you said about how I can use its API to automate my edit, like reading, for example, part of the file? I am probably not making any sense at all, and this is probably a lost cause. But if you having any idea what I'm saying and can help then that would be great. If I'm making no sense to you the also say so. :)

Posted
13 minutes ago, Computer Eric said:

PKHex doesn't decrypt the full Sav/Pkm file all at once, just parts and sections,

If you feed it a encrypted pkm, it will decrypt it and provide you with values as you ask for them.

13 minutes ago, Computer Eric said:

And PKM.cs is used to decrypt and encrypt the PK files for the all the types of generations, same with the SaveFile.cs being it decrypts and encrypts the save files for the all the types of generations as well.

Most of the shared logic is in PKX.cs, and SaveUtil.cs

Basically the program reads the data, then various utility functions bend it into usable shape.

13 minutes ago, Computer Eric said:

I can add it to a .NET project, and from google it says .NET is used in C++, so Is there any way to reference this code in a C++ project.

Probably, but I'd advise against using multiple languages that you are unfamiliar with in the same project.

13 minutes ago, Computer Eric said:

I assume I am getting everything wrong here too, but Is there any program or way I can decrypt the whole save file at once?

If 'decrypt' means deserialize, then yes, you could use serialization with the pkm/sav by exporting it to json or whatnot.

13 minutes ago, Computer Eric said:

And from what you said about how I can use its API to automate my edit, like reading, for example, part of the file?

Sure. Here's an example using LINQPad with a reference to PKHeX.Core.dll:

image.png

 

With LINQPad you can also 'Dump' which gives a ton of info about the object that is dumped:

image.png

... (cropped)

Posted

Ok, I think I understand it a lot better now. :) Thanks, Also now that I see how complicated this project might be I am going to continue taking the C++ and C# courses so I can get better at them before I make something crazy. Thank you for the help, I'll save this project and this page as notes. 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...