Skip to content

Commit

Permalink
- fixed admin add familiar command when using char name matching
Browse files Browse the repository at this point in the history
- cleaned up a few responses for fam commands
- finally got castle boy taken care of without game throwing any red, needed to be looking in ScriptSpawn instead of BuffSpawn
  • Loading branch information
mfoltz committed Sep 15, 2024
1 parent da93560 commit 01aad5f
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 29 deletions.
7 changes: 3 additions & 4 deletions Commands/FamiliarCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static void BindFamiliar(ChatCommandContext ctx, int choice)
{
if (choice < 1 || choice > famKeys.Count)
{
LocalizationService.HandleReply(ctx, $"Invalid choice, please use 1 to {famKeys.Count} (Current List:<color=white>{set}</color>)");
LocalizationService.HandleReply(ctx, $"Invalid choice, please use <color=white>1</color> to <color=white>{famKeys.Count}</color> (Current List: <color=yellow>{set}</color>)");
return;
}

Expand Down Expand Up @@ -352,8 +352,7 @@ public static void AddFamiliar(ChatCommandContext ctx, string name, string unit)
lastListName = $"box{unlocksData.UnlockedFamiliars.Count + 1}";
unlocksData.UnlockedFamiliars[lastListName] = [];
SaveUnlockedFamiliars(steamId, unlocksData);
FamiliarUtilities.
ParseAddedFamiliar(ctx, steamId, unit, lastListName);
FamiliarUtilities.ParseAddedFamiliar(ctx, steamId, unit, lastListName);
}
else
{
Expand All @@ -379,7 +378,7 @@ public static void RemoveFamiliarFromSet(ChatCommandContext ctx, int choice)
// Remove the old set
if (choice < 1 || choice > familiarSet.Count)
{
LocalizationService.HandleReply(ctx, $"Invalid choice, please use 1 to {familiarSet.Count} (Current List:<color=white>{familiarSet}</color>)");
LocalizationService.HandleReply(ctx, $"Invalid choice, please use <color=white>1</color> to <color=white>{familiarSet.Count}</color> (Current List:<color=yellow>{activeSet}</color>)");
return;
}
PrefabGUID familiarId = new(familiarSet[choice - 1]);
Expand Down
104 changes: 89 additions & 15 deletions Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@
using Bloodcraft.Systems.Leveling;
using Bloodcraft.Systems.Quests;
using Bloodcraft.Utilities;
using Il2CppInterop.Runtime;
using ProjectM;
using ProjectM.Network;
using ProjectM.Physics;
using ProjectM.Scripting;
using ProjectM.Shared;
using Stunlock.Core;
using System.Collections;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
using static Bloodcraft.Utilities.EntityUtilities;

namespace Bloodcraft;
internal static class Core
Expand All @@ -38,8 +31,6 @@ public static void Initialize()
{
if (hasInitialized) return;

//SCTFixTest(); // only useful for removing SCT prefabs if for some reason they are being generated in mass

hasInitialized = true;

_ = new PlayerService();
Expand Down Expand Up @@ -82,9 +73,10 @@ public static void StartCoroutine(IEnumerator routine)
MonoBehaviour.StartCoroutine(routine.WrapToIl2Cpp());
}

/*
static readonly ComponentType[] SCTComponent =
[
ComponentType.ReadOnly(Il2CppType.Of<PrefabGUID>()),
ComponentType.ReadOnly(Il2CppType.Of<ScrollingCombatTextMessage>()),
];
static readonly PrefabGUID SCTPrefab = new(-1661525964);
Expand All @@ -100,8 +92,12 @@ static void SCTFixTest() // one off thing hopefully but leaving since those have
int counter = 0;
try
{
Dictionary<string, Dictionary<string, int>> userTargetCounts = [];
IEnumerable<Entity> prefabEntities = GetEntitiesEnumerable(sctQuery); // destroy errant SCT entities and log what's going on
if (prefabEntities.Count() > 5000)
int entityCount = prefabEntities.Count();
Core.Log.LogInfo(entityCount); // okay yeah definitely something with either familiar summons or just undead summons?
if (entityCount > 5000)
{
foreach (Entity entity in prefabEntities)
{
Expand All @@ -111,12 +107,32 @@ static void SCTFixTest() // one off thing hopefully but leaving since those have
{
if (ServerGameManager.TryGetBuffer<SyncToUserBuffer>(entity, out var syncToUserBuffer))
{
if (entity.TryGetComponent(out ScrollingCombatTextMessage scrollingCombatText))
if (!syncToUserBuffer.IsEmpty)
{
Entity target = scrollingCombatText.Target.GetSyncedEntityOrNull();
if (target.Exists())
string userName = syncToUserBuffer[0].UserEntity.Read<User>().CharacterName.Value;
if (entity.TryGetComponent(out ScrollingCombatTextMessage scrollingCombatText))
{
DestroyUtility.Destroy(EntityManager, target);
Entity target = scrollingCombatText.Target.GetSyncedEntityOrNull();
if (target.Exists() && !target.IsPlayer())
{
string targetName = target.Read<PrefabGUID>().LookupName();
if (!userTargetCounts.ContainsKey(userName))
{
userTargetCounts[userName] = [];
}
Dictionary<string, int> targetCounts = userTargetCounts[userName];
if (!targetCounts.ContainsKey(targetName))
{
targetCounts[targetName] = 0;
}
targetCounts[targetName]++;
DestroyUtility.Destroy(EntityManager, target);
}
}
}
}
Expand All @@ -126,6 +142,20 @@ static void SCTFixTest() // one off thing hopefully but leaving since those have
}
Log.LogWarning($"Cleared {counter} SCT entities");
}
foreach (var userEntry in userTargetCounts)
{
string userName = userEntry.Key;
var targetCounts = userEntry.Value;
Log.LogInfo($"User: {userName}");
foreach (var targetEntry in targetCounts)
{
string targetName = targetEntry.Key;
int count = targetEntry.Value;
Log.LogInfo($"\tTarget: {targetName}, Count: {count}");
}
}
}
catch (Exception e)
{
Expand All @@ -136,4 +166,48 @@ static void SCTFixTest() // one off thing hopefully but leaving since those have
sctQuery.Dispose();
}
}
static readonly ComponentType[] PrefabGUIDComponent =
[
ComponentType.ReadOnly(Il2CppType.Of<PrefabGUID>()),
];
static readonly PrefabGUID WitheredPrefab = new(-1584807109);
static void UnitFixTest() // one off thing hopefully but leaving since those have a habit of coming back around
{
// -1661525964 SCT prefab
EntityQuery prefabQuery = EntityManager.CreateEntityQuery(new EntityQueryDesc
{
All = PrefabGUIDComponent,
Options = EntityQueryOptions.IncludeAll
});
try
{
Dictionary<string, Dictionary<string, int>> userTargetCounts = [];
IEnumerable<Entity> prefabEntities = GetEntitiesEnumerable(prefabQuery);
int entityCount = prefabEntities.Count();
int counter = 0;
//Core.Log.LogInfo(entityCount);
foreach (Entity entity in prefabEntities)
{
if (entity.TryGetComponent(out PrefabGUID prefab) && prefab.Equals(WitheredPrefab) && entity.Has<BlockFeedBuff>() && entity.TryGetComponent(out EntityOwner owner) && owner.Owner.Exists())
{
StatChangeUtility.KillOrDestroyEntity(EntityManager, entity, owner.Owner, owner.Owner, ServerTime, StatChangeReason.Default, true);
counter++;
}
}
Log.LogWarning($"Destroyed {counter} withered units");
}
catch (Exception e)
{
Log.LogError(e);
}
finally
{
prefabQuery.Dispose();
}
}
*/
}
13 changes: 8 additions & 5 deletions Patches/BuffSystemSpawnServerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Bloodcraft.Utilities;
using HarmonyLib;
using ProjectM;
using ProjectM.Gameplay.Scripting;
using ProjectM.Network;
using ProjectM.Scripting;
using ProjectM.Shared;
Expand Down Expand Up @@ -71,6 +70,7 @@ static void OnUpdatePrefix(BuffSystem_Spawn_Server __instance)
Entity player = Entity.Null;

// sections should be grouped appropriately to not interfere with each other
//Core.Log.LogInfo($"BuffSystem_Spawn_Server Prefix: {prefabGUID.LookupName()}");

/* there might be some reason I'm forgetting I don't just process these over in deathEventListerSystem but let's try and find out
if (prefabGUID.Equals(feedExecute) && entity.GetBuffTarget().TryGetPlayer(out player)) // feed execute kills
Expand Down Expand Up @@ -242,14 +242,17 @@ static void OnUpdatePrefix(BuffSystem_Spawn_Server __instance)
if (swordPermabuff.Has<AmplifyBuff>()) swordPermabuff.Remove<AmplifyBuff>();
}
}
else if (prefabGUID.Equals(castlemanCombatBuff))
{
if (entity.Has<Script_Castleman_AdaptLevel_DataShared>()) entity.Remove<Script_Castleman_AdaptLevel_DataShared>();
}
else if (prefabGUID.Equals(holyBeamPowerBuff))
{
if (entity.Has<LifeTime>()) entity.Write(new LifeTime { Duration = 30f, EndAction = LifeTimeEndAction.Destroy });
}
/* apparently doesn't actually go through here, huh
else if (prefabGUID.Equals(castlemanCombatBuff))
{
if (entity.Has<Script_Castleman_AdaptLevel_DataShared>()) entity.Remove<Script_Castleman_AdaptLevel_DataShared>();
Core.Log.LogInfo("Removed AdaptLevel from CastleMan combat buff...");
}
*/
}
}
/*
Expand Down
4 changes: 0 additions & 4 deletions Patches/LinkMinionToOwnerOnSpawnSystemPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ static void OnUpdatePrefix(LinkMinionToOwnerOnSpawnSystem __instance)
}
}
}
else if (entity.GetOwner().TryGetPlayer(out Entity character))
{
Core.Log.LogInfo($" {entity.Read<PrefabGUID>().LookupName()} minion linked to {character.Read<PlayerCharacter>().Name.Value}");
}
}
}
finally
Expand Down
14 changes: 14 additions & 0 deletions Patches/ScriptSpawnServerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using HarmonyLib;
using ProjectM;
using ProjectM.Gameplay.Scripting;
using ProjectM.Scripting;
using ProjectM.Shared.Systems;
using Stunlock.Core;
using Unity.Collections;
Expand All @@ -27,6 +28,19 @@ static void OnUpdatePrefix(ScriptSpawnServer __instance)
{
foreach (Entity entity in entities)
{
if (entity.Has<Script_Castleman_AdaptLevel_DataShared>())
{
//Core.Log.LogInfo("CastleManCombatBuff");
if (entity.GetBuffTarget().TryGetFollowedPlayer(out Entity _))
{
if (entity.Has<ScriptSpawn>()) entity.Remove<ScriptSpawn>();
if (entity.Has<ScriptUpdate>()) entity.Remove<ScriptUpdate>();
if (entity.Has<ScriptDestroy>()) entity.Remove<ScriptDestroy>();
if (entity.Has<Script_Buff_ModifyDynamicCollision_DataServer>()) entity.Remove<Script_Buff_ModifyDynamicCollision_DataServer>();
entity.Remove<Script_Castleman_AdaptLevel_DataShared>();
}
}

if (!entity.Has<BloodBuff>() || !entity.Has<EntityOwner>()) continue;

if (entity.GetOwner().TryGetPlayer(out Entity player))
Expand Down
2 changes: 1 addition & 1 deletion Utilities/FamiliarUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static void ParseAddedFamiliar(ChatCommandContext ctx, ulong steamId, str
return;
}

data.UnlockedFamiliars[activeSet].Add(prefab);
data.UnlockedFamiliars[activeSet].Add(result.GuidHash);
SaveUnlockedFamiliars(steamId, data);
LocalizationService.HandleReply(ctx, $"<color=green>{result.GetPrefabName()}</color> (<color=yellow>{result.GuidHash}</color>) added to <color=white>{activeSet}</color>.");
}
Expand Down

0 comments on commit 01aad5f

Please sign in to comment.