Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Utils.cs
Go to the documentation of this file.
1using System;
7using System.IO;
8using System.Linq;
13using Microsoft.Xna.Framework.Graphics.PackedVector;
14using Microsoft.Xna.Framework.Input;
15using ReLogic.Content;
17using ReLogic.OS;
21using Terraria.UI;
25
26namespace Terraria;
27
28public static class Utils
29{
30 public delegate bool TileActionAttempt(int x, int y);
31
33
35
36 public struct ChaseResults
37 {
39
41
42 public float InterceptionTime;
43
45 }
46
47 public const long MaxCoins = 999999999L;
48
50
51 private static Regex _substitutionRegex = new Regex("{(\\?(?:!)?)?([a-zA-Z][\\w\\.]*)}", RegexOptions.Compiled);
52
53 private const ulong RANDOM_MULTIPLIER = 25214903917uL;
54
55 private const ulong RANDOM_ADD = 11uL;
56
57 private const ulong RANDOM_MASK = 281474976710655uL;
58
60 {
62 }
63
64 public static double Lerp(double value1, double value2, double amount)
65 {
66 return value1 + (value2 - value1) * amount;
67 }
68
69 public static Vector2 Round(Vector2 input)
70 {
71 return new Vector2((float)Math.Round(input.X), (float)Math.Round(input.Y));
72 }
73
74 public static bool IsPowerOfTwo(int x)
75 {
76 if (x != 0)
77 {
78 return (x & (x - 1)) == 0;
79 }
80 return false;
81 }
82
83 public static float SmoothStep(float min, float max, float x)
84 {
85 return MathHelper.Clamp((x - min) / (max - min), 0f, 1f);
86 }
87
88 public static double SmoothStep(double min, double max, double x)
89 {
90 return Clamp((x - min) / (max - min), 0.0, 1.0);
91 }
92
93 public static float UnclampedSmoothStep(float min, float max, float x)
94 {
95 return (x - min) / (max - min);
96 }
97
98 public static double UnclampedSmoothStep(double min, double max, double x)
99 {
100 return (x - min) / (max - min);
101 }
102
104 {
105 string text = null;
106 string text2 = "";
108 for (int i = 0; i < args.Length; i++)
109 {
110 if (args[i].Length == 0)
111 {
112 continue;
113 }
114 if (args[i][0] == '-' || args[i][0] == '+')
115 {
116 if (text != null)
117 {
118 dictionary.Add(text.ToLower(), text2);
119 text2 = "";
120 }
121 text = args[i];
122 text2 = "";
123 }
124 else
125 {
126 if (text2 != "")
127 {
128 text2 += " ";
129 }
130 text2 += args[i];
131 }
132 }
133 if (text != null)
134 {
135 dictionary.Add(text.ToLower(), text2);
136 text2 = "";
137 }
138 return dictionary;
139 }
140
141 public static void Swap<T>(ref T t1, ref T t2)
142 {
143 T val = t1;
144 t1 = t2;
145 t2 = val;
146 }
147
148 public static T Clamp<T>(T value, T min, T max) where T : IComparable<T>
149 {
150 if (value.CompareTo(max) > 0)
151 {
152 return max;
153 }
154 if (value.CompareTo(min) < 0)
155 {
156 return min;
157 }
158 return value;
159 }
160
161 public static float Turn01ToCyclic010(float value)
162 {
163 return 1f - ((float)Math.Cos(value * ((float)Math.PI * 2f)) * 0.5f + 0.5f);
164 }
165
166 public static float PingPongFrom01To010(float value)
167 {
168 value %= 1f;
169 if (value < 0f)
170 {
171 value += 1f;
172 }
173 if (value >= 0.5f)
174 {
175 return 2f - value * 2f;
176 }
177 return value * 2f;
178 }
179
180 public static float MultiLerp(float percent, params float[] floats)
181 {
182 float num = 1f / ((float)floats.Length - 1f);
183 float num2 = num;
184 int num3 = 0;
185 while (percent / num2 > 1f && num3 < floats.Length - 2)
186 {
187 num2 += num;
188 num3++;
189 }
190 return MathHelper.Lerp(floats[num3], floats[num3 + 1], (percent - num * (float)num3) / num);
191 }
192
193 public static float WrappedLerp(float value1, float value2, float percent)
194 {
195 float num = percent * 2f;
196 if (num > 1f)
197 {
198 num = 2f - num;
199 }
200 return MathHelper.Lerp(value1, value2, num);
201 }
202
203 public static float GetLerpValue(float from, float to, float t, bool clamped = false)
204 {
205 if (clamped)
206 {
207 if (from < to)
208 {
209 if (t < from)
210 {
211 return 0f;
212 }
213 if (t > to)
214 {
215 return 1f;
216 }
217 }
218 else
219 {
220 if (t < to)
221 {
222 return 1f;
223 }
224 if (t > from)
225 {
226 return 0f;
227 }
228 }
229 }
230 return (t - from) / (to - from);
231 }
232
233 public static float Remap(float fromValue, float fromMin, float fromMax, float toMin, float toMax, bool clamped = true)
234 {
236 }
237
238 public static void ClampWithinWorld(ref int minX, ref int minY, ref int maxX, ref int maxY, bool lastValuesInclusiveToIteration = false, int fluffX = 0, int fluffY = 0)
239 {
240 int num = (lastValuesInclusiveToIteration ? 1 : 0);
245 }
246
248 {
249 ChaseResults result = default(ChaseResults);
251 {
253 result2.InterceptionHappens = true;
254 result2.InterceptionPosition = chaserPosition;
255 result2.InterceptionTime = 0f;
256 result2.ChaserVelocity = Vector2.Zero;
257 return result2;
258 }
259 if (chaserSpeed <= 0f)
260 {
261 return default(ChaseResults);
262 }
264 float num = value.Length();
265 float num2 = runnerVelocity.Length();
266 if (num2 == 0f)
267 {
268 result.InterceptionTime = num / chaserSpeed;
269 result.InterceptionPosition = runnerPosition;
270 }
271 else
272 {
273 float a = chaserSpeed * chaserSpeed - num2 * num2;
274 float b = 2f * Vector2.Dot(value, runnerVelocity);
275 float c = (0f - num) * num;
277 {
278 return default(ChaseResults);
279 }
280 if (result3 < 0f && result4 < 0f)
281 {
282 return default(ChaseResults);
283 }
284 if (result3 > 0f && result4 > 0f)
285 {
286 result.InterceptionTime = Math.Min(result3, result4);
287 }
288 else
289 {
290 result.InterceptionTime = Math.Max(result3, result4);
291 }
292 result.InterceptionPosition = runnerPosition + runnerVelocity * result.InterceptionTime;
293 }
294 result.ChaserVelocity = (result.InterceptionPosition - chaserPosition) / result.InterceptionTime;
295 result.InterceptionHappens = true;
296 return result;
297 }
298
305
306 public static bool SolveQuadratic(float a, float b, float c, out float result1, out float result2)
307 {
308 float num = b * b - 4f * a * c;
309 result1 = 0f;
310 result2 = 0f;
311 if (num > 0f)
312 {
313 result1 = (0f - b + (float)Math.Sqrt(num)) / (2f * a);
314 result2 = (0f - b - (float)Math.Sqrt(num)) / (2f * a);
315 return true;
316 }
317 if (num < 0f)
318 {
319 return false;
320 }
321 result1 = (result2 = (0f - b + (float)Math.Sqrt(num)) / (2f * a));
322 return true;
323 }
324
325 public static double GetLerpValue(double from, double to, double t, bool clamped = false)
326 {
327 if (clamped)
328 {
329 if (from < to)
330 {
331 if (t < from)
332 {
333 return 0.0;
334 }
335 if (t > to)
336 {
337 return 1.0;
338 }
339 }
340 else
341 {
342 if (t < to)
343 {
344 return 1.0;
345 }
346 if (t > from)
347 {
348 return 0.0;
349 }
350 }
351 }
352 return (t - from) / (to - from);
353 }
354
356 {
357 if (Main.dayTime)
358 {
359 return 4.5f + (float)(Main.time / 54000.0) * 15f;
360 }
361 return 19.5f + (float)(Main.time / 32400.0) * 9f;
362 }
363
368
370 {
371 return new Vector2(0f, -1f).RotatedBy(timeFrom0To24 / 24f * ((float)Math.PI * 2f));
372 }
373
374 public static string[] ConvertMonoArgsToDotNet(string[] brokenArgs)
375 {
377 string text = "";
378 for (int i = 0; i < brokenArgs.Length; i++)
379 {
380 if (brokenArgs[i].StartsWith("-"))
381 {
382 if (text != "")
383 {
385 text = "";
386 }
387 else
388 {
389 arrayList.Add("");
390 }
392 }
393 else
394 {
395 if (text != "")
396 {
397 text += " ";
398 }
399 text += brokenArgs[i];
400 }
401 }
403 string[] array = new string[arrayList.Count];
405 return array;
406 }
407
408 public static T Max<T>(params T[] args) where T : IComparable
409 {
410 T result = args[0];
411 for (int i = 1; i < args.Length; i++)
412 {
413 if (result.CompareTo(args[i]) < 0)
414 {
415 result = args[i];
416 }
417 }
418 return result;
419 }
420
422 {
423 Vector2 vector = rect.TopLeft();
424 Vector2 vector2 = rect.TopRight();
425 Vector2 vector3 = rect.BottomLeft();
426 Vector2 vector4 = rect.BottomRight();
427 if (lineStart.Between(vector, vector4) || lineEnd.Between(vector, vector4))
428 {
429 return 0f;
430 }
431 float value = vector.Distance(vector.ClosestPointOnLine(lineStart, lineEnd));
432 float value2 = vector2.Distance(vector2.ClosestPointOnLine(lineStart, lineEnd));
433 float value3 = vector3.Distance(vector3.ClosestPointOnLine(lineStart, lineEnd));
434 float value4 = vector4.Distance(vector4.ClosestPointOnLine(lineStart, lineEnd));
436 }
437
439 {
443 foreach (TextSnippet textSnippet in array)
444 {
445 string[] array2 = textSnippet.Text.Split('\n');
446 for (int j = 0; j < array2.Length - 1; j++)
447 {
448 list2.Add(textSnippet.CopyMorph(array2[j]));
449 list.Add(list2);
450 list2 = new List<TextSnippet>();
451 }
452 list2.Add(textSnippet.CopyMorph(array2[array2.Length - 1]));
453 }
454 list.Add(list2);
455 if (maxWidth != -1)
456 {
457 for (int k = 0; k < list.Count; k++)
458 {
460 float num = 0f;
461 for (int l = 0; l < list3.Count; l++)
462 {
463 float stringLength = list3[l].GetStringLength(font);
464 if (stringLength + num > (float)maxWidth)
465 {
466 int num2 = maxWidth - (int)num;
467 if (num > 0f)
468 {
469 num2 -= 16;
470 }
471 int num3 = Math.Min(list3[l].Text.Length, num2 / 8);
472 if (num3 < 0)
473 {
474 num3 = 0;
475 }
476 string[] array3 = list3[l].Text.Split(' ');
477 int num4 = num3;
478 if (array3.Length > 1)
479 {
480 num4 = 0;
481 for (int m = 0; m < array3.Length; m++)
482 {
483 bool flag = num4 == 0;
484 if (!(num4 + array3[m].Length <= num3 || flag))
485 {
486 break;
487 }
488 num4 += array3[m].Length + 1;
489 }
490 if (num4 > num3)
491 {
492 num4 = num3;
493 }
494 }
495 string newText = list3[l].Text.Substring(0, num4);
496 string newText2 = list3[l].Text.Substring(num4);
497 list2 = new List<TextSnippet> { list3[l].CopyMorph(newText2) };
498 for (int n = l + 1; n < list3.Count; n++)
499 {
500 list2.Add(list3[n]);
501 }
502 list3[l] = list3[l].CopyMorph(newText);
503 list[k] = list[k].Take(l + 1).ToList();
504 list.Insert(k + 1, list2);
505 break;
506 }
507 num += stringLength;
508 }
509 num = 0f;
510 }
511 }
512 if (maxLines != -1)
513 {
514 while (list.Count > maxLines)
515 {
516 list.RemoveAt(maxLines);
517 }
518 }
519 return list;
520 }
521
522 public static string[] WordwrapString(string text, DynamicSpriteFont font, int maxWidth, int maxLines, out int lineAmount)
523 {
524 string[] array = new string[maxLines];
525 int num = 0;
526 List<string> list = new List<string>(text.Split('\n'));
527 List<string> list2 = new List<string>(list[0].Split(' '));
528 for (int i = 1; i < list.Count && i < maxLines; i++)
529 {
530 list2.Add("\n");
531 list2.AddRange(list[i].Split(' '));
532 }
533 bool flag = true;
534 while (list2.Count > 0)
535 {
536 string text2 = list2[0];
537 string text3 = " ";
538 if (list2.Count == 1)
539 {
540 text3 = "";
541 }
542 if (text2 == "\n")
543 {
544 array[num++] += text2;
545 flag = true;
546 if (num >= maxLines)
547 {
548 break;
549 }
550 list2.RemoveAt(0);
551 }
552 else if (flag)
553 {
554 if (font.MeasureString(text2).X > (float)maxWidth)
555 {
556 string text4 = text2[0].ToString() ?? "";
557 int num2 = 1;
558 while (font.MeasureString(text4 + text2[num2] + "-").X <= (float)maxWidth)
559 {
560 text4 += text2[num2++];
561 }
562 text4 += "-";
563 array[num++] = text4 + " ";
564 if (num >= maxLines)
565 {
566 break;
567 }
568 list2.RemoveAt(0);
569 list2.Insert(0, text2.Substring(num2));
570 }
571 else
572 {
573 ref string reference = ref array[num];
575 flag = false;
576 list2.RemoveAt(0);
577 }
578 }
579 else if (font.MeasureString(array[num] + text2).X > (float)maxWidth)
580 {
581 num++;
582 if (num >= maxLines)
583 {
584 break;
585 }
586 flag = true;
587 }
588 else
589 {
590 ref string reference2 = ref array[num];
592 flag = false;
593 list2.RemoveAt(0);
594 }
595 }
596 lineAmount = num;
597 if (lineAmount == maxLines)
598 {
599 lineAmount--;
600 }
601 return array;
602 }
603
605 {
606 return new Rectangle((int)(center.X - size.X / 2f), (int)(center.Y - size.Y / 2f), (int)size.X, (int)size.Y);
607 }
608
610 {
611 if (elipseSizes == Vector2.Zero)
612 {
613 return Vector2.Zero;
614 }
615 if (angleVector == Vector2.Zero)
616 {
617 return Vector2.Zero;
618 }
619 angleVector.Normalize();
621 vector = Vector2.One / vector;
623 angleVector.Normalize();
624 return angleVector * elipseSizes / 2f;
625 }
626
627 public static bool FloatIntersect(float r1StartX, float r1StartY, float r1Width, float r1Height, float r2StartX, float r2StartY, float r2Width, float r2Height)
628 {
630 {
631 return false;
632 }
633 return true;
634 }
635
636 public static long CoinsCount(out bool overFlowing, Item[] inv, params int[] ignoreSlots)
637 {
639 long num = 0L;
640 for (int i = 0; i < inv.Length; i++)
641 {
642 if (!list.Contains(i))
643 {
644 switch (inv[i].type)
645 {
646 case 71:
647 num += inv[i].stack;
648 break;
649 case 72:
650 num += (long)inv[i].stack * 100L;
651 break;
652 case 73:
653 num += (long)inv[i].stack * 10000L;
654 break;
655 case 74:
656 num += (long)inv[i].stack * 1000000L;
657 break;
658 }
659 }
660 }
661 overFlowing = false;
662 return num;
663 }
664
665 public static int[] CoinsSplit(long count)
666 {
667 int[] array = new int[4];
668 long num = 0L;
669 long num2 = 1000000L;
670 for (int num3 = 3; num3 >= 0; num3--)
671 {
672 array[num3] = (int)((count - num) / num2);
673 num += array[num3] * num2;
674 num2 /= 100;
675 }
676 return array;
677 }
678
679 public static long CoinsCombineStacks(out bool overFlowing, params long[] coinCounts)
680 {
681 long num = 0L;
682 foreach (long num2 in coinCounts)
683 {
684 num += num2;
685 if (num >= 999999999)
686 {
687 overFlowing = true;
688 return 999999999L;
689 }
690 }
691 overFlowing = false;
692 return num;
693 }
694
695 public static void PoofOfSmoke(Vector2 position)
696 {
697 int num = Main.rand.Next(3, 7);
698 for (int i = 0; i < num; i++)
699 {
700 int num2 = Gore.NewGore(position, (Main.rand.NextFloat() * ((float)Math.PI * 2f)).ToRotationVector2() * new Vector2(2f, 0.7f) * 0.7f, Main.rand.Next(11, 14));
701 Main.gore[num2].scale = 0.7f;
702 Main.gore[num2].velocity *= 0.5f;
703 }
704 for (int j = 0; j < 10; j++)
705 {
706 Dust obj = Main.dust[Dust.NewDust(position, 14, 14, 16, 0f, 0f, 100, default(Color), 1.5f)];
707 obj.position += new Vector2(5f);
708 obj.velocity = (Main.rand.NextFloat() * ((float)Math.PI * 2f)).ToRotationVector2() * new Vector2(2f, 0.7f) * 0.7f * (0.5f + 0.5f * Main.rand.NextFloat());
709 }
710 }
711
716
717 public static string PrettifyPercentDisplay(float percent, string originalFormat)
718 {
719 return percent.ToString(originalFormat, CultureInfo.InvariantCulture).TrimEnd('0', '%', ' ').TrimEnd('.', ' ')
720 .TrimStart('0', ' ') + "%";
721 }
722
723 public static void TrimTextIfNeeded(ref string text, DynamicSpriteFont font, float scale, float maxWidth)
724 {
725 int num = 0;
726 Vector2 vector = font.MeasureString(text) * scale;
727 while (vector.X > maxWidth)
728 {
729 text = text.Substring(0, text.Length - 1);
730 num++;
731 vector = font.MeasureString(text) * scale;
732 }
733 if (num > 0)
734 {
735 text = text.Substring(0, text.Length - 1) + "…";
736 }
737 }
738
739 public static string FormatWith(string original, object obj)
740 {
743 {
744 if (match.Groups[1].Length != 0)
745 {
746 return "";
747 }
748 string name = match.Groups[2].ToString();
750 return (propertyDescriptor == null) ? "" : (propertyDescriptor.GetValue(obj) ?? "").ToString();
751 });
752 }
753
754 public static bool TryCreatingDirectory(string folderPath)
755 {
757 {
758 return true;
759 }
760 try
761 {
763 return true;
764 }
765 catch (Exception exception)
766 {
768 return false;
769 }
770 }
771
772 public static void OpenFolder(string folderPath)
773 {
775 {
776 if (Platform.IsLinux)
777 {
779 {
780 FileName = "open-folder",
781 Arguments = folderPath,
782 UseShellExecute = true,
783 CreateNoWindow = true
784 });
785 }
786 else
787 {
789 }
790 }
791 }
792
793 public static byte[] ToByteArray(this string str)
794 {
795 byte[] array = new byte[str.Length * 2];
796 Buffer.BlockCopy(str.ToCharArray(), 0, array, 0, array.Length);
797 return array;
798 }
799
800 public static float NextFloat(this UnifiedRandom r)
801 {
802 return (float)r.NextDouble();
803 }
804
805 public static float NextFloatDirection(this UnifiedRandom r)
806 {
807 return (float)r.NextDouble() * 2f - 1f;
808 }
809
810 public static float NextFloat(this UnifiedRandom random, FloatRange range)
811 {
812 return random.NextFloat() * (range.Maximum - range.Minimum) + range.Minimum;
813 }
814
815 public static T NextFromList<T>(this UnifiedRandom random, params T[] objs)
816 {
817 return objs[random.Next(objs.Length)];
818 }
819
820 public static T NextFromCollection<T>(this UnifiedRandom random, List<T> objs)
821 {
822 return objs[random.Next(objs.Count)];
823 }
824
825 public static int Next(this UnifiedRandom random, IntRange range)
826 {
827 return random.Next(range.Minimum, range.Maximum + 1);
828 }
829
830 public static Vector2 NextVector2Square(this UnifiedRandom r, float min, float max)
831 {
832 return new Vector2((max - min) * (float)r.NextDouble() + min, (max - min) * (float)r.NextDouble() + min);
833 }
834
836 {
837 return new Vector2((float)rect.X + r.NextFloat() * (float)rect.Width, (float)rect.Y + r.NextFloat() * (float)rect.Height);
838 }
839
840 public static Vector2 NextVector2Unit(this UnifiedRandom r, float startRotation = 0f, float rotationRange = (float)Math.PI * 2f)
841 {
842 return (startRotation + rotationRange * r.NextFloat()).ToRotationVector2();
843 }
844
846 {
847 return r.NextVector2Unit() * new Vector2(circleHalfWidth, circleHalfHeight) * r.NextFloat();
848 }
849
851 {
852 return r.NextVector2Unit() * new Vector2(circleHalfWidth, circleHalfHeight);
853 }
854
855 public static int Width(this Asset<Texture2D> asset)
856 {
857 if (!asset.IsLoaded)
858 {
859 return 0;
860 }
861 return asset.Value.Width;
862 }
863
864 public static int Height(this Asset<Texture2D> asset)
865 {
866 if (!asset.IsLoaded)
867 {
868 return 0;
869 }
870 return asset.Value.Height;
871 }
872
873 public static Rectangle Frame(this Asset<Texture2D> tex, int horizontalFrames = 1, int verticalFrames = 1, int frameX = 0, int frameY = 0, int sizeOffsetX = 0, int sizeOffsetY = 0)
874 {
875 if (!tex.IsLoaded)
876 {
877 return Rectangle.Empty;
878 }
879 return tex.Value.Frame(horizontalFrames, verticalFrames, frameX, frameY, sizeOffsetX, sizeOffsetY);
880 }
881
882 public static Rectangle OffsetSize(this Rectangle rect, int xSize, int ySize)
883 {
884 rect.Width += xSize;
885 rect.Height += ySize;
886 return rect;
887 }
888
889 public static Vector2 Size(this Asset<Texture2D> tex)
890 {
891 if (!tex.IsLoaded)
892 {
893 return Vector2.Zero;
894 }
895 return tex.Value.Size();
896 }
897
898 public static Rectangle Frame(this Texture2D tex, int horizontalFrames = 1, int verticalFrames = 1, int frameX = 0, int frameY = 0, int sizeOffsetX = 0, int sizeOffsetY = 0)
899 {
900 int num = tex.Width / horizontalFrames;
901 int num2 = tex.Height / verticalFrames;
902 return new Rectangle(num * frameX, num2 * frameY, num + sizeOffsetX, num2 + sizeOffsetY);
903 }
904
905 public static Vector2 OriginFlip(this Rectangle rect, Vector2 origin, SpriteEffects effects)
906 {
907 if (effects.HasFlag(SpriteEffects.FlipHorizontally))
908 {
909 origin.X = (float)rect.Width - origin.X;
910 }
911 if (effects.HasFlag(SpriteEffects.FlipVertically))
912 {
913 origin.Y = (float)rect.Height - origin.Y;
914 }
915 return origin;
916 }
917
918 public static Vector2 Size(this Texture2D tex)
919 {
920 return new Vector2(tex.Width, tex.Height);
921 }
922
923 public static void WriteRGB(this BinaryWriter bb, Color c)
924 {
925 bb.Write(c.R);
926 bb.Write(c.G);
927 bb.Write(c.B);
928 }
929
930 public static void WriteVector2(this BinaryWriter bb, Vector2 v)
931 {
932 bb.Write(v.X);
933 bb.Write(v.Y);
934 }
935
936 public static void WritePackedVector2(this BinaryWriter bb, Vector2 v)
937 {
938 bb.Write(new HalfVector2(v.X, v.Y).PackedValue);
939 }
940
941 public static Color ReadRGB(this BinaryReader bb)
942 {
943 return new Color(bb.ReadByte(), bb.ReadByte(), bb.ReadByte());
944 }
945
946 public static Vector2 ReadVector2(this BinaryReader bb)
947 {
948 return new Vector2(bb.ReadSingle(), bb.ReadSingle());
949 }
950
952 {
954 halfVector.PackedValue = bb.ReadUInt32();
955 return halfVector.ToVector2();
956 }
957
958 public static Vector2 Left(this Rectangle r)
959 {
960 return new Vector2(r.X, r.Y + r.Height / 2);
961 }
962
963 public static Vector2 Right(this Rectangle r)
964 {
965 return new Vector2(r.X + r.Width, r.Y + r.Height / 2);
966 }
967
968 public static Vector2 Top(this Rectangle r)
969 {
970 return new Vector2(r.X + r.Width / 2, r.Y);
971 }
972
973 public static Vector2 Bottom(this Rectangle r)
974 {
975 return new Vector2(r.X + r.Width / 2, r.Y + r.Height);
976 }
977
978 public static Vector2 TopLeft(this Rectangle r)
979 {
980 return new Vector2(r.X, r.Y);
981 }
982
983 public static Vector2 TopRight(this Rectangle r)
984 {
985 return new Vector2(r.X + r.Width, r.Y);
986 }
987
988 public static Vector2 BottomLeft(this Rectangle r)
989 {
990 return new Vector2(r.X, r.Y + r.Height);
991 }
992
993 public static Vector2 BottomRight(this Rectangle r)
994 {
995 return new Vector2(r.X + r.Width, r.Y + r.Height);
996 }
997
998 public static Vector2 Center(this Rectangle r)
999 {
1000 return new Vector2(r.X + r.Width / 2, r.Y + r.Height / 2);
1001 }
1002
1003 public static Vector2 Size(this Rectangle r)
1004 {
1005 return new Vector2(r.Width, r.Height);
1006 }
1007
1008 public static float Distance(this Rectangle r, Vector2 point)
1009 {
1010 if (FloatIntersect(r.Left, r.Top, r.Width, r.Height, point.X, point.Y, 0f, 0f))
1011 {
1012 return 0f;
1013 }
1014 if (point.X >= (float)r.Left && point.X <= (float)r.Right)
1015 {
1016 if (point.Y < (float)r.Top)
1017 {
1018 return (float)r.Top - point.Y;
1019 }
1020 return point.Y - (float)r.Bottom;
1021 }
1022 if (point.Y >= (float)r.Top && point.Y <= (float)r.Bottom)
1023 {
1024 if (point.X < (float)r.Left)
1025 {
1026 return (float)r.Left - point.X;
1027 }
1028 return point.X - (float)r.Right;
1029 }
1030 if (point.X < (float)r.Left)
1031 {
1032 if (point.Y < (float)r.Top)
1033 {
1034 return Vector2.Distance(point, r.TopLeft());
1035 }
1036 return Vector2.Distance(point, r.BottomLeft());
1037 }
1038 if (point.Y < (float)r.Top)
1039 {
1040 return Vector2.Distance(point, r.TopRight());
1041 }
1042 return Vector2.Distance(point, r.BottomRight());
1043 }
1044
1045 public static Vector2 ClosestPointInRect(this Rectangle r, Vector2 point)
1046 {
1047 Vector2 result = point;
1048 if (result.X < (float)r.Left)
1049 {
1050 result.X = r.Left;
1051 }
1052 if (result.X > (float)r.Right)
1053 {
1054 result.X = r.Right;
1055 }
1056 if (result.Y < (float)r.Top)
1057 {
1058 result.Y = r.Top;
1059 }
1060 if (result.Y > (float)r.Bottom)
1061 {
1062 result.Y = r.Bottom;
1063 }
1064 return result;
1065 }
1066
1067 public static Rectangle Modified(this Rectangle r, int x, int y, int w, int h)
1068 {
1069 return new Rectangle(r.X + x, r.Y + y, r.Width + w, r.Height + h);
1070 }
1071
1072 public static bool IntersectsConeFastInaccurate(this Rectangle targetRect, Vector2 coneCenter, float coneLength, float coneRotation, float maximumAngle)
1073 {
1074 Vector2 point = coneCenter + coneRotation.ToRotationVector2() * coneLength;
1075 Vector2 spinningpoint = targetRect.ClosestPointInRect(point) - coneCenter;
1076 float num = spinningpoint.RotatedBy(0f - coneRotation).ToRotation();
1078 {
1079 return false;
1080 }
1081 return spinningpoint.Length() < coneLength;
1082 }
1083
1084 public static bool IntersectsConeSlowMoreAccurate(this Rectangle targetRect, Vector2 coneCenter, float coneLength, float coneRotation, float maximumAngle)
1085 {
1086 Vector2 point = coneCenter + coneRotation.ToRotationVector2() * coneLength;
1087 if (DoesFitInCone(targetRect.ClosestPointInRect(point), coneCenter, coneLength, coneRotation, maximumAngle))
1088 {
1089 return true;
1090 }
1091 if (DoesFitInCone(targetRect.TopLeft(), coneCenter, coneLength, coneRotation, maximumAngle))
1092 {
1093 return true;
1094 }
1095 if (DoesFitInCone(targetRect.TopRight(), coneCenter, coneLength, coneRotation, maximumAngle))
1096 {
1097 return true;
1098 }
1099 if (DoesFitInCone(targetRect.BottomLeft(), coneCenter, coneLength, coneRotation, maximumAngle))
1100 {
1101 return true;
1102 }
1103 if (DoesFitInCone(targetRect.BottomRight(), coneCenter, coneLength, coneRotation, maximumAngle))
1104 {
1105 return true;
1106 }
1107 return false;
1108 }
1109
1110 public static bool DoesFitInCone(Vector2 point, Vector2 coneCenter, float coneLength, float coneRotation, float maximumAngle)
1111 {
1113 float num = spinningpoint.RotatedBy(0f - coneRotation).ToRotation();
1115 {
1116 return false;
1117 }
1118 return spinningpoint.Length() < coneLength;
1119 }
1120
1121 public static float ToRotation(this Vector2 v)
1122 {
1123 return (float)Math.Atan2(v.Y, v.X);
1124 }
1125
1126 public static Vector2 ToRotationVector2(this float f)
1127 {
1128 return new Vector2((float)Math.Cos(f), (float)Math.Sin(f));
1129 }
1130
1131 public static Vector2 RotatedBy(this Vector2 spinningpoint, double radians, Vector2 center = default(Vector2))
1132 {
1133 float num = (float)Math.Cos(radians);
1134 float num2 = (float)Math.Sin(radians);
1136 Vector2 result = center;
1137 result.X += vector.X * num - vector.Y * num2;
1138 result.Y += vector.X * num2 + vector.Y * num;
1139 return result;
1140 }
1141
1142 public static Vector2D RotatedBy(this Vector2D spinningpoint, double radians, Vector2D center = default(Vector2D))
1143 {
1144 //IL_000e: Unknown result type (might be due to invalid IL or missing references)
1145 //IL_000f: Unknown result type (might be due to invalid IL or missing references)
1146 //IL_0010: Unknown result type (might be due to invalid IL or missing references)
1147 //IL_0015: Unknown result type (might be due to invalid IL or missing references)
1148 //IL_0016: Unknown result type (might be due to invalid IL or missing references)
1149 //IL_0017: Unknown result type (might be due to invalid IL or missing references)
1150 //IL_0021: Unknown result type (might be due to invalid IL or missing references)
1151 //IL_0029: Unknown result type (might be due to invalid IL or missing references)
1152 //IL_003d: Unknown result type (might be due to invalid IL or missing references)
1153 //IL_0045: Unknown result type (might be due to invalid IL or missing references)
1154 //IL_0050: Unknown result type (might be due to invalid IL or missing references)
1155 double num = Math.Cos(radians);
1156 double num2 = Math.Sin(radians);
1158 Vector2D result = center;
1159 result.X += val.X * num - val.Y * num2;
1160 result.Y += val.X * num2 + val.Y * num;
1161 return result;
1162 }
1163
1165 {
1166 return spinninpoint.RotatedBy(Main.rand.NextDouble() * maxRadians - Main.rand.NextDouble() * maxRadians);
1167 }
1168
1169 public static Vector2 Floor(this Vector2 vec)
1170 {
1171 vec.X = (int)vec.X;
1172 vec.Y = (int)vec.Y;
1173 return vec;
1174 }
1175
1176 public static bool HasNaNs(this Vector2 vec)
1177 {
1178 if (!float.IsNaN(vec.X))
1179 {
1180 return float.IsNaN(vec.Y);
1181 }
1182 return true;
1183 }
1184
1185 public static bool Between(this Vector2 vec, Vector2 minimum, Vector2 maximum)
1186 {
1187 if (vec.X >= minimum.X && vec.X <= maximum.X && vec.Y >= minimum.Y)
1188 {
1189 return vec.Y <= maximum.Y;
1190 }
1191 return false;
1192 }
1193
1194 public static Vector2 ToVector2(this Point p)
1195 {
1196 return new Vector2(p.X, p.Y);
1197 }
1198
1199 public static Vector2 ToVector2(this Point16 p)
1200 {
1201 return new Vector2(p.X, p.Y);
1202 }
1203
1204 public static Vector2D ToVector2D(this Point p)
1205 {
1206 //IL_000e: Unknown result type (might be due to invalid IL or missing references)
1207 return new Vector2D((double)p.X, (double)p.Y);
1208 }
1209
1210 public static Vector2D ToVector2D(this Point16 p)
1211 {
1212 //IL_000e: Unknown result type (might be due to invalid IL or missing references)
1213 return new Vector2D((double)p.X, (double)p.Y);
1214 }
1215
1216 public static Vector2 ToWorldCoordinates(this Point p, float autoAddX = 8f, float autoAddY = 8f)
1217 {
1218 return p.ToVector2() * 16f + new Vector2(autoAddX, autoAddY);
1219 }
1220
1221 public static Vector2 ToWorldCoordinates(this Point16 p, float autoAddX = 8f, float autoAddY = 8f)
1222 {
1223 return p.ToVector2() * 16f + new Vector2(autoAddX, autoAddY);
1224 }
1225
1227 {
1230 {
1231 return targetPosition;
1232 }
1233 return currentPosition + v.SafeNormalize(Vector2.Zero) * maxAmountAllowedToMove;
1234 }
1235
1237 {
1238 return new Point16((int)vec.X >> 4, (int)vec.Y >> 4);
1239 }
1240
1242 {
1243 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
1244 //IL_0009: Unknown result type (might be due to invalid IL or missing references)
1245 return new Point16((int)vec.X >> 4, (int)vec.Y >> 4);
1246 }
1247
1249 {
1250 return new Point((int)vec.X >> 4, (int)vec.Y >> 4);
1251 }
1252
1254 {
1255 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
1256 //IL_0009: Unknown result type (might be due to invalid IL or missing references)
1257 return new Point((int)vec.X >> 4, (int)vec.Y >> 4);
1258 }
1259
1260 public static Point ToPoint(this Vector2 v)
1261 {
1262 return new Point((int)v.X, (int)v.Y);
1263 }
1264
1265 public static Point ToPoint(this Vector2D v)
1266 {
1267 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
1268 //IL_0007: Unknown result type (might be due to invalid IL or missing references)
1269 return new Point((int)v.X, (int)v.Y);
1270 }
1271
1272 public static Vector2D ToVector2D(this Vector2 v)
1273 {
1274 //IL_000e: Unknown result type (might be due to invalid IL or missing references)
1275 return new Vector2D((double)v.X, (double)v.Y);
1276 }
1277
1279 {
1280 if (v == Vector2.Zero || v.HasNaNs())
1281 {
1282 return defaultValue;
1283 }
1284 return Vector2.Normalize(v);
1285 }
1286
1288 {
1289 Vector2 value = P - A;
1290 Vector2 vector = B - A;
1291 float num = vector.LengthSquared();
1292 float num2 = Vector2.Dot(value, vector) / num;
1293 if (num2 < 0f)
1294 {
1295 return A;
1296 }
1297 if (num2 > 1f)
1298 {
1299 return B;
1300 }
1301 return A + vector * num2;
1302 }
1303
1305 {
1307 {
1308 return true;
1309 }
1312 Vector2[] array = new Vector2[4]
1313 {
1314 rectTopLeft.ClosestPointOnLine(lineStart, lineEnd),
1315 p.ClosestPointOnLine(lineStart, lineEnd),
1316 vector.ClosestPointOnLine(lineStart, lineEnd),
1317 rectBottomRight.ClosestPointOnLine(lineStart, lineEnd)
1318 };
1319 for (int i = 0; i < array.Length; i++)
1320 {
1322 {
1323 return true;
1324 }
1325 }
1326 return false;
1327 }
1328
1330 {
1331 return spinninpoint.RotatedBy(Main.rand.NextDouble() * maxRadians - Main.rand.NextDouble() * maxRadians);
1332 }
1333
1334 public static float AngleTo(this Vector2 Origin, Vector2 Target)
1335 {
1336 return (float)Math.Atan2(Target.Y - Origin.Y, Target.X - Origin.X);
1337 }
1338
1339 public static float AngleFrom(this Vector2 Origin, Vector2 Target)
1340 {
1341 return (float)Math.Atan2(Origin.Y - Target.Y, Origin.X - Target.X);
1342 }
1343
1345 {
1346 float num = currentVelocity.Length();
1348 return currentVelocity.ToRotation().AngleTowards(targetAngle, (float)Math.PI / 180f).ToRotationVector2() * num;
1349 }
1350
1351 public static float Distance(this Vector2 Origin, Vector2 Target)
1352 {
1353 return Vector2.Distance(Origin, Target);
1354 }
1355
1356 public static float DistanceSQ(this Vector2 Origin, Vector2 Target)
1357 {
1358 return Vector2.DistanceSquared(Origin, Target);
1359 }
1360
1361 public static Vector2 DirectionTo(this Vector2 Origin, Vector2 Target)
1362 {
1363 return Vector2.Normalize(Target - Origin);
1364 }
1365
1366 public static Vector2 DirectionFrom(this Vector2 Origin, Vector2 Target)
1367 {
1368 return Vector2.Normalize(Origin - Target);
1369 }
1370
1371 public static bool WithinRange(this Vector2 Origin, Vector2 Target, float MaxRange)
1372 {
1373 return Vector2.DistanceSquared(Origin, Target) <= MaxRange * MaxRange;
1374 }
1375
1376 public static Vector2 XY(this Vector4 vec)
1377 {
1378 return new Vector2(vec.X, vec.Y);
1379 }
1380
1381 public static Vector2 ZW(this Vector4 vec)
1382 {
1383 return new Vector2(vec.Z, vec.W);
1384 }
1385
1386 public static Vector3 XZW(this Vector4 vec)
1387 {
1388 return new Vector3(vec.X, vec.Z, vec.W);
1389 }
1390
1391 public static Vector3 YZW(this Vector4 vec)
1392 {
1393 return new Vector3(vec.Y, vec.Z, vec.W);
1394 }
1395
1397 {
1398 return new Color((byte)((float)(firstColor.R * secondColor.R) / 255f), (byte)((float)(firstColor.G * secondColor.G) / 255f), (byte)((float)(firstColor.B * secondColor.B) / 255f));
1399 }
1400
1402 {
1403 return new Color((byte)((float)(firstColor.R * secondColor.R) / 255f), (byte)((float)(firstColor.G * secondColor.G) / 255f), (byte)((float)(firstColor.B * secondColor.B) / 255f), (byte)((float)(firstColor.A * secondColor.A) / 255f));
1404 }
1405
1406 public static string Hex3(this Color color)
1407 {
1408 return (color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2")).ToLower();
1409 }
1410
1411 public static string Hex4(this Color color)
1412 {
1413 return (color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2") + color.A.ToString("X2")).ToLower();
1414 }
1415
1416 public static int ToDirectionInt(this bool value)
1417 {
1418 if (!value)
1419 {
1420 return -1;
1421 }
1422 return 1;
1423 }
1424
1425 public static int ToInt(this bool value)
1426 {
1427 if (!value)
1428 {
1429 return 0;
1430 }
1431 return 1;
1432 }
1433
1434 public static int ModulusPositive(this int myInteger, int modulusNumber)
1435 {
1437 }
1438
1439 public static float AngleLerp(this float curAngle, float targetAngle, float amount)
1440 {
1441 float angle;
1442 if (targetAngle < curAngle)
1443 {
1444 float num = targetAngle + (float)Math.PI * 2f;
1446 }
1447 else
1448 {
1449 if (!(targetAngle > curAngle))
1450 {
1451 return curAngle;
1452 }
1453 float num = targetAngle - (float)Math.PI * 2f;
1455 }
1456 return MathHelper.WrapAngle(angle);
1457 }
1458
1459 public static float AngleTowards(this float curAngle, float targetAngle, float maxChange)
1460 {
1463 if (curAngle < targetAngle)
1464 {
1465 if (targetAngle - curAngle > (float)Math.PI)
1466 {
1467 curAngle += (float)Math.PI * 2f;
1468 }
1469 }
1470 else if (curAngle - targetAngle > (float)Math.PI)
1471 {
1472 curAngle -= (float)Math.PI * 2f;
1473 }
1476 }
1477
1478 public static bool deepCompare(this int[] firstArray, int[] secondArray)
1479 {
1480 if (firstArray == null && secondArray == null)
1481 {
1482 return true;
1483 }
1484 if (firstArray != null && secondArray != null)
1485 {
1486 if (firstArray.Length != secondArray.Length)
1487 {
1488 return false;
1489 }
1490 for (int i = 0; i < firstArray.Length; i++)
1491 {
1492 if (firstArray[i] != secondArray[i])
1493 {
1494 return false;
1495 }
1496 }
1497 return true;
1498 }
1499 return false;
1500 }
1501
1502 public static List<int> GetTrueIndexes(this bool[] array)
1503 {
1504 List<int> list = new List<int>();
1505 for (int i = 0; i < array.Length; i++)
1506 {
1507 if (array[i])
1508 {
1509 list.Add(i);
1510 }
1511 }
1512 return list;
1513 }
1514
1515 public static List<int> GetTrueIndexes(params bool[][] arrays)
1516 {
1517 List<int> list = new List<int>();
1518 foreach (bool[] array in arrays)
1519 {
1520 list.AddRange(array.GetTrueIndexes());
1521 }
1522 return list.Distinct().ToList();
1523 }
1524
1525 public static int Count<T>(this T[] arr, T value)
1526 {
1527 int num = 0;
1528 foreach (T x in arr)
1529 {
1530 if (EqualityComparer<T>.Default.Equals(x, value))
1531 {
1532 num++;
1533 }
1534 }
1535 return num;
1536 }
1537
1538 public static bool PressingShift(this KeyboardState kb)
1539 {
1540 if (!kb.IsKeyDown(Keys.LeftShift))
1541 {
1542 return kb.IsKeyDown(Keys.RightShift);
1543 }
1544 return true;
1545 }
1546
1547 public static bool PressingControl(this KeyboardState kb)
1548 {
1549 if (!kb.IsKeyDown(Keys.LeftControl))
1550 {
1551 return kb.IsKeyDown(Keys.RightControl);
1552 }
1553 return true;
1554 }
1555
1556 public static R[] MapArray<T, R>(T[] array, Func<T, R> mapper)
1557 {
1558 R[] array2 = new R[array.Length];
1559 for (int i = 0; i < array.Length; i++)
1560 {
1561 array2[i] = mapper(array[i]);
1562 }
1563 return array2;
1564 }
1565
1566 public static bool PlotLine(Point16 p0, Point16 p1, TileActionAttempt plot, bool jump = true)
1567 {
1568 return PlotLine(p0.X, p0.Y, p1.X, p1.Y, plot, jump);
1569 }
1570
1571 public static bool PlotLine(Point p0, Point p1, TileActionAttempt plot, bool jump = true)
1572 {
1573 return PlotLine(p0.X, p0.Y, p1.X, p1.Y, plot, jump);
1574 }
1575
1576 private static bool PlotLine(int x0, int y0, int x1, int y1, TileActionAttempt plot, bool jump = true)
1577 {
1578 if (x0 == x1 && y0 == y1)
1579 {
1580 return plot(x0, y0);
1581 }
1582 bool flag = Math.Abs(y1 - y0) > Math.Abs(x1 - x0);
1583 if (flag)
1584 {
1585 Swap(ref x0, ref y0);
1586 Swap(ref x1, ref y1);
1587 }
1588 int num = Math.Abs(x1 - x0);
1589 int num2 = Math.Abs(y1 - y0);
1590 int num3 = num / 2;
1591 int num4 = y0;
1592 int num5 = ((x0 < x1) ? 1 : (-1));
1593 int num6 = ((y0 < y1) ? 1 : (-1));
1594 for (int i = x0; i != x1; i += num5)
1595 {
1596 if (flag)
1597 {
1598 if (!plot(num4, i))
1599 {
1600 return false;
1601 }
1602 }
1603 else if (!plot(i, num4))
1604 {
1605 return false;
1606 }
1607 num3 -= num2;
1608 if (num3 >= 0)
1609 {
1610 continue;
1611 }
1612 num4 += num6;
1613 if (!jump)
1614 {
1615 if (flag)
1616 {
1617 if (!plot(num4, i))
1618 {
1619 return false;
1620 }
1621 }
1622 else if (!plot(i, num4))
1623 {
1624 return false;
1625 }
1626 }
1627 num3 += num;
1628 }
1629 return true;
1630 }
1631
1632 public static int RandomNext(ref ulong seed, int bits)
1633 {
1635 return (int)(seed >> 48 - bits);
1636 }
1637
1638 public static ulong RandomNextSeed(ulong seed)
1639 {
1640 return (seed * 25214903917L + 11) & 0xFFFFFFFFFFFFuL;
1641 }
1642
1643 public static float RandomFloat(ref ulong seed)
1644 {
1645 return (float)RandomNext(ref seed, 24) / 16777216f;
1646 }
1647
1648 public static int RandomInt(ref ulong seed, int max)
1649 {
1650 if ((max & -max) == max)
1651 {
1652 return (int)((long)max * (long)RandomNext(ref seed, 31) >> 31);
1653 }
1654 int num;
1655 int num2;
1656 do
1657 {
1658 num = RandomNext(ref seed, 31);
1659 num2 = num % max;
1660 }
1661 while (num - num2 + (max - 1) < 0);
1662 return num2;
1663 }
1664
1665 public static int RandomInt(ref ulong seed, int min, int max)
1666 {
1667 return RandomInt(ref seed, max - min) + min;
1668 }
1669
1670 public static bool PlotTileLine(Vector2 start, Vector2 end, float width, TileActionAttempt plot)
1671 {
1672 //IL_0001: Unknown result type (might be due to invalid IL or missing references)
1673 //IL_0007: Unknown result type (might be due to invalid IL or missing references)
1674 return PlotTileLine(start.ToVector2D(), end.ToVector2D(), width, plot);
1675 }
1676
1677 public static bool PlotTileLine(Vector2D start, Vector2D end, double width, TileActionAttempt plot)
1678 {
1679 //IL_0019: Unknown result type (might be due to invalid IL or missing references)
1680 //IL_001a: Unknown result type (might be due to invalid IL or missing references)
1681 //IL_001b: Unknown result type (might be due to invalid IL or missing references)
1682 //IL_0020: Unknown result type (might be due to invalid IL or missing references)
1683 //IL_0021: Unknown result type (might be due to invalid IL or missing references)
1684 //IL_0029: Unknown result type (might be due to invalid IL or missing references)
1685 //IL_002e: Unknown result type (might be due to invalid IL or missing references)
1686 //IL_002f: Unknown result type (might be due to invalid IL or missing references)
1687 //IL_0036: Unknown result type (might be due to invalid IL or missing references)
1688 //IL_003c: Unknown result type (might be due to invalid IL or missing references)
1689 //IL_0042: Unknown result type (might be due to invalid IL or missing references)
1690 //IL_0047: Unknown result type (might be due to invalid IL or missing references)
1691 //IL_0049: Unknown result type (might be due to invalid IL or missing references)
1692 //IL_004a: Unknown result type (might be due to invalid IL or missing references)
1693 //IL_004c: Unknown result type (might be due to invalid IL or missing references)
1694 //IL_0058: Unknown result type (might be due to invalid IL or missing references)
1695 //IL_0059: Unknown result type (might be due to invalid IL or missing references)
1696 //IL_005b: Unknown result type (might be due to invalid IL or missing references)
1697 //IL_0067: Unknown result type (might be due to invalid IL or missing references)
1698 //IL_006f: Unknown result type (might be due to invalid IL or missing references)
1699 double num = width / 2.0;
1700 Vector2D val = end - start;
1701 Vector2D val2 = val / ((Vector2D)(ref val)).Length();
1702 Vector2D val3 = new Vector2D(0.0 - val2.Y, val2.X) * num;
1703 Point point = (start - val3).ToTileCoordinates();
1705 Point point3 = start.ToTileCoordinates();
1706 Point point4 = end.ToTileCoordinates();
1707 Point lineMinOffset = new Point(point.X - point3.X, point.Y - point3.Y);
1708 Point lineMaxOffset = new Point(point2.X - point3.X, point2.Y - point3.Y);
1709 return PlotLine(point3.X, point3.Y, point4.X, point4.Y, (int x, int y) => PlotLine(x + lineMinOffset.X, y + lineMinOffset.Y, x + lineMaxOffset.X, y + lineMaxOffset.Y, plot, jump: false));
1710 }
1711
1712 public static bool PlotTileTale(Vector2D start, Vector2D end, double width, TileActionAttempt plot)
1713 {
1714 //IL_0007: Unknown result type (might be due to invalid IL or missing references)
1715 //IL_0008: Unknown result type (might be due to invalid IL or missing references)
1716 //IL_0025: Unknown result type (might be due to invalid IL or missing references)
1717 //IL_0027: Unknown result type (might be due to invalid IL or missing references)
1718 //IL_002c: Unknown result type (might be due to invalid IL or missing references)
1719 //IL_0031: Unknown result type (might be due to invalid IL or missing references)
1720 //IL_0032: Unknown result type (might be due to invalid IL or missing references)
1721 //IL_003a: Unknown result type (might be due to invalid IL or missing references)
1722 //IL_003f: Unknown result type (might be due to invalid IL or missing references)
1723 //IL_0041: Unknown result type (might be due to invalid IL or missing references)
1724 //IL_0048: Unknown result type (might be due to invalid IL or missing references)
1725 //IL_004e: Unknown result type (might be due to invalid IL or missing references)
1726 //IL_0053: Unknown result type (might be due to invalid IL or missing references)
1727 //IL_005a: Unknown result type (might be due to invalid IL or missing references)
1728 //IL_0069: Unknown result type (might be due to invalid IL or missing references)
1729 double halfWidth = width / 2.0;
1730 Vector2D val = end - start;
1731 Vector2D val2 = val / ((Vector2D)(ref val)).Length();
1732 Vector2D perpOffset = new Vector2D(0.0 - val2.Y, val2.X);
1733 Point pointStart = start.ToTileCoordinates();
1734 Point point = end.ToTileCoordinates();
1735 int length = 0;
1736 PlotLine(pointStart.X, pointStart.Y, point.X, point.Y, delegate
1737 {
1738 length++;
1739 return true;
1740 });
1741 length--;
1742 int curLength = 0;
1743 return PlotLine(pointStart.X, pointStart.Y, point.X, point.Y, delegate(int x, int y)
1744 {
1745 //IL_002d: Unknown result type (might be due to invalid IL or missing references)
1746 //IL_0033: Unknown result type (might be due to invalid IL or missing references)
1747 //IL_003e: Unknown result type (might be due to invalid IL or missing references)
1748 //IL_0044: Unknown result type (might be due to invalid IL or missing references)
1749 //IL_0049: Unknown result type (might be due to invalid IL or missing references)
1750 //IL_0055: Unknown result type (might be due to invalid IL or missing references)
1751 //IL_005b: Unknown result type (might be due to invalid IL or missing references)
1752 //IL_0066: Unknown result type (might be due to invalid IL or missing references)
1753 //IL_006c: Unknown result type (might be due to invalid IL or missing references)
1754 //IL_0071: Unknown result type (might be due to invalid IL or missing references)
1755 double num = 1.0 - (double)curLength / (double)length;
1756 curLength++;
1759 Point point4 = new Point(point2.X - pointStart.X, point2.Y - pointStart.Y);
1760 Point point5 = new Point(point3.X - pointStart.X, point3.Y - pointStart.Y);
1761 return PlotLine(x + point4.X, y + point4.Y, x + point5.X, y + point5.Y, plot, jump: false);
1762 });
1763 }
1764
1765 public static bool PlotTileArea(int x, int y, TileActionAttempt plot)
1766 {
1767 if (!WorldGen.InWorld(x, y))
1768 {
1769 return false;
1770 }
1774 list2.Add(new Point(x, y));
1775 while (list2.Count > 0)
1776 {
1777 list.Clear();
1779 list2.Clear();
1780 while (list.Count > 0)
1781 {
1782 Point item = list[0];
1783 if (!WorldGen.InWorld(item.X, item.Y, 1))
1784 {
1785 list.Remove(item);
1786 continue;
1787 }
1788 hashSet.Add(item);
1789 list.Remove(item);
1790 if (plot(item.X, item.Y))
1791 {
1792 Point item2 = new Point(item.X - 1, item.Y);
1793 if (!hashSet.Contains(item2))
1794 {
1795 list2.Add(item2);
1796 }
1797 item2 = new Point(item.X + 1, item.Y);
1798 if (!hashSet.Contains(item2))
1799 {
1800 list2.Add(item2);
1801 }
1802 item2 = new Point(item.X, item.Y - 1);
1803 if (!hashSet.Contains(item2))
1804 {
1805 list2.Add(item2);
1806 }
1807 item2 = new Point(item.X, item.Y + 1);
1808 if (!hashSet.Contains(item2))
1809 {
1810 list2.Add(item2);
1811 }
1812 }
1813 }
1814 }
1815 return true;
1816 }
1817
1818 public static int RandomConsecutive(double random, int odds)
1819 {
1820 return (int)Math.Log(1.0 - random, 1.0 / (double)odds);
1821 }
1822
1823 public static Vector2 RandomVector2(UnifiedRandom random, float min, float max)
1824 {
1825 return new Vector2((max - min) * (float)random.NextDouble() + min, (max - min) * (float)random.NextDouble() + min);
1826 }
1827
1828 public static Vector2D RandomVector2D(UnifiedRandom random, double min, double max)
1829 {
1830 //IL_0018: Unknown result type (might be due to invalid IL or missing references)
1831 return new Vector2D((max - min) * random.NextDouble() + min, (max - min) * random.NextDouble() + min);
1832 }
1833
1834 public static bool IndexInRange<T>(this T[] t, int index)
1835 {
1836 if (index >= 0)
1837 {
1838 return index < t.Length;
1839 }
1840 return false;
1841 }
1842
1843 public static bool IndexInRange<T>(this List<T> t, int index)
1844 {
1845 if (index >= 0)
1846 {
1847 return index < t.Count;
1848 }
1849 return false;
1850 }
1851
1852 public static T SelectRandom<T>(UnifiedRandom random, params T[] choices)
1853 {
1854 return choices[random.Next(choices.Length)];
1855 }
1856
1857 public static void DrawBorderStringFourWay(SpriteBatch sb, DynamicSpriteFont font, string text, float x, float y, Color textColor, Color borderColor, Vector2 origin, float scale = 1f)
1858 {
1859 Color color = borderColor;
1861 for (int i = 0; i < 5; i++)
1862 {
1863 switch (i)
1864 {
1865 case 0:
1866 zero.X = x - 2f;
1867 zero.Y = y;
1868 break;
1869 case 1:
1870 zero.X = x + 2f;
1871 zero.Y = y;
1872 break;
1873 case 2:
1874 zero.X = x;
1875 zero.Y = y - 2f;
1876 break;
1877 case 3:
1878 zero.X = x;
1879 zero.Y = y + 2f;
1880 break;
1881 default:
1882 zero.X = x;
1883 zero.Y = y;
1884 color = textColor;
1885 break;
1886 }
1887 DynamicSpriteFontExtensionMethods.DrawString(sb, font, text, zero, color, 0f, origin, scale, SpriteEffects.None, 0f);
1888 }
1889 }
1890
1891 public static Vector2 DrawBorderString(SpriteBatch sb, string text, Vector2 pos, Color color, float scale = 1f, float anchorx = 0f, float anchory = 0f, int maxCharactersDisplayed = -1)
1892 {
1894 {
1895 text.Substring(0, maxCharactersDisplayed);
1896 }
1898 Vector2 vector = value.MeasureString(text);
1899 ChatManager.DrawColorCodedStringWithShadow(sb, value, text, pos, color, 0f, new Vector2(anchorx, anchory) * vector, new Vector2(scale), -1f, 1.5f);
1900 return vector * scale;
1901 }
1902
1903 public static Vector2 DrawBorderStringBig(SpriteBatch spriteBatch, string text, Vector2 pos, Color color, float scale = 1f, float anchorx = 0f, float anchory = 0f, int maxCharactersDisplayed = -1)
1904 {
1906 {
1907 text.Substring(0, maxCharactersDisplayed);
1908 }
1910 for (int i = -1; i < 2; i++)
1911 {
1912 for (int j = -1; j < 2; j++)
1913 {
1914 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, value, text, pos + new Vector2(i, j), Color.Black, 0f, new Vector2(anchorx, anchory) * value.MeasureString(text), scale, SpriteEffects.None, 0f);
1915 }
1916 }
1917 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, value, text, pos, color, 0f, new Vector2(anchorx, anchory) * value.MeasureString(text), scale, SpriteEffects.None, 0f);
1918 return value.MeasureString(text) * scale;
1919 }
1920
1921 public static void DrawInvBG(SpriteBatch sb, Rectangle R, Color c = default(Color))
1922 {
1923 DrawInvBG(sb, R.X, R.Y, R.Width, R.Height, c);
1924 }
1925
1926 public static void DrawInvBG(SpriteBatch sb, float x, float y, float w, float h, Color c = default(Color))
1927 {
1928 DrawInvBG(sb, (int)x, (int)y, (int)w, (int)h, c);
1929 }
1930
1931 public static void DrawInvBG(SpriteBatch sb, int x, int y, int w, int h, Color c = default(Color))
1932 {
1933 if (c == default(Color))
1934 {
1935 c = new Color(63, 65, 151, 255) * 0.785f;
1936 }
1938 if (w < 20)
1939 {
1940 w = 20;
1941 }
1942 if (h < 20)
1943 {
1944 h = 20;
1945 }
1946 sb.Draw(value, new Rectangle(x, y, 10, 10), new Rectangle(0, 0, 10, 10), c);
1947 sb.Draw(value, new Rectangle(x + 10, y, w - 20, 10), new Rectangle(10, 0, 10, 10), c);
1948 sb.Draw(value, new Rectangle(x + w - 10, y, 10, 10), new Rectangle(value.Width - 10, 0, 10, 10), c);
1949 sb.Draw(value, new Rectangle(x, y + 10, 10, h - 20), new Rectangle(0, 10, 10, 10), c);
1950 sb.Draw(value, new Rectangle(x + 10, y + 10, w - 20, h - 20), new Rectangle(10, 10, 10, 10), c);
1951 sb.Draw(value, new Rectangle(x + w - 10, y + 10, 10, h - 20), new Rectangle(value.Width - 10, 10, 10, 10), c);
1952 sb.Draw(value, new Rectangle(x, y + h - 10, 10, 10), new Rectangle(0, value.Height - 10, 10, 10), c);
1953 sb.Draw(value, new Rectangle(x + 10, y + h - 10, w - 20, 10), new Rectangle(10, value.Height - 10, 10, 10), c);
1954 sb.Draw(value, new Rectangle(x + w - 10, y + h - 10, 10, 10), new Rectangle(value.Width - 10, value.Height - 10, 10, 10), c);
1955 }
1956
1957 public static string ReadEmbeddedResource(string path)
1958 {
1959 using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path);
1961 return streamReader.ReadToEnd();
1962 }
1963
1964 public static void DrawSplicedPanel(SpriteBatch sb, Texture2D texture, int x, int y, int w, int h, int leftEnd, int rightEnd, int topEnd, int bottomEnd, Color c)
1965 {
1966 if (w < leftEnd + rightEnd)
1967 {
1968 w = leftEnd + rightEnd;
1969 }
1970 if (h < topEnd + bottomEnd)
1971 {
1972 h = topEnd + bottomEnd;
1973 }
1974 sb.Draw(texture, new Rectangle(x, y, leftEnd, topEnd), new Rectangle(0, 0, leftEnd, topEnd), c);
1975 sb.Draw(texture, new Rectangle(x + leftEnd, y, w - leftEnd - rightEnd, topEnd), new Rectangle(leftEnd, 0, texture.Width - leftEnd - rightEnd, topEnd), c);
1976 sb.Draw(texture, new Rectangle(x + w - rightEnd, y, topEnd, rightEnd), new Rectangle(texture.Width - rightEnd, 0, rightEnd, topEnd), c);
1977 sb.Draw(texture, new Rectangle(x, y + topEnd, leftEnd, h - topEnd - bottomEnd), new Rectangle(0, topEnd, leftEnd, texture.Height - topEnd - bottomEnd), c);
1978 sb.Draw(texture, new Rectangle(x + leftEnd, y + topEnd, w - leftEnd - rightEnd, h - topEnd - bottomEnd), new Rectangle(leftEnd, topEnd, texture.Width - leftEnd - rightEnd, texture.Height - topEnd - bottomEnd), c);
1979 sb.Draw(texture, new Rectangle(x + w - rightEnd, y + topEnd, rightEnd, h - topEnd - bottomEnd), new Rectangle(texture.Width - rightEnd, topEnd, rightEnd, texture.Height - topEnd - bottomEnd), c);
1980 sb.Draw(texture, new Rectangle(x, y + h - bottomEnd, leftEnd, bottomEnd), new Rectangle(0, texture.Height - bottomEnd, leftEnd, bottomEnd), c);
1981 sb.Draw(texture, new Rectangle(x + leftEnd, y + h - bottomEnd, w - leftEnd - rightEnd, bottomEnd), new Rectangle(leftEnd, texture.Height - bottomEnd, texture.Width - leftEnd - rightEnd, bottomEnd), c);
1982 sb.Draw(texture, new Rectangle(x + w - rightEnd, y + h - bottomEnd, rightEnd, bottomEnd), new Rectangle(texture.Width - rightEnd, texture.Height - bottomEnd, rightEnd, bottomEnd), c);
1983 }
1984
1985 public static void DrawSettingsPanel(SpriteBatch spriteBatch, Vector2 position, float width, Color color)
1986 {
1987 DrawPanel(TextureAssets.SettingsPanel.Value, 2, 0, spriteBatch, position, width, color);
1988 }
1989
1990 public static void DrawSettings2Panel(SpriteBatch spriteBatch, Vector2 position, float width, Color color)
1991 {
1992 DrawPanel(TextureAssets.SettingsPanel.Value, 2, 0, spriteBatch, position, width, color);
1993 }
1994
1995 public static void DrawPanel(Texture2D texture, int edgeWidth, int edgeShove, SpriteBatch spriteBatch, Vector2 position, float width, Color color)
1996 {
1997 spriteBatch.Draw(texture, position, new Rectangle(0, 0, edgeWidth, texture.Height), color);
1998 spriteBatch.Draw(texture, new Vector2(position.X + (float)edgeWidth, position.Y), new Rectangle(edgeWidth + edgeShove, 0, texture.Width - (edgeWidth + edgeShove) * 2, texture.Height), color, 0f, Vector2.Zero, new Vector2((width - (float)(edgeWidth * 2)) / (float)(texture.Width - (edgeWidth + edgeShove) * 2), 1f), SpriteEffects.None, 0f);
1999 spriteBatch.Draw(texture, new Vector2(position.X + width - (float)edgeWidth, position.Y), new Rectangle(texture.Width - edgeWidth, 0, edgeWidth, texture.Height), color);
2000 }
2001
2002 public static void DrawRectangle(SpriteBatch sb, Vector2 start, Vector2 end, Color colorStart, Color colorEnd, float width)
2003 {
2004 DrawLine(sb, start, new Vector2(start.X, end.Y), colorStart, colorEnd, width);
2005 DrawLine(sb, start, new Vector2(end.X, start.Y), colorStart, colorEnd, width);
2006 DrawLine(sb, end, new Vector2(start.X, end.Y), colorStart, colorEnd, width);
2007 DrawLine(sb, end, new Vector2(end.X, start.Y), colorStart, colorEnd, width);
2008 }
2009
2011 {
2014 float num = (end - start).Length();
2015 float rotation = vector2.ToRotation() - (float)Math.PI / 2f;
2016 if (vector2.HasNaNs())
2017 {
2018 return;
2019 }
2020 framing(0, vector, num, default(Rectangle), out var distanceCovered, out var frame, out var origin, out var color);
2021 sb.Draw(tex, vector, frame, color, rotation, frame.Size() / 2f, scale, SpriteEffects.None, 0f);
2022 num -= distanceCovered * scale.Y;
2023 vector += vector2 * ((float)frame.Height - origin.Y) * scale.Y;
2024 if (num > 0f)
2025 {
2026 float num2 = 0f;
2027 while (num2 + 1f < num)
2028 {
2029 framing(1, vector, num - num2, frame, out distanceCovered, out frame, out origin, out color);
2030 if (num - num2 < (float)frame.Height)
2031 {
2032 distanceCovered *= (num - num2) / (float)frame.Height;
2033 frame.Height = (int)(num - num2);
2034 }
2035 sb.Draw(tex, vector, frame, color, rotation, origin, scale, SpriteEffects.None, 0f);
2036 num2 += distanceCovered * scale.Y;
2037 vector += vector2 * distanceCovered * scale.Y;
2038 }
2039 }
2040 framing(2, vector, num, default(Rectangle), out distanceCovered, out frame, out origin, out color);
2041 sb.Draw(tex, vector, frame, color, rotation, origin, scale, SpriteEffects.None, 0f);
2042 }
2043
2044 public static void DrawLine(SpriteBatch spriteBatch, Point start, Point end, Color color)
2045 {
2046 DrawLine(spriteBatch, new Vector2(start.X << 4, start.Y << 4), new Vector2(end.X << 4, end.Y << 4), color);
2047 }
2048
2049 public static void DrawLine(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color)
2050 {
2051 float num = Vector2.Distance(start, end);
2052 Vector2 vector = (end - start) / num;
2054 Vector2 screenPosition = Main.screenPosition;
2055 float rotation = vector.ToRotation();
2056 for (float num2 = 0f; num2 <= num; num2 += 4f)
2057 {
2058 float num3 = num2 / num;
2059 spriteBatch.Draw(TextureAssets.BlackTile.Value, vector2 - screenPosition, null, new Color(new Vector4(num3, num3, num3, 1f) * color.ToVector4()), rotation, Vector2.Zero, 0.25f, SpriteEffects.None, 0f);
2060 vector2 = start + num2 * vector;
2061 }
2062 }
2063
2064 public static void DrawLine(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color colorStart, Color colorEnd, float width)
2065 {
2066 float num = Vector2.Distance(start, end);
2067 Vector2 vector = (end - start) / num;
2069 Vector2 screenPosition = Main.screenPosition;
2070 float rotation = vector.ToRotation();
2071 float scale = width / 16f;
2072 for (float num2 = 0f; num2 <= num; num2 += width)
2073 {
2074 float amount = num2 / num;
2075 spriteBatch.Draw(TextureAssets.BlackTile.Value, vector2 - screenPosition, null, Color.Lerp(colorStart, colorEnd, amount), rotation, Vector2.Zero, scale, SpriteEffects.None, 0f);
2076 vector2 = start + num2 * vector;
2077 }
2078 }
2079
2080 public static void DrawRectForTilesInWorld(SpriteBatch spriteBatch, Rectangle rect, Color color)
2081 {
2082 DrawRectForTilesInWorld(spriteBatch, new Point(rect.X, rect.Y), new Point(rect.X + rect.Width, rect.Y + rect.Height), color);
2083 }
2084
2085 public static void DrawRectForTilesInWorld(SpriteBatch spriteBatch, Point start, Point end, Color color)
2086 {
2087 DrawRect(spriteBatch, new Vector2(start.X << 4, start.Y << 4), new Vector2((end.X << 4) - 4, (end.Y << 4) - 4), color);
2088 }
2089
2090 public static void DrawRect(SpriteBatch spriteBatch, Rectangle rect, Color color)
2091 {
2092 DrawRect(spriteBatch, new Vector2(rect.X, rect.Y), new Vector2(rect.X + rect.Width, rect.Y + rect.Height), color);
2093 }
2094
2095 public static void DrawRect(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color)
2096 {
2097 DrawLine(spriteBatch, start, new Vector2(start.X, end.Y), color);
2098 DrawLine(spriteBatch, start, new Vector2(end.X, start.Y), color);
2099 DrawLine(spriteBatch, end, new Vector2(start.X, end.Y), color);
2100 DrawLine(spriteBatch, end, new Vector2(end.X, start.Y), color);
2101 }
2102
2104 {
2105 DrawLine(spriteBatch, topLeft, topRight, color);
2106 DrawLine(spriteBatch, topRight, bottomRight, color);
2107 DrawLine(spriteBatch, bottomRight, bottomLeft, color);
2108 DrawLine(spriteBatch, bottomLeft, topLeft, color);
2109 }
2110
2111 public static void DrawCursorSingle(SpriteBatch sb, Color color, float rot = float.NaN, float scale = 1f, Vector2 manualPosition = default(Vector2), int cursorSlot = 0, int specialMode = 0)
2112 {
2113 bool flag = false;
2114 bool flag2 = true;
2115 bool flag3 = true;
2116 Vector2 origin = Vector2.Zero;
2119 {
2121 }
2122 if (float.IsNaN(rot))
2123 {
2124 rot = 0f;
2125 }
2126 else
2127 {
2128 flag = true;
2129 rot -= (float)Math.PI * 3f / 4f;
2130 }
2131 if (cursorSlot == 4 || cursorSlot == 5)
2132 {
2133 flag2 = false;
2134 origin = new Vector2(8f);
2135 if (flag && specialMode == 0)
2136 {
2137 float num = rot;
2138 if (num < 0f)
2139 {
2140 num += (float)Math.PI * 2f;
2141 }
2142 for (float num2 = 0f; num2 < 4f; num2 += 1f)
2143 {
2144 if (Math.Abs(num - (float)Math.PI / 2f * num2) <= (float)Math.PI / 4f)
2145 {
2146 rot = (float)Math.PI / 2f * num2;
2147 break;
2148 }
2149 }
2150 }
2151 }
2153 if ((Main.ThickMouse && cursorSlot == 0) || cursorSlot == 1)
2154 {
2156 }
2157 if (flag2)
2158 {
2159 sb.Draw(TextureAssets.Cursors[cursorSlot].Value, vector + vector2 + Vector2.One, null, color.MultiplyRGB(new Color(0.2f, 0.2f, 0.2f, 0.5f)), rot, origin, scale * 1.1f, SpriteEffects.None, 0f);
2160 }
2161 if (flag3)
2162 {
2163 sb.Draw(TextureAssets.Cursors[cursorSlot].Value, vector + vector2, null, color, rot, origin, scale, SpriteEffects.None, 0f);
2164 }
2165 }
2166}
void Draw(Texture2D texture, Vector2 position, Color color)
static float Lerp(float value1, float value2, float amount)
Definition MathHelper.cs:53
static float WrapAngle(float angle)
Definition MathHelper.cs:87
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
static float Min(float value1, float value2)
Definition MathHelper.cs:36
static void DrawString(this SpriteBatch spriteBatch, DynamicSpriteFont spriteFont, string text, Vector2 position, Color color)
static bool IsLinux
Definition Platform.cs:23
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
void AddRange(IEnumerable< KeyValuePair< TKey, TValue > > collection)
void Add(TKey key, TValue value)
virtual ? PropertyDescriptor Find(string name, bool ignoreCase)
static PropertyDescriptorCollection GetProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static CultureInfo InvariantCulture
static DirectoryInfo CreateDirectory(string path)
Definition Directory.cs:28
static bool Exists([NotNullWhen(true)] string? path)
Definition Directory.cs:43
static double Cos(double d)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static double Atan2(double y, double x)
static double Sqrt(double d)
static decimal Round(decimal d)
Definition Math.cs:1096
static double Log(double d)
static double Abs(double value)
static double Sin(double a)
const double PI
Definition Math.cs:16
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static RuntimeAssembly GetExecutingAssembly(ref StackCrawlMark stackMark)
Definition Assembly.cs:198
static int NewDust(Vector2 Position, int Width, int Height, int Type, float SpeedX=0f, float SpeedY=0f, int Alpha=0, Color newColor=default(Color), float Scale=1f)
Definition Dust.cs:73
static Asset< DynamicSpriteFont > DeathText
Definition FontAssets.cs:12
static Asset< DynamicSpriteFont > MouseText
Definition FontAssets.cs:10
static Asset< Texture2D > SettingsPanel
static Asset< Texture2D > InventoryBack13
static Asset< Texture2D > BlackTile
static Asset< Texture2D >[] Cursors
static int NewGore(Vector2 Position, Vector2 Velocity, int Type, float Scale=1f)
Definition Gore.cs:1288
static double time
Definition Main.cs:1284
static int maxTilesY
Definition Main.cs:1116
static Gore[] gore
Definition Main.cs:1687
static bool dayTime
Definition Main.cs:1282
static float UIScale
Definition Main.cs:2624
static Vector2 DrawThickCursor(bool smart=false)
Definition Main.cs:45092
static Vector2 screenPosition
Definition Main.cs:1715
static int maxTilesX
Definition Main.cs:1114
static SpriteViewMatrix GameViewMatrix
Definition Main.cs:227
static UnifiedRandom rand
Definition Main.cs:1387
static bool ThickMouse
Definition Main.cs:2666
static int mouseY
Definition Main.cs:606
static int mouseX
Definition Main.cs:604
static Dust[] dust
Definition Main.cs:1677
static Vector2 DrawColorCodedStringWithShadow(SpriteBatch spriteBatch, DynamicSpriteFont font, TextSnippet[] snippets, Vector2 position, float rotation, Vector2 origin, Vector2 baseScale, out int hoveredSnippet, float maxWidth=-1f, float spread=2f)
static List< TextSnippet > ParseMessage(string text, Color baseColor)
static void ShowDirectoryCreationFailError(Exception exception, string folderPath)
delegate void LaserLineFraming(int stage, Vector2 currentPosition, float distanceLeft, Rectangle lastFrame, out float distanceCovered, out Rectangle frame, out Vector2 origin, out Color color)
static void Swap< T >(ref T t1, ref T t2)
Definition Utils.cs:141
static Vector2D RotatedBy(this Vector2D spinningpoint, double radians, Vector2D center=default(Vector2D))
Definition Utils.cs:1142
static Vector2 Vector2FromElipse(Vector2 angleVector, Vector2 elipseSizes)
Definition Utils.cs:609
static Vector2 ZW(this Vector4 vec)
Definition Utils.cs:1381
static void DrawCursorSingle(SpriteBatch sb, Color color, float rot=float.NaN, float scale=1f, Vector2 manualPosition=default(Vector2), int cursorSlot=0, int specialMode=0)
Definition Utils.cs:2111
static double Lerp(double value1, double value2, double amount)
Definition Utils.cs:64
static float Remap(float fromValue, float fromMin, float fromMax, float toMin, float toMax, bool clamped=true)
Definition Utils.cs:233
static Point16 ToTileCoordinates16(this Vector2D vec)
Definition Utils.cs:1241
static Regex _substitutionRegex
Definition Utils.cs:51
static float NextFloat(this UnifiedRandom random, FloatRange range)
Definition Utils.cs:810
static Vector2 RotatedByRandom(this Vector2 spinninpoint, double maxRadians)
Definition Utils.cs:1164
static Vector2 TopRight(this Rectangle r)
Definition Utils.cs:983
static Vector3 XZW(this Vector4 vec)
Definition Utils.cs:1386
static int[] CoinsSplit(long count)
Definition Utils.cs:665
static bool WithinRange(this Vector2 Origin, Vector2 Target, float MaxRange)
Definition Utils.cs:1371
static Vector2 DirectionTo(this Vector2 Origin, Vector2 Target)
Definition Utils.cs:1361
static bool TryCreatingDirectory(string folderPath)
Definition Utils.cs:754
static Vector2 Center(this Rectangle r)
Definition Utils.cs:998
static bool IntersectsConeFastInaccurate(this Rectangle targetRect, Vector2 coneCenter, float coneLength, float coneRotation, float maximumAngle)
Definition Utils.cs:1072
static Vector2 RandomVector2(UnifiedRandom random, float min, float max)
Definition Utils.cs:1823
static int ToInt(this bool value)
Definition Utils.cs:1425
static List< int > GetTrueIndexes(params bool[][] arrays)
Definition Utils.cs:1515
static Vector2 Size(this Texture2D tex)
Definition Utils.cs:918
static string ReadEmbeddedResource(string path)
Definition Utils.cs:1957
static string FormatWith(string original, object obj)
Definition Utils.cs:739
const ulong RANDOM_MASK
Definition Utils.cs:57
static float WrappedLerp(float value1, float value2, float percent)
Definition Utils.cs:193
static void DrawSplicedPanel(SpriteBatch sb, Texture2D texture, int x, int y, int w, int h, int leftEnd, int rightEnd, int topEnd, int bottomEnd, Color c)
Definition Utils.cs:1964
delegate bool TileActionAttempt(int x, int y)
static void WriteVector2(this BinaryWriter bb, Vector2 v)
Definition Utils.cs:930
static Vector2 rotateTowards(Vector2 currentPosition, Vector2 currentVelocity, Vector2 targetPosition, float maxChange)
Definition Utils.cs:1344
static bool IsPowerOfTwo(int x)
Definition Utils.cs:74
static Rectangle Modified(this Rectangle r, int x, int y, int w, int h)
Definition Utils.cs:1067
static void DrawInvBG(SpriteBatch sb, Rectangle R, Color c=default(Color))
Definition Utils.cs:1921
static void DrawRectForTilesInWorld(SpriteBatch spriteBatch, Rectangle rect, Color color)
Definition Utils.cs:2080
static bool PressingShift(this KeyboardState kb)
Definition Utils.cs:1538
static Dictionary< DynamicSpriteFont, float[]> charLengths
Definition Utils.cs:49
static Color MultiplyRGB(this Color firstColor, Color secondColor)
Definition Utils.cs:1396
static Vector2 NextVector2Circular(this UnifiedRandom r, float circleHalfWidth, float circleHalfHeight)
Definition Utils.cs:845
static Vector2D ToVector2D(this Point16 p)
Definition Utils.cs:1210
static Vector2 NextVector2FromRectangle(this UnifiedRandom r, Rectangle rect)
Definition Utils.cs:835
static string[] WordwrapString(string text, DynamicSpriteFont font, int maxWidth, int maxLines, out int lineAmount)
Definition Utils.cs:522
static Vector2 ReadPackedVector2(this BinaryReader bb)
Definition Utils.cs:951
static int Count< T >(this T[] arr, T value)
Definition Utils.cs:1525
static Vector2 NextVector2CircularEdge(this UnifiedRandom r, float circleHalfWidth, float circleHalfHeight)
Definition Utils.cs:850
static void DrawInvBG(SpriteBatch sb, float x, float y, float w, float h, Color c=default(Color))
Definition Utils.cs:1926
static int RandomInt(ref ulong seed, int min, int max)
Definition Utils.cs:1665
static Rectangle Frame(this Texture2D tex, int horizontalFrames=1, int verticalFrames=1, int frameX=0, int frameY=0, int sizeOffsetX=0, int sizeOffsetY=0)
Definition Utils.cs:898
static Vector2 BottomLeft(this Rectangle r)
Definition Utils.cs:988
static Vector2 OriginFlip(this Rectangle rect, Vector2 origin, SpriteEffects effects)
Definition Utils.cs:905
static R[] MapArray< T, R >(T[] array, Func< T, R > mapper)
Definition Utils.cs:1556
static Vector2 BottomRight(this Rectangle r)
Definition Utils.cs:993
static Vector2D RandomVector2D(UnifiedRandom random, double min, double max)
Definition Utils.cs:1828
static void PoofOfSmoke(Vector2 position)
Definition Utils.cs:695
static int RandomInt(ref ulong seed, int max)
Definition Utils.cs:1648
static double GetLerpValue(double from, double to, double t, bool clamped=false)
Definition Utils.cs:325
static float RandomFloat(ref ulong seed)
Definition Utils.cs:1643
static bool deepCompare(this int[] firstArray, int[] secondArray)
Definition Utils.cs:1478
static int RandomConsecutive(double random, int odds)
Definition Utils.cs:1818
static Color ReadRGB(this BinaryReader bb)
Definition Utils.cs:941
static string[] ConvertMonoArgsToDotNet(string[] brokenArgs)
Definition Utils.cs:374
static float AngleFrom(this Vector2 Origin, Vector2 Target)
Definition Utils.cs:1339
static Vector2 ToRotationVector2(this float f)
Definition Utils.cs:1126
static Vector2 Left(this Rectangle r)
Definition Utils.cs:958
static float Distance(this Rectangle r, Vector2 point)
Definition Utils.cs:1008
static ChaseResults GetChaseResults(Vector2 chaserPosition, float chaserSpeed, Vector2 runnerPosition, Vector2 runnerVelocity)
Definition Utils.cs:247
static void WriteRGB(this BinaryWriter bb, Color c)
Definition Utils.cs:923
static float NextFloatDirection(this UnifiedRandom r)
Definition Utils.cs:805
static void DrawBorderStringFourWay(SpriteBatch sb, DynamicSpriteFont font, string text, float x, float y, Color textColor, Color borderColor, Vector2 origin, float scale=1f)
Definition Utils.cs:1857
static bool PlotTileLine(Vector2D start, Vector2D end, double width, TileActionAttempt plot)
Definition Utils.cs:1677
static bool FloatIntersect(float r1StartX, float r1StartY, float r1Width, float r1Height, float r2StartX, float r2StartY, float r2Width, float r2Height)
Definition Utils.cs:627
static string Hex3(this Color color)
Definition Utils.cs:1406
static bool PlotLine(int x0, int y0, int x1, int y1, TileActionAttempt plot, bool jump=true)
Definition Utils.cs:1576
static T NextFromList< T >(this UnifiedRandom random, params T[] objs)
Definition Utils.cs:815
static float AngleTowards(this float curAngle, float targetAngle, float maxChange)
Definition Utils.cs:1459
static Vector2 Round(Vector2 input)
Definition Utils.cs:69
static int RandomNext(ref ulong seed, int bits)
Definition Utils.cs:1632
static bool PlotLine(Point p0, Point p1, TileActionAttempt plot, bool jump=true)
Definition Utils.cs:1571
static void DrawInvBG(SpriteBatch sb, int x, int y, int w, int h, Color c=default(Color))
Definition Utils.cs:1931
static T NextFromCollection< T >(this UnifiedRandom random, List< T > objs)
Definition Utils.cs:820
static float GetLerpValue(float from, float to, float t, bool clamped=false)
Definition Utils.cs:203
static bool DoesFitInCone(Vector2 point, Vector2 coneCenter, float coneLength, float coneRotation, float maximumAngle)
Definition Utils.cs:1110
static float Turn01ToCyclic010(float value)
Definition Utils.cs:161
static Rectangle OffsetSize(this Rectangle rect, int xSize, int ySize)
Definition Utils.cs:882
static Vector2 ClosestPointInRect(this Rectangle r, Vector2 point)
Definition Utils.cs:1045
static long CoinsCombineStacks(out bool overFlowing, params long[] coinCounts)
Definition Utils.cs:679
static Vector2 TopLeft(this Rectangle r)
Definition Utils.cs:978
static float DistanceSQ(this Vector2 Origin, Vector2 Target)
Definition Utils.cs:1356
static bool RectangleLineCollision(Vector2 rectTopLeft, Vector2 rectBottomRight, Vector2 lineStart, Vector2 lineEnd)
Definition Utils.cs:1304
static Vector2 Bottom(this Rectangle r)
Definition Utils.cs:973
static Vector2 Size(this Asset< Texture2D > tex)
Definition Utils.cs:889
static double UnclampedSmoothStep(double min, double max, double x)
Definition Utils.cs:98
static Vector2 Floor(this Vector2 vec)
Definition Utils.cs:1169
static Vector2 DirectionFrom(this Vector2 Origin, Vector2 Target)
Definition Utils.cs:1366
static Vector2 DrawBorderString(SpriteBatch sb, string text, Vector2 pos, Color color, float scale=1f, float anchorx=0f, float anchory=0f, int maxCharactersDisplayed=-1)
Definition Utils.cs:1891
static float SmoothStep(float min, float max, float x)
Definition Utils.cs:83
static double SmoothStep(double min, double max, double x)
Definition Utils.cs:88
static Vector2 RotatedBy(this Vector2 spinningpoint, double radians, Vector2 center=default(Vector2))
Definition Utils.cs:1131
static Dictionary< string, string > ParseArguements(string[] args)
Definition Utils.cs:103
static bool IndexInRange< T >(this T[] t, int index)
Definition Utils.cs:1834
static void DrawRect(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color)
Definition Utils.cs:2095
static float Distance(this Vector2 Origin, Vector2 Target)
Definition Utils.cs:1351
static void DrawLine(SpriteBatch spriteBatch, Point start, Point end, Color color)
Definition Utils.cs:2044
static float NextFloat(this UnifiedRandom r)
Definition Utils.cs:800
const ulong RANDOM_MULTIPLIER
Definition Utils.cs:53
const ulong RANDOM_ADD
Definition Utils.cs:55
static void DrawRectangle(SpriteBatch sb, Vector2 start, Vector2 end, Color colorStart, Color colorEnd, float width)
Definition Utils.cs:2002
static Vector2 NextVector2Square(this UnifiedRandom r, float min, float max)
Definition Utils.cs:830
static Rectangle Frame(this Asset< Texture2D > tex, int horizontalFrames=1, int verticalFrames=1, int frameX=0, int frameY=0, int sizeOffsetX=0, int sizeOffsetY=0)
Definition Utils.cs:873
static bool PlotTileArea(int x, int y, TileActionAttempt plot)
Definition Utils.cs:1765
static bool PlotTileLine(Vector2 start, Vector2 end, float width, TileActionAttempt plot)
Definition Utils.cs:1670
static int ModulusPositive(this int myInteger, int modulusNumber)
Definition Utils.cs:1434
static Vector2 NextVector2Unit(this UnifiedRandom r, float startRotation=0f, float rotationRange=(float) Math.PI *2f)
Definition Utils.cs:840
static void DrawLaser(SpriteBatch sb, Texture2D tex, Vector2 start, Vector2 end, Vector2 scale, LaserLineFraming framing)
Definition Utils.cs:2010
static bool HasNaNs(this Vector2 vec)
Definition Utils.cs:1176
static int Height(this Asset< Texture2D > asset)
Definition Utils.cs:864
static bool PlotTileTale(Vector2D start, Vector2D end, double width, TileActionAttempt plot)
Definition Utils.cs:1712
static Vector2 Right(this Rectangle r)
Definition Utils.cs:963
static Point16 ToTileCoordinates16(this Vector2 vec)
Definition Utils.cs:1236
static Vector2 SafeNormalize(this Vector2 v, Vector2 defaultValue)
Definition Utils.cs:1278
static void DrawSettingsPanel(SpriteBatch spriteBatch, Vector2 position, float width, Color color)
Definition Utils.cs:1985
static Color MultiplyRGBA(this Color firstColor, Color secondColor)
Definition Utils.cs:1401
static Vector2 ReadVector2(this BinaryReader bb)
Definition Utils.cs:946
static float AngleTo(this Vector2 Origin, Vector2 Target)
Definition Utils.cs:1334
static T Max< T >(params T[] args)
Definition Utils.cs:408
static Point ToTileCoordinates(this Vector2D vec)
Definition Utils.cs:1253
static void DrawLine(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color colorStart, Color colorEnd, float width)
Definition Utils.cs:2064
static void DrawPanel(Texture2D texture, int edgeWidth, int edgeShove, SpriteBatch spriteBatch, Vector2 position, float width, Color color)
Definition Utils.cs:1995
static Vector2 ToVector2(this Point p)
Definition Utils.cs:1194
static Color ColorLerp_BlackToWhite(float percent)
Definition Utils.cs:59
static Vector2D ToVector2D(this Point p)
Definition Utils.cs:1204
static void DrawRect(SpriteBatch spriteBatch, Vector2 topLeft, Vector2 topRight, Vector2 bottomRight, Vector2 bottomLeft, Color color)
Definition Utils.cs:2103
static Vector2 FactorAcceleration(Vector2 currentVelocity, float timeToInterception, Vector2 descendOfProjectile, int framesOfLenience)
Definition Utils.cs:299
static byte[] ToByteArray(this string str)
Definition Utils.cs:793
static int Width(this Asset< Texture2D > asset)
Definition Utils.cs:855
static T Clamp< T >(T value, T min, T max)
Definition Utils.cs:148
static void TrimTextIfNeeded(ref string text, DynamicSpriteFont font, float scale, float maxWidth)
Definition Utils.cs:723
static Vector2 ToWorldCoordinates(this Point p, float autoAddX=8f, float autoAddY=8f)
Definition Utils.cs:1216
static string PrettifyPercentDisplay(float percent, string originalFormat)
Definition Utils.cs:717
static Vector3 YZW(this Vector4 vec)
Definition Utils.cs:1391
delegate Color ColorLerpMethod(float percent)
static float AngleLerp(this float curAngle, float targetAngle, float amount)
Definition Utils.cs:1439
static Vector2 GetDayTimeAsDirectionIn24HClock()
Definition Utils.cs:364
static List< int > GetTrueIndexes(this bool[] array)
Definition Utils.cs:1502
static Vector2 ToWorldCoordinates(this Point16 p, float autoAddX=8f, float autoAddY=8f)
Definition Utils.cs:1221
static Vector2 ClosestPointOnLine(this Vector2 P, Vector2 A, Vector2 B)
Definition Utils.cs:1287
static void OpenFolder(string folderPath)
Definition Utils.cs:772
static void DrawRectForTilesInWorld(SpriteBatch spriteBatch, Point start, Point end, Color color)
Definition Utils.cs:2085
static Vector2 ToScreenPosition(this Vector2 worldPosition)
Definition Utils.cs:712
static float GetDayTimeAs24FloatStartingFromMidnight()
Definition Utils.cs:355
static T SelectRandom< T >(UnifiedRandom random, params T[] choices)
Definition Utils.cs:1852
static float PingPongFrom01To010(float value)
Definition Utils.cs:166
static Vector2 Top(this Rectangle r)
Definition Utils.cs:968
static bool PressingControl(this KeyboardState kb)
Definition Utils.cs:1547
static Point ToPoint(this Vector2D v)
Definition Utils.cs:1265
static void WritePackedVector2(this BinaryWriter bb, Vector2 v)
Definition Utils.cs:936
static string Hex4(this Color color)
Definition Utils.cs:1411
static void ClampWithinWorld(ref int minX, ref int minY, ref int maxX, ref int maxY, bool lastValuesInclusiveToIteration=false, int fluffX=0, int fluffY=0)
Definition Utils.cs:238
static Vector2 GetDayTimeAsDirectionIn24HClock(float timeFrom0To24)
Definition Utils.cs:369
static ulong RandomNextSeed(ulong seed)
Definition Utils.cs:1638
static void DrawRect(SpriteBatch spriteBatch, Rectangle rect, Color color)
Definition Utils.cs:2090
static bool IntersectsConeSlowMoreAccurate(this Rectangle targetRect, Vector2 coneCenter, float coneLength, float coneRotation, float maximumAngle)
Definition Utils.cs:1084
static List< List< TextSnippet > > WordwrapStringSmart(string text, Color c, DynamicSpriteFont font, int maxWidth, int maxLines)
Definition Utils.cs:438
static long CoinsCount(out bool overFlowing, Item[] inv, params int[] ignoreSlots)
Definition Utils.cs:636
static bool Between(this Vector2 vec, Vector2 minimum, Vector2 maximum)
Definition Utils.cs:1185
static int Next(this UnifiedRandom random, IntRange range)
Definition Utils.cs:825
static Vector2 DrawBorderStringBig(SpriteBatch spriteBatch, string text, Vector2 pos, Color color, float scale=1f, float anchorx=0f, float anchory=0f, int maxCharactersDisplayed=-1)
Definition Utils.cs:1903
static Vector2 XY(this Vector4 vec)
Definition Utils.cs:1376
static Vector2 RotateRandom(this Vector2 spinninpoint, double maxRadians)
Definition Utils.cs:1329
static Point ToTileCoordinates(this Vector2 vec)
Definition Utils.cs:1248
static float MultiLerp(float percent, params float[] floats)
Definition Utils.cs:180
static Vector2 ToVector2(this Point16 p)
Definition Utils.cs:1199
static Vector2 Size(this Rectangle r)
Definition Utils.cs:1003
static bool SolveQuadratic(float a, float b, float c, out float result1, out float result2)
Definition Utils.cs:306
static float LineRectangleDistance(Rectangle rect, Vector2 lineStart, Vector2 lineEnd)
Definition Utils.cs:421
static Point ToPoint(this Vector2 v)
Definition Utils.cs:1260
static Rectangle CenteredRectangle(Vector2 center, Vector2 size)
Definition Utils.cs:604
static float ToRotation(this Vector2 v)
Definition Utils.cs:1121
static float UnclampedSmoothStep(float min, float max, float x)
Definition Utils.cs:93
static bool PlotLine(Point16 p0, Point16 p1, TileActionAttempt plot, bool jump=true)
Definition Utils.cs:1566
static int ToDirectionInt(this bool value)
Definition Utils.cs:1416
static Vector2D ToVector2D(this Vector2 v)
Definition Utils.cs:1272
static Vector2 MoveTowards(this Vector2 currentPosition, Vector2 targetPosition, float maxAmountAllowedToMove)
Definition Utils.cs:1226
static void DrawSettings2Panel(SpriteBatch spriteBatch, Vector2 position, float width, Color color)
Definition Utils.cs:1990
static void DrawLine(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color)
Definition Utils.cs:2049
const long MaxCoins
Definition Utils.cs:47
static bool InWorld(int x, int y, int fluff=0)
Definition WorldGen.cs:5816
static Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491
static float Dot(Vector2 value1, Vector2 value2)
Definition Vector2.cs:121
static Vector2 Transform(Vector2 position, Matrix matrix)
Definition Vector2.cs:317
static float DistanceSquared(Vector2 value1, Vector2 value2)
Definition Vector2.cs:107
static float Distance(Vector2 value1, Vector2 value2)
Definition Vector2.cs:91