-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.cs
More file actions
83 lines (70 loc) · 2.64 KB
/
Util.cs
File metadata and controls
83 lines (70 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using GHPC.Equipment.Optics;
using GHPC.Weapons;
using UnityEngine;
namespace CustomMissionUtility
{
internal class Util
{
public static string[] menu_screens = new string[] {
"MainMenu2_Scene",
"MainMenu2-1_Scene",
"LOADER_MENU",
"LOADER_INITIAL",
"t64_menu"
};
public static T[] AppendToArray<T>(T[] array, T new_item)
{
List<T> values = new List<T>();
foreach (T old_item in array)
{
values.Add(old_item);
}
values.Add(new_item);
return values.ToArray();
}
public static void ShallowCopy(System.Object dest, System.Object src)
{
BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
FieldInfo[] destFields = dest.GetType().GetFields(flags);
FieldInfo[] srcFields = src.GetType().GetFields(flags);
foreach (FieldInfo srcField in srcFields)
{
FieldInfo destField = destFields.FirstOrDefault(field => field.Name == srcField.Name);
if (destField != null && !destField.IsLiteral)
{
if (srcField.FieldType == destField.FieldType)
destField.SetValue(dest, srcField.GetValue(src));
}
}
}
public static UsableOptic GetDayOptic(FireControlSystem fcs)
{
if (fcs.MainOptic.slot.IsLinkedNightSight)
{
return fcs.MainOptic.slot.LinkedDaySight.PairedOptic;
}
else
{
return fcs.MainOptic;
}
}
public static void EmptyRack(GHPC.Weapons.AmmoRack rack)
{
MethodInfo removeVis = typeof(GHPC.Weapons.AmmoRack).GetMethod("RemoveAmmoVisualFromSlot", BindingFlags.Instance | BindingFlags.NonPublic);
PropertyInfo stored_clips = typeof(GHPC.Weapons.AmmoRack).GetProperty("StoredClips");
stored_clips.SetValue(rack, new List<AmmoType.AmmoClip>());
rack.SlotIndicesByAmmoType = new Dictionary<AmmoType, List<byte>>();
foreach (Transform transform in rack.VisualSlots)
{
AmmoStoredVisual vis = transform.GetComponentInChildren<AmmoStoredVisual>();
if (vis != null && vis.AmmoType != null)
{
removeVis.Invoke(rack, new object[] { transform });
}
}
}
}
}