MinecraftConsoles/Minecraft.Client/Common/DLC/DLCSkinFile.cpp
Langtanium 760484e546 Squashed commit of the following:
commit b40530fa5e12bdd0e2d03686b111964f9c5b3359
Author: Langtanium <94726057+Langtanium@users.noreply.github.com>
Date:   Wed Apr 15 19:59:46 2026 -0700

    Implemented skin offsets in UI

    Added code to render skin offsets in the skin select UI.

commit a8384d984089b989a162550705dee7a505412e22
Author: Langtanium <94726057+Langtanium@users.noreply.github.com>
Date:   Wed Apr 15 19:38:08 2026 -0700

    Partially implemented offsets

    Added code that visually shifts the player's model parts, but only in game not in the skin select UI.

commit 875100cf9afe7df258dc653a4b33857d3cd285c1
Author: Langtanium <94726057+Langtanium@users.noreply.github.com>
Date:   Wed Apr 15 16:48:03 2026 -0700

    Minor change

    Simplified redundant conditions in HumanoidModel.cpp

commit 96f683d1fb93d09a49987460ef698e0d125c2c93
Merge: db685a74 24c74aa2
Author: Langtanium <94726057+Langtanium@users.noreply.github.com>
Date:   Tue Apr 14 16:37:30 2026 -0700

    Merge branch 'feat/64x64-skins' into feat/skin-offsets

commit db685a74f34d02cc83e33ab97c5a7ad9a62ef023
Author: Langtanium <94726057+Langtanium@users.noreply.github.com>
Date:   Tue Apr 14 15:35:38 2026 -0700

    Fixed skin offset data

    Fixed skin offsets so they now return the actual data instead of the defaults, added a few minor tweaks, and added code in PlayerRenderer.cpp to access offsets (Can read the offsets but can not apply them).

commit aa769d54adb8f5bf96c75d10766422d23cc9129a
Author: Langtanium <94726057+Langtanium@users.noreply.github.com>
Date:   Sat Apr 11 19:36:52 2026 -0700

    Fixed crashes

    Fixed code for offsets preventing crashes. The amount of offsets is correctly obtain, but lacks the actual data.

commit f18ac12cc072db74ed9b8da937e00c2e15f889a0
Merge: 8e76763a fd2fd659
Author: Langtanium <94726057+Langtanium@users.noreply.github.com>
Date:   Fri Apr 10 16:06:57 2026 -0700

    Merge branch 'feat/64x64-skins' into feat/skin-offsets

commit 8e76763a3ddeaff943243fd0469d6c4a7b12b6c1
Author: Langtanium <94726057+Langtanium@users.noreply.github.com>
Date:   Tue Apr 7 16:50:43 2026 -0700

    Made more changes

    Made more changes in files to support skin offsets. The game still crashes when trying to load skins.

commit 1a8f3532979033717044e74e6ceb766e23e35032
Merge: a1d9ae59 bb5fa506
Author: Langtanium <94726057+Langtanium@users.noreply.github.com>
Date:   Tue Apr 7 13:12:39 2026 -0700

    Merge branch 'feat/64x64-skins' into feat/skin-offsets

commit a1d9ae591ac27117626aac708a4204a9e2451684
Author: Langtanium <94726057+Langtanium@users.noreply.github.com>
Date:   Fri Apr 3 21:50:42 2026 -0700

    Added small additions

    Added more code referencing skin offsets. Still doesn't work correctly.

commit d28a751d9ca0527854e40be82e7841a650c2f189
Merge: 3888de7a 8bf03435
Author: Langtanium <94726057+Langtanium@users.noreply.github.com>
Date:   Thu Apr 2 17:09:08 2026 -0700

    Merge branch 'smartcmd:main' into feat/skin-offsets

commit 3888de7ab401d9562b7b922eca8b898aa73ba024
Author: Langtanium <94726057+Langtanium@users.noreply.github.com>
Date:   Thu Apr 2 17:07:48 2026 -0700

    Added code for skin offsets

    Added code to the file which have the functionality to get skin boxes and duplicated the functionality for skin offsets. The code causes the game to crash when switching to third person. The error occurs with the skin offsets returning as an empty class object.
2026-04-15 20:00:28 -07:00

428 lines
10 KiB
C++

