/// <param name="logger">The logger instance to write to.</param> protected TraceLogSource() { LogSource = new ManualLogSource("Trace"); }
public Main() { this.timer = new Stopwatch(); this.ctorTimeStart(); instance = this; logSource = base.Logger; HashSet <String> submodules = new HashSet <String>(); this.CreateAccessors(); this.CreateCustomAccessors(); IncState(); this.working = true; this.Load += IncState; this.Enable += IncState; this.FirstFrame += IncState; this.CompatChecks(); if (this.working) { #if TIMER //this.watch = new Stopwatch(); this.Load += this.AwakeTimeStart; this.Enable += this.EnableTimeStart; this.FirstFrame += this.StartTimeStart; #endif this.Tick += () => RoR2Application.isModded = true; ReinCore.ReinCore.AddModHash(pluginGUID, Properties.Info.ver, useBuild, useRev, networkVersion); #if CROSSMODFUNCTIONALITY this.CrossModFunctionality(); #endif #if ROGUEWISP this.CreateRogueWisp(); #endif #if BOSSHPBAR this.EditBossHPBar(); #endif #if ANCIENTWISP this.CreateAncientWisp(); #endif #if ARCHAICWISP this.CreateArchaicWisp(); #endif #if FIRSTWISP this.CreateFirstWisp(); #endif #if WISPITEM this.CreateWispFriend(); #endif #if STAGE this.CreateStage(); #endif #if NETWORKING this.RegisterNetworkMessages(); #else this.SetupNetworkingFramework(); this.SetupNetworkingFunctions(); #endif #if SOUNDPLAYER this.SetupSoundPlayer(); #endif #if MATEDITOR this.SetupMatEditor(); #endif this.SetupSkinSelector(); this.SetupEffectSkinning(); #if LV1DPSTEST SpawnsCore.monsterEdits += this.SpawnsCore_monsterEdits1; RoR2.GlobalEventManager.onCharacterDeathGlobal += this.GlobalEventManager_onCharacterDeathGlobal; #endif this.FirstFrame += this.Main_FirstFrame; #if TIMER this.Load += this.AwakeTimeStop; this.Enable += this.EnableTimeStop; this.FirstFrame += this.StartTimeStop; #endif } else { Main.LogF("Rogue Wisp has failed to load properly and will not be enabled. See preceding errors."); } this.FirstFrame += this.Main_FirstFrame2; this.Enable += IncState; this.FirstFrame += IncState; this.ctorTimeStop(); }
public void Awake() { _logger = base.Logger; IL.RoR2.HealthComponent.ServerFixedUpdate += (il) => { ILCursor cursor = new ILCursor(il); bool ILFound = cursor.TryGotoNext( MoveType.After, x => x.MatchLdarg(0), x => x.MatchLdarg(0), x => x.MatchLdfld(typeof(HealthComponent).GetFieldCached("ospTimer")), x => x.MatchCall <UnityEngine.Time>("get_fixedDeltaTime"), x => x.MatchSub(), x => x.MatchStfld(typeof(HealthComponent).GetFieldCached("ospTimer")) ); if (ILFound) { cursor.Emit(OpCodes.Ldarg_0); cursor.EmitDelegate <Action <HealthComponent> >((healthComponent) => { if (!healthComponent) { return; } if (!healthComponent.body.hasOneShotProtection) { return; } AdditionalShieldInfo asi = null; if (!shieldInfoAttachments.TryGetValue(healthComponent, out asi)) { asi = new AdditionalShieldInfo(); asi.hadShields = healthComponent.shield > 0; shieldInfoAttachments.Add(healthComponent, asi); } else { asi.hadShields = healthComponent.shield > 0; } }); } else { Logger.Log(LogLevel.Error, "ShieldRebalance: failed to apply IL patch (HealthComponent.ServerFixedUpdate)! Mod will not work."); return; } }; IL.RoR2.HealthComponent.TakeDamage += (il) => { ILCursor cursor = new ILCursor(il); bool ILFound = cursor.TryGotoNext( MoveType.After, x => x.MatchLdarg(0), x => x.MatchLdfld(typeof(HealthComponent).GetFieldCached("body")), x => x.MatchCallvirt <CharacterBody>("get_hasOneShotProtection"), x => x.MatchBrfalse(out _), x => x.MatchLdarg(1), x => x.MatchLdfld(typeof(DamageInfo).GetFieldCached("damageType")), x => x.MatchLdcI4(out _), x => x.MatchAnd(), x => x.MatchLdcI4(out _), x => x.MatchBeq(out _) ); if (ILFound) { cursor.Emit(OpCodes.Ldarg_0); cursor.Emit(OpCodes.Ldloc, 5); cursor.Emit(OpCodes.Ldarg_0); cursor.Emit(OpCodes.Ldfld, typeof(HealthComponent).GetFieldCached("serverDamageTakenThisUpdate")); cursor.EmitDelegate <Func <HealthComponent, float, float, float> >((healthComponent, damage, serverDamageTakenThisUpdate) => { if (!healthComponent) { return(damage); } AdditionalShieldInfo asi = null; if (shieldInfoAttachments.TryGetValue(healthComponent, out asi)) { if (healthComponent.barrier <= 0) { if (asi.hadShields) { if (damage >= healthComponent.combinedHealth) { float healthDamage = Mathf.Max(0f, -((healthComponent.fullHealth * healthComponent.body.oneShotProtectionFraction) - healthComponent.health)); damage = healthComponent.shield + healthDamage; healthComponent.InvokeMethod("TriggerOneShotProtection"); return(damage); } } else { float num5 = (healthComponent.fullHealth) * (1f - healthComponent.body.oneShotProtectionFraction); float b = Mathf.Max(0f, num5 - serverDamageTakenThisUpdate); float originalDamage = damage; damage = Mathf.Min(damage, b); if (damage != originalDamage) { healthComponent.InvokeMethod("TriggerOneShotProtection"); } return(damage); } } } return(damage); }); cursor.Emit(OpCodes.Stloc, 5); } else { Logger.Log(LogLevel.Error, "ShieldRebalance: failed to apply IL patch (HealthComponent.TakeDamage)! Mod will not work."); return; } }; }