public clsResult ReadPIE(StreamReader File, clsObjectData Owner) { clsResult ReturnResult = new clsResult("Reading PIE"); int A = 0; int B = 0; string strTemp = ""; string[] SplitText = null; int LevelCount = 0; int NewQuadCount = 0; int NewTriCount = 0; int C = 0; string TextureName = ""; sPIELevel[] Levels = null; int LevelNum = 0; bool GotText = default(bool); string strTemp2; int D = 0; int PIEVersion = 0; int Count = 0; Levels = new sPIELevel[0]; LevelNum = -1; do { strTemp = File.ReadLine(); if ( strTemp == null ) { goto FileFinished; } Reeval: if ( strTemp.Substring(0, 3) == "PIE" ) { PIEVersion = int.Parse(strTemp.Substring(strTemp.Length - (strTemp.Length - 4), strTemp.Length - 4)); if ( PIEVersion != 2 & PIEVersion != 3 ) { ReturnResult.ProblemAdd("Version is unknown."); return ReturnResult; } } else if ( strTemp.Substring(0, 4) == "TYPE" ) { } else if ( strTemp.Substring(0, 7) == "TEXTURE" ) { TextureName = strTemp.Substring(strTemp.Length - (strTemp.Length - 10), strTemp.Length - 10); A = Strings.InStrRev(TextureName, " ", -1, (CompareMethod)0); if ( A > 0 ) { A = Strings.InStrRev(TextureName, " ", A - 1, (CompareMethod)0); } else { ReturnResult.ProblemAdd("Bad texture name."); return ReturnResult; } if ( A > 0 ) { TextureName = TextureName.Substring(0, A - 1); } else { ReturnResult.ProblemAdd("Bad texture name."); return ReturnResult; } } else if ( strTemp.Substring(0, 6) == "LEVELS" ) { LevelCount = int.Parse(strTemp.Substring(strTemp.Length - (strTemp.Length - 7), strTemp.Length - 7)); Levels = new sPIELevel[LevelCount]; } else if ( strTemp.Substring(0, 6) == "LEVEL " ) { LevelNum = (int.Parse(strTemp.Substring(strTemp.Length - (strTemp.Length - 6), strTemp.Length - 6))) - 1; if ( LevelNum >= LevelCount ) { ReturnResult.ProblemAdd("Level number >= number of levels."); return ReturnResult; } } else if ( strTemp.Substring(0, 6) == "POINTS" ) { Levels[LevelNum].PointCount = int.Parse(strTemp.Substring(strTemp.Length - (strTemp.Length - 7), strTemp.Length - 7)); Levels[LevelNum].Point = new sXYZ_sng[Levels[LevelNum].PointCount]; A = 0; do { strTemp = File.ReadLine(); if ( strTemp == null ) { goto FileFinished; } strTemp2 = Strings.Left(strTemp, 1); if ( char.Parse(strTemp2) == '\t' || strTemp2 == " " ) { SplitText = new string[3]; C = 0; SplitText[0] = ""; GotText = false; for ( B = 0; B <= strTemp.Length - 1; B++ ) { if ( strTemp[B] != ' ' && strTemp[B] != ControlChars.Tab ) { GotText = true; SplitText[C] += strTemp[B].ToString(); } else { if ( GotText ) { C++; if ( C == 3 ) { break; } SplitText[C] = ""; GotText = false; } } } try { Levels[LevelNum].Point[A].X = float.Parse(SplitText[0]); Levels[LevelNum].Point[A].Y = float.Parse(SplitText[1]); Levels[LevelNum].Point[A].Z = float.Parse(SplitText[2]); } catch ( Exception ) { ReturnResult.ProblemAdd("Bad point " + Convert.ToString(A)); return ReturnResult; } A++; } else if ( string.IsNullOrEmpty(strTemp2) ) { } else { goto Reeval; } } while ( true ); } else if ( strTemp.Substring(0, 8) == "POLYGONS" ) { Levels[LevelNum].PolygonCount = int.Parse(strTemp.Substring(strTemp.Length - (strTemp.Length - 9), strTemp.Length - 9)); Levels[LevelNum].Polygon = new sPIELevel.sPolygon[Levels[LevelNum].PolygonCount]; A = 0; do { strTemp = File.ReadLine(); if ( strTemp == null ) { goto FileFinished; } strTemp2 = Strings.Left(strTemp, 1); if ( char.Parse(strTemp2) == '\t' || strTemp2 == " " ) { C = 0; SplitText = new string[C + 1]; SplitText[C] = ""; for ( B = 0; B <= strTemp.Length - 1; B++ ) { if ( strTemp[B] == ' ' || strTemp[B] == ControlChars.Tab ) { if ( SplitText[C].Length > 0 ) { C++; Array.Resize(ref SplitText, C + 1); SplitText[C] = ""; } } else { SplitText[C] += strTemp[B].ToString(); } } if ( SplitText[C].Length == 0 ) { Array.Resize(ref SplitText, C); } else { C++; } if ( PIEVersion == 3 ) { //200, pointcount, points, texcoords if ( C < 2 ) { ReturnResult.ProblemAdd("Too few fields for polygon " + Convert.ToString(A)); return ReturnResult; } try { Count = int.Parse(SplitText[1]); } catch ( Exception ex ) { ReturnResult.ProblemAdd("Bad polygon point count: " + ex.Message); return ReturnResult; } Levels[LevelNum].Polygon[A].PointCount = Count; Levels[LevelNum].Polygon[A].PointNum = new int[Count]; Levels[LevelNum].Polygon[A].TexCoord = new sXY_sng[Count]; if ( Count == 3 ) { NewTriCount++; } else if ( Count == 4 ) { NewQuadCount++; } if ( SplitText.GetUpperBound(0) + 1 == 0 ) { goto Reeval; } else if ( SplitText.GetUpperBound(0) + 1 != (2 + Count * 3) ) { ReturnResult.ProblemAdd("Wrong number of fields (" + Convert.ToString(SplitText.GetUpperBound(0) + 1) + ") for polygon " + Convert.ToString(A)); return ReturnResult; } for ( B = 0; B <= Count - 1; B++ ) { try { Levels[LevelNum].Polygon[A].PointNum[B] = int.Parse(SplitText[2 + B]); } catch ( Exception ex ) { ReturnResult.ProblemAdd("Bad polygon point: " + ex.Message); return ReturnResult; } try { Levels[LevelNum].Polygon[A].TexCoord[B].X = float.Parse(SplitText[2 + Count + 2 * B]); } catch ( Exception ex ) { ReturnResult.ProblemAdd("Bad polygon x tex coord: " + ex.Message); return ReturnResult; } try { Levels[LevelNum].Polygon[A].TexCoord[B].Y = float.Parse(SplitText[2 + Count + 2 * B + 1]); } catch ( Exception ex ) { ReturnResult.ProblemAdd("Bad polygon y tex coord: " + ex.Message); return ReturnResult; } } A++; } else if ( PIEVersion == 2 ) { D = 0; do { //flag, numpoints, points[], x4 ignore if animated, texcoord[]xy Levels[LevelNum].Polygon[A].PointCount = int.Parse(SplitText[D + 1]); Levels[LevelNum].Polygon[A].PointNum = new int[Levels[LevelNum].Polygon[A].PointCount]; Levels[LevelNum].Polygon[A].TexCoord = new sXY_sng[Levels[LevelNum].Polygon[A].PointCount]; if ( Levels[LevelNum].Polygon[A].PointCount == 3 ) { NewTriCount++; } else if ( Levels[LevelNum].Polygon[A].PointCount == 4 ) { NewQuadCount++; } for ( B = 0; B <= Levels[LevelNum].Polygon[A].PointCount - 1; B++ ) { Levels[LevelNum].Polygon[A].PointNum[B] = int.Parse(SplitText[D + 2 + B]); } C = D + 2 + Levels[LevelNum].Polygon[A].PointCount; if ( SplitText[D] == "4200" || SplitText[D] == "4000" || SplitText[D] == "6a00" || SplitText[D] == "4a00" || SplitText[D] == "6200" || SplitText[D] == "14200" || SplitText[D] == "14a00" || SplitText[D] == "16a00" ) { C += 4; } for ( B = 0; B <= Levels[LevelNum].Polygon[A].PointCount - 1; B++ ) { Levels[LevelNum].Polygon[A].TexCoord[B].X = float.Parse(SplitText[C]); Levels[LevelNum].Polygon[A].TexCoord[B].Y = float.Parse(SplitText[C + 1]); C += 2; } D = C; A++; } while ( D < SplitText.GetUpperBound(0) ); } } else if ( string.IsNullOrEmpty(strTemp2) ) { } else { goto Reeval; } } while ( true ); } else if ( strTemp.Substring(0, 10) == "CONNECTORS" ) { ConnectorCount = int.Parse(strTemp.Substring(strTemp.Length - (strTemp.Length - 11), strTemp.Length - 11)); Connectors = new sXYZ_sng[ConnectorCount]; A = 0; do { strTemp = File.ReadLine(); if ( strTemp == null ) { goto FileFinished; } strTemp2 = Strings.Left(strTemp, 1); if ( char.Parse(strTemp2) == '\t' || strTemp2 == " " ) { SplitText = new string[3]; C = 0; SplitText[0] = ""; GotText = false; for ( B = 0; B <= strTemp.Length - 1; B++ ) { if ( strTemp[B] != ' ' && strTemp[B] != ControlChars.Tab ) { GotText = true; SplitText[C] += strTemp[B].ToString(); } else { if ( GotText ) { C++; if ( C == 3 ) { break; } SplitText[C] = ""; GotText = false; } } } try { Connectors[A].X = float.Parse(SplitText[0]); Connectors[A].Y = float.Parse(SplitText[2]); Connectors[A].Z = float.Parse(SplitText[1]); } catch ( Exception ) { ReturnResult.ProblemAdd("Bad connector " + Convert.ToString(A)); return ReturnResult; } A++; } else if ( string.IsNullOrEmpty(strTemp2) ) { } else { goto Reeval; } } while ( true ); } else { } } while ( true ); FileFinished: GLTextureNum = Owner.Get_TexturePage_GLTexture(TextureName.Substring(0, TextureName.Length - 4)); if ( GLTextureNum == 0 ) { ReturnResult.WarningAdd("Texture " + Convert.ToString(ControlChars.Quote) + TextureName + Convert.ToString(ControlChars.Quote) + " was not loaded"); } TriangleCount = NewTriCount; QuadCount = NewQuadCount; Triangles = new sTriangle[TriangleCount]; Quads = new sQuad[QuadCount]; NewTriCount = 0; NewQuadCount = 0; for ( LevelNum = 0; LevelNum <= LevelCount - 1; LevelNum++ ) { for ( A = 0; A <= Levels[LevelNum].PolygonCount - 1; A++ ) { if ( Levels[LevelNum].Polygon[A].PointCount == 3 ) { Triangles[NewTriCount].PosA = Levels[LevelNum].Point[Levels[LevelNum].Polygon[A].PointNum[0]]; Triangles[NewTriCount].PosB = Levels[LevelNum].Point[Levels[LevelNum].Polygon[A].PointNum[1]]; Triangles[NewTriCount].PosC = Levels[LevelNum].Point[Levels[LevelNum].Polygon[A].PointNum[2]]; if ( PIEVersion == 2 ) { Triangles[NewTriCount].TexCoordA.X = (float)(Levels[LevelNum].Polygon[A].TexCoord[0].X / 255.0D); Triangles[NewTriCount].TexCoordA.Y = (float)(Levels[LevelNum].Polygon[A].TexCoord[0].Y / 255.0D); Triangles[NewTriCount].TexCoordB.X = (float)(Levels[LevelNum].Polygon[A].TexCoord[1].X / 255.0D); Triangles[NewTriCount].TexCoordB.Y = (float)(Levels[LevelNum].Polygon[A].TexCoord[1].Y / 255.0D); Triangles[NewTriCount].TexCoordC.X = (float)(Levels[LevelNum].Polygon[A].TexCoord[2].X / 255.0D); Triangles[NewTriCount].TexCoordC.Y = (float)(Levels[LevelNum].Polygon[A].TexCoord[2].Y / 255.0D); } else if ( PIEVersion == 3 ) { Triangles[NewTriCount].TexCoordA = Levels[LevelNum].Polygon[A].TexCoord[0]; Triangles[NewTriCount].TexCoordB = Levels[LevelNum].Polygon[A].TexCoord[1]; Triangles[NewTriCount].TexCoordC = Levels[LevelNum].Polygon[A].TexCoord[2]; } NewTriCount++; } else if ( Levels[LevelNum].Polygon[A].PointCount == 4 ) { Quads[NewQuadCount].PosA = Levels[LevelNum].Point[Levels[LevelNum].Polygon[A].PointNum[0]]; Quads[NewQuadCount].PosB = Levels[LevelNum].Point[Levels[LevelNum].Polygon[A].PointNum[1]]; Quads[NewQuadCount].PosC = Levels[LevelNum].Point[Levels[LevelNum].Polygon[A].PointNum[2]]; Quads[NewQuadCount].PosD = Levels[LevelNum].Point[Levels[LevelNum].Polygon[A].PointNum[3]]; if ( PIEVersion == 2 ) { Quads[NewQuadCount].TexCoordA.X = (float)(Levels[LevelNum].Polygon[A].TexCoord[0].X / 255.0D); Quads[NewQuadCount].TexCoordA.Y = (float)(Levels[LevelNum].Polygon[A].TexCoord[0].Y / 255.0D); Quads[NewQuadCount].TexCoordB.X = (float)(Levels[LevelNum].Polygon[A].TexCoord[1].X / 255.0D); Quads[NewQuadCount].TexCoordB.Y = (float)(Levels[LevelNum].Polygon[A].TexCoord[1].Y / 255.0D); Quads[NewQuadCount].TexCoordC.X = (float)(Levels[LevelNum].Polygon[A].TexCoord[2].X / 255.0D); Quads[NewQuadCount].TexCoordC.Y = (float)(Levels[LevelNum].Polygon[A].TexCoord[2].Y / 255.0D); Quads[NewQuadCount].TexCoordD.X = (float)(Levels[LevelNum].Polygon[A].TexCoord[3].X / 255.0D); Quads[NewQuadCount].TexCoordD.Y = (float)(Levels[LevelNum].Polygon[A].TexCoord[3].Y / 255.0D); } else if ( PIEVersion == 3 ) { Quads[NewQuadCount].TexCoordA = Levels[LevelNum].Polygon[A].TexCoord[0]; Quads[NewQuadCount].TexCoordB = Levels[LevelNum].Polygon[A].TexCoord[1]; Quads[NewQuadCount].TexCoordC = Levels[LevelNum].Polygon[A].TexCoord[2]; Quads[NewQuadCount].TexCoordD = Levels[LevelNum].Polygon[A].TexCoord[3]; } NewQuadCount++; } } } return ReturnResult; }
public clsResult ReadPIE(StreamReader File, clsObjectData Owner) { int num; int num2; int num3; bool flag; int num6; int num8; int num9; int num10; clsResult result; string[] strArray; string str; string str2; string[] strArray2; int num12; clsResult result2 = new clsResult("Reading PIE"); string stringCheck = ""; sPIELevel[] levelArray = new sPIELevel[0]; int index = -1; Label_001E: str = File.ReadLine(); if (str == null) { goto Label_0BD9; } Label_002F: if (Strings.Left(str, 3) == "PIE") { num10 = Conversions.ToInteger(Strings.Right(str, str.Length - 4)); if ((num10 != 2) & (num10 != 3)) { result2.ProblemAdd("Version is unknown."); return result2; } goto Label_001E; } if (Strings.Left(str, 4) == "TYPE") { goto Label_001E; } if (Strings.Left(str, 7) == "TEXTURE") { stringCheck = Strings.Right(str, str.Length - 10); num = Strings.InStrRev(stringCheck, " ", -1, CompareMethod.Binary); if (num > 0) { num = Strings.InStrRev(stringCheck, " ", num - 1, CompareMethod.Binary); } else { result2.ProblemAdd("Bad texture name."); return result2; } if (num <= 0) { result2.ProblemAdd("Bad texture name."); return result2; } stringCheck = Strings.Left(stringCheck, num - 1); goto Label_001E; } if (Strings.Left(str, 6) == "LEVELS") { num6 = Conversions.ToInteger(Strings.Right(str, str.Length - 7)); levelArray = new sPIELevel[(num6 - 1) + 1]; goto Label_001E; } if (Strings.Left(str, 6) == "LEVEL ") { index = Conversions.ToInteger(Strings.Right(str, str.Length - 6)) - 1; if (index >= num6) { result2.ProblemAdd("Level number >= number of levels."); return result2; } goto Label_001E; } if (Strings.Left(str, 6) != "POINTS") { if (Strings.Left(str, 8) != "POLYGONS") { if (Strings.Left(str, 10) != "CONNECTORS") { goto Label_001E; } this.ConnectorCount = Conversions.ToInteger(Strings.Right(str, str.Length - 11)); this.Connectors = new modMath.sXYZ_sng[(this.ConnectorCount - 1) + 1]; num = 0; goto Label_0A69; } levelArray[index].PolygonCount = Conversions.ToInteger(Strings.Right(str, str.Length - 9)); levelArray[index].Polygon = new sPIELevel.sPolygon[(levelArray[index].PolygonCount - 1) + 1]; num = 0; } else { levelArray[index].PointCount = Conversions.ToInteger(Strings.Right(str, str.Length - 7)); levelArray[index].Point = new modMath.sXYZ_sng[(levelArray[index].PointCount - 1) + 1]; num = 0; while (true) { str = File.ReadLine(); if (str == null) { goto Label_0BD9; } str2 = Strings.Left(str, 1); if (!((str2 == "\t") | (str2 == " "))) { if (str2 != "") { goto Label_002F; } } else { strArray = new string[3]; num3 = 0; strArray[0] = ""; flag = false; int num11 = str.Length - 1; for (num2 = 0; num2 <= num11; num2++) { if ((str[num2] != ' ') & (str[num2] != '\t')) { flag = true; strArray2 = strArray; num12 = num3; strArray2[num12] = strArray2[num12] + Conversions.ToString(str[num2]); } else if (flag) { num3++; if (num3 == 3) { break; } strArray[num3] = ""; flag = false; } } try { levelArray[index].Point[num].X = Conversions.ToSingle(strArray[0]); levelArray[index].Point[num].Y = Conversions.ToSingle(strArray[1]); levelArray[index].Point[num].Z = Conversions.ToSingle(strArray[2]); } catch (Exception exception1) { ProjectData.SetProjectError(exception1); Exception exception = exception1; result2.ProblemAdd("Bad point " + Conversions.ToString(num)); result = result2; ProjectData.ClearProjectError(); return result; } num++; } } } while (true) { str = File.ReadLine(); if (str == null) { goto Label_0BD9; } str2 = Strings.Left(str, 1); if (!((str2 == "\t") | (str2 == " "))) { if (str2 != "") { goto Label_002F; } } else { num3 = 0; strArray = new string[num3 + 1]; strArray[num3] = ""; int num13 = str.Length - 1; for (num2 = 0; num2 <= num13; num2++) { if ((str[num2] == ' ') | (str[num2] == '\t')) { if (strArray[num3].Length > 0) { num3++; strArray = (string[]) Utils.CopyArray((Array) strArray, new string[num3 + 1]); strArray[num3] = ""; } } else { strArray2 = strArray; num12 = num3; strArray2[num12] = strArray2[num12] + Conversions.ToString(str[num2]); } } if (strArray[num3].Length == 0) { strArray = (string[]) Utils.CopyArray((Array) strArray, new string[(num3 - 1) + 1]); } else { num3++; } if (num10 == 3) { int num4; if (num3 < 2) { result2.ProblemAdd("Too few fields for polygon " + Conversions.ToString(num)); return result2; } try { num4 = Conversions.ToInteger(strArray[1]); } catch (Exception exception7) { ProjectData.SetProjectError(exception7); Exception exception2 = exception7; result2.ProblemAdd("Bad polygon point count: " + exception2.Message); result = result2; ProjectData.ClearProjectError(); return result; } levelArray[index].Polygon[num].PointCount = num4; levelArray[index].Polygon[num].PointNum = new int[(num4 - 1) + 1]; levelArray[index].Polygon[num].TexCoord = new modMath.sXY_sng[(num4 - 1) + 1]; switch (num4) { case 3: num9++; break; case 4: num8++; break; } int num14 = strArray.GetUpperBound(0) + 1; if (num14 == 0) { goto Label_002F; } if (num14 != (2 + (num4 * 3))) { result2.ProblemAdd("Wrong number of fields (" + Conversions.ToString((int) (strArray.GetUpperBound(0) + 1)) + ") for polygon " + Conversions.ToString(num)); return result2; } int num15 = num4 - 1; for (num2 = 0; num2 <= num15; num2++) { try { levelArray[index].Polygon[num].PointNum[num2] = Conversions.ToInteger(strArray[2 + num2]); } catch (Exception exception8) { ProjectData.SetProjectError(exception8); Exception exception3 = exception8; result2.ProblemAdd("Bad polygon point: " + exception3.Message); result = result2; ProjectData.ClearProjectError(); return result; } try { levelArray[index].Polygon[num].TexCoord[num2].X = Conversions.ToSingle(strArray[(2 + num4) + (2 * num2)]); } catch (Exception exception9) { ProjectData.SetProjectError(exception9); Exception exception4 = exception9; result2.ProblemAdd("Bad polygon x tex coord: " + exception4.Message); result = result2; ProjectData.ClearProjectError(); return result; } try { levelArray[index].Polygon[num].TexCoord[num2].Y = Conversions.ToSingle(strArray[((2 + num4) + (2 * num2)) + 1]); } catch (Exception exception10) { ProjectData.SetProjectError(exception10); Exception exception5 = exception10; result2.ProblemAdd("Bad polygon y tex coord: " + exception5.Message); result = result2; ProjectData.ClearProjectError(); return result; } } num++; } else if (num10 == 2) { int num5 = 0; do { levelArray[index].Polygon[num].PointCount = Conversions.ToInteger(strArray[num5 + 1]); levelArray[index].Polygon[num].PointNum = new int[(levelArray[index].Polygon[num].PointCount - 1) + 1]; levelArray[index].Polygon[num].TexCoord = new modMath.sXY_sng[(levelArray[index].Polygon[num].PointCount - 1) + 1]; if (levelArray[index].Polygon[num].PointCount == 3) { num9++; } else if (levelArray[index].Polygon[num].PointCount == 4) { num8++; } int num16 = levelArray[index].Polygon[num].PointCount - 1; for (num2 = 0; num2 <= num16; num2++) { levelArray[index].Polygon[num].PointNum[num2] = Conversions.ToInteger(strArray[(num5 + 2) + num2]); } num3 = (num5 + 2) + levelArray[index].Polygon[num].PointCount; if ((((((((strArray[num5] == "4200") | (strArray[num5] == "4000")) | (strArray[num5] == "6a00")) | (strArray[num5] == "4a00")) | (strArray[num5] == "6200")) | (strArray[num5] == "14200")) | (strArray[num5] == "14a00")) | (strArray[num5] == "16a00")) { num3 += 4; } int num17 = levelArray[index].Polygon[num].PointCount - 1; for (num2 = 0; num2 <= num17; num2++) { levelArray[index].Polygon[num].TexCoord[num2].X = Conversions.ToSingle(strArray[num3]); levelArray[index].Polygon[num].TexCoord[num2].Y = Conversions.ToSingle(strArray[num3 + 1]); num3 += 2; } num5 = num3; num++; } while (num5 < strArray.GetUpperBound(0)); } } } Label_0A69: str = File.ReadLine(); if (str != null) { str2 = Strings.Left(str, 1); if (!((str2 == "\t") | (str2 == " "))) { if (str2 != "") { goto Label_002F; } } else { strArray = new string[3]; num3 = 0; strArray[0] = ""; flag = false; int num18 = str.Length - 1; for (num2 = 0; num2 <= num18; num2++) { if ((str[num2] != ' ') & (str[num2] != '\t')) { flag = true; strArray2 = strArray; num12 = num3; strArray2[num12] = strArray2[num12] + Conversions.ToString(str[num2]); } else if (flag) { num3++; if (num3 == 3) { break; } strArray[num3] = ""; flag = false; } } try { this.Connectors[num].X = Conversions.ToSingle(strArray[0]); this.Connectors[num].Y = Conversions.ToSingle(strArray[2]); this.Connectors[num].Z = Conversions.ToSingle(strArray[1]); } catch (Exception exception11) { ProjectData.SetProjectError(exception11); Exception exception6 = exception11; result2.ProblemAdd("Bad connector " + Conversions.ToString(num)); result = result2; ProjectData.ClearProjectError(); return result; } num++; } goto Label_0A69; } Label_0BD9: this.GLTextureNum = Owner.Get_TexturePage_GLTexture(Strings.Left(stringCheck, stringCheck.Length - 4)); if (this.GLTextureNum == 0) { result2.WarningAdd("Texture \"" + stringCheck + "\" was not loaded"); } this.TriangleCount = num9; this.QuadCount = num8; this.Triangles = new sTriangle[(this.TriangleCount - 1) + 1]; this.Quads = new sQuad[(this.QuadCount - 1) + 1]; num9 = 0; num8 = 0; int num19 = num6 - 1; for (index = 0; index <= num19; index++) { int num20 = levelArray[index].PolygonCount - 1; for (num = 0; num <= num20; num++) { if (levelArray[index].Polygon[num].PointCount == 3) { this.Triangles[num9].PosA = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[0]]; this.Triangles[num9].PosB = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[1]]; this.Triangles[num9].PosC = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[2]]; switch (num10) { case 2: this.Triangles[num9].TexCoordA.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[0].X) / 255.0); this.Triangles[num9].TexCoordA.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[0].Y) / 255.0); this.Triangles[num9].TexCoordB.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[1].X) / 255.0); this.Triangles[num9].TexCoordB.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[1].Y) / 255.0); this.Triangles[num9].TexCoordC.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[2].X) / 255.0); this.Triangles[num9].TexCoordC.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[2].Y) / 255.0); break; case 3: this.Triangles[num9].TexCoordA = levelArray[index].Polygon[num].TexCoord[0]; this.Triangles[num9].TexCoordB = levelArray[index].Polygon[num].TexCoord[1]; this.Triangles[num9].TexCoordC = levelArray[index].Polygon[num].TexCoord[2]; break; } num9++; continue; } if (levelArray[index].Polygon[num].PointCount == 4) { this.Quads[num8].PosA = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[0]]; this.Quads[num8].PosB = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[1]]; this.Quads[num8].PosC = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[2]]; this.Quads[num8].PosD = levelArray[index].Point[levelArray[index].Polygon[num].PointNum[3]]; switch (num10) { case 2: this.Quads[num8].TexCoordA.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[0].X) / 255.0); this.Quads[num8].TexCoordA.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[0].Y) / 255.0); this.Quads[num8].TexCoordB.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[1].X) / 255.0); this.Quads[num8].TexCoordB.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[1].Y) / 255.0); this.Quads[num8].TexCoordC.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[2].X) / 255.0); this.Quads[num8].TexCoordC.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[2].Y) / 255.0); this.Quads[num8].TexCoordD.X = (float) (((double) levelArray[index].Polygon[num].TexCoord[3].X) / 255.0); this.Quads[num8].TexCoordD.Y = (float) (((double) levelArray[index].Polygon[num].TexCoord[3].Y) / 255.0); break; case 3: this.Quads[num8].TexCoordA = levelArray[index].Polygon[num].TexCoord[0]; this.Quads[num8].TexCoordB = levelArray[index].Polygon[num].TexCoord[1]; this.Quads[num8].TexCoordC = levelArray[index].Polygon[num].TexCoord[2]; this.Quads[num8].TexCoordD = levelArray[index].Polygon[num].TexCoord[3]; break; } num8++; } } } return result2; }
public Result ReadPIE(StreamReader file, clsObjectData owner) { var returnResult = new Result("Reading PIE", false); logger.Debug("Reading PIE"); var a = 0; var levelCount = 0; var newQuadCount = 0; var newTriCount = 0; var textureName = ""; sPIELevel[] levels = null; var levelNum = 0; var D = 0; var pieVersion = 0; levels = new sPIELevel[0]; levelNum = -1; do { var strTemp = file.ReadLine(); if (strTemp == null) { goto FileFinished; } Reeval: if (strTemp.Substring(0, 3) == "PIE") { pieVersion = int.Parse(strTemp.Substring(strTemp.Length - (strTemp.Length - 4), strTemp.Length - 4)); if (pieVersion != 2 & pieVersion != 3) { returnResult.ProblemAdd("Version is unknown."); return(returnResult); } } else if (strTemp.Substring(0, 4) == "TYPE") { } else if (strTemp.Substring(0, 7) == "TEXTURE") { textureName = strTemp.Substring(strTemp.Length - (strTemp.Length - 10), strTemp.Length - 10); a = textureName.LastIndexOf(" "); if (a > 0) { a = textureName.LastIndexOf(" ", a - 1) + 1; } else { returnResult.ProblemAdd("Bad texture name."); return(returnResult); } if (a > 0) { textureName = textureName.Substring(0, a - 1); } else { returnResult.ProblemAdd("Bad texture name."); return(returnResult); } } else if (strTemp.Substring(0, 6) == "LEVELS") { levelCount = int.Parse(strTemp.Substring(strTemp.Length - (strTemp.Length - 7), strTemp.Length - 7)); levels = new sPIELevel[levelCount]; } else if (strTemp.Substring(0, 6) == "LEVEL ") { levelNum = (int.Parse(strTemp.Substring(strTemp.Length - (strTemp.Length - 6), strTemp.Length - 6))) - 1; if (levelNum >= levelCount) { returnResult.ProblemAdd("Level number >= number of levels."); return(returnResult); } } else { var b = 0; string[] splitText = null; var c = 0; var gotText = default(bool); string strTemp2; if (strTemp.Substring(0, 6) == "POINTS") { levels[levelNum].PointCount = int.Parse(strTemp.Substring(strTemp.Length - (strTemp.Length - 7), strTemp.Length - 7)); levels[levelNum].Point = new XYZDouble[levels[levelNum].PointCount]; a = 0; do { strTemp = file.ReadLine(); if (strTemp == null) { goto FileFinished; } strTemp2 = strTemp.Left(1); if (char.Parse(strTemp2) == '\t' || strTemp2 == " ") { splitText = new string[3]; c = 0; splitText[0] = ""; gotText = false; for (b = 0; b <= strTemp.Length - 1; b++) { if (strTemp[b] != ' ' && strTemp[b] != '\t') { gotText = true; splitText[c] += strTemp[b].ToString(); } else { if (gotText) { c++; if (c == 3) { break; } splitText[c] = ""; gotText = false; } } } try { levels[levelNum].Point[a].X = float.Parse(splitText[0]); levels[levelNum].Point[a].Y = float.Parse(splitText[1]); levels[levelNum].Point[a].Z = float.Parse(splitText[2]); } catch (Exception) { returnResult.ProblemAdd("Bad point " + Convert.ToString(a)); return(returnResult); } a++; } else if (string.IsNullOrEmpty(strTemp2)) { } else { goto Reeval; } } while (true); } else if (strTemp.Substring(0, 8) == "POLYGONS") { levels[levelNum].PolygonCount = int.Parse(strTemp.Substring(strTemp.Length - (strTemp.Length - 9), strTemp.Length - 9)); levels[levelNum].Polygon = new sPIELevel.sPolygon[levels[levelNum].PolygonCount]; a = 0; do { strTemp = file.ReadLine(); if (strTemp == null) { goto FileFinished; } strTemp2 = strTemp.Left(1); if (char.Parse(strTemp2) == '\t' || strTemp2 == " ") { c = 0; splitText = new string[c + 1]; splitText[c] = ""; for (b = 0; b <= strTemp.Length - 1; b++) { if (strTemp[b] == ' ' || strTemp[b] == '\t') { if (splitText[c].Length > 0) { c++; Array.Resize(ref splitText, c + 1); splitText[c] = ""; } } else { splitText[c] += strTemp[b].ToString(); } } if (splitText[c].Length == 0) { Array.Resize(ref splitText, c); } else { c++; } if (pieVersion == 3) { //200, pointcount, points, texcoords if (c < 2) { returnResult.ProblemAdd("Too few fields for polygon " + Convert.ToString(a)); return(returnResult); } var count = 0; try { count = int.Parse(splitText[1]); } catch (Exception ex) { returnResult.ProblemAdd("Bad polygon point count: " + ex.Message); return(returnResult); } levels[levelNum].Polygon[a].PointCount = count; levels[levelNum].Polygon[a].PointNum = new int[count]; levels[levelNum].Polygon[a].TexCoord = new XYDouble[count]; if (count == 3) { newTriCount++; } else if (count == 4) { newQuadCount++; } if (splitText.GetUpperBound(0) + 1 == 0) { goto Reeval; } if (splitText.GetUpperBound(0) + 1 != (2 + count * 3)) { returnResult.ProblemAdd("Wrong number of fields (" + Convert.ToString(splitText.GetUpperBound(0) + 1) + ") for polygon " + Convert.ToString(a)); return(returnResult); } for (b = 0; b <= count - 1; b++) { try { levels[levelNum].Polygon[a].PointNum[b] = int.Parse(splitText[2 + b]); } catch (Exception ex) { returnResult.ProblemAdd("Bad polygon point: " + ex.Message); return(returnResult); } try { levels[levelNum].Polygon[a].TexCoord[b].X = float.Parse(splitText[2 + count + 2 * b]); } catch (Exception ex) { returnResult.ProblemAdd("Bad polygon x tex coord: " + ex.Message); return(returnResult); } try { levels[levelNum].Polygon[a].TexCoord[b].Y = float.Parse(splitText[2 + count + 2 * b + 1]); } catch (Exception ex) { returnResult.ProblemAdd("Bad polygon y tex coord: " + ex.Message); return(returnResult); } } a++; } else if (pieVersion == 2) { D = 0; do { //flag, numpoints, points[], x4 ignore if animated, texcoord[]xy levels[levelNum].Polygon[a].PointCount = int.Parse(splitText[D + 1]); levels[levelNum].Polygon[a].PointNum = new int[levels[levelNum].Polygon[a].PointCount]; levels[levelNum].Polygon[a].TexCoord = new XYDouble[levels[levelNum].Polygon[a].PointCount]; if (levels[levelNum].Polygon[a].PointCount == 3) { newTriCount++; } else if (levels[levelNum].Polygon[a].PointCount == 4) { newQuadCount++; } for (b = 0; b <= levels[levelNum].Polygon[a].PointCount - 1; b++) { levels[levelNum].Polygon[a].PointNum[b] = int.Parse(splitText[D + 2 + b]); } c = D + 2 + levels[levelNum].Polygon[a].PointCount; if (splitText[D] == "4200" || splitText[D] == "4000" || splitText[D] == "6a00" || splitText[D] == "4a00" || splitText[D] == "6200" || splitText[D] == "14200" || splitText[D] == "14a00" || splitText[D] == "16a00") { c += 4; } for (b = 0; b <= levels[levelNum].Polygon[a].PointCount - 1; b++) { levels[levelNum].Polygon[a].TexCoord[b].X = float.Parse(splitText[c]); levels[levelNum].Polygon[a].TexCoord[b].Y = float.Parse(splitText[c + 1]); c += 2; } D = c; a++; } while (D < splitText.GetUpperBound(0)); } } else if (string.IsNullOrEmpty(strTemp2)) { } else { goto Reeval; } } while (true); } else if (strTemp.Substring(0, 10) == "CONNECTORS") { ConnectorCount = int.Parse(strTemp.Substring(strTemp.Length - (strTemp.Length - 11), strTemp.Length - 11)); Connectors = new XYZDouble[ConnectorCount]; a = 0; do { strTemp = file.ReadLine(); if (strTemp == null) { goto FileFinished; } strTemp2 = strTemp.Left(1); if (char.Parse(strTemp2) == '\t' || strTemp2 == " ") { splitText = new string[3]; c = 0; splitText[0] = ""; gotText = false; for (b = 0; b <= strTemp.Length - 1; b++) { if (strTemp[b] != ' ' && strTemp[b] != '\t') { gotText = true; splitText[c] += strTemp[b].ToString(); } else { if (gotText) { c++; if (c == 3) { break; } splitText[c] = ""; gotText = false; } } } try { Connectors[a].X = float.Parse(splitText[0]); Connectors[a].Y = float.Parse(splitText[2]); Connectors[a].Z = float.Parse(splitText[1]); } catch (Exception) { returnResult.ProblemAdd("Bad connector " + Convert.ToString(a)); return(returnResult); } a++; } else if (string.IsNullOrEmpty(strTemp2)) { } else { goto Reeval; } } while (true); } } } while (true); FileFinished: GLTextureNum = owner.Get_TexturePage_GLTexture(textureName.Substring(0, textureName.Length - 4)); if (GLTextureNum == 0) { returnResult.WarningAdd("Texture \"{0}\" was not loaded".Format2(textureName)); } TriangleCount = newTriCount; QuadCount = newQuadCount; Triangles = new sTriangle[TriangleCount]; Quads = new sQuad[QuadCount]; newTriCount = 0; newQuadCount = 0; for (levelNum = 0; levelNum <= levelCount - 1; levelNum++) { for (a = 0; a <= levels[levelNum].PolygonCount - 1; a++) { if (levels[levelNum].Polygon[a].PointCount == 3) { Triangles[newTriCount].PosA = levels[levelNum].Point[levels[levelNum].Polygon[a].PointNum[0]]; Triangles[newTriCount].PosB = levels[levelNum].Point[levels[levelNum].Polygon[a].PointNum[1]]; Triangles[newTriCount].PosC = levels[levelNum].Point[levels[levelNum].Polygon[a].PointNum[2]]; if (pieVersion == 2) { Triangles[newTriCount].TexCoordA.X = (float)(levels[levelNum].Polygon[a].TexCoord[0].X / 255.0D); Triangles[newTriCount].TexCoordA.Y = (float)(levels[levelNum].Polygon[a].TexCoord[0].Y / 255.0D); Triangles[newTriCount].TexCoordB.X = (float)(levels[levelNum].Polygon[a].TexCoord[1].X / 255.0D); Triangles[newTriCount].TexCoordB.Y = (float)(levels[levelNum].Polygon[a].TexCoord[1].Y / 255.0D); Triangles[newTriCount].TexCoordC.X = (float)(levels[levelNum].Polygon[a].TexCoord[2].X / 255.0D); Triangles[newTriCount].TexCoordC.Y = (float)(levels[levelNum].Polygon[a].TexCoord[2].Y / 255.0D); } else if (pieVersion == 3) { Triangles[newTriCount].TexCoordA = levels[levelNum].Polygon[a].TexCoord[0]; Triangles[newTriCount].TexCoordB = levels[levelNum].Polygon[a].TexCoord[1]; Triangles[newTriCount].TexCoordC = levels[levelNum].Polygon[a].TexCoord[2]; } newTriCount++; } else if (levels[levelNum].Polygon[a].PointCount == 4) { Quads[newQuadCount].PosA = levels[levelNum].Point[levels[levelNum].Polygon[a].PointNum[0]]; Quads[newQuadCount].PosB = levels[levelNum].Point[levels[levelNum].Polygon[a].PointNum[1]]; Quads[newQuadCount].PosC = levels[levelNum].Point[levels[levelNum].Polygon[a].PointNum[2]]; Quads[newQuadCount].PosD = levels[levelNum].Point[levels[levelNum].Polygon[a].PointNum[3]]; if (pieVersion == 2) { Quads[newQuadCount].TexCoordA.X = (float)(levels[levelNum].Polygon[a].TexCoord[0].X / 255.0D); Quads[newQuadCount].TexCoordA.Y = (float)(levels[levelNum].Polygon[a].TexCoord[0].Y / 255.0D); Quads[newQuadCount].TexCoordB.X = (float)(levels[levelNum].Polygon[a].TexCoord[1].X / 255.0D); Quads[newQuadCount].TexCoordB.Y = (float)(levels[levelNum].Polygon[a].TexCoord[1].Y / 255.0D); Quads[newQuadCount].TexCoordC.X = (float)(levels[levelNum].Polygon[a].TexCoord[2].X / 255.0D); Quads[newQuadCount].TexCoordC.Y = (float)(levels[levelNum].Polygon[a].TexCoord[2].Y / 255.0D); Quads[newQuadCount].TexCoordD.X = (float)(levels[levelNum].Polygon[a].TexCoord[3].X / 255.0D); Quads[newQuadCount].TexCoordD.Y = (float)(levels[levelNum].Polygon[a].TexCoord[3].Y / 255.0D); } else if (pieVersion == 3) { Quads[newQuadCount].TexCoordA = levels[levelNum].Polygon[a].TexCoord[0]; Quads[newQuadCount].TexCoordB = levels[levelNum].Polygon[a].TexCoord[1]; Quads[newQuadCount].TexCoordC = levels[levelNum].Polygon[a].TexCoord[2]; Quads[newQuadCount].TexCoordD = levels[levelNum].Polygon[a].TexCoord[3]; } newQuadCount++; } } } return(returnResult); }