Advertisement
sharkbait263

[BO2] HUD Elements

Jun 4th, 2014
1,239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 18.17 KB | None | 0 0
  1.        public static String centerString(string[] StringArray)
  2.         {
  3.             Int32 num3;
  4.             Int32 length = 0;
  5.             Int32 num2 = 0;
  6.             String str = "";
  7.             for (num3 = 0; num3 < StringArray.Length; num3++)
  8.             {
  9.                 if (StringArray[num3].Length > length)
  10.                 {
  11.                     length = StringArray[num3].Length;
  12.                 }
  13.             }
  14.             for (num3 = 0; num3 < StringArray.Length; num3++)
  15.             {
  16.                 str = "";
  17.                 if (StringArray[num3].Length < length)
  18.                 {
  19.                     num2 = length - StringArray[num3].Length;
  20.                     if (StringArray[num3].Contains("[{+"))
  21.                     {
  22.                         num2 += 13;
  23.                     }
  24.                     for (Int32 i = 0; i < num2; i++)
  25.                     {
  26.                         str = str + " ";
  27.                     }
  28.                 }
  29.                 StringArray[num3] = str + StringArray[num3];
  30.             }
  31.             String str2 = "";
  32.             for (num3 = 0; num3 < StringArray.Length; num3++)
  33.             {
  34.                 str2 = str2 + StringArray[num3] + "\n";
  35.             }
  36.             return ("^7" + str2);
  37.         }
  38.  
  39.         public static void ChangeAlpha(UInt32 elemIndex, Byte Alpha)
  40.         {
  41.             Lib.WriteByte((elemIndex + HudStruct.color) + 3, Alpha);
  42.         }
  43.  
  44.         public static void ChangeText(UInt32 elemIndex, String Text)
  45.         {
  46.             Lib.WriteInt16(elemIndex + HudStruct.text, G_LocalizedStringIndex(Text));
  47.         }
  48.  
  49.         public static void DestroyElement(UInt32 Element)
  50.         {
  51.             PS3.SetMemory(Element, new Byte[HudStruct.IndexSize]);
  52.         }
  53.  
  54.         public static void FadeOverTime(UInt32 elemIndex, Int16 Time, Byte R = 0, Byte G = 0, Byte B = 0, Byte A = 0)
  55.         {
  56.             Lib.WriteBytes(elemIndex + HudStruct.fromColor, Lib.ReadBytes(elemIndex + HudStruct.color, 4));
  57.             Lib.WriteInt16(elemIndex + HudStruct.fadeTime, Time);
  58.             Lib.WriteUInt32(elemIndex + HudStruct.fadeStartTime, GetLevelTime());
  59.             Lib.WriteBytes(elemIndex + HudStruct.color, new Byte[] { R, G, B, A });
  60.         }
  61.  
  62.         public static void FadeAlphaOverTime(UInt32 elemIndex, Int16 Time, Byte A = 0)
  63.         {
  64.             Byte[] RGB = Lib.ReadBytes(elemIndex + HudStruct.color, 3);
  65.  
  66.             Lib.WriteBytes(elemIndex + HudStruct.fromColor, Lib.ReadBytes(elemIndex + HudStruct.color, 4));
  67.             Lib.WriteInt16(elemIndex + HudStruct.fadeTime, Time);
  68.             Lib.WriteUInt32(elemIndex + HudStruct.fadeStartTime, GetLevelTime());
  69.             Lib.WriteBytes(elemIndex + HudStruct.color, new Byte[] { RGB[0], RGB[1], RGB[2], A });
  70.         }
  71.  
  72.         public static void FontScaleOverTime(UInt32 elemIndex, Double FontSize, Int16 time)
  73.         {
  74.             Lib.WriteSingle(elemIndex + HudStruct.fromFontScale, Lib.ReadSingle(elemIndex + HudStruct.FontSize));
  75.             Lib.WriteUInt32(elemIndex + HudStruct.fontScaleStartTime, GetLevelTime());
  76.             Lib.WriteInt16(elemIndex + HudStruct.fontScaleTime, time);
  77.             Lib.WriteSingle(elemIndex + HudStruct.FontSize, (Single) FontSize);
  78.         }
  79.  
  80.         public static Int16 G_LocalizedStringIndex(String Text)
  81.         {
  82.             return (Int16)RPC.Call(0x275D24, Text);
  83.         }
  84.  
  85.         public static UInt32 GetLevelTime()
  86.         {
  87.             return Lib.ReadUInt32(0x1608100 + 0x798);
  88.         }
  89.  
  90.         private static UInt32 HudElem_Alloc()
  91.         {
  92.             for (UInt32 i = 120; i < 1024; i++)
  93.             {
  94.                 UInt32 Index = HudStruct.G_Hudelems + (i * HudStruct.IndexSize);
  95.                 if (Lib.ReadByte(Index + HudStruct.type) == 0)
  96.                 {
  97.                     Lib.WriteBytes(Index, new Byte[0x88]);
  98.                     return Index;
  99.                 }
  100.             }
  101.             return 0;
  102.         }
  103.  
  104.         private static UInt32 Objective_Alloc()
  105.         {
  106.             for (UInt32 i = 3; i <= 31; i++)
  107.             {
  108.                 UInt32 Index = ObjStruct.ObjectiveIndex + (i * ObjStruct.ObjectiveIndexLength);
  109.                 if (Lib.ReadInt32(Index) == 0)
  110.                 {
  111.                     Lib.WriteBytes(Index, new Byte[0x30]);
  112.                     return Index;
  113.                 }
  114.             }
  115.             return 0;
  116.         }
  117.  
  118.  
  119.         public static void Huds_DestroyAll()
  120.         {
  121.             PS3.SetMemory(HudStruct.G_Hudelems + (60 * HudStruct.IndexSize), new Byte[HudStruct.IndexSize * 0x400]);
  122.         }
  123.  
  124.  
  125.         public static void Objective_DestroyAll()
  126.         {
  127.             Lib.WriteBytes(ObjStruct.ObjectiveIndex + (3 * ObjStruct.ObjectiveIndexLength), new Byte[ObjStruct.ObjectiveIndexLength * 31]);
  128.         }
  129.  
  130.         public static Int32 getMaterialIndex(String Material)
  131.         {
  132.             return (Int32)RPC.Call(0x276020, Material);
  133.         }
  134.  
  135.         public static void MoveOverTime(UInt32 elemIndex, Int16 time, Single x, Single y)
  136.         {
  137.             Lib.WriteSingle(elemIndex + HudStruct.fromX, Lib.ReadSingle(elemIndex));
  138.             Lib.WriteSingle(elemIndex + HudStruct.fromY, Lib.ReadSingle(elemIndex + HudStruct.Y));
  139.             Lib.WriteInt32(elemIndex + HudStruct.moveStartTime, (Int32)GetLevelTime());
  140.             Lib.WriteInt16(elemIndex + HudStruct.moveTime, time);
  141.             Lib.WriteSingle(elemIndex, x);
  142.             Lib.WriteSingle(elemIndex + HudStruct.Y, y);
  143.         }
  144.  
  145.         public static Int32[] RandomizeRGB()
  146.         {
  147.             Int32[] numArray = new Int32[4];
  148.             Random random = new Random();
  149.             numArray[0] = random.Next(0, 255);
  150.             numArray[1] = random.Next(0, 255);
  151.             numArray[2] = random.Next(0, 255);
  152.             numArray[3] = 255;
  153.             return numArray;
  154.         }
  155.  
  156.         public static Byte[] ReverseArray(Byte[] Arry)
  157.         {
  158.             Array.Reverse(Arry);
  159.             return Arry;
  160.         }
  161.  
  162.         public static void ScaleOverTime(UInt32 elemIndex, Int16 time, Int16 width, Int16 height)
  163.         {
  164.             Lib.WriteUInt32(elemIndex + HudStruct.scaleStartTime, GetLevelTime());
  165.             Lib.WriteInt32(elemIndex + HudStruct.fromHeight, Lib.ReadInt16(elemIndex + HudStruct.Width));
  166.             Lib.WriteInt32(elemIndex + HudStruct.fromWidth, Lib.ReadInt16(elemIndex + HudStruct.Height));
  167.             Lib.WriteInt16(elemIndex + HudStruct.Width, width);
  168.             Lib.WriteInt16(elemIndex + HudStruct.Height, height);
  169.             Lib.WriteInt16(elemIndex + HudStruct.scaleTime, time);
  170.         }
  171.  
  172.         public static UInt32 SetShader(Int32 clientIndex, Object Material, Int16 Width, Int16 Height, Single X, Single Y, UInt32 align = 0, Int32 r = 255, Int32 g = 255, Int32 b = 255, Int32 a = 255)
  173.         {
  174.             UInt32 Shader = HudElem_Alloc();
  175.             Lib.WriteByte(Shader + HudStruct.type, 8);//8 = Icon
  176.             if (Material is String)
  177.             { Functions.precacheShader((string)Material); Lib.WriteByte(Shader + HudStruct.materialIndex, Convert.ToByte(getMaterialIndex((String)Material))); }
  178.             if (Material is Int32)
  179.             { Lib.WriteByte(Shader + HudStruct.materialIndex, Convert.ToByte(Material)); }
  180.             Lib.WriteInt16(Shader + HudStruct.Height, Height);
  181.             Lib.WriteInt16(Shader + HudStruct.Width, Width);
  182.             if (align != 0)
  183.             { Lib.WriteByte(Shader + HudStruct.alignOrg, 5); Lib.WriteByte(Shader + HudStruct.alignScreen, Convert.ToByte(align)); }
  184.             else
  185.             { Lib.WriteSingle(Shader + HudStruct.X, X); Lib.WriteSingle(Shader + HudStruct.Y, Y); }
  186.             Lib.WriteInt32(Shader + HudStruct.clientOffset, clientIndex);
  187.             PS3.SetMemory(Shader + HudStruct.ui3dWindow, new Byte[] { 0xFF });
  188.             Lib.WriteBytes(Shader + HudStruct.color, new Byte[] { (Byte)r, (Byte)g, (Byte)b, (Byte)a });
  189.             return Shader;
  190.         }
  191.  
  192.         public static Int32 SetTimer(UInt32 elemIndex, Int32 Time = 60, String Direction = "Up", Boolean Tenths = true)
  193.         {
  194.             if (Lib.ReadByte(elemIndex + HudStruct.type) != 0x8 && Direction == "Up" && !Tenths)
  195.             { Lib.WriteByte(elemIndex + HudStruct.type, 0xA); }
  196.             if (Lib.ReadByte(elemIndex + HudStruct.type) != 0x8 && Direction == "Up" && Tenths)
  197.             { Lib.WriteByte(elemIndex + HudStruct.type, 0xC); }
  198.             if (Lib.ReadByte(elemIndex + HudStruct.type) != 0x8 && Direction == "Down" && !Tenths)
  199.             { Lib.WriteByte(elemIndex + HudStruct.type, 0x9); }
  200.             if (Lib.ReadByte(elemIndex + HudStruct.type) != 0x8 && Direction == "Down" && Tenths)
  201.             { Lib.WriteByte(elemIndex + HudStruct.type, 0xB); }
  202.  
  203.             if (Direction == "Up")
  204.             { Lib.WriteInt32(elemIndex + HudStruct.time, (Int32)GetLevelTime() - (Time * 1000)); return (Int32)GetLevelTime() - (Time * 1000); }
  205.             if (Direction == "Down")
  206.             { Lib.WriteInt32(elemIndex + HudStruct.time, (Int32)GetLevelTime() + (Time * 1000)); return (Int32)GetLevelTime() + (Time * 1000); }
  207.             return (Int32)GetLevelTime() + (Time * 1000);
  208.         }
  209.  
  210.         public static Int32 SetClock(UInt32 elemIndex, Int32 Duration = 60, Int32 Time = 60, String Direction = "Up")
  211.         {
  212.             if (Lib.ReadByte(elemIndex + HudStruct.type) != 0x1 && Direction == "Up")
  213.             { Lib.WriteByte(elemIndex + HudStruct.type, 0xE); }
  214.             if (Lib.ReadByte(elemIndex + HudStruct.type) != 0x1 && Direction == "Down")
  215.             { Lib.WriteByte(elemIndex + HudStruct.type, 0xD); }
  216.             if (Direction == "Up")
  217.             {
  218.                 Lib.WriteInt32(elemIndex + HudStruct.duration, Duration * 1000);
  219.                 Lib.WriteInt32(elemIndex + HudStruct.time, (Int32)GetLevelTime() - (Time * 1000));
  220.                 return (Int32)GetLevelTime() - (Time * 1000);
  221.             }
  222.             if (Direction == "Down")
  223.             {
  224.                 Lib.WriteInt32(elemIndex + HudStruct.duration, Duration * 1000);
  225.                 Lib.WriteInt32(elemIndex + HudStruct.time, (Int32)GetLevelTime() + (Time * 1000));
  226.                 return (Int32)GetLevelTime() + (Time * 1000);
  227.             }
  228.             return 0;
  229.         }
  230.  
  231.         public static UInt32 SetValue(UInt32 elemIndex, Single Value)
  232.         {
  233.             Lib.WriteByte(elemIndex + HudStruct.type, 7);
  234.             Lib.WriteSingle(elemIndex + HudStruct.value, Value);
  235.             return (UInt32)Value;
  236.         }
  237.  
  238.         public static UInt32 SetObjective(Int16 onEntity = 0x3FF, Object Material = null, Single[] Position = null)
  239.         {
  240.             UInt32 Objective = Objective_Alloc();
  241.             Lib.WriteInt32(Objective, 1);
  242.             Lib.WriteSingle(Objective + ObjStruct.Origin, Position);
  243.             Lib.WriteInt16(Objective + ObjStruct.targetEntNum, onEntity);
  244.             if (Material is String)
  245.             { Functions.precacheShader((string)Material); Lib.WriteInt32(Objective + ObjStruct.MaterialIndex, (Int16)getMaterialIndex((String)Material)); }
  246.             if (Material is Int32)
  247.             { Lib.WriteInt32(Objective + ObjStruct.MaterialIndex, (Int32)Material); }
  248.             return Objective;
  249.         }
  250.  
  251.         public static UInt32 SetWaypoint(Int32 clientIndex = 0x3FF, Int16 onEntity = 0x3FF, Object Material = null, Single[] Position = null, Boolean DirectionalArrows = true, Int32 R = 255, Int32 G = 255, Int32 B = 255, Int32 A = 255)
  252.         {
  253.             UInt32 Waypoint = HudElem_Alloc();
  254.             Lib.WriteByte(Waypoint + HudStruct.type, 0xF);//0xF = Waypoint
  255.             if (Material is String && DirectionalArrows)
  256.             { Functions.precacheShader((string)Material); Lib.WriteByte(Waypoint + HudStruct.offscreenMaterialIndex, Convert.ToByte(getMaterialIndex((String)Material))); }
  257.             if (Material is Int32 && DirectionalArrows)
  258.             { Lib.WriteByte(Waypoint + HudStruct.offscreenMaterialIndex, Convert.ToByte(Material)); }
  259.             if (!DirectionalArrows)
  260.             { SetWaypointNoArrows(Waypoint, Material); }
  261.             Lib.WriteSingle(Waypoint, Position);
  262.             Lib.WriteInt32(Waypoint + HudStruct.clientOffset, clientIndex);
  263.             Lib.WriteInt16(Waypoint + HudStruct.targetEntNum, onEntity);
  264.             Lib.WriteByte(Waypoint + HudStruct.ui3dWindow, 0xFF);
  265.             Lib.WriteBytes(Waypoint + HudStruct.color, new Byte[] { (Byte)R, (Byte)G, (Byte)B, (Byte)A });
  266.             return Waypoint;
  267.         }
  268.  
  269.         public static void SetWaypointNoArrows(UInt32 Waypoint, Object Material = null)
  270.         {
  271.             Lib.WriteByte(Waypoint + HudStruct.offscreenMaterialIndex, 0);
  272.             Lib.WriteSingle(Waypoint + HudStruct.Height, 2.3f);
  273.             if (Material is String)
  274.             { Functions.precacheShader((string)Material); Lib.WriteByte(Waypoint + HudStruct.materialIndex, Convert.ToByte(getMaterialIndex((String)Material))); }
  275.             if (Material is Int32)
  276.             { Lib.WriteByte(Waypoint + HudStruct.materialIndex, Convert.ToByte(Material)); }
  277.         }
  278.  
  279.         public static UInt32 SetWaypointText(UInt32 Waypoint, String TextString, Int32 Font, Single FontSize)
  280.         {
  281.             Lib.WriteSingle(Waypoint + HudStruct.FontSize, FontSize);
  282.             Lib.WriteByte(Waypoint + HudStruct.Font, Convert.ToByte(Font));
  283.             Lib.WriteInt16(Waypoint + HudStruct.label, G_LocalizedStringIndex(TextString));
  284.             return 0;
  285.         }
  286.  
  287.         public static UInt32 SetText(Int32 clientIndex, String TextString, Int32 Font, Single FontSize, Single X, Single Y, UInt32 align = 0, Int32 r = 255, Int32 g = 255, Int32 b = 255, Int32 a = 255, Int32 glowr = 255, Int32 glowg = 255, Int32 glowb = 255, Int32 glowa = 0)
  288.         {
  289.             UInt32 Text = HudElem_Alloc();
  290.             Lib.WriteByte(Text + HudStruct.type, 1);//1 = Text
  291.             Lib.WriteSingle(Text + HudStruct.FontSize, FontSize);
  292.             Lib.WriteByte(Text + HudStruct.Font, Convert.ToByte(Font));
  293.             if (align != 0)
  294.             { Lib.WriteByte(Text + HudStruct.alignOrg, 5); Lib.WriteByte(Text + HudStruct.alignScreen, Convert.ToByte(align)); }
  295.             else
  296.             { Lib.WriteSingle(Text + HudStruct.X, X); Lib.WriteSingle(Text + HudStruct.Y, Y); }
  297.             Lib.WriteInt32(Text + HudStruct.clientOffset, clientIndex);
  298.             Lib.WriteInt16(Text + HudStruct.text, G_LocalizedStringIndex(TextString));
  299.             Lib.WriteBytes(Text + HudStruct.color, new Byte[] { (Byte)r, (Byte)g, (Byte)b, (Byte)a });
  300.             Lib.WriteBytes(Text + HudStruct.glowColor, new Byte[] { (Byte)glowr, (Byte)glowg, (Byte)glowb, (Byte)glowa });
  301.             Lib.WriteByte(Text + HudStruct.ui3dWindow, 0xFF);
  302.             return Text;
  303.         }
  304.  
  305.         public static UInt32 SetTypewriter(Int32 clientIndex, String Text, Int32 Font, Single FontSize, Single X, Single Y, UInt32 align, UInt32 Type = 0, UInt16 Lettertime = 200, UInt16 fxDecayStartTime = 7000, UInt16 fxDecayDuration = 1000, Int32 r = 255, Int32 g = 255, Int32 b = 255, Int32 a = 255, Int32 glowr = 255, Int32 glowg = 255, Int32 glowb = 255, Int32 glowa = 0)
  306.         {
  307.             UInt32 elemIndex = SetText(clientIndex, Text, Font, FontSize, X, Y, align, r, g, b, a, glowr, glowg, glowb, glowa);
  308.             Lib.WriteUInt32(elemIndex + HudStruct.flags, Type);
  309.             Lib.WriteUInt32(elemIndex + HudStruct.fxBirthTime, GetLevelTime());
  310.             Lib.WriteUInt16(elemIndex + HudStruct.fxLetterTime, Lettertime);
  311.             Lib.WriteUInt16(elemIndex + HudStruct.fxDecayStartTime, fxDecayStartTime);
  312.             Lib.WriteUInt16(elemIndex + HudStruct.fxDecayDuration, fxDecayDuration);
  313.             return elemIndex;
  314.         }
  315.  
  316.         public class ObjStruct
  317.         {
  318.             public static UInt32
  319.             ObjectiveIndex = 0x1608194,
  320.             ObjectiveIndexLength = 0x30,
  321.             Origin = 0x04,
  322.             X = 0x04,
  323.             Y = 0x08,
  324.             Z = 0x0C,
  325.             targetEntNum = 0x10,
  326.             MaterialIndex = 0x1C,
  327.             State = 0x28,
  328.             Team = 0x2D;
  329.         }
  330.  
  331.         public class HudStruct
  332.         {
  333.             public static UInt32
  334.             G_Hudelems = 0x15DDB00,
  335.             IndexSize = 0x88,
  336.             X = 0x00,
  337.             Y = 0x04,
  338.             Z = 0x08,
  339.             FontSize = 0xC,
  340.             fromFontScale = 0x10,
  341.             fontScaleStartTime = 0x14,
  342.             color = 0x18,
  343.             fromColor = 0x1C,
  344.             fadeStartTime = 0x20,
  345.             scaleStartTime = 0x24,
  346.             fromX = 0x28,
  347.             fromY = 0x2C,
  348.             moveStartTime = 0x30,
  349.             time = 0x34,
  350.             duration = 0x38,
  351.             value = 0x3C,
  352.             sort = 0x40,
  353.             glowColor = 0x44,
  354.             fxBirthTime = 0x48,
  355.             flags = 0x4C,
  356.             targetEntNum = 0x50,
  357.             fontScaleTime = 0x52,
  358.             fadeTime = 0x54,
  359.             label = 0x56,
  360.             Width = 0x58,
  361.             Height = 0x5A,
  362.             fromWidth = 0x5C,
  363.             fromHeight = 0x5E,
  364.             scaleTime = 0x60,
  365.             moveTime = 0x62,
  366.             text = 0x64,
  367.             fxLetterTime = 0x66,
  368.             fxDecayStartTime = 0x68,
  369.             fxDecayDuration = 0x6A,
  370.             fxRedactDecayStartTime = 0x6C,
  371.             fxRedactDecayDuration = 0x6E,
  372.             type = 0x70,
  373.             Font = 0x71,
  374.             alignOrg = 0x72,
  375.             alignScreen = 0x73,
  376.             materialIndex = 0x74,
  377.             offscreenMaterialIndex = 0x75,
  378.             fromAlignOrg = 0x76,
  379.             fromAlignScreen = 0x77,
  380.             soundID = 0x78,
  381.             ui3dWindow = 0x79,
  382.             flag2 = 0x7A,
  383.             clientOffset = 0x7C,
  384.             team = 0x80,
  385.             abilityFlag = 0x84;
  386.  
  387.             public class Align
  388.             {
  389.                 public static UInt32
  390.                 TOP_RIGHT = 0xA8,
  391.                 TOP_LEFT = 0x88,
  392.                 TOP_CENTERED = 0x78,
  393.                 BOTTOM_RIGHT = 0xAA,
  394.                 BOTTOM_LEFT = 0x8A,
  395.                 BOTTOM_CENTER = 0x9A,
  396.                 CENTER_MIDDLE = 0x92,
  397.                 CENTER_LEFT = 0x82,
  398.                 CENTER_RIGHT = 0xA2;
  399.             }
  400.             public class Typewriter
  401.             {
  402.                 public static UInt32
  403.                 Normal = 0x800,
  404.                 Classic = 0x4000;
  405.             }
  406.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement