Skip to content

Commit

Permalink
Merge pull request #166 from tobiasksu/mp-deathexplosion
Browse files Browse the repository at this point in the history
Add Multiplayer Option to allow for reduced ship explosion effects
  • Loading branch information
roncli committed Sep 29, 2021
2 parents 9e32206 + da9c19d commit 3fe781a
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 43 deletions.
1 change: 1 addition & 0 deletions GameMod/GameMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<Compile Include="MPCreeperSync.cs" />
<Compile Include="MPCustomModeFile.cs" />
<Compile Include="MPDamageEffects.cs" />
<Compile Include="MPDeathExplosion.cs" />
<Compile Include="MPDeathReview.cs" />
<Compile Include="MPErrorSmoothingFix.cs" />
<Compile Include="MPFixGhostProjectiles.cs" />
Expand Down
99 changes: 99 additions & 0 deletions GameMod/MPDeathExplosion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using HarmonyLib;
using Overload;
using System;
using System.Collections.Generic;
using System.Reflection.Emit;
using UnityEngine;

namespace GameMod
{
[HarmonyPatch(typeof(PlayerShip), "DyingUpdate")]
class MPDeathExplosion_PlayerShip_DyingUpdate
{
static void CreateExitMovingExplosion(Vector3 vector)
{
if (!Menus.mms_reduced_ship_explosions)
{
ExplosionManager.CreateExitMovingExplosion(vector);
}
}

static void StartAndEmitParticleInstant(ParticleSubManager psm, int pp_idx, Vector3 pos, Quaternion rot, int emit_count)
{
if (!Menus.mms_reduced_ship_explosions)
{
psm.StartAndEmitParticleInstant(pp_idx, pos, rot, emit_count);
}
}

static void CreateExpElementFromResourcesAndEmit(FXExpElement exp_element, Transform transform, int emit_count, bool all = false)
{
if (!Menus.mms_reduced_ship_explosions)
{
ExplosionManager.CreateExpElementFromResourcesAndEmit(exp_element, transform, emit_count, all);
}
}

static void CreateMinorExplosion(Vector3 vector)
{
if (!Menus.mms_reduced_ship_explosions)
{
ExplosionManager.CreateMinorExplosion(vector);
}
}

static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codes)
{
foreach (var code in codes)
{
if (code.opcode == OpCodes.Call && code.operand == AccessTools.Method(typeof(ExplosionManager), "CreateMinorExplosion", new Type[] { typeof(Vector3) }))
code.operand = AccessTools.Method(typeof(MPDeathExplosion_PlayerShip_DyingUpdate), "CreateMinorExplosion");

if (code.opcode == OpCodes.Call && code.operand == AccessTools.Method(typeof(ExplosionManager), "CreateExitMovingExplosion"))
code.operand = AccessTools.Method(typeof(MPDeathExplosion_PlayerShip_DyingUpdate), "CreateExitMovingExplosion");

if (code.opcode == OpCodes.Callvirt && code.operand == AccessTools.Method(typeof(ParticleSubManager), "StartAndEmitParticleInstant"))
{
code.opcode = OpCodes.Call;
code.operand = AccessTools.Method(typeof(MPDeathExplosion_PlayerShip_DyingUpdate), "StartAndEmitParticleInstant");
}

if (code.opcode == OpCodes.Call && code.operand == AccessTools.Method(typeof(ExplosionManager), "CreateExpElementFromResourcesAndEmit", new Type[] { typeof(FXExpElement), typeof(Transform), typeof(int), typeof(bool) }))
code.operand = AccessTools.Method(typeof(MPDeathExplosion_PlayerShip_DyingUpdate), "CreateExpElementFromResourcesAndEmit");

yield return code;
}
}
}

