-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #708 from starfi5h/pr-combatFix
Combat balance change and bugfix
- Loading branch information
Showing
18 changed files
with
348 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
NebulaPatcher/Patches/Transpilers/DFGBaseComponent_Transpiler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#region | ||
|
||
using System.Collections.Generic; | ||
using System.Reflection.Emit; | ||
using HarmonyLib; | ||
using NebulaModel.Logger; | ||
using NebulaWorld; | ||
|
||
#endregion | ||
|
||
namespace NebulaPatcher.Patches.Transpilers; | ||
|
||
[HarmonyPatch(typeof(DFGBaseComponent))] | ||
internal class DFGBaseComponent_Transpiler | ||
{ | ||
[HarmonyTranspiler] | ||
[HarmonyPatch(nameof(DFGBaseComponent.UpdateFactoryThreat))] | ||
public static IEnumerable<CodeInstruction> UpdateFactoryThreat_Transpiler(IEnumerable<CodeInstruction> instructions) | ||
{ | ||
try | ||
{ | ||
/* Launch assault for player who on remote planet and has no power buildings | ||
from: | ||
if (num24 == 0.0 && this.groundSystem.local_player_grounded_alive) | ||
{ | ||
num24 = 10.0; | ||
ref Vector3 ptr2 = ref this.groundSystem.local_player_pos; | ||
vector = new Vector3(ptr2.x - num, ptr2.y - num2, ptr2.z - num3); | ||
num18 = num16; | ||
num19 = num17; | ||
} | ||
to: | ||
>> if (num24 == 0.0 && LaunchCondition(this)) | ||
{ | ||
... | ||
} | ||
*/ | ||
|
||
var codeMatcher = new CodeMatcher(instructions) | ||
.End() | ||
.MatchBack(true, | ||
new CodeMatch(OpCodes.Ldloc_S), | ||
new CodeMatch(OpCodes.Ldc_R8), | ||
new CodeMatch(OpCodes.Bne_Un), | ||
new CodeMatch(OpCodes.Ldarg_0), | ||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(DFGBaseComponent), nameof(DFGBaseComponent.groundSystem))), | ||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(EnemyDFGroundSystem), nameof(EnemyDFGroundSystem.local_player_grounded_alive))), | ||
new CodeMatch(OpCodes.Brfalse)); | ||
|
||
if (codeMatcher.IsInvalid) | ||
{ | ||
Log.Warn("DFGBaseComponent.UpdateFactoryThreat: Can't find target"); | ||
return codeMatcher.InstructionEnumeration(); | ||
} | ||
codeMatcher.Advance(-2) | ||
.RemoveInstruction() | ||
.SetAndAdvance(OpCodes.Call, AccessTools.Method(typeof(DFGBaseComponent_Transpiler), nameof(LaunchCondition))); | ||
|
||
return codeMatcher.InstructionEnumeration(); | ||
} | ||
catch (System.Exception e) | ||
{ | ||
Log.Warn("Transpiler DFGBaseComponent.UpdateFactoryThreat failed."); | ||
Log.Warn(e); | ||
return instructions; | ||
} | ||
} | ||
|
||
static bool LaunchCondition(DFGBaseComponent @this) | ||
{ | ||
if (!Multiplayer.IsActive || @this.groundSystem.local_player_alive == true) return @this.groundSystem.local_player_alive; | ||
|
||
var planetId = @this.groundSystem.planet.id; | ||
var players = Multiplayer.Session.Combat.Players; | ||
for (var i = 0; i < players.Length; i++) | ||
{ | ||
if (players[i].isAlive && players[i].planetId == planetId) | ||
{ | ||
@this.groundSystem.local_player_pos = players[i].position; | ||
Log.Info($"Base attack LaunchCondition: player[{i}] planeId{planetId}"); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.