Skip to content

Commit

Permalink
FF8: Increase max texture size to 16384 for external textures (#601)
Browse files Browse the repository at this point in the history
Additionally fix also minor crashes happening on Non-US versions
  • Loading branch information
myst6re committed Sep 14, 2023
1 parent 612f2ef commit 5c7da23
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 32 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

- Graphics: Fix crash when using external texture replacement ( https://github.com/julianxhokaxhiu/FFNx/pull/588 )
- Graphics: Fix texture glitches using external texture replacement ( https://github.com/julianxhokaxhiu/FFNx/pull/591 )
- Graphics: Fix external texture blending ( https://github.com/julianxhokaxhiu/FFNx/pull/598 )
- Graphics: Fix external texture blending ( https://github.com/julianxhokaxhiu/FFNx/pull/598 https://github.com/julianxhokaxhiu/FFNx/pull/601 )
- Graphics: Increase max texture size to 16384 for external textures ( https://github.com/julianxhokaxhiu/FFNx/pull/601 )
- Music: Add `ff8_external_music_force_original_filenames` option to use original music names (eg 018s-julia.ogg) instead of just the main identifier in external music ( https://github.com/julianxhokaxhiu/FFNx/pull/594 )
- Voice: Enable battle dialogs voice acting
- Voice: Enable worldmap voice acting
Expand Down
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

#define NV_VERSION (!(version & 1))
#define JP_VERSION (version == VERSION_FF8_12_JP || version == VERSION_FF8_12_JP_NV)
#define FF8_US_VERSION (version == VERSION_FF8_12_US || version == VERSION_FF8_12_US_NV || version == VERSION_FF8_12_US_EIDOS || version == VERSION_FF8_12_US_EIDOS_NV)

// FF8 does not support BLUE text!
enum
Expand Down
41 changes: 27 additions & 14 deletions src/ff8/texture_packer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,16 @@ uint8_t TexturePacker::getMaxScale(const uint8_t *texData) const
return 1;
}

if (!_tiledTexs.contains(texData))
auto it = _tiledTexs.find(texData);

if (it == _tiledTexs.end())
{
if (trace_all || trace_vram) ffnx_warning("TexturePacker::%s Unknown tex data\n", __func__);

return 0;
}

const TiledTex &tiledTex = _tiledTexs.at(texData);
const TiledTex &tiledTex = it->second;

uint8_t maxScale = 1;

Expand Down Expand Up @@ -291,13 +293,6 @@ uint8_t TexturePacker::getMaxScale(const uint8_t *texData) const
}
}

if (maxScale > MAX_SCALE)
{
ffnx_warning("External texture size cannot exceed original size * %d\n", MAX_SCALE);

return MAX_SCALE;
}

return maxScale;
}

Expand Down Expand Up @@ -659,6 +654,13 @@ uint8_t TexturePacker::TextureInfos::computeScale(int sourcePixelW, int sourceH,
return 0;
}

if (scaleW > MAX_SCALE)
{
ffnx_warning("External texture size cannot exceed \"original size * %d\" (scale=%d)\n", MAX_SCALE, scaleW);

return 0;
}

return scaleW;
}

Expand Down Expand Up @@ -688,7 +690,7 @@ void TexturePacker::TextureInfos::copyRect(
{
uint32_t color = *(sourceRGBA + x / scaleRatio + y / scaleRatio * sourceW);
uint32_t alpha = color & 0xFF000000;
*(targetRGBA + x + y * targetW) = (color & 0xFFFFFF) | (alpha == 0xFF000000 ? 0x7F000000 : 0);
*(targetRGBA + x + y * targetW) = (color & 0xFFFFFF) | (alpha >= 0x7F000000 ? 0x7F000000 : 0);
}
}
}
Expand Down Expand Up @@ -717,6 +719,12 @@ bool TexturePacker::Texture::createImage(uint8_t palette_index, bool has_pal, co

uint8_t scale = computeScale();

if (trace_all || trace_vram)
{
ffnx_info("TexturePacker::Texture::%s: width=%d height=%d offset=%d format=%d size=%d depth=%d numLayers=%d numMips=%d hasAlpha=%d scale=%d\n", __func__,
_image->m_width, _image->m_height, _image->m_offset, _image->m_format, _image->m_size, _image->m_depth, _image->m_numLayers, _image->m_numMips, _image->m_hasAlpha);
}

if (scale == 0)
{
destroyImage();
Expand Down Expand Up @@ -746,7 +754,7 @@ void TexturePacker::Texture::copyRect(int vramXBpp2, int vramY, Tim::Bpp texture
{
if (bpp() == textureBpp) {
TextureInfos::copyRect(
(const uint32_t *)_image->m_data, vramXBpp2 - x(), vramY - y(), _image->m_width, _scale, bpp(),
(const uint32_t *)_image->m_data + _image->m_offset, vramXBpp2 - x(), vramY - y(), _image->m_width, _scale, bpp(),
target, targetX, targetY, targetW, targetScale
);
}
Expand Down Expand Up @@ -801,7 +809,8 @@ bool TexturePacker::TextureBackground::createImage(const char *extension, char *
void TexturePacker::TextureBackground::copyRect(int vramXBpp2, int vramY, Tim::Bpp textureBpp, uint32_t *target, int targetX, int targetY, int targetW, uint8_t targetScale) const
{
const int sourceXBpp2 = vramXBpp2 - x(), sourceY = vramY - y();
const uint8_t textureId = _textureId >= 0 ? _textureId : sourceXBpp2 / TEXTURE_WIDTH_BPP16;
const bool withTextureId = _textureId >= 0;
const uint8_t textureId = withTextureId ? _textureId : sourceXBpp2 / TEXTURE_WIDTH_BPP16;
const uint16_t sourceX = (sourceXBpp2 % TEXTURE_WIDTH_BPP16) << (2 - int(textureBpp));
const uint16_t key = uint16_t(textureId) | (uint16_t(sourceX / TILE_SIZE) << 4) | (uint16_t(sourceY / TILE_SIZE) << 8) | (uint16_t(textureBpp) << 12);

Expand All @@ -810,6 +819,10 @@ void TexturePacker::TextureBackground::copyRect(int vramXBpp2, int vramY, Tim::B
return;
}

const bimg::ImageContainer *img = image();
const uint32_t *imgData = (const uint32_t *)img->m_data + img->m_offset;
uint32_t imgWidth = img->m_width;
uint8_t imgScale = scale();
bool multiMatch = _tileIdsByPosition.count(key) > 1, matched = false;

// Iterate over matching tiles
Expand Down Expand Up @@ -838,11 +851,11 @@ void TexturePacker::TextureBackground::copyRect(int vramXBpp2, int vramY, Tim::B
}

const int col = tileId % _colsCount, row = tileId / _colsCount;
const int srcX = _textureId >= 0 ? tile.srcX : col * TILE_SIZE, srcY = _textureId >= 0 ? tile.srcY : row * TILE_SIZE;
const int srcX = withTextureId ? tile.srcX : col * TILE_SIZE, srcY = withTextureId ? tile.srcY : row * TILE_SIZE;
const int imageXBpp2 = srcX / (4 >> int(textureBpp)) + sourceXBpp2 % (4 << int(textureBpp)), imageY = srcY + sourceY % TILE_SIZE;

TextureInfos::copyRect(
(const uint32_t *)image()->m_data, imageXBpp2, imageY, image()->m_width, scale(), textureBpp,
imgData, imageXBpp2, imageY, imgWidth, imgScale, textureBpp,
target, targetX, targetY, targetW, targetScale
);

Expand Down
2 changes: 1 addition & 1 deletion src/ff8/texture_packer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ constexpr int VRAM_WIDTH = 1024;
constexpr int VRAM_HEIGHT = 512;
constexpr int VRAM_DEPTH = 2;
constexpr ModdedTextureId INVALID_TEXTURE = ModdedTextureId(0xFFFFFFFF);
constexpr int MAX_SCALE = 10;
constexpr int MAX_SCALE = 128;

class TexturePacker {
public:
Expand Down
2 changes: 1 addition & 1 deletion src/ff8/uv_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void uv_patch_init()
* - And when the game uses the UVs from the SSIGPU instruction, we alter
* the computation of U and V using the forgotten bits.
*/
bool isUs = version == VERSION_FF8_12_US || version == VERSION_FF8_12_US_NV || version == VERSION_FF8_12_US_EIDOS || version == VERSION_FF8_12_US_EIDOS_NV;
bool isUs = version == FF8_US_VERSION;

// Worldmap with Fog enabled
replace_call(ff8_externals.sub_53BB90 + (isUs ? 0x42D : 0x43B), worldmap_fog_filter_polygons_in_block_1);
Expand Down
2 changes: 1 addition & 1 deletion src/ff8_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ void ff8_find_externals()
ff8_externals.ssigpu_init = get_relative_call(ff8_externals.sub_45B460, 0x26);
ff8_externals.d3dcaps = (uint32_t *)get_absolute_value(ff8_externals.ssigpu_init, 0x6C);

if(version == VERSION_FF8_12_US || version == VERSION_FF8_12_US_NV || version == VERSION_FF8_12_US_EIDOS || version == VERSION_FF8_12_US_EIDOS_NV)
if(version == FF8_US_VERSION)
{
ff8_externals.worldmap_section38_position = (uint32_t **)get_absolute_value(ff8_externals.worldmap_sub_53F310, 0x296);
ff8_externals.worldmap_section39_position = (uint32_t **)get_absolute_value(ff8_externals.worldmap_sub_53F310, 0x321);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,7 @@ bimg::ImageContainer* Renderer::createImageContainer(cmrc::file* file, bimg::Tex
{
if (trace_all || trace_renderer) ffnx_trace("Renderer::%s: convert image to format %d\n", __func__, targetFormat);

bimg::ImageContainer* converted = bimg::imageConvert(&defaultAllocator, targetFormat, *img);
bimg::ImageContainer* converted = bimg::imageConvert(&defaultAllocator, targetFormat, *img, false);

bimg::imageFree(img);

Expand Down
25 changes: 13 additions & 12 deletions src/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1255,17 +1255,18 @@ void voice_init()
replace_function(ff8_externals.battle_get_actor_name_sub_47EAF0, ff8_battle_get_actor_name);

// == World Map ==
replace_call_function(ff8_externals.sub_543CB0 + 0x638, ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_5484B0 + 0x524, ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54A230 + 0xF, ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54D7E0 + 0x72, ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + 0x206, ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + 0x396, ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + 0x3D2, ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + 0x67D, ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + 0x6A6, ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + 0xEED, ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54FDA0 + 0xAE, ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54FDA0 + 0x178, ff8_world_dialog_assign_text);
bool isUs = version == FF8_US_VERSION;
replace_call_function(ff8_externals.sub_543CB0 + (isUs ? 0x638 : 0x605), ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_5484B0 + (isUs ? 0x524 : 0x4FD), ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54A230 + (isUs ? 0xF : 0xD), ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54D7E0 + (isUs ? 0x72 : 0x6F), ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + (isUs ? 0x206 : 0x20C), ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + (isUs ? 0x396 : 0x3A9), ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + (isUs ? 0x3D2 : 0x3E5), ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + (isUs ? 0x67D : 0x68F), ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + (isUs ? 0x6A6 : 0x6BC), ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + (isUs ? 0xEED : 0xF72), ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54FDA0 + (isUs ? 0xAE : 0xAC), ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54FDA0 + (isUs ? 0x178 : 0x175), ff8_world_dialog_assign_text);
}
}
2 changes: 1 addition & 1 deletion src/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void world_init()
playerPosZ = playerPosX+1;
playerPosY = playerPosX+2;
BYTE *wm_struct;
if(version == VERSION_FF8_12_US || version == VERSION_FF8_12_US_NV || version == VERSION_FF8_12_US_EIDOS || version == VERSION_FF8_12_US_EIDOS_NV)
if(version == FF8_US_VERSION)
{
wm_struct = (BYTE*)get_absolute_value(ff8_externals.sub_53C750, 0x633);
bCollisionEnabled = (DWORD*)get_absolute_value(ff8_externals.sub_53E6B0, 0x4);
Expand Down

0 comments on commit 5c7da23

Please sign in to comment.