From 1b8b30e259f58d73bf8fec332174670f4e1f08f2 Mon Sep 17 00:00:00 2001 From: petap0w Date: Sun, 12 Oct 2025 17:52:22 +0200 Subject: [PATCH 1/6] Addition of background prop to pokemon --- decoder/gym.go | 8 ++++---- decoder/pokemon.go | 17 +++++++++++++---- decoder/pokestop.go | 8 ++++---- sql/50_pokemon_background.up.sql | 2 ++ util/pogo.go | 2 +- 5 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 sql/50_pokemon_background.up.sql diff --git a/decoder/gym.go b/decoder/gym.go index b3963c77..09ecda6e 100644 --- a/decoder/gym.go +++ b/decoder/gym.go @@ -181,7 +181,7 @@ func (gym *Gym) updateGymFromFort(fortData *pogo.PokemonFortProto, cellId uint64 TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms,omitempty"` Alignment int `json:"alignment,omitempty"` Badge int `json:"badge,omitempty"` - LocationCard int `json:"location_card,omitempty"` + Background int `json:"background,omitempty"` } gym.Id = fortData.FortId gym.Lat = fortData.Latitude //fmt.Sprintf("%f", fortData.Latitude) @@ -200,7 +200,7 @@ func (gym *Gym) updateGymFromFort(fortData *pogo.PokemonFortProto, cellId uint64 TempEvolutionFinishMs: fortData.GuardPokemonDisplay.TemporaryEvolutionFinishMs, Alignment: int(fortData.GuardPokemonDisplay.Alignment), Badge: int(fortData.GuardPokemonDisplay.PokemonBadge), - LocationCard: util.ExtractLocationCardFromDisplay(fortData.GuardPokemonDisplay), + Background: util.ExtractBackgroundFromDisplay(fortData.GuardPokemonDisplay), }) gym.GuardingPokemonDisplay = null.StringFrom(string(display)) } @@ -331,7 +331,7 @@ func (gym *Gym) updateGymFromGymInfoOutProto(gymData *pogo.GymGetInfoOutProto) * TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms,omitempty"` Alignment int `json:"alignment,omitempty"` Badge int `json:"badge,omitempty"` - LocationCard int `json:"location_card,omitempty"` + Background int `json:"background,omitempty"` DeployedMs int64 `json:"deployed_ms,omitempty"` DeployedTime int64 `json:"deployed_time,omitempty"` BattlesWon int32 `json:"battles_won"` @@ -364,7 +364,7 @@ func (gym *Gym) updateGymFromGymInfoOutProto(gymData *pogo.GymGetInfoOutProto) * TempEvolutionFinishMs: pokemonDisplay.TemporaryEvolutionFinishMs, Alignment: int(pokemonDisplay.Alignment), Badge: int(pokemonDisplay.PokemonBadge), - LocationCard: util.ExtractLocationCardFromDisplay(pokemonDisplay), + Background: util.ExtractBackgroundFromDisplay(pokemonDisplay), Shiny: pokemonDisplay.Shiny, MotivationNow: util.RoundedFloat4(motivatedPokemon.MotivationNow), CpNow: motivatedPokemon.CpNow, diff --git a/decoder/pokemon.go b/decoder/pokemon.go index 23ba0cfb..9894cdfa 100644 --- a/decoder/pokemon.go +++ b/decoder/pokemon.go @@ -68,6 +68,7 @@ type Pokemon struct { IsDitto bool `db:"is_ditto" json:"is_ditto"` SeenType null.String `db:"seen_type" json:"seen_type"` Shiny null.Bool `db:"shiny" json:"shiny"` + Background null.Int `db:"background" json:"background"` Username null.String `db:"username" json:"username"` Capture1 null.Float `db:"capture_1" json:"capture_1"` Capture2 null.Float `db:"capture_2" json:"capture_2"` @@ -109,6 +110,7 @@ type Pokemon struct { //`display_pokemon_id` smallint unsigned DEFAULT NULL, //`seen_type` enum('wild','encounter','nearby_stop','nearby_cell') DEFAULT NULL, //`shiny` tinyint(1) DEFAULT '0', +//`background` smallint unsigned DEFAULT NULL, //`username` varchar(32) DEFAULT NULL, //`capture_1` double(18,14) DEFAULT NULL, //`capture_2` double(18,14) DEFAULT NULL, @@ -148,7 +150,7 @@ func getPokemonRecord(ctx context.Context, db db.DbDetails, encounterId uint64) "SELECT id, pokemon_id, lat, lon, spawn_id, expire_timestamp, atk_iv, def_iv, sta_iv, golbat_internal, iv, "+ "move_1, move_2, gender, form, cp, level, strong, weather, costume, weight, height, size, "+ "display_pokemon_id, is_ditto, pokestop_id, updated, first_seen_timestamp, changed, cell_id, "+ - "expire_timestamp_verified, shiny, username, pvp, is_event, seen_type "+ + "expire_timestamp_verified, shiny, background, username, pvp, is_event, seen_type "+ "FROM pokemon WHERE id = ?", strconv.FormatUint(encounterId, 10)) statsCollector.IncDbQuery("select pokemon", err) @@ -211,6 +213,7 @@ func hasChangesPokemon(old *Pokemon, new *Pokemon) bool { old.IsDitto != new.IsDitto || old.SeenType != new.SeenType || old.Shiny != new.Shiny || + old.Background != new.Background || old.IsEvent != new.IsEvent || !floatAlmostEqual(old.Lat, new.Lat, floatTolerance) || !floatAlmostEqual(old.Lon, new.Lon, floatTolerance) || @@ -315,12 +318,12 @@ func savePokemonRecordAsAtTime(ctx context.Context, db db.DbDetails, pokemon *Po "spawn_id, expire_timestamp, atk_iv, def_iv, sta_iv, golbat_internal, iv, move_1, move_2,"+ "gender, form, cp, level, strong, weather, costume, weight, height, size,"+ "display_pokemon_id, is_ditto, pokestop_id, updated, first_seen_timestamp, changed, cell_id,"+ - "expire_timestamp_verified, shiny, username, %s is_event, seen_type) "+ + "expire_timestamp_verified, shiny, background, username, %s is_event, seen_type) "+ "VALUES (\"%d\", :pokemon_id, :lat, :lon, :spawn_id, :expire_timestamp, :atk_iv, :def_iv, :sta_iv,"+ ":golbat_internal, :iv, :move_1, :move_2, :gender, :form, :cp, :level, :strong, :weather, :costume,"+ ":weight, :height, :size, :display_pokemon_id, :is_ditto, :pokestop_id, :updated,"+ - ":first_seen_timestamp, :changed, :cell_id, :expire_timestamp_verified, :shiny, :username, %s :is_event,"+ - ":seen_type)", pvpField, pokemon.Id, pvpValue), pokemon) + ":first_seen_timestamp, :changed, :cell_id, :expire_timestamp_verified, :shiny, :background, :username,"+ + "%s :is_event, :seen_type)", pvpField, pokemon.Id, pvpValue), pokemon) statsCollector.IncDbQuery("insert pokemon", err) if err != nil { @@ -369,6 +372,7 @@ func savePokemonRecordAsAtTime(ctx context.Context, db db.DbDetails, pokemon *Po "is_ditto = :is_ditto, "+ "seen_type = :seen_type, "+ "shiny = :shiny, "+ + "background = :background, "+ "username = :username, "+ "%s"+ "is_event = :is_event "+ @@ -474,6 +478,7 @@ func createPokemonWebhooks(ctx context.Context, db db.DbDetails, old *Pokemon, n "capture_2": new.Capture2.ValueOrZero(), "capture_3": new.Capture3.ValueOrZero(), "shiny": new.Shiny, + "background": new.Background, "username": new.Username, "display_pokemon_id": new.DisplayPokemonId, "is_event": new.IsEvent, @@ -1103,6 +1108,9 @@ func (pokemon *Pokemon) clearIv(cp bool) { func (pokemon *Pokemon) addEncounterPokemon(ctx context.Context, db db.DbDetails, proto *pogo.PokemonProto, username string) { pokemon.Username = null.StringFrom(username) pokemon.Shiny = null.BoolFrom(proto.PokemonDisplay.Shiny) + if proto.PokemonDisplay.LocationCard != nil { + pokemon.Background = null.IntFrom(int64(proto.PokemonDisplay.LocationCard.LocationCard.Number())) + } pokemon.Cp = null.IntFrom(int64(proto.Cp)) pokemon.Move1 = null.IntFrom(int64(proto.Move1)) pokemon.Move2 = null.IntFrom(int64(proto.Move2)) @@ -1253,6 +1261,7 @@ func (pokemon *Pokemon) setPokemonDisplay(pokemonId int16, display *pogo.Pokemon pokemon.Move2 = null.NewInt(0, false) pokemon.Cp = null.NewInt(0, false) pokemon.Shiny = null.NewBool(false, false) + pokemon.Background = null.NewInt(0, false) pokemon.IsDitto = false pokemon.DisplayPokemonId = null.NewInt(0, false) pokemon.Pvp = null.NewString("", false) diff --git a/decoder/pokestop.go b/decoder/pokestop.go index f0afa989..0a88fa38 100644 --- a/decoder/pokestop.go +++ b/decoder/pokestop.go @@ -454,8 +454,8 @@ func (stop *Pokestop) updatePokestopFromQuestProto(questProto *pogo.FortSearchOu if display.Shiny { infoData["shiny"] = display.Shiny } - if locationCard := util.ExtractLocationCardFromDisplay(display); locationCard != 0 { - infoData["location_card"] = locationCard + if background := util.ExtractBackgroundFromDisplay(display); background != 0 { + infoData["background"] = background } if breadMode := int(display.BreadModeEnum); breadMode != 0 { infoData["bread_mode"] = breadMode @@ -609,7 +609,7 @@ func (stop *Pokestop) updatePokestopFromGetPokemonSizeContestEntryOutProto(conte TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms"` Alignment int `json:"alignment"` Badge int `json:"badge"` - LocationCard int `json:"location_card"` + Background int `json:"background"` } type contestJson struct { TotalEntries int `json:"total_entries"` @@ -637,7 +637,7 @@ func (stop *Pokestop) updatePokestopFromGetPokemonSizeContestEntryOutProto(conte TempEvolutionFinishMs: entry.GetPokemonDisplay().TemporaryEvolutionFinishMs, Alignment: int(entry.GetPokemonDisplay().Alignment), Badge: int(entry.GetPokemonDisplay().PokemonBadge), - LocationCard: util.ExtractLocationCardFromDisplay(entry.PokemonDisplay), + Background: util.ExtractBackgroundFromDisplay(entry.PokemonDisplay), }) } diff --git a/sql/50_pokemon_background.up.sql b/sql/50_pokemon_background.up.sql new file mode 100644 index 00000000..8dcf5d0a --- /dev/null +++ b/sql/50_pokemon_background.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE pokemon + add `background` smallint unsigned DEFAULT NULL AFTER `shiny`; diff --git a/util/pogo.go b/util/pogo.go index dc92af7b..f29dbc24 100644 --- a/util/pogo.go +++ b/util/pogo.go @@ -27,7 +27,7 @@ var IncidentTypeToName = map[int8]string{ 9: "showcase", } -func ExtractLocationCardFromDisplay(display *pogo.PokemonDisplayProto) int { +func ExtractBackgroundFromDisplay(display *pogo.PokemonDisplayProto) int { if display.LocationCard == nil { return 0 } From a67fcc868f258de094529cf031c0273263f0e892 Mon Sep 17 00:00:00 2001 From: Fabio1988 Date: Thu, 16 Oct 2025 21:06:54 +0200 Subject: [PATCH 2/6] fix: util usage --- background.patch | 74 +++++++++++++++++++++++++++++++++++++++++++++ decoder/gym.go | 4 +-- decoder/pokemon.go | 5 ++- decoder/pokestop.go | 2 +- util/pogo.go | 4 +-- 5 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 background.patch diff --git a/background.patch b/background.patch new file mode 100644 index 00000000..db656441 --- /dev/null +++ b/background.patch @@ -0,0 +1,74 @@ +diff --git a/decoder/gym.go b/decoder/gym.go +index 09ecda6..117a42f 100644 +--- a/decoder/gym.go ++++ b/decoder/gym.go +@@ -181,7 +181,7 @@ func (gym *Gym) updateGymFromFort(fortData *pogo.PokemonFortProto, cellId uint64 + TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms,omitempty"` + Alignment int `json:"alignment,omitempty"` + Badge int `json:"badge,omitempty"` +- Background int `json:"background,omitempty"` ++ Background int64 `json:"background,omitempty"` + } + gym.Id = fortData.FortId + gym.Lat = fortData.Latitude //fmt.Sprintf("%f", fortData.Latitude) +@@ -331,7 +331,7 @@ func (gym *Gym) updateGymFromGymInfoOutProto(gymData *pogo.GymGetInfoOutProto) * + TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms,omitempty"` + Alignment int `json:"alignment,omitempty"` + Badge int `json:"badge,omitempty"` +- Background int `json:"background,omitempty"` ++ Background int64 `json:"background,omitempty"` + DeployedMs int64 `json:"deployed_ms,omitempty"` + DeployedTime int64 `json:"deployed_time,omitempty"` + BattlesWon int32 `json:"battles_won"` +diff --git a/decoder/pokemon.go b/decoder/pokemon.go +index 9894cdf..898c396 100644 +--- a/decoder/pokemon.go ++++ b/decoder/pokemon.go +@@ -6,6 +6,7 @@ import ( + "encoding/json" + "errors" + "fmt" ++ "golbat/util" + "strconv" + "strings" + "sync" +@@ -1108,9 +1109,7 @@ func (pokemon *Pokemon) clearIv(cp bool) { + func (pokemon *Pokemon) addEncounterPokemon(ctx context.Context, db db.DbDetails, proto *pogo.PokemonProto, username string) { + pokemon.Username = null.StringFrom(username) + pokemon.Shiny = null.BoolFrom(proto.PokemonDisplay.Shiny) +- if proto.PokemonDisplay.LocationCard != nil { +- pokemon.Background = null.IntFrom(int64(proto.PokemonDisplay.LocationCard.LocationCard.Number())) +- } ++ pokemon.Background = null.IntFrom(util.ExtractBackgroundFromDisplay(proto.PokemonDisplay)) + pokemon.Cp = null.IntFrom(int64(proto.Cp)) + pokemon.Move1 = null.IntFrom(int64(proto.Move1)) + pokemon.Move2 = null.IntFrom(int64(proto.Move2)) +diff --git a/decoder/pokestop.go b/decoder/pokestop.go +index 0a88fa3..4a3b4f5 100644 +--- a/decoder/pokestop.go ++++ b/decoder/pokestop.go +@@ -609,7 +609,7 @@ func (stop *Pokestop) updatePokestopFromGetPokemonSizeContestEntryOutProto(conte + TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms"` + Alignment int `json:"alignment"` + Badge int `json:"badge"` +- Background int `json:"background"` ++ Background int64 `json:"background"` + } + type contestJson struct { + TotalEntries int `json:"total_entries"` +diff --git a/util/pogo.go b/util/pogo.go +index f29dbc2..9c09f0c 100644 +--- a/util/pogo.go ++++ b/util/pogo.go +@@ -27,9 +27,9 @@ var IncidentTypeToName = map[int8]string{ + 9: "showcase", + } + +-func ExtractBackgroundFromDisplay(display *pogo.PokemonDisplayProto) int { ++func ExtractBackgroundFromDisplay(display *pogo.PokemonDisplayProto) int64 { + if display.LocationCard == nil { + return 0 + } +- return int(display.LocationCard.LocationCard) ++ return int64(display.LocationCard.LocationCard) + } diff --git a/decoder/gym.go b/decoder/gym.go index 09ecda6e..117a42ff 100644 --- a/decoder/gym.go +++ b/decoder/gym.go @@ -181,7 +181,7 @@ func (gym *Gym) updateGymFromFort(fortData *pogo.PokemonFortProto, cellId uint64 TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms,omitempty"` Alignment int `json:"alignment,omitempty"` Badge int `json:"badge,omitempty"` - Background int `json:"background,omitempty"` + Background int64 `json:"background,omitempty"` } gym.Id = fortData.FortId gym.Lat = fortData.Latitude //fmt.Sprintf("%f", fortData.Latitude) @@ -331,7 +331,7 @@ func (gym *Gym) updateGymFromGymInfoOutProto(gymData *pogo.GymGetInfoOutProto) * TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms,omitempty"` Alignment int `json:"alignment,omitempty"` Badge int `json:"badge,omitempty"` - Background int `json:"background,omitempty"` + Background int64 `json:"background,omitempty"` DeployedMs int64 `json:"deployed_ms,omitempty"` DeployedTime int64 `json:"deployed_time,omitempty"` BattlesWon int32 `json:"battles_won"` diff --git a/decoder/pokemon.go b/decoder/pokemon.go index 9894cdfa..898c396e 100644 --- a/decoder/pokemon.go +++ b/decoder/pokemon.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "fmt" + "golbat/util" "strconv" "strings" "sync" @@ -1108,9 +1109,7 @@ func (pokemon *Pokemon) clearIv(cp bool) { func (pokemon *Pokemon) addEncounterPokemon(ctx context.Context, db db.DbDetails, proto *pogo.PokemonProto, username string) { pokemon.Username = null.StringFrom(username) pokemon.Shiny = null.BoolFrom(proto.PokemonDisplay.Shiny) - if proto.PokemonDisplay.LocationCard != nil { - pokemon.Background = null.IntFrom(int64(proto.PokemonDisplay.LocationCard.LocationCard.Number())) - } + pokemon.Background = null.IntFrom(util.ExtractBackgroundFromDisplay(proto.PokemonDisplay)) pokemon.Cp = null.IntFrom(int64(proto.Cp)) pokemon.Move1 = null.IntFrom(int64(proto.Move1)) pokemon.Move2 = null.IntFrom(int64(proto.Move2)) diff --git a/decoder/pokestop.go b/decoder/pokestop.go index 0a88fa38..4a3b4f5a 100644 --- a/decoder/pokestop.go +++ b/decoder/pokestop.go @@ -609,7 +609,7 @@ func (stop *Pokestop) updatePokestopFromGetPokemonSizeContestEntryOutProto(conte TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms"` Alignment int `json:"alignment"` Badge int `json:"badge"` - Background int `json:"background"` + Background int64 `json:"background"` } type contestJson struct { TotalEntries int `json:"total_entries"` diff --git a/util/pogo.go b/util/pogo.go index f29dbc24..9c09f0cd 100644 --- a/util/pogo.go +++ b/util/pogo.go @@ -27,9 +27,9 @@ var IncidentTypeToName = map[int8]string{ 9: "showcase", } -func ExtractBackgroundFromDisplay(display *pogo.PokemonDisplayProto) int { +func ExtractBackgroundFromDisplay(display *pogo.PokemonDisplayProto) int64 { if display.LocationCard == nil { return 0 } - return int(display.LocationCard.LocationCard) + return int64(display.LocationCard.LocationCard) } From c63738bf9142e49fa555507cf240ede1e5a5c20f Mon Sep 17 00:00:00 2001 From: Fabio1988 Date: Thu, 16 Oct 2025 21:12:41 +0200 Subject: [PATCH 3/6] fix: set background in correct method --- decoder/pokemon.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/decoder/pokemon.go b/decoder/pokemon.go index 898c396e..41940919 100644 --- a/decoder/pokemon.go +++ b/decoder/pokemon.go @@ -1109,7 +1109,6 @@ func (pokemon *Pokemon) clearIv(cp bool) { func (pokemon *Pokemon) addEncounterPokemon(ctx context.Context, db db.DbDetails, proto *pogo.PokemonProto, username string) { pokemon.Username = null.StringFrom(username) pokemon.Shiny = null.BoolFrom(proto.PokemonDisplay.Shiny) - pokemon.Background = null.IntFrom(util.ExtractBackgroundFromDisplay(proto.PokemonDisplay)) pokemon.Cp = null.IntFrom(int64(proto.Cp)) pokemon.Move1 = null.IntFrom(int64(proto.Move1)) pokemon.Move2 = null.IntFrom(int64(proto.Move2)) @@ -1260,7 +1259,6 @@ func (pokemon *Pokemon) setPokemonDisplay(pokemonId int16, display *pogo.Pokemon pokemon.Move2 = null.NewInt(0, false) pokemon.Cp = null.NewInt(0, false) pokemon.Shiny = null.NewBool(false, false) - pokemon.Background = null.NewInt(0, false) pokemon.IsDitto = false pokemon.DisplayPokemonId = null.NewInt(0, false) pokemon.Pvp = null.NewString("", false) @@ -1272,6 +1270,7 @@ func (pokemon *Pokemon) setPokemonDisplay(pokemonId int16, display *pogo.Pokemon pokemon.Gender = null.IntFrom(int64(display.Gender)) pokemon.Form = null.IntFrom(int64(display.Form)) pokemon.Costume = null.IntFrom(int64(display.Costume)) + pokemon.Background = null.IntFrom(util.ExtractBackgroundFromDisplay(display)) if !pokemon.isNewRecord() { pokemon.repopulateIv(int64(display.WeatherBoostedCondition), display.IsStrongPokemon) } From 31c90670f597f166d991e13a865afe322478a919 Mon Sep 17 00:00:00 2001 From: Fabio1988 Date: Fri, 17 Oct 2025 09:39:28 +0200 Subject: [PATCH 4/6] fix: ExtractPokemonFromDisplay method --- decoder/gym.go | 20 ++++++++++---------- decoder/pokemon.go | 3 ++- decoder/pokestop.go | 4 ++-- util/pogo.go | 7 ++++--- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/decoder/gym.go b/decoder/gym.go index 117a42ff..c1fbd164 100644 --- a/decoder/gym.go +++ b/decoder/gym.go @@ -173,15 +173,15 @@ func calculatePowerUpPoints(fortData *pogo.PokemonFortProto) (null.Int, null.Int func (gym *Gym) updateGymFromFort(fortData *pogo.PokemonFortProto, cellId uint64) *Gym { type pokemonDisplay struct { - Form int `json:"form,omitempty"` - Costume int `json:"costume,omitempty"` - Gender int `json:"gender"` - Shiny bool `json:"shiny,omitempty"` - TempEvolution int `json:"temp_evolution,omitempty"` - TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms,omitempty"` - Alignment int `json:"alignment,omitempty"` - Badge int `json:"badge,omitempty"` - Background int64 `json:"background,omitempty"` + Form int `json:"form,omitempty"` + Costume int `json:"costume,omitempty"` + Gender int `json:"gender"` + Shiny bool `json:"shiny,omitempty"` + TempEvolution int `json:"temp_evolution,omitempty"` + TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms,omitempty"` + Alignment int `json:"alignment,omitempty"` + Badge int `json:"badge,omitempty"` + Background *int64 `json:"background,omitempty"` } gym.Id = fortData.FortId gym.Lat = fortData.Latitude //fmt.Sprintf("%f", fortData.Latitude) @@ -331,7 +331,7 @@ func (gym *Gym) updateGymFromGymInfoOutProto(gymData *pogo.GymGetInfoOutProto) * TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms,omitempty"` Alignment int `json:"alignment,omitempty"` Badge int `json:"badge,omitempty"` - Background int64 `json:"background,omitempty"` + Background *int64 `json:"background,omitempty"` DeployedMs int64 `json:"deployed_ms,omitempty"` DeployedTime int64 `json:"deployed_time,omitempty"` BattlesWon int32 `json:"battles_won"` diff --git a/decoder/pokemon.go b/decoder/pokemon.go index 41940919..4dcbd5ff 100644 --- a/decoder/pokemon.go +++ b/decoder/pokemon.go @@ -1247,6 +1247,7 @@ func (pokemon *Pokemon) setPokemonDisplay(pokemonId int16, display *pogo.Pokemon if oldId != pokemonId || pokemon.Form != null.IntFrom(int64(display.Form)) || pokemon.Costume != null.IntFrom(int64(display.Costume)) || pokemon.Gender != null.IntFrom(int64(display.Gender)) || + pokemon.Background != null.IntFromPtr(util.ExtractBackgroundFromDisplay(display)) || pokemon.IsStrong.ValueOrZero() != display.IsStrongPokemon { log.Debugf("Pokemon %d changed from (%d,%d,%d,%d,%t) to (%d,%d,%d,%d,%t)", pokemon.Id, oldId, pokemon.Form.ValueOrZero(), pokemon.Costume.ValueOrZero(), pokemon.Gender.ValueOrZero(), @@ -1270,7 +1271,7 @@ func (pokemon *Pokemon) setPokemonDisplay(pokemonId int16, display *pogo.Pokemon pokemon.Gender = null.IntFrom(int64(display.Gender)) pokemon.Form = null.IntFrom(int64(display.Form)) pokemon.Costume = null.IntFrom(int64(display.Costume)) - pokemon.Background = null.IntFrom(util.ExtractBackgroundFromDisplay(display)) + pokemon.Background = null.IntFromPtr(util.ExtractBackgroundFromDisplay(display)) if !pokemon.isNewRecord() { pokemon.repopulateIv(int64(display.WeatherBoostedCondition), display.IsStrongPokemon) } diff --git a/decoder/pokestop.go b/decoder/pokestop.go index 4a3b4f5a..ee910222 100644 --- a/decoder/pokestop.go +++ b/decoder/pokestop.go @@ -454,7 +454,7 @@ func (stop *Pokestop) updatePokestopFromQuestProto(questProto *pogo.FortSearchOu if display.Shiny { infoData["shiny"] = display.Shiny } - if background := util.ExtractBackgroundFromDisplay(display); background != 0 { + if background := util.ExtractBackgroundFromDisplay(display); background != nil { infoData["background"] = background } if breadMode := int(display.BreadModeEnum); breadMode != 0 { @@ -609,7 +609,7 @@ func (stop *Pokestop) updatePokestopFromGetPokemonSizeContestEntryOutProto(conte TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms"` Alignment int `json:"alignment"` Badge int `json:"badge"` - Background int64 `json:"background"` + Background *int64 `json:"background,omitempty"` } type contestJson struct { TotalEntries int `json:"total_entries"` diff --git a/util/pogo.go b/util/pogo.go index 9c09f0cd..a4634634 100644 --- a/util/pogo.go +++ b/util/pogo.go @@ -27,9 +27,10 @@ var IncidentTypeToName = map[int8]string{ 9: "showcase", } -func ExtractBackgroundFromDisplay(display *pogo.PokemonDisplayProto) int64 { +func ExtractBackgroundFromDisplay(display *pogo.PokemonDisplayProto) *int64 { if display.LocationCard == nil { - return 0 + return nil } - return int64(display.LocationCard.LocationCard) + result := int64(display.LocationCard.LocationCard) + return &result } From 0c15f761ee020332b45adf1ee4727f8e8d17ec52 Mon Sep 17 00:00:00 2001 From: Fabio1988 Date: Sat, 18 Oct 2025 11:54:31 +0200 Subject: [PATCH 5/6] fix: Add background to in-memory result --- decoder/api_pokemon_common.go | 107 ++++++++++++++++----------------- decoder/api_pokemon_scan_v1.go | 2 + 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/decoder/api_pokemon_common.go b/decoder/api_pokemon_common.go index d492a0f0..d62381a0 100644 --- a/decoder/api_pokemon_common.go +++ b/decoder/api_pokemon_common.go @@ -1,61 +1,60 @@ package decoder import ( - "github.com/UnownHash/gohbem" + "github.com/UnownHash/gohbem" ) func buildApiPokemonResult(pokemon *Pokemon) ApiPokemonResult { - return ApiPokemonResult{ - Id: pokemon.Id, - PokestopId: pokemon.PokestopId, - SpawnId: pokemon.SpawnId, - Lat: pokemon.Lat, - Lon: pokemon.Lon, - Weight: pokemon.Weight, - Size: pokemon.Size, - Height: pokemon.Height, - ExpireTimestamp: pokemon.ExpireTimestamp, - Updated: pokemon.Updated, - PokemonId: pokemon.PokemonId, - Move1: pokemon.Move1, - Move2: pokemon.Move2, - Gender: pokemon.Gender, - Cp: pokemon.Cp, - AtkIv: pokemon.AtkIv, - DefIv: pokemon.DefIv, - StaIv: pokemon.StaIv, - Iv: pokemon.Iv, - Form: pokemon.Form, - Level: pokemon.Level, - Weather: pokemon.Weather, - Costume: pokemon.Costume, - FirstSeenTimestamp: pokemon.FirstSeenTimestamp, - Changed: pokemon.Changed, - CellId: pokemon.CellId, - ExpireTimestampVerified: pokemon.ExpireTimestampVerified, - DisplayPokemonId: pokemon.DisplayPokemonId, - IsDitto: pokemon.IsDitto, - SeenType: pokemon.SeenType, - Shiny: pokemon.Shiny, - Username: pokemon.Username, - Pvp: func() map[string][]gohbem.PokemonEntry { - if ohbem != nil { - pvp, err := ohbem.QueryPvPRank(int(pokemon.PokemonId), - int(pokemon.Form.ValueOrZero()), - int(pokemon.Costume.ValueOrZero()), - int(pokemon.Gender.ValueOrZero()), - int(pokemon.AtkIv.ValueOrZero()), - int(pokemon.DefIv.ValueOrZero()), - int(pokemon.StaIv.ValueOrZero()), - float64(pokemon.Level.ValueOrZero())) - if err != nil { - return nil - } - return pvp - } - return nil - }(), - } + return ApiPokemonResult{ + Id: pokemon.Id, + PokestopId: pokemon.PokestopId, + SpawnId: pokemon.SpawnId, + Lat: pokemon.Lat, + Lon: pokemon.Lon, + Weight: pokemon.Weight, + Size: pokemon.Size, + Height: pokemon.Height, + ExpireTimestamp: pokemon.ExpireTimestamp, + Updated: pokemon.Updated, + PokemonId: pokemon.PokemonId, + Move1: pokemon.Move1, + Move2: pokemon.Move2, + Gender: pokemon.Gender, + Cp: pokemon.Cp, + AtkIv: pokemon.AtkIv, + DefIv: pokemon.DefIv, + StaIv: pokemon.StaIv, + Iv: pokemon.Iv, + Form: pokemon.Form, + Level: pokemon.Level, + Weather: pokemon.Weather, + Costume: pokemon.Costume, + FirstSeenTimestamp: pokemon.FirstSeenTimestamp, + Changed: pokemon.Changed, + CellId: pokemon.CellId, + ExpireTimestampVerified: pokemon.ExpireTimestampVerified, + DisplayPokemonId: pokemon.DisplayPokemonId, + IsDitto: pokemon.IsDitto, + SeenType: pokemon.SeenType, + Shiny: pokemon.Shiny, + Background: pokemon.Background, + Username: pokemon.Username, + Pvp: func() map[string][]gohbem.PokemonEntry { + if ohbem != nil { + pvp, err := ohbem.QueryPvPRank(int(pokemon.PokemonId), + int(pokemon.Form.ValueOrZero()), + int(pokemon.Costume.ValueOrZero()), + int(pokemon.Gender.ValueOrZero()), + int(pokemon.AtkIv.ValueOrZero()), + int(pokemon.DefIv.ValueOrZero()), + int(pokemon.StaIv.ValueOrZero()), + float64(pokemon.Level.ValueOrZero())) + if err != nil { + return nil + } + return pvp + } + return nil + }(), + } } - - diff --git a/decoder/api_pokemon_scan_v1.go b/decoder/api_pokemon_scan_v1.go index 073c6b1d..de72c8ff 100644 --- a/decoder/api_pokemon_scan_v1.go +++ b/decoder/api_pokemon_scan_v1.go @@ -48,6 +48,7 @@ type ApiPokemonResult struct { IsDitto bool `json:"is_ditto"` SeenType null.String `json:"seen_type"` Shiny null.Bool `json:"shiny"` + Background null.Int `json:"background"` Username null.String `json:"username"` Capture1 null.Float `json:"capture_1"` Capture2 null.Float `json:"capture_2"` @@ -308,6 +309,7 @@ func GetPokemonInArea(retrieveParameters ApiPokemonScan) []*ApiPokemonResult { IsDitto: pokemon.IsDitto, SeenType: pokemon.SeenType, Shiny: pokemon.Shiny, + Background: pokemon.Background, Username: pokemon.Username, Pvp: func() map[string][]gohbem.PokemonEntry { if ohbem != nil { From bea33d2b6f450074311d4a86c2dd01afee5b55da Mon Sep 17 00:00:00 2001 From: Fabio1988 Date: Sat, 18 Oct 2025 12:11:36 +0200 Subject: [PATCH 6/6] fix: remove diff patch file --- background.patch | 74 ------------------------------------------------ 1 file changed, 74 deletions(-) delete mode 100644 background.patch diff --git a/background.patch b/background.patch deleted file mode 100644 index db656441..00000000 --- a/background.patch +++ /dev/null @@ -1,74 +0,0 @@ -diff --git a/decoder/gym.go b/decoder/gym.go -index 09ecda6..117a42f 100644 ---- a/decoder/gym.go -+++ b/decoder/gym.go -@@ -181,7 +181,7 @@ func (gym *Gym) updateGymFromFort(fortData *pogo.PokemonFortProto, cellId uint64 - TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms,omitempty"` - Alignment int `json:"alignment,omitempty"` - Badge int `json:"badge,omitempty"` -- Background int `json:"background,omitempty"` -+ Background int64 `json:"background,omitempty"` - } - gym.Id = fortData.FortId - gym.Lat = fortData.Latitude //fmt.Sprintf("%f", fortData.Latitude) -@@ -331,7 +331,7 @@ func (gym *Gym) updateGymFromGymInfoOutProto(gymData *pogo.GymGetInfoOutProto) * - TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms,omitempty"` - Alignment int `json:"alignment,omitempty"` - Badge int `json:"badge,omitempty"` -- Background int `json:"background,omitempty"` -+ Background int64 `json:"background,omitempty"` - DeployedMs int64 `json:"deployed_ms,omitempty"` - DeployedTime int64 `json:"deployed_time,omitempty"` - BattlesWon int32 `json:"battles_won"` -diff --git a/decoder/pokemon.go b/decoder/pokemon.go -index 9894cdf..898c396 100644 ---- a/decoder/pokemon.go -+++ b/decoder/pokemon.go -@@ -6,6 +6,7 @@ import ( - "encoding/json" - "errors" - "fmt" -+ "golbat/util" - "strconv" - "strings" - "sync" -@@ -1108,9 +1109,7 @@ func (pokemon *Pokemon) clearIv(cp bool) { - func (pokemon *Pokemon) addEncounterPokemon(ctx context.Context, db db.DbDetails, proto *pogo.PokemonProto, username string) { - pokemon.Username = null.StringFrom(username) - pokemon.Shiny = null.BoolFrom(proto.PokemonDisplay.Shiny) -- if proto.PokemonDisplay.LocationCard != nil { -- pokemon.Background = null.IntFrom(int64(proto.PokemonDisplay.LocationCard.LocationCard.Number())) -- } -+ pokemon.Background = null.IntFrom(util.ExtractBackgroundFromDisplay(proto.PokemonDisplay)) - pokemon.Cp = null.IntFrom(int64(proto.Cp)) - pokemon.Move1 = null.IntFrom(int64(proto.Move1)) - pokemon.Move2 = null.IntFrom(int64(proto.Move2)) -diff --git a/decoder/pokestop.go b/decoder/pokestop.go -index 0a88fa3..4a3b4f5 100644 ---- a/decoder/pokestop.go -+++ b/decoder/pokestop.go -@@ -609,7 +609,7 @@ func (stop *Pokestop) updatePokestopFromGetPokemonSizeContestEntryOutProto(conte - TempEvolutionFinishMs int64 `json:"temp_evolution_finish_ms"` - Alignment int `json:"alignment"` - Badge int `json:"badge"` -- Background int `json:"background"` -+ Background int64 `json:"background"` - } - type contestJson struct { - TotalEntries int `json:"total_entries"` -diff --git a/util/pogo.go b/util/pogo.go -index f29dbc2..9c09f0c 100644 ---- a/util/pogo.go -+++ b/util/pogo.go -@@ -27,9 +27,9 @@ var IncidentTypeToName = map[int8]string{ - 9: "showcase", - } - --func ExtractBackgroundFromDisplay(display *pogo.PokemonDisplayProto) int { -+func ExtractBackgroundFromDisplay(display *pogo.PokemonDisplayProto) int64 { - if display.LocationCard == nil { - return 0 - } -- return int(display.LocationCard.LocationCard) -+ return int64(display.LocationCard.LocationCard) - }