using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using MioGame;
using MioGame.GlobalFunctions;
using MioGame.GlobalFunctions.engine;
using MioModLoader;
using MioModdingApi;
using On.MioGame;
using On.MioGame.GlobalFunctions.engine;
using On.MioGame.GlobalFunctions.game;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
[assembly: AssemblyCompany("MioBossRefightMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1e76355c40503405acb5840e643d88de30626ea9")]
[assembly: AssemblyProduct("MioBossRefightMod")]
[assembly: AssemblyTitle("MioBossRefightMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace MioBossRefightMod;
public class MioBossRefightMod : Mod
{
private const int Cond_FirstUseEver = 4;
private const int Cond_Always = 1;
private const int WindowFlags_NoDocking = 2097152;
private readonly Dictionary<string, BossInfo> Boss_Locations = new Dictionary<string, BossInfo>
{
{
"Ati",
new BossInfo(-1441f, 1703f, "BOSS:SASUKE")
},
{
"Egis",
new BossInfo(-1680f, 1539f, "BOSS:CRABASH")
},
{
"Acat",
new BossInfo(-2046f, 1868f, "BOSS:BLACKSMITH")
},
{
"Atmos",
new BossInfo(-2650f, 1413f, "BOSS:TRAPU")
},
{
"Poltergates",
new BossInfo(-2582f, 1576f, "BOSS:DOOR")
},
{
"Calderon",
new BossInfo(-3199f, 1752f, "BOSS:ZANGY")
},
{
"Ancille & Targa",
new BossInfo(-3643f, 1847f, "BOSS:TWIN_CRABASH")
},
{
"Sol & Vin",
new BossInfo(-2541f, 2309f, "BOSS:TWIN")
},
{
"Flora",
new BossInfo(-815f, 1426f, "BOSS:VINE")
},
{
"Crow",
new BossInfo(-1229f, 1638f, "BOSS:SCARECROW")
},
{
"Shii",
new BossInfo(-123f, 2420f, "BOSS:SHII")
},
{
"Friends :)",
new BossInfo(48f, 1915f, "BOSS:SPIDY")
},
{
"Nabuu",
new BossInfo(-272f, 1901f, "BOSS:BAMBY")
},
{
"Lombre",
new BossInfo(-251f, 1634f, "BOSS:DEVOURER")
},
{
"AnRa",
new BossInfo(-3215f, 482f, "BOSS:PROJEKT")
},
{
"Debby",
new BossInfo(-1647f, 440f, "BOSS:RAMBO")
},
{
"Sawlong",
new BossInfo(-1397f, 593f, "BOSS:SAW_LONGUE")
},
{
"Vlad",
new BossInfo(-916f, 464f, "BOSS:WASHING_MACHINE")
}
};
private readonly string[] Boss_rush_order = new string[15]
{
"Egis", "Acat", "Flora", "Crow", "Calderon", "Checkpoint", "Lombre", "Atmos", "Poltergates", "Nabuu",
"Checkpoint", "Friends :)", "Ancille & Targa", "Vlad", "Sol & Vin"
};
private bool _isOpen;
private bool _keybindWasDown;
private bool _pollPrimed;
private string Boss_refight_request = "";
private int Boss_refight_step = -1;
private bool Nexus_teleport = false;
private Vec_float_3 boss_camera_pos = default(Vec_float_3);
private bool Started_boss_rush = false;
private int Current_boss_index = -1;
private string boss_name = "";
private float boss_cur_health = 0f;
private float boss_max_health = 0f;
private float boss_init_max_health = 0f;
private float boss_decay_health = 0f;
private float last_hit_amount = 0f;
private bool boss_is_dead = false;
private bool died_recently = false;
private int died_recently_counter = -1;
private static ModMenuPage? modPage;
private ToggleOption? close_menu_option;
private ToggleOption? health_info_option;
private ToggleOption? heal_start_option;
private KeybindOption? menu_keybind;
private NumberOption? wait_time_option;
public override void Initialize()
{
Hooks();
ConnectMenus();
}
public void Hooks()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Expected O, but got Unknown
gui_render.Prefix += new orig_gui_render(Gui_render_Prefix);
default_boss_health_bar.Prefix += new orig_default_boss_health_bar(Boss_health_bar_prefix);
fixed_update.Prefix += new orig_fixed_update(Fixed_update_Prefix);
update_camera.Prefix += new orig_update_camera(Update_cam_prefix);
((Mod)this).LogMessage("Connected hooks");
}
public void ConnectMenus()
{
modPage = ModMenu.RegisterMod((Mod)(object)this, "Boss Refight Mod", "Boss Refight Mod Options");
close_menu_option = modPage.RegisterToggle("close_menu", "Close Menu", true, "Close the menu after starting a boss");
health_info_option = modPage.RegisterToggle("health_info", "Show boss health info", false, "Show detailed information about a boss' health in the menu");
heal_start_option = modPage.RegisterToggle("heal_start", "Heal before fights", false, "Heals you before starting a boss (not yet implemented)");
menu_keybind = modPage.RegisterKeybind("menu_keybind", "Boss fight menu", (Key)338, (Gamepad_button)0, (Mouse_button)0, "Button to open the menu", true, false);
wait_time_option = modPage.RegisterNumber("wait_time", "Wait time between bosses", 7, 20, 1, (int?)10, "How long to wait after beating a boss to move on to the next boss during boss rush", "{0}");
((Mod)this).LogMessage("Registered options");
}
private unsafe void Update_cam_prefix(Game* game)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
if (Boss_refight_step != -1 && Boss_refight_request != "")
{
Unsafe.Write(&((Game_cam)(&((Game)game).game_cam)).position, boss_camera_pos);
}
}
private void Gui_render_Prefix()
{
try
{
UpdateCursor();
if (!_isOpen)
{
return;
}
bool flag = Functions.ImGui__is_gui_disabled();
if (flag)
{
Functions.ImGui__enable_gui();
}
try
{
if (_isOpen)
{
DrawMenu();
}
}
finally
{
if (flag)
{
Functions.ImGui__disable_gui();
}
}
}
catch (Exception ex)
{
((Mod)this).LogMessage("[gui] draw error: " + ex);
}
}
private unsafe void Boss_health_bar_prefix(TNode_Boss_fight_node bf, Boss_analyzer_state* s)
{
//IL_000d: 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_0013: 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)
Val_ref data = ((Node2)((Boss_fight_node)((TNode_Boss_fight_node)(ref bf)).d).boss_node).data;
Boss* mem = (Boss*)data.mem;
boss_name = Util.MioStringToString(*((Val_ref)(ref data)).struct_name());
float num = Math.Abs(boss_cur_health - ((Rt)(&((Boss_health)(&((Boss)mem).health)).rt)).cur_health);
if ((double)num > 0.1)
{
last_hit_amount = num;
}
boss_max_health = ((Boss_health)(&((Boss)mem).health)).max_health;
boss_init_max_health = ((Boss_health)(&((Boss)mem).health)).initial_max_health;
boss_cur_health = ((Rt)(&((Boss_health)(&((Boss)mem).health)).rt)).cur_health;
boss_decay_health = ((Boss_health)(&((Boss)mem).health)).decayed_health;
bool dead = ((Rt)(&((Boss_health)(&((Boss)mem).health)).rt)).dead;
if (!boss_is_dead && dead)
{
boss_is_dead = true;
died_recently = true;
died_recently_counter = 0;
}
else if (boss_is_dead && !dead)
{
boss_is_dead = false;
}
}
private bool Start_next_boss_rush_boss()
{
Current_boss_index++;
if (Current_boss_index < Boss_rush_order.Length)
{
RequestBoss(Boss_rush_order[Current_boss_index]);
return true;
}
return false;
}
private unsafe void Fixed_update_Prefix(Game* __this)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: 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_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
PollToggle();
Handle_boss_refight(*__this);
if (Nexus_teleport)
{
Vec_float_3 position = New_camera_pos(((Game_cam)(&((Game)__this).game_cam)).position, ((Loco)(&((Mio)(&((Game)__this).mio)).loco)).initial_position, -1388.7153f, 1551.1289f);
((Mio)(&((Game)__this).mio)).move_to(new Vec_float_3
{
Base = new _vec_storage_float_3
{
x = -1388.7153f,
y = 1551.1289f,
z = 0f
}
});
Unsafe.Write(&((Game_cam)(&((Game)__this).game_cam)).position, position);
Nexus_teleport = false;
}
if (Started_boss_rush && Current_boss_index == -1)
{
Start_next_boss_rush_boss();
}
if (!died_recently)
{
return;
}
int num = died_recently_counter;
NumberOption? obj = wait_time_option;
if (num >= ((obj != null) ? obj.Value : 10) * 60)
{
return;
}
died_recently_counter++;
int num2 = died_recently_counter;
NumberOption? obj2 = wait_time_option;
if (num2 >= ((obj2 != null) ? obj2.Value : 10) * 60)
{
died_recently = false;
died_recently_counter = -1;
if (Started_boss_rush && Current_boss_index >= 0 && !Start_next_boss_rush_boss())
{
Started_boss_rush = false;
Current_boss_index = -1;
}
}
}
private void PollToggle()
{
KeybindOption? obj = menu_keybind;
bool flag = ((obj != null) ? new bool?(obj.WasPressed) : ((bool?)null)) ?? false;
if (!_pollPrimed)
{
_pollPrimed = true;
_keybindWasDown = flag;
return;
}
if (flag && !_keybindWasDown)
{
_isOpen = !_isOpen;
}
_keybindWasDown = flag;
}
private void UpdateCursor()
{
try
{
gui.toggle_mouse_cursor(_isOpen);
}
catch (Exception ex)
{
((Mod)this).LogMessage("[gui] cursor toggle failed: " + ex);
}
}
private unsafe void DrawMenu()
{
//IL_0003: 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_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
ImVec2 val = new ImVec2
{
x = 12f,
y = 12f
};
ImVec2 val2 = new ImVec2
{
x = 0f,
y = 0f
};
ImVec2 val3 = new ImVec2
{
x = 150f,
y = 700f
};
Functions.ImGui__SetNextWindowPos(&val, 4, &val2);
Functions.ImGui__SetNextWindowSize(&val3, 4);
Functions.ImGui__SetNextWindowCollapsed(false, 1);
Functions.ImGui__SetNextWindowBgAlpha(0.92f);
fixed (byte* ptr = Utf8("Boss Fights"))
{
bool isOpen = _isOpen;
if (Functions.ImGui__Begin((sbyte*)ptr, &isOpen, 2097152))
{
Functions.ImGui__Separator();
ToggleOption? obj = health_info_option;
if (((obj != null) ? new bool?(obj.Value) : ((bool?)null)) ?? false)
{
Text("Boss health: " + boss_name);
Text($"Current/max: {boss_cur_health:f2}/{boss_max_health:f2}");
Text($"Decayed: {boss_decay_health:f2}");
Text($"Original max: {boss_init_max_health:f2}");
Text($"Last hit damage: {last_hit_amount:f2}");
Functions.ImGui__Separator();
}
if (!Started_boss_rush)
{
foreach (string key in Boss_Locations.Keys)
{
if (!AddBossButton(key))
{
ToggleOption? obj2 = close_menu_option;
if (((obj2 != null) ? new bool?(obj2.Value) : ((bool?)null)) ?? false)
{
isOpen = false;
}
}
}
Functions.ImGui__Separator();
}
Text("Boss rush");
if (!Started_boss_rush && Button("Start boss rush", 120f))
{
Started_boss_rush = true;
ToggleOption? obj3 = close_menu_option;
if (((obj3 != null) ? new bool?(obj3.Value) : ((bool?)null)) ?? false)
{
isOpen = false;
}
}
if (Started_boss_rush && Current_boss_index != -1)
{
Text("Current Boss:");
Text(Boss_rush_order[Current_boss_index]);
if (Current_boss_index < Boss_rush_order.Length - 1 && Boss_rush_order[Current_boss_index] == "Checkpoint" && Button("Start next boss", 120f))
{
Start_next_boss_rush_boss();
ToggleOption? obj4 = close_menu_option;
if (((obj4 != null) ? new bool?(obj4.Value) : ((bool?)null)) ?? false)
{
isOpen = false;
}
}
if (Button("Restart current boss", 120f))
{
RequestBoss(Boss_rush_order[Current_boss_index]);
ToggleOption? obj5 = close_menu_option;
if (((obj5 != null) ? new bool?(obj5.Value) : ((bool?)null)) ?? false)
{
isOpen = false;
}
}
if (Button("End boss rush", 120f))
{
Started_boss_rush = false;
Current_boss_index = -1;
}
}
if (Button("Return to Nexus", 120f))
{
Nexus_teleport = true;
}
if (Button("Close", 120f))
{
isOpen = false;
}
}
Functions.ImGui__End();
_isOpen = isOpen;
}
}
private void RequestBoss(string name)
{
if (name == "Checkpoint")
{
Nexus_teleport = true;
_isOpen = true;
}
else
{
Boss_refight_step = 0;
Boss_refight_request = name;
}
}
private bool AddBossButton(string name)
{
if (Button(name, 120f))
{
RequestBoss(name);
return false;
}
return true;
}
private static Vec_float_3 New_camera_pos(Vec_float_3 initial_camera_pos, Vec_float_3 initial_pos, float x, float y)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: 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)
//IL_0045: 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_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: 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_005b: Unknown result type (might be due to invalid IL or missing references)
float x2 = initial_camera_pos.x - initial_pos.x + x;
float y2 = initial_camera_pos.y - initial_pos.y + y;
return new Vec_float_3
{
Base = new _vec_storage_float_3
{
x = x2,
y = y2,
z = initial_camera_pos.z
}
};
}
private unsafe void Handle_boss_refight(Game game)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: 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)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0308: Unknown result type (might be due to invalid IL or missing references)
//IL_0334: Unknown result type (might be due to invalid IL or missing references)
//IL_0336: Unknown result type (might be due to invalid IL or missing references)
//IL_033b: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
//IL_0386: Unknown result type (might be due to invalid IL or missing references)
//IL_0387: Unknown result type (might be due to invalid IL or missing references)
Mio mio = game.mio;
if (Boss_refight_step == -1 || !(Boss_refight_request != ""))
{
return;
}
BossInfo valueOrDefault = Boss_Locations.GetValueOrDefault(Boss_refight_request);
if (valueOrDefault != null)
{
if (Boss_refight_step == 0)
{
boss_camera_pos = New_camera_pos(game.game_cam.position, game.mio.loco.initial_position, valueOrDefault.x, valueOrDefault.y);
if (Boss_refight_request == "Debby" || Boss_refight_request == "AnRa")
{
((Mio)(ref mio)).move_to(new Vec_float_3
{
Base = new _vec_storage_float_3
{
x = -134f,
y = 2454f,
z = 0f
}
});
}
else
{
((Mio)(ref mio)).move_to(default(Vec_float_3));
}
Boss_refight_step++;
}
else if (Boss_refight_step == 1)
{
RemoveFlag(game, valueOrDefault.flag);
if (Boss_refight_request == "Debby")
{
game.save.plotpoints.mel.quest = (Quest)3;
game.save.plotpoints.mel.rambo_awoken = false;
}
if (Boss_refight_request == "AnRa")
{
RemoveFlag(game, "VOICE:HALYN");
}
if (Boss_refight_request == "Ati" || Boss_refight_request == "Shii")
{
String val = Util.StringToMioString("VOICE:HALYN");
((Save)(ref game.save)).acquire(&val);
}
Boss_refight_step++;
}
else if (Boss_refight_step == 2)
{
if (Boss_refight_request == "Debby")
{
game.save.plotpoints.mel.quest = (Quest)3;
game.save.plotpoints.mel.rambo_awoken = false;
}
if (Boss_refight_request == "AnRa")
{
RemoveFlag(game, "VOICE:HALYN");
}
if (Boss_refight_request == "Debby" || Boss_refight_request == "AnRa")
{
((Mio)(ref mio)).move_to(default(Vec_float_3));
}
Boss_refight_step++;
}
else if (Boss_refight_step == 3)
{
((Mio)(ref mio)).move_to(new Vec_float_3
{
Base = new _vec_storage_float_3
{
x = valueOrDefault.x,
y = valueOrDefault.y,
z = 0f
}
});
ToggleOption? obj = heal_start_option;
if (((obj != null) ? new bool?(obj.Value) : ((bool?)null)) ?? false)
{
mio.life.health_points = mio.life.max_health_points;
}
Boss_refight_step = -1;
Boss_refight_request = "";
}
}
else
{
((Mod)this).LogMessage("Failed to find boss '" + Boss_refight_request + "'");
Boss_refight_step = -1;
Boss_refight_request = "";
}
}
private unsafe static void RemoveFlag(Game game, string flag)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
String val = Util.StringToMioString(flag);
Save_entry* ptr = ((Save)(ref game.save)).peek(&val);
if (ptr != null)
{
Unsafe.Write(&((Save_entry)ptr).flags, (Flags)0);
}
}
private static byte[] Utf8(string s)
{
byte[] array = new byte[Encoding.UTF8.GetByteCount(s) + 1];
Encoding.UTF8.GetBytes(s, 0, s.Length, array, 0);
return array;
}
private unsafe static bool Button(string label, float width)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
ImVec2 val = new ImVec2
{
x = width,
y = 0f
};
fixed (byte* ptr = Utf8(label))
{
return Functions.ImGui__Button((sbyte*)ptr, &val);
}
}
private unsafe static void Text(string s)
{
fixed (byte* ptr = Utf8(s))
{
Functions.ImGui__TextUnformatted((sbyte*)ptr, (sbyte*)null);
}
}
}
internal record BossInfo(float x, float y, string flag);