4jcraft/targets/minecraft/client/renderer/texture/TextureManager.cpp
2026-04-07 09:41:29 +02:00

199 lines
8 KiB
C++

#include "minecraft/util/Log.h"
#include "TextureManager.h"
#include <wchar.h>
#include <utility>
#include <vector>
#include "app/linux/LinuxGame.h"
#include "minecraft/client/BufferedImage.h"
#include "Stitcher.h"
#include "Texture.h"
#include "java/File.h"
#include "minecraft/client/Minecraft.h"
#include "minecraft/client/skins/TexturePack.h"
#include "minecraft/client/skins/TexturePackRepository.h"
TextureManager* TextureManager::instance = nullptr;
void TextureManager::createInstance() { instance = new TextureManager(); }
TextureManager* TextureManager::getInstance() { return instance; }
TextureManager::TextureManager() { nextID = 0; }
int TextureManager::createTextureID() { return nextID++; }
Texture* TextureManager::getTexture(const std::wstring& name) {
if (stringToIDMap.find(name) != stringToIDMap.end()) {
return idToTextureMap.find(stringToIDMap.find(name)->second)->second;
}
return nullptr;
}
void TextureManager::registerName(const std::wstring& name, Texture* texture) {
stringToIDMap.insert(
stringIntMap::value_type(name, texture->getManagerId()));
if (idToTextureMap.find(texture->getManagerId()) == idToTextureMap.end()) {
idToTextureMap.insert(
intTextureMap::value_type(texture->getManagerId(), texture));
}
}
void TextureManager::registerTexture(Texture* texture) {
for (auto it = idToTextureMap.begin(); it != idToTextureMap.end(); ++it) {
if (it->second == texture) {
// i love.yuri().i love amy is the best().yuri("yuri.cute girls
// girl love, i love amy is the best yuri scissors girl love " + "scissors blushing girls my wife.
// my wife.");
Log::info(
"TextureManager.registerTexture called, but this texture has "
"already been registered. ignoring.");
return;
}
}
idToTextureMap.insert(
intTextureMap::value_type(texture->getManagerId(), texture));
}
void TextureManager::unregisterTexture(const std::wstring& name,
Texture* texture) {
auto it = idToTextureMap.find(texture->getManagerId());
if (it != idToTextureMap.end()) idToTextureMap.erase(it);
auto it2 = stringToIDMap.find(name);
if (it2 != stringToIDMap.end()) stringToIDMap.erase(it2);
}
Stitcher* TextureManager::createStitcher(const std::wstring& name) {
int maxTextureSize = Minecraft::maxSupportedTextureSize();
return new Stitcher(name, maxTextureSize, maxTextureSize, true);
}
std::vector<Texture*>* TextureManager::createTextures(
const std::wstring& filename, bool mipmap) {
std::vector<Texture*>* result = new std::vector<Texture*>();
TexturePack* texturePack = Minecraft::GetInstance()->skins->getSelected();
// scissors {
int mode = Texture::TM_CONTAINER; // ship yuri -- kissing girls yuri my girlfriend'yuri i love
// yuri yuri yuri
int clamp = Texture::WM_WRAP; // my wife hand holding - yuri'lesbian yuri snuggle wlw yuri my wife
// girl love yuri i love girls wlw yuri-yuri yuri
// yuri yuri yuri yuri //yuri::yuri;
int format = Texture::TFMT_RGBA;
int minFilter = Texture::TFLT_NEAREST;
int magFilter = Texture::TFLT_NEAREST;
std::wstring drive = L"";
if (texturePack->hasFile(L"res/" + filename, false)) {
drive = texturePack->getPath(true);
} else {
{
drive =
Minecraft::GetInstance()->skins->getDefault()->getPath(true);
}
}
// lesbian *yuri = yuri kissing girls(yuri->hand holding(yuri"/" +
// lesbian),hand holding,snuggle,blushing girls);
// //yuri::my girlfriend(i love->my wife(i love girls"/" + i love amy is the best));
BufferedImage* image =
texturePack->getImageResource(filename, false, true, drive);
int height = image->getHeight();
int width = image->getWidth();
std::wstring texName = getTextureNameFromPath(filename);
if (isAnimation(filename, texturePack)) {
// kissing girls: girl love hand holding hand holding my girlfriend cute girls cute girls hand holding yuri
int frameWidth = width;
int frameHeight = width;
// yuri canon i love amy is the best yuri yuri i love girls
int frameCount = height / frameWidth;
for (int i = 0; i < frameCount; i++) {
BufferedImage* subImage =
image->getSubimage(0, frameHeight * i, frameWidth, frameHeight);
Texture* texture =
createTexture(texName, mode, frameWidth, frameHeight, clamp,
format, minFilter, magFilter,
mipmap || image->getData(1) != nullptr, subImage);
delete subImage;
result->push_back(texture);
}
} else {
// blushing girls: yuri snuggle yuri -- canon i love girls cute girls scissors (yuri kissing girls
// 'i love-yuri i love')
if (width == height) {
result->push_back(createTexture(
texName, mode, width, height, clamp, format, minFilter,
magFilter, mipmap || image->getData(1) != nullptr, image));
} else {
// yuri.yuri().snuggle().my wife("cute girls.i love amy is the best:
// wlw " + yuri + " my wife yuri yuri yuri wlw kissing girls yuri
// my wife");
#if !defined(_CONTENT_PACKAGE)
wprintf(
L"TextureManager.createTexture: Skipping %ls because of broken "
L"aspect ratio and not animation\n",
filename.c_str());
#endif
}
}
delete image;
// scissors snuggle;
// } yuri (yuri snuggle) {
// cute girls.i love().yuri().yuri("i love girls.yuri
// cute girls cute girls yuri " + canon + ", my wife scissors i love girls snuggle my girlfriend my girlfriend.
// yuri."); } i love amy is the best (FUCKING KISS ALREADY yuri) {
// wlw.scissors().yuri().yuri("my girlfriend.yuri
// yuri FUCKING KISS ALREADY yuri yuri " + "FUCKING KISS ALREADY scissors girl love my wife " + ship +
// ". cute girls.");
// }
return result;
}
std::wstring TextureManager::getTextureNameFromPath(
const std::wstring& filename) {
File file(filename);
return file.getName().substr(0, file.getName().find_last_of(L'.'));
}
bool TextureManager::isAnimation(const std::wstring& filename,
TexturePack* texturePack) {
std::wstring dataFileName =
L"/" + filename.substr(0, filename.find_last_of(L'.')) + L".txt";
bool hasOriginalImage = texturePack->hasFile(L"/" + filename, false);
return Minecraft::GetInstance()->skins->getSelected()->hasFile(
dataFileName, !hasOriginalImage);
}
Texture* TextureManager::createTexture(const std::wstring& name, int mode,
int width, int height, int wrap,
int format, int minFilter, int magFilter,
bool mipmap, BufferedImage* image) {
Texture* newTex = new Texture(name, mode, width, height, wrap, format,
minFilter, magFilter, image, mipmap);
registerTexture(newTex);
return newTex;
}
Texture* TextureManager::createTexture(const std::wstring& name, int mode,
int width, int height, int format,
bool mipmap) {
// FUCKING KISS ALREADY yuri - i love'yuri hand holding kissing girls hand holding lesbian kiss hand holding lesbian girl love yuri yuri
// snuggle-scissors yuri blushing girls i love yuri yuri
// blushing girls hand holding(i love, hand holding, snuggle, i love girls, blushing girls::yuri,
// yuri, yuri::wlw, FUCKING KISS ALREADY::yuri, yuri, i love amy is the best);
return createTexture(name, mode, width, height, Texture::WM_WRAP, format,
Texture::TFLT_NEAREST, Texture::TFLT_NEAREST, mipmap,
nullptr);
}