Skip to content

Commit

Permalink
Merge branch 'gponick-add-dashed-option'
Browse files Browse the repository at this point in the history
* gponick-add-dashed-option:
  cleanup variable names and code for obstructed line changes, and add option to disable indirect LoF feature, plus add a thickness setting for the obstructed line
  Refactor based on PR comments. Add dash thickness also.
  Add option to modify obstructed lines, both the first half and second. Defaults to only second half, purple-ish.
  Refactor to keep the lerping.
  Add a dashed option and code paths. Tested.
  • Loading branch information
janxious committed May 21, 2018
2 parents 365783c + 26630b1 commit 3be4218
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 36 deletions.
87 changes: 84 additions & 3 deletions BTMLColorLOSMod/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,97 @@

namespace BTMLColorLOSMod
{
// the properties in in here are to be a deserializer step from JSON format
// into the C# variables used by the mod.
public class Settings
{
// the float here is to hold deserialized JSON data coming from ModTek and convert it to a UnityEngine.Color
#region IndirectLineOfFireArcOptions

// The color to be patched into the game for coloring indirect lines of fire
// Defaults to magenta if the user gives us funky data so it should stand out
public Color IndirectLineOfFireArcColor = Color.magenta;

public float[] indirectLineOfFireArcColor
{
set => IndirectLineOfFireArcColor = new Color(value[0], value[1], value[2], value[3]);
}

// The color to be patched into the game for coloring indirect lines of fire
// Controls whether we set the Indirect Line Of Fire Line to Dashed (true: dashed, false: solid)
public bool IndirectLineOfFireArcDashed = false;

public bool indirectLineOfFireArcDashed
{
set => IndirectLineOfFireArcDashed = value;
}

// Controls the thickness of the Indirect Line of Fire when dashed
public float IndirectLineOfFireArcDashedThicknessMultiplier = 1.75f;

public float indirectLineOfFireArcDashedThicknessMultiplier
{
set => IndirectLineOfFireArcDashedThicknessMultiplier = value;
}

// Controls whether we change anything about the Indirect Line of Fire arc style.
public bool IndirectLineOfFireArcActive = true;

public bool indirectLineOfFireArcActive
{
set => IndirectLineOfFireArcActive = value;
}

#endregion

#region obstructedLineOfFireAttackerSide

// The color to be patched into the game for the coloring obstructed Line of Fire (LOF)'s part between
// the shooter and obstruction
// Defaults to magenta if the user gives us funky data so it should stand out
public Color IndirectLineOfFireArcColor = Color.magenta;
public Color ObstructedLineOfFireAttackerSideColor = Color.magenta;

public float[] obstructedLineOfFireAttackerSideColor
{
set => ObstructedLineOfFireAttackerSideColor = new Color(value[0], value[1], value[2], value[3]);
}

// Controls whether we change the color of the near part of an obstructed LOF line.
public bool ObstructedLineOfFireAttackerSideActive = true;

public bool obstructedLineOfFireAttackerSideActive
{
set => ObstructedLineOfFireAttackerSideActive = value;
}

#endregion

#region obstructedLineOfFireTargetSide

// The color to be patched into the game for the coloring obstructed Line of Fire (LOF)'s part between
// the obstruction and target.
// Defaults to magenta if the user gives us funky data so it should stand out
public Color ObstructedLineOfFireTargetSideColor = Color.magenta;

public float[] obstructedLineOfFireTargetSideColor
{
set => ObstructedLineOfFireTargetSideColor = new Color(value[0], value[1], value[2], value[3]);
}

// Controls whether we change the color of the far part of an obstructed LOF line.
public bool ObstructedLineOfFireTargetSideActive = true;

public bool obstructedLineOfFireTargetSideActive
{
set => ObstructedLineOfFireTargetSideActive = value;
}

// Controls the thickness of the obstructed LOF target side line.
public float ObstructedLineOfFireTargetSiteThicknessMultiplier = 1.75f;

public float obstructedLineOfFireTargetSiteThicknessMultiplier
{
set => ObstructedLineOfFireTargetSiteThicknessMultiplier = value;
}

#endregion
}
}
65 changes: 47 additions & 18 deletions BTMLColorLOSMod/WeaponRangeIndicators_DrawLine_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BattleTech.UI;
using Harmony;
using UnityEngine;
using static BTMLColorLOSMod.BTMLColorLOSMod;

