using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Managers;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("GlitnirRaces")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GlitnirRaces")]
[assembly: AssemblyTitle("GlitnirRaces")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("glitnir.races", "Glitnir Races", "2.1.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class GlitnirRacesPlugin : BaseUnityPlugin
{
public class RaceConfig
{
public string RaceId;
public string DisplayName;
public ConfigEntry<bool> Enabled;
public ConfigEntry<string> Scale;
public ConfigEntry<string> SkinColor;
public ConfigEntry<string> EarColor;
public ConfigEntry<string> EyeColor;
public ConfigEntry<string> SecretCode;
public ConfigEntry<string> Players;
}
[HarmonyPatch(typeof(Player), "OnDeath")]
private static class PlayerDeathPatch
{
private static void Prefix(Player __instance)
{
}
}
[HarmonyPatch(typeof(Player), "OnSpawned")]
private static class PlayerSpawnedPatch
{
private static void Postfix(Player __instance)
{
if (!((Object)(object)__instance == (Object)null) && !((Object)(object)Instance == (Object)null))
{
if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer)
{
Instance.RestoreLocalSavedRaceIfNeeded();
}
if (HasPlayer(LockedPlayers, __instance) || IsPlayerLocked(__instance))
{
SetZdoLocked(__instance, locked: true);
}
Instance.ApplyRaceWithDelays(__instance);
}
}
}
[HarmonyPatch(typeof(VisEquipment), "SetSkinColor")]
private static class PreventForcedRaceSkinOverridePatch
{
private static bool Prefix(VisEquipment __instance, Vector3 __0)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__instance == (Object)null)
{
return true;
}
if (IsApplyingRace)
{
return true;
}
Player component = ((Component)__instance).GetComponent<Player>();
if ((Object)(object)component == (Object)null)
{
return true;
}
string race = GetRace(component);
if (!RaceUsesForcedSkin(race))
{
return true;
}
CacheOriginalSkinValue(component, __0);
if ((Object)(object)Instance != (Object)null)
{
Instance.ForceSkinAfterVanilla(component, race);
}
return false;
}
}
[HarmonyPatch]
private static class VisEquipmentOnlineRefreshPatch
{
[CompilerGenerated]
private sealed class <TargetMethods>d__0 : IEnumerable<MethodBase>, IEnumerable, IEnumerator<MethodBase>, IDisposable, IEnumerator
{
private int <>1__state;
private MethodBase <>2__current;
private int <>l__initialThreadId;
private string[] <methodNames>5__1;
private string[] <>s__2;
private int <>s__3;
private string <methodName>5__4;
private MethodInfo <method>5__5;
MethodBase IEnumerator<MethodBase>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <TargetMethods>d__0(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<methodNames>5__1 = null;
<>s__2 = null;
<methodName>5__4 = null;
<method>5__5 = null;
<>1__state = -2;
}
private bool MoveNext()
{
int num = <>1__state;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -1;
goto IL_00eb;
}
<>1__state = -1;
<methodNames>5__1 = new string[9] { "UpdateEquipmentVisuals", "UpdateVisuals", "SetChestItem", "SetLegItem", "SetHelmetItem", "SetShoulderItem", "SetUtilityItem", "SetLeftItem", "SetRightItem" };
<>s__2 = <methodNames>5__1;
<>s__3 = 0;
goto IL_0108;
IL_00eb:
<method>5__5 = null;
<methodName>5__4 = null;
<>s__3++;
goto IL_0108;
IL_0108:
if (<>s__3 < <>s__2.Length)
{
<methodName>5__4 = <>s__2[<>s__3];
<method>5__5 = AccessTools.Method(typeof(VisEquipment), <methodName>5__4, (Type[])null, (Type[])null);
if (<method>5__5 != null)
{
<>2__current = <method>5__5;
<>1__state = 1;
return true;
}
goto IL_00eb;
}
<>s__2 = null;
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<MethodBase> IEnumerable<MethodBase>.GetEnumerator()
{
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
return this;
}
return new <TargetMethods>d__0(0);
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<MethodBase>)this).GetEnumerator();
}
}
[IteratorStateMachine(typeof(<TargetMethods>d__0))]
private static IEnumerable<MethodBase> TargetMethods()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <TargetMethods>d__0(-2);
}
private static void Postfix(VisEquipment __instance)
{
if (!((Object)(object)__instance == (Object)null) && !((Object)(object)Instance == (Object)null) && !IsApplyingRace)
{
Instance.ForceSkinAfterVanilla(__instance);
}
}
}
[HarmonyPatch]
private static class PlayerOnlineRefreshPatch
{
[CompilerGenerated]
private sealed class <TargetMethods>d__0 : IEnumerable<MethodBase>, IEnumerable, IEnumerator<MethodBase>, IDisposable, IEnumerator
{
private int <>1__state;
private MethodBase <>2__current;
private int <>l__initialThreadId;
private string[] <methodNames>5__1;
private string[] <>s__2;
private int <>s__3;
private string <methodName>5__4;
private MethodInfo <method>5__5;
MethodBase IEnumerator<MethodBase>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <TargetMethods>d__0(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<methodNames>5__1 = null;
<>s__2 = null;
<methodName>5__4 = null;
<method>5__5 = null;
<>1__state = -2;
}
private bool MoveNext()
{
int num = <>1__state;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -1;
goto IL_00ba;
}
<>1__state = -1;
<methodNames>5__1 = new string[3] { "UpdateEquipment", "OnInventoryChanged", "UpdateVisual" };
<>s__2 = <methodNames>5__1;
<>s__3 = 0;
goto IL_00d7;
IL_00ba:
<method>5__5 = null;
<methodName>5__4 = null;
<>s__3++;
goto IL_00d7;
IL_00d7:
if (<>s__3 < <>s__2.Length)
{
<methodName>5__4 = <>s__2[<>s__3];
<method>5__5 = AccessTools.Method(typeof(Player), <methodName>5__4, (Type[])null, (Type[])null);
if (<method>5__5 != null)
{
<>2__current = <method>5__5;
<>1__state = 1;
return true;
}
goto IL_00ba;
}
<>s__2 = null;
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<MethodBase> IEnumerable<MethodBase>.GetEnumerator()
{
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
return this;
}
return new <TargetMethods>d__0(0);
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<MethodBase>)this).GetEnumerator();
}
}
[IteratorStateMachine(typeof(<TargetMethods>d__0))]
private static IEnumerable<MethodBase> TargetMethods()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <TargetMethods>d__0(-2);
}
private static void Postfix(Player __instance)
{
if (!((Object)(object)__instance == (Object)null) && !((Object)(object)Instance == (Object)null) && !IsApplyingRace)
{
Instance.RequestOnlineVisualRefresh(__instance);
}
}
}
[HarmonyPatch(typeof(Chat), "InputText")]
private static class ChatPatch
{
private static bool Prefix(Chat __instance)
{
object input = ((Terminal)__instance).m_input;
string text = GetInputText(input).Trim();
if (TrySecretRaceCode(text, input))
{
return false;
}
return true;
}
private static bool TrySecretRaceCode(string text, object input)
{
string raceFromSecretCode = GetRaceFromSecretCode(text);
if (raceFromSecretCode == null)
{
return false;
}
TransformLocalPlayerFromMarketplace(raceFromSecretCode);
SetInputText(input, "");
return true;
}
private static string GetInputText(object input)
{
if (input == null)
{
return "";
}
PropertyInfo propertyInfo = input.GetType().GetProperty("text") ?? input.GetType().GetProperty("Text");
return (!(propertyInfo != null)) ? "" : (propertyInfo.GetValue(input)?.ToString() ?? "");
}
private static void SetInputText(object input, string value)
{
if (input != null)
{
PropertyInfo propertyInfo = input.GetType().GetProperty("text") ?? input.GetType().GetProperty("Text");
if (propertyInfo != null && propertyInfo.CanWrite)
{
propertyInfo.SetValue(input, value);
}
}
}
}
[CompilerGenerated]
private sealed class <ApplyRaceDelayed>d__70 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public Player p;
public float delay;
public GlitnirRacesPlugin <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ApplyRaceDelayed>d__70(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(delay);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
if ((Object)(object)p != (Object)null)
{
<>4__this.ApplyRace(p);
}
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <ForceSkinRefresh>d__72 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public Player p;
public string race;
public GlitnirRacesPlugin <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ForceSkinRefresh>d__72(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Expected O, but got Unknown
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = null;
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
<>4__this.ForceSkinNow(p, race);
<>2__current = (object)new WaitForSeconds(0.05f);
<>1__state = 2;
return true;
case 2:
<>1__state = -1;
<>4__this.ForceSkinNow(p, race);
<>2__current = (object)new WaitForSeconds(0.2f);
<>1__state = 3;
return true;
case 3:
<>1__state = -1;
<>4__this.ForceSkinNow(p, race);
<>2__current = (object)new WaitForSeconds(0.5f);
<>1__state = 4;
return true;
case 4:
<>1__state = -1;
<>4__this.ForceSkinNow(p, race);
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 5;
return true;
case 5:
<>1__state = -1;
<>4__this.ForceSkinNow(p, race);
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private const string ModGUID = "glitnir.races";
private const string ModName = "Glitnir Races";
private const string ModVersion = "2.1.2";
private const string RaceOrc = "orc";
private const string RaceElf = "elfo";
private const string RaceDarkElf = "elfonegro";
private const string RaceDwarf = "anao";
private const string RaceHalfling = "halfling";
private const string RaceHuman = "humano";
private const string RaceJotun = "jotun";
private const string ZdoRaceKey = "GlitnirRace";
private const string ZdoLockedKey = "GlitnirRaceLocked";
private const string ZdoEarColorKey = "GlitnirRaceEarColor";
private const string ZdoSkinColorKey = "GlitnirRaceSkinColor";
private const string RpcSetRace = "GlitnirRaces_SetRace";
private readonly Harmony harmony = new Harmony("glitnir.races");
public static GlitnirRacesPlugin Instance;
public static readonly Dictionary<string, RaceConfig> Races = new Dictionary<string, RaceConfig>();
public static ConfigEntry<string> LockedPlayers;
private static GameObject ElfEarsPrefab;
private static GameObject OrcEarsPrefab;
private static GameObject HighElfEyesPrefab;
private static GameObject OrcTuskPrefab;
private static bool IsApplyingRace = false;
private static bool RpcRegistered = false;
private static readonly Dictionary<long, string> NetworkRaces = new Dictionary<long, string>();
private static readonly Dictionary<string, string> LastAppliedRace = new Dictionary<string, string>();
private static readonly Dictionary<string, Vector3> OriginalSkinColors = new Dictionary<string, Vector3>();
private static readonly Dictionary<string, float> LastSkinRefreshRequest = new Dictionary<string, float>();
private static readonly Dictionary<Transform, Vector3> OrcHelmetOriginalScale = new Dictionary<Transform, Vector3>();
private static readonly Dictionary<Transform, Vector3> OrcHelmetOriginalPosition = new Dictionary<Transform, Vector3>();
private float timer = 0f;
private float syncTimer = 0f;
private float localSaveTimer = 0f;
private static readonly Vector3 HumanScale = Vector3.one;
private static readonly Vector3 OrcHelmetScaleMult = new Vector3(1.18f, 1.18f, 1.18f);
private static readonly Vector3 OrcHelmetOffset = new Vector3(0f, 0.015f, 0f);
private static readonly Vector3 ElfEarPosition = new Vector3(0f, 0f, 0f);
private static readonly Vector3 ElfEarRotation = new Vector3(0f, 0f, 0f);
private static readonly Vector3 ElfEarScale = new Vector3(1f, 1f, 1f);
private static readonly Vector3 OrcEarPosition = new Vector3(0.0002f, 0.001225f, 0.000934f);
private static readonly Vector3 OrcEarRotation = new Vector3(24.5f, 81.89f, -2.969f);
private static readonly Vector3 OrcEarScale = new Vector3(1.137024f, 1.637663f, 1.083586f);
private static readonly Vector3 HighElfEyesPosition = new Vector3(-0.0063f, -0.0194f, -0.00017f);
private static readonly Vector3 HighElfEyesRotation = new Vector3(-18.776f, -89.449f, -0.691f);
private static readonly Vector3 HighElfEyesScale = new Vector3(0.00993f, 0.011539f, 0.01272f);
private static readonly Vector3 OrcTuskPosition = new Vector3(-0.00137f, 0.00114f, -0.00014f);
private static readonly Vector3 OrcTuskRotation = new Vector3(-16.932f, -110.817f, 8.571f);
private static readonly Vector3 OrcTuskScale = new Vector3(0.00494f, 0.005076f, 0.00559f);
private void Awake()
{
Instance = this;
CreateRaceConfigs();
LockedPlayers = SyncedConfig("Geral", "PlayersBloqueados", "", "Players que já escolheram raça. Use ID ou nome separado por vírgula.");
SynchronizationManager.OnConfigurationSynchronized += OnConfigurationSynchronized;
LoadAssets();
RegisterCommands();
harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Glitnir Races 2.1.2 carregado!");
}
private void CreateRaceConfigs()
{
Races.Clear();
CreateRaceConfig("orc", "Orc", enabled: true, "1.2,1.2,1.2", "#448512", "#448512", "#FF0000", "IIIIIiiiilllllIII");
CreateRaceConfig("elfo", "Alto Elfo", enabled: true, "1,1,1", "-1", "-1", "#00FF00", "IIIIIiiiillllll");
CreateRaceConfig("elfonegro", "Elfo Negro", enabled: true, "1,1,1", "#341539", "#341539", "#FFFF00", "IIIIIiiiillllIll");
CreateRaceConfig("anao", "Anão", enabled: true, "1,0.8,0.8", "-1", "-1", "#E0B0FF", "IIIIIiiiilllllil");
CreateRaceConfig("halfling", "Halfling", enabled: true, "1,0.8,0.8", "-1", "-1", "#FF7518", "IIIIIiiiillllliI");
CreateRaceConfig("jotun", "Jotun", enabled: true, "1.2,1.2,1.2", "#4cc0dd", "#4cc0dd", "#6dceee", "IIIIIiiiilllJOTUN");
CreateRaceConfig("humano", "Humano", enabled: true, "1,1,1", "-1", "-1", "#00F0FF", "IIIIIiiiilllllll");
}
private void CreateRaceConfig(string raceId, string displayName, bool enabled, string scale, string skinColor, string earColor, string eyeColor, string secretCode)
{
string group = "Raca - " + displayName;
RaceConfig value = new RaceConfig
{
RaceId = raceId,
DisplayName = displayName,
Enabled = SyncedConfig(group, "Usar", enabled, "Ativa ou desativa a raça " + displayName + "."),
Scale = SyncedConfig(group, "Tamanho", scale, "Tamanho da raça no formato X,Y,Z. Exemplo: 1.2,1.2,1.2"),
SkinColor = SyncedConfig(group, "Cor", skinColor, "Cor da pele em HEX. Exemplo: #33732E. Também aceita R,G,B. Use -1 para não alterar a cor escolhida pelo player."),
EarColor = SyncedConfig(group, "CorOrelha", earColor, "Cor da orelha em HEX. Exemplo: #89F336. Também aceita R,G,B. Use -1 para usar a cor da pele/config da raça."),
EyeColor = SyncedConfig(group, "CorOlho", eyeColor, "Cor brilhante dos olhos em HEX. Exemplo: #FF0000."),
SecretCode = SyncedConfig(group, "CodigoSecreto", secretCode, "Código secreto usado no chat para escolher essa raça."),
Players = SyncedConfig(group, "Players", "", "Players definidos como " + displayName + ". Use ID ou nome separado por vírgula.")
};
Races[raceId] = value;
}
private ConfigEntry<T> SyncedConfig<T>(string group, string name, T value, string description)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Expected O, but got Unknown
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
{
IsAdminOnly = true
};
ConfigDescription val2 = new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { val });
return ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, val2);
}
private void OnConfigurationSynchronized(object sender, EventArgs args)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Configuração sincronizada pelo Jotunn.");
if ((Object)(object)Player.m_localPlayer == (Object)null)
{
return;
}
foreach (Player allPlayer in Player.GetAllPlayers())
{
ApplyRaceWithDelays(allPlayer);
}
}
private void LoadAssets()
{
ElfEarsPrefab = LoadPrefabFromEmbedded("elf_ears");
OrcEarsPrefab = LoadPrefabFromEmbedded("orc_ears");
HighElfEyesPrefab = LoadPrefabFromEmbedded("high_elf_eyes");
OrcTuskPrefab = LoadPrefabFromEmbedded("orc_tusk");
}
private GameObject LoadPrefabFromEmbedded(string assetName)
{
try
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string x) => x.EndsWith(assetName));
if (text == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Asset embutido " + assetName + " não encontrado dentro da DLL."));
string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
foreach (string text2 in manifestResourceNames)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("RESOURCE: " + text2));
}
return null;
}
using Stream stream = executingAssembly.GetManifestResourceStream(text);
if (stream == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Stream do asset embutido " + assetName + " veio nulo."));
return null;
}
byte[] array;
using (MemoryStream memoryStream = new MemoryStream())
{
stream.CopyTo(memoryStream);
array = memoryStream.ToArray();
}
AssetBundle val = AssetBundle.LoadFromMemory(array);
if ((Object)(object)val == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Falha ao carregar AssetBundle embutido: " + assetName));
return null;
}
GameObject val2 = val.LoadAsset<GameObject>(assetName);
if ((Object)(object)val2 == (Object)null)
{
val2 = val.LoadAllAssets<GameObject>().FirstOrDefault();
}
if ((Object)(object)val2 == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Nenhum prefab encontrado dentro do AssetBundle embutido " + assetName + "."));
}
else
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("Prefab embutido " + assetName + " carregado com sucesso."));
}
return val2;
}
catch (Exception arg)
{
((BaseUnityPlugin)this).Logger.LogError((object)$"Erro ao carregar asset embutido {assetName}: {arg}");
return null;
}
}
private void RegisterCommands()
{
RegisterRaceCommand("orc");
RegisterRaceCommand("elfo");
RegisterRaceCommand("elfonegro");
RegisterRaceCommand("anao");
RegisterRaceCommand("halfling");
RegisterRaceCommand("humano");
RegisterRaceCommand("jotun");
RegisterResetRaceCommand();
foreach (KeyValuePair<string, RaceConfig> race in Races)
{
string value = race.Value.SecretCode.Value;
string key = race.Key;
if (!string.IsNullOrWhiteSpace(value))
{
RegisterSecretCodeCommand(value, key);
}
}
}
private void RegisterSecretCodeCommand(string code, string race)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
new ConsoleCommand(code, "", (ConsoleEvent)delegate
{
TransformLocalPlayerFromMarketplace(race);
}, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
}
private void RegisterRaceCommand(string race)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
new ConsoleCommand(race, race + " me ou " + race + " NomeDoPlayer", (ConsoleEvent)delegate(ConsoleEventArgs args)
{
if (!HasDevCommands())
{
args.Context.AddString("Apenas ADM com devcommands pode usar este comando.");
}
else if (!IsRaceEnabled(race))
{
args.Context.AddString("A raça " + GetRaceName(race) + " está desativada na config.");
}
else if (args.Args.Length < 2)
{
args.Context.AddString("Uso: " + race + " me ou " + race + " NomeDoPlayer");
}
else
{
Player targetPlayer = GetTargetPlayer(args);
if ((Object)(object)targetPlayer == (Object)null)
{
args.Context.AddString("Player não encontrado.");
}
else
{
SetRace(targetPlayer, race, lockPlayer: false, broadcast: true);
ApplyRaceWithDelays(targetPlayer);
SpawnEffect(targetPlayer);
args.Context.AddString(targetPlayer.GetPlayerName() + " agora é " + GetRaceName(race) + ".");
}
}
}, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
}
private void RegisterResetRaceCommand()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Expected O, but got Unknown
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
new ConsoleCommand("racareset", "racareset me ou racareset NomeDoPlayer", (ConsoleEvent)delegate(ConsoleEventArgs args)
{
if (!HasDevCommands())
{
args.Context.AddString("Apenas ADM com devcommands pode usar este comando.");
}
else if (args.Args.Length < 2)
{
args.Context.AddString("Uso: racareset me ou racareset NomeDoPlayer");
}
else
{
Player targetPlayer2 = GetTargetPlayer(args);
if ((Object)(object)targetPlayer2 == (Object)null)
{
args.Context.AddString("Player não encontrado.");
}
else
{
ResetRace(targetPlayer2, broadcast: true);
args.Context.AddString("Raça de " + targetPlayer2.GetPlayerName() + " removida.");
}
}
}, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
new ConsoleCommand("racadesfazer", "racadesfazer me ou racadesfazer NomeDoPlayer", (ConsoleEvent)delegate(ConsoleEventArgs args)
{
if (!HasDevCommands())
{
args.Context.AddString("Apenas ADM com devcommands pode usar este comando.");
}
else if (args.Args.Length < 2)
{
args.Context.AddString("Uso: racadesfazer me ou racadesfazer NomeDoPlayer");
}
else
{
Player targetPlayer = GetTargetPlayer(args);
if ((Object)(object)targetPlayer == (Object)null)
{
args.Context.AddString("Player não encontrado.");
}
else
{
ResetRace(targetPlayer, broadcast: true);
args.Context.AddString("Raça de " + targetPlayer.GetPlayerName() + " desfeita.");
}
}
}, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
}
private Player GetTargetPlayer(ConsoleEventArgs args)
{
string typedName = string.Join(" ", args.Args.Skip(1)).Trim();
if (typedName.Equals("me", StringComparison.OrdinalIgnoreCase))
{
return Player.m_localPlayer;
}
return ((IEnumerable<Player>)Player.GetAllPlayers()).FirstOrDefault((Func<Player, bool>)((Player p) => (Object)(object)p != (Object)null && p.GetPlayerName().Equals(typedName, StringComparison.OrdinalIgnoreCase)));
}
private void Update()
{
RegisterRpcIfNeeded();
syncTimer += Time.deltaTime;
if (syncTimer >= 2f)
{
syncTimer = 0f;
SyncLocalRace();
}
localSaveTimer += Time.deltaTime;
if (localSaveTimer >= 3f)
{
localSaveTimer = 0f;
RestoreLocalSavedRaceIfNeeded();
}
timer += Time.deltaTime;
if (timer < 0.6f)
{
return;
}
timer = 0f;
if ((Object)(object)Player.m_localPlayer == (Object)null)
{
return;
}
foreach (Player allPlayer in Player.GetAllPlayers())
{
ApplyRace(allPlayer);
}
}
private void RestoreLocalSavedRaceIfNeeded()
{
Player localPlayer = Player.m_localPlayer;
if ((Object)(object)localPlayer == (Object)null)
{
return;
}
string savedLocalRace = GetSavedLocalRace();
if (string.IsNullOrWhiteSpace(savedLocalRace) || !IsRaceEnabled(savedLocalRace))
{
return;
}
string race = GetRace(localPlayer);
if (string.IsNullOrWhiteSpace(race))
{
long playerIdLong = GetPlayerIdLong(localPlayer);
if (playerIdLong != 0)
{
NetworkRaces[playerIdLong] = savedLocalRace;
}
SetZdoRace(localPlayer, savedLocalRace);
SetRaceVisualZdo(localPlayer, savedLocalRace);
SetZdoLocked(localPlayer, locked: true);
BroadcastRace(localPlayer, savedLocalRace);
ApplyRaceWithDelays(localPlayer);
}
else
{
SetZdoLocked(localPlayer, locked: true);
}
}
private void RegisterRpcIfNeeded()
{
if (!RpcRegistered && ZRoutedRpc.instance != null)
{
ZRoutedRpc.instance.Register<long, string>("GlitnirRaces_SetRace", (Action<long, long, string>)RPC_SetRace);
RpcRegistered = true;
((BaseUnityPlugin)this).Logger.LogInfo((object)"RPC multiplayer do Glitnir Races registrado.");
}
}
private static void RPC_SetRace(long sender, long playerId, string race)
{
if (playerId == 0)
{
return;
}
Player val = FindPlayerById(playerId);
if (string.IsNullOrWhiteSpace(race))
{
NetworkRaces.Remove(playerId);
if ((Object)(object)val != (Object)null && (Object)(object)Instance != (Object)null)
{
Instance.ResetRace(val, broadcast: false);
}
return;
}
NetworkRaces[playerId] = race;
if ((Object)(object)val != (Object)null && (Object)(object)Instance != (Object)null)
{
SetZdoRace(val, race);
SetRaceVisualZdo(val, race);
if ((Object)(object)val == (Object)(object)Player.m_localPlayer)
{
SaveLocalRace(race, locked: true);
}
Instance.ApplyRaceWithDelays(val);
}
}
private static void BroadcastRace(Player player, string race)
{
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)player == (Object)null || ZRoutedRpc.instance == null)
{
return;
}
long playerIdLong = GetPlayerIdLong(player);
if (playerIdLong != 0)
{
if (string.IsNullOrWhiteSpace(race))
{
NetworkRaces.Remove(playerIdLong);
SetZdoRace(player, "");
SetZdoLocked(player, locked: false);
SetZdoVector(player, "GlitnirRaceEarColor", new Vector3(-1f, -1f, -1f));
SetZdoVector(player, "GlitnirRaceSkinColor", new Vector3(-1f, -1f, -1f));
}
else
{
NetworkRaces[playerIdLong] = race;
SetZdoRace(player, race);
SetRaceVisualZdo(player, race);
}
ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "GlitnirRaces_SetRace", new object[2]
{
playerIdLong,
race ?? ""
});
}
}
private void SyncLocalRace()
{
Player localPlayer = Player.m_localPlayer;
if (!((Object)(object)localPlayer == (Object)null) && !IsDedicatedOrRemoteServer())
{
string race = GetRace(localPlayer);
if (!string.IsNullOrWhiteSpace(race))
{
BroadcastRace(localPlayer, race);
}
}
}
private static Player FindPlayerById(long playerId)
{
if (playerId == 0)
{
return null;
}
return ((IEnumerable<Player>)Player.GetAllPlayers()).FirstOrDefault((Func<Player, bool>)((Player p) => (Object)(object)p != (Object)null && GetPlayerIdLong(p) == playerId));
}
private void ApplyRaceWithDelays(Player p)
{
if (!((Object)(object)p == (Object)null))
{
ApplyRace(p);
((MonoBehaviour)this).StartCoroutine(ApplyRaceDelayed(p, 0.1f));
((MonoBehaviour)this).StartCoroutine(ApplyRaceDelayed(p, 0.5f));
((MonoBehaviour)this).StartCoroutine(ApplyRaceDelayed(p, 1f));
((MonoBehaviour)this).StartCoroutine(ApplyRaceDelayed(p, 2f));
}
}
[IteratorStateMachine(typeof(<ApplyRaceDelayed>d__70))]
private IEnumerator ApplyRaceDelayed(Player p, float delay)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ApplyRaceDelayed>d__70(0)
{
<>4__this = this,
p = p,
delay = delay
};
}
private void QueueSkinRefresh(Player p, string race)
{
if (!((Object)(object)p == (Object)null) && !string.IsNullOrWhiteSpace(race))
{
string text = GetVisualKey(p);
if (string.IsNullOrWhiteSpace(text))
{
text = ((Object)p).GetInstanceID().ToString();
}
float time = Time.time;
if (!LastSkinRefreshRequest.TryGetValue(text, out var value) || !(time - value < 1.25f))
{
LastSkinRefreshRequest[text] = time;
((MonoBehaviour)this).StartCoroutine(ForceSkinRefresh(p, race));
}
}
}
[IteratorStateMachine(typeof(<ForceSkinRefresh>d__72))]
private IEnumerator ForceSkinRefresh(Player p, string race)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ForceSkinRefresh>d__72(0)
{
<>4__this = this,
p = p,
race = race
};
}
private void ForceSkinNow(Player p, string race)
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)p == (Object)null || string.IsNullOrWhiteSpace(race) || GetRace(p) != race)
{
return;
}
bool isApplyingRace = IsApplyingRace;
IsApplyingRace = true;
try
{
if (RaceUsesForcedSkin(race))
{
ApplySkin(p, GetNetworkSkinColor(p, race));
}
switch (race)
{
case "orc":
ApplyOrcEars(p, ToColor(GetRaceEarColor(p, race)));
break;
case "elfonegro":
ApplyEars(p, ToColor(GetRaceEarColor(p, race)));
break;
case "jotun":
ApplyOrcEars(p, ToColor(GetRaceEarColor(p, race)));
break;
default:
if (!(race == "halfling"))
{
break;
}
goto case "elfo";
case "elfo":
ApplyEars(p, ToColor(GetRaceEarColor(p, race)));
break;
}
Transform obj = FindHead(((Component)p).transform);
Transform val = ((obj != null) ? obj.Find("HighElfEyes") : null);
if ((Object)(object)val != (Object)null)
{
ApplyEyeColor(val, GetRaceEyeColor(race));
}
}
finally
{
IsApplyingRace = isApplyingRace;
}
}
public void RequestOnlineVisualRefresh(Player p)
{
if ((Object)(object)p == (Object)null)
{
return;
}
string race = GetRace(p);
if (!string.IsNullOrWhiteSpace(race))
{
ApplyRaceWithDelays(p);
if (RaceUsesForcedSkin(race) || race == "elfo" || race == "halfling")
{
QueueSkinRefresh(p, race);
}
}
}
public void RequestOnlineVisualRefresh(VisEquipment vis)
{
if (!((Object)(object)vis == (Object)null))
{
Player val = ((Component)vis).GetComponent<Player>();
if ((Object)(object)val == (Object)null)
{
val = ((Component)vis).GetComponentInParent<Player>();
}
if ((Object)(object)val != (Object)null)
{
RequestOnlineVisualRefresh(val);
}
}
}
public void ForceSkinAfterVanilla(Player p, string race)
{
if (!((Object)(object)p == (Object)null) && !string.IsNullOrWhiteSpace(race))
{
QueueSkinRefresh(p, race);
}
}
public void ForceSkinAfterVanilla(VisEquipment vis)
{
if ((Object)(object)vis == (Object)null)
{
return;
}
Player val = ((Component)vis).GetComponent<Player>();
if ((Object)(object)val == (Object)null)
{
val = ((Component)vis).GetComponentInParent<Player>();
}
if (!((Object)(object)val == (Object)null))
{
string race = GetRace(val);
if (RaceUsesForcedSkin(race) || race == "elfo" || race == "halfling")
{
QueueSkinRefresh(val, race);
}
}
}
public void ApplyRace(Player p)
{
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_0153: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_0357: Unknown result type (might be due to invalid IL or missing references)
//IL_035c: Unknown result type (might be due to invalid IL or missing references)
//IL_02de: Unknown result type (might be due to invalid IL or missing references)
//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0304: Unknown result type (might be due to invalid IL or missing references)
//IL_0326: Unknown result type (might be due to invalid IL or missing references)
//IL_032b: Unknown result type (might be due to invalid IL or missing references)
//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)p == (Object)null || IsApplyingRace)
{
return;
}
string race = GetRace(p);
string visualKey = GetVisualKey(p);
string value = "";
if (!string.IsNullOrWhiteSpace(visualKey))
{
LastAppliedRace.TryGetValue(visualKey, out value);
}
bool flag = value != race;
IsApplyingRace = true;
try
{
if (flag)
{
if (value == "orc")
{
ResetOrcHelmet(p);
}
((Component)p).transform.localScale = HumanScale;
if (RaceUsesForcedSkin(value))
{
ResetSkin(p);
}
RemoveHeadAttachment(p, "Ears");
RemoveHeadAttachment(p, "OrcEars");
RemoveHeadAttachment(p, "HighElfEyes");
RemoveHeadAttachment(p, "OrcTusk");
RemovePlayerAttachment(p, "JotunFreeze");
if (!string.IsNullOrWhiteSpace(visualKey))
{
LastAppliedRace[visualKey] = race;
}
}
if (string.IsNullOrWhiteSpace(race))
{
((Component)p).transform.localScale = HumanScale;
return;
}
if (!IsRaceEnabled(race))
{
((Component)p).transform.localScale = HumanScale;
return;
}
Vector3 raceScale = GetRaceScale(race);
((Component)p).transform.localScale = raceScale;
if (RaceUsesForcedSkin(race))
{
CacheOriginalSkinIfNeeded(p);
ApplySkin(p, GetNetworkSkinColor(p, race));
QueueSkinRefresh(p, race);
}
switch (race)
{
case "orc":
ApplyOrcEars(p, ToColor(GetRaceEarColor(p, race)));
ApplyHighElfEyes(p);
ApplyOrcTusk(p);
ScaleOrcHelmet(p);
break;
case "elfonegro":
ApplyEars(p, ToColor(GetRaceEarColor(p, race)));
ApplyHighElfEyes(p);
break;
case "elfo":
ApplyEars(p, ToColor(GetRaceEarColor(p, race)));
QueueSkinRefresh(p, race);
ApplyHighElfEyes(p);
break;
case "halfling":
ApplyEars(p, ToColor(GetRaceEarColor(p, race)));
QueueSkinRefresh(p, race);
ApplyHighElfEyes(p);
break;
case "anao":
ApplyHighElfEyes(p);
break;
case "jotun":
ApplyOrcEars(p, ToColor(GetRaceEarColor(p, race)));
ApplyHighElfEyes(p);
ApplyFreezingEffect(p);
break;
case "humano":
ApplyHighElfEyes(p);
break;
}
}
finally
{
IsApplyingRace = false;
}
}
private static void SetRaceVisualZdo(Player player, string race)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)player == (Object)null) && !string.IsNullOrWhiteSpace(race))
{
SetZdoVector(player, "GlitnirRaceEarColor", GetCalculatedRaceEarColor(player, race));
if (RaceUsesForcedSkin(race))
{
SetZdoVector(player, "GlitnirRaceSkinColor", GetRaceSkinColor(race));
}
}
}
private static Vector3 GetRaceEarColor(Player p, string race)
{
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
if (!string.IsNullOrWhiteSpace(race) && Races.TryGetValue(race, out var value))
{
Vector3 val = ParseColorConfig(value.EarColor.Value, new Vector3(-1f, -1f, -1f));
if (val.x >= 0f && val.y >= 0f && val.z >= 0f)
{
return val;
}
}
Vector3 zdoVector = GetZdoVector(p, "GlitnirRaceEarColor", new Vector3(-1f, -1f, -1f));
if (zdoVector.x >= 0f && zdoVector.y >= 0f && zdoVector.z >= 0f)
{
return zdoVector;
}
if (RaceUsesForcedSkin(race))
{
return GetNetworkSkinColor(p, race);
}
if ((Object)(object)Instance != (Object)null)
{
return Instance.GetCurrentSkinVector(p);
}
return Vector3.one;
}
private static Vector3 GetCalculatedRaceEarColor(Player p, string race)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
if (!string.IsNullOrWhiteSpace(race) && Races.TryGetValue(race, out var value))
{
Vector3 val = ParseColorConfig(value.EarColor.Value, new Vector3(-1f, -1f, -1f));
if (val.x >= 0f && val.y >= 0f && val.z >= 0f)
{
return val;
}
}
if (RaceUsesForcedSkin(race))
{
return GetRaceSkinColor(race);
}
if ((Object)(object)Instance != (Object)null)
{
return Instance.GetCurrentSkinVector(p);
}
return Vector3.one;
}
private static Vector3 GetNetworkSkinColor(Player p, string race)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
if (RaceUsesForcedSkin(race))
{
return GetRaceSkinColor(race);
}
Vector3 zdoVector = GetZdoVector(p, "GlitnirRaceSkinColor", new Vector3(-1f, -1f, -1f));
if (zdoVector.x >= 0f && zdoVector.y >= 0f && zdoVector.z >= 0f)
{
return zdoVector;
}
return GetRaceSkinColor(race);
}
private static Color GetRaceEyeColor(string race)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
if (!Races.TryGetValue(race, out var value))
{
return Color.cyan;
}
Vector3 val = ParseColorConfig(value.EyeColor.Value, new Vector3(0f, 1f, 1f));
if (val.x < 0f || val.y < 0f || val.z < 0f)
{
return Color.cyan;
}
return new Color(val.x, val.y, val.z, 1f);
}
private void ApplyEyeColor(Transform t, Color color)
{
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)t == (Object)null)
{
return;
}
Renderer[] componentsInChildren = ((Component)t).GetComponentsInChildren<Renderer>(true);
foreach (Renderer val in componentsInChildren)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
Material[] materials = val.materials;
foreach (Material val2 in materials)
{
if (!((Object)(object)val2 == (Object)null))
{
if (val2.HasProperty("_EmissionColor"))
{
val2.EnableKeyword("_EMISSION");
val2.SetColor("_EmissionColor", color * 3.5f);
}
if (val2.HasProperty("_Color"))
{
val2.SetColor("_Color", color);
}
if (val2.HasProperty("_BaseColor"))
{
val2.SetColor("_BaseColor", color);
}
if (val2.HasProperty("_TintColor"))
{
val2.SetColor("_TintColor", color);
}
}
}
}
}
private void ApplyFreezingEffect(Player p)
{
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)p == (Object)null || (Object)(object)ZNetScene.instance == (Object)null)
{
return;
}
Transform val = ((Component)p).transform.Find("JotunFreeze");
if (!((Object)(object)val != (Object)null))
{
GameObject prefab = ZNetScene.instance.GetPrefab("vfx_Freezing");
if ((Object)(object)prefab == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"vfx_Freezing não encontrado.");
return;
}
GameObject val2 = Object.Instantiate<GameObject>(prefab, ((Component)p).transform);
((Object)val2).name = "JotunFreeze";
val2.transform.localPosition = Vector3.zero;
val2.transform.localRotation = Quaternion.identity;
val2.transform.localScale = Vector3.one;
}
}
private void RemovePlayerAttachment(Player p, string objectName)
{
if (!((Object)(object)p == (Object)null))
{
Transform val = ((Component)p).transform.Find(objectName);
if ((Object)(object)val != (Object)null)
{
Object.Destroy((Object)(object)((Component)val).gameObject);
}
}
}
private void ScaleOrcHelmet(Player p)
{
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)p == (Object)null || GetRace(p) != "orc")
{
return;
}
HashSet<Transform> hashSet = new HashSet<Transform>();
Renderer[] componentsInChildren = ((Component)p).GetComponentsInChildren<Renderer>(true);
foreach (Renderer val in componentsInChildren)
{
if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).transform == (Object)null))
{
Transform transform = ((Component)val).transform;
string text = GetTransformPath(transform).ToLowerInvariant();
bool flag = text.Contains("helmet") || text.Contains("helm") || text.Contains("headgear");
bool flag2 = text.Contains("hair") || text.Contains("beard") || text.Contains("ear") || text.Contains("orc") || text.Contains("tusk") || text.Contains("eye") || text.Contains("high");
if (!(!flag || flag2))
{
hashSet.Add(transform);
}
}
}
foreach (Transform item in hashSet)
{
if (!OrcHelmetOriginalScale.ContainsKey(item))
{
OrcHelmetOriginalScale[item] = item.localScale;
}
if (!OrcHelmetOriginalPosition.ContainsKey(item))
{
OrcHelmetOriginalPosition[item] = item.localPosition;
}
Vector3 val2 = OrcHelmetOriginalScale[item];
Vector3 val3 = OrcHelmetOriginalPosition[item];
item.localScale = new Vector3(val2.x * OrcHelmetScaleMult.x, val2.y * OrcHelmetScaleMult.y, val2.z * OrcHelmetScaleMult.z);
item.localPosition = val3 + OrcHelmetOffset;
}
}
private void ResetOrcHelmet(Player p)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)p == (Object)null)
{
return;
}
Transform[] componentsInChildren = ((Component)p).GetComponentsInChildren<Transform>(true);
foreach (Transform val in componentsInChildren)
{
if (!((Object)(object)val == (Object)null))
{
if (OrcHelmetOriginalScale.TryGetValue(val, out var value))
{
val.localScale = value;
}
if (OrcHelmetOriginalPosition.TryGetValue(val, out var value2))
{
val.localPosition = value2;
}
}
}
}
private string GetTransformPath(Transform t)
{
if ((Object)(object)t == (Object)null)
{
return "";
}
string text = ((Object)t).name;
Transform parent = t.parent;
while ((Object)(object)parent != (Object)null)
{
text = ((Object)parent).name + "/" + text;
parent = parent.parent;
}
return text;
}
private bool SetRace(Player player, string race, bool lockPlayer, bool broadcast)
{
if ((Object)(object)player == (Object)null)
{
return false;
}
if (!IsRaceEnabled(race))
{
return false;
}
if (RaceUsesForcedSkin(race))
{
CacheOriginalSkinIfNeeded(player);
}
string playerId = GetPlayerId(player);
string playerName = player.GetPlayerName();
long playerIdLong = GetPlayerIdLong(player);
ClearRace(playerId, playerName);
if (race != "humano" && Races.TryGetValue(race, out var value))
{
Add(value.Players, playerId);
}
if (playerIdLong != 0)
{
NetworkRaces[playerIdLong] = race;
}
SetZdoRace(player, race);
SetRaceVisualZdo(player, race);
if ((Object)(object)player == (Object)(object)Player.m_localPlayer)
{
SaveLocalRace(race, lockPlayer || IsPlayerLocked(player));
}
if (broadcast)
{
BroadcastRace(player, race);
}
if (lockPlayer)
{
Add(LockedPlayers, playerId);
Add(LockedPlayers, playerName);
SetZdoLocked(player, locked: true);
}
return true;
}
private void ResetRace(Player player, bool broadcast)
{
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)player == (Object)null))
{
string playerId = GetPlayerId(player);
string playerName = player.GetPlayerName();
long playerIdLong = GetPlayerIdLong(player);
string visualKey = GetVisualKey(player);
ClearRace(playerId, playerName);
Remove(LockedPlayers, playerId);
Remove(LockedPlayers, playerName);
if (playerIdLong != 0)
{
NetworkRaces.Remove(playerIdLong);
}
if (!string.IsNullOrWhiteSpace(visualKey))
{
LastAppliedRace[visualKey] = "";
}
SetZdoRace(player, "");
SetZdoLocked(player, locked: false);
SetZdoVector(player, "GlitnirRaceEarColor", new Vector3(-1f, -1f, -1f));
SetZdoVector(player, "GlitnirRaceSkinColor", new Vector3(-1f, -1f, -1f));
if ((Object)(object)player == (Object)(object)Player.m_localPlayer)
{
ClearLocalSavedRace();
}
ResetOrcHelmet(player);
ResetSkin(player);
((Component)player).transform.localScale = HumanScale;
RemoveHeadAttachment(player, "Ears");
RemoveHeadAttachment(player, "OrcEars");
RemoveHeadAttachment(player, "HighElfEyes");
RemoveHeadAttachment(player, "OrcTusk");
RemovePlayerAttachment(player, "JotunFreeze");
ApplyRaceWithDelays(player);
if (broadcast)
{
BroadcastRace(player, "");
}
}
}
private static bool IsDedicatedOrRemoteServer()
{
try
{
if ((Object)(object)ZNet.instance == (Object)null)
{
return false;
}
return !ZNet.instance.IsServer();
}
catch
{
return false;
}
}
private static bool IsRaceEnabled(string race)
{
if (string.IsNullOrWhiteSpace(race))
{
return false;
}
if (!Races.TryGetValue(race, out var value))
{
return false;
}
return value.Enabled.Value;
}
private static bool RaceUsesForcedSkin(string race)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
if (string.IsNullOrWhiteSpace(race))
{
return false;
}
if (!Races.TryGetValue(race, out var value))
{
return false;
}
Vector3 val = ParseColorConfig(value.SkinColor.Value, new Vector3(-1f, -1f, -1f));
return val.x >= 0f && val.y >= 0f && val.z >= 0f;
}
private static Vector3 GetRaceScale(string race)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
if (!Races.TryGetValue(race, out var value))
{
return HumanScale;
}
return ParseVector(value.Scale.Value, HumanScale);
}
private static Vector3 GetRaceSkinColor(string race)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
if (!Races.TryGetValue(race, out var value))
{
return Vector3.one;
}
return ParseColorConfig(value.SkinColor.Value, Vector3.one);
}
private static Vector3 ParseVector(string value, Vector3 fallback)
{
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
try
{
if (string.IsNullOrWhiteSpace(value))
{
return fallback;
}
string[] array = value.Split(new char[1] { ',' });
if (array.Length != 3)
{
return fallback;
}
float num = float.Parse(array[0].Trim(), CultureInfo.InvariantCulture);
float num2 = float.Parse(array[1].Trim(), CultureInfo.InvariantCulture);
float num3 = float.Parse(array[2].Trim(), CultureInfo.InvariantCulture);
return new Vector3(num, num2, num3);
}
catch
{
return fallback;
}
}
private static Vector3 ParseColorConfig(string value, Vector3 fallback)
{
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
try
{
if (string.IsNullOrWhiteSpace(value))
{
return fallback;
}
value = value.Trim();
if (value.Equals("-1", StringComparison.OrdinalIgnoreCase) || value.Equals("none", StringComparison.OrdinalIgnoreCase) || value.Equals("nao", StringComparison.OrdinalIgnoreCase) || value.Equals("não", StringComparison.OrdinalIgnoreCase) || value.Equals("-1,-1,-1", StringComparison.OrdinalIgnoreCase))
{
return new Vector3(-1f, -1f, -1f);
}
if (value.StartsWith("#"))
{
Color val = default(Color);
if (ColorUtility.TryParseHtmlString(value, ref val))
{
return new Vector3(val.r, val.g, val.b);
}
return fallback;
}
return ParseVector(value, fallback);
}
catch
{
return fallback;
}
}
private static string GetRace(Player player)
{
if ((Object)(object)player == (Object)null)
{
return "";
}
long playerIdLong = GetPlayerIdLong(player);
string zdoRace = GetZdoRace(player);
if (!string.IsNullOrWhiteSpace(zdoRace))
{
if (playerIdLong != 0)
{
NetworkRaces[playerIdLong] = zdoRace;
}
return zdoRace;
}
foreach (KeyValuePair<string, RaceConfig> race in Races)
{
if (race.Key == "humano" || !HasPlayer(race.Value.Players, player))
{
continue;
}
if (playerIdLong != 0)
{
NetworkRaces[playerIdLong] = race.Key;
}
return race.Key;
}
if (!IsDedicatedOrRemoteServer() && playerIdLong != 0L && NetworkRaces.TryGetValue(playerIdLong, out var value) && !string.IsNullOrWhiteSpace(value))
{
return value;
}
return "";
}
private static void SetZdoRace(Player player, string race)
{
if ((Object)(object)player == (Object)null)
{
return;
}
try
{
ZNetView component = ((Component)player).GetComponent<ZNetView>();
if (!((Object)(object)component == (Object)null) && component.GetZDO() != null)
{
component.GetZDO().Set("GlitnirRace", race);
}
}
catch
{
}
}
private static string GetZdoRace(Player player)
{
if ((Object)(object)player == (Object)null)
{
return "";
}
try
{
ZNetView component = ((Component)player).GetComponent<ZNetView>();
if ((Object)(object)component == (Object)null || component.GetZDO() == null)
{
return "";
}
return component.GetZDO().GetString("GlitnirRace", "");
}
catch
{
return "";
}
}
private static void SetZdoLocked(Player player, bool locked)
{
if ((Object)(object)player == (Object)null)
{
return;
}
try
{
ZNetView component = ((Component)player).GetComponent<ZNetView>();
if (!((Object)(object)component == (Object)null) && component.GetZDO() != null)
{
component.GetZDO().Set("GlitnirRaceLocked", locked);
}
}
catch
{
}
}
private static bool GetZdoLocked(Player player)
{
if ((Object)(object)player == (Object)null)
{
return false;
}
try
{
ZNetView component = ((Component)player).GetComponent<ZNetView>();
if ((Object)(object)component == (Object)null || component.GetZDO() == null)
{
return false;
}
return component.GetZDO().GetBool("GlitnirRaceLocked", false);
}
catch
{
return false;
}
}
private static void SetZdoVector(Player player, string key, Vector3 value)
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)player == (Object)null || string.IsNullOrWhiteSpace(key))
{
return;
}
try
{
ZNetView component = ((Component)player).GetComponent<ZNetView>();
if (!((Object)(object)component == (Object)null) && component.GetZDO() != null)
{
component.GetZDO().Set(key + "_x", value.x);
component.GetZDO().Set(key + "_y", value.y);
component.GetZDO().Set(key + "_z", value.z);
}
}
catch
{
}
}
private static Vector3 GetZdoVector(Player player, string key, Vector3 fallback)
{
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)player == (Object)null || string.IsNullOrWhiteSpace(key))
{
return fallback;
}
try
{
ZNetView component = ((Component)player).GetComponent<ZNetView>();
if ((Object)(object)component == (Object)null || component.GetZDO() == null)
{
return fallback;
}
float @float = component.GetZDO().GetFloat(key + "_x", fallback.x);
float float2 = component.GetZDO().GetFloat(key + "_y", fallback.y);
float float3 = component.GetZDO().GetFloat(key + "_z", fallback.z);
return new Vector3(@float, float2, float3);
}
catch
{
return fallback;
}
}
private static bool IsPlayerLocked(Player player)
{
if ((Object)(object)player == (Object)null)
{
return false;
}
if (GetZdoLocked(player))
{
return true;
}
if ((Object)(object)player == (Object)(object)Player.m_localPlayer && !IsDedicatedOrRemoteServer() && HasSavedLocalRaceLocked())
{
return true;
}
if (HasPlayer(LockedPlayers, player))
{
return true;
}
return false;
}
private static string GetLocalSavePrefix()
{
return "GlitnirRaces_" + GetCurrentWorldOrServerKey() + "_";
}
private static string GetSavedLocalRace()
{
try
{
return PlayerPrefs.GetString(GetLocalSavePrefix() + "Race", "");
}
catch
{
return "";
}
}
private static bool HasSavedLocalRaceLocked()
{
try
{
return PlayerPrefs.GetInt(GetLocalSavePrefix() + "Locked", 0) == 1;
}
catch
{
return false;
}
}
private static string GetCurrentWorldOrServerKey()
{
try
{
if ((Object)(object)ZNet.instance == (Object)null)
{
return "unknown";
}
string text = (ZNet.instance.IsServer() ? "local" : "remote");
string text2 = "";
if (!ZNet.instance.IsServer())
{
text2 = ReadStringField(ZNet.instance, "m_serverHost");
if (string.IsNullOrWhiteSpace(text2))
{
text2 = ReadStringField(ZNet.instance, "m_serverName");
}
if (string.IsNullOrWhiteSpace(text2))
{
text2 = ReadStringField(ZNet.instance, "m_hostName");
}
}
else
{
MethodInfo methodInfo = AccessTools.Method(typeof(ZNet), "GetWorldName", (Type[])null, (Type[])null);
if (methodInfo != null)
{
text2 = methodInfo.Invoke(ZNet.instance, null)?.ToString() ?? "";
}
if (string.IsNullOrWhiteSpace(text2))
{
text2 = ReadStringField(ZNet.instance, "m_worldName");
}
}
if (string.IsNullOrWhiteSpace(text2))
{
text2 = "unknown";
}
return SanitizePlayerPrefsKey(text + "_" + text2);
}
catch
{
return "unknown";
}
}
private static string ReadStringField(object obj, string fieldName)
{
try
{
if (obj == null)
{
return "";
}
FieldInfo fieldInfo = AccessTools.Field(obj.GetType(), fieldName);
if (fieldInfo == null)
{
return "";
}
return fieldInfo.GetValue(obj)?.ToString() ?? "";
}
catch
{
return "";
}
}
private static string SanitizePlayerPrefsKey(string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return "unknown";
}
char[] array = value.ToCharArray();
for (int i = 0; i < array.Length; i++)
{
if (!char.IsLetterOrDigit(array[i]) && array[i] != '_' && array[i] != '-')
{
array[i] = '_';
}
}
return new string(array);
}
private static void SaveLocalRace(string race, bool locked)
{
if (string.IsNullOrWhiteSpace(race))
{
return;
}
try
{
PlayerPrefs.SetString(GetLocalSavePrefix() + "Race", race);
if (locked)
{
PlayerPrefs.SetInt(GetLocalSavePrefix() + "Locked", 1);
}
PlayerPrefs.Save();
}
catch
{
}
}
private static void ClearLocalSavedRace()
{
try
{
PlayerPrefs.DeleteKey(GetLocalSavePrefix() + "Race");
PlayerPrefs.DeleteKey(GetLocalSavePrefix() + "Locked");
PlayerPrefs.Save();
}
catch
{
}
}
private string GetRaceName(string race)
{
if (Races.TryGetValue(race, out var value))
{
return value.DisplayName;
}
return race;
}
private static void TransformLocalPlayerFromMarketplace(string race)
{
Player localPlayer = Player.m_localPlayer;
if ((Object)(object)localPlayer == (Object)null || (Object)(object)Instance == (Object)null)
{
return;
}
if (!IsRaceEnabled(race))
{
((Character)localPlayer).Message((MessageType)2, "Essa raça está desativada.", 0, (Sprite)null);
return;
}
if (RaceUsesForcedSkin(race))
{
Instance.CacheOriginalSkinIfNeeded(localPlayer);
}
if (IsPlayerLocked(localPlayer) || (!IsDedicatedOrRemoteServer() && HasSavedLocalRaceLocked()))
{
Instance.RestoreLocalSavedRaceIfNeeded();
((Character)localPlayer).Message((MessageType)2, "Você ja faz parte de uma raça!", 0, (Sprite)null);
return;
}
Instance.SetRace(localPlayer, race, lockPlayer: true, broadcast: true);
Instance.ApplyRaceWithDelays(localPlayer);
Instance.SpawnEffect(localPlayer);
((Character)localPlayer).Message((MessageType)2, "Agora eu sou: " + Instance.GetRaceName(race), 0, (Sprite)null);
}
public void SpawnEffect(Player p)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)p == (Object)null) && !((Object)(object)ZNetScene.instance == (Object)null))
{
Vector3 val = ((Component)p).transform.position + Vector3.up * 1f;
Quaternion rotation = ((Component)p).transform.rotation;
GameObject prefab = ZNetScene.instance.GetPrefab("fx_Fader_Roar");
GameObject prefab2 = ZNetScene.instance.GetPrefab("fx_Fader_Roar_Projectile_Hit");
if ((Object)(object)prefab != (Object)null)
{
Object.Instantiate<GameObject>(prefab, val, rotation);
}
if ((Object)(object)prefab2 != (Object)null)
{
Object.Instantiate<GameObject>(prefab2, val, rotation);
}
}
}
private void ApplySkin(Player p, Vector3 color)
{
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
VisEquipment component = ((Component)p).GetComponent<VisEquipment>();
if (!((Object)(object)component == (Object)null))
{
MethodInfo method = typeof(VisEquipment).GetMethod("SetSkinColor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (method != null)
{
method.Invoke(component, new object[1] { color });
}
}
}
private void CacheOriginalSkinIfNeeded(Player p)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)p == (Object)null))
{
string visualKey = GetVisualKey(p);
if (!string.IsNullOrWhiteSpace(visualKey) && !OriginalSkinColors.ContainsKey(visualKey))
{
OriginalSkinColors[visualKey] = GetCurrentSkinVector(p);
}
}
}
private static void CacheOriginalSkinValue(Player p, Vector3 skin)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)p == (Object)null))
{
string visualKey = GetVisualKey(p);
if (!string.IsNullOrWhiteSpace(visualKey) && !OriginalSkinColors.ContainsKey(visualKey))
{
OriginalSkinColors[visualKey] = skin;
}
}
}
private void ResetSkin(Player p)
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)p == (Object)null))
{
string visualKey = GetVisualKey(p);
if (!string.IsNullOrWhiteSpace(visualKey) && OriginalSkinColors.TryGetValue(visualKey, out var value))
{
ApplySkin(p, value);
}
}
}
private Vector3 GetCurrentSkinVector(Player p)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)p == (Object)null)
{
return Vector3.one;
}
VisEquipment component = ((Component)p).GetComponent<VisEquipment>();
if ((Object)(object)component == (Object)null)
{
return Vector3.one;
}
try
{
FieldInfo field = typeof(VisEquipment).GetField("m_skinColor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
object value = field.GetValue(component);
if (value is Vector3)
{
Vector3 result = (Vector3)value;
if (true)
{
return result;
}
}
}
}
catch
{
}
return Vector3.one;
}
private void ApplyEars(Player p, Color color)
{
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)p == (Object)null || (Object)(object)ElfEarsPrefab == (Object)null)
{
return;
}
Transform val = FindHead(((Component)p).transform);
if (!((Object)(object)val == (Object)null))
{
Transform val2 = val.Find("Ears");
if ((Object)(object)val2 == (Object)null)
{
GameObject val3 = Object.Instantiate<GameObject>(ElfEarsPrefab, val);
((Object)val3).name = "Ears";
StripItemComponents(val3);
val2 = val3.transform;
}
val2.localPosition = ElfEarPosition;
val2.localRotation = Quaternion.Euler(ElfEarRotation);
val2.localScale = ElfEarScale;
FixEarMaterials(val2);
ApplyColor(val2, color);
}
}
private void ApplyOrcEars(Player p, Color color)
{
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)p == (Object)null)
{
return;
}
if ((Object)(object)OrcEarsPrefab == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Prefab de orelha Orc não encontrado. Verifique o AssetBundle orc_ears.");
return;
}
Transform val = FindHead(((Component)p).transform);
if (!((Object)(object)val == (Object)null))
{
Transform val2 = val.Find("OrcEars");
if ((Object)(object)val2 == (Object)null)
{
GameObject val3 = Object.Instantiate<GameObject>(OrcEarsPrefab, val);
((Object)val3).name = "OrcEars";
StripItemComponents(val3);
val2 = val3.transform;
}
val2.localPosition = OrcEarPosition;
val2.localRotation = Quaternion.Euler(OrcEarRotation);
val2.localScale = new Vector3(OrcEarScale.x / ((Component)p).transform.localScale.x, OrcEarScale.y / ((Component)p).transform.localScale.y, OrcEarScale.z / ((Component)p).transform.localScale.z);
FixEarMaterials(val2);
ApplyColor(val2, color);
}
}
private void ApplyHighElfEyes(Player p)
{
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)p == (Object)null)
{
return;
}
if ((Object)(object)HighElfEyesPrefab == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Prefab de olhos não encontrado. Verifique o AssetBundle high_elf_eyes.");
return;
}
Transform val = FindHead(((Component)p).transform);
if (!((Object)(object)val == (Object)null))
{
Transform val2 = val.Find("HighElfEyes");
if ((Object)(object)val2 == (Object)null)
{
GameObject val3 = Object.Instantiate<GameObject>(HighElfEyesPrefab, val);
((Object)val3).name = "HighElfEyes";
StripItemComponents(val3);
val2 = val3.transform;
}
val2.localPosition = HighElfEyesPosition;
val2.localRotation = Quaternion.Euler(HighElfEyesRotation);
val2.localScale = HighElfEyesScale;
ApplyEyeColor(val2, GetRaceEyeColor(GetRace(p)));
}
}
private void ApplyOrcTusk(Player p)
{
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)p == (Object)null)
{
return;
}
if ((Object)(object)OrcTuskPrefab == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Prefab de dente Orc não encontrado. Verifique o AssetBundle orc_tusk.");
return;
}
Transform val = FindHead(((Component)p).transform);
if (!((Object)(object)val == (Object)null))
{
Transform val2 = val.Find("OrcTusk");
if ((Object)(object)val2 == (Object)null)
{
GameObject val3 = Object.Instantiate<GameObject>(OrcTuskPrefab, val);
((Object)val3).name = "OrcTusk";
StripItemComponents(val3);
FixEarMaterials(val3.transform);
val2 = val3.transform;
}
val2.localPosition = OrcTuskPosition;
val2.localRotation = Quaternion.Euler(OrcTuskRotation);
val2.localScale = OrcTuskScale;
FixEarMaterials(val2);
}
}
private void RemoveHeadAttachment(Player p, string objectName)
{
if ((Object)(object)p == (Object)null)
{
return;
}
Transform val = FindHead(((Component)p).transform);
if (!((Object)(object)val == (Object)null))
{
Transform val2 = val.Find(objectName);
if ((Object)(object)val2 != (Object)null)
{
Object.Destroy((Object)(object)((Component)val2).gameObject);
}
}
}
private void FixEarMaterials(Transform t)
{
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)t == (Object)null)
{
return;
}
Shader val = Shader.Find("Standard");
Renderer[] componentsInChildren = ((Component)t).GetComponentsInChildren<Renderer>(true);
foreach (Renderer val2 in componentsInChildren)
{
if ((Object)(object)val2 == (Object)null)
{
continue;
}
Material[] materials = val2.materials;
foreach (Material val3 in materials)
{
if (!((Object)(object)val3 == (Object)null))
{
if (val3.IsKeywordEnabled("_EMISSION"))
{
val3.DisableKeyword("_EMISSION");
}
if (val3.HasProperty("_EmissionColor"))
{
val3.SetColor("_EmissionColor", Color.black);
}
if ((Object)(object)val != (Object)null)
{
val3.shader = val;
}
}
}
}
}
private void ApplyColor(Transform t, Color c)
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)t == (Object)null)
{
return;
}
Renderer[] componentsInChildren = ((Component)t).GetComponentsInChildren<Renderer>(true);
foreach (Renderer val in componentsInChildren)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
Material[] materials = val.materials;
foreach (Material val2 in materials)
{
if (!((Object)(object)val2 == (Object)null))
{
val2.color = c;
if (val2.HasProperty("_Color"))
{
val2.SetColor("_Color", c);
}
if (val2.HasProperty("_BaseColor"))
{
val2.SetColor("_BaseColor", c);
}
if (val2.HasProperty("_TintColor"))
{
val2.SetColor("_TintColor", c);
}
}
}
}
}
private Transform FindHead(Transform t)
{
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Expected O, but got Unknown
if ((Object)(object)t == (Object)null)
{
return null;
}
string text = ((Object)t).name.ToLowerInvariant();
if (text == "head" || text.Contains("head") || text.Contains("bip001 head") || text.Contains("helmet_attach") || text.Contains("head_attach"))
{
return t;
}
foreach (Transform item in t)
{
Transform t2 = item;
Transform val = FindHead(t2);
if ((Object)(object)val != (Object)null)
{
return val;
}
}
return null;
}
private void StripItemComponents(GameObject obj)
{
if (!((Object)(object)obj == (Object)null))
{
Collider[] componentsInChildren = obj.GetComponentsInChildren<Collider>(true);
foreach (Collider val in componentsInChildren)
{
Object.Destroy((Object)(object)val);
}
Rigidbody[] componentsInChildren2 = obj.GetComponentsInChildren<Rigidbody>(true);
foreach (Rigidbody val2 in componentsInChildren2)
{
Object.Destroy((Object)(object)val2);
}
ItemDrop[] componentsInChildren3 = obj.GetComponentsInChildren<ItemDrop>(true);
foreach (ItemDrop val3 in componentsInChildren3)
{
Object.Destroy((Object)(object)val3);
}
ZNetView[] componentsInChildren4 = obj.GetComponentsInChildren<ZNetView>(true);
foreach (ZNetView val4 in componentsInChildren4)
{
Object.Destroy((Object)(object)val4);
}
}
}
private static Color ToColor(Vector3 v)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
return new Color(v.x, v.y, v.z, 1f);
}
private static string GetPlayerId(Player player)
{
long playerIdLong = GetPlayerIdLong(player);
if (playerIdLong != 0)
{
return playerIdLong.ToString();
}
return ((Object)(object)player != (Object)null) ? player.GetPlayerName() : "";
}
private static string GetVisualKey(Player player)
{
if ((Object)(object)player == (Object)null)
{
return "";
}
long playerIdLong = GetPlayerIdLong(player);
if (playerIdLong != 0)
{
return playerIdLong.ToString();
}
return player.GetPlayerName();
}
private static long GetPlayerIdLong(Player player)
{
if ((Object)(object)player == (Object)null)
{
return 0L;
}
try
{
long playerID = player.GetPlayerID();
if (playerID != 0)
{
return playerID;
}
}
catch
{
}
return 0L;
}
private static List<string> GetList(ConfigEntry<string> entry)
{
if (entry == null)
{
return new List<string>();
}
return (from x in entry.Value.Split(new char[1] { ',' })
select x.Trim() into x
where !string.IsNullOrEmpty(x)
select x).ToList();
}
private static bool Has(ConfigEntry<string> entry, string value)
{
if (entry == null || string.IsNullOrWhiteSpace(value))
{
return false;
}
return GetList(entry).Any((string x) => x.Equals(value, StringComparison.OrdinalIgnoreCase));
}
private static bool HasPlayer(ConfigEntry<string> entry, Player player)
{
if ((Object)(object)player == (Object)null)
{
return false;
}
string playerId = GetPlayerId(player);
string playerName = player.GetPlayerName();
return Has(entry, playerId) || Has(entry, playerName);
}
private static void Add(ConfigEntry<string> entry, string value)
{
if (entry != null && !string.IsNullOrWhiteSpace(value))
{
List<string> list = GetList(entry);
if (!list.Any((string x) => x.Equals(value, StringComparison.OrdinalIgnoreCase)))
{
list.Add(value);
}
entry.Value = string.Join(",", list);
}
}
private static void Remove(ConfigEntry<string> entry, string value)
{
if (entry != null && !string.IsNullOrWhiteSpace(value))
{
entry.Value = string.Join(",", from x in GetList(entry)
where !x.Equals(value, StringComparison.OrdinalIgnoreCase)
select x);
}
}
private static void ClearRace(string playerId, string playerName)
{
foreach (KeyValuePair<string, RaceConfig> race in Races)
{
Remove(race.Value.Players, playerId);
Remove(race.Value.Players, playerName);
}
}
public static bool HasDevCommands()
{
return GetBool("Terminal", "m_cheat") || GetBool("Console", "m_cheat") || GetBool("Terminal", "m_devcommands") || GetBool("Console", "m_devcommands");
}
private static bool GetBool(string typeName, string fieldName)
{
Type type = AccessTools.TypeByName(typeName);
if (type == null)
{
return false;
}
FieldInfo fieldInfo = AccessTools.Field(type, fieldName);
if (fieldInfo == null)
{
return false;
}
object value = fieldInfo.GetValue(null);
bool flag = default(bool);
int num;
if (value is bool)
{
flag = (bool)value;
num = 1;
}
else
{
num = 0;
}
return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
}
private static string GetRaceFromSecretCode(string text)
{
if (string.IsNullOrWhiteSpace(text))
{
return null;
}
foreach (KeyValuePair<string, RaceConfig> race in Races)
{
RaceConfig value = race.Value;
if (value == null || value.SecretCode == null || !value.Enabled.Value || !text.Equals(value.SecretCode.Value, StringComparison.Ordinal))
{
continue;
}
return race.Key;
}
return null;
}
private void OnDestroy()
{
SynchronizationManager.OnConfigurationSynchronized -= OnConfigurationSynchronized;
harmony.UnpatchSelf();
}
}