Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2022
1,938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.79 KB | None | 0 0
  1. public static class BruteForcer
  2. {
  3.     public static (float x, float y, float z) teleporterPos = (-6612, 1024, -3351);
  4.     public static (float x, float y, float z) elevatorStartPos = (1813.50732421875f, 768, 4472.35693359375f);
  5.     public static (float x, float y, float z) target1Pos = (-5789.0634765625f, 1024, -1558.23718261719f);
  6.  
  7.     public static (float x, float y, float z) inCornerPos = (7013.36474609375f, 908.641296386719f, -3849.3798828125f);
  8.     public static (float x, float y, float z) target2Pos = (4445.69482421875f, 3439.88891601563f, -6623.66259765625f);
  9.  
  10.     public static List<TriangleDataModel> allFloorTris;
  11.     public static List<TriangleDataModel> flatFloorTris;
  12.  
  13.     public static void Run()
  14.     {
  15.         Config.Print("START");
  16.  
  17.         allFloorTris = TriangleUtilities.GetLevelTriangles().FindAll(tri => tri.IsFloor());
  18.         flatFloorTris = TriangleUtilities.GetLevelTriangles().FindAll(tri => tri.IsFloor() && tri.NormY == 1);
  19.  
  20.         //Test(-200_000_000, -100_000_000, 100_000, elevatorStartPos, target1Pos);
  21.         Run(-61_095_980, -60_000_000, 200, inCornerPos, target2Pos);
  22.  
  23.         Config.Print("END");
  24.     }
  25.  
  26.     public static void Run(double startSpeed, double endSpeed, double speedIncrement, (float x, float y, float z) startPos, (float x, float y, float z) endPos)
  27.     {
  28.         //for (double speed0 = startSpeed; speed0 <= endSpeed; speed0 += speedIncrement)
  29.  
  30.         List<double> hSpeeds = GetSuccessiveHSpeeds2(startSpeed);
  31.         hSpeeds.Sort();
  32.         foreach (double speed0 in hSpeeds)
  33.         {
  34.             for (int angle0 = 0; angle0 < 65536; angle0 += 16)
  35.             {
  36.                 MarioPuState state0 = new MarioPuState(startPos.x, startPos.y, startPos.z, speed0, angle0, 0.99834132194519f, null, 0);
  37.                 MarioPuState state1 = TestOverflowJump(state0, angle0);
  38.                 if (state1 != null)
  39.                 {
  40.                     List<MarioPuState> state1Bs = GetSuccessiveStates(state1);
  41.                     foreach (MarioPuState state1B in state1Bs)
  42.                     {
  43.                         for (int angle1 = 0; angle1 < 65536; angle1 += 16)
  44.                         {
  45.                             MarioPuState state2 = TestOverflowJump(state1B, angle1);
  46.                             if (state2 != null)
  47.                             {
  48.                                 List<MarioPuState> state2Bs = GetSuccessiveStates(state2);
  49.                                 foreach (MarioPuState state2B in state2Bs)
  50.                                 {
  51.                                     double angle2 = MoreMath.AngleTo_AngleUnits(endPos.x, endPos.z, state2B.X, state2B.Z);
  52.                                     ushort angle2Truncated = MoreMath.NormalizeAngleTruncated(Math.Round(angle2));
  53.                                     MarioPuState state3 = TestOverflowJump(state2B, angle2Truncated);
  54.                                     if (state3 != null && state3.GetPuX() == 0 && state3.GetPuZ() == 0)
  55.                                     {
  56.                                         double distToStart = MoreMath.GetDistanceBetween(state3.X, state3.Y, state3.Z, startPos.x, startPos.y, startPos.z);
  57.                                         double yDistToEnd = state3.Y - endPos.y;
  58.                                         if (distToStart < 5000 && yDistToEnd >= -1000)
  59.                                         {
  60.                                             Config.Print("state0 = " + state0);
  61.                                             Config.Print("state1 = " + state1);
  62.                                             Config.Print("state1B = " + state1B);
  63.                                             Config.Print("state2 = " + state2);
  64.                                             Config.Print("state2B = " + state2B);
  65.                                             Config.Print("state3 = " + state3);
  66.                                             Config.Print("dist to start = " + distToStart);
  67.                                             Config.Print("yDist to end = " + yDistToEnd);
  68.                                             Config.Print();
  69.                                         }
  70.                                     }
  71.                                 }
  72.                             }
  73.                         }
  74.                     }
  75.                 }
  76.             }
  77.         }
  78.     }
  79.  
  80.     public static MarioPuState TestOverflowJump(MarioPuState state, int angle)
  81.     {
  82.         (double testX, double testZ) = MoreMath.AddVectorToPoint(state.HSpeed / 4 * state.YNorm, angle, state.X, state.Z);
  83.         double testY = state.Y;
  84.  
  85.         double modTestX = MoreMath.MaybeNegativeModulus(testX, 65536);
  86.         double modTestY = MoreMath.MaybeNegativeModulus(testY, 65536);
  87.         double modTestZ = MoreMath.MaybeNegativeModulus(testZ, 65536);
  88.  
  89.         foreach (TriangleDataModel tri in allFloorTris)
  90.         {
  91.             if (tri.IsPointInsideAndAboveTriangle(modTestX, modTestY, modTestZ))
  92.             {
  93.                 return null; // would prematurely go to PU
  94.             }
  95.         }
  96.  
  97.         double hSpeed = state.HSpeed * 0.8;
  98.         double hDist = hSpeed / 4;
  99.         double vSpeed = 42 + state.HSpeed / 4;
  100.         double vDist = vSpeed / 4;
  101.  
  102.         (double x, double z) = MoreMath.AddVectorToPoint(hDist, angle, state.X, state.Z);
  103.         double y = state.Y + vDist;
  104.  
  105.         double modX = MoreMath.MaybeNegativeModulus(x, 65536);
  106.         double modY = MoreMath.MaybeNegativeModulus(y, 65536);
  107.         double modZ = MoreMath.MaybeNegativeModulus(z, 65536);
  108.  
  109.         if (modX < -8192 || modX > 8192) return null;
  110.         if (modZ < -8192 || modZ > 8192) return null;
  111.         if (modY < -8192) return null;
  112.  
  113.         double? bestFloorY = null;
  114.         float yNorm = 1;
  115.         foreach (TriangleDataModel tri in allFloorTris)
  116.         {
  117.             if (tri.IsPointInsideAndAboveTriangle(modX, modY, modZ))
  118.             {
  119.                 double floorY = tri.GetHeightOnTriangle(modX, modZ);
  120.                 if (bestFloorY == null || floorY > bestFloorY)
  121.                 {
  122.                     bestFloorY = floorY;
  123.                     yNorm = tri.NormY;
  124.                 }
  125.             }
  126.         }
  127.  
  128.         if (bestFloorY.HasValue && bestFloorY.Value > state.Y - 3000)
  129.         {
  130.             (double test2X, double test2Z) = MoreMath.AddVectorToPoint(hSpeed / 4 * yNorm, angle, x, z);
  131.             double test2Y = bestFloorY.Value;
  132.  
  133.             double modTest2X = MoreMath.MaybeNegativeModulus(test2X, 65536);
  134.             double modTest2Y = MoreMath.MaybeNegativeModulus(test2Y, 65536);
  135.             double modTest2Z = MoreMath.MaybeNegativeModulus(test2Z, 65536);
  136.  
  137.             foreach (TriangleDataModel tri in allFloorTris)
  138.             {
  139.                 if (tri.IsPointInsideAndAboveTriangle(modTest2X, modTest2Y, modTest2Z))
  140.                 {
  141.                     return null; // would go to PU immediately after
  142.                 }
  143.             }
  144.  
  145.             return new MarioPuState(x, bestFloorY.Value, z, hSpeed, angle, yNorm, state, state.Index + 1);
  146.         }
  147.         return null;
  148.     }
  149.  
  150.     public class MarioPuState
  151.     {
  152.         public readonly double X;
  153.         public readonly double Y;
  154.         public readonly double Z;
  155.         public readonly double HSpeed;
  156.         public readonly double Angle;
  157.         public readonly double YNorm;
  158.         public readonly MarioPuState Predecessor;
  159.         public readonly int Index;
  160.  
  161.         public MarioPuState(double x, double y, double z, double hSpeed, double angle, double yNorm, MarioPuState predecessor, int index)
  162.         {
  163.             X = x;
  164.             Y = y;
  165.             Z = z;
  166.             HSpeed = hSpeed;
  167.             Angle = angle;
  168.             YNorm = yNorm;
  169.             Predecessor = predecessor;
  170.             Index = index;
  171.         }
  172.  
  173.         public int GetPuX()
  174.         {
  175.             return PuUtilities.GetPuIndex(X);
  176.         }
  177.  
  178.         public int GetPuZ()
  179.         {
  180.             return PuUtilities.GetPuIndex(Z);
  181.         }
  182.  
  183.         public string GetLineage()
  184.         {
  185.             double deltaY = Predecessor == null ? 0 : Y - Predecessor.Y;
  186.             string past = Predecessor == null ? "" : Predecessor.GetLineage();
  187.             string current = ToString() + " " + deltaY + "\r\n";
  188.             return past + current;
  189.         }
  190.  
  191.         public override string ToString()
  192.         {
  193.             return string.Format(
  194.                 "X={0} Y={1} Z={2} HSpeed={3} Angle={4}",
  195.                 (int)X, (int)Y, (int)Z, (int)HSpeed, Angle);
  196.         }
  197.     }
  198.  
  199.     public static List<double> GetSuccessiveHSpeeds(double hSpeed)
  200.     {
  201.         List<double> output = new List<double>();
  202.         for (int numJumps = 1; numJumps <= 3; numJumps++)
  203.         {
  204.             for (int numDusts = 0; numDusts <= numJumps * 3 + 3; numDusts++)
  205.             {
  206.                 double value = hSpeed * Math.Pow(0.8, numJumps) * Math.Pow(0.98, numDusts);
  207.                 if (value > -200_000) continue;
  208.                 output.Add(value);
  209.             }
  210.         }
  211.         return output;
  212.     }
  213.  
  214.     public static List<double> GetSuccessiveHSpeeds2(double hSpeed)
  215.     {
  216.         List<double> output = new List<double>();
  217.         for (int numJumps = 0; numJumps <= 4; numJumps++)
  218.         {
  219.             for (int numDusts = 0; numDusts <= numJumps * 3 + 3; numDusts++)
  220.             {
  221.                 double value = hSpeed * Math.Pow(0.8, numJumps) * Math.Pow(0.98, numDusts);
  222.                 if (value > -200_000) continue;
  223.                 output.Add(value);
  224.             }
  225.         }
  226.         return output;
  227.     }
  228.  
  229.     public static List<MarioPuState> GetSuccessiveStates(MarioPuState state)
  230.     {
  231.         List<double> hSpeeds = GetSuccessiveHSpeeds(state.HSpeed);
  232.         return hSpeeds.ConvertAll(
  233.             hSpeed => new MarioPuState(state.X, state.Y, state.Z, hSpeed, state.Angle, state.YNorm, state, state.Index));
  234.     }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement