codemonkey85 Posted July 19, 2009 Posted July 19, 2009 (edited) Just as an FYI to all those out there, this project is long dead. You can see my new stuff here: http://projectpokemon.org/forums/showthread.php?20984-PKMDS-Code-Library-Gen-V Hello all, I've finally decided to publicly release my PKMDS code library! It is attached to this post. Feel free to ask any questions you might have about how to use it. Please note that this library was written in VB.Net and compiled on / for a Windows machine. To use it you need the latest .Net framework from Microsoft. Enjoy! SOURCE: See attachment. For all imagery used in the software, see here. If you would like the entire Visual Studio Solution, you can find it here. WHAT IS THIS? It has been a goal of mine for some time to create a code library for people to write their own Pokémon DS save file / PKM file viewing and editing software. What does this mean to you? See the below image: [url]http://i162.photobucket.com/albums/t257/codemonkey85/PKM_Directory_Preview.png[/url] In theory, any person who writes Windows applications in VB.Net or Visual C# should be able to import my .DLL file into their project and recreate the above program (and many others) with minimal coding and without the use of any other external files. As evandixon from the Project Pokémon forums said, "When this is finished, nearly everyone can make a PokeMod [Pokémon save hacking program] themselves". CURRENT FEATURES: -The ability to open and read any Pokémon DS save file (in raw 512kb format) created by Diamond, Pearl, or Platinum. -The ability to open and read any PKM file, or any encrypted and shuffled Pokémon BIN file (136 byte storage or 236 byte party format). -The ability to make some edits in the aforementioned files. -A full collection of Platinum front sprites and box icons for representing the Pokémon being read (including shiny and all alternate formes). -Some other Pokémon DS imagery, including PC storage wallpapers, status symbols, type symbols, etc. -Foreign character support for in-game names. MORE TO COME: -Eventually full unrestricted editing of PKM files and save files... right now a lot of properties of the various classes / structures are read only, because it seemed like less of a headache to code at the time. In retrospect that was not a perfect plan. -There's more, which will be added to this readme as I think of it. FAQ: Please see the thread at Project Pokémon. [url]http://projectpokemon.org/forums/showthread.php?p=40202#post40202[/url] SPECIAL THANKS: COM - For creating Pokesav and inspiring everyone to do better than him. Sabresite - For helping me get started and giving me an endless supply of helpful advice. Also the PKM character to Unicode conversion table, and basically the entire structure of PKM data. SCV - For dedicated patience and problem solving ability, not to mention encouragement. Also thanks to the above for the handy save block checksum algorithm. Jiggy-Ninja - For hard work and unrelenting help, specifically the Pokédex and Trainer Card signature data structures. Also for pointing out stupid mistakes. Poryhack - For, among other things, the ribbon images. Kazumi - For the Pokémon DP font (which I still can't seem to use right...) mingot - For basically giving me the PID / IV relationship code, YOU SAVED MY LIFE. fenzo and coolbho3000 - For creating and maintaining an awesome Pokémon community. damio - For helping tremendously with Friend Codes and general questions here and there. loadingNOW - What doesn't this guy do? Thanks for the save file documentation, and thanks for whatever else I got from you directly or indirectly. Bulbapedia & Serebii - For being handy reference. Legendary Pokémon - For being a source of data. X-Act and really Smogon in general - For answering some questions, and providing the stat formula. GatorShark - For demystifying the Spinda spot rendering process. Mastermind_X - For the Platinum sprites. Also you're basically all awesome. So cheers! DISCLAIMER: Pokémon and all respective names & images are trademark & copyright of Nintendo & Game Freak 1995 - 2009 PokemonDSLib_2009_WITH_SOURCE.zip PKMDS_VIEWER.zip Edited May 26, 2013 by codemonkey85
Toffeuy Posted July 19, 2009 Posted July 19, 2009 Why not just put the readme file onto the post? Ahhh... I like the display
codemonkey85 Posted July 19, 2009 Author Posted July 19, 2009 It seemed like a good idea for it to be immediately visible, since there is a disclaimer in there to keep me / us from getting sued.
evandixon Posted July 19, 2009 Posted July 19, 2009 (edited) Cool. Now I just have to find some use for it. [Edit]: I know! Something Impractical! Edited July 19, 2009 by evandixon
BarkingFrog Posted July 22, 2009 Posted July 22, 2009 This is nice, but documentation will make this .dll more beautiful.. why? .dll can be used by any application in the world *as long as it run on windows, i think.. don't know about linux and mac, never build app on linux, and building for mac is 3x harder because using Objective C* if you use Visual Studio family it's just "Add Existing Item" -> browse -> bla.. bla.. bla.. and all the function is showed up.. how bout the other that doesn't used Visual Studio family.. i think a documentation would be very nice to them.. *No offense, just suggestion..* A function documentation, how to used it, what parameter, just function listing, that would be enough.. *just assume that everybody here at least know how to use .dll, don't care if they don't* my regards, and thanks P.S. It's a cool .dll [Edit] Cool.Now I just have to find some use for it. [Edit]: I know! Something Impractical! Yeah, use ASP.NET.. but it will cost a huge bandwidth..
evandixon Posted July 22, 2009 Posted July 22, 2009 This is nice, but documentation will make this .dll more beautiful..why? .dll can be used by any application in the world *as long as it run on windows, i think.. don't know about linux and mac, never build app on linux, and building for mac is 3x harder because using Objective C* if you use Visual Studio family it's just "Add Existing Item" -> browse -> bla.. bla.. bla.. and all the function is showed up.. how bout the other that doesn't used Visual Studio family.. i think a documentation would be very nice to them.. *No offense, just suggestion..* A function documentation, how to used it, what parameter, just function listing, that would be enough.. *just assume that everybody here at least know how to use .dll, don't care if they don't* my regards, and thanks P.S. It's a cool .dll [Edit] Yeah, use ASP.NET.. but it will cost a huge bandwidth.. I failed on that. There was a security exception when I tried to read a save file. The dll reads the file as a stream. Codemonkey, I suggest adding an overloads function that reads it as a byte() (IO.File.ReadAllBytes())
codemonkey85 Posted July 22, 2009 Author Posted July 22, 2009 Overloaded functions cannot differ by only return types, so I will have to name it as a separate function if I want to do it that way. So ASP.Net cannot read files using streams? That seems like an odd limitation. evandixon, do you mind pasting the specific code you used to open the save file? As for documentation within the .DLL, that is something I plan to do. I will document it using commentation and XML tagging. However, there are thousands of lines of code to go through, so it will take me a while.
evandixon Posted July 22, 2009 Posted July 22, 2009 The specific errordetails/line of code... There was a security exeption when trying to read a save file (PokemonLib.OpenDPSav(filename)), even though I gave everything full control of the directory the save file was in. In other applications, I have successfully read all the bytes of a file, so a fix on that part should fix the problem.
codemonkey85 Posted July 23, 2009 Author Posted July 23, 2009 I see. Well, like I said, I suppose I will just write a function to return a byte array instead of a DPSaveFile or PtSaveFile. Hopefully that byte array can be serialized into one of those structures; if not, I suppose you could always work with the data manually.
BarkingFrog Posted July 25, 2009 Posted July 25, 2009 ... So ASP.Net cannot read files using streams? That seems like an odd limitation. ... However, there are thousands of lines of code to go through, so it will take me a while. ... I don't thinks so, ASP.NET can do stream read and stream write if I'm not mistaken.. how about the file permission? no problem with that? Don't worry, without documentation we just need to brute force the function.. but with that it make a little relax.. :grog::grog:
evandixon Posted July 31, 2009 Posted July 31, 2009 I don't thinks so, ASP.NET can do stream read and stream write if I'm not mistaken.. how about the file permission? no problem with that?Don't worry, without documentation we just need to brute force the function.. but with that it make a little relax.. :grog::grog: I was running the code on my box, and gave the world full control over everything in the C:/inetpub/ folder.
codemonkey85 Posted August 13, 2009 Author Posted August 13, 2009 Hey people, I just uploaded the latest build of my library. I made some changes that I think will help quite a bit with readability and usage of the library. For instance, several of the dictionaries are no longer declared with "Byte" or "UInt16" keys, but rather with enumerations of the aforementioned types that use proper names. I have also used those enumerations elsewhere in the code. So in other words, if you want to see if a Pokémon is a Bulbasaur, you used to do this: If PKM.Species.ID = 1 Then [...] And now you can do it this way instead: If PKM.Species.ID = Species.Bulbasaur Then [...] The same goes with item index values, move index values, etc. That should help a lot, I think.
Matt140 Posted August 13, 2009 Posted August 13, 2009 Thanks for the update, this library makes things way to easy :biggrin:
evandixon Posted August 13, 2009 Posted August 13, 2009 Hey people,I just uploaded the latest build of my library. I made some changes that I think will help quite a bit with readability and usage of the library. For instance, several of the dictionaries are no longer declared with "Byte" or "UInt16" keys, but rather with enumerations of the aforementioned types that use proper names. I have also used those enumerations elsewhere in the code. So in other words, if you want to see if a Pokémon is a Bulbasaur, you used to do this: If PKM.Species.ID = 1 Then [...] And now you can do it this way instead: If PKM.Species.ID = Species.Bulbasaur Then [...] The same goes with item index values, move index values, etc. That should help a lot, I think. I added the latest version to the Unofficial Upload Bin, although it is not live at the time of posting, with no trouble. Btw, I don't see the attribute for Pokerus (I looked throughout,even with the .Net Reflector, but it should be in .Stats, shouldn't it?), and it would be nice if the Origins.Location would automatic, so I don't have to write a chuink of code...: [size=2][color=#0000ff][size=2][color=#0000ff][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2][color=#000000] Pokemon [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#000000] PokemonDSLib.PokemonLib.Pokemon[/color][/size] [/color][/size][/color][/size][size=2][color=#0000ff] [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Public[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Function[/color][/size][/color][/size][size=2] AreaMet() [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]String[/color][/size] [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size][/color][/size][size=2] Pokemon.Origins.Hometown.Name = [/size][size=2][color=#a31515][size=2][color=#a31515]"Platinum"[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Then[/color][/size] [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Return[/color][/size][/color][/size][size=2] Pokemon.Origins.Location.Platinum.Name[/size] [size=2][color=#0000ff][size=2][color=#0000ff]Else[/color][/size] [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Return[/color][/size][/color][/size][size=2] Pokemon.Origins.Location.DiamondPearl.Name[/size] [size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size] [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Function[/color][/size] [/color][/size] ...in order to display the Location met. A few more suggestions: -Pokemon Output to a Byte Array (Both PC and Party), so it might work better in my ASP.Net application (Writing the Output directly to the output stream, rather than saving it to a file) -Reform on RawDeserialize, because it is causing Security Exceptions when run out of the DLL -Auto-Detect for Encrypted Pokemon (right now, I have the application assuming that the pokemon is un-encrypted, and that might cause a major problem in the future.) If you wish to see the source for my ASP.Net application, I can PM it to you, CodeMonkey85.
Jiggy-Ninja Posted August 14, 2009 Posted August 14, 2009 I added the latest version to the Unofficial Upload Bin, although it is not live at the time of posting, with no trouble.Btw, I don't see the attribute for Pokerus (I looked throughout,even with the .Net Reflector, but it should be in .Stats, shouldn't it?), and it would be nice if the Origins.Location would automatic, so I don't have to write a chuink of code...: [size=2][color=#0000ff][size=2][color=#0000ff][size=2][color=#0000ff][size=2][color=#0000ff]Dim[/color][/size][/color][/size][size=2][color=#000000] Pokemon [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#000000] PokemonDSLib.PokemonLib.Pokemon[/color][/size] [/color][/size][/color][/size][size=2][color=#0000ff] [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Public[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Function[/color][/size][/color][/size][size=2] AreaMet() [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]String[/color][/size] [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size][/color][/size][size=2] Pokemon.Origins.Hometown.Name = [/size][size=2][color=#a31515][size=2][color=#a31515]"Platinum"[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Then[/color][/size] [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Return[/color][/size][/color][/size][size=2] Pokemon.Origins.Location.Platinum.Name[/size] [size=2][color=#0000ff][size=2][color=#0000ff]Else[/color][/size] [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Return[/color][/size][/color][/size][size=2] Pokemon.Origins.Location.DiamondPearl.Name[/size] [size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size] [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Function[/color][/size] [/color][/size] ...in order to display the Location met. A few more suggestions: -Pokemon Output to a Byte Array (Both PC and Party), so it might work better in my ASP.Net application (Writing the Output directly to the output stream, rather than saving it to a file) -Reform on RawDeserialize, because it is causing Security Exceptions when run out of the DLL -Auto-Detect for Encrypted Pokemon (right now, I have the application assuming that the pokemon is un-encrypted, and that might cause a major problem in the future.) If you wish to see the source for my ASP.Net application, I can PM it to you, CodeMonkey85. The thing with the Location stuff is that the location that is displayed depends on the game reading the data, not the Pokemon's hometown. As for autodetecting encryption...it might not be possible to do that guaranteed.
codemonkey85 Posted August 14, 2009 Author Posted August 14, 2009 Jiggy is right on both counts. For location, if you aren't reading directly from a save file and don't want to pick, you could always just display both. As far as detecting encryption status goes, I leave it to the user(s) to be sane enough to always save encrypted PKM files with the .bin file extension. But I doubt anyone would use those anyway, so there doesn't seem to be any harm in assuming everything is decrypted. In regard to the PokéRus, I have kept off of that until I am certain what the value range is and what it means. I am certain it is not as simple as "infected", "cured", or nothing. I'm not sure why RawDeserialize is giving you issues, still, and I honestly can't think of an easier way to output a byte array than to just use that function. I guess I could make all of the structure members public (if they aren't already) and allow you to get the bytes yourself. For PC instead of party, you would only really need to get the full structure like normal and then truncate your array to 136 bytes.
evandixon Posted August 14, 2009 Posted August 14, 2009 For PC instead of party, you would only really need to get the full structure like normal and then truncate your array to 136 bytes. Does it really output in Party format? If so, that would be great! I could make an online converter!! I'm not sure why RawDeserialize is giving you issues I think it has something to do with the Marshal class (I looked for its description, and it mentioned "Unmanaged code", so ASP.Net [or IIS, I'm not sure] is blocking any external program from using it.) In regard to the PokéRus, I have kept off of that until I am certain what the value range is and what it means. I am certain it is not as simple as "infected", "cured", or nothing. That isn't something I care about anyway, but others might... I leave it to the user(s) to be sane enough to always save encrypted PKM files with the .bin file extension I need to fix that, because if someone saves it with a *.pkm extension, and uploads it, I suspect that the page will crash hopelessly, and require that I manually delete it.
Jiggy-Ninja Posted August 15, 2009 Posted August 15, 2009 (edited) Well, some things that could be done to test for auto encryption is to test certain areas against their known range of values. For example, the Dex number must be between 1 and 493 (inclusive). By my math, when a Pokemon is encrypted, there is a 99.2% chance that the value will be outside of that range.* Even just using that as a criteria, we can have an incredible amount of certainty in whether or not the Pokemon is encrypted. The PP Ups area is even more restricted than the dex number area. If we consider just the 4 PP Ups area, we can determine whether or not the Pokemon is encrypted with 99.999994% certainty. That works out to a 1 in 16,777,216 chance of guessing wrong. So, it is possible to auto-detect encryption with an incredible amount of accuracy. Perhaps with some not-so-fancy PRNG math, we could do it with 100% certainty. It may very well be impossible for the PRNG to make the PP Ups area look legal. Also, I've noticed that a few of my PKM files that I made with Pokesav are in the encrypted format. So there is a bit of a good use for this. *The dex number on a Pokemon is stored in 16 bits, so its full range is 65,536 numbers. Dex number, by contrast, has only 493 possible numbers. When the Pokemon is encrypted, the value at that location is effectively random, so we can consider that all possible values have an equal probability of occurring. 65,536 - 493 = 65,043, meaning that over 65,000 of the possible values are not possible for a Pokemon to have. 65,043/65,536 = 0.9924774169921875, which works out to about a 99% chance of an encrypted Pokemon having a value in the dex number area outside of the possible range. Edited August 15, 2009 by Jiggy-Ninja
codemonkey85 Posted August 15, 2009 Author Posted August 15, 2009 Does it really output in Party format? The Pokemon class in my library is exactly 236 bytes in size. It's always in party format, technically. Jiggy, that... is good work. This is more viable than I thought.
evandixon Posted August 15, 2009 Posted August 15, 2009 I'm not sure why RawDeserialize is giving you issues, If one of the following happen, it will probebly stop: 1. The library is open-sourced. (This will trick ASP.Net [or IIS, I'm not sure which] into thinking that it is my application that is using the code, rather than a DLL) 2. I somehow manage to grant the permission to used un-managed code 3. Raw-Deserialize stops using un-managed code 4. I get in the .Net Reflector attempting to obtain the source for #1. (I tried this earlier, but it didn't work too well.) The Pokemon class in my library is exactly 236 bytes in size. It's always in party format, technically. When I have time, I'll try to make the bin a converter, because I tested the Export function on my computer, and it worked fine wth no problems.
Matt140 Posted August 15, 2009 Posted August 15, 2009 Just a thought, couldn't a BinaryWriter/BinaryReader be used to read and write the file (it would be one massive chunk of code though).
codemonkey85 Posted August 16, 2009 Author Posted August 16, 2009 Yes, you could do it that way and work with the data manually. That's actually EXACTLY what I was doing when I first started this whole project. Ugh. Now that I've fallen in love with binary serialization, I don't know if I'll ever use the BinaryReader / Writer class again.
Browner87 Posted August 25, 2009 Posted August 25, 2009 I guess even if we promise only constructive criticism you wouldn't consider releasing your full source complete with mess, would you codemonkey85? Even by PM? I just personally dislike DLLs. It's just a pet peeve of mine. I also LOVE being able to mess with source code.
codemonkey85 Posted August 25, 2009 Author Posted August 25, 2009 At this rate, I'll never get the code totally cleaned up, so I suppose I will post the source (or a link to it) shortly. At that point, people can feel free to make suggestions regarding the efficiency of the code, or functions they have created that could be added (with credit of course).
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now