From 6c02793bd9960d3988c482fbd945b705e1693af9 Mon Sep 17 00:00:00 2001 From: devseed Date: Mon, 2 Dec 2024 01:41:52 +0900 Subject: [PATCH] add baranoki_fnt_psp for non monospace font --- Readme.md | 2 +- asset/plugin/baranoki_fnt_psp.lua | 72 ++++++++++++++++++++++++++++ asset/plugin/lualib/util_declear.lua | 5 +- src/core_solver.cpp | 4 +- src/plugin_lua.c | 7 +++ 5 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 asset/plugin/baranoki_fnt_psp.lua diff --git a/Readme.md b/Readme.md index 58bbaf5..5cb8f67 100644 --- a/Readme.md +++ b/Readme.md @@ -6,7 +6,7 @@ Also, it supports for droping file, save decoded image and show cursor moving in tiles. Futhermore, the window is flexible for changing size and support for zooming in and out with converting the client coordinate to logical coordinate. -The main purpose is for analyzing game font or textures. +The main purpose is for analyzing game font or textures. See [TileDB](https://github.com/YuriSizuku/TileViewer/wiki/Font-Database) and [TexDB](https://github.com/YuriSizuku/TileViewer/wiki/Texture-Database) in detail. ![tile_test1](asset/picture/tile_test1.png) (example of decoding a 2bpp tile font) diff --git a/asset/plugin/baranoki_fnt_psp.lua b/asset/plugin/baranoki_fnt_psp.lua new file mode 100644 index 0000000..42167c5 --- /dev/null +++ b/asset/plugin/baranoki_fnt_psp.lua @@ -0,0 +1,72 @@ +---@diagnostic disable : lowercase-global, missing-fields, undefined-global, duplicate-doc-field, undefined-field + +version = "v0.1" +description = "[lua_baranoki_fnt::init] lua plugin to decode BaranoKiniBaranoSaku 4bpp non monospace font" + +-- struct declear +---@class fontentry_t -- 10 bytes +---@field wchar string +---@field dispw integer +---@field tilew integer +---@field tileh integer +---@field x integer +---@field y integer +---@field offset integer + +-- global declear +g_data = nil --- @type string +g_tilecfg = nil ---@type tilecfg_t +g_fontmap = {} + +function decode_pre() + --- get neccessory data for decoding + g_tilecfg = get_tilecfg() + g_data = get_rawdata() + + --- set the information for decoding + local bpp, w, count = string.unpack("= w or y1 >= h) then return 0 end + local pixeli = y1*w + x1 + local offset = g_fontmap[i].offset + pixeli * bpp // 8 + if(offset >= g_data:len()) then return 0 end + + d = string.byte(g_data, offset + 1) + if(pixeli%2 == 0) then d = (d>>4) & 0xf + else d = d & 0xf end + d = 255 * d // (2<sendui(decoder->context, &text, &textsize); wxtext.Append(text); - if(decoder->msg) + if(decoder->msg && decoder->msg[0]) { wxLogMessage("[TileSolver::LoadDecoder] %s decoder->sendui msg: \n %s", m_pluginfile.GetFullName(), decoder->msg); @@ -262,7 +262,7 @@ int TileSolver::Decode(struct tilecfg_t *tilecfg, wxFileName pluginfile) if(!wxGetApp().m_usegui) wxtext = m_plugincfg; else wxtext = wxGetApp().m_configwindow->GetPlugincfg(); decoder->recvui(decoder->context, wxtext.mb_str(), wxtext.size()); - if(decoder->msg) + if(decoder->msg && decoder->msg[0]) { wxLogMessage("[TileSolver::Decode] %s decoder->recvui msg: \n %s", m_pluginfile.GetFullName(), decoder->msg); diff --git a/src/plugin_lua.c b/src/plugin_lua.c index 10719f2..c480000 100644 --- a/src/plugin_lua.c +++ b/src/plugin_lua.c @@ -312,6 +312,7 @@ PLUGIN_STATUS decode_sendui_lua(void *context, const char **buf, size_t *bufsize if(!lua_isfunction(L, -1)) { lua_pop(L, 1); + if(s_msg[strlen(s_msg) - 1] =='\n') s_msg[strlen(s_msg) - 1] = '\0'; return STATUS_CALLBACKERROR; } lua_call(L, 0, 1); @@ -334,6 +335,7 @@ PLUGIN_STATUS decode_recvui_lua(void *context, const char *buf, size_t bufsize) if(!lua_isfunction(L, -1)) { lua_pop(L, 1); + if(s_msg[strlen(s_msg) - 1] =='\n') s_msg[strlen(s_msg) - 1] = '\0'; return STATUS_CALLBACKERROR; } @@ -372,6 +374,8 @@ PLUGIN_STATUS decode_recvui_lua(void *context, const char *buf, size_t bufsize) return res ? STATUS_OK : STATUS_FAIL; decode_recvui_lua_fail: + if(s_msg[strlen(s_msg) - 1] =='\n') s_msg[strlen(s_msg) - 1] = '\0'; + cJSON_Delete(root); return STATUS_FAIL; } @@ -388,6 +392,7 @@ PLUGIN_STATUS decode_pixel_lua(void *context, if(!lua_isfunction(L, -1)) { lua_pop(L, 1); + if(s_msg[strlen(s_msg) - 1] =='\n') s_msg[strlen(s_msg) - 1] = '\0'; return STATUS_CALLBACKERROR; } lua_pushinteger(L, pos->i); @@ -416,6 +421,7 @@ PLUGIN_STATUS decode_pre_lua(void *context, if(!lua_isfunction(L, -1)) { lua_pop(L, 1); + if(s_msg[strlen(s_msg) - 1] =='\n') s_msg[strlen(s_msg) - 1] = '\0'; return STATUS_CALLBACKERROR; } lua_call(L, 0, 1); @@ -435,6 +441,7 @@ PLUGIN_STATUS decode_post_lua(void *context, if(!lua_isfunction(L, -1)) { lua_pop(L, 1); + if(s_msg[strlen(s_msg) - 1] =='\n') s_msg[strlen(s_msg) - 1] = '\0'; return STATUS_CALLBACKERROR; } lua_call(L, 0, 1);