Upload from upload_mods.ps1

This commit is contained in:
Nathaniel Cosford
2025-06-04 16:13:32 +09:30
commit 7345f42201
470 changed files with 51966 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
using KFCommonUtilityLib.Scripts.StaticManagers;
namespace KFCommonUtilityLib.Scripts.NetPackages
{
public class NetPackageEntityActionIndex : NetPackage
{
private int entityID;
private int mode;
public NetPackageEntityActionIndex Setup(int entityID, int mode)
{
this.entityID = entityID;
this.mode = mode;
return this;
}
public override int GetLength()
{
return 5;
}
public override void ProcessPackage(World _world, GameManager _callbacks)
{
if (MultiActionManager.SetModeForEntity(entityID, mode) && ConnectionManager.Instance.IsServer)
{
ConnectionManager.Instance.SendPackage(NetPackageManager.GetPackage<NetPackageEntityActionIndex>().Setup(entityID, mode), false, -1, entityID);
}
}
public override void write(PooledBinaryWriter _writer)
{
base.write(_writer);
_writer.Write(entityID);
_writer.Write((byte)mode);
}
public override void read(PooledBinaryReader _reader)
{
entityID = _reader.ReadInt32();
mode = _reader.ReadByte();
}
}
}

View File

@@ -0,0 +1,81 @@
namespace KFCommonUtilityLib.Scripts.NetPackages
{
public class NetPackageEntitySpawnWithCVar : NetPackageEntitySpawn
{
byte[] cvarData;
public NetPackageEntitySpawnWithCVar Setup(EntityCreationData _es, EntityAlive _ea)
{
Setup(_es);
using (var bw = MemoryPools.poolBinaryWriter.AllocSync(true))
{
using (var ms = MemoryPools.poolMemoryStream.AllocSync(true))
{
bw.SetBaseStream(ms);
if (_ea && _ea.Buffs != null)
{
var buff = _ea.Buffs;
bw.Write(buff.CVars.Count);
foreach (var cvar in buff.CVars)
{
bw.Write(cvar.Key);
bw.Write(cvar.Value);
}
}
else
{
bw.Write(0);
}
cvarData = ms.ToArray();
}
}
return this;
}
public override int GetLength()
{
return base.GetLength() + 200;
}
public override void ProcessPackage(World _world, GameManager _callbacks)
{
base.ProcessPackage(_world, _callbacks);
if (_world == null || _callbacks == null || es.id == -1)
{
return;
}
EntityAlive ea = _world.GetEntity(es.id) as EntityAlive;
if (!ea)
{
return;
}
using (var ms = MemoryPools.poolMemoryStream.AllocSync(true))
{
ms.Write(cvarData, 0, cvarData.Length);
ms.Position = 0;
using (var br = MemoryPools.poolBinaryReader.AllocSync(true))
{
br.SetBaseStream(ms);
var count = br.ReadInt32();
for (int i = 0; i < count; i++)
{
ea.Buffs.SetCustomVar(br.ReadString(), br.ReadSingle(), false);
}
}
}
ea.FireEvent(CustomEnums.onSelfFirstCVarSync);
}
public override void read(PooledBinaryReader _reader)
{
base.read(_reader);
cvarData = _reader.ReadBytes(_reader.ReadInt32());
}
public override void write(PooledBinaryWriter _writer)
{
base.write(_writer);
_writer.Write(cvarData.Length);
_writer.Write(cvarData);
}
}
}

View File

@@ -0,0 +1,49 @@
using KFCommonUtilityLib.Scripts.Utilities;
class NetPackageFixedReload : NetPackage
{
private int entityId;
private byte actionIndex;
public NetPackageFixedReload Setup(int entityId, int actionIndex)
{
this.entityId = entityId;
this.actionIndex = (byte)actionIndex;
return this;
}
public override int GetLength()
{
return 5;
}
public override void ProcessPackage(World _world, GameManager _callbacks)
{
if (_world == null)
{
return;
}
if (!_world.IsRemote())
{
MultiActionUtils.FixedItemReloadServer(entityId, actionIndex);
}
else
{
MultiActionUtils.FixedItemReloadClient(entityId, actionIndex);
}
}
public override void read(PooledBinaryReader _reader)
{
entityId = _reader.ReadInt32();
actionIndex = _reader.ReadByte();
}
public override void write(PooledBinaryWriter _writer)
{
base.write(_writer);
_writer.Write(entityId);
_writer.Write(actionIndex);
}
}

View File