[HarmonyPatch(typeof(PlayerShip), "StartDying")]
class MPDeathExplosion_PlayerShip_StartDying
{
static ParticleElement CreateRandomExplosionSimple(Transform transform, float scale = 1f, float sim_speed = 1f)
{
if (!Menus.mms_reduced_ship_explosions)
{
return ExplosionManager.CreateRandomExplosionSimple(transform, scale, sim_speed);
}

return null;
}

static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codes)
{
foreach (var code in codes)
{
if (code.opcode == OpCodes.Callvirt && code.operand == AccessTools.Method(typeof(ParticleSubManager), "StartAndEmitParticleInstant"))
{
code.opcode = OpCodes.Call;
code.operand = AccessTools.Method(typeof(MPDeathExplosion_PlayerShip_DyingUpdate), "StartAndEmitParticleInstant");
}

if (code.opcode == OpCodes.Call && code.operand == AccessTools.Method(typeof(ExplosionManager), "CreateRandomExplosionSimple"))
code.operand = AccessTools.Method(typeof(MPDeathExplosion_PlayerShip_StartDying), "CreateRandomExplosionSimple");

yield return code;
}
}
}
}
2 changes: 2 additions & 0 deletions GameMod/MPSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ static void Postfix(string filename)
Menus.mms_weapon_lag_compensation_scale = ModPrefs.GetInt("MP_PM_WEAPON_LAG_COMPENSATION_SCALE", Menus.mms_weapon_lag_compensation_scale);
Menus.mms_sticky_death_summary = ModPrefs.GetBool("MP_PM_STICKY_DEATH_SUMMARY", Menus.mms_sticky_death_summary);
MPDeathReview.stickyDeathReview = Menus.mms_sticky_death_summary;
Menus.mms_reduced_ship_explosions = ModPrefs.GetBool("MP_PM_REDUCED_SHIP_EXPLOSIONS", Menus.mms_reduced_ship_explosions);
Menus.mms_damageeffect_alpha_mult = ModPrefs.GetInt("MP_PM_DAMAGEEFFECT_ALPHA_MULT", Menus.mms_damageeffect_alpha_mult);
Menus.mms_damageeffect_drunk_blur_mult = ModPrefs.GetInt("MP_PM_DAMAGEEFFECT_DRUNK_BLUR_MULT", Menus.mms_damageeffect_drunk_blur_mult);
Menus.mms_match_time_limit = ModPrefs.GetInt("MP_PM_MATCH_TIME_LIMIT", Menus.mms_match_time_limit);
Expand Down Expand Up @@ -292,6 +293,7 @@ private static void Prefix(string filename)
ModPrefs.SetInt("MP_PM_WEAPON_LAG_COMPENSATION_SCALE", Menus.mms_weapon_lag_compensation_scale);
ModPrefs.SetInt("MP_PM_SHIP_LAG_COMPENSATION_SCALE", Menus.mms_ship_lag_compensation_scale);
ModPrefs.SetBool("MP_PM_STICKY_DEATH_SUMMARY", Menus.mms_sticky_death_summary);
ModPrefs.SetBool("MP_PM_REDUCED_SHIP_EXPLOSIONS", Menus.mms_reduced_ship_explosions);
ModPrefs.SetInt("MP_PM_DAMAGEEFFECT_ALPHA_MULT", Menus.mms_damageeffect_alpha_mult);
ModPrefs.SetInt("MP_PM_DAMAGEEFFECT_DRUNK_BLUR_MULT", Menus.mms_damageeffect_drunk_blur_mult);
ModPrefs.SetInt("MP_PM_MATCH_TIME_LIMIT", Menus.mms_match_time_limit);
Expand Down
179 changes: 136 additions & 43 deletions GameMod/Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ public static class Menus
public static MenuState msLagCompensation = (MenuState)76;
public static MenuState msAutoSelect = (MenuState)77;
public static MenuState msAxisCurveEditor = (MenuState)78;
public static MenuState msTeamColors = (MenuState)79;
//public static UIElementType uiServerBrowser = (UIElementType)89;
public static UIElementType uiLagCompensation = (UIElementType)90;
public static UIElementType uiAutoSelect = (UIElementType)91;
public static UIElementType uiAxisCurveEditor = (UIElementType)92;
public static UIElementType uiTeamColors = (UIElementType)93;
public static bool mms_ctf_boost { get; set; }

public static string GetMMSCtfCarrierBoost()
Expand Down Expand Up @@ -162,6 +164,7 @@ public static void SetLagCompensationDefaults()
public static int mms_damageeffect_alpha_mult = 30;
public static int mms_damageeffect_drunk_blur_mult = 10;
public static int mms_match_time_limit = 60;
public static bool mms_reduced_ship_explosions = false;
}


Expand Down Expand Up @@ -519,11 +522,9 @@ static void DrawMoreOptions(UIElement uie, ref Vector2 position)
position.y += 56f;
uie.SelectAndDrawSliderItem(Loc.LS("DAMAGE COLOR INTENSITY"), position, 10, ((float)Menus.mms_damageeffect_alpha_mult) / 100f);
position.y += 56f;
uie.SelectAndDrawStringOptionItem(Loc.LS("TEAM COLORS"), position, 11, Menus.GetMMSTeamColorDefault(), "DISPLAY TEAM COLORS IN DEFAULT ORANGE/BLUE OR CUSTOM", 1.5f, false);
uie.SelectAndDrawStringOptionItem(Loc.LS("SHIP EXPLOSION EFFECTS"), position, 12, Menus.mms_reduced_ship_explosions ? Loc.LS("REDUCED") : Loc.LS("FULL"), Loc.LS("REDUCED VISUAL CLUTTER DURING DEATH ROLL"));
position.y += 56f;
uie.SelectAndDrawStringOptionItem(Loc.LS("MY TEAM"), position, 12, Menus.GetMMSTeamColorSelf(), "", 1.5f, Menus.mms_team_color_default);
position.y += 56f;
uie.SelectAndDrawStringOptionItem(Loc.LS("ENEMY TEAM"), position, 13, Menus.GetMMSTeamColorEnemy(), "", 1.5f, Menus.mms_team_color_default);
uie.SelectAndDrawItem(Loc.LS("TEAM COLORS"), position, 11, false, 1f, 0.75f);
position.y += 56f;
uie.SelectAndDrawItem(Loc.LS("LAG COMPENSATION SETTINGS"), position, 6, false, 1f, 0.75f);
position.y += 56f;
Expand Down Expand Up @@ -632,56 +633,20 @@ static void Update()
MenuManager.PlayCycleSound(1f, (float)((double)UIElement.SliderPos * 5.0 - 3.0));
break;
case 11:
Menus.mms_team_color_default = !Menus.mms_team_color_default;
MenuManager.ChangeMenuState(Menus.msTeamColors, false);
UIManager.DestroyAll(false);
MenuManager.PlaySelectSound(1f);
ProcessColorSelections();
break;
case 12:
Menus.mms_team_color_self = (Menus.mms_team_color_self + 9 + UIManager.m_select_dir) % 9;
if (Menus.mms_team_color_self == Menus.mms_team_color_enemy)
Menus.mms_team_color_self = (Menus.mms_team_color_self + 9 + UIManager.m_select_dir) % 9;
MenuManager.PlaySelectSound(1f);
ProcessColorSelections();
break;
case 13:
Menus.mms_team_color_enemy = (Menus.mms_team_color_enemy + 9 + UIManager.m_select_dir) % 9;
if (Menus.mms_team_color_enemy == Menus.mms_team_color_self)
Menus.mms_team_color_enemy = (Menus.mms_team_color_enemy + 9 + UIManager.m_select_dir) % 9;
Menus.mms_reduced_ship_explosions = !Menus.mms_reduced_ship_explosions;
MenuManager.PlaySelectSound(1f);
ProcessColorSelections();
break;
default:
break;
}
MenuManager.UnReverseOption();
}
}

static void ProcessColorSelections()
{
if (GameplayManager.IsMultiplayerActive)
{
// Update ship colors
foreach (var ps in UnityEngine.Object.FindObjectsOfType<PlayerShip>())
{
ps.UpdateShipColors(ps.c_player.m_mp_team, -1, -1, -1);
ps.UpdateRimColor(true);
}
// Update CTF flag/carrier colors
if (CTF.IsActive)
{
for (int i = 0; i < CTF.FlagObjs.Count; i++)
{
CTF.UpdateFlagColor(CTF.FlagObjs[i], i);
}
foreach (var player in Overload.NetworkManager.m_Players)
{
CTF.UpdateShipEffects(player);
}
}
}
UIManager.InitMpNames();
}
}

[HarmonyPatch(typeof(MenuManager), "Update")]
Expand All @@ -692,6 +657,9 @@ private static void Postfix(ref float ___m_menu_state_timer)
{
if (MenuManager.m_menu_state == Menus.msLagCompensation)
LagCompensationUpdate(ref ___m_menu_state_timer);

if (MenuManager.m_menu_state == Menus.msTeamColors)
TeamColorsUpdate(ref ___m_menu_state_timer);
}

private static void LagCompensationUpdate(ref float m_menu_state_timer)
Expand Down Expand Up @@ -790,6 +758,104 @@ private static void LagCompensationUpdate(ref float m_menu_state_timer)
}
}

private static void TeamColorsUpdate(ref float m_menu_state_timer)
{
UIManager.MouseSelectUpdate();
switch (MenuManager.m_menu_sub_state)
{
case MenuSubState.INIT:
if (m_menu_state_timer > 0.25f)
{
UIManager.CreateUIElement(UIManager.SCREEN_CENTER, 7000, Menus.uiTeamColors);
MenuManager.m_menu_sub_state = MenuSubState.ACTIVE;
m_menu_state_timer = 0f;
MenuManager.SetDefaultSelection(0);
}
break;
case MenuSubState.ACTIVE:
UIManager.ControllerMenu();
Controls.m_disable_menu_letter_keys = false;
int menu_micro_state = MenuManager.m_menu_micro_state;

if (m_menu_state_timer > 0.25f)
{
if (UIManager.PushedSelect(100) || (MenuManager.option_dir && UIManager.PushedDir() || UIManager.SliderMouseDown()))
{
MenuManager.MaybeReverseOption();
switch (UIManager.m_menu_selection)
{
case 1:
Menus.mms_team_color_default = !Menus.mms_team_color_default;
MenuManager.PlaySelectSound(1f);
ProcessColorSelections();
break;
case 2:
Menus.mms_team_color_self = (Menus.mms_team_color_self + 9 + UIManager.m_select_dir) % 9;
if (Menus.mms_team_color_self == Menus.mms_team_color_enemy)
Menus.mms_team_color_self = (Menus.mms_team_color_self + 9 + UIManager.m_select_dir) % 9;
MenuManager.PlaySelectSound(1f);
ProcessColorSelections();
break;
case 3:
Menus.mms_team_color_enemy = (Menus.mms_team_color_enemy + 9 + UIManager.m_select_dir) % 9;
if (Menus.mms_team_color_enemy == Menus.mms_team_color_self)
Menus.mms_team_color_enemy = (Menus.mms_team_color_enemy + 9 + UIManager.m_select_dir) % 9;
MenuManager.PlaySelectSound(1f);
ProcessColorSelections();
break;
case 100:
MenuManager.PlaySelectSound(1f);
m_menu_state_timer = 0f;
UIManager.DestroyAll(false);
MenuManager.m_menu_state = 0;
MenuManager.m_menu_micro_state = 0;
MenuManager.m_menu_sub_state = MenuSubState.BACK;
break;
}
}
}
break;
case MenuSubState.BACK:
if (m_menu_state_timer > 0.25f)
{
MenuManager.ChangeMenuState(((Stack<MenuState>)AccessTools.Field(typeof(MenuManager), "m_back_stack").GetValue(null)).Pop(), true);
AccessTools.Field(typeof(MenuManager), "m_went_back").SetValue(null, true);
}
break;
case MenuSubState.START:
if (m_menu_state_timer > 0.25f)
{

}
break;
}
}

static void ProcessColorSelections()
{
if (GameplayManager.IsMultiplayerActive)
{
// Update ship colors
foreach (var ps in UnityEngine.Object.FindObjectsOfType<PlayerShip>())
{
ps.UpdateShipColors(ps.c_player.m_mp_team, -1, -1, -1);
ps.UpdateRimColor(true);
}
// Update CTF flag/carrier colors
if (CTF.IsActive)
{
for (int i = 0; i < CTF.FlagObjs.Count; i++)
{
CTF.UpdateFlagColor(CTF.FlagObjs[i], i);
}
foreach (var player in Overload.NetworkManager.m_Players)
{
CTF.UpdateShipEffects(player);
}
}
}
UIManager.InitMpNames();
}
}

[HarmonyPatch(typeof(UIElement), "Draw")]
Expand All @@ -799,6 +865,33 @@ static void Postfix(UIElement __instance)
{
if (__instance.m_type == Menus.uiLagCompensation && __instance.m_alpha > 0f)
DrawLagCompensationWindow(__instance);

if (__instance.m_type == Menus.uiTeamColors && __instance.m_alpha > 0f)
DrawTeamColorsWindow(__instance);
}

static void DrawTeamColorsWindow(UIElement uie)
{
UIManager.ui_bg_dark = true;
uie.DrawMenuBG();
Vector2 position = uie.m_position;
position.y = UIManager.UI_TOP + 64f;
uie.DrawHeaderMedium(Vector2.up * (UIManager.UI_TOP + 30f), Loc.LS("TEAM COLOR SETTINGS"), 265f);
position.y += 20f;
uie.DrawMenuSeparator(position);
position.y += 40f;
uie.SelectAndDrawStringOptionItem(Loc.LS("TEAM COLORS"), position, 1, Menus.GetMMSTeamColorDefault(), "DISPLAY TEAM COLORS IN DEFAULT ORANGE/BLUE OR CUSTOM", 1.5f, false);
position.y += 64f;
uie.SelectAndDrawStringOptionItem(Loc.LS("MY TEAM"), position, 2, Menus.GetMMSTeamColorSelf(), "", 1.5f, Menus.mms_team_color_default);
position.y += 64f;
uie.SelectAndDrawStringOptionItem(Loc.LS("ENEMY TEAM"), position, 3, Menus.GetMMSTeamColorEnemy(), "", 1.5f, Menus.mms_team_color_default);
position.y += 64f;
position.y = UIManager.UI_BOTTOM - 120f;
uie.DrawMenuSeparator(position);
position.y += 5f;
DrawMenuToolTipMultiline(uie, position, 15f);
position.y = UIManager.UI_BOTTOM - 30f;
uie.SelectAndDrawItem(Loc.LS("BACK"), position, 100, fade: false);
}

static void DrawLagCompensationWindow(UIElement uie)
Expand Down

0 comments on commit 3fe781a

Please sign in to comment.