[WIP] Added external texture loader

This commit is contained in:
KiritoDev 2022-04-26 16:57:40 -05:00
commit 6373e7c57d
19 changed files with 169 additions and 119 deletions

View file

@ -5,7 +5,7 @@
#include <string>
#include <stdint.h>
#include <map>
#include <unordered_map>
#include <string>
#include <vector>
#include "Resource.h"
@ -43,9 +43,9 @@ namespace Ship
private:
std::string MainPath;
std::string PatchesPath;
std::map<std::string, HANDLE> mpqHandles;
std::unordered_map<std::string, HANDLE> mpqHandles;
std::vector<std::string> addedFiles;
std::map<uint64_t, std::string> hashes;
std::unordered_map<uint64_t, std::string> hashes;
HANDLE mainMPQ;
bool LoadMainMPQ(bool enableWriting, bool genCRCMap);

View file

@ -82,4 +82,8 @@ namespace Ship {
std::cout << "Log initialization failed: " << ex.what() << std::endl;
}
}
ModManager* GlobalCtx2::GetModManager() {
return INSTANCE;
}
}

View file

@ -6,6 +6,7 @@
#include "ConfigFile.h"
namespace Ship {
class ModManager;
class ResourceMgr;
class Window;
@ -19,6 +20,7 @@ namespace Ship {
std::shared_ptr<ResourceMgr> GetResourceManager() { return ResMan; }
std::shared_ptr<spdlog::logger> GetLogger() { return Logger; }
std::shared_ptr<ConfigFile> GetConfig() { return Config; }
ModManager* GetModManager();
GlobalCtx2(const std::string& Name);
~GlobalCtx2();

View file

@ -25,6 +25,8 @@
#include "gfx_rendering_api.h"
#include "gfx_screen_config.h"
#include "../../SohHooks.h"
#include "../../GlobalCtx2.h"
#include "../../TextureMod.h"
#include "../../luslog.h"
#include "../StrHash64.h"
@ -95,8 +97,8 @@ struct ColorCombiner {
uint8_t shader_input_mapping[2][7];
};
static map<uint64_t, struct ColorCombiner> color_combiner_pool;
static map<uint64_t, struct ColorCombiner>::iterator prev_combiner = color_combiner_pool.end();
static unordered_map<uint64_t, struct ColorCombiner> color_combiner_pool;
static unordered_map<uint64_t, struct ColorCombiner>::iterator prev_combiner = color_combiner_pool.end();
static struct RSP {
float modelview_matrix_stack[11][4][4];
@ -203,8 +205,8 @@ struct FBInfo {
};
static bool fbActive = 0;
static map<int, FBInfo>::iterator active_fb;
static map<int, FBInfo> framebuffers;
static unordered_map<int, FBInfo>::iterator active_fb;
static unordered_map<int, FBInfo> framebuffers;
static set<pair<float, float>> get_pixel_depth_pending;
static map<pair<float, float>, uint16_t> get_pixel_depth_cached;
@ -218,6 +220,7 @@ static unsigned long get_time(void)
#else
#include <time.h>
#include <string>
#include "../../GlobalCtx2.h"
static unsigned long get_time(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
@ -826,6 +829,11 @@ static void import_texture(int i, int tile) {
uint8_t siz = rdp.texture_tile[tile].siz;
uint32_t tmem_index = rdp.texture_tile[tile].tmem_index;
Ship::TextureModule* tex_module = Ship::GlobalCtx2::GetInstance()->GetModManager()->TextureMod;
if(tex_module->LookupTexture(i, rdp.loaded_texture[tmem_index].otr_path, gfx_get_current_rendering_api(), &rendering_state.textures[i], fmt, siz, rdp.texture_tile[tile].palette, rdp.loaded_texture[tmem_index].addr)) {
return;
}
if (gfx_texture_cache_lookup(i, tile))
{
return;
@ -848,7 +856,7 @@ static void import_texture(int i, int tile) {
} else if (siz == G_IM_SIZ_16b) {
import_texture_ia16(tile);
} else {
abort();
// abort();
}
} else if (fmt == G_IM_FMT_CI) {
if (siz == G_IM_SIZ_4b) {
@ -856,7 +864,7 @@ static void import_texture(int i, int tile) {
} else if (siz == G_IM_SIZ_8b) {
import_texture_ci8(tile);
} else {
abort();
// abort();
}
} else if (fmt == G_IM_FMT_I) {
if (siz == G_IM_SIZ_4b) {
@ -864,10 +872,10 @@ static void import_texture(int i, int tile) {
} else if (siz == G_IM_SIZ_8b) {
import_texture_i8(tile);
} else {
abort();
//abort();
}
} else {
abort();
// abort();
}
int t1 = get_time();
//printf("Time diff: %d\n", t1 - t0);
@ -1616,7 +1624,7 @@ static void gfx_dp_set_scissor(uint32_t mode, uint32_t ulx, uint32_t uly, uint32
rdp.viewport_or_scissor_changed = true;
}
static void gfx_dp_set_texture_image(uint32_t format, uint32_t size, uint32_t width, const void* addr, char* otr_path) {
void gfx_dp_set_texture_image(uint32_t format, uint32_t size, uint32_t width, const void* addr, char* otr_path) {
rdp.texture_to_load.addr = (const uint8_t*)addr;
rdp.texture_to_load.siz = size;
rdp.texture_to_load.width = width;
@ -1713,7 +1721,10 @@ static void gfx_dp_load_block(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_image_line_size_bytes = size_bytes;
//assert(size_bytes <= 4096 && "bug: too big texture");
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr = rdp.texture_to_load.addr;
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path = rdp.texture_to_load.otr_path;
if(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path)
free(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path);
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path = _strdup(rdp.texture_to_load.otr_path);
rdp.textures_changed[rdp.texture_tile[tile].tmem_index] = true;
}
@ -1746,7 +1757,9 @@ static void gfx_dp_load_tile(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t
assert(size_bytes <= 4096 && "bug: too big texture");
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr = rdp.texture_to_load.addr + start_offset;
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path = rdp.texture_to_load.otr_path;
if(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path)
free(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path);
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path = _strdup(rdp.texture_to_load.otr_path);
rdp.texture_tile[tile].uls = uls;
rdp.texture_tile[tile].ult = ult;
rdp.texture_tile[tile].lrs = lrs;
@ -2398,6 +2411,9 @@ static void gfx_run_dl(Gfx* cmd) {
char* imgData = (char*)i;
if (strstr(imgData, "spot04_room_0Tex_"))
volatile u32 bla = 0;
if ((i & 0xF0000000) != 0xF0000000)
if (ResourceMgr_OTRSigCheck(imgData) == 1)
i = (uintptr_t)ResourceMgr_LoadTexByName(imgData);

View file

@ -4,20 +4,15 @@
#include "SohImGuiImpl.h"
namespace Ship {
std::vector<ModModule*> modules;
void ModManager::Init() {
// ResManager->GetArchive()->loa
// modules.push_back(new TextureModule(this));
// std::shared_ptr<Ship::Archive> archive = std::make_shared<Ship::Archive>("mods/TexMods.otr", "", false);
for (auto& mod : modules) {
mod->Init();
// mod->Open(archive);
}
TextureMod = new TextureModule(this);
const std::shared_ptr<Archive> archive = std::make_shared<Archive>("mods/TexModDemo.otr", "", false);
static_cast<ModModule*>(TextureMod)->Init();
static_cast<ModModule*>(TextureMod)->Open(archive);
}
void ModManager::Exit() {
for (auto& mod : modules)
mod->Exit();
static_cast<ModModule*>(TextureMod)->Exit();
}
}

View file

@ -2,10 +2,13 @@
#include "ResourceMgr.h"
namespace Ship {
class TextureModule;
class ModManager {
public:
std::shared_ptr<Ship::ResourceMgr> ResManager;
explicit ModManager(std::shared_ptr<Ship::ResourceMgr> manager) : ResManager(manager) {}
std::shared_ptr<ResourceMgr> ResManager;
TextureModule* TextureMod;
explicit ModManager(std::shared_ptr<ResourceMgr> manager) : ResManager(manager) {}
void Init();
void Exit();
};

View file

@ -1,6 +1,6 @@
#include "TextureMod.h"
#include <map>
#include <unordered_map>
#include <string>
#include <iostream>
#include <filesystem>
@ -16,8 +16,8 @@ namespace fs = std::filesystem;
namespace Ship {
void TextureModule::Init() {
BIND_HOOK(LOOKUP_TEXTURE, Hook_LookupTexture);
BIND_HOOK(GRAYOUT_TEXTURE, Hook_GrayScaleFilter);
//BIND_HOOK(LOAD_TEXTURE, Hook_LoadTexture);
BIND_HOOK(INVALIDATE_TEXTURE, Hook_InvalidateTexture);
SohImGui::BindCmd("reload", { .handler = [&](const std::vector<std::string>&) {
@ -29,54 +29,48 @@ namespace Ship {
} });
}
void TextureModule::Open(std::shared_ptr<Ship::Archive> archive) {
void TextureModule::Open(std::shared_ptr<Archive> archive) {
this->LoadedOTRS.push_back(archive);
}
void TextureModule::Close(Ship::Archive otr) {
void TextureModule::Close(Archive otr) {
// Remove all loaded textures
// this->LoadedOTRS.erase(std::find(this->LoadedOTRS.begin(), this->LoadedOTRS.end(), otr));
}
void TextureModule::Hook_LookupTexture(HookEvent call) {
const auto raw_path = BIND_PTR("path", char*);
if (raw_path == nullptr) return;
bool TextureModule::LookupTexture(int tile, char* path, GfxRenderingAPI* api, TextureCacheNode** node, uint32_t fmt, uint32_t siz, uint32_t palette, const uint8_t* orig_addr) {
const auto api = BIND_PTR("gfx_api", GfxRenderingAPI*);
const auto path = normalize(raw_path) + ".png";
const auto node = BIND_PTR("node", TextureCacheNode**);
const auto fmt = BIND_VAR("fmt", uint32_t*);
const auto siz = BIND_VAR("siz", uint32_t*);
const auto tile = BIND_VAR("tile", int*);
const auto palette = BIND_VAR("palette", uint32_t*);
const auto orig_addr = BIND_VAR("addr", const uint8_t**);
// INFO("The game is trying to load %s", path.c_str());
if (path == nullptr || (path != nullptr && (strlen(path) > 128 || path[0] == '\0')))
return false;
if (this->TextureCache.contains(path) && this->TextureCache[path][tile] != nullptr) {
*node = this->TextureCache[path][tile];
api->select_texture(tile, (*node)->second.texture_id);
call->cancelled = true;
return;
return true;
}
// OTRTODO: Implement loading order
TextureData* tex_data = nullptr;
if (!this->TexturePool.contains(path)) {
std::shared_ptr<Ship::File> raw_data = std::make_shared<Ship::File>();
this->Manager->ResManager->GetArchive()->LoadPatchFile(path, false, raw_data);
for(auto &otr : LoadedOTRS) {
const auto fix_path = normalize(path) + ".png";
std::shared_ptr<File> raw_data = std::make_shared<File>();
if (!otr->HasFile(fix_path)) continue;
otr->LoadFile(fix_path, false, raw_data);
if (raw_data->bIsLoaded) {
char* tdata = new char[raw_data->dwBufferSize];
auto tdata = new char[raw_data->dwBufferSize];
memcpy(tdata, raw_data->buffer.get(), raw_data->dwBufferSize);
tex_data = new TextureData({ .data = tdata, .size = raw_data->dwBufferSize });
INFO("Loaded %s", path.c_str());
INFO("Loaded %s", path);
this->TexturePool[path] = tex_data;
}
}
}
if (tex_data == nullptr)
return;
return false;
if (!this->TextureCache.contains(path)) this->TextureCache[path].resize(10);
@ -90,7 +84,7 @@ namespace Ship {
uint8_t* img_data = stbi_load_from_memory(reinterpret_cast<const stbi_uc*>(tex_data->data), tex_data->size, &tex_data->width, &tex_data->height, nullptr, 4);
if (!img_data)
return;
return false;
switch (tex_data->color_modifier) {
case GRAYSCALE: {
@ -104,14 +98,63 @@ namespace Ship {
this->TextureCache[path][tile] = entry;
stbi_image_free(img_data);
call->cancelled = true;
return true;
}
void TextureModule::Hook_GrayScaleFilter(HookEvent event) {
// this->Exit();
}
void TextureModule::Hook_LoadTexture(HookEvent event) {
char* path = (char*)event->baseArgs["path"] + 7; // __OTR__
void** outPtr = (void**)event->baseArgs["texture"];
TextureData* tex_data = nullptr;
if (!this->TexturePool.contains(path)) {
for(auto &otr : LoadedOTRS) {
const auto fix_path = normalize(path) + ".png";
std::shared_ptr<File> raw_data = std::make_shared<File>();
if (!otr->HasFile(fix_path)) continue;
otr->LoadFile(fix_path, false, raw_data);
if (raw_data->bIsLoaded) {
auto tdata = new char[raw_data->dwBufferSize];
memcpy(tdata, raw_data->buffer.get(), raw_data->dwBufferSize);
tex_data = new TextureData({ .data = tdata, .size = raw_data->dwBufferSize });
INFO("Loaded %s", path);
}
}
}
if (tex_data == nullptr)
return;
uint8_t* img_data = stbi_load_from_memory(reinterpret_cast<const stbi_uc*>(tex_data->data), tex_data->size, &tex_data->width, &tex_data->height, nullptr, 4);
if (!img_data)
{
delete[] tex_data->data;
delete tex_data;
return;
}
switch (tex_data->color_modifier) {
case GRAYSCALE: {
GrayOutTexture(img_data, tex_data->width, tex_data->height);
}
default:;
}
*outPtr = malloc(tex_data->size);
memcpy(*outPtr, img_data, tex_data->size);
//*outPtr = img_data;
stbi_image_free(img_data);
delete[] tex_data->data;
delete tex_data;
}
void TextureModule::Hook_InvalidateTexture(HookEvent event) {
// this->Exit();
}

View file

@ -4,6 +4,7 @@
#include "Lib/Fast3D/gfx_pc.h"
namespace Ship {
enum TextureMod {
GRAYSCALE,
NONE
@ -15,23 +16,24 @@ namespace Ship {
int width;
int height;
char* loaded_data;
std::shared_ptr<Ship::Archive> parent;
std::shared_ptr<Archive> parent;
TextureMod color_modifier = NONE;
};
class TextureModule : public ModModule {
public:
explicit TextureModule(ModManager* Manager) : ModModule(Manager) {}
bool LookupTexture(int tile, char* path, GfxRenderingAPI* api, TextureCacheNode** node, uint32_t fmt, uint32_t siz, uint32_t palette, const uint8_t* addr);
private:
std::vector<std::shared_ptr<Ship::Archive>> LoadedOTRS;
std::map<std::string, TextureData*> TexturePool;
std::map<std::string, std::vector<TextureCacheNode*>> TextureCache;
std::vector<std::shared_ptr<Archive>> LoadedOTRS;
std::unordered_map<std::string, TextureData*> TexturePool;
std::unordered_map<std::string, std::vector<TextureCacheNode*>> TextureCache;
void Init() override;
void Open(std::shared_ptr<Ship::Archive> archive) override;
void Close(Ship::Archive mod) override;
void Open(std::shared_ptr<Archive> archive) override;
void Close(Archive mod) override;
void Exit() override;
protected:
void Hook_LookupTexture(HookEvent event);
void Hook_LoadTexture(HookEvent event);
void Hook_GrayScaleFilter(HookEvent event);
void Hook_InvalidateTexture(HookEvent event);
};

View file

@ -197,13 +197,17 @@ extern "C" {
}
char* ResourceMgr_LoadTexByName(char* texPath) {
const auto res = static_cast<Ship::Texture*>(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(texPath).get());
void* imageData = nullptr;
ModInternal::bindHook(LOAD_TEXTURE);
ModInternal::initBindHook(2,
HookParameter({ .name = "path", .parameter = (void*)texPath }),
HookParameter({ .name = "texture", .parameter = static_cast<void*>(&res->imageData) })
HookParameter({ .name = "texture", .parameter = &imageData })
);
ModInternal::callBindHook(0);
if(imageData)
return (char*)imageData;
const auto res = static_cast<Ship::Texture*>(Ship::GlobalCtx2::GetInstance()->GetResourceManager()->LoadResource(texPath).get());
return (char*)res->imageData;
}

View file

@ -2,6 +2,7 @@
#include "../libultraship/SohImGuiImpl.h"
#include <vector>
#include <string>
#include <map>
#define Path _Path
#define PATH_HACK

View file

@ -188,7 +188,7 @@ extern "C" void ResourceMgr_CacheDirectory(const char* resName) {
OTRGlobals::Instance->context->GetResourceManager()->CacheDirectory(resName);
}
extern "C" void ResourceMgr_DirtyDirectory(const char* resName) {
OTRGlobals::Instance->context->GetResourceManager()->DirtyDirectory(resName);
//OTRGlobals::Instance->context->GetResourceManager()->DirtyDirectory(resName);
}
extern "C" void ResourceMgr_InvalidateCache() {

View file

@ -728,9 +728,10 @@ void func_8002CDE4(GlobalContext* globalCtx, TitleCardContext* titleCtx) {
void TitleCard_InitBossName(GlobalContext* globalCtx, TitleCardContext* titleCtx, void* texture, s16 x, s16 y, u8 width,
u8 height) {
if (ResourceMgr_OTRSigCheck(texture))
texture = ResourceMgr_LoadTexByName(texture);
//if (ResourceMgr_OTRSigCheck(texture))
// texture = ResourceMgr_LoadTexByName(texture);
// Only works for english
titleCtx->texture = texture;
titleCtx->x = x;
titleCtx->y = y;
@ -946,7 +947,7 @@ void TitleCard_InitPlaceName(GlobalContext* globalCtx, TitleCardContext* titleCt
texture = newName;
}
titleCtx->texture = ResourceMgr_LoadTexByName(texture);
titleCtx->texture = texture;
//titleCtx->texture = texture;
titleCtx->x = x;

View file

@ -56,8 +56,7 @@ void func_801109B0(GlobalContext* globalCtx) {
doActionOffset = 0x5700;
}
memcpy(interfaceCtx->doActionSegment, ResourceMgr_LoadTexByName(gAttackDoActionENGTex), 0x180);
memcpy(interfaceCtx->doActionSegment + 0x180, ResourceMgr_LoadTexByName(gCheckDoActionENGTex), 0x180);
memcpy(interfaceCtx->doActionSegment, gAttackDoActionENGTex, sizeof(gAttackDoActionENGTex) /* including 0 byte */);
//DmaMgr_SendRequest1(interfaceCtx->doActionSegment, (uintptr_t)_do_action_staticSegmentRomStart + doActionOffset, 0x300,
//"../z_construct.c", 174);
@ -69,7 +68,7 @@ void func_801109B0(GlobalContext* globalCtx) {
doActionOffset = 0x5B80;
}
memcpy(interfaceCtx->doActionSegment + 0x300, ResourceMgr_LoadTexByName(gReturnDoActionENGTex), 0x180);
memcpy(interfaceCtx->doActionSegment + 0x300, gReturnDoActionENGTex, sizeof(gReturnDoActionENGTex) /* including 0 byte */);
//DmaMgr_SendRequest1(interfaceCtx->doActionSegment + 0x300, (uintptr_t)_do_action_staticSegmentRomStart + doActionOffset,
//0x180, "../z_construct.c", 178);

View file

@ -174,7 +174,7 @@ void Font_LoadChar(Font* font, u8 character, u16 codePointIndex) {
//"../z_kanfont.c", 93);
if (character < 0x8B)
memcpy(&font->charTexBuf[codePointIndex], ResourceMgr_LoadTexByName(fntTbl[character]), FONT_CHAR_TEX_SIZE);
memcpy(&font->charTexBuf[codePointIndex], fntTbl[character], strlen(fntTbl[character]) + 1);
}
/**
@ -183,7 +183,7 @@ void Font_LoadChar(Font* font, u8 character, u16 codePointIndex) {
* The different icons are given in the MessageBoxIcon enum.
*/
void Font_LoadMessageBoxIcon(Font* font, u16 icon) {
memcpy(font->iconBuf, msgStaticTbl[4 + icon], FONT_CHAR_TEX_SIZE);
memcpy(font->iconBuf, msgStaticTbl[4 + icon], strlen(msgStaticTbl[4 + icon]) + 1);
}
/**
@ -218,7 +218,7 @@ void Font_LoadOrderedFont(Font* font) {
osSyncPrintf("nes_mes_buf[%d]=%d\n", codePointIndex, font->msgBuf[codePointIndex]);
offset = (font->msgBuf[codePointIndex] - '\x20') * FONT_CHAR_TEX_SIZE;
memcpy(fontBuf, ResourceMgr_LoadTexByName(fntTbl[offset / FONT_CHAR_TEX_SIZE]), FONT_CHAR_TEX_SIZE);
memcpy(fontBuf, fntTbl[offset / FONT_CHAR_TEX_SIZE], strlen(fntTbl[offset / FONT_CHAR_TEX_SIZE]) + 1);
//DmaMgr_SendRequest1(fontBuf, fontStatic + offset, FONT_CHAR_TEX_SIZE, "../z_kanfont.c", 134);
fontBufIndex += FONT_CHAR_TEX_SIZE / 8;
}

View file

@ -408,7 +408,7 @@ void Map_InitData(GlobalContext* globalCtx, s16 room) {
//gMapData->owMinimapTexSize[mapIndex], "../z_map_exp.c", 309);
if (sEntranceIconMapIndex < 24)
memcpy(globalCtx->interfaceCtx.mapSegment, ResourceMgr_LoadTexByName(minimapTableOW[sEntranceIconMapIndex]), gMapData->owMinimapTexSize[mapIndex]);
memcpy(globalCtx->interfaceCtx.mapSegment, minimapTableOW[sEntranceIconMapIndex], strlen(minimapTableOW[sEntranceIconMapIndex]) + 1);
interfaceCtx->unk_258 = mapIndex;
break;
@ -440,7 +440,7 @@ void Map_InitData(GlobalContext* globalCtx, s16 room) {
//((gMapData->dgnMinimapTexIndexOffset[mapIndex] + room) * 0xFF0),
//0xFF0, "../z_map_exp.c", 346);
memcpy(globalCtx->interfaceCtx.mapSegment, ResourceMgr_LoadTexByName(minimapTableDangeon[gMapData->dgnMinimapTexIndexOffset[mapIndex] + room]), 0xFF0);
memcpy(globalCtx->interfaceCtx.mapSegment, minimapTableDangeon[gMapData->dgnMinimapTexIndexOffset[mapIndex] + room], strlen(minimapTableDangeon[gMapData->dgnMinimapTexIndexOffset[mapIndex] + room]) + 1);
R_COMPASS_OFFSET_X = gMapData->roomCompassOffsetX[mapIndex][room];
R_COMPASS_OFFSET_Y = gMapData->roomCompassOffsetY[mapIndex][room];

View file

@ -1531,10 +1531,8 @@ void Message_Decode(GlobalContext* globalCtx) {
msgCtx->textboxBackgroundYOffsetIdx = (font->msgBuf[msgCtx->msgBufPos + 3] & 0xF0) >> 4;
msgCtx->textboxBackgroundUnkArg = font->msgBuf[msgCtx->msgBufPos + 3] & 0xF;
memcpy((uintptr_t)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE,
ResourceMgr_LoadTexByName(gRedMessageXLeftTex), 0x900);
memcpy((uintptr_t)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE + 0x900,
ResourceMgr_LoadTexByName(gRedMessageXRightTex), 0x900);
memcpy((uintptr_t)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE, gRedMessageXLeftTex, strlen(gRedMessageXLeftTex) + 1);
memcpy((uintptr_t)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE + 0x900, gRedMessageXRightTex, strlen(gRedMessageXRightTex) + 1);
msgCtx->msgBufPos += 3;
R_TEXTBOX_BG_YPOS = R_TEXTBOX_Y + 8;
@ -1668,7 +1666,7 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) {
// "Text Box Type"
osSyncPrintf("吹き出し種類=%d\n", msgCtx->textBoxType);
if (textBoxType < TEXTBOX_TYPE_NONE_BOTTOM) {
memcpy(msgCtx->textboxSegment, ResourceMgr_LoadTexByName(msgStaticTbl[messageStaticIndices[textBoxType]]), MESSAGE_STATIC_TEX_SIZE);
memcpy(msgCtx->textboxSegment, msgStaticTbl[messageStaticIndices[textBoxType]], strlen(msgStaticTbl[messageStaticIndices[textBoxType]]) + 1);
if (textBoxType == TEXTBOX_TYPE_BLACK) {
msgCtx->textboxColorRed = 0;
msgCtx->textboxColorGreen = 0;

View file

@ -2117,8 +2117,7 @@ void Interface_LoadActionLabel(InterfaceContext* interfaceCtx, u16 action, s16 l
if (action != DO_ACTION_NONE) {
//osCreateMesgQueue(&interfaceCtx->loadQueue, &interfaceCtx->loadMsg, OS_MESG_BLOCK);
memcpy(interfaceCtx->doActionSegment + (loadOffset * DO_ACTION_TEX_SIZE), ResourceMgr_LoadTexByName(doAction),
DO_ACTION_TEX_SIZE);
memcpy(interfaceCtx->doActionSegment + (loadOffset * DO_ACTION_TEX_SIZE), doAction, strlen(doAction) + 1);
//DmaMgr_SendRequest2(&interfaceCtx->dmaRequest_160,
//interfaceCtx->doActionSegment + (loadOffset * DO_ACTION_TEX_SIZE),
//(uintptr_t)_do_action_staticSegmentRomStart + (action * DO_ACTION_TEX_SIZE), DO_ACTION_TEX_SIZE,
@ -2203,7 +2202,7 @@ void Interface_LoadActionLabelB(GlobalContext* globalCtx, u16 action) {
// OTRTODO
osCreateMesgQueue(&interfaceCtx->loadQueue, &interfaceCtx->loadMsg, OS_MESG_BLOCK);
memcpy(interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE, ResourceMgr_LoadTexByName(doAction), DO_ACTION_TEX_SIZE);
memcpy(interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE, doAction, strlen(doAction) + 1);
//DmaMgr_SendRequest2(&interfaceCtx->dmaRequest_160, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE,
//(uintptr_t)_do_action_staticSegmentRomStart + (action * DO_ACTION_TEX_SIZE), DO_ACTION_TEX_SIZE, 0,
//&interfaceCtx->loadQueue, NULL, "../z_parameter.c", 2228);

View file

@ -539,7 +539,7 @@ void EnMag_DrawImageRGBA32(Gfx** gfxp, s16 centerX, s16 centerY, u8* source, u32
s32 pad;
s32 i;
source = ResourceMgr_LoadTexByName(source);
//source = ResourceMgr_LoadTexByName(source);
func_80094D28(&gfx);
@ -549,41 +549,21 @@ void EnMag_DrawImageRGBA32(Gfx** gfxp, s16 centerX, s16 centerY, u8* source, u32
textureHeight = 4096 / (width << 2);
remainingSize = (width * height) << 2;
textureSize = (width * textureHeight) << 2;
textureCount = remainingSize / textureSize;
textureCount = 1; //remainingSize / textureSize;
if ((remainingSize % textureSize) != 0) {
textureCount += 1;
}
gDPSetTileCustom(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_32b, width, textureHeight, 0, G_TX_NOMIRROR | G_TX_CLAMP,
gDPSetTileCustom(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_32b, width, height, 0, G_TX_NOMIRROR | G_TX_CLAMP,
G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
remainingSize -= textureSize;
for (i = 0; i < textureCount; i++) {
gDPSetTextureImage(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_32b, width, curTexture);
gDPLoadSync(gfx++);
gDPLoadTile(gfx++, G_TX_LOADTILE, 0, 0, (width - 1) << 2, (textureHeight - 1) << 2);
gDPLoadTile(gfx++, G_TX_LOADTILE, 0, 0, (width - 1) << 2, (height - 1) << 2);
gSPTextureRectangle(gfx++, rectLeft << 2, rectTop << 2, (rectLeft + (s32)width) << 2,
(rectTop + textureHeight) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10);
curTexture += textureSize;
rectTop += textureHeight;
if ((remainingSize - textureSize) < 0) {
if (remainingSize > 0) {
textureHeight = remainingSize / (s32)(width << 2);
remainingSize -= textureSize;
gDPSetTileCustom(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_32b, width, textureHeight, 0,
G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK,
G_TX_NOLOD, G_TX_NOLOD);
}
} else {
remainingSize -= textureSize;
}
}
(rectTop + height) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10);
*gfxp = gfx;
}

View file

@ -1878,7 +1878,7 @@ void KaleidoScope_UpdateNamePanel(GlobalContext* globalCtx) {
sp2A += 12;
}
memcpy(pauseCtx->nameSegment, ResourceMgr_LoadTexByName(mapNameTextures[sp2A]), 0x400);
memcpy(pauseCtx->nameSegment, mapNameTextures[sp2A], strlen(mapNameTextures[sp2A]) + 1);
} else {
osSyncPrintf("zoom_name=%d\n", pauseCtx->namedItem);
@ -1891,7 +1891,7 @@ void KaleidoScope_UpdateNamePanel(GlobalContext* globalCtx) {
osSyncPrintf("J_N=%d point=%d\n", gSaveContext.language, sp2A);
memcpy(pauseCtx->nameSegment, ResourceMgr_LoadTexByName(iconNameTextures[sp2A]), 0x400);
memcpy(pauseCtx->nameSegment, iconNameTextures[sp2A], strlen(iconNameTextures[sp2A]) + 1);
}
pauseCtx->nameDisplayTimer = 0;
@ -2985,7 +2985,10 @@ void KaleidoScope_UpdateCursorSize(PauseContext* pauseCtx) {
void KaleidoScope_LoadDungeonMap(GlobalContext* globalCtx) {
InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx;
/*
memcpy(interfaceCtx->mapSegment, sDungeonMapTexs[R_MAP_TEX_INDEX], strlen(sDungeonMapTexs[R_MAP_TEX_INDEX]) + 1);
memcpy(interfaceCtx->mapSegment + 0x800, sDungeonMapTexs[R_MAP_TEX_INDEX + 1], strlen(sDungeonMapTexs[R_MAP_TEX_INDEX + 1]) + 1);
*/
memcpy(interfaceCtx->mapSegment, ResourceMgr_LoadTexByName(sDungeonMapTexs[R_MAP_TEX_INDEX]), 0x800);
memcpy(interfaceCtx->mapSegment + 0x800, ResourceMgr_LoadTexByName(sDungeonMapTexs[R_MAP_TEX_INDEX + 1]), 0x800);
}
@ -3167,7 +3170,7 @@ void KaleidoScope_Update(GlobalContext* globalCtx)
if (((void)0, gSaveContext.worldMapArea) < 22) {
if (gSaveContext.language == LANGUAGE_ENG) {
memcpy(pauseCtx->nameSegment + 0x400, ResourceMgr_LoadTexByName(mapNameTextures[36 + gSaveContext.worldMapArea]), 0xA00);
memcpy(pauseCtx->nameSegment + 0x400, mapNameTextures[36 + gSaveContext.worldMapArea], strlen(mapNameTextures[36 + gSaveContext.worldMapArea]) + 1);
} else if (gSaveContext.language == LANGUAGE_GER) {
memcpy(pauseCtx->nameSegment + 0x400, ResourceMgr_LoadTexByName(mapNameTextures[59 + gSaveContext.worldMapArea]), 0xA00);
} else {