@@ -0,0 +1,69 @@
using UnityEngine;
namespace KFCommonUtilityLib.Scripts.NetPackages
{
public class NetPackageRemoteAttachPrefab : NetPackage
{
private int entityID;
private string prefab;
private string path;
private Vector3 localPosition;
private Vector3 localRotation;
private Vector3 localScale;
public NetPackageRemoteAttachPrefab Setup(int entityID, string prefab, string path, Vector3 localPosition, Vector3 localRotation, Vector3 localScale)
{
this.entityID = entityID;
this.prefab = prefab;
this.path = path;
this.localPosition = localPosition;
this.localRotation = localRotation;
this.localScale = localScale;
return this;
}
public override int GetLength()
{
return 200;
}
public override void ProcessPackage(World _world, GameManager _callbacks)
{
if (_world == null || _callbacks == null)
{
return;
}
var entity = _world.GetEntity(entityID) as EntityAlive;
if (!entity || !entity.isEntityRemote)
{
return;
}
if (ConnectionManager.Instance.IsServer)
{
ConnectionManager.Instance.SendPackage(NetPackageManager.GetPackage<NetPackageRemoteAttachPrefab>().Setup(entityID, prefab, path, localPosition, localRotation, localScale), false, -1, -1, entityID);
}
MinEventActionAttachPrefabToEntitySync.RemoteAttachPrefab(entity, prefab, path, localPosition, localRotation, localScale);
}
public override void read(PooledBinaryReader _reader)
{
entityID = _reader.ReadInt32();
prefab = _reader.ReadString();
path = _reader.ReadString();
localPosition = StreamUtils.ReadVector3(_reader);
localRotation = StreamUtils.ReadVector3(_reader);
localScale = StreamUtils.ReadVector3(_reader);
}
public override void write(PooledBinaryWriter _writer)
{
base.write(_writer);
_writer.Write(entityID);
_writer.Write(prefab);
_writer.Write(path);
StreamUtils.Write(_writer, localPosition);
StreamUtils.Write(_writer, localRotation);
StreamUtils.Write(_writer, localScale);
}
}
}

View File

@@ -0,0 +1,117 @@
using UnityEngine;
class NetPackageSyncWeaponLabelColor : NetPackage
{
public NetPackageSyncWeaponLabelColor Setup(int entityId, bool isText, Color color, int index0, int index1, int nameId)
{
this.entityId = entityId;
this.isText = isText;
this.color = color;
this.index0 = index0;
if (!isText)
{
this.index1 = index1;
this.nameId = nameId;
}
return this;
}
public override int GetLength()
{
return isText ? 20 : 28;
}
public override void ProcessPackage(World _world, GameManager _callbacks)
{
if (_world == null)
return;
NetSyncSetWeaponLabelColor(_world.GetEntity(entityId) as EntityAlive, isText, index0, color, index1, nameId, true);
}
public static void NetSyncSetWeaponLabelColor(EntityAlive holdingEntity, bool isText, int slot0, Color color, int slot1, int nameId, bool fromNet = false)
{
if (!holdingEntity || (holdingEntity.isEntityRemote && !fromNet))
{
if (holdingEntity)
Log.Out("netsync failed! isEntityRemote: " + holdingEntity.isEntityRemote + " fromNet: " + fromNet);
else
Log.Out("Entity not found!");
return;
}
if (SetWeaponLabelColor(holdingEntity, isText, slot0, color, slot1, nameId))
{
//Log.Out("trying to set weapon label on " + (SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer ? "server" : "client") + " color: " + color.ToString() + " entity: " + holdingEntity.entityId + " from net: " + fromNet);
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer && SingletonMonoBehaviour<ConnectionManager>.Instance.ClientCount() > 0)
{
int allButAttachedToEntityId = holdingEntity.entityId;
if (holdingEntity && holdingEntity.AttachedMainEntity)
allButAttachedToEntityId = holdingEntity.AttachedMainEntity.entityId;
SingletonMonoBehaviour<ConnectionManager>.Instance.SendPackage(NetPackageManager.GetPackage<NetPackageSyncWeaponLabelColor>().Setup(holdingEntity.entityId, isText, color, slot0, slot1, nameId), false, -1, allButAttachedToEntityId, allButAttachedToEntityId, null, 15);
}
else if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsClient && !fromNet)
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(NetPackageManager.GetPackage<NetPackageSyncWeaponLabelColor>().Setup(holdingEntity.entityId, isText, color, slot0, slot1, nameId));
}
}
public static bool SetWeaponLabelColor(EntityAlive holdingEntity, bool isText, int slot0, Color color, int slot1, int nameId)
{
if (GameManager.IsDedicatedServer)
return true;
if (isText)
{
WeaponLabelControllerBase controller = holdingEntity.inventory.GetHoldingItemTransform()?.GetComponent<WeaponLabelControllerBase>();
//if (holdingEntity.emodel.avatarController is AvatarMultiBodyController multiBody && multiBody.HeldItemTransform != null)
// controller = multiBody.HeldItemTransform.GetComponent<WeaponLabelControllerBase>();
//else if (holdingEntity.emodel.avatarController is LegacyAvatarController legacy && legacy.HeldItemTransform != null)
// controller = legacy.HeldItemTransform.GetComponent<WeaponLabelControllerBase>();
return controller && controller.setLabelColor(slot0, color);
}
else
{
WeaponColorControllerBase controller = holdingEntity.inventory.GetHoldingItemTransform()?.GetComponent<WeaponColorControllerBase>();
//if (holdingEntity.emodel.avatarController is AvatarMultiBodyController multiBody && multiBody.HeldItemTransform != null)
// controller = multiBody.HeldItemTransform.GetComponent<WeaponColorControllerBase>();
//else if (holdingEntity.emodel.avatarController is LegacyAvatarController legacy && legacy.HeldItemTransform != null)
// controller = legacy.HeldItemTransform.GetComponent<WeaponColorControllerBase>();
return controller && controller.setMaterialColor(slot0, slot1, nameId, color);
}
}
public override void read(PooledBinaryReader _reader)
{
entityId = _reader.ReadInt32();
isText = _reader.ReadBoolean();
color = StreamUtils.ReadColor(_reader);
index0 = _reader.ReadChar();
if (!isText)
{
index1 = _reader.ReadChar();
nameId = _reader.ReadInt32();
}
}
public override void write(PooledBinaryWriter _writer)
{
base.write(_writer);
_writer.Write(entityId);
_writer.Write(isText);
StreamUtils.Write(_writer, color);
_writer.Write((char)index0);
if (!isText)
{
_writer.Write((char)index1);
_writer.Write(nameId);
}
}
private int entityId;
private bool isText;
private Color color;
private int index0;
private int index1;
private int nameId;
}

