Skip to content

Commit

Permalink
- yeesh, lotta max sct
Browse files Browse the repository at this point in the history
- minor prestige get info display fix
- deathmage owner buff skellies allied again
-fams have 10 minute death timer to get rid of after people log out since not destroying them when people log out anymore as the game no longer cares for that >_>
  • Loading branch information
mfoltz committed Nov 23, 2024
1 parent 4a1913c commit 0000f27
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 18 deletions.
127 changes: 123 additions & 4 deletions Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
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.UI;
using Stunlock.Core;
using System.Collections;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;

Expand All @@ -28,6 +30,9 @@ internal static class Core
public static ManualLogSource Log => Plugin.LogInstance;

static MonoBehaviour MonoBehaviour;

static readonly PrefabGUID ReturnBuff = new(-560330878);
static readonly PrefabGUID ReturnNoInvulnerableBuff = new(2086395440);
public static byte[] OLD_SHARED_KEY { get; internal set; }
public static byte[] NEW_SHARED_KEY { get; internal set; }

Expand All @@ -40,7 +45,7 @@ public static void Initialize()
_ = new LocalizationService();

if (ConfigService.ClientCompanion) _ = new EclipseService();

if (ConfigService.ExtraRecipes) RecipeUtilities.AddExtraRecipes();
if (ConfigService.StarterKit) ConfigUtilities.StarterKitItems();
if (ConfigService.PrestigeSystem) BuffUtilities.PrestigeBuffs();
Expand Down Expand Up @@ -85,10 +90,13 @@ public static void Initialize()
Core.Log.LogInfo("=============================");
}
*/

OLD_SHARED_KEY = Convert.FromBase64String(SecretManager.GetOldSharedKey());
NEW_SHARED_KEY = Convert.FromBase64String(SecretManager.GetNewSharedKey());


ModifyReturnBuffPrefabs();
//LogSCTPRefabs();

hasInitialized = true;
}
static World GetServerWorld()
Expand All @@ -105,4 +113,115 @@ public static void StartCoroutine(IEnumerator routine)

MonoBehaviour.StartCoroutine(routine.WrapToIl2Cpp());
}
static void ModifyReturnBuffPrefabs()
{
if (SystemService.PrefabCollectionSystem._PrefabGuidToEntityMap.TryGetValue(ReturnBuff, out Entity buffEntity))
{
if (buffEntity.TryGetBuffer<HealOnGameplayEvent>(out var buffer))
{
HealOnGameplayEvent healOnGameplayEvent = buffer[0];
healOnGameplayEvent.showSCT = false;

buffer[0] = healOnGameplayEvent;
}
}

if (SystemService.PrefabCollectionSystem._PrefabGuidToEntityMap.TryGetValue(ReturnNoInvulnerableBuff, out buffEntity))
{
if (buffEntity.TryGetBuffer<HealOnGameplayEvent>(out var buffer))
{
HealOnGameplayEvent healOnGameplayEvent = buffer[0];
healOnGameplayEvent.showSCT = false;

buffer[0] = healOnGameplayEvent;
}
}
}

static readonly PrefabGUID SCTPrefab = new(-1661525964);

static readonly ComponentType[] PrefabGUIDComponent =
[
ComponentType.ReadOnly(Il2CppType.Of<PrefabGUID>()),
];
static void LogSCTPRefabs()
{
EntityQuery prefabGUIDQuery = EntityManager.CreateEntityQuery(new EntityQueryDesc
{
All = PrefabGUIDComponent,
Options = EntityQueryOptions.IncludeDisabled
});

//int counter = 0;

Dictionary<string, Dictionary<string, Dictionary<string, int>>> playerOwnedTargetCounts = new();

NativeArray<Entity> entities = prefabGUIDQuery.ToEntityArray(Allocator.TempJob);
try
{
foreach (Entity entity in entities)
{
if (!entity.Has<SpawnTag>() && entity.TryGetComponent(out PrefabGUID prefabGUID))
{
if (prefabGUID.Equals(SCTPrefab) && entity.TryGetComponent(out ScrollingCombatTextMessage scrollingCombatTextMessage))
{
Entity target = scrollingCombatTextMessage.Target.GetEntityOnServer();
PrefabGUID prefabSCT = scrollingCombatTextMessage.Type; // SCT prefab type

if (target.TryGetComponent(out EntityOwner entityOwner)
&& entityOwner.Owner.IsPlayer()
&& target.TryGetComponent(out PrefabGUID targetPrefabGUID))
{
User user = entityOwner.Owner.GetUser();
string characterPrefabName = targetPrefabGUID.LookupName(); // Character prefab name
string sctPrefabName = prefabSCT.LookupName(); // SCT prefab name

// Initialize data structures if not present
if (!playerOwnedTargetCounts.ContainsKey(user.CharacterName.Value))
{
playerOwnedTargetCounts[user.CharacterName.Value] = new Dictionary<string, Dictionary<string, int>>();
}

if (!playerOwnedTargetCounts[user.CharacterName.Value].ContainsKey(characterPrefabName))
{
playerOwnedTargetCounts[user.CharacterName.Value][characterPrefabName] = new Dictionary<string, int>();
}

if (!playerOwnedTargetCounts[user.CharacterName.Value][characterPrefabName].ContainsKey(sctPrefabName))
{
playerOwnedTargetCounts[user.CharacterName.Value][characterPrefabName][sctPrefabName] = 1;
}
else
{
playerOwnedTargetCounts[user.CharacterName.Value][characterPrefabName][sctPrefabName]++;
}
}
}
}
}
}
finally
{
entities.Dispose();
prefabGUIDQuery.Dispose();

// Log the results
foreach (var playerEntry in playerOwnedTargetCounts)
{
Log.LogWarning($"Player: {playerEntry.Key}");
Log.LogWarning(new string('-', 20));

foreach (var characterPrefabEntry in playerEntry.Value)
{
Log.LogInfo($" CharacterPrefabGUID: {characterPrefabEntry.Key}");
foreach (var sctEntry in characterPrefabEntry.Value)
{
Log.LogInfo($" SCTPrefabName: {sctEntry.Key} | Count: {sctEntry.Value}");
}
}

Log.LogInfo(""); // Blank line for better readability
}
}
}
}
16 changes: 11 additions & 5 deletions Patches/DealDamageSystemPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static void OnUpdatePrefix(DealDamageSystem __instance)
{
if (!player.HasBuff(stormShield01))
{
BuffUtilities.TryApplyBuffWithOwner(player, userEntity, stormShield01);
BuffUtilities.TryApplyBuff(player, stormShield01);
}
else if (player.TryGetBuff(stormShield01, out Entity stormShieldFirstBuff))
{
Expand All @@ -126,7 +126,7 @@ static void OnUpdatePrefix(DealDamageSystem __instance)
age.Value = 0f;
});

