Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gen 4 Pokémon Mystery Gift Overhaul #518

Open
wants to merge 8 commits into
base: master
from

Conversation

Projects
None yet
3 participants
@ubergeek77
Copy link

commented May 22, 2019

I've gone in and "overhauled" the way Gen 4 Mystery Gifts are distributed to connected clients. Here's an overview of what I've changed:

  • 19 out of the full list of 40 Gen 4 Pokémon Game IDs were previously missing entirely. These games have been added to the code and are now recognized as Gen 4 Pokémon games for Mystery Gift support.
    • For instance, before these changes, Pokémon Pearl and Pokémon HeartGold were not recognized as Gen 4 Pokémon games.
  • Rather than distribute the gifts based on a date moduli, every Gen 4 Mystery Gift is distributed based on its original, real life Nintendo Wi-Fi Connection distribution date, on a per Game ID basis.
    • Each game language will receive the appropriate Wonder Card in that language.
    • Since the Nintendo DS' clock is used for the "received" date on a Wonder Card, this distribution method makes it easier for players to receive Mystery Gifts that are indistinguishable from gifts that were actually downloaded from the real Nintendo Wi-Fi Connection.
  • Only events that were specifically Wi-Fi Events have been included in this overhaul.
    • Because there are substantially more Local Events that have been distributed in the past, because said events are largely disorganized between different languages and locales, and because the distribution times for those would have overlapped with the ones I have included in the code, I did not include any Local Events in this overhaul. This is an emulator for Nintendo Wi-Fi Connection, after all.
  • This repository had some .myg files that did not correspond to real-life Nintendo Wi-Fi Connection distributions. As to not delete them outright and preserve them, they have been moved to a separate subfolder.
    • If there is ever a point where it is desired to keep the old distribution method with these old .myg files, it would be trivial to add a special case for, for instance, Nintendo DS clock dates where the year is greater than or equal to 2019. Connections with local dates matching that year could simply fall back to the day modulus method, where the variable dlc_path would be appended before calling the relevant functions. Doing this does make the code slightly less easy to read, so while I have tested this myself outside of my repository, I did not find it appropriate to include in this pull request.
  • The new .myg files that I have added use filenames that are much easier to understand. They also specify the language for that file, where previous filenames found in this repository did not. For example:
    • Previous Secret Key filename: 17p.myg
    • My Secret Key File: ENG_017_Plat_SecretKey.myg
  • I'm not entirely sure if GitHub will include my Wiki in this pull request, but I have also updated the relevant Wiki pages for this change. These pages will tell users how the new distribution system works, as well as provide a full, comprehensive list of the events that will be distributed. I have changed one page and added another page:

I have tested this new method on my own devices, and it works great. I am very happy with these changes.

I appreciate your consideration into this pull request. If there is anything unsatisfactory about my code changes, please let me know, and I will do my best to address your concerns.

ubergeek77 added some commits May 22, 2019

Gen 4 Pokémon Mystery Gift Overhaul
Added many missing Game IDs to the list of valid games to receive DLC
Gen 4 Mystery Gifts will now be distributed based on their original release dates
Removed some overlooked redundant code
The function looking up the event filename for a given date was erroneously called twice (assigned to a variable and then called again without using the variable)

Non-English gamecodes for HG/SS were referenced twice in each of the international Mystery Gifts.
@sepalani
Copy link
Collaborator

left a comment

This PR can be a bit improved, IMO.

It doesn't seem PEP8 compliant and I'm also not fond of these if-else-if forests, a (named) tuple, a dictionary or another data structure can be used instead and you can loop through it. I'll think about it and add some details regarding that later this week.

Then, The first and last commit can be squashed together.

Otherwise, I'm not against the idea. If you need some help on how to squash these commits or use git in general, feel free to ask.

@sepalani sepalani requested a review from barronwaffles May 22, 2019

@ubergeek77

This comment has been minimized.

Copy link
Author

commented May 22, 2019

Very fair points. This can absolutely be improved to be more dynamic. It would be much better to have some sort of "event registry" that has all of the needed information on an event, and then have the code generate the needed Game IDs and filenames on the fly, rather than being manually specified. Perhaps all of this could even be read from a .json file.

I have a few ideas on how to tackle this, so I'll take a crack at it later today.

@ubergeek77

This comment has been minimized.

Copy link
Author

commented May 22, 2019

I've moved the event definitions out of the code and into a json file. Here's how it works:

  • The client DS requests a Mystery Gift from the server.
  • The server loops over every event found in the .json file.
  • For any given event definition:
    • If the current Game ID's language subcode (last character in Game ID) is found in the lang_subcodes key for said event, continue to the next check.
    • If the current Game ID matches the "short code" contained in the valid_games key for said event (where a short code is a 1 character representation of a Gen 4 game), continue to the next check.
    • The server retrieves the given event's registered start date and end date, and determines if the Nintendo DS' reported date is within those two dates. If it is, we have found our event. We continue to filename generation:
    • Using the following items in the following order, dynamically generate the filename we expect for said event:
      • Current Game ID's language subcode converted to a 3-character identifier (i.e. J -> JPN)
      • Current event's Wonder Card ID (padded to 3 characters)
      • A human-readable representation of the list of games the event is valid for
      • The event's registered shortname
    • The logic used in the previous point to generate the expected filename will match every .myg file I previously submitted in the PR.

The benefit of moving this to a .json file is that anyone can add their own events rather easily, so long as the .myg filename matches what the server expects for that event. Care will have to be taken to ensure the start and end dates for each event do not overlap with any others, and I have done so for the events in my submitted g4_events.json file; no event will prevent another event from being served.

Additionally, the file dlc.py has been formatted for PEP8 compliance.

Please let me know what you think!

@ubergeek77

This comment has been minimized.

Copy link
Author

commented May 23, 2019

Quick update: I wrote a verification script using the new function I made, and there are some slight errors in my .json file. I also caught a few .myg files that are missing. I'll go through this and commit the fixes soon.

@ubergeek77

This comment has been minimized.

Copy link
Author

commented May 23, 2019

Aforementioned event errors have been corrected.

@barronwaffles

This comment has been minimized.

Copy link
Owner

commented May 23, 2019

I'll free up some time over the next few days to look over the changes, but the idea of using the original distribution dates does feel like a practical solution.

@barronwaffles
Copy link
Owner

left a comment

I'll just throw a couple of comments now - still too busy to scan over it much further, sorry.

Will attempt to free up this weekend for further review.

# This way, if someone knows exactly when an event happened in real life,
# they know exactly which date to change to in order to receive
# a particular gift.
gen_4_pokemon_gamecodes = [

This comment has been minimized.

Copy link
@barronwaffles

barronwaffles Jun 4, 2019

Owner

This list could probably be collapsed further by excluding the language key/indicator - it doesn't seem like it's being utilized at this level.

@@ -117,6 +145,82 @@ def filter_list_by_date(data, token):
return ret


def todays_g4_event_filename(today, gamecd, dlc_path):
event_filename = "null"

This comment has been minimized.

Copy link
@barronwaffles

barronwaffles Jun 4, 2019

Owner

It might save some logic if you returned 'None' when the event evaluation below failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.