Skip to content

Commit

Permalink
Add extra check in enemies
Browse files Browse the repository at this point in the history
  • Loading branch information
starfi5h committed Jul 3, 2024
1 parent 50f91e7 commit 1a85fb6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DFGKillEnemyProcessor : PacketProcessor<DFGKillEnemyPacket>
protected override void ProcessPacket(DFGKillEnemyPacket packet, NebulaConnection conn)
{
var factory = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory;
if (factory == null) return;
if (factory == null || packet.EnemyId >= factory.enemyPool.Length) return;

if (IsHost)
{
Expand Down
37 changes: 37 additions & 0 deletions NebulaPatcher/Patches/Transpilers/EnemyDFHiveSystem_Transpiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,43 @@ public static IEnumerable<CodeInstruction> GameTickLogic_Transpiler(IEnumerable<
.MatchForward(true, new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(DFRelayComponent), nameof(DFRelayComponent.RealizePlanetBase))))
.Set(OpCodes.Call, AccessTools.Method(typeof(EnemyDFHiveSystem_Transpiler), nameof(RealizePlanetBase)));


// Insert null guard in EnemyUnitComponent loop
// if (ptr10.id == k)
// {
// ref EnemyData ptr11 = ref enemyPool[ptr10.enemyId];
// PrefabDesc prefabDesc = SpaceSector.PrefabDescByModelIndex[(int)ptr11.modelIndex];
// if (prefabDesc == null) continue; // null guard

codeMatcher.MatchForward(true,
new CodeMatch(OpCodes.Ldloc_S),
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(EnemyUnitComponent), nameof(EnemyUnitComponent.id))),
new CodeMatch(OpCodes.Ldloc_S),
new CodeMatch(OpCodes.Bne_Un));
if (codeMatcher.IsInvalid)
{
Log.Warn("EnemyDFHiveSystem.GameTickLogic: Can't find operand_continue");
return codeMatcher.InstructionEnumeration();
}
var operand_continue = codeMatcher.Operand;

codeMatcher.MatchForward(true,
new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(typeof(SpaceSector), nameof(SpaceSector.PrefabDescByModelIndex))),
new CodeMatch(OpCodes.Ldloc_S),
new CodeMatch(OpCodes.Ldfld),
new CodeMatch(OpCodes.Ldelem_Ref),
new CodeMatch(OpCodes.Stloc_S));
if (codeMatcher.IsInvalid)
{
Log.Warn("EnemyDFHiveSystem.GameTickLogic: Can't find operand_prefabDesc");
return codeMatcher.InstructionEnumeration();
}
var operand_prefabDesc = codeMatcher.Operand;

codeMatcher.Advance(1).Insert(
new CodeInstruction(OpCodes.Ldloc_S, operand_prefabDesc),
new CodeInstruction(OpCodes.Brfalse_S, operand_continue));

return codeMatcher.InstructionEnumeration();
}
catch (System.Exception e)
Expand Down

0 comments on commit 1a85fb6

Please sign in to comment.