Skip to content

Commit 2127fed

Browse files
committed
reformat code
1 parent 9a1fac1 commit 2127fed

File tree

8 files changed

+470
-469
lines changed

8 files changed

+470
-469
lines changed

Source/.editorconfig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ csharp_space_around_binary_operators = before_and_after
44
csharp_using_directive_placement = outside_namespace:silent
55
csharp_prefer_simple_using_statement = true:suggestion
66
csharp_prefer_braces = true:silent
7-
csharp_style_namespace_declarations = block_scoped:silent
7+
csharp_style_namespace_declarations = file_scoped:none
88
csharp_style_expression_bodied_methods = false:silent
99
csharp_style_expression_bodied_constructors = false:silent
1010
csharp_style_expression_bodied_operators = false:silent
@@ -26,7 +26,7 @@ csharp_style_deconstructed_variable_declaration = true:suggestion
2626
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
2727
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
2828
csharp_prefer_static_local_function = true:suggestion
29-
csharp_new_line_before_open_brace = accessors,anonymous_methods,anonymous_types,lambdas,methods,properties,types
29+
csharp_new_line_before_open_brace = accessors, anonymous_methods, anonymous_types, lambdas, methods, properties, types
3030
csharp_new_line_before_else = false
3131
csharp_new_line_before_catch = false
3232
csharp_new_line_before_finally = false
@@ -53,31 +53,31 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
5353

5454
dotnet_naming_symbols.interface.applicable_kinds = interface
5555
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
56-
dotnet_naming_symbols.interface.required_modifiers =
56+
dotnet_naming_symbols.interface.required_modifiers =
5757

5858
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
5959
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
60-
dotnet_naming_symbols.types.required_modifiers =
60+
dotnet_naming_symbols.types.required_modifiers =
6161

6262
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
6363
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
64-
dotnet_naming_symbols.non_field_members.required_modifiers =
64+
dotnet_naming_symbols.non_field_members.required_modifiers =
6565

6666
# Naming styles
6767

6868
dotnet_naming_style.begins_with_i.required_prefix = I
69-
dotnet_naming_style.begins_with_i.required_suffix =
70-
dotnet_naming_style.begins_with_i.word_separator =
69+
dotnet_naming_style.begins_with_i.required_suffix =
70+
dotnet_naming_style.begins_with_i.word_separator =
7171
dotnet_naming_style.begins_with_i.capitalization = pascal_case
7272

73-
dotnet_naming_style.pascal_case.required_prefix =
74-
dotnet_naming_style.pascal_case.required_suffix =
75-
dotnet_naming_style.pascal_case.word_separator =
73+
dotnet_naming_style.pascal_case.required_prefix =
74+
dotnet_naming_style.pascal_case.required_suffix =
75+
dotnet_naming_style.pascal_case.word_separator =
7676
dotnet_naming_style.pascal_case.capitalization = pascal_case
7777

78-
dotnet_naming_style.pascal_case.required_prefix =
79-
dotnet_naming_style.pascal_case.required_suffix =
80-
dotnet_naming_style.pascal_case.word_separator =
78+
dotnet_naming_style.pascal_case.required_prefix =
79+
dotnet_naming_style.pascal_case.required_suffix =
80+
dotnet_naming_style.pascal_case.word_separator =
8181
dotnet_naming_style.pascal_case.capitalization = pascal_case
8282
dotnet_style_operator_placement_when_wrapping = beginning_of_line
8383
tab_width = 4

Source/IconMaterialPatch.cs

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -24,77 +24,79 @@ You should have received a copy of the GNU General Public License
2424
using KSPBuildTools;
2525
using UnityEngine;
2626

