Skip to content

Commit b07165f

Browse files
committed
fix mdb
lower case vertex parameter name
1 parent 3dca455 commit b07165f

File tree

9 files changed

+71
-162
lines changed

9 files changed

+71
-162
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@
4747
/ModelScale/Debug/*
4848
/Dxbc2Asm/Release/*
4949
/Dxbc2Asm/Debug/*
50+
/x64/*

EDF_Tools/EDF_Tools.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
</PropertyGroup>
7777
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
7878
<LinkIncremental>true</LinkIncremental>
79+
<IntDir>$(Configuration)\</IntDir>
80+
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
7981
</PropertyGroup>
8082
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
8183
<LinkIncremental>false</LinkIncremental>

EDF_Tools/MDB.cpp

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ int CMDBtoXML::Read(const std::wstring& path, bool onecore)
5151

5252
// Check version
5353
GameVersion = ReadInt32(&buffer[0x4], 0);
54+
if (GameVersion == 0x20) {
55+
xmlHeader->SetAttribute("version", "6");
56+
}
5457
// Name
5558
NameTableCount = ReadInt32(&buffer[0x8], 0);
5659
NameTableOffset = ReadInt32(&buffer[0xC], 0);
@@ -820,24 +823,20 @@ MDBObjectLayout CMDBtoXML::ReadObjectLayout(int pos, const std::vector<char>& bu
820823
{
821824
MDBObjectLayout out;
822825

823-
unsigned char seg[4];
824-
825-
int position = pos;
826-
Read4Bytes(seg, buffer, position);
827-
out.type = GetIntFromChunk(seg);
828-
829-
position = pos + 0x4;
830-
Read4Bytes(seg, buffer, position);
831-
out.offset = GetIntFromChunk(seg);
832-
833-
position = pos + 0x8;
834-
Read4Bytes(seg, buffer, position);
835-
out.channel = GetIntFromChunk(seg);
836-
837-
position = pos + 0x0C;
838-
Read4Bytes(seg, buffer, position);
839-
int offset = GetIntFromChunk(seg);
840-
out.name = ReadASCII(buffer, pos + offset);
826+
out.type = ReadInt32(&buffer[pos], 0);
827+
out.offset = ReadInt32(&buffer[pos + 0x4], 0);
828+
out.channel = ReadInt32(&buffer[pos + 0x8], 0);
829+
830+
int offset = ReadInt32(&buffer[pos + 0x0C], 0);
831+
std::string name = ReadASCII(buffer, pos + offset);
832+
// In case of EDF6, Convert parameter names to lowercase
833+
if (GameVersion == 0x20) {
834+
// Ignore the skin parameters
835+
if ( CompareStringIsSame(name, "BLENDWEIGHT", 12) && CompareStringIsSame(name, "BLENDINDICES", 13) ) {
836+
name = ConvertToLower(name);
837+
}
838+
}
839+
out.name = name;
841840

842841
return out;
843842
}
@@ -846,25 +845,17 @@ MDBTexture CMDBtoXML::ReadTexture(int pos, const std::vector<char>& buffer)
846845
{
847846
MDBTexture out;
848847

849-
unsigned char seg[4];
850848
int offset = 0;
851849

852-
int position = pos;
853-
Read4Bytes(seg, buffer, position);
854-
out.ID = GetIntFromChunk(seg);
850+
out.ID = ReadInt32(&buffer[pos], 0);
855851

856-
position = pos + 0x4;
857-
Read4Bytes(seg, buffer, position);
858-
offset = GetIntFromChunk(seg);
852+
offset = ReadInt32(&buffer[pos + 0x4], 0);
859853
out.mapping = ReadUnicode(buffer, pos + offset);
860854

861-
position = pos + 0x8;
862-
Read4Bytes(seg, buffer, position);
863-
offset = GetIntFromChunk(seg);
855+
offset = ReadInt32(&buffer[pos + 0x8], 0);
864856
out.filename = ReadUnicode(buffer, pos + offset);
865-
866-
position = pos + 0xC;
867-
out.raw = ReadRaw(buffer, position, 4);
857+
858+
out.raw = ReadRaw(buffer, (pos + 0xC), 4);
868859

869860
return out;
870861
}

EDF_Tools/util.cpp

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,15 @@ std::string ReadASCII(const std::vector<char>& chunk, int pos)
228228
unsigned int bufPos = pos;
229229

230230
std::vector< unsigned char > bytes;
231-
232-
int zeroCount = 0;
233-
234231
//Repeat until EOF, or otherwise broken
235232
while (bufPos < chunk.size())
236233
{
237234
bytes.push_back(chunk[bufPos]);
238235

239-
if (chunk[bufPos] == 0x00)
236+
if (chunk[bufPos] == 0)
240237
{
241-
zeroCount++;
242-
if (zeroCount == 1)
243-
break;
238+
break;
244239
}
245-
else
246-
zeroCount = 0;
247240
bufPos++;
248241
}
249242

@@ -405,8 +398,43 @@ float IntHexAsFloat(int in)
405398
return out;
406399
}
407400

401+
// 0 is same, Compares whether two strings are the same.
402+
int CompareStringIsSame(const std::string& str1, const char* str2, int length)
403+
{
404+
int nonSame = 1;
405+
if (str1.size() == length) {
406+
for (int i = 0; i < length; i++) {
407+
if (str1[i] != str2[i]) {
408+
nonSame += i;
409+
break;
410+
}
411+
}
412+
nonSame = 0;
413+
}
414+
return nonSame;
415+
}
416+
408417
//Converts a string to lower case
409-
std::wstring ConvertToLower( std::wstring in )
418+
std::string ConvertToLower(const std::string& in)
419+
{
420+
std::string out;
421+
for (int i = 0; i < in.size(); i++)
422+
{
423+
out += tolower(in[i]);
424+
// to upper: in[i] & 0b11011111;
425+
/*
426+
if (!in[i]) {
427+
out += in[i];
428+
}
429+
else {
430+
out += (in[i] | 0b00100000);
431+
}*/
432+
}
433+
return out;
434+
}
435+
436+
//Converts a wide string to lower case
437+
std::wstring ConvertToLower(const std::wstring& in )
410438
{
411439
std::wstring out;
412440
for( int i = 0; i < in.size( ); ++i )
@@ -417,7 +445,7 @@ std::wstring ConvertToLower( std::wstring in )
417445
}
418446