#include "stdafx.h"
#include "DLCManager.h"
#include "DLCSkinFile.h"
#include "..\..\ModelPart.h"
#include "..\..\EntityRenderer.h"
#include "..\..\EntityRenderDispatcher.h"
#include "..\..\..\Minecraft.World\Player.h"
#include "..\..\..\Minecraft.World\StringHelpers.h"
DLCSkinFile::DLCSkinFile(const wstring &path) : DLCFile(DLCManager::e_DLCType_Skin,path)
{
m_displayName = L"";
m_themeName = L"";
m_cape = L"";
m_bIsFree = false;
m_uiAnimOverrideBitmask=0L;
}
void DLCSkinFile::addData(PBYTE pbData, DWORD dwBytes)
{
app.AddMemoryTextureFile(m_path,pbData,dwBytes);
}
void DLCSkinFile::addParameter(DLCManager::EDLCParameterType type, const wstring &value)
{
switch(type)
{
case DLCManager::e_DLCParamType_DisplayName:
{
// 4J Stu - In skin pack 2, the name for Zap is mis-spelt with two p's as Zapp
// dlcskin00000109.png
if( m_path.compare(L"dlcskin00000109.png") == 0)
{
m_displayName = L"Zap";
}
else
{
m_displayName = value;
}
}
break;
case DLCManager::e_DLCParamType_ThemeName:
m_themeName = value;
break;
case DLCManager::e_DLCParamType_Free: // If this parameter exists, then mark this as free
m_bIsFree = true;
break;
case DLCManager::e_DLCParamType_Credit: // If this parameter exists, then mark this as free
//add it to the DLC credits list
// we'll need to justify this text since we don't have a lot of room for lines of credits
{
if(app.AlreadySeenCreditText(value)) break;
// first add a blank string for spacing
app.AddCreditText(L"");
int maximumChars = 55;
bool bIsSDMode=!RenderManager.IsHiDef() && !RenderManager.IsWidescreen();
if(bIsSDMode)
{
maximumChars = 45;
}
switch(XGetLanguage())
{
case XC_LANGUAGE_JAPANESE:
case XC_LANGUAGE_TCHINESE:
case XC_LANGUAGE_KOREAN:
maximumChars = 35;
break;
}
wstring creditValue = value;
while (creditValue.length() > maximumChars)
{
unsigned int i = 1;
while (i < creditValue.length() && (i + 1) <= maximumChars)
{
i++;
}
size_t iLast=creditValue.find_last_of(L" ", i);
switch(XGetLanguage())
{
case XC_LANGUAGE_JAPANESE:
case XC_LANGUAGE_TCHINESE:
case XC_LANGUAGE_KOREAN:
iLast = maximumChars;
break;
default:
iLast=creditValue.find_last_of(L" ", i);
break;
}
// if a space was found, include the space on this line
if(iLast!=i)
{
iLast++;
}
app.AddCreditText((creditValue.substr(0, iLast)).c_str());
creditValue = creditValue.substr(iLast);
}
app.AddCreditText(creditValue.c_str());
}
break;
case DLCManager::e_DLCParamType_Cape:
m_cape = value;
break;
case DLCManager::e_DLCParamType_Box:
{
WCHAR wchBodyPart[10];
SKIN_BOX *pSkinBox = new SKIN_BOX;
ZeroMemory(pSkinBox,sizeof(SKIN_BOX));
#ifdef __PS3__
// 4J Stu - The Xbox version used swscanf_s which isn't available in GCC.
swscanf(value.c_str(), L"%10ls%f%f%f%f%f%f%f%f%f%f%f", wchBodyPart,
#else
swscanf_s(value.c_str(), L"%9ls%f%f%f%f%f%f%f%f%f%f%f", wchBodyPart,10,
#endif
&pSkinBox->fX,
&pSkinBox->fY,
&pSkinBox->fZ,
&pSkinBox->fW,
&pSkinBox->fH,
&pSkinBox->fD,
&pSkinBox->fU,
&pSkinBox->fV,
&pSkinBox->fA,
&pSkinBox->fM,
&pSkinBox->fS);
if(wcscmp(wchBodyPart,L"HEAD")==0)
{
pSkinBox->ePart=eBodyPart_Head;
}
else if(wcscmp(wchBodyPart,L"BODY")==0)
{
pSkinBox->ePart=eBodyPart_Body;
}
else if(wcscmp(wchBodyPart,L"ARM0")==0)
{
pSkinBox->ePart=eBodyPart_Arm0;
}
else if(wcscmp(wchBodyPart,L"ARM1")==0)
{
pSkinBox->ePart=eBodyPart_Arm1;
}
else if(wcscmp(wchBodyPart,L"LEG0")==0)
{
pSkinBox->ePart=eBodyPart_Leg0;
}
else if(wcscmp(wchBodyPart,L"LEG1")==0)
{
pSkinBox->ePart=eBodyPart_Leg1;
}
else if(wcscmp(wchBodyPart,L"HEADWEAR")==0)
{
pSkinBox->ePart=eBodyPart_Headwear;
}
else if(wcscmp(wchBodyPart,L"JACKET")==0)
{
pSkinBox->ePart=eBodyPart_Jacket;
}
else if(wcscmp(wchBodyPart,L"SLEEVE0")==0)
{
pSkinBox->ePart=eBodyPart_Sleeve0;
}
else if(wcscmp(wchBodyPart,L"SLEEVE1")==0)
{
pSkinBox->ePart=eBodyPart_Sleeve1;
}
else if(wcscmp(wchBodyPart,L"PANTS0")==0)
{
pSkinBox->ePart=eBodyPart_Pants0;
}
else if(wcscmp(wchBodyPart,L"PANTS1")==0)
{
pSkinBox->ePart=eBodyPart_Pants1;
}
else if(wcscmp(wchBodyPart,L"WAIST")==0)
{
pSkinBox->ePart=eBodyPart_Waist;
}
else if(wcscmp(wchBodyPart,L"LEGGING0")==0)
{
pSkinBox->ePart=eBodyPart_Legging0;
}
else if(wcscmp(wchBodyPart,L"LEGGING1")==0)
{
pSkinBox->ePart=eBodyPart_Legging1;
}
else if(wcscmp(wchBodyPart,L"SOCK0")==0)
{
pSkinBox->ePart=eBodyPart_Sock0;
}
else if(wcscmp(wchBodyPart,L"SOCK1")==0)
{
pSkinBox->ePart=eBodyPart_Sock1;
}
else if(wcscmp(wchBodyPart,L"BOOT0")==0)
{
pSkinBox->ePart=eBodyPart_Boot0;
}
else if(wcscmp(wchBodyPart,L"BOOT1")==0)
{
pSkinBox->ePart=eBodyPart_Boot1;
}
else if(wcscmp(wchBodyPart,L"ARMARMOR0")==0)
{
pSkinBox->ePart=eBodyPart_ArmArmor0;
}
else if(wcscmp(wchBodyPart,L"ARMARMOR1")==0)
{
pSkinBox->ePart=eBodyPart_ArmArmor1;
}
else if(wcscmp(wchBodyPart,L"BODYARMOR")==0)
{
pSkinBox->ePart=eBodyPart_BodyArmor;
}
else if(wcscmp(wchBodyPart,L"BELT")==0)
{
pSkinBox->ePart=eBodyPart_Belt;
}
// add this to the skin's vector of parts
m_AdditionalBoxes.push_back(pSkinBox);
}
break;
case DLCManager::e_DLCParamType_Offset:
{
WCHAR wchBodyPart[10];
wchar_t wchDirection[2];
SKIN_OFFSET *pSkinOffset = new SKIN_OFFSET;
ZeroMemory(pSkinOffset,sizeof(SKIN_OFFSET));
#ifdef __PS3__
// 4J Stu - The Xbox version used swscanf_s which isn't available in GCC.
swscanf(value.c_str(), L"%10ls%2ls%f", wchBodyPart,
#else
swscanf_s(value.c_str(), L"%9ls%2ls%f", wchBodyPart,10, wchDirection,2,
#endif
&pSkinOffset->fO);
if(wcscmp(wchDirection,L"X")==0)
{
pSkinOffset->fD=eOffsetDirection_X;
}
else if (wcscmp(wchDirection,L"Y")==0)
{
pSkinOffset->fD=eOffsetDirection_Y;
}
else if(wcscmp(wchDirection,L"Z")==0)
{
pSkinOffset->fD=eOffsetDirection_Z;
}
if(wcscmp(wchBodyPart,L"HEAD")==0)
{
pSkinOffset->ePart=eBodyOffset_Head;
}
else if(wcscmp(wchBodyPart,L"BODY")==0)
{
pSkinOffset->ePart=eBodyOffset_Body;
}
else if(wcscmp(wchBodyPart,L"ARM0")==0)
{
pSkinOffset->ePart=eBodyOffset_Arm0;
}
else if(wcscmp(wchBodyPart,L"ARM1")==0)
{
pSkinOffset->ePart=eBodyOffset_Arm1;
}
else if(wcscmp(wchBodyPart,L"LEG0")==0)
{
pSkinOffset->ePart=eBodyOffset_Leg0;
}
else if(wcscmp(wchBodyPart,L"LEG1")==0)
{
pSkinOffset->ePart=eBodyOffset_Leg1;
}
else if(wcscmp(wchBodyPart,L"HEADWEAR")==0)
{
pSkinOffset->ePart=eBodyOffset_Headwear;
}
else if(wcscmp(wchBodyPart,L"JACKET")==0)
{
pSkinOffset->ePart=eBodyOffset_Jacket;
}
else if(wcscmp(wchBodyPart,L"SLEEVE0")==0)
{
pSkinOffset->ePart=eBodyOffset_Sleeve0;
}
else if(wcscmp(wchBodyPart,L"SLEEVE1")==0)
{
pSkinOffset->ePart=eBodyOffset_Sleeve1;
}
else if(wcscmp(wchBodyPart,L"PANTS0")==0)
{
pSkinOffset->ePart=eBodyOffset_Pants0;
}
else if(wcscmp(wchBodyPart,L"PANTS1")==0)
{
pSkinOffset->ePart=eBodyOffset_Pants1;
}
else if(wcscmp(wchBodyPart,L"WAIST")==0)
{
pSkinOffset->ePart=eBodyOffset_Waist;
}
else if(wcscmp(wchBodyPart,L"LEGGING0")==0)
{
pSkinOffset->ePart=eBodyOffset_Legging0;
}
else if(wcscmp(wchBodyPart,L"LEGGING1")==0)
{
pSkinOffset->ePart=eBodyOffset_Legging1;
}
else if(wcscmp(wchBodyPart,L"SOCK0")==0)
{
pSkinOffset->ePart=eBodyOffset_Sock0;
}
else if(wcscmp(wchBodyPart,L"SOCK1")==0)
{
pSkinOffset->ePart=eBodyOffset_Sock1;
}
else if(wcscmp(wchBodyPart,L"BOOT0")==0)
{
pSkinOffset->ePart=eBodyOffset_Boot0;
}
else if(wcscmp(wchBodyPart,L"BOOT1")==0)
{
pSkinOffset->ePart=eBodyOffset_Boot1;
}
else if(wcscmp(wchBodyPart,L"ARMARMOR1")==0)
{
pSkinOffset->ePart=eBodyOffset_ArmArmor1;
}
else if(wcscmp(wchBodyPart,L"ARMARMOR0")==0)
{
pSkinOffset->ePart=eBodyOffset_ArmArmor0;
}
else if(wcscmp(wchBodyPart,L"BODYARMOR")==0)
{
pSkinOffset->ePart=eBodyOffset_BodyArmor;
}
else if(wcscmp(wchBodyPart,L"BELT")==0)
{
pSkinOffset->ePart=eBodyOffset_Belt;
}
else if(wcscmp(wchBodyPart,L"TOOL0")==0)
{
pSkinOffset->ePart=eBodyOffset_Tool0;
}
else if(wcscmp(wchBodyPart,L"TOOL1")==0)
{
pSkinOffset->ePart=eBodyOffset_Tool1;
}
// add this to the skin's vector of offsets
m_Offsets.push_back(pSkinOffset);
}
break;
case DLCManager::e_DLCParamType_Anim:
#ifdef __PS3__
// 4J Stu - The Xbox version used swscanf_s which isn't available in GCC.
swscanf(value.c_str(), L"%X", &m_uiAnimOverrideBitmask);
#else
swscanf_s(value.c_str(), L"%X", &m_uiAnimOverrideBitmask,sizeof(unsigned int));
#endif
DWORD skinId = app.getSkinIdFromPath(m_path);
app.SetAnimOverrideBitmask(skinId, m_uiAnimOverrideBitmask);
break;
}
}
// vector<ModelPart *> *DLCSkinFile::getAdditionalModelParts()
// {
// return &m_AdditionalModelParts;
// }
int DLCSkinFile::getAdditionalBoxesCount()
{
return static_cast<int>(m_AdditionalBoxes.size());
}
vector<SKIN_BOX *> *DLCSkinFile::getAdditionalBoxes()
{
return &m_AdditionalBoxes;
}
int DLCSkinFile::getOffsetsCount()
{
return static_cast<int>(m_Offsets.size());
}
vector<SKIN_OFFSET *> *DLCSkinFile::getOffsets()
{
return &m_Offsets;
}
wstring DLCSkinFile::getParameterAsString(DLCManager::EDLCParameterType type)
{
switch(type)
{
case DLCManager::e_DLCParamType_DisplayName:
return m_displayName;
case DLCManager::e_DLCParamType_ThemeName:
return m_themeName;
case DLCManager::e_DLCParamType_Cape:
return m_cape;
default:
return L"";
}
}
bool DLCSkinFile::getParameterAsBool(DLCManager::EDLCParameterType type)
{
switch(type)
{
case DLCManager::e_DLCParamType_Free:
// Patch all DLC to be "paid"
return false;
// return m_bIsFree;
default:
return false;
}
}