Skip to content

Instantly share code, notes, and snippets.

@jcefoli
Last active March 20, 2024 22:36
Show Gist options
  • Save jcefoli/c79879735235ec8de8392da257c6a466 to your computer and use it in GitHub Desktop.
Save jcefoli/c79879735235ec8de8392da257c6a466 to your computer and use it in GitHub Desktop.
Generates Gameshark codes for Pokemon Gold/Silver/Crystal to encounter a specific Pokemon at a specific level
<#
.DESCRIPTION
Generates Gameshark codes for Pokemon Gold/Silver/Crystal to encounter a specific Pokemon at a specific level
Takes user input for the Pokemon name and level and generates the codes
#>
function ConvertTo-Hex {
param (
[Parameter(Mandatory=$true)]
[int]$Number
)
return "{0:X2}" -f $Number
}
#define a hashtable with the first 251 pokemon decimal numbers and their names
$pkmnHashTable = @{
1 = "bulbasaur"
2 = "ivysaur"
3 = "venusaur"
4 = "charmander"
5 = "charmeleon"
6 = "charizard"
7 = "squirtle"
8 = "wartortle"
9 = "blastoise"
10 = "caterpie"
11 = "metapod"
12 = "butterfree"
13 = "weedle"
14 = "kakuna"
15 = "beedrill"
16 = "pidgey"
17 = "pidgeotto"
18 = "pidgeot"
19 = "rattata"
20 = "raticate"
21 = "spearow"
22 = "fearow"
23 = "ekans"
24 = "arbok"
25 = "pikachu"
26 = "raichu"
27 = "sandshrew"
28 = "sandslash"
29 = "nidoran♀"
30 = "nidorina"
31 = "nidoqueen"
32 = "nidoran♂"
33 = "nidorino"
34 = "nidoking"
35 = "clefairy"
36 = "clefable"
37 = "vulpix"
38 = "ninetales"
39 = "jigglypuff"
40 = "wigglytuff"
41 = "zubat"
42 = "golbat"
43 = "oddish"
44 = "gloom"
45 = "vileplume"
46 = "paras"
47 = "parasect"
48 = "venonat"
49 = "venomoth"
50 = "diglett"
51 = "dugtrio"
52 = "meowth"
53 = "persian"
54 = "psyduck"
55 = "golduck"
56 = "mankey"
57 = "primeape"
58 = "growlithe"
59 = "arcanine"
60 = "poliwag"
61 = "poliwhirl"
62 = "poliwrath"
63 = "abra"
64 = "kadabra"
65 = "alakazam"
66 = "machop"
67 = "machoke"
68 = "machamp"
69 = "bellsprout"
70 = "weepinbell"
71 = "victreebel"
72 = "tentacool"
73 = "tentacruel"
74 = "geodude"
75 = "graveler"
76 = "golem"
77 = "ponyta"
78 = "rapidash"
79 = "slowpoke"
80 = "slowbro"
81 = "magnemite"
82 = "magneton"
83 = "farfetchd"
84 = "doduo"
85 = "dodrio"
86 = "seel"
87 = "dewgong"
88 = "grimer"
89 = "muk"
90 = "shellder"
91 = "cloyster"
92 = "gastly"
93 = "haunter"
94 = "gengar"
95 = "onix"
96 = "drowzee"
97 = "hypno"
98 = "krabby"
99 = "kingler"
100 = "voltorb"
101 = "electrode"
102 = "exeggcute"
103 = "exeggutor"
104 = "cubone"
105 = "marowak"
106 = "hitmonlee"
107 = "hitmonchan"
108 = "lickitung"
109 = "koffing"
110 = "weezing"
111 = "rhyhorn"
112 = "rhydon"
113 = "chansey"
114 = "tangela"
115 = "kangaskhan"
116 = "horsea"
117 = "seadra"
118 = "goldeen"
119 = "seaking"
120 = "staryu"
121 = "starmie"
122 = "mr. mime"
123 = "scyther"
124 = "jynx"
125 = "electabuzz"
126 = "magmar"
127 = "pinsir"
128 = "tauros"
129 = "magikarp"
130 = "gyarados"
131 = "lapras"
132 = "ditto"
133 = "eevee"
134 = "vaporeon"
135 = "jolteon"
136 = "flareon"
137 = "porygon"
138 = "omanyte"
139 = "omastar"
140 = "kabuto"
141 = "kabutops"
142 = "aerodactyl"
143 = "snorlax"
144 = "articuno"
145 = "zapdos"
146 = "moltres"
147 = "dratini"
148 = "dragonair"
149 = "dragonite"
150 = "mewtwo"
151 = "mew"
152 = "chikorita"
153 = "bayleef"
154 = "meganium"
155 = "cyndaquil"
156 = "quilava"
157 = "typhlosion"
158 = "totodile"
159 = "croconaw"
160 = "feraligatr"
161 = "sentret"
162 = "furret"
163 = "hoothoot"
164 = "noctowl"
165 = "ledyba"
166 = "ledian"
167 = "spinarak"
168 = "ariados"
169 = "crobat"
170 = "chinchou"
171 = "lanturn"
172 = "pichu"
173 = "cleffa"
174 = "igglybuff"
175 = "togepi"
176 = "togetic"
177 = "natu"
178 = "xatu"
179 = "mareep"
180 = "flaaffy"
181 = "ampharos"
182 = "bellossom"
183 = "marill"
184 = "azumarill"
185 = "sudowoodo"
186 = "politoed"
187 = "hoppip"
188 = "skiploom"
189 = "jumpluff"
190 = "aipom"
191 = "sunkern"
192 = "sunflora"
193 = "yanma"
194 = "wooper"
195 = "quagsire"
196 = "espeon"
197 = "umbreon"
198 = "murkrow"
199 = "slowking"
200 = "misdreavus"
201 = "unown"
202 = "wobbuffet"
203 = "girafarig"
204 = "pineco"
205 = "forretress"
206 = "dunsparce"
207 = "gligar"
208 = "steelix"
209 = "snubbull"
210 = "granbull"
211 = "qwilfish"
212 = "scizor"
213 = "shuckle"
214 = "heracross"
215 = "sneasel"
216 = "teddiursa"
217 = "ursaring"
218 = "slugma"
219 = "magcargo"
220 = "swinub"
221 = "piloswine"
222 = "corsola"
223 = "remoraid"
224 = "octillery"
225 = "delibird"
226 = "mantine"
227 = "skarmory"
228 = "houndour"
229 = "houndoom"
230 = "kingdra"
231 = "phanpy"
232 = "donphan"
233 = "porygon2"
234 = "stantler"
235 = "smeargle"
236 = "tyrogue"
237 = "hitmontop"
238 = "smoochum"
239 = "elekid"
240 = "magby"
241 = "miltank"
242 = "blissey"
243 = "raikou"
244 = "entei"
245 = "suicune"
246 = "larvitar"
247 = "pupitar"
248 = "tyranitar"
249 = "lugia"
250 = "ho-oh"
251 = "celebi"
}
# Handle Title Case using .NET
$culture = [System.Globalization.CultureInfo]::CurrentCulture
$textInfo = $culture.TextInfo
# Get pokemon number from name (via Hashtable)
function Get-PokemonNumber {
param (
[Parameter(Mandatory=$true)]
[string]$Name
)
$pkmnHashTable.GetEnumerator() | Where-Object { $_.Value -eq $Name } | Select-Object -ExpandProperty Key
}
# Vaidate the Pokemon name from the array
function Get-ValidPokemonName {
param (
[Parameter(Mandatory=$true)]
[string]$Prompt
)
while ($true) {
$pkName = Read-Host $Prompt
$pkName = $pkName -replace " ", "" #strip spaces in case name was copied incorrectly
$pkName = $pkName.ToLower()
if ($pkmnHashTable.ContainsValue($pkName)) {
return $textInfo.ToTitleCase($pkName)
} else {
Write-Host "Pokemon name is invalid. Please try again."
}
}
}
# User Input for Pokemon Name
$pkName = Get-ValidPokemonName -Prompt "Enter the name of the Pokemon"
# User Input for Pokemon Level
$pkLevel = 0
while ($pkLevel -lt 1 -or $pkLevel -gt 100) {
$pkLevel = Read-Host "Enter the level of the Pokemon encounter"
if ($pkLevel -lt 1 -or $pkLevel -gt 100) {
Write-Host "Invalid level. Please enter a number between 1 and 100."
}
}
# Convert the level and pokemon number to hex
$pkLevelHex = ConvertTo-Hex -Number $pkLevel
$pkNumHex = ConvertTo-Hex (Get-PokemonNumber -Name $pkName)
# Inject hex values into the Gameshark codes
$pkmnModifierCode = "01" + $pkNumHex + 'EDD0'
$levelModifierCode = "01" + $pkLevelHex + "FCD0"
# Print all the things!
Write-Output "L$pkLevel $($textInfo.ToTitleCase($pkName))`:"
Write-Output "$pkmnModifierCode`n$levelModifierCode"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment