Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Overlayer/Core/Drawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Overlayer.Core;

public static class Drawer {
public static CodeEditor.CodeEditor codeEditor = new("OverlayerCodeEditor",
new CodeTheme() {
new CodeTheme {
background = "#333333",
linenumbg = "#222222",
color = "#FFFFFF",
Expand Down Expand Up @@ -104,7 +104,7 @@ static Drawer() {
} else if(name.EndsWith("Hex")) {
try {
var val = (string)TagManager.tags[name].Tag.Getter.Invoke(null,
new object[] { "-1", Overlayer.Utils.Extensions.DefaultTrimStr });
["-1", Overlayer.Utils.Extensions.DefaultTrimStr]);
str = str.Replace("{" + match.Groups[1].Value + "}",
"<color=#" + val + ">{" + match.Groups[1].Value + "}</color>");
} catch {
Expand Down Expand Up @@ -543,7 +543,8 @@ public static bool DrawEnum<T>(ref T @enum) where T : Enum {
public static bool DrawEase(ref Ease ease) {
string[] names = Enum.GetNames(typeof(Ease));
int current = (int)ease;
Texture2D[] easeImages = new Texture2D[] { null, Icon_EaseLinear, Icon_EaseInSine, Icon_EaseOutSine, Icon_EaseInOutSine, Icon_EaseInQuad, Icon_EaseOutQuad, Icon_EaseInOutQuad, Icon_EaseInCubic, Icon_EaseOutCubic, Icon_EaseInOutCubic, Icon_EaseInQuart, Icon_EaseOutQuart, Icon_EaseInOutQuart, Icon_EaseInQuint, Icon_EaseOutQuint, Icon_EaseInOutQuint, Icon_EaseInExpo, Icon_EaseOutExpo, Icon_EaseInOutExpo, Icon_EaseInCirc, Icon_EaseOutCirc, Icon_EaseInOutCirc, Icon_EaseInElastic, Icon_EaseOutElastic, Icon_EaseInOutElastic, Icon_EaseInBack, Icon_EaseOutBack, Icon_EaseInOutBack, Icon_EaseInBounce, Icon_EaseOutBounce, Icon_EaseInOutBounce };
Texture2D[] easeImages = [null, Icon_EaseLinear, Icon_EaseInSine, Icon_EaseOutSine, Icon_EaseInOutSine, Icon_EaseInQuad, Icon_EaseOutQuad, Icon_EaseInOutQuad, Icon_EaseInCubic, Icon_EaseOutCubic, Icon_EaseInOutCubic, Icon_EaseInQuart, Icon_EaseOutQuart, Icon_EaseInOutQuart, Icon_EaseInQuint, Icon_EaseOutQuint, Icon_EaseInOutQuint, Icon_EaseInExpo, Icon_EaseOutExpo, Icon_EaseInOutExpo, Icon_EaseInCirc, Icon_EaseOutCirc, Icon_EaseInOutCirc, Icon_EaseInElastic, Icon_EaseOutElastic, Icon_EaseInOutElastic, Icon_EaseInBack, Icon_EaseOutBack, Icon_EaseInOutBack, Icon_EaseInBounce, Icon_EaseOutBounce, Icon_EaseInOutBounce
];
bool result = SelectionPopup(ref current, names, easeImages, "");
if(result) {
ease = (Ease)current;
Expand Down Expand Up @@ -663,7 +664,7 @@ private static bool DrawExprInternal<T>(Texture2D icon, string label, string id,
Color old = GUI.color;
bool isExpr = value.IsExpr;
GUILayout.BeginHorizontal();
if(icon != null) {
if(icon) {
GUILayout.Label(icon);
GUILayout.Space(4);
}
Expand Down
4 changes: 2 additions & 2 deletions Overlayer/Core/ImageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class ImageManager {
public static bool Initialized { get; private set; } = false;
public static Sprite DefaultSprite {
get {
if(_defaultSprite == null) {
if(_defaultSprite is null) {
CreateDefault();
}
return _defaultSprite;
Expand All @@ -23,7 +23,7 @@ public static Sprite DefaultSprite {

static void CreateDefault() {
Texture2D tex = new(2, 2);
tex.SetPixels(new Color[4] { Color.clear, Color.clear, Color.clear, Color.clear });
tex.SetPixels([Color.clear, Color.clear, Color.clear, Color.clear]);
tex.Apply();
_defaultSprite = Sprite.Create(tex, new Rect(0, 0, 2, 2), new Vector2(0.5f, 0.5f));
}
Expand Down
2 changes: 1 addition & 1 deletion Overlayer/Core/ProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static bool OrderByDrag(int from, int to) {
}

public static void Destroy(OverlayerProfile profile) {
if(profile == null || !Profiles.Contains(profile)) {
if(profile is null || !Profiles.Contains(profile)) {
return;
}

Expand Down
135 changes: 67 additions & 68 deletions Overlayer/Core/Scripting/Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,11 @@ public static bool TranspilerWithArgs(Engine engine, string typeColonMethodName,
harmony.Patch(target, transpiler: new HarmonyMethod(wrap));
return true;
}*/
[Api("getLanguage", RequireTypes = new[] { typeof(SystemLanguage) })]
[Api("getLanguage", RequireTypes = [typeof(SystemLanguage)])]
public static SystemLanguage GetLanguage(Engine engine) => RDString.language;
[Api("ease", RequireTypes = new Type[] { typeof(Ease) })]
[Api("ease", RequireTypes = [typeof(Ease)])]
public static float EasedValue(Engine engine, Ease ease, float lifetime) => DOVirtual.EasedValue(0, 1, lifetime, ease);
[Api("easeColor", RequireTypes = new Type[] { typeof(Color) })]
[Api("easeColor", RequireTypes = [typeof(Color)])]
public static Color EasedColor(Engine engine, Color color, Ease ease, float lifetime) => color * DOVirtual.EasedValue(0, 1, lifetime, ease);
[Api("easeColorFromTo")]
public static Color EasedColor(Engine engine, Color from, Color to, Ease ease, float lifetime) => from + ((to - from) * DOVirtual.EasedValue(0, 1, lifetime, ease));
Expand Down Expand Up @@ -446,7 +446,7 @@ public static OverlayerText CreateTextFromJson(string json, OverlayerProfile pro
var config = TextConfigImporter.Import(token);
return profile.ObjectManager.Create(config);
}
[Api("createTexture", RequireTypes = new[] { typeof(Texture2D) })]
[Api("createTexture", RequireTypes = [typeof(Texture2D)])]
public static Texture2D CreateTexture(string imagePath) {
if(!File.Exists(imagePath)) {
return null;
Expand Down Expand Up @@ -477,10 +477,10 @@ public static void PlaySound(string path) {
};
AudioPlayer.Play(sound);
}
[Api("loadAudio", Comment = new string[]
{
[Api("loadAudio", Comment =
[
"Load Audio(UnityEngine.AudioClip) With Callback (.mp3, .ogg, .aiff, .wav)"
}, RequireTypes = new Type[] { typeof(AudioClip) })]
], RequireTypes = [typeof(AudioClip)])]
public static void LoadAudio(string path, JsValue callback) {
if(callback is not Function func) {
return;
Expand All @@ -489,16 +489,16 @@ public static void LoadAudio(string path, JsValue callback) {
FIWrapper fi = new(func);
AudioPlayer.LoadAudio(path, ac => fi.Call(ac));
}
[Api("setAudio", Comment = new string[]
{
[Api("setAudio", Comment =
[
"Set Audio(UnityEngine.AudioClip) With Callback (.mp3, .ogg, .aiff, .wav)"
}, RequireTypes = new Type[] { typeof(AudioSource) })]
], RequireTypes = [typeof(AudioSource)])]
public static void SetAudio(string path, AudioSource source) => AudioPlayer.LoadAudio(path, clip => source.clip = clip);
public class On {
[Api("rewind", Comment = new[]
{
[Api("rewind", Comment =
[
"On ADOFAI Rewind (Level Start, Scene Moved, etc..)"
})]
])]
public static void Rewind(Engine engine, JsValue func) {
if(func is not Function fi) {
return;
Expand All @@ -507,10 +507,10 @@ public static void Rewind(Engine engine, JsValue func) {
FIWrapper wrapper = new(fi);
harmony.Postfix(MiscUtils.MethodByName("scrController:Awake_Rewind"), new Action(() => wrapper.Call()));
}
[Api("hit", Comment = new[]
{
[Api("hit", Comment =
[
"On Tile Hit"
})]
])]
public static void Hit(Engine engine, JsValue func) {
if(func is not Function fi) {
return;
Expand All @@ -519,10 +519,10 @@ public static void Hit(Engine engine, JsValue func) {
FIWrapper wrapper = new(fi);
harmony.Postfix(MiscUtils.MethodByName("scrController:Hit"), new Action(() => wrapper.Call()));
}
[Api("dead", Comment = new[]
{
[Api("dead", Comment =
[
"On Dead"
})]
])]
public static void Dead(Engine engine, JsValue func) {
if(func is not Function fi) {
return;
Expand All @@ -535,10 +535,10 @@ public static void Dead(Engine engine, JsValue func) {
}
}));
}
[Api("fail", Comment = new[]
{
[Api("fail", Comment =
[
"On Fail"
})]
])]
public static void Fail(Engine engine, JsValue func) {
if(func is not Function fi) {
return;
Expand All @@ -547,10 +547,10 @@ public static void Fail(Engine engine, JsValue func) {
FIWrapper wrapper = new(fi);
harmony.Postfix(MiscUtils.MethodByName("scrController:FailAction"), new Action<scrController>(__instance => wrapper.Call()));
}
[Api("clear", Comment = new[]
{
[Api("clear", Comment =
[
"On Clear"
})]
])]
public static void Clear(Engine engine, JsValue func) {
if(func is not Function fi) {
return;
Expand All @@ -564,26 +564,26 @@ public static void Clear(Engine engine, JsValue func) {
}));
}
#region KeyEvents
[Api("anyKey", Comment = new[]
{
[Api("anyKey", Comment =
[
"On Any Key Pressed"
})]
])]
public static void AnyKey(Engine engine, JsValue func) {
if(func is not Function fi) {
return;
}

FIWrapper wrapper = new(fi);
harmony.Postfix(MiscUtils.MethodByName("scrController:Update"), new Action(() => {
harmony.Postfix(MiscUtils.MethodByName("scrController:Update"), () => {
if(Input.anyKey) {
wrapper.Call();
}
}));
});
}
[Api("anyKeyDown", Comment = new[]
{
[Api("anyKeyDown", Comment =
[
"On Any Key Down"
})]
])]
public static void AnyKeyDown(Engine engine, JsValue func) {
if(func is not Function fi) {
return;
Expand All @@ -596,75 +596,74 @@ public static void AnyKeyDown(Engine engine, JsValue func) {
}
}));
}
[Api("key", Comment = new[]
{
[Api("key", Comment =
[
"On Key Pressed"
})]
])]
public static void Key(Engine engine, KeyCode key, JsValue func) {
if(func is not Function fi) {
return;
}

FIWrapper wrapper = new(fi);
harmony.Postfix(MiscUtils.MethodByName("scrController:Update"), new Action(() => {
harmony.Postfix(MiscUtils.MethodByName("scrController:Update"), () => {
if(Input.GetKey(key)) {
wrapper.Call();
}
}));
});
}
[Api("keyUp", Comment = new[]
{
[Api("keyUp", Comment =
[
"On Key Up"
})]
])]
public static void KeyUp(Engine engine, KeyCode key, JsValue func) {
if(func is not Function fi) {
return;
}

FIWrapper wrapper = new(fi);
harmony.Postfix(MiscUtils.MethodByName("scrController:Update"), new Action(() => {
harmony.Postfix(MiscUtils.MethodByName("scrController:Update"), () => {
if(Input.GetKeyUp(key)) {
wrapper.Call();
}
}));
});
}
[Api("keyDown", Comment = new[]
{
[Api("keyDown", Comment =
[
"On Key Down"
})]
])]
public static void KeyDown(Engine engine, KeyCode key, JsValue func) {
if(func is not Function fi) {
return;
}

FIWrapper wrapper = new(fi);
harmony.Postfix(MiscUtils.MethodByName("scrController:Update"), new Action(() => {
harmony.Postfix(MiscUtils.MethodByName("scrController:Update"), () => {
if(Input.GetKeyDown(key)) {
wrapper.Call();
}
}));
});
}
#endregion
}
[Api(Comment = new string[]
{
"These Methods Are Recommended To Use In 'On.rewind' Callback."
},
RequireTypes = new Type[]
{
typeof(SpriteRenderer),
[Api(Comment =
[
"These Methods Are Recommended To Use In 'On.rewind' Callback."
],
RequireTypes =
[
typeof(SpriteRenderer),
typeof(scrHitTextMesh),
typeof(HitMargin),
typeof(SfxSound),
typeof(HitSound)
})]
])]
public class Adofai {
[Api("getPlanetRenderer", ReturnComment = "UnityEngine.SpriteRenderer (Planet SpriteRenderer)")]
public static SpriteRenderer GetPlanetRenderer(scrPlanet planet, PlanetRenderer planetrenderer) => planet.GetOrAddRenderer(planetrenderer);
[Api("scalePlanet")]
public static void ScalePlanet(PlanetRenderer planetrender, Vector2 vec) {
ScaleAll(new[]
{
ScaleAll([
(mr.GetValue(planetrender.sprite) as SpriteRenderer)?.transform,
planetrender.coreParticles?.transform,
planetrender.tailParticles?.transform,
Expand All @@ -675,8 +674,8 @@ public static void ScalePlanet(PlanetRenderer planetrender, Vector2 vec) {
planetrender.faceSprite?.transform,
planetrender.faceDetails?.transform,
planetrender.faceHolder?.transform,
planetrender.samuraiSprite?.transform,
}, vec);
planetrender.samuraiSprite?.transform
], vec);
}
[Api("setDiscordRp")]
public static void SetDiscordRp(string title, string state, string details) {
Expand All @@ -702,10 +701,10 @@ public static void SetAutoText(string text) {
betaText.gameObject.SetActive(true);
betaText.GetComponent<UnityEngine.UI.Text>().text = text;
}
[Api("configAutoText", ParamComment = new string[]
{
[Api("configAutoText", ParamComment =
[
"UnityEngine.UI.Text Callback"
})]
])]
public static void ConfigAutoText(Engine engine, JsValue configFunc) {
if(configFunc is not Function func) {
return;
Expand Down Expand Up @@ -740,7 +739,7 @@ public static void ConfigTiles(Engine engine, JsValue configFunc) {
FIWrapper wrapper = new(func);
var list = scrLevelMaker.instance.listFloors;
for(int i = 0; i < list.Count; i++) {
wrapper.Call(wrapper.args.Length == 1 ? new object[] { list[i] } : new object[] { i, list[i] });
wrapper.Call(wrapper.args.Length == 1 ? [list[i]] : [i, list[i]]);
}
}
[Api("setJudgeText")]
Expand All @@ -755,10 +754,10 @@ public static void SetJudgeText(HitMargin hitMargin, string text) {
}
}));
}
[Api("configJudgeText", ParamComment = new string[]
{
[Api("configJudgeText", ParamComment =
[
"scrHitTextMesh Callback"
})]
])]
public static void ConfigJudgeText(Engine engine, HitMargin hitMargin, JsValue configFunc) {
if(configFunc is not Function func) {
return;
Expand Down Expand Up @@ -805,7 +804,7 @@ private static void InjectAutoTextUpdate() {
return;
}

harmony.Patch(typeof(scrShowIfDebug).GetMethod("Update", (BindingFlags)15420), new HarmonyMethod(EmitUtils.Wrap(new Func<bool>(() => false))));
harmony.Patch(typeof(scrShowIfDebug).GetMethod("Update", (BindingFlags)15420), new HarmonyMethod(EmitUtils.Wrap(() => false)));
autoTextInjected = true;
}
private static void InjectStartRadius() {
Expand Down
6 changes: 3 additions & 3 deletions Overlayer/Core/Scripting/JSNet/Utils/EmitUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class EmitUtils {

static EmitUtils() {
accessIgnored = [];
iact = typeof(IgnoresAccessChecksToAttribute).GetConstructor(new Type[1] { typeof(string) });
iact = typeof(IgnoresAccessChecksToAttribute).GetConstructor([typeof(string)]);
AssemblyName assemblyName = new("JSNet.Utils.RuntimeAssembly");
ass = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
mod = ass.DefineDynamicModule(assemblyName.Name);
Expand Down Expand Up @@ -65,7 +65,7 @@ public static void Convert(this ILGenerator il, Type to) {
il.Emit(OpCodes.Conv_R8);
break;
case TypeCode.String:
il.Emit(OpCodes.Call, typeof(Convert).GetMethod("ToString", new Type[1] { to }));
il.Emit(OpCodes.Call, typeof(Convert).GetMethod("ToString", [to]));
break;
case TypeCode.DBNull:
case TypeCode.Decimal:
Expand Down Expand Up @@ -115,7 +115,7 @@ public static void IgnoreAccessCheck(Type type) {

private static CustomAttributeBuilder GetIACT(string name) {
ConstructorInfo con = iact;
object[] constructorArgs = new string[1] { name };
object[] constructorArgs = [name];
return new CustomAttributeBuilder(con, constructorArgs);
}

Expand Down
Loading