BuffUtilities.TryApplyBuffWithOwner(player, userEntity, stormShield02);
BuffUtilities.TryApplyBuff(player, stormShield02);
}
}
else if (player.TryGetBuff(stormShield02, out Entity stormShieldSecondBuff))
Expand All @@ -136,7 +136,7 @@ static void OnUpdatePrefix(DealDamageSystem __instance)
age.Value = 0f;
});

BuffUtilities.TryApplyBuffWithOwner(player, userEntity, stormShield03);
BuffUtilities.TryApplyBuff(player, stormShield03);
}
}
else if (player.TryGetBuff(stormShield03, out Entity stormShieldThirdBuff))
Expand All @@ -149,12 +149,18 @@ static void OnUpdatePrefix(DealDamageSystem __instance)
}
else
{
BuffUtilities.TryApplyBuffWithOwner(player, userEntity, prefabGUID);
BuffUtilities.TryApplyBuff(player, prefabGUID);
}
}
else
{
BuffUtilities.TryApplyBuffWithOwner(dealDamageEvent.Target, userEntity, prefabGUID);
if (BuffUtilities.TryApplyBuff(dealDamageEvent.Target, prefabGUID) && dealDamageEvent.Target.TryGetBuff(prefabGUID, out Entity buffEntity))
{
buffEntity.With((ref EntityOwner entityOwner) =>
{
entityOwner.Owner = player;
});
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Patches/LinkMinionToOwnerOnSpawnSystemPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static void OnUpdatePrefix(LinkMinionToOwnerOnSpawnSystem __instance)
}
}

