Skip to content

Commit

Permalink
fix DynamicEquipAdjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
yoship1639 committed Oct 25, 2020
1 parent 70e93d9 commit 1e11774
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Player2VRM/MainPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MainPlugin : BaseUnityPlugin
{
public const string PluginGuid = "com.yoship1639.plugins.player2vrm";
public const string PluginName = "Player2VRM";
public const string PluginVersion = "1.3.5.0";
public const string PluginVersion = "1.3.6.0";

void Awake()
{
Expand Down
32 changes: 19 additions & 13 deletions Player2VRM/Player2VRM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ static class EquipAdjustPos_OcPlEquipCtrl_lateMove
//{ OcEquipSlot.WpMain, "EquipMain" }, // これの位置を変えると、ピッケル・斧の所持位置と、壁などの設置場所(!!)が変わる。
};

// 装備位置変更設定をキャッシュするか(毎フレームパースするのは無駄)。この設定自体はキャッシュしない。
static bool CachingEnabled => !Settings.ReadBool("DynamicEquipAdjustment", false);

// 装備位置変更設定のキャッシュ(VRMモデルに合わせるかどうか、オフセット値)
static readonly Dictionary<OcEquipSlot, bool> equipPositionIsAdujstedToVrmModel = new Dictionary<OcEquipSlot, bool>();
static readonly Dictionary<OcEquipSlot, Vector3> equipPositionOffsets = new Dictionary<OcEquipSlot, Vector3>();
Expand Down Expand Up @@ -108,33 +105,41 @@ internal static HashSet<OcPlEquip> GetPlEquips(OcPlEquipCtrl plEquipCtrl)
}
}

static bool CachingEnabled(string playername)
{
var cache = !Settings.ReadBool(playername, "DynamicEquipAdjustment", false);
return cache;
}

static Vector3 GetOffset(OcEquipSlot equipSlot, string playername = null)
{
var cache = CachingEnabled(playername);
Vector3 offset;
if (equipPositionOffsets.TryGetValue(equipSlot, out offset) && CachingEnabled)
if (equipPositionOffsets.TryGetValue(equipSlot, out offset) && cache)
{
return offset;
}

offset = equipSlot2Key.TryGetValue(equipSlot, out var key)
? Settings.ReadVector3(playername, $"{key}Offset", Vector3.zero, false)
: Vector3.zero;
if (CachingEnabled) equipPositionOffsets.Add(equipSlot, offset);
if (cache) equipPositionOffsets.Add(equipSlot, offset);
return offset;

}
static bool IsAdujstedToVrmModel(OcEquipSlot equipSlot)
static bool IsAdujstedToVrmModel(OcEquipSlot equipSlot, string playername)
{
var cache = CachingEnabled(playername);
bool result;
if (equipPositionIsAdujstedToVrmModel.TryGetValue(equipSlot, out result) && CachingEnabled)
if (equipPositionIsAdujstedToVrmModel.TryGetValue(equipSlot, out result) && cache)
{
return result;
}

result = equipSlot2Key.TryGetValue(equipSlot, out var key)
? Settings.ReadBool($"{key}FollowsModel", false, false)
: false;
if (CachingEnabled) equipPositionIsAdujstedToVrmModel.Add(equipSlot, result);
if (cache) equipPositionIsAdujstedToVrmModel.Add(equipSlot, result);
return result;
}

Expand All @@ -154,7 +159,7 @@ static Animator GetPlRelatedModelAnimator(OcPl pl)

static void AdjustEquipPos(OcPlEquip plEquip, string playername = null)
{
if (IsAdujstedToVrmModel(plEquip.EquipSlot) && epuipBaseBones.TryGetValue(plEquip.EquipSlot, out var bone))
if (IsAdujstedToVrmModel(plEquip.EquipSlot, playername) && epuipBaseBones.TryGetValue(plEquip.EquipSlot, out var bone))
{
var modelHeadTrans = GetPlRelatedModelAnimator(plEquip.OwnerPl).GetBoneTransform(bone);
plEquip.transform.SetParent(modelHeadTrans, false);
Expand All @@ -175,7 +180,8 @@ static void AdjustEquipPos(OcPlEquip plEquip, string playername = null)

static Vector3 GetQuiverOffset(string playername = null)
{
if (quiverOffset.HasValue && CachingEnabled) return quiverOffset.Value;
var cache = CachingEnabled(playername);
if (quiverOffset.HasValue && cache) return quiverOffset.Value;
quiverOffset = Settings.ReadVector3(playername, "EquipArrowOffset", Vector3.zero, false);
return quiverOffset.Value;
}
Expand Down Expand Up @@ -521,7 +527,6 @@ class AdjustPlCam : MonoBehaviour
private bool enableAdjustDoF;

private Bloom bloom;
private ColorGrading colorGrading;
private AmbientOcclusion ambientOcclusion;
private Vignette vignette;

Expand Down Expand Up @@ -627,11 +632,12 @@ private System.Collections.IEnumerator CheckPlayerName(int max_count)
}
OcPlVRM.DelayedPostfix(ocpl);
}

}



