using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using MioGame;
using MioGame.Shader;
using MioModLoader;
using MioModdingApi;
using On.MioGame;
using On.MioGame.GlobalFunctions.game;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
[assembly: AssemblyCompany("ColorMio")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+289f4aba56ff0c4df38bc3ed22cb692cf4ecfe30")]
[assembly: AssemblyProduct("ColorMio")]
[assembly: AssemblyTitle("ColorMio")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
internal record GradientPoint(float r, float g, float b, float t);
namespace ColorMio;
public class ColorMio : Mod
{
public Vec_float_3 color;
public Vec_float_3 outlineColor;
public Vec_float_3 intensity;
public float currentTick;
public float maxTick = 300f;
private readonly string[] colors = new string[3] { "red", "green", "blue" };
private static ModMenuPage? modPage;
private static Dictionary<string, NumberOption> tints = new Dictionary<string, NumberOption>();
private static Dictionary<string, NumberOption> outlines = new Dictionary<string, NumberOption>();
private static NumberOption? rainbowDuration;
private static ChoiceOption? gradientOption;
private Dictionary<string, GradientPoint[]> gradientConfig = new Dictionary<string, GradientPoint[]>();
private List<string> gradientChoices;
private readonly Vec_float_3 zeroVect;
private readonly Vec_float_3 origColor;
public override void Initialize()
{
Hooks();
LoadGradients();
ConnectMenus();
}
public void ConnectMenus()
{
modPage = ModMenu.RegisterMod((Mod)(object)this, "Color Mio", "Color Mio");
try
{
RegisterRGB("tint", "Tint", 1, "The {0} value of the tentacle color.", tints, delegate(int value, string c)
{
SetColorChannel(ref color, c, value);
});
RegisterRGB("int", "Intensity", 1, "The {0} intensity value of the tentacle color.", tints, delegate(int value, string c)
{
SetColorChannel(ref intensity, c, value);
});
gradientOption = modPage.RegisterChoice("gradient_choice", "Gradient", (IReadOnlyList<string>)gradientChoices, 0, "Choose a gradient to cycle through");
rainbowDuration = modPage.RegisterNumber("rainbow_duration", "Rainbow duration", 1, 20, 1, (int?)5, "How long to cycle through all the colours when rainbow gradient is selected", "{0} seconds");
gradientOption.Changed += delegate
{
updateMaxTick();
};
rainbowDuration.Changed += delegate
{
updateMaxTick();
};
updateMaxTick();
}
catch (Exception ex)
{
((Mod)this).LogMessage("Could not initialize options: " + ex);
}
void updateMaxTick()
{
if (gradientOption.Value == "rainbow")
{
maxTick = rainbowDuration.Value * 60;
}
else if (gradientOption.Value != "none")
{
maxTick = gradientConfig[gradientOption.Value][^1].t;
}
}
}
private void Hooks()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
render_tentacle_2.Prefix += new orig_render_tentacle_2(Render_tentacle_prefix);
fixed_update.Prefix += new orig_fixed_update(Fixed_update_Prefix);
}
private void LoadGradients()
{
string text = Path.Combine(((Mod)this).GetModConfigPath(), "gradients.json");
if (!File.Exists(text))
{
Directory.CreateDirectory(Path.GetDirectoryName(text));
Dictionary<string, GradientPoint[]> value = new Dictionary<string, GradientPoint[]>();
File.WriteAllText(text, JsonSerializer.Serialize(value, new JsonSerializerOptions
{
WriteIndented = true
}));
}
try
{
Dictionary<string, GradientPoint[]> dictionary = JsonSerializer.Deserialize<Dictionary<string, GradientPoint[]>>(File.ReadAllText(text));
if (dictionary != null)
{
gradientConfig = dictionary;
gradientChoices.AddRange(gradientConfig.Keys);
}
}
catch (Exception ex)
{
((Mod)this).LogMessage("could not read " + text + ", using defaults: " + ex.Message);
try
{
File.Copy(text, text + ".broken", overwrite: true);
}
catch
{
}
}
}
private static Vec_float_3 Lerp_Vectors(Vec_float_3 a, Vec_float_3 b, float r)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
return new Vec_float_3
{
Base = new _vec_storage_float_3
{
x = a.x * (1f - r) + b.x * r,
y = a.y * (1f - r) + b.y * r,
z = a.z * (1f - r) + b.z * r
}
};
}
private static Vec_float_3 Gradient_Point_as_Vec(GradientPoint gradient)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
return new Vec_float_3
{
Base = new _vec_storage_float_3
{
x = gradient.r,
y = gradient.g,
z = gradient.b
}
};
}
private static Vec_float_3 Lerp_Gradient(GradientPoint[] gradient, float t)
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
int num = -1;
for (int i = 0; i < gradient.Length - 1; i++)
{
if (gradient[i].t <= t && t < gradient[i + 1].t)
{
num = i;
break;
}
}
if (num == -1)
{
return Gradient_Point_as_Vec(gradient[0]);
}
GradientPoint gradientPoint = gradient[num];
GradientPoint gradientPoint2 = gradient[num + 1];
float r = (t - gradientPoint.t) / (gradientPoint2.t - gradientPoint.t);
return Lerp_Vectors(Gradient_Point_as_Vec(gradientPoint), Gradient_Point_as_Vec(gradientPoint2), r);
}
private unsafe void Fixed_update_Prefix(Game* __this)
{
currentTick = (currentTick + 1f) % maxTick;
}
private static Vec_float_3 HueToRGB(float hue)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
return new Vec_float_3
{
Base = new _vec_storage_float_3
{
x = f_func(5f, hue),
y = f_func(3f, hue),
z = f_func(1f, hue)
}
};
static float f_func(float n, float h)
{
return 1f - Math.Max(0f, Math.Min(k_func(n, h), Math.Min(4f - k_func(n, h), 1f)));
}
static float k_func(float n, float h)
{
return (n + h / 60f) % 6f;
}
}
private unsafe void Render_tentacle_prefix(uint idx, Tentacle* t, Vec_float_3 chain_u, Vec_float_3 chain_v, Array_Vec_float_3* chain, Array_Shader__Tentacle_vertex* vertices, Array_unsigned_int* indices, Tentacle_consts* consts)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
ref Vec_float_3 reference = ref ((Tentacle_consts)consts).tint;
Vec_float_3 val = default(Vec_float_3);
ChoiceOption? obj = gradientOption;
string text = ((obj != null) ? obj.Value : null) ?? "none";
val = ((text == "none") ? MultiplyVector(color, 0.003921569f) : ((!(text == "rainbow")) ? MultiplyVector(Lerp_Gradient(gradientConfig[text], currentTick), 0.003921569f) : HueToRGB(currentTick / maxTick * 360f)));
reference = MultiplyVector(val, MultiplyVector(DivideVector(1f, origColor), intensity));
}
private unsafe void Mio_hair_outline_color_Hook(orig_mio_hair_outline_color orig, Vec_float_3* retBuffer)
{
ref Vec_float_3 reference = ref Unsafe.AsRef<Vec_float_3>((void*)retBuffer);
reference.x = outlineColor.x;
reference.y = outlineColor.y;
reference.z = outlineColor.z;
}
private void PrintVector(ref Vec_float_3 vec)
{
((Mod)this).LogMessage("x: " + vec.x);
((Mod)this).LogMessage("y: " + vec.y);
((Mod)this).LogMessage("z: " + vec.z);
}
private static Vec_float_3 MultiplyVector(Vec_float_3 vec, float multiplier)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
vec.x *= multiplier;
vec.y *= multiplier;
vec.z *= multiplier;
return vec;
}
private static Vec_float_3 MultiplyVector(Vec_float_3 vec1, Vec_float_3 vec2)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
vec1.x *= vec2.x;
vec1.y *= vec2.y;
vec1.z *= vec2.z;
return vec1;
}
private static Vec_float_3 DivideVector(float numerator, Vec_float_3 vec)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
vec.x = numerator / vec.x;
vec.y = numerator / vec.y;
vec.z = numerator / vec.z;
return vec;
}
private static void SetColorChannel(ref Vec_float_3 color, string channel, int value)
{
switch (channel)
{
case "red":
color.x = value;
break;
case "green":
color.y = value;
break;
case "blue":
color.z = value;
break;
}
}
private void RegisterRGB(string id, string title, int initialValue, string description, Dictionary<string, NumberOption> collection, Action<int, string> changed)
{
if (modPage == null)
{
return;
}
string[] array = colors;
foreach (string c in array)
{
tints[c] = modPage.RegisterNumber(c + "_" + id, title + " (" + c + ")", 0, 255, 1, (int?)initialValue, string.Format(description, c), "{0}");
tints[c].Changed += delegate(int value)
{
changed(value, c);
};
changed(tints[c].Value, c);
}
}
public ColorMio()
{
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
int num = 2;
List<string> list = new List<string>(num);
CollectionsMarshal.SetCount(list, num);
Span<string> span = CollectionsMarshal.AsSpan(list);
int num2 = 0;
span[num2] = "none";
num2++;
span[num2] = "rainbow";
gradientChoices = list;
zeroVect = new Vec_float_3
{
Base = new _vec_storage_float_3
{
x = 0f,
y = 0f,
z = 0f
}
};
origColor = new Vec_float_3
{
Base = new _vec_storage_float_3
{
x = 0.9411765f,
y = 0.83137256f,
z = 0.5019608f
}
};
((Mod)this)..ctor();
}
}