mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-02-21 07:17:53 +01:00
tmp
This commit is contained in:
parent
f5fccb0235
commit
46581780e0
37 changed files with 2343 additions and 2444 deletions
|
|
@ -1,73 +1,42 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Penumbra.GameData.Enums;
|
||||
using Penumbra.GameData.Structs;
|
||||
using Penumbra.GameData.Util;
|
||||
using Penumbra.Interop.Structs;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Penumbra.Meta.Files
|
||||
namespace Penumbra.Meta.Files;
|
||||
|
||||
public sealed unsafe class CmpFile : MetaBaseFile
|
||||
{
|
||||
public class CmpFile
|
||||
private const int RacialScalingStart = 0x2A800;
|
||||
|
||||
public float this[ SubRace subRace, RspAttribute attribute ]
|
||||
{
|
||||
private const int RacialScalingStart = 0x2A800;
|
||||
get => *( float* )( Data + RacialScalingStart + subRace.ToRspIndex() * RspEntry.ByteSize + ( int )attribute * 4 );
|
||||
set => *( float* )( Data + RacialScalingStart + subRace.ToRspIndex() * RspEntry.ByteSize + ( int )attribute * 4 ) = value;
|
||||
}
|
||||
|
||||
private readonly byte[] _byteData = new byte[RacialScalingStart];
|
||||
private readonly RspEntry[] _rspEntries;
|
||||
public override void Reset()
|
||||
=> Functions.MemCpyUnchecked( Data, ( byte* )DefaultData.Data, DefaultData.Length );
|
||||
|
||||
public CmpFile( byte[] bytes )
|
||||
public void Reset( IEnumerable< (SubRace, RspAttribute) > entries )
|
||||
{
|
||||
foreach( var (r, a) in entries )
|
||||
{
|
||||
if( bytes.Length < RacialScalingStart )
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
Array.Copy( bytes, _byteData, RacialScalingStart );
|
||||
var rspEntryNum = ( bytes.Length - RacialScalingStart ) / RspEntry.ByteSize;
|
||||
var tmp = new List< RspEntry >( rspEntryNum );
|
||||
for( var i = 0; i < rspEntryNum; ++i )
|
||||
{
|
||||
tmp.Add( new RspEntry( bytes, RacialScalingStart + i * RspEntry.ByteSize ) );
|
||||
}
|
||||
|
||||
_rspEntries = tmp.ToArray();
|
||||
this[ r, a ] = GetDefault( r, a );
|
||||
}
|
||||
}
|
||||
|
||||
public RspEntry this[ SubRace subRace ]
|
||||
=> _rspEntries[ subRace.ToRspIndex() ];
|
||||
public CmpFile()
|
||||
: base( CharacterUtility.HumanCmpIdx )
|
||||
{
|
||||
AllocateData( DefaultData.Length );
|
||||
Reset();
|
||||
}
|
||||
|
||||
public bool Set( SubRace subRace, RspAttribute attribute, float value )
|
||||
{
|
||||
var entry = _rspEntries[ subRace.ToRspIndex() ];
|
||||
var oldValue = entry[ attribute ];
|
||||
if( oldValue == value )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
entry[ attribute ] = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
public byte[] WriteBytes()
|
||||
{
|
||||
using var s = new MemoryStream( RacialScalingStart + _rspEntries.Length * RspEntry.ByteSize );
|
||||
s.Write( _byteData, 0, _byteData.Length );
|
||||
foreach( var entry in _rspEntries )
|
||||
{
|
||||
var bytes = entry.ToBytes();
|
||||
s.Write( bytes, 0, bytes.Length );
|
||||
}
|
||||
|
||||
return s.ToArray();
|
||||
}
|
||||
|
||||
private CmpFile( byte[] data, RspEntry[] entries )
|
||||
{
|
||||
_byteData = data.ToArray();
|
||||
_rspEntries = entries.Select( e => new RspEntry( e ) ).ToArray();
|
||||
}
|
||||
|
||||
public CmpFile Clone()
|
||||
=> new( _byteData, _rspEntries );
|
||||
public static float GetDefault( SubRace subRace, RspAttribute attribute )
|
||||
{
|
||||
var data = ( byte* )Penumbra.CharacterUtility.DefaultResources[ CharacterUtility.HumanCmpIdx ].Address;
|
||||
return *( float* )( data + RacialScalingStart + subRace.ToRspIndex() * RspEntry.ByteSize + ( int )attribute * 4 );
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue