Skip to content

Commit

Permalink
clean up formatting a little
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzo committed Jul 27, 2024
1 parent c5681db commit fee6a8d
Show file tree
Hide file tree
Showing 158 changed files with 1,729 additions and 1,193 deletions.
9 changes: 9 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
BasedOnStyle: LLVM
UseTab: Never
IndentWidth: 2
TabWidth: 2
ColumnLimit: 80
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
AlignAfterOpenBracket: BlockIndent
AlignOperands: DontAlign
8 changes: 4 additions & 4 deletions common/Bonelab/Bonelab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@

namespace Sst.Utilities {
public class Bonelab {
public static void DockToWrist(GameObject gameObject,
bool rightHand = false) {
public static void
DockToWrist(GameObject gameObject, bool rightHand = false) {
var physicsRig = LevelHooks.RigManager.physicsRig;
var hand = rightHand ? physicsRig.rightHand : physicsRig.leftHand;
gameObject.transform.SetParent(hand.transform);
gameObject.transform.localPosition = new Vector3(-0.31f, 0.3f, 0f);
gameObject.transform.localRotation = Quaternion.Euler(32f, 4f, 3f);
}

public static TextMeshPro CreateTextOnWrist(string name,
bool rightHand = false) {
public static TextMeshPro
CreateTextOnWrist(string name, bool rightHand = false) {
var text = new GameObject(name);
var tmp = text.AddComponent<TextMeshPro>();
tmp.alignment = TextAlignmentOptions.BottomRight;
Expand Down
9 changes: 6 additions & 3 deletions common/Bonelab/HundredPercent/AchievementTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ private static void Unlock(string id) {

private static async Task SaveUnlockedToFile() {
byte[] bytes = Encoding.UTF8.GetBytes(string.Join("\n", Unlocked));
using (var stream = new FileStream(SAVE_PATH, FileMode.Create,
FileAccess.Write, FileShare.Read,
bufferSize: 4096, useAsync: true)) {
using (
var stream = new FileStream(
SAVE_PATH, FileMode.Create, FileAccess.Write, FileShare.Read,
bufferSize: 4096, useAsync: true
)
) {
await stream.WriteAsync(bytes, 0, bytes.Length);
};
}
Expand Down
10 changes: 6 additions & 4 deletions common/Bonelab/HundredPercent/CapsuleTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ private static void Unlock(string id) {
return;

Unlocked.Add(id);
OnUnlock?.Invoke(id,
AssetWarehouse.Instance.GetCrate(new Barcode(id))?.Title);
OnUnlock?.Invoke(
id, AssetWarehouse.Instance.GetCrate(new Barcode(id))?.Title
);
}

[HarmonyPatch(typeof(PlayerUnlocks),
nameof(PlayerUnlocks.IncrementUnlockForBarcode))]
[HarmonyPatch(
typeof(PlayerUnlocks), nameof(PlayerUnlocks.IncrementUnlockForBarcode)
)]
class PlayerUnlocks_IncrementUnlockForBarcode_Patch {
[HarmonyPostfix()]
internal static void Postfix(string barcode) {
Expand Down
9 changes: 5 additions & 4 deletions common/Bonelab/HundredPercent/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public void SendStateIfChanged(GameState state = null) {
SendState(state);
}

private bool IsStateDifferentFromLastSent(GameState state) =>
_lastSentState == null || state.isComplete != _lastSentState.isComplete
private bool IsStateDifferentFromLastSent(GameState state
) => _lastSentState == null || state.isComplete != _lastSentState.isComplete
|| state.isLoading != _lastSentState.isLoading
|| state.levelBarcode != _lastSentState.levelBarcode
|| state.capsulesUnlocked != _lastSentState.capsulesUnlocked
Expand Down Expand Up @@ -98,8 +98,9 @@ private void SendStateAfterUpdate(Action<GameState> onStateCreated) {
onStateCreated(state);
SendStateIfChanged(state);
};
MelonEvents.OnLateUpdate.Subscribe(onAfterUpdate,
unsubscribeOnFirstInvocation: true);
MelonEvents.OnLateUpdate.Subscribe(
onAfterUpdate, unsubscribeOnFirstInvocation: true
);
}

public void Dispose() { _ipcServer.Dispose(); }
Expand Down
17 changes: 9 additions & 8 deletions common/Bonelab/Il2CppNullable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ static Il2CppNullable() {
TClassPtr = Il2CppClassPointerStore<T>.NativeClassPtr;

uint align = 0;
hasValueOffset = (int)IL2CPP.il2cpp_field_get_offset(
IL2CPP.GetIl2CppField(classPtr, "hasValue"));
hasValueOffset = (int
)IL2CPP.il2cpp_field_get_offset(IL2CPP.GetIl2CppField(classPtr, "hasValue")
);
valueSize = IL2CPP.il2cpp_class_value_size(TClassPtr, ref align);
marshalSize = Marshal.SizeOf(typeof(T));
}
Expand Down Expand Up @@ -59,8 +60,8 @@ public unsafe Il2CppNullable(T? nullable) {
IntPtr obj = IL2CPP.il2cpp_object_new(classPtr);

uint gcHandle = RuntimeSpecificsStore.ShouldUseWeakRefs(classPtr)
? IL2CPP.il2cpp_gchandle_new_weakref(obj, false)
: IL2CPP.il2cpp_gchandle_new(obj, false);
? IL2CPP.il2cpp_gchandle_new_weakref(obj, false)
: IL2CPP.il2cpp_gchandle_new(obj, false);
AccessTools.Field(typeof(Il2CppObjectBase), "myGcHandle")
.SetValue(this, gcHandle);

Expand All @@ -85,8 +86,8 @@ public unsafe Il2CppNullable(T value) {
*(byte *)(dataPtr + hasValueOffset) = 1;

uint gcHandle = RuntimeSpecificsStore.ShouldUseWeakRefs(classPtr)
? IL2CPP.il2cpp_gchandle_new_weakref(obj, false)
: IL2CPP.il2cpp_gchandle_new(obj, false);
? IL2CPP.il2cpp_gchandle_new_weakref(obj, false)
: IL2CPP.il2cpp_gchandle_new(obj, false);

AccessTools.Field(typeof(Il2CppObjectBase), "myGcHandle")
.SetValue(this, gcHandle);
Expand All @@ -95,8 +96,8 @@ public unsafe Il2CppNullable(T value) {
private static unsafe void Set<U>(IntPtr tgt, U value)
where U : unmanaged { *(U *)tgt = value; }

public static implicit
operator Il2CppSystem.Nullable<T>(Il2CppNullable<T> me) {
public static implicit operator Il2CppSystem.Nullable<T>(Il2CppNullable<T> me
) {
return new Il2CppSystem.Nullable<T>(me.Pointer);
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/Bonelab/LevelHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ static class LevelHooks {

private static Scene _loadingScene;

private static void SafeInvoke(string name, Action<LevelCrate> action,
LevelCrate level) {
private static void
SafeInvoke(string name, Action<LevelCrate> action, LevelCrate level) {
try {
action?.Invoke(level);
} catch (Exception ex) {
Expand Down
2 changes: 1 addition & 1 deletion common/Bonelab/Levels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class Barcodes {
CAMPAIGN_LEVEL_BARCODES.ToHashSet();

public static bool IsMenu(string barcode) => barcode == Barcodes.MAIN_MENU
|| barcode == Barcodes.VOID_G114;
|| barcode == Barcodes.VOID_G114;

public class LabworksBarcodes {
public const string BREAKROOM =
Expand Down
17 changes: 9 additions & 8 deletions common/Boneworks/Il2CppNullable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ static Il2CppNullable() {
TClassPtr = Il2CppClassPointerStore<T>.NativeClassPtr;

uint align = 0;
hasValueOffset = (int)IL2CPP.il2cpp_field_get_offset(
IL2CPP.GetIl2CppField(classPtr, "has_value"));
hasValueOffset = (int
)IL2CPP.il2cpp_field_get_offset(IL2CPP.GetIl2CppField(classPtr, "has_value")
);
valueSize = IL2CPP.il2cpp_class_value_size(TClassPtr, ref align);
marshalSize = Marshal.SizeOf(typeof(T));
}
Expand Down Expand Up @@ -59,8 +60,8 @@ public unsafe Il2CppNullable(T? nullable) {
IntPtr obj = IL2CPP.il2cpp_object_new(classPtr);

uint gcHandle = RuntimeSpecificsStore.ShouldUseWeakRefs(classPtr)
? IL2CPP.il2cpp_gchandle_new_weakref(obj, false)
: IL2CPP.il2cpp_gchandle_new(obj, false);
? IL2CPP.il2cpp_gchandle_new_weakref(obj, false)
: IL2CPP.il2cpp_gchandle_new(obj, false);
AccessTools.Field(typeof(Il2CppObjectBase), "myGcHandle")
.SetValue(this, gcHandle);

Expand All @@ -85,8 +86,8 @@ public unsafe Il2CppNullable(T value) {
*(byte *)(dataPtr + hasValueOffset) = 1;

uint gcHandle = RuntimeSpecificsStore.ShouldUseWeakRefs(classPtr)
? IL2CPP.il2cpp_gchandle_new_weakref(obj, false)
: IL2CPP.il2cpp_gchandle_new(obj, false);
? IL2CPP.il2cpp_gchandle_new_weakref(obj, false)
: IL2CPP.il2cpp_gchandle_new(obj, false);

AccessTools.Field(typeof(Il2CppObjectBase), "myGcHandle")
.SetValue(this, gcHandle);
Expand All @@ -95,8 +96,8 @@ public unsafe Il2CppNullable(T value) {
private static unsafe void Set<U>(IntPtr tgt, U value)
where U : unmanaged { *(U *)tgt = value; }

public static implicit
operator Il2CppSystem.Nullable<T>(Il2CppNullable<T> me) {
public static implicit operator Il2CppSystem.Nullable<T>(Il2CppNullable<T> me
) {
return new Il2CppSystem.Nullable<T>(me.Pointer);
}
}
Expand Down
108 changes: 64 additions & 44 deletions common/Utilities/Colliders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public static class Colliders {
private static Assembly _unityAssembly;
public static Assembly UnityAssembly {
get => _unityAssembly ??
(_unityAssembly = AppDomain.CurrentDomain.GetAssemblies().First(
asm => asm.GetType("UnityEngine.Collider") != null));
(_unityAssembly = AppDomain.CurrentDomain.GetAssemblies().First(
asm => asm.GetType("UnityEngine.Collider") != null
));
}

public static int NonPhysicalLayerMask = LayerMask.GetMask(
Expand Down Expand Up @@ -98,42 +99,51 @@ public static bool IsColliderPhysical(Collider collider) {
new LayerMask() { value = 0x7fffffff };

public static class DebugColliderPrefabs {
public static GameObject BOX =
Geometry.CreatePrefabCube("DebugCollider_Box", Color.magenta, -0.5f,
0.5f, -0.5f, 0.5f, -0.5f, 0.5f);
public static GameObject BOX = Geometry.CreatePrefabCube(
"DebugCollider_Box", Color.magenta, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f,
0.5f
);
public static GameObject SPHERE = Geometry.CreatePrefabSphere(
"DebugCollider_Sphere", Color.magenta, 0.5f, 2);
"DebugCollider_Sphere", Color.magenta, 0.5f, 2
);
public static GameObject CYLINDER = Geometry.CreatePrefabUnclosedCylinder(
"DebugCollider_Cylinder", Color.magenta, 0.5f, 20, 0.5f, -0.5f);
"DebugCollider_Cylinder", Color.magenta, 0.5f, 20, 0.5f, -0.5f
);
}

public static IEnumerable<Collider> AllColliders() {
foreach (var rootObject in Utilities.Unity.RootObjects()) {
var colliders = new List<Collider>();
Utilities.Unity.FindDescendantComponentsOfType(
ref colliders, rootObject.transform, true);
ref colliders, rootObject.transform, true
);
foreach (var unknownCollider in colliders) {
yield return ToUnderlyingType(unknownCollider);
}
}
}

public static void VisualizeAllIn(GameObject ancestor,
bool visualizeTriggers = false) =>
VisualizeAllIn(ancestor, DEFAULT_LAYER_MASK, visualizeTriggers);
public static void VisualizeAllIn(GameObject ancestor, LayerMask layerMask,
bool visualizeTriggers = false) {
DebugColliderPrefabs.BOX =
Geometry.CreatePrefabCube("DebugCollider_Box", Color.magenta, -0.5f,
0.5f, -0.5f, 0.5f, -0.5f, 0.5f);
public static void VisualizeAllIn(
GameObject ancestor, bool visualizeTriggers = false
) => VisualizeAllIn(ancestor, DEFAULT_LAYER_MASK, visualizeTriggers);
public static void VisualizeAllIn(
GameObject ancestor, LayerMask layerMask, bool visualizeTriggers = false
) {
DebugColliderPrefabs.BOX = Geometry.CreatePrefabCube(
"DebugCollider_Box", Color.magenta, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f,
0.5f
);
DebugColliderPrefabs.SPHERE = Geometry.CreatePrefabSphere(
"DebugCollider_Sphere", Color.magenta, 0.5f, 2);
"DebugCollider_Sphere", Color.magenta, 0.5f, 2
);
DebugColliderPrefabs.CYLINDER = Geometry.CreatePrefabUnclosedCylinder(
"DebugCollider_Cylinder", Color.magenta, 0.5f, 20, 0.5f, -0.5f);
"DebugCollider_Cylinder", Color.magenta, 0.5f, 20, 0.5f, -0.5f
);

var colliders = new List<Collider>();
Unity.FindDescendantComponentsOfType(ref colliders, ancestor.transform,
true);
Unity.FindDescendantComponentsOfType(
ref colliders, ancestor.transform, true
);
foreach (var unknownCollider in colliders) {
var collider = ToUnderlyingType(unknownCollider);
var isMatchingLayer = (layerMask.value & collider.gameObject.layer) != 0;
Expand All @@ -147,19 +157,20 @@ public static void VisualizeAllIn(GameObject ancestor, LayerMask layerMask,
// Mesh colliders only have collision in the direction of their faces
// but convex mesh colliders are solid.
if (collider is MeshCollider && !((MeshCollider)collider).convex) {
Visualize(collider, _colorHighlighter,
Utilities.Shaders.HighlightShader);
Visualize(
collider, _colorHighlighter, Utilities.Shaders.HighlightShader
);
} else {
Visualize(collider, _colorDefault, Utilities.Shaders.DefaultShader);
}
}
}

public static ColliderVisualization
Visualize(Collider collider, Color color, Shader shader,
bool watchForChanges = true,
Func<ColliderVisualization, bool> onUpdate = null,
Transform parent = null) {
public static ColliderVisualization Visualize(
Collider collider, Color color, Shader shader,
bool watchForChanges = true,
Func<ColliderVisualization, bool> onUpdate = null, Transform parent = null
) {
var castedCollider = ToUnderlyingType(collider);

if (parent == null)
Expand All @@ -184,17 +195,20 @@ public static ColliderVisualization

case CapsuleCollider capsuleCollider: {
visualization = new GameObject("SpeedrunTools_DebugCollider_Capsule");
var cylinder = GameObject.Instantiate(DebugColliderPrefabs.CYLINDER,
visualization.transform);
var cylinder = GameObject.Instantiate(
DebugColliderPrefabs.CYLINDER, visualization.transform
);
SetMaterial(cylinder, color, shader);
cylinder.active = true;
var endA = GameObject.Instantiate(DebugColliderPrefabs.SPHERE,
visualization.transform);
var endA = GameObject.Instantiate(
DebugColliderPrefabs.SPHERE, visualization.transform
);
SetMaterial(endA, color, shader);
endA.active = true;
endA.transform.localPosition = new Vector3(0, -0.5f, 0);
var endB = GameObject.Instantiate(DebugColliderPrefabs.SPHERE,
visualization.transform);
var endB = GameObject.Instantiate(
DebugColliderPrefabs.SPHERE, visualization.transform
);
SetMaterial(endB, color, shader);
endB.active = true;
endB.transform.localPosition = new Vector3(0, 0.5f, 0);
Expand All @@ -215,7 +229,8 @@ public static ColliderVisualization

default: {
MelonLogger.Warning(
$"Cannot render collider of unsupported type: {castedCollider}");
$"Cannot render collider of unsupported type: {castedCollider}"
);
return null;
}
}
Expand Down Expand Up @@ -265,8 +280,10 @@ public void UpdateVisualization() {
}

case SphereCollider sphereCollider: {
if (!NeedsUpdate(sphereCollider.center,
new Vector3(sphereCollider.radius, 0f, 0f)))
if (!NeedsUpdate(
sphereCollider.center,
new Vector3(sphereCollider.radius, 0f, 0f)
))
break;
transform.localPosition = sphereCollider.center;
var diameter = sphereCollider.radius * 2;
Expand All @@ -275,14 +292,17 @@ public void UpdateVisualization() {
}

case CapsuleCollider capsuleCollider: {
if (!NeedsUpdate(capsuleCollider.center,
new Vector3(capsuleCollider.direction,
capsuleCollider.radius,
capsuleCollider.height)))
if (!NeedsUpdate(
capsuleCollider.center,
new Vector3(
capsuleCollider.direction, capsuleCollider.radius,
capsuleCollider.height
)
))
break;
transform.localPosition = capsuleCollider.center;
transform.localRotation =
capsuleCollider.direction == 0 ? Quaternion.Euler(0, 0, 90)
transform.localRotation = capsuleCollider.direction == 0
? Quaternion.Euler(0, 0, 90)
: capsuleCollider.direction == 2 ? Quaternion.Euler(90, 0, 0)
: Quaternion.identity;
var diameter = capsuleCollider.radius * 2;
Expand Down Expand Up @@ -321,8 +341,8 @@ private bool NeedsUpdate(Vector3 center, Vector3 other) {
}
}

private static void SetMaterial(GameObject gameObject, Color color,
Shader shader = null) {
private static void
SetMaterial(GameObject gameObject, Color color, Shader shader = null) {
var meshRenderer = gameObject.GetComponent<MeshRenderer>();
meshRenderer.shadowCastingMode =
UnityEngine.Rendering.ShadowCastingMode.Off;
Expand Down
Loading

0 comments on commit fee6a8d

Please sign in to comment.