View File

@@ -0,0 +1,82 @@
class NetPackageSyncWeaponLabelText : NetPackage
{
public NetPackageSyncWeaponLabelText Setup(int entityId, int slot, string data)
{
this.entityId = entityId;
this.slot = slot;
this.data = data;
return this;
}
public override int GetLength()
{
return 6 + data.Length;
}
public override void ProcessPackage(World _world, GameManager _callbacks)
{
if (_world == null)
return;
NetSyncSetWeaponLabelText(_world.GetEntity(entityId) as EntityAlive, slot, data, true);
}
public override void read(PooledBinaryReader _reader)
{
entityId = _reader.ReadInt32();
slot = (int)_reader.ReadChar();
data = _reader.ReadString();
}
public override void write(PooledBinaryWriter _writer)
{
base.write(_writer);
_writer.Write(entityId);
_writer.Write((char)slot);
_writer.Write(data);
}
public static void NetSyncSetWeaponLabelText(EntityAlive holdingEntity, int slot, string data, bool fromNet = false)
{
if (!holdingEntity || (holdingEntity.isEntityRemote && !fromNet))
{
if (holdingEntity)
Log.Out("netsync failed! isEntityRemote: " + holdingEntity.isEntityRemote + " fromNet: " + fromNet);
else
Log.Out("Entity not found!");
return;
}
if (SetWeaponLabelText(holdingEntity, slot, data))
{
//Log.Out("trying to set weapon label on " + (SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer ? "server" : "client") + " slot: " + slot + " text: " + data + " entity: " + holdingEntity.entityId + " from net: " + fromNet);
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer && SingletonMonoBehaviour<ConnectionManager>.Instance.ClientCount() > 0)
{
int allButAttachedToEntityId = holdingEntity.entityId;
if (holdingEntity.AttachedMainEntity)
allButAttachedToEntityId = holdingEntity.AttachedMainEntity.entityId;
SingletonMonoBehaviour<ConnectionManager>.Instance.SendPackage(NetPackageManager.GetPackage<NetPackageSyncWeaponLabelText>().Setup(holdingEntity.entityId, slot, data), false, -1, allButAttachedToEntityId, allButAttachedToEntityId, null, 15);
}
else if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsClient && !fromNet)
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(NetPackageManager.GetPackage<NetPackageSyncWeaponLabelText>().Setup(holdingEntity.entityId, slot, data));
}
}
public static bool SetWeaponLabelText(EntityAlive holdingEntity, int slot, string data)
{
if (GameManager.IsDedicatedServer)
return true;
WeaponLabelControllerBase controller = holdingEntity.inventory.GetHoldingItemTransform()?.GetComponent<WeaponLabelControllerBase>();
//if (holdingEntity.emodel.avatarController is AvatarMultiBodyController multiBody && multiBody.HeldItemTransform != null)
// controller = multiBody.HeldItemTransform.GetComponent<WeaponLabelControllerBase>();
//else if (holdingEntity.emodel.avatarController is LegacyAvatarController legacy && legacy.HeldItemTransform)
// controller = legacy.HeldItemTransform.GetComponent<WeaponLabelControllerBase>();
return controller && controller.setLabelText(slot, data);
}
private int entityId;
private int slot;
private string data;
}