2017-10-20 02:00:49 +00:00
|
|
|
// Byte serialization, written by Marco.
|
|
|
|
Class ExtPlayerStat extends Object implements(ExtSaveDataBase);
|
|
|
|
|
|
|
|
var int ArVersion,SaveNum;
|
|
|
|
var transient int BufferOffset,BufferSize;
|
|
|
|
var transient array<int> EOFStack;
|
|
|
|
var array<byte> Buffer;
|
|
|
|
var array<string> StrMap;
|
|
|
|
const CurrentSaveVer=1;
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
final function bool LoadStatFile(PlayerController Other)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local string S;
|
|
|
|
|
|
|
|
FlushData();
|
|
|
|
S = class'ServerExtMut'.Static.GetStatFile(Other.PlayerReplicationInfo.UniqueId);
|
2020-11-28 20:12:58 +00:00
|
|
|
if (Class'Engine'.Static.BasicLoadObject(Self,S,false,CurrentSaveVer))
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
BufferSize = Buffer.Length;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
BufferSize = 0;
|
|
|
|
Buffer.Length = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
final function SaveStatFile(PlayerController Other)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local string S;
|
|
|
|
|
|
|
|
S = class'ServerExtMut'.Static.GetStatFile(Other.PlayerReplicationInfo.UniqueId);
|
|
|
|
Class'Engine'.Static.BasicSaveObject(Self,S,false,CurrentSaveVer);
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function SaveInt(int Value, optional byte MaxVal)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
++MaxVal;
|
2020-11-28 20:12:58 +00:00
|
|
|
if ((BufferOffset+MaxVal)>Buffer.Length)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
Buffer.Length = (BufferOffset+MaxVal);
|
|
|
|
BufferSize = Buffer.Length;
|
|
|
|
}
|
|
|
|
Buffer[BufferOffset++] = Value & 255;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MaxVal>1)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
Buffer[BufferOffset++] = (Value >> 8) & 255;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MaxVal>2)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
Buffer[BufferOffset++] = (Value >> 16) & 255;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MaxVal>3)
|
2017-10-20 02:00:49 +00:00
|
|
|
Buffer[BufferOffset++] = (Value >> 24) & 255;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function int ReadInt(optional byte MaxVal)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local int Res;
|
|
|
|
|
|
|
|
++MaxVal;
|
2020-11-28 20:12:58 +00:00
|
|
|
if ((BufferOffset+MaxVal)>BufferSize)
|
2017-10-20 02:00:49 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
Res = Buffer[BufferOffset++];
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MaxVal>1)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
Res = Res | (Buffer[BufferOffset++] << 8);
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MaxVal>2)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
Res = Res | (Buffer[BufferOffset++] << 16);
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MaxVal>3)
|
2017-10-20 02:00:49 +00:00
|
|
|
Res = Res | (Buffer[BufferOffset++] << 24);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Res;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function SaveStr(string S)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local int i;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (S=="")
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
SaveInt(0,1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
S = Left(S,255);
|
|
|
|
i = StrMap.Find(S);
|
2020-11-28 20:12:58 +00:00
|
|
|
if (i==-1)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
i = StrMap.Length;
|
|
|
|
StrMap[StrMap.Length] = S;
|
|
|
|
}
|
|
|
|
SaveInt((i+1),1);
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
function string ReadStr()
|
|
|
|
{
|
|
|
|
local int i;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
i = ReadInt(1);
|
2020-11-28 20:12:58 +00:00
|
|
|
if (i==0 || i>StrMap.Length)
|
2017-10-20 02:00:49 +00:00
|
|
|
return "";
|
|
|
|
return StrMap[i-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
function int TellOffset()
|
|
|
|
{
|
|
|
|
return BufferOffset;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function SeekOffset(int Offset)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
BufferOffset = Clamp(Offset,0,BufferSize);
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
function int TotalSize()
|
|
|
|
{
|
|
|
|
return BufferSize;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
function ToEnd()
|
|
|
|
{
|
|
|
|
BufferOffset = BufferSize;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
function ToStart()
|
|
|
|
{
|
|
|
|
BufferOffset = 0;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
function bool AtEnd()
|
|
|
|
{
|
|
|
|
return (BufferOffset>=BufferSize);
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function SkipBytes(int Count)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
BufferOffset = Clamp(BufferOffset+Count,0,BufferSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
function FlushData()
|
|
|
|
{
|
|
|
|
ArVersion = 0;
|
|
|
|
SaveNum = 0;
|
|
|
|
BufferOffset = 0;
|
|
|
|
BufferSize = 0;
|
|
|
|
Buffer.Length = 0;
|
|
|
|
EOFStack.Length = 0;
|
|
|
|
StrMap.Length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
final function DebugData()
|
|
|
|
{
|
|
|
|
local string S,SS;
|
|
|
|
local array<byte> B;
|
|
|
|
local int i;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
GetData(B);
|
|
|
|
`Log("DEBUG DATA: Data size: "$B.Length);
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=0; i<B.Length; ++i)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
S $= Chr(Max(B[i],1));
|
|
|
|
SS $= "."$B[i];
|
|
|
|
}
|
|
|
|
`Log("DEBUG DATA: "$S);
|
|
|
|
`Log("DEBUG DATA: "$SS);
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function GetData(out array<byte> Res)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local int i,l,o,j;
|
|
|
|
|
|
|
|
Res = Buffer;
|
|
|
|
Res.Insert(0,1);
|
|
|
|
Res[0] = ArVersion;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
// Add string map to start.
|
|
|
|
// Write string map length.
|
|
|
|
Res.Insert(1,2);
|
|
|
|
l = StrMap.Length;
|
|
|
|
Res[1] = l & 255;
|
|
|
|
Res[2] = (l >> 8) & 255;
|
|
|
|
o = 3;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
// write each entry.
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=0; i<StrMap.Length; ++i)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
l = Len(StrMap[i]);
|
|
|
|
Res.Insert(o,l+1);
|
|
|
|
Res[o++] = l;
|
2020-11-28 20:12:58 +00:00
|
|
|
for (j=0; j<l; ++j)
|
2017-10-20 02:00:49 +00:00
|
|
|
Res[o++] = Asc(Mid(StrMap[i],j,1));
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function SetData(out array<byte> S)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local int i,o,l,j;
|
|
|
|
|
|
|
|
ArVersion = S[0];
|
|
|
|
Buffer = S;
|
|
|
|
|
|
|
|
// read string map length.
|
|
|
|
StrMap.Length = Buffer[1] | (Buffer[2] << 8);
|
|
|
|
o = 3;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
// read each string map entry.
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=0; i<StrMap.Length; ++i)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
l = Buffer[o++];
|
|
|
|
StrMap[i] = "";
|
2020-11-28 20:12:58 +00:00
|
|
|
for (j=0; j<l; ++j)
|
2017-10-20 02:00:49 +00:00
|
|
|
StrMap[i] $= Chr(Buffer[o++]);
|
|
|
|
}
|
|
|
|
Buffer.Remove(0,o);
|
|
|
|
|
|
|
|
BufferSize = Buffer.Length;
|
|
|
|
}
|
|
|
|
|
|
|
|
function int GetArVer()
|
|
|
|
{
|
|
|
|
return ArVersion;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function SetArVer(int Ver)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
ArVersion = Ver;
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function PushEOFLimit(int EndOffset)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
EOFStack.AddItem(BufferSize);
|
|
|
|
BufferSize = EndOffset;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
function PopEOFLimit()
|
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (EOFStack.Length==0)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
`Log(Self@"WARNING: Tried to pop one EoF stack down too far!!!");
|
|
|
|
return; // Whoops, error.
|
|
|
|
}
|
|
|
|
BufferSize = EOFStack[EOFStack.Length-1];
|
|
|
|
EOFStack.Length = EOFStack.Length-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function int GetSaveVersion()
|
|
|
|
{
|
|
|
|
return SaveNum;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function SetSaveVersion(int Num)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
SaveNum = Num;
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultproperties
|
|
|
|
{
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
}
|