forked from yling/yPokeStats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathylingstats.lua
More file actions
152 lines (131 loc) · 5.72 KB
/
ylingstats.lua
File metadata and controls
152 lines (131 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
-- yPokeStats
-- by YliNG
-- v2.2
-- https://github.com/yling
if emu and not memory then
console:log("This script is made to work with VBA-rr. It will not work with mGBA.")
return false
end
dofile "data/tables.lua" -- Tables with games data, and various data - including names
dofile "data/memory.lua" -- Functions and Pokemon table generation
dofile "data/display.lua" -- Display module
local gamedata = getGameInfo() -- Gets game info
local version, lan, gen, resolution = gamedata[1], gamedata[2], gamedata[3], gamedata[4]
Display.setResolution(resolution)
-- Note : "O" seems to be the letter used in DSi enhanced games
-- (Couldn't find any source for this, NDSi Enhanced french version of pokemon black still shows "F", Spanish NDSi Enhanced version still shows "S")
-- "O" seems to be (USA, Europe)
-- https://wiki.no-intro.org/index.php?title=Nintendo_-_Nintendo_DSi_(Digital)_(CDN)_dat_notes#Region_Code_to_No-Intro_Region_Map
if games[version][lan] == nil then -- If language is not available default to french
if lan == "D" or lan == "H" or lan == "I" or lan == "O" or lan == "S" or lan == "X" or lan == "Y" or lan == "Z" then
lan = "F"
end
end
if version == 0 or not games[version] or not games[version][lan] then
if games[version] and games[version]["E"] then
print("This version is supported, but not in this language. Check gamesdata.lua to add it.")
else
print("This game isn't supported. Is it a hackrom ? It might work but you'll have to add it yourself. Check gamesdata.lua")
end
print("Version: "..version)
print("Language: "..lan)
print("Language: "..bit.tohex(lan))
return
end
print("Welcome to yPokeStats Unified ")
print("Game :", games[version][lan][1])
pkmnSide = {PLAYER = 1, ENEMY = 2}
local key = { SWITCH_MODE = "J", -- Switch mode (EV,IV,Stats)
SWITCH_SELECTED_POKEMON = "K", -- Switch pokemon side (Enemy / player)
POKEMON_SLOT = "L", -- Pokemon Slot
TOGGLE_MORE = "M", -- Show more data
TOGGLE_HELP = "H"} -- Toggle help
local state = {selectedPkmnSide = pkmnSide.PLAYER, mode = 3, help = true, more = false, pokemonSlot = {1, 1}}
local cache = {lastpid = 0, lastchecksum = 0, lastPokemonSide = pkmnSide.PLAYER}
local pokemon = nil
local monitor = {yling = false, count = 0, clockcount = 0, totalclocktime = 0, lastclocktime = 0, highestclocktime = 0, meanclocktime = 0}
local prev = input.get() -- Preparing the input tables - allows to check if a key has been pressed
function main() -- Main function - display (check memory.lua for calculations)
nClock = os.clock() -- Set the clock (for performance monitoring)
statusChange(input.get()) -- Check for key input and changes status
-- Clear pokemon data when status changes to prevent displaying wrong pokemon
if cache.lastPokemonSide ~= state.selectedPkmnSide then
pokemon = nil
end
cache.lastPokemonSide = state.selectedPkmnSide
-- Resolve pokemon memory address
if state.selectedPkmnSide == pkmnSide.PLAYER then
base = resolveBase(games[version][lan][2]) -- Player pokemon
else
base = resolveBase(games[version][lan][3]) -- Enemy pokemon
end
size = games[version][lan][4]
start = base + size * (state.pokemonSlot[state.selectedPkmnSide] - 1)
-- Fetch pokemon data if valid memory found
if start and (memory.readdwordunsigned(start) ~= 0 or memory.readbyteunsigned(start) ~= 0) then
if not pokemon or isPokemonChanged(cache.lastpid, cache.lastchecksum, start, gen, state.selectedPkmnSide, pokemon["hp"]["current"]) or not pokemon["species"] then
local fetched = fetchPokemon(start, gen, state.selectedPkmnSide)
monitor.count = monitor.count + 1
if fetched and fetched["species"] and fetched["speciesname"] then
if fetched["hp"] and fetched["hp"]["max"] > 0 and fetched["hp"]["max"] < 1000 then
pokemon = fetched
if gen >= 3 then
cache.lastpid = pokemon["pid"]
cache.lastchecksum = pokemon["checksum"]
else
cache.lastpid = pokemon["species"]
cache.lastchecksum = pokemon["ivs"]
end
end
end
end
else
-- No PID found - reset pokemonSlot
if state.selectedPkmnSide == pkmnSide.PLAYER then
state.pokemonSlot[1] = 1
else
state.pokemonSlot[2] = 1
end
end
-- Render
Display.mainRender(pokemon, gen, version, state, cache.lastpid, monitor, key, table)
-- Script performance monitoring
clocktime = os.clock() - nClock
monitor.clockcount = monitor.clockcount + 1
monitor.totalclocktime = monitor.totalclocktime + clocktime
monitor.lastclocktime = clocktime ~= 0 and clocktime or monitor.lastclocktime
monitor.highestclocktime = clocktime > monitor.highestclocktime and clocktime or monitor.highestclocktime
monitor.meanclocktime = monitor.totalclocktime / monitor.clockcount
Display.performanceStats(monitor)
end
gui.register(main)
function statusChange(input)
if input[key.SWITCH_MODE] and not prev[key.SWITCH_MODE] then
local max = (gen <= 2) and 3 or 4
state.mode = (state.mode < max) and (state.mode + 1) or 1
end
if input[key.SWITCH_SELECTED_POKEMON] and not prev[key.SWITCH_SELECTED_POKEMON] then
state.selectedPkmnSide = (state.selectedPkmnSide == 1) and 2 or 1
end
if input[key.POKEMON_SLOT] and not prev[key.POKEMON_SLOT] then
if gen <= 2 and state.selectedPkmnSide == pkmnSide.ENEMY then
state.pokemonSlot[2] = 1
else
state.pokemonSlot[state.selectedPkmnSide] = (state.pokemonSlot[state.selectedPkmnSide] < 6) and (state.pokemonSlot[state.selectedPkmnSide] + 1) or 1
end
end
if input[key.TOGGLE_MORE] and not prev[key.TOGGLE_MORE] then
state.help = false
state.more = not state.more
end
if input[key.TOGGLE_HELP] and not prev[key.TOGGLE_HELP] then
state.more = false
state.help = not state.help
end
if input["Y"] and not prev["Y"] then
state.more = false
state.help = false
monitor.yling = not monitor.yling
end
prev = input
end