fvb Matching (#2820)

* fvb Matching

* J2DScreen debug work
This commit is contained in:
hatal175 2025-11-19 04:13:35 +02:00 committed by GitHub
parent 158899a16d
commit 8a39ebfa8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 157 additions and 162 deletions

View File

@ -45,6 +45,7 @@
".ninja_*": true,
"objdiff.json": true,
".cache/**": true,
"compile_commands.json": true,
},
"clangd.arguments": [
"--function-arg-placeholders=0",

View File

@ -891,7 +891,7 @@ config.libs = [
Object(MatchingFor("GZ2E01", "GZ2P01", "GZ2J01"), "JSystem/JStudio/JStudio/ctb.cpp"),
Object(MatchingFor("GZ2E01", "GZ2P01", "GZ2J01", "Shield", "ShieldD"), "JSystem/JStudio/JStudio/ctb-data.cpp"),
Object(Equivalent, "JSystem/JStudio/JStudio/functionvalue.cpp"), # weak func order
Object(NonMatching, "JSystem/JStudio/JStudio/fvb.cpp"),
Object(MatchingFor("GZ2E01", "GZ2P01", "GZ2J01"), "JSystem/JStudio/JStudio/fvb.cpp"),
Object(MatchingFor("GZ2E01", "GZ2P01", "GZ2J01", "Shield"), "JSystem/JStudio/JStudio/fvb-data.cpp"),
Object(MatchingFor("GZ2E01", "GZ2P01", "GZ2J01", "Shield"), "JSystem/JStudio/JStudio/fvb-data-parse.cpp"),
Object(MatchingFor("GZ2E01", "GZ2P01", "GZ2J01"), "JSystem/JStudio/JStudio/jstudio-control.cpp"),

View File

@ -211,7 +211,10 @@ public:
/* 0xD8 */ f32 mTranslateY;
/* 0xDC */ JSUTree<J2DPane> mPaneTree;
/* 0xF8 */ const J2DAnmTransform* mTransform;
#if !(PLATFORM_WII || PLATFORM_SHIELD)
/* 0xFC */ u32 _fc;
#endif
};
#endif /* J2DPANE_H */

View File

@ -14,7 +14,7 @@ struct TEBit {
const void* parseVariableUInt_16_32_following(const void* pu16, u32* pu32First, u32* pu32Second,
TEBit* tebit);
inline u32 align_roundUp(u32 arg0, u32 uAlign) {
inline u32 align_roundUp(unsigned int arg0, unsigned int uAlign) {
return (arg0 + uAlign - 1) & ~(uAlign - 1);
}

View File

@ -34,16 +34,12 @@ private:
};
#ifdef DEBUG
// these macros are probably wrong, needs work
#define JGADGET_ASSERTWARN(line, COND) \
if (!(COND)) { \
JGadget_outMessage out(JGadget_outMessage::warning, __FILE__, line); \
out << #COND; \
}
((COND)) || (JGadget_outMessage(JGadget_outMessage::warning, __FILE__, line) << #COND, false);
#define JGADGET_WARNMSG(line, msg) \
JGadget_outMessage out(JGadget_outMessage::warning, __FILE__, line); \
out << msg;
JGadget_outMessage(JGadget_outMessage::warning, __FILE__, line) << msg, false;
#define JGADGET_WARNMSG1(line, msg, arg) \
JGadget_outMessage out(JGadget_outMessage::warning, __FILE__, line); \

View File

@ -170,7 +170,7 @@ struct TVector_pointer_void : public TVector<void*, TAllocator<void*> > {
void** erase(void**, void**);
void clear() { erase(begin(), end()); }
void push_back(const void*& value) { insert(end(), (void* const&)value); }
void push_back(void* const& value) { insert(end(), (void* const&)value); }
};
template <typename T>
@ -185,7 +185,7 @@ struct TVector_pointer : TVector_pointer_void {
T* end() { return (T*)TVector_pointer_void::end(); }
void push_back(const T& ref) {
static_cast<TVector_pointer_void*>(this)->push_back((const void*&)ref);
static_cast<TVector_pointer_void*>(this)->push_back((void* const&)ref);
}
};

View File

@ -389,16 +389,20 @@ template <typename T>
struct TVec2 {
TVec2() {}
TVec2(T v) { set(v); }
TVec2(T x, T y) { set(x, y); }
template <typename U>
TVec2(U x, U y) { set(x, y); }
void set(T v) { y = x = v; }
void set(T x, T y) {
template <typename U>
void set(U x, U y) {
this->x = x;
this->y = y;
}
void set(const TVec2& other) {
template <typename U>
void set(const TVec2<U>& other) {
x = other.x;
y = other.y;
}
@ -481,9 +485,12 @@ template<> struct TBox<TVec2<f32> > {
};
template <typename T>
struct TBox2 : TBox<TVec2<T> > {
struct TBox2 : public TBox<TVec2<T> > {
TBox2() {}
TBox2(const TVec2<f32>& i, const TVec2<f32>& f) { set(i, f); }
TBox2(const TVec2<f32>& _i, const TVec2<f32>& _f) {
i.set(_i);
f.set(_f);
}
TBox2(f32 x0, f32 y0, f32 x1, f32 y1) { set(x0, y0, x1, y1); }
void absolute() {

View File

@ -15,8 +15,7 @@ public:
u32 get_size() const { return get()->size; }
const void* getNext() const {
u32 size = get_size();
return (const void*)((u8*)getRaw() + size);
return (const void*)((u8*)getRaw() + get_size());
}
u16 get_type() const { return get()->type; }
u16 get_IDSize() const { return get()->id_size; }
@ -28,8 +27,7 @@ public:
return ret;
}
const void* getContent() const {
u32 size = align_roundUp(get_IDSize(), 4);
return (const void*)((int)getBlockEnd_() + size);
return (const void*)((int)getBlockEnd_() + align_roundUp(get_IDSize(), 4));
}
};

View File

@ -26,9 +26,11 @@ typedef enum TEComposite {
/* 0x8 */ COMPOSITE_ENUM_SIZE,
};
typedef TFunctionValue_composite::TData (*CompositeDataFunc)(const void*);
struct CompositeOperation {
TFunctionValue_composite::CompositeFunc composite;
TFunctionValue_composite::TData (*getCompositeData)(const void*);
CompositeDataFunc getCompositeData;
};
struct TBlock {

View File

@ -39,9 +39,9 @@ public:
void prepare(const data::TParse_TBlock& block, TControl* control);
TFunctionValue* const& referFunctionValue() { return pfv_; }
TFunctionValue* const referFunctionValue() { return pfv_; }
private:
protected:
/* 0x0C */ JGadget::TLinkListNode mNode;
/* 0x14 */ TFunctionValue* pfv_;
};

View File

@ -22,6 +22,7 @@ protected:
struct TObject_ID : public TIDData {
TObject_ID(const void* id, u32 id_size) : TIDData(id, id_size) {}
~TObject_ID() {}
TIDData const& getIDData() const { return *this; }
const u8 *getID() const { return TIDData::getID(); }
};

View File

@ -18,7 +18,7 @@
/* 802F8498-802F8540 2F2DD8 00A8+00 0/0 59/59 4/4 .text __ct__9J2DScreenFv */
J2DScreen::J2DScreen()
: J2DPane(NULL, true, 'root', JGeometry::TBox2<f32>(JGeometry::TVec2<f32>(0.0f, 0.0f), JGeometry::TVec2<f32>(640.0f, 480.0f))), mColor() {
: J2DPane(NULL, true, 'root', JGeometry::TBox2<f32>(JGeometry::TVec2<f32>(0, 0), JGeometry::TVec2<f32>(640, 480))), mColor() {
field_0x4 = -1;
mScissor = false;
mMaterialNum = 0;
@ -59,10 +59,9 @@ bool J2DScreen::setPriority(char const* resName, u32 param_1, JKRArchive* p_arch
return false;
}
void* res = JKRFileLoader::getGlbResource(resName, p_archive);
void* res = JKRGetNameResource(resName, p_archive);
if (res != NULL) {
u32 size = p_archive->getExpandedResSize(res);
JSUMemoryInputStream stream(res, size);
JSUMemoryInputStream stream(res, p_archive->getExpandedResSize(res));
return setPriority(&stream, param_1, p_archive);
}
@ -96,11 +95,7 @@ bool J2DScreen::private_set(JSURandomInputStream* p_stream, u32 param_1, JKRArch
clean();
}
if (make_end) {
return p_stream->isGood();
}
return false;
return make_end ? p_stream->isGood() : false;
}
/* 802F8834-802F8894 2F3174 0060+00 1/1 0/0 0/0 .text
@ -110,6 +105,7 @@ bool J2DScreen::checkSignature(JSURandomInputStream* p_stream) {
p_stream->read(&header, sizeof(J2DScrnHeader));
if (header.mTag != 'SCRN' || (header.mType != 'blo1' && header.mType != 'blo2')) {
JUT_WARN(257, "%s", "SCRN resource is broken.\n")
return false;
} else {
return true;
@ -123,14 +119,13 @@ bool J2DScreen::getScreenInformation(JSURandomInputStream* p_stream) {
p_stream->read(&info, sizeof(J2DScrnInfoHeader));
if (info.mTag != 'INF1') {
JUT_WARN(282, "%s", "SCRN resource is broken.\n")
return false;
}
JGeometry::TBox2<f32> dimensions(0.0f, 0.0f, info.mWidth, info.mHeight);
place(dimensions);
place(JGeometry::TBox2<f32>(0.0f, 0.0f, info.mWidth, info.mHeight));
JUtility::TColor color(info.mColor);
mColor = color;
mColor = info.mColor;
if (info.mSize > 0x10) {
p_stream->skip(info.mSize - 0x10);
@ -156,7 +151,7 @@ s32 J2DScreen::makeHierarchyPanes(J2DPane* p_basePane, JSURandomInputStream* p_s
case 'BGN1':
p_stream->seek(header.mSize, JSUStreamSeekFrom_CUR);
int ret = makeHierarchyPanes(next_pane, p_stream, param_2, p_archive);
s32 ret = makeHierarchyPanes(next_pane, p_stream, param_2, p_archive);
if (ret != 0) {
return ret;
}
@ -165,18 +160,12 @@ s32 J2DScreen::makeHierarchyPanes(J2DPane* p_basePane, JSURandomInputStream* p_s
p_stream->seek(header.mSize, JSUStreamSeekFrom_CUR);
return 0;
case 'TEX1':
J2DResReference* texRes = getResReference(p_stream, param_2);
mTexRes = texRes;
if (texRes == NULL) {
if ((mTexRes = getResReference(p_stream, param_2)) == NULL) {
return 2;
}
break;
case 'FNT1':
J2DResReference* fntRes = getResReference(p_stream, param_2);
mFontRes = fntRes;
if (fntRes == NULL) {
if ((mFontRes = getResReference(p_stream, param_2)) == NULL) {
return 2;
}
break;
@ -389,9 +378,10 @@ bool J2DScreen::createMaterial(JSURandomInputStream* p_stream, u32 param_1, JKRA
u8* buffer = new (-4) u8[header.mSize];
if (mMaterials != NULL && buffer != NULL) {
J2DMaterialBlock* pBlock = (J2DMaterialBlock*)buffer;
p_stream->seek(position, JSUStreamSeekFrom_SET);
p_stream->read(buffer, header.mSize);
J2DMaterialFactory factory(*(J2DMaterialBlock*)buffer);
J2DMaterialFactory factory(*pBlock);
for (u16 i = 0; i < mMaterialNum; i++) {
factory.create(&mMaterials[i], i, param_1, mTexRes, mFontRes, p_archive);
@ -400,19 +390,20 @@ bool J2DScreen::createMaterial(JSURandomInputStream* p_stream, u32 param_1, JKRA
if (param_1 & 0x1F0000) {
u32 offset =
buffer[0x14] << 0x18 | buffer[0x15] << 0x10 | buffer[0x16] << 8 | buffer[0x17];
char* sec = (char*)buffer + offset;
u16* sec_s = ((u16*)sec);
u32 size = ((u16*)sec)[0]*2;
u16 num = sec_s[size + 1];
while (sec[num] != 0) {
num++;
ResNTAB* sec_s = (ResNTAB*)((u8*)buffer + offset);
u16 entryNum = sec_s->mEntryNum;
u16 lastOffset = sec_s->mEntries[entryNum - 1].mOffs;
char* ptr = (char*)sec_s;
u16 size = lastOffset;
while (ptr[size] != 0) {
size++;
}
num++;
size++;
u8* nametab = new u8[num];
u8* nametab = new u8[size];
if (nametab != NULL) {
for (u16 i = 0; i < num; i++) {
nametab[i] = sec[i];
for (u16 i = 0; i < size; i++) {
nametab[i] = ((u8*)sec_s)[i];
}
mNameTable = new JUTNameTab((ResNTAB*)nametab);

View File

@ -12,16 +12,16 @@
namespace JStudio {
namespace fvb {
TObject::~TObject() {}
TObject::~TObject() {
JGADGET_ASSERTWARN(26, pfv_!=NULL);
}
// NONMATCHING regalloc, missing mr, addition order
void TObject::prepare(data::TParse_TBlock const& rBlock, TControl* pControl) {
ASSERT(pfv_ != 0);
ASSERT(pControl != 0);
JUT_ASSERT(35, pfv_!=0);
JUT_ASSERT(36, pControl!=0);
TFunctionValueAttributeSet set = pfv_->getAttributeSet();
const void* pNext = rBlock.getNext();
const void* pData = rBlock.getContent();
const void* pNext = (const void*)rBlock.getNext();
const void* pData = (const void*)rBlock.getContent();
while (pData < pNext) {
data::TParse_TParagraph para(pData);
data::TParse_TParagraph::TData dat;
@ -36,133 +36,129 @@ void TObject::prepare(data::TParse_TBlock const& rBlock, TControl* pControl) {
prepare_data_(dat, pControl);
break;
case 0x10: {
JUT_EXPECT(u32Size >= 4);
ASSERT(pContent != 0);
JGADGET_ASSERTWARN(61, u32Size>=4);
JUT_ASSERT(62, pContent!=0);
TFunctionValueAttribute_refer* pfvaRefer = set.refer_get();
JUT_EXPECT(pfvaRefer != NULL);
JGADGET_ASSERTWARN(64, pfvaRefer!=NULL);
if (pfvaRefer == NULL) {
JUTWarn w;
w << "invalid paragraph";
} else {
JGadget::TVector_pointer<TFunctionValue*>& rCnt = pfvaRefer->refer_referContainer();
u32* content = (u32*)pContent;
u32 i = content[0];
u32* ptr = content + 1;
for (; i != 0; ptr++, i--) {
u32 size = *ptr;
TObject* pObject = pControl->getObject(ptr + 1, size);
if (pObject == NULL) {
JUTWarn w;
w << "object not found by ID";
} else {
TFunctionValue* rfv = pObject->referFunctionValue();
rCnt.push_back(rfv);
}
ptr += align_roundUp(size, 4) >> 2;
JGADGET_WARNMSG(67, "invalid paragraph");
break;
}
JGadget::TVector_pointer<TFunctionValue*>& rCnt = pfvaRefer->refer_referContainer();
u8* content = (u8*)pContent;
u32 i = *(u32*)content;
u8* ptr = content + 4;
for (; i != 0; i--) {
u32 size = *(u32*)ptr;
TObject* pObject = pControl->getObject(ptr + 4, size);
if (pObject != NULL) {
TFunctionValue* const rfv = pObject->referFunctionValue();
TFunctionValue* const* pRfv = &rfv;
rCnt.push_back(*pRfv);
} else {
JGADGET_WARNMSG(85, "object not found by ID");
}
ptr += align_roundUp(size, 4) + 4;
}
} break;
case 0x11: {
JUT_EXPECT(u32Size >= 4);
ASSERT(pContent != 0);
JGADGET_ASSERTWARN(93, u32Size>=4);
JUT_ASSERT(94, pContent!=0);
TFunctionValueAttribute_refer* pfvaRefer = set.refer_get();
JUT_EXPECT(pfvaRefer != NULL);
JGADGET_ASSERTWARN(96, pfvaRefer!=NULL);
if (pfvaRefer == NULL) {
JUTWarn w;
w << "invalid paragraph";
} else {
JGadget::TVector_pointer<TFunctionValue*>& rCnt = pfvaRefer->refer_referContainer();
u32* content = (u32*)pContent;
u32* ptr = content;
u32 i = content[0];
for (; ptr++, i != 0; i--) {
u32 index = *ptr;
TObject* pObject = pControl->getObject_index(index);
if (pObject == NULL) {
JUTWarn w;
w << "object not found by index : " << index;
} else {
TFunctionValue& rfv = *pObject->referFunctionValue();
rCnt.push_back(&rfv);
}
JGADGET_WARNMSG(99, "invalid paragraph");
break;
}
JGadget::TVector_pointer<TFunctionValue*>& rCnt = pfvaRefer->refer_referContainer();
u8* ptr = (u8*)pContent;
u32 i = *(u32*)ptr;
for (; ptr += 4, i != 0; i--) {
u32 index = *(u32*)ptr;
TObject* pObject = pControl->getObject_index(index);
if (pObject != NULL) {
TFunctionValue* const rfv = pObject->referFunctionValue();
TFunctionValue* const* pRfv = &rfv;
rCnt.push_back(*pRfv);
} else {
JGADGET_WARNMSG(114, "object not found by index : " << index);
}
}
} break;
case 0x12: {
JUT_EXPECT(u32Size == 8);
ASSERT(pContent != 0);
JGADGET_ASSERTWARN(121, u32Size==8);
JUT_ASSERT(122, pContent!=0);
TFunctionValueAttribute_range* pfvaRange = set.range_get();
JUT_EXPECT(pfvaRange != NULL);
JGADGET_ASSERTWARN(124, pfvaRange!=NULL);
if (pfvaRange == NULL) {
JUTWarn w;
w << "invalid paragraph";
} else {
f32* arr = (f32*)pContent;
pfvaRange->range_set(arr[0], arr[1]);
JGADGET_WARNMSG(127, "invalid paragraph");
break;
}
f32* arr = (f32*)pContent;
pfvaRange->range_set(arr[0], arr[1]);
} break;
case 0x13: {
JUT_EXPECT(u32Size == 4);
ASSERT(pContent != 0);
JGADGET_ASSERTWARN(138, u32Size==4);
JUT_ASSERT(139, pContent!=0);
TFunctionValueAttribute_range* pfvaRange = set.range_get();
JUT_EXPECT(pfvaRange != NULL);
JGADGET_ASSERTWARN(141, pfvaRange!=NULL);
if (pfvaRange == NULL) {
JUTWarn w;
w << "invalid paragraph";
} else {
TFunctionValue::TEProgress prog = *(TFunctionValue::TEProgress*)pContent;
pfvaRange->range_setProgress(prog);
JGADGET_WARNMSG(144, "invalid paragraph");
break;
}
TFunctionValue::TEProgress prog = *(TFunctionValue::TEProgress*)pContent;
pfvaRange->range_setProgress(prog);
} break;
case 0x14: {
JUT_EXPECT(u32Size == 4);
ASSERT(pContent != 0);
JGADGET_ASSERTWARN(156, u32Size==4);
JUT_ASSERT(157, pContent!=0);
TFunctionValueAttribute_range* pfvaRange = set.range_get();
JUT_EXPECT(pfvaRange != NULL);
JGADGET_ASSERTWARN(159, pfvaRange!=NULL);
if (pfvaRange == NULL) {
JUTWarn w;
w << "invalid paragraph";
} else {
TFunctionValue::TEAdjust adjust = *(TFunctionValue::TEAdjust*)pContent;
pfvaRange->range_setAdjust(adjust);
JGADGET_WARNMSG(162, "invalid paragraph");
break;
}
TFunctionValue::TEAdjust adjust = *(TFunctionValue::TEAdjust*)pContent;
pfvaRange->range_setAdjust(adjust);
} break;
case 0x15: {
JUT_EXPECT(u32Size == 4);
ASSERT(pContent != 0);
JGADGET_ASSERTWARN(174, u32Size==4);
JUT_ASSERT(175, pContent!=0);
TFunctionValueAttribute_range* pfvaRange = set.range_get();
JUT_EXPECT(pfvaRange != NULL);
JGADGET_ASSERTWARN(177, pfvaRange!=NULL);
if (pfvaRange == NULL) {
JUTWarn w;
w << "invalid paragraph";
} else {
u16* out = (u16*)pContent;
pfvaRange->range_setOutside((TFunctionValue::TEOutside)out[0],
(TFunctionValue::TEOutside)out[1]);
JGADGET_WARNMSG(180, "invalid paragraph");
break;
}
u16* out = (u16*)pContent;
pfvaRange->range_setOutside((TFunctionValue::TEOutside)out[0],
(TFunctionValue::TEOutside)out[1]);
} break;
case 0x16: {
JUT_EXPECT(u32Size == 4);
ASSERT(pContent != 0);
JGADGET_ASSERTWARN(193, u32Size==4);
JUT_ASSERT(194, pContent!=0);
TFunctionValueAttribute_interpolate* pfvaInterpolate = set.interpolate_get();
JUT_EXPECT(pfvaInterpolate != NULL);
JGADGET_ASSERTWARN(197, pfvaInterpolate!=NULL);
if (pfvaInterpolate == NULL) {
JUTWarn w;
w << "invalid paragraph";
} else {
TFunctionValue::TEInterpolate interp = *(TFunctionValue::TEInterpolate*)pContent;
pfvaInterpolate->interpolate_set(interp);
JGADGET_WARNMSG(200, "invalid paragraph");
break;
}
TFunctionValue::TEInterpolate interp = *(TFunctionValue::TEInterpolate*)pContent;
pfvaInterpolate->interpolate_set(interp);
} break;
default:
JUTWarn w;
w << "unknown paragraph : " << u32Type;
JGADGET_WARNMSG(211, "unknown paragraph : " << u32Type);
}
pData = dat.next;
ASSERT(pData != 0);
JUT_ASSERT(214, pData!=0);
}
end:
JUT_EXPECT(pData == pNext);
JGADGET_ASSERTWARN(216, pData==pNext);
pfv_->prepare();
}
@ -221,21 +217,22 @@ TObject_composite::TObject_composite(const data::TParse_TBlock& block) : TObject
void TObject_composite::prepare_data_(const data::TParse_TParagraph::TData& rData,
TControl* control) {
ASSERT(rData.u32Type == data::PARAGRAPH_DATA);
JUT_ASSERT(306, rData.u32Type==data::PARAGRAPH_DATA);
u32 u32Size = rData.u32Size;
JUT_EXPECT(u32Size == 8);
struct unknown {
data::TEComposite composite_type;
u32 data;
};
const unknown* pContent = static_cast<const unknown*>(rData.pContent);
ASSERT(pContent != NULL);
JGADGET_ASSERTWARN(310, u32Size== 8);
JUT_ASSERT(311, pContent!=NULL);
const data::CompositeOperation* op = getCompositeOperation_(pContent->composite_type);
fnValue.data_set(op->composite, op->getCompositeData(&pContent->data));
data::TEComposite type = pContent->composite_type;
const data::CompositeOperation* op = getCompositeOperation_(type);
data::CompositeDataFunc pfn = op->getCompositeData;
JUT_ASSERT(316, pfn!=NULL);
fnValue.data_set(op->composite, pfn(&pContent->data));
}
/* 80284338-802843B8 27EC78 0080+00 1/1 0/0 0/0 .text
@ -245,15 +242,14 @@ TObject_constant::TObject_constant(data::TParse_TBlock const& param_0)
void TObject_constant::prepare_data_(const data::TParse_TParagraph::TData& rData,
TControl* control) {
ASSERT(rData.u32Type == data::PARAGRAPH_DATA);
JUT_ASSERT(337, rData.u32Type==data::PARAGRAPH_DATA);
u32 u32Size = rData.u32Size;
JUT_EXPECT(u32Size == 4);
const f32* pContent = static_cast<const f32*>(rData.pContent);
ASSERT(pContent != NULL);
fnValue.data_set(pContent[0]);
JGADGET_ASSERTWARN(341, u32Size==4);
JUT_ASSERT(342, pContent!=NULL);
f32 val = pContent[0];
fnValue.data_set(val);
}
/* 802843C8-80284448 27ED08 0080+00 1/1 0/0 0/0 .text