419447
//Function to determine "type" of string argument
420-
ValueType DetermineType( std::wstring input )
448+
ValueType DetermineType(const std::wstring& input )
421449
{
422450
std::wstring lower = ConvertToLower( input );
423451
if( lower == L"true" || lower == L"false" )

EDF_Tools/util.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ bool IsValidFloat( const std::wstring& input );
5050
//Converts a int hex to float
5151
float IntHexAsFloat(int in);
5252

53+
// 0 is same, Compares whether two strings are the same.
54+
// Why do I need this method to work!
55+
int CompareStringIsSame(const std::string& str1, const char* str2, int length);
5356
//Converts a string to lower case
54-
std::wstring ConvertToLower( std::wstring in );
57+
std::string ConvertToLower(const std::string& in);
58+
//Converts a wide string to lower case
59+
std::wstring ConvertToLower(const std::wstring& in );
5560

5661
//Value type enum.
5762
enum ValueType
@@ -64,7 +69,7 @@ enum ValueType
6469
T_INVALID
6570
};
6671
//Function to determine "type" of string argument
67-
ValueType DetermineType( std::wstring input );
72+
ValueType DetermineType(const std::wstring& input );
6873

6974
//Helper fn to read a file
7075
std::wstring ReadFile( const wchar_t* filename );

EDF_Tools/x64/Debug/EDF Tools.exe.recipe

Lines changed: 0 additions & 11 deletions
This file was deleted.

EDF_Tools/x64/Debug/EDF Tools.ilk

-11.7 MB
Binary file not shown.

EDF_Tools/x64/Debug/EDF_Tools.log

Lines changed: 0 additions & 107 deletions
This file was deleted.

EDF_Tools/x64/Debug/vc143.idb

-747 KB
Binary file not shown.

0 commit comments

Comments
 (0)