namespace BTMLColorLOSMod
{
Expand All @@ -20,10 +21,7 @@ static bool Prefix(
ref bool isMelee,
WeaponRangeIndicators __instance)
{
// var colorSettings = SettingsHelper.LoadSettings();
CombatHUD HUD = (CombatHUD) ReflectionHelper.GetPrivateProperty(__instance, "HUD");
// set up this line drawer because it has some materials we want later

if (__instance.DEBUG_showLOSLines)
{
DEBUG_LOSLineDrawer debugDrawer =
Expand Down Expand Up @@ -144,6 +142,7 @@ static bool Prefix(

line.SetPosition(1, vector2);
}
// LOF obstructed
else
{
if (target == HUD.SelectionHandler.ActiveState.FacingEnemy)
Expand All @@ -162,15 +161,30 @@ static bool Prefix(
Vector3 collisionPoint = previewInfo.collisionPoint;
collisionPoint = Vector3.Project(collisionPoint - vector, vector2 - vector) + vector;
line.SetPosition(1, collisionPoint);
if (ModSettings.ObstructedLineOfFireAttackerSideActive)
{
line.material.color = Color.white;
line.startColor = line.endColor = ModSettings.ObstructedLineOfFireAttackerSideColor;
}

LineRenderer line2 =
(LineRenderer) ReflectionHelper.InvokePrivateMethode(__instance, "getLine",
new object[] { });
line2.positionCount = 2;
line2.startWidth = __instance.LOSWidthBlocked;
line2.endWidth = __instance.LOSWidthBlocked;
line2.startWidth = __instance.LOSWidthBlocked *
ModSettings.ObstructedLineOfFireTargetSiteThicknessMultiplier;
line2.endWidth = __instance.LOSWidthBlocked *
ModSettings.ObstructedLineOfFireTargetSiteThicknessMultiplier;
;
line2.material = __instance.MaterialInRange;
LineRenderer lineRenderer5 = line2;
Color color2 = lineRenderer5.startColor = (line2.endColor = __instance.LOSBlocked);

line2.startColor = line2.endColor = __instance.LOSBlocked;
if (ModSettings.ObstructedLineOfFireTargetSideActive)
{
line2.startColor = line2.endColor = ModSettings.ObstructedLineOfFireTargetSideColor;
line2.material.color = Color.white;
}

line2.SetPosition(0, collisionPoint);
line2.SetPosition(1, vector2);
GameObject coverIcon =
Expand All @@ -187,18 +201,33 @@ static bool Prefix(
// arc shot
else
{
// other than formatting this block is the only thing that changed from the decompiled code
if (ModSettings.IndirectLineOfFireArcActive)
{
float shotQuality = (float) ReflectionHelper.InvokePrivateMethode(__instance,
"GetShotQuality", new object[] {selectedActor, position, rotation, target});
Color color6 = Color.Lerp(
Color.clear,
ModSettings.IndirectLineOfFireArcColor,
shotQuality);
if (ModSettings.IndirectLineOfFireArcDashed)
{
line.material = __instance.MaterialOutOfRange;
line.material.color = color6;
line.endWidth = __instance.LOSWidthEnd *
ModSettings
.IndirectLineOfFireArcDashedThicknessMultiplier; // dashes are harder to see,
line.startWidth = __instance.LOSWidthBegin *
ModSettings
.IndirectLineOfFireArcDashedThicknessMultiplier; // so make 'em bigger
}
else
{
line.material.color = Color.white;
line.endColor = line.startColor = color6;
}
}

Vector3[] pointsForArc = WeaponRangeIndicators.GetPointsForArc(18, 30f, vector, vector2);
float shotQuality = (float) ReflectionHelper.InvokePrivateMethode(__instance,
"GetShotQuality", new object[] {selectedActor, position, rotation, target});
// alright future me, this is probably destructive in some way, but
// this lets us set the color of the line via that color6 bit.
line.material.color = Color.white;
Color color6 = Color.Lerp(
Color.clear,
BTMLColorLOSMod.ModSettings.IndirectLineOfFireArcColor,
shotQuality);
line.endColor = (line.startColor = color6);
line.positionCount = 18;
line.SetPositions(pointsForArc);
}
Expand Down
12 changes: 11 additions & 1 deletion BTMLColorLOSMod/mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
"ConflictsWith": [],

"Settings": {
"indirectLineOfFireArcColor": [1, 0.5, 0, 1]
"indirectLineOfFireArcActive": true,
"indirectLineOfFireArcColor": [1, 0.5, 0, 1],
"indirectLineOfFireArcDashed": false,
"indirectLineOfFireArcDashedThicknessMultiplier": 1.75,

"obstructedLineOfFireAttackerSideActive": false,
"obstructedLineOfFireAttackerSideColor": [0, 0.25, 1, 1],

"obstructedLineOfFireTargetSideActive": true,
"obstructedLineOfFireTargetSideColor": [0.6, 0, 1, 0.9],
"obstructedLineOfFireTargetSiteThicknessMultiplier": 1.25
}
}
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
# BTMLColorLOSMod
BattleTech Mod (using [BTML](https://github.com/Mpstark/BattleTechModLoader) and [ModTek](https://github.com/Mpstark/ModTek)) that changes the color of indirect firing lines in battle to a different color from direct.

## Installing
After [installing BTML and Modtek](https://github.com/Mpstark/ModTek/wiki/The-Drop-Dead-Simple-Guide-to-Installing-BTML-&-ModTek-&-ModTek-mods), put into `\BATTLETECH\Mods\BTMLColorLOSMod` folder and launch the game.

## Features
- Make the line drawn between your currently controlled mech and an enemy in your firing arc with indirect-fire only a different color

## Settings
Setting | Type | Default | Description
--- | --- | --- | ---
indirectLineOfFireArcColor | float[4] | default [1, 0.5, 0, 1] (an orange-ish color) | the default in vanilla is [1, 0, 0, 1].

Note that the last number controls alpha transparency, so if you make it a zero you will probably not have an indirect firing line at all. All numbers should be between 0 and 1.
- Change the color of indirect line of fire indicator drawn between the currently controlled mech and enemy targets
- Add dashes to the indirect line of fire indicator drawn between the currently controlled mech and enemy targets
- Change the color of the line of fire indicator for obstructed targets on the attacker and target sides of the obstruction

## Download
Downloads can be found on [github](https://github.com/janxious/BTMLColorLOSMod/releases).
Downloads can be found on [Github](https://github.com/janxious/BTMLColorLOSMod/releases) and on [Nexus](https://www.nexusmods.com/battletech/mods/135).

## Install
- [Install BTML and Modtek](https://github.com/Mpstark/ModTek/wiki/The-Drop-Dead-Simple-Guide-to-Installing-BTML-&-ModTek-&-ModTek-mods).
- Put the `BTMLColorLOSMod.dll` and `mod.json` files into `\BATTLETECH\Mods\BTMLColorLOSMod` folder.
- If you want to change the settings do so in the mod.json.
- Start the game.

## Settings
Setting | Type | Default | Description
--- | --- | --- | ---
`indirectLineOfFireArcActive` | `bool` | `true` | change the look of the indirect firing line arc
`indirectLineOfFireArcColor` | `float[4]` | `[1, 0.5, 0, 1]` (orange) | the color of the indirect firing line arc. The default in vanilla is `[1, 0, 0, 1]` (red).
`indirectLineOfFireArcDashed` | `bool` | `false` | make the indirect firing line arc a dashed line
`indirectLineOfFireArcDashedThicknessMultiplier` | `float` | `1.75` | change how thick the indirect firing line looks when dashed
`obstructedLineOfFireAttackerSideActive` | `bool` | false | change the look of the line of fire indicator when obstructed on the side nearest the attacker
`obstructedLineOfFireAttackerSideColor` | `float[4]` | `[0, 0.25, 1, 1]` (blue) | line of fire color nearest the attacker when fire is obstructed
`obstructedLineOfFireTargetSideActive` | `bool` | true | change the look of the line of fire indicator when obstructed on the side nearest the target
`obstructedLineOfFireTargetSideColor` | `float[4]` | `[0.6, 0, 1, 0.9]` (purple) | line of fire color nearest the target when fire is obstructed
`obstructedLineOfFireTargetSiteThicknessMultiplier` | `float` | `1.25` | change how thick the obstructed firing line looks on the target side

Note that the last number in the above `float[4]` controls alpha transparency, so if you make it a `0` you will probably not have an indirect firing line at all. All numbers should be between `0` and `1`.

## Special Thanks

HBS, @Mpstark, @Morphyum, @gponick


## New HBS Patch Instructions
## Maintainer Notes: New HBS Patch Instructions

* pop open VS
* grab the latest version of the assembly
* copy the new version of the methods in `original_src` over the existing ones
* see if anything important changed via git
* see if anything important changed via git

0 comments on commit 3be4218

Please sign in to comment.