Add ped cloth texture and palette sync, closes #11

This commit is contained in:
Sardelka
2022-06-17 19:14:56 +08:00
parent 09a97c43fd
commit 13883242e4
7 changed files with 28 additions and 34 deletions

View File

@ -21,7 +21,7 @@ namespace RageCoop.Client
{
private bool _gameLoaded = false;
internal static readonly string CurrentVersion = "V0_4_1";
internal static readonly string CurrentVersion = "V0_5_0";
internal static int LocalPlayerID=0;

View File

@ -10,6 +10,9 @@
<GenerateDocumentationFile>False</GenerateDocumentationFile>
<DocumentationFile></DocumentationFile>
<DebugType>portable</DebugType>
<AssemblyVersion>0.5.0</AssemblyVersion>
<FileVersion>0.5.0</FileVersion>
<Version>0.5.0</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@ -70,8 +70,8 @@ namespace RageCoop.Client
{
get;set;
}
private Dictionary<byte, short> _lastClothes = null;
internal Dictionary<byte, short> Clothes { get; set; }
private byte[] _lastClothes = null;
public byte[] Clothes { get; set; }
internal float Heading { get; set; }
internal Vector3 RotationVelocity { get; set; }
@ -136,7 +136,7 @@ namespace RageCoop.Client
return;
}
if (!Clothes.Compare(_lastClothes))
if (!Clothes.SequenceEqual(_lastClothes))
{
SetClothes();
}
@ -290,9 +290,9 @@ namespace RageCoop.Client
private void SetClothes()
{
foreach (KeyValuePair<byte, short> cloth in Clothes)
for (byte i = 0; i < 11; i++)
{
Function.Call(Hash.SET_PED_COMPONENT_VARIATION, MainPed.Handle, cloth.Key, cloth.Value, 0, 0);
Function.Call(Hash.SET_PED_COMPONENT_VARIATION, MainPed.Handle, i, Clothes[i], Clothes[i+11], Clothes[i+22]);
}
_lastClothes = Clothes;
}

View File

@ -65,13 +65,21 @@ namespace RageCoop.Client
return 0;
}
public static Dictionary<byte, short> GetPedClothes(this Ped ped)
// Not sure whether component will always be lesser than 255, whatever...
public static byte[] GetPedClothes(this Ped ped)
{
Dictionary<byte, short> result = new Dictionary<byte, short>();
var result = new byte[33];
for (byte i = 0; i < 11; i++)
{
short mod = Function.Call<short>(Hash.GET_PED_DRAWABLE_VARIATION, ped.Handle, i);
result.Add(i, mod);
result[i]=(byte)Function.Call<short>(Hash.GET_PED_DRAWABLE_VARIATION, ped.Handle, i);
}
for (byte i = 11; i < 22; i++)
{
result[i]=(byte)Function.Call<short>(Hash.GET_PED_TEXTURE_VARIATION, ped.Handle, i);
}
for (byte i = 22; i < 33; i++)
{
result[i]=(byte)Function.Call<short>(Hash.GET_PED_PALETTE_VARIATION, ped.Handle, i);
}
return result;
}

View File

@ -18,7 +18,7 @@ namespace RageCoop.Core
public int ModelHash { get; set; }
public Dictionary<byte, short> Clothes { get; set; }
public byte[] Clothes { get; set; }
public int OwnerID { get; set; }
@ -40,15 +40,7 @@ namespace RageCoop.Core
// Write model hash
byteArray.AddInt(ModelHash);
// Write player clothes
// Write the count of clothes
byteArray.AddRange(BitConverter.GetBytes((ushort)Clothes.Count));
// Loop the dictionary and add the values
foreach (KeyValuePair<byte, short> cloth in Clothes)
{
byteArray.Add(cloth.Key);
byteArray.AddRange(BitConverter.GetBytes(cloth.Value));
}
byteArray.AddRange(Clothes);
//Write OwnerID for this ped
byteArray.AddRange(BitConverter.GetBytes(OwnerID));
@ -89,16 +81,7 @@ namespace RageCoop.Core
ModelHash = reader.ReadInt();
// Read player clothes
// Create new Dictionary
Clothes = new Dictionary<byte, short>();
// Read the count of clothes
ushort clothCount = reader.ReadUShort();
// For clothCount
for (ushort i = 0; i < clothCount; i++)
{
// Read cloth value
Clothes.Add(reader.ReadByte(), reader.ReadShort());
}
Clothes =reader.ReadByteArray(33);
// Read ped OwnerID
OwnerID= reader.ReadInt();

View File

@ -3,8 +3,8 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<AssemblyVersion>0.4</AssemblyVersion>
<FileVersion>0.4</FileVersion>
<AssemblyVersion>0.5</AssemblyVersion>
<FileVersion>0.5</FileVersion>
<RepositoryUrl>https://github.com/RAGECOOP/RAGECOOP-V</RepositoryUrl>
<PackageProjectUrl>https://ragecoop.online/</PackageProjectUrl>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
@ -12,7 +12,7 @@
<Product>$(AssemblyName)-V</Product>
<PackageId>RAGECOOP-V</PackageId>
<Authors>RAGECOOP</Authors>
<Version>0.4</Version>
<Version>0.5</Version>
<DebugType>embedded</DebugType>
</PropertyGroup>

View File

@ -26,7 +26,7 @@ namespace RageCoop.Server
internal class Server
{
private static readonly string _compatibleVersion = "V0_4";
private static readonly string _compatibleVersion = "V0_5";
public static readonly Settings MainSettings = Util.Read<Settings>("Settings.xml");
public static NetServer MainNetServer;