27-
namespace Shabby
28-
{
29-
[HarmonyPatch(typeof(PartLoader), "SetPartIconMaterials")]
30-
class SetPartIconMaterialsPatch
31-
{
32-
static MethodInfo mInfo_ShaderFind = AccessTools.Method(typeof(Shader), nameof(Shader.Find));
27+
namespace Shabby;
3328

34-
static MethodInfo mInfo_FindOverrideIconShader =
35-
AccessTools.Method(typeof(SetPartIconMaterialsPatch), nameof(FindOverrideIconShader));
29+
[HarmonyPatch(typeof(PartLoader), "SetPartIconMaterials")]
30+
internal class SetPartIconMaterialsPatch
31+
{
32+
private static MethodInfo mInfo_ShaderFind =
33+
AccessTools.Method(typeof(Shader), nameof(Shader.Find));
3634

37-
static Shader FindOverrideIconShader(Material material) =>
38-
Shabby.TryFindIconShader(material.shader.name) ?? Shabby.FindShader("KSP/ScreenSpaceMask");
35+
private static MethodInfo mInfo_FindOverrideIconShader =
36+
AccessTools.Method(typeof(SetPartIconMaterialsPatch), nameof(FindOverrideIconShader));
3937

40-
/// <summary>
41-
/// The stock method iterates through every material in the icon prefab and replaces some
42-
/// stock shaders with 'ScreenSpaceMask'-prefixed ones. All shaders not explicitly checked,
43-
/// including custom shaders, are replaced with 'KSP/ScreenSpaceMask'.
44-
/// This transpiler inserts logic to check for additional replacements.
45-
/// </summary>
46-
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
47-
{
48-
var code = instructions.ToList();
49-
object locMaterial = null;
38+
private static Shader FindOverrideIconShader(Material material) =>
39+
Shabby.TryFindIconShader(material.shader.name) ?? Shabby.FindShader("KSP/ScreenSpaceMask");
5040

51-
for (var i = 0; i < code.Count; ++i) {
52-
// Material material = sharedMaterials[j];
53-
// IL_002C ldloc.3
54-
// IL_002D ldloc.s 4
55-
// IL_002F ldelem.ref
56-
// IL_0030 stloc.s 6
57-
if (locMaterial == null
58-
&& code[i].opcode == OpCodes.Ldloc_3
59-
&& code[i + 1].opcode == OpCodes.Ldloc_S
60-
&& code[i + 2].opcode == OpCodes.Ldelem_Ref
61-
&& code[i + 3].opcode == OpCodes.Stloc_S) {
62-
// Extract the stack index of the material local.
63-
locMaterial = code[i + 3].operand;
64-
}
41+
/// <summary>
42+
/// The stock method iterates through every material in the icon prefab and replaces some
43+
/// stock shaders with 'ScreenSpaceMask'-prefixed ones. All shaders not explicitly checked,
44+
/// including custom shaders, are replaced with 'KSP/ScreenSpaceMask'.
45+
/// This transpiler inserts logic to check for additional replacements.
46+
/// </summary>
47+
private static IEnumerable<CodeInstruction> Transpiler(
48+
IEnumerable<CodeInstruction> instructions)
49+
{
50+
var code = instructions.ToList();
51+
object locMaterial = null;
6552

66-
// material2 = new Material(Shader.Find("KSP/ScreenSpaceMask"));
67-
// IL_0191 ldstr "KSP/ScreenSpaceMask"
68-
// IL_0196 call class UnityEngine.Shader UnityEngine.Shader::Find(string)
69-
// IL_019D newobj instance void UnityEngine.Material::.ctor(class UnityEngine.Shader)
70-
// IL_01A2 stloc.s 7
71-
if (code[i].Is(OpCodes.Ldstr, "KSP/ScreenSpaceMask") && code[i + 1].Calls(mInfo_ShaderFind)) {
72-
// Replace the call to Shader.Find with FindOverrideIconShader(material).
73-
if (locMaterial == null) break;
74-
code[i].opcode = OpCodes.Ldloc_S;
75-
code[i].operand = locMaterial;
76-
code[i + 1].operand = mInfo_FindOverrideIconShader;
77-
return code;
78-
}
53+
for (var i = 0; i < code.Count; ++i) {
54+
// Material material = sharedMaterials[j];
55+
// IL_002C ldloc.3
56+
// IL_002D ldloc.s 4
57+
// IL_002F ldelem.ref
58+
// IL_0030 stloc.s 6
59+
if (locMaterial == null
60+
&& code[i].opcode == OpCodes.Ldloc_3
61+
&& code[i + 1].opcode == OpCodes.Ldloc_S
62+
&& code[i + 2].opcode == OpCodes.Ldelem_Ref
63+
&& code[i + 3].opcode == OpCodes.Stloc_S) {
64+
// Extract the stack index of the material local.
65+
locMaterial = code[i + 3].operand;
7966
}
8067

81-
Log.Error("failed to patch part icon shader replacement");
82-
return code;
68+
// material2 = new Material(Shader.Find("KSP/ScreenSpaceMask"));
69+
// IL_0191 ldstr "KSP/ScreenSpaceMask"
70+
// IL_0196 call class UnityEngine.Shader UnityEngine.Shader::Find(string)
71+
// IL_019D newobj instance void UnityEngine.Material::.ctor(class UnityEngine.Shader)
72+
// IL_01A2 stloc.s 7
73+
if (code[i].Is(OpCodes.Ldstr, "KSP/ScreenSpaceMask") &&
74+
code[i + 1].Calls(mInfo_ShaderFind)) {
75+
// Replace the call to Shader.Find with FindOverrideIconShader(material).
76+
if (locMaterial == null) break;
77+
code[i].opcode = OpCodes.Ldloc_S;
78+
code[i].operand = locMaterial;
79+
code[i + 1].operand = mInfo_FindOverrideIconShader;
80+
return code;
81+
}
8382
}
83+
84+
Log.Error("failed to patch part icon shader replacement");
85+
return code;
8486
}
87+
}
8588

86-
[HarmonyPatch(TargetType, "GetIconShader")]
87-
class KSPCFGetIconShaderPatch
88-
{
89-
const string TargetType = "KSPCommunityFixes.Performance.PartParsingPerf";
89+
[HarmonyPatch(TargetType, "GetIconShader")]
90+
internal class KSPCFGetIconShaderPatch
91+
{
92+
private const string TargetType = "KSPCommunityFixes.Performance.PartParsingPerf";
9093

91-
static bool Prepare() => AccessTools.TypeByName(TargetType) != null;
94+
private static bool Prepare() => AccessTools.TypeByName(TargetType) != null;
9295

93-
static void Postfix(string materialShaderName, ref Shader __result)
94-
{
95-
if (__result.name != "KSP/ScreenSpaceMask") return;
96-
if (Shabby.TryFindIconShader(materialShaderName) is not Shader iconShader) return;
97-
__result = iconShader;
98-
}
96+
private static void Postfix(string materialShaderName, ref Shader __result)
97+
{
98+
if (__result.name != "KSP/ScreenSpaceMask") return;
99+
if (Shabby.TryFindIconShader(materialShaderName) is not Shader iconShader) return;
100+
__result = iconShader;
99101
}
100-
}
102+
}

0 commit comments

Comments
 (0)