[HarmonyPatch(typeof(OcPl))]
[HarmonyPatch("charaChangeSteup")]
[HarmonyPatch(nameof(OcPl.charaChangeSteup))]
static class OcPlVRM
{
static Dictionary<string, GameObject> dic_vrmModel = new Dictionary<string, GameObject>();
Expand Down
4 changes: 2 additions & 2 deletions Player2VRM/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.5.0")]
[assembly: AssemblyFileVersion("1.3.5.0")]
[assembly: AssemblyVersion("1.3.6.0")]
[assembly: AssemblyFileVersion("1.3.6.0")]
22 changes: 11 additions & 11 deletions Player2VRM/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static string ReadSettings(string playername, string key, bool useCache =
{
return null;
}
dic_players_settings.Add(playername, new Dictionary<string, string>());
if (useCache) dic_players_settings.Add(playername, new Dictionary<string, string>());
var lines = File.ReadAllLines(_SettingsPath);
foreach (var line in lines)
{
Expand All @@ -194,7 +194,7 @@ public static string ReadSettings(string playername, string key, bool useCache =

var args = line.Split('=');
if (args.Length != 2) continue;
dic_players_settings[playername][args[0]] = args[1];
if (useCache) dic_players_settings[playername][args[0]] = args[1];

if (args[0] == key)
{
Expand All @@ -211,31 +211,31 @@ public static string ReadSettings(string playername, string key, bool useCache =

public static int ReadInt(string playername, string key, int defaultValue = 0, bool useCache = true)
{
var str = ReadSettings(playername, key);
var str = ReadSettings(playername, key, useCache);
var res = defaultValue;
if (int.TryParse(str, out res)) return res;
return defaultValue;
}

public static float ReadFloat(string playername, string key, float defaultValue = 0.0f, bool useCache = true)
{
var str = ReadSettings(playername, key);
var str = ReadSettings(playername, key, useCache);
var res = defaultValue;
if (float.TryParse(str, out res)) return res;
return defaultValue;
}

public static bool ReadBool(string playername, string key, bool defaultValue = false, bool useCache = true)
{
var str = ReadSettings(playername, key);
var str = ReadSettings(playername, key, useCache);
var res = defaultValue;
if (bool.TryParse(str, out res)) return res;
return defaultValue;
}

public static Vector3 ReadVector3(string playername, string key, Vector3 defaultValue = default, bool useCache = true)
{
var str = ReadSettings(playername, key);
var str = ReadSettings(playername, key, useCache);
if (str == null) return defaultValue;
var match = new Regex("\\((?<x>[^,]*?),(?<y>[^,]*?),(?<z>[^,]*?)\\)").Match(str);
if (match.Success == false) return defaultValue;
Expand Down Expand Up @@ -274,7 +274,7 @@ public static string ReadSettings(string key, bool useCache = true)

var args = line.Split('=');
if (args.Length != 2) continue;
dic_common_settings[args[0]] = args[1];
if (useCache) dic_common_settings[args[0]] = args[1];
if (args[0] == key)
{
retval = args[1];
Expand All @@ -291,31 +291,31 @@ public static string ReadSettings(string key, bool useCache = true)

public static int ReadInt(string key, int defaultValue = 0, bool useCache = true)
{
var str = ReadSettings(key);
var str = ReadSettings(key, useCache);
var res = defaultValue;
if (int.TryParse(str, out res)) return res;
return defaultValue;
}

public static float ReadFloat(string key, float defaultValue = 0.0f, bool useCache = true)
{
var str = ReadSettings(key);
var str = ReadSettings(key, useCache);
var res = defaultValue;
if (float.TryParse(str, out res)) return res;
return defaultValue;
}

public static bool ReadBool(string key, bool defaultValue = false, bool useCache = true)
{
var str = ReadSettings(key);
var str = ReadSettings(key, useCache);
var res = defaultValue;
if (bool.TryParse(str, out res)) return res;
return defaultValue;
}

public static Vector3 ReadVector3(string key, Vector3 defaultValue = default, bool useCache = true)
{
var str = ReadSettings(key);
var str = ReadSettings(key, useCache);
if (str == null) return defaultValue;
var match = new Regex("\\((?<x>[^,]*?),(?<y>[^,]*?),(?<z>[^,]*?)\\)").Match(str);
if (match.Success == false) return defaultValue;
Expand Down

0 comments on commit 1e11774

Please sign in to comment.