# Go to root of PyNXBot import sys sys.path.append('../') from lookups import PKMString from nxbot import SWSHBot from structure import EncounterNest8Archive from structure import NestHoleReward8Archive pmtext = PKMString() buf = bytearray(open('../resources/bytes/local_raid','rb').read()) encounter = EncounterNest8Archive.GetRootAsEncounterNest8Archive(buf,0) buf = bytearray(open('../resources/bytes/local_drop','rb').read()) drop = NestHoleReward8Archive.GetRootAsNestHoleReward8Archive(buf,0) buf = bytearray(open('../resources/bytes/local_bonus','rb').read()) bonus = NestHoleReward8Archive.GetRootAsNestHoleReward8Archive(buf,0) if encounter.TablesIsNone(): print('Wrong offset!') else: for ii in range(encounter.TablesLength()): table = encounter.Tables(ii); print(f"Table ID:0x{table.TableID():X}") print(f"Game Version:{table.GameVersion()}") for jj in range(table.EntriesLength()): entry = table.Entries(jj) msg = f"{entry.EntryIndex()}: {'G-' if entry.IsGigantamax() else ''}{pmtext.species[entry.Species()]}{('-' + str(entry.AltForm())) if entry.AltForm() > 0 else ''}" msg = f"{msg:25}\t" if entry.Ability() == 4: msg +=f"HA allowed\t"
import sys,os sys.path.append('../') from lookups import PKMString from structure import PersonalTable,WC8 pmtext = PKMString('zh') buf = bytearray(open('../resources/bytes/personal_swsh','rb').read()) pt = PersonalTable(buf) def getString(slist): if slist[0] == slist[1]: return slist[0] else: output = '' for ii in range(9): output += '{{tt|' + slist[ii] + '|' + WC8.LANG[ii] + '}}<br>' return output[:-4] def getribbon(flag): if flag[0] == 16: if flag[1] == 26: return '经典奖章' if flag[1] == 28: return '活动奖章' if flag[1] == 29: return '生日奖章' if flag[1] == 31: return '回忆奖章' if flag[1] == 32: return '许愿奖章' return flag
def getpmname(species, forme, cangmax, isShiny): formtext = pmtext.forms[pt.getFormeNameIndex(species, forme)] t = pmtext.species[species] if species == 849 or species == 869 or species == 678 or species == 876 or ( (species in pt.Galarlist or species in pt.Alolalist) and forme): t += '<br><small>' + formtext + '</small>' if cangmax: t += f'<br><small>{GMAXSTR}</small>' if isShiny: t += f'<br><small>{SHINYSTR}</small>' return t pmtexten = PKMString('en') def getitemimage(itemid): filename = pmtexten.items[itemid].replace(" ", "").replace("’", "'").lower() url = f"https://www.serebii.net/itemdex/sprites/{filename}.png" return f'<img src="{url}" alt="{filename}">' def getitemname(itemid): txt = getitemimage(itemid) + pmtext.items[itemid] if itemid >= 1130 and itemid <= 1229: tr = itemid - 1130 return txt + " (" + pmtext.trmoves[tr] + ")" else:
class Util(): STRINGS = PKMString() PT = PersonalTable( bytearray(open('../resources/bytes/personal_swsh', 'rb').read())) GenderSymbol = ['♂', '♀', '-'] @staticmethod def translate(lang): Util.STRINGS = PKMString(lang) @staticmethod def convertImage(filename): import colorsys import numpy from PIL import Image image = Image.open(filename).convert('RGBA') h = image.height w = image.width pixels = numpy.array(image) hsv_array = numpy.empty(shape=(h, w, 5), dtype=float) for row in range(h): for column in range(w): rgb = pixels[row, column] hsv = colorsys.rgb_to_hsv(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255) hsv_array[row, column, 0] = hsv[0] hsv_array[row, column, 1] = hsv[1] hsv_array[row, column, 2] = hsv[2] hsv_array[row, column, 3] = rgb[3] return hsv_array @staticmethod def generatePallete(hsv_array, size=32): # Crop the image import numpy h, w, d = hsv_array.shape if h > size: top = (h - size) // 2 bottom = h - size - top if hsv_array[:top, :, 3].any() or hsv_array[-bottom:, :, 3].any(): print("Image is too large") hsv_array = hsv_array[top:-bottom, :, :] h = size if w > size: left = (w - size) // 2 right = w - size - left if hsv_array[:, :left, 3].any() or hsv_array[:, -right:, 3].any(): print("Image is too large") hsv_array = hsv_array[:, left:-right, :] w = size # Find all colors Colorlist = numpy.empty((0, 3), int) for r in range(h): if not hsv_array[r, :, 3].any(): continue for c in range(w): hsv = hsv_array[r, c] if hsv[3] == 0: continue HVB = Util.convert2HVB(hsv) idx = Util.findinlist(HVB, Colorlist) if idx < 0: Colorlist = numpy.append(Colorlist, [HVB], axis=0) hsv_array[r, c, 4] = len(Colorlist) - 1 else: hsv_array[r, c, 4] = idx return Colorlist, hsv_array @staticmethod def convert2HVB(hsv): import math H = min(29, math.floor(hsv[0] * 30)) V = min(14, math.floor(hsv[1] * 15)) B = min(14, math.floor(hsv[2] * 15)) return [H, V, B] @staticmethod def findinlist(element, nplist): import numpy for ii in range(len(nplist)): if numpy.array_equal(nplist[ii], element): return ii return -1
def translate(lang): Util.STRINGS = PKMString(lang)
def gettype_short(species, formid = 0): pi = pt.getFormeEntry(species,formid) type1 = pmtext.types[pi.Type1()] type2 = pmtext.types[pi.Type2()] if type1 == type2: return "type1=" + type1 else: return "type1=" + type1 + "|type2=" + type2 def getmsg2_short(entry, rank): msg = f'|Raid|{entry.Level()}|{entry.Probabilities(rank)}%|' msg += gettype_short(entry.Species(),entry.AltForm()) msg += getform_short(entry.Species(),entry.IsGigantamax(),entry.AltForm(),entry.ShinyFlag() == 2) + "}}" return msg pmtext = PKMString('en') buf = bytearray(open('../resources/bytes/local_drop','rb').read()) drop = NestHoleReward8Archive.GetRootAsNestHoleReward8Archive(buf,0) buf = bytearray(open('../resources/bytes/local_bonus','rb').read()) bonus = NestHoleReward8Archive.GetRootAsNestHoleReward8Archive(buf,0) buf = bytearray(open('../resources/bytes/personal_swsh','rb').read()) pt = PersonalTable(buf) buf = bytearray(open(Path + 'normal_encount','rb').read()) if Island == 0 else bytearray(open(Path + f'normal_encount_rigel{Island}','rb').read()) eventencounter = NestHoleDistributionEncounter8Archive.GetRootAsNestHoleDistributionEncounter8Archive(buf,0x20) buf = bytearray(open(Path + 'drop_rewards','rb').read()) dropreward = NestHoleDistributionReward8Archive.GetRootAsNestHoleDistributionReward8Archive(buf,0x20) buf = bytearray(open(Path + 'bonus_rewards','rb').read()) bonusreward = NestHoleDistributionReward8Archive.GetRootAsNestHoleDistributionReward8Archive(buf,0x20) buf = bytearray(open(Path + 'dai_encount','rb').read()) crystalencounter = NestHoleCrystalEncounter8Archive.GetRootAsNestHoleCrystalEncounter8Archive(buf,0x20)