Skip to content

Commit 33dc3f6

Browse files
committed
Fill Hundrets adding new group now updates texture flag of field_8 and field_C in case it has or not texture
Improved Resize/Reposition/Rotate of selected piece if opened in PEditor (changes are applied in PEditor) Fixed Remove Edge in case offsetEdge is greater than number of Edges Assign correct Hundrets when group is duplicated (this affects also to Symmetric feature)
1 parent 49ea223 commit 33dc3f6

1 file changed

Lines changed: 94 additions & 12 deletions

File tree

FF7PModel.cs

Lines changed: 94 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,26 @@ public static void LoadPModel(ref PModel Model, string strPFolder, string strPFi
357357
Model.Groups = new PGroup[Model.Header.numGroups];
358358
ReadPGroups(fileBuffer, ref fileBufferPos, Model.Header.numGroups, ref Model.Groups, strPFullFileName);
359359

360+
361+
// Let's check Texture flag of model Group and texture flag of Hundret
362+
// and normalize value/flag in case they are change.
363+
// If this happens it is probably for older kimera versions
364+
int iGroupIdx = 0, iValue = 0;
365+
foreach(PGroup itmGroup in Model.Groups)
366+
{
367+
if (itmGroup.texFlag == 1) iValue = 0x2;
368+
else iValue = -0x2;
369+
370+
if (itmGroup.texFlag != ((Model.Hundrets[iGroupIdx].field_8 & 0x2) == 0 ? 0 : 1))
371+
Model.Hundrets[iGroupIdx].field_8 += iValue;
372+
373+
if (itmGroup.texFlag != ((Model.Hundrets[iGroupIdx].field_C & 0x2) == 0 ? 0 : 1))
374+
Model.Hundrets[iGroupIdx].field_C += iValue;
375+
376+
iGroupIdx++;
377+
}
378+
379+
360380
// BoundingBox
361381
Model.BoundingBox = new PBoundingBox();
362382
ReadPBoundingBox(fileBuffer, ref fileBufferPos, ref Model.BoundingBox, strPFullFileName);
@@ -1298,12 +1318,22 @@ public static void RotatePModelModifiers(ref PModel Model, float alpha, float be
12981318
Model.rotateGamma = gamma;
12991319
}
13001320

1301-
private static void FillHundrestsDefaultValues(ref PHundret hundret)
1321+
private static void FillHundrestsDefaultValues(ref PHundret hundret, bool bHasTexCoords)
13021322
{
13031323
hundret.field_0 = 1;
13041324
hundret.field_4 = 1;
1305-
hundret.field_8 = 246274;
1306-
hundret.field_C = 147458;
1325+
1326+
if (bHasTexCoords)
1327+
{
1328+
hundret.field_8 = 229894; // V_TEXTURE = 1 && V_LINEARFILTER = 1
1329+
hundret.field_C = 131078; // V_TrueTEXTURE = 1 && V_LINEARFILTER = 1
1330+
}
1331+
else
1332+
{
1333+
hundret.field_8 = 229888; // V_TEXTURE = 0 && V_LINEARFIL TER = 0
1334+
hundret.field_C = 131072; // V_TrueTEXTURE = 0 && V_LINEARFILTER = 0
1335+
}
1336+
13071337
hundret.texID = 0;
13081338
hundret.texture_set_ptr = 0;
13091339
hundret.field_18 = 0;
@@ -1441,7 +1471,7 @@ public static void AddGroup(ref PModel Model, Point3D[] vertsV, PPolygon[] faces
14411471
// Increase Hundrets
14421472
Model.Header.mirex_h += 1;
14431473
Array.Resize(ref Model.Hundrets, Model.Header.mirex_h);
1444-
FillHundrestsDefaultValues(ref Model.Hundrets[Model.Header.mirex_h - 1]);
1474+
FillHundrestsDefaultValues(ref Model.Hundrets[Model.Header.mirex_h - 1], Model.Groups[groupIndex].texFlag == 1);
14451475

14461476
if (Model.Header.mirex_h > 1)
14471477
Model.Hundrets[Model.Header.mirex_h - 1].texID = Model.Hundrets[Model.Header.mirex_h - 2].texID;
@@ -1884,12 +1914,12 @@ public static void ApplyPChangesPE(ref PModel Model, bool DNormals)
18841914

18851915
for (int iGroupIdx = 0; iGroupIdx < Model.Header.numGroups; iGroupIdx++)
18861916
{
1887-
Model.Groups[iGroupIdx].repGroupX = 0;
1888-
Model.Groups[iGroupIdx].repGroupY = 0;
1889-
Model.Groups[iGroupIdx].repGroupZ = 0;
18901917
Model.Groups[iGroupIdx].rszGroupX = 1;
18911918
Model.Groups[iGroupIdx].rszGroupY = 1;
18921919
Model.Groups[iGroupIdx].rszGroupZ = 1;
1920+
Model.Groups[iGroupIdx].repGroupX = 0;
1921+
Model.Groups[iGroupIdx].repGroupY = 0;
1922+
Model.Groups[iGroupIdx].repGroupZ = 0;
18931923
Model.Groups[iGroupIdx].rotGroupAlpha = 0;
18941924
Model.Groups[iGroupIdx].rotGroupBeta = 0;
18951925
Model.Groups[iGroupIdx].rotGroupGamma = 0;
@@ -1898,6 +1928,19 @@ public static void ApplyPChangesPE(ref PModel Model, bool DNormals)
18981928
Model.Groups[iGroupIdx].rotationQuaternionGroup.z = 0;
18991929
Model.Groups[iGroupIdx].rotationQuaternionGroup.w = 1;
19001930
}
1931+
1932+
Model.resizeX = 1;
1933+
Model.resizeY = 1;
1934+
Model.resizeZ = 1;
1935+
1936+
Model.repositionX = 0;
1937+
Model.repositionY = 0;
1938+
Model.repositionZ = 0;
1939+
1940+
Model.rotateAlpha = 0;
1941+
Model.rotateBeta = 0;
1942+
Model.rotateGamma = 0;
1943+
19011944
}
19021945
catch
19031946
{
@@ -2177,6 +2220,41 @@ public static void DestroyPModelResources(ref PModel Model)
21772220
// ---------------------------------------------------------------------------------------------------
21782221
// =========================================== COPY PMODEL ===========================================
21792222
// ---------------------------------------------------------------------------------------------------
2223+
public static PHundret CopyPHundret(PHundret hundretIn)
2224+
{
2225+
PHundret newPHundret = new PHundret();
2226+
2227+
newPHundret.alpharef = hundretIn.alpharef;
2228+
newPHundret.blend_mode = hundretIn.blend_mode;
2229+
newPHundret.destblend = hundretIn.destblend;
2230+
2231+
newPHundret.field_0 = hundretIn.field_0;
2232+
newPHundret.field_4 = hundretIn.field_4;
2233+
newPHundret.field_8 = hundretIn.field_8;
2234+
newPHundret.field_C = hundretIn.field_C;
2235+
newPHundret.field_18 = hundretIn.field_18;
2236+
newPHundret.field_1C = hundretIn.field_1C;
2237+
newPHundret.field_20 = hundretIn.field_20;
2238+
newPHundret.field_2C = hundretIn.field_2C;
2239+
newPHundret.field_3C = hundretIn.field_3C;
2240+
newPHundret.field_4C = hundretIn.field_4C;
2241+
newPHundret.field_50 = hundretIn.field_50;
2242+
newPHundret.field_54 = hundretIn.field_54;
2243+
newPHundret.field_58 = hundretIn.field_58;
2244+
newPHundret.field_60 = hundretIn.field_60;
2245+
2246+
newPHundret.lightstate_ambient = hundretIn.lightstate_ambient;
2247+
newPHundret.lightstate_material_ptr = hundretIn.lightstate_material_ptr;
2248+
newPHundret.shademode = hundretIn.shademode;
2249+
newPHundret.srcblend = hundretIn.srcblend;
2250+
newPHundret.texID = hundretIn.texID;
2251+
newPHundret.texture_set_ptr = hundretIn.texture_set_ptr;
2252+
newPHundret.vertex_alpha = hundretIn.vertex_alpha;
2253+
newPHundret.zSort = hundretIn.zSort;
2254+
2255+
return newPHundret;
2256+
}
2257+
21802258
public static PModel CopyPModel(PModel modelIn)
21812259
{
21822260
PModel modelOut;
@@ -2420,12 +2498,15 @@ public static void RemoveGroupEdges(ref PModel Model, int iGroupIdx)
24202498
iCountEdgesGroups = GetNextGroup(Model, iCountEdgesGroups);
24212499
}
24222500

2423-
ei2 = Model.Groups[iGroupIdx].offsetEdge;
2424-
2425-
for (ei = iCountNumEdges; ei < Model.Header.numEdges; ei++)
2501+
if (Model.Groups[iGroupIdx].offsetEdge < Model.Edges.Length)
24262502
{
2427-
Model.Edges[ei2] = Model.Edges[ei];
2428-
ei2++;
2503+
ei2 = Model.Groups[iGroupIdx].offsetEdge;
2504+
2505+
for (ei = iCountNumEdges; ei < Model.Header.numEdges; ei++)
2506+
{
2507+
Model.Edges[ei2] = Model.Edges[ei];
2508+
ei2++;
2509+
}
24292510
}
24302511
}
24312512

@@ -3031,6 +3112,7 @@ public static bool DuplicateGroup(ref PModel Model, int iGroupIdx)
30313112
AddGroup(ref Model, vVerts, vFaces, vTexCoords, vVcolors, vPcolors);
30323113

30333114
Model.Groups[Model.Header.numGroups - 1].texID = Model.Groups[iGroupIdx].texID;
3115+
Model.Hundrets[Model.Header.numGroups - 1] = CopyPHundret(Model.Hundrets[iGroupIdx]);
30343116

30353117
iDuplicateGroupResult = true;
30363118
}

0 commit comments

Comments
 (0)