Skip to content

Commit

Permalink
Added validation checks to prevent NRE's
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmightyLks committed May 23, 2021
1 parent bce1a64 commit 1165db5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
4 changes: 2 additions & 2 deletions HelperPlus/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
37 changes: 27 additions & 10 deletions HelperPlus/Services/RichTextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public string BuildRichText(Player player)
try
{
StringBuilder builder = new StringBuilder();
short appendedLines = 0;

builder.Append("<voffset=35em>");
if (_helperPlus.Config.Environment.Enabled)
{
Expand Down Expand Up @@ -162,29 +162,46 @@ private void AddEnvironmentSection(StringBuilder builder, Player player)
out RaycastHit raycastHit,
100f
);
Room targetRoom = Map.Get.Rooms.OrderBy(room => Vector3.Distance(raycastHit.point, room.Position)).FirstOrDefault();


builder.Append($"<size={TextSize}%>");

//builder.Append($"<margin-left=5em>{raycastHit.point}\n{raycastHit.point}\n<margin-left=1em>{raycastHit.point}\nTest");
if (_helperPlus.Config.Environment.DisplayTargetPosition)
{
Room targetRoom = Map.Get.Rooms.OrderBy(room => Vector3.Distance(raycastHit.point, room.Position)).FirstOrDefault();
builder.AppendLine($"Target Position: {(didRaycastHit ? raycastHit.point.ToString() : "None")}");
builder.AppendLine($"Target MapPoint: {(didRaycastHit ? new MapPoint(targetRoom, raycastHit.point).ToString() : "None")}");
bool isValidPlayer = player != null && player.RoleType != RoleType.Spectator && player.RoleType != RoleType.None;

string targetPosition = didRaycastHit ? raycastHit.point.ToString() : "None";
string targetMapPoint = didRaycastHit && isValidPlayer && targetRoom != null ? new MapPoint(targetRoom, raycastHit.point).ToString() : "None";

builder.AppendLine($"Target Position: {targetPosition}");
builder.AppendLine($"Target MapPoint: {targetMapPoint}");
}
if (_helperPlus.Config.Environment.DisplayTargetName)
{
builder.AppendLine($"Target Name: {(didRaycastHit ? raycastHit.transform.gameObject.name : "None")}");
string targetName = didRaycastHit ? raycastHit.transform.gameObject.name : "None";

builder.AppendLine($"Target Name: {targetName}");
}
if (_helperPlus.Config.Environment.DisplayPosition)
{
builder.AppendLine($"Player Position: {player.Position}");
builder.AppendLine($"Player MapPoint: {(didRaycastHit ? player.MapPoint.ToString() : "None")}");
bool isValidPlayer = player != null && player.RoleType != RoleType.Spectator && player.RoleType != RoleType.None;
string playerPosition = isValidPlayer ? player.Position.ToString() : "None";
string playerMapPoint = isValidPlayer ? player.MapPoint.ToString() : "None";

builder.AppendLine($"Player Position: {playerPosition}");
builder.AppendLine($"Player MapPoint: {playerMapPoint}");
}
if (_helperPlus.Config.Environment.DisplayCurrentRoom)
{
builder.AppendLine($"Current Room Name: {player.Room.RoomName}");
builder.AppendLine($"Current Room Type: {player.Room.RoomType}");
bool isValidPlayer = player != null && player.RoleType != RoleType.Spectator && player.RoleType != RoleType.None;
Room room = player?.Room;

string currentRoomName = (isValidPlayer && room != null ? player.Room.RoomName : "None");
string currentRoomType = (isValidPlayer && room != null ? player.Room.RoomType.ToString() : "None");

builder.AppendLine($"Current Room Name: {currentRoomName}");
builder.AppendLine($"Current Room Type: {currentRoomType}");
}
}
}
Expand Down

0 comments on commit 1165db5

Please sign in to comment.