if (!GameMode.Equals(GameModeType.PvE)) entity.Write(new EntityOwner { Owner = player });
entity.Write(new EntityOwner { Owner = player });
}
}
else if (entityOwner.Owner.TryGetComponent(out entityOwner) && entityOwner.Owner.IsPlayer())
Expand Down
10 changes: 6 additions & 4 deletions Services/EclipseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public enum NetworkEventSubType
RegisterUser,
ProgressToClient,
ConfigsToClient,
UpdateShiftSlot
//UpdateShiftSlot
}
public static void HandleClientMessage(string message)
{
Expand Down Expand Up @@ -220,11 +220,12 @@ public static void SendClientAbilityData(Entity character)
Entity userEntity = character.Read<PlayerCharacter>().UserEntity;
User user = userEntity.Read<User>();

string message = BuildAbilityMessage(GetAbilityData(character));
string messageWithMAC = $"{message};mac{ChatMessageSystemPatch.GenerateMACV1_2_2(message)}";
//string message = BuildAbilityMessage(GetAbilityData(character));
//string messageWithMAC = $"{message};mac{ChatMessageSystemPatch.GenerateMACV1_2_2(message)}";

LocalizationService.HandleServerReply(EntityManager, user, messageWithMAC);
//LocalizationService.HandleServerReply(EntityManager, user, messageWithMAC);
}
/*
public static string BuildAbilityMessage((int prefabHash, int cooldown, int charges, int chargesCooldown) data)
{
var sb = new StringBuilder();
Expand All @@ -233,6 +234,7 @@ public static string BuildAbilityMessage((int prefabHash, int cooldown, int char
return sb.ToString();
}
*/
public static (int Percent, int Level, int Prestige, int Class) GetExperienceData(ulong steamId)
{
int experiencePercent = 0;
Expand Down
19 changes: 18 additions & 1 deletion Systems/Familiars/FamiliarSummonSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using ProjectM.Network;
using ProjectM.Scripting;
using ProjectM.Shared;
using ProjectM.UI;
using Stunlock.Core;
using Unity.Entities;
using Unity.Transforms;
Expand All @@ -27,13 +26,17 @@ internal static class FamiliarSummonSystem
static readonly GameDifficulty GameDifficulty = SystemService.ServerGameSettingsSystem.Settings.GameDifficulty;
static readonly GameModeType GameMode = SystemService.ServerGameSettingsSystem._Settings.GameModeType;

const float FAMILIAR_LIFETIME = 600f;

static readonly int MaxFamiliarLevel = ConfigService.MaxFamiliarLevel;
static readonly float FamiliarPrestigeStatMultiplier = ConfigService.FamiliarPrestigeStatMultiplier;
static readonly float VBloodDamageMultiplier = ConfigService.VBloodDamageMultiplier;

static readonly bool FamiliarPrestige = ConfigService.FamiliarPrestige;

static readonly PrefabGUID InvulnerableBuff = new(-480024072);
static readonly PrefabGUID InkCrawlerDeathBuff = new(1273155981);

static readonly PrefabGUID DivineAngel = new(-1737346940);

static readonly PrefabGUID IgnoredFaction = new(-1430861195);
Expand Down Expand Up @@ -120,6 +123,7 @@ public static bool ModifyFamiliar(User user, ulong steamId, int famKey, Entity p
ModifyCollision(familiar);
ModifyDropTable(familiar);
PreventDisableFamiliar(familiar);
NothingLivesForever(familiar);

if (!ConfigService.FamiliarCombat) DisableCombat(player, familiar);

Expand All @@ -146,6 +150,8 @@ public static bool ModifyFamiliar(User user, ulong steamId, int famKey, Entity p
return false;
}
}

/*
static void AddEquipment(Entity familiar)
{
if (ServerGameManager.TryGetBuffer<InteractAbilityBuffer>(familiar, out var buffer))
Expand Down Expand Up @@ -201,6 +207,7 @@ static void AddEquipment(Entity familiar)
}
}
}
*/
static void DisableCombat(Entity player, Entity familiar)
{
FactionReference factionReference = familiar.Read<FactionReference>();
Expand Down Expand Up @@ -396,6 +403,16 @@ public enum FamiliarStatType
{FamiliarStatType.CCReduction, 0.5f},
{FamiliarStatType.ShieldAbsorb, 1f}
};
static void NothingLivesForever(Entity familiar)
{
if (BuffUtilities.TryApplyBuff(familiar, InkCrawlerDeathBuff) && familiar.TryGetBuff(InkCrawlerDeathBuff, out Entity buffEntity))
{
buffEntity.With((ref LifeTime lifeTime) =>
{
lifeTime.Duration = FAMILIAR_LIFETIME;
});
}
}
public static void ModifyDamageStats(Entity familiar, int level, ulong steamId, int famKey)
{
float scalingFactor = 0.1f + (level / (float)MaxFamiliarLevel) * 0.9f; // Calculate scaling factor for power and such
Expand Down
7 changes: 4 additions & 3 deletions Systems/Leveling/PrestigeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,11 @@ public static void DisplayPrestigeInfo(ChatCommandContext ctx, ulong steamId, Pr
else
{
if (steamId.TryGetPlayerPrestiges(out var prestigeData) &&
prestigeData.TryGetValue(PrestigeType.Experience, out var expPrestigeLevel) && expPrestigeLevel > 0)
prestigeData.TryGetValue(parsedPrestigeType, out var parsedPrestigeLevel) && parsedPrestigeLevel > 0
&& prestigeData.TryGetValue(PrestigeType.Experience, out var expPrestigeLevel) && expPrestigeLevel > 0)
{
// Apply flat rate reduction for leveling experience
reductionFactor = ConfigService.LevelingPrestigeReducer * expPrestigeLevel;
reductionFactor = ConfigService.PrestigeRatesReducer * parsedPrestigeLevel;

// Apply rate gain with linear increase for expertise/legacy
gainFactor = ConfigService.PrestigeRateMultiplier * expPrestigeLevel;
Expand All @@ -367,7 +368,7 @@ public static void DisplayPrestigeInfo(ChatCommandContext ctx, ulong steamId, Pr
float statGainIncrease = ConfigService.PrestigeStatMultiplier * prestigeLevel;
string statGainString = (statGainIncrease * 100).ToString("F2") + "%";

string totalEffectString = (combinedFactor * 100).ToString("F2") + "%";
string totalEffectString = (combinedFactor >= 0 ? "+" : "-") + (combinedFactor * 100).ToString("F2") + "%";

LocalizationService.HandleReply(ctx, $"<color=#90EE90>{parsedPrestigeType}</color> Prestige Info:");
LocalizationService.HandleReply(ctx, $"Current Prestige Level: <color=yellow>{prestigeLevel}</color>/{maxPrestigeLevel}");
Expand Down

0 comments on commit 0000f27

Please sign in to comment.