Skip to content

Commit

Permalink
Get Info/Tile ID - Add Sanity Checks
Browse files Browse the repository at this point in the history
Now the behaviors are similar both in Maniacs and EasyRPG.
  • Loading branch information
jetrotal committed Jan 8, 2025
1 parent 349232d commit a6f98cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4102,6 +4102,8 @@ bool Game_Interpreter::CommandManiacGetGameInfo(lcf::rpg::EventCommand const& co
tile_coords.w = ValueOrVariableBitfield(com.parameters[0], 3, com.parameters[5]);
tile_coords.h = ValueOrVariableBitfield(com.parameters[0], 4, com.parameters[6]);

if (tile_coords.w <= 0 || tile_coords.h <= 0) return true;

auto tiles = Game_Map::GetTilesIdAt(tile_coords.x, tile_coords.y, tile_coords.w, tile_coords.h, tile_layer);

for (int i = 0; i < tile_coords.w * tile_coords.h; i++) {
Expand Down
4 changes: 4 additions & 0 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,10 @@ void Game_Map::ReplaceTileAt(int x, int y, int new_id, int layer) {
}

int Game_Map::GetTileIdAt(int x, int y, int layer, bool chipIdOrIndex) {
if (x < 0 || x >= map->width || y < 0 || y >= map->height) {
return 0; // Return 0 for out-of-bounds coordinates
}

auto pos = x + y * map->width;
auto& layer_vec = layer >= 1 ? map->upper_layer : map->lower_layer;

Expand Down

0 comments on commit a6f98cb

Please sign in to comment.