Skip to content

Commit

Permalink
speed up item synchronization and add trader items limit
Browse files Browse the repository at this point in the history
  • Loading branch information
GenZmeY committed Sep 19, 2023
1 parent 37921be commit 97294a4
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 168 deletions.
38 changes: 17 additions & 21 deletions CTI/Classes/CTI.uc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CTI extends Info
config(CTI);

const LatestVersion = 3;
const LatestVersion = 4;

const CfgRemoveItems = class'RemoveItems';
const CfgAddItems = class'AddItems';
Expand All @@ -22,19 +22,19 @@ var private config E_LogLevel LogLevel;
var private config String UnlockDLC;
var private config bool bPreloadContent;
var private config bool bOfficialWeaponsList;
var private config bool bDisableItemLimitCheck;

var private KFGameInfo KFGI;
var private KFGameInfo KFGI;
var private KFGameReplicationInfo KFGRI;

var private Array<class<KFWeaponDefinition> > WeapDefs;
var private Array<class<KFWeaponDefinition> > RemoveItems;
var private Array<class<KFWeaponDefinition> > AddItems;

var private Array<CTI_RepInfo> RepInfos;

var private bool ReadyToSync;

var private Array<S_PreloadContent> PreloadContent;

public simulated function bool SafeDestroy()
{
`Log_Trace();
Expand Down Expand Up @@ -95,6 +95,8 @@ private function PreInit()
bOfficialWeaponsList = false;

case 2:
case 3:
bDisableItemLimitCheck = false;

case MaxInt:
`Log_Info("Config updated to version" @ LatestVersion);
Expand Down Expand Up @@ -129,7 +131,7 @@ private function PreInit()

if (!Unlocker.static.IsValidTypeUnlockDLC(UnlockDLC, LogLevel))
{
`Log_Warn("Wrong 'UnlockDLC' (" $ UnlockDLC $ "), return to default value (False)");
`Log_Warn("Wrong 'UnlockDLC' value (" $ UnlockDLC $ "), return to default value (False)");
UnlockDLC = "False";
SaveConfig();
}
Expand Down Expand Up @@ -189,34 +191,35 @@ private function PostInit()
CfgRemoveItems.default.bAll,
CfgRemoveItems.default.bHRG,
CfgRemoveItems.default.bDLC,
bDisableItemLimitCheck,
LogLevel);

WeapDefs = Trader.static.GetTraderWeapDefs(KFGRI, LogLevel);

ReadyToSync = true;

foreach RepInfos(RepInfo)
{
if (RepInfo.PendingSync)
{
RepInfo.ServerSync();
RepInfo.Replicate(WeapDefs);
}
}
}

private function Preload(Array<class<KFWeaponDefinition> > Content)
private function Preload(const out Array<class<KFWeaponDefinition> > Content)
{
local Array<class<KFWeapon> > OfficialWeapons;
local Array<S_PreloadContent> PreloadContent;
local S_PreloadContent SPC;

`Log_Trace();

OfficialWeapons = Trader.static.GetTraderWeapons();

foreach Content(SPC.KFWD)
{
SPC.KFWC = class<KFWeapon> (DynamicLoadObject(SPC.KFWD.default.WeaponClassPath, class'Class'));
if (SPC.KFWC != None)
{
if (OfficialWeapons.Find(SPC.KFWC) != INDEX_NONE)
if (SPC.KFWC.GetPackageName() == 'CTI' || SPC.KFWC.GetPackageName() == 'KFGameContent')
{
`Log_Debug("Skip preload:" @ SPC.KFWD.GetPackageName() $ "." $ SPC.KFWD);
continue;
Expand Down Expand Up @@ -271,26 +274,19 @@ public function bool CreateRepInfo(Controller C)

`Log_Trace();

if (C == None) return false;
if (C == None || KFPlayerController(C) == None) return false;

RepInfo = Spawn(class'CTI_RepInfo', C);

if (RepInfo == None) return false;

RepInfo.PrepareSync(
Self,
LogLevel,
RemoveItems,
AddItems,
CfgRemoveItems.default.bAll,
CfgRemoveItems.default.bHRG,
CfgRemoveItems.default.bDLC);
RepInfo.PrepareSync(Self, KFPlayerController(C), LogLevel);

RepInfos.AddItem(RepInfo);

if (ReadyToSync)
{
RepInfo.ServerSync();
RepInfo.Replicate(WeapDefs);
}
else
{
Expand Down
10 changes: 9 additions & 1 deletion CTI/Classes/CTI_LocalMessage.uc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ var private localized String IncompatibleGRIWarning;
var const String SecondsShortDefault;
var private localized String SecondsShort;

var const String PleaseWaitDefault;
var private localized String PleaseWait;

enum E_CTI_LocalMessageType
{
CTI_SyncItems,
CTI_WaitingGRI,
CTI_IncompatibleGRI,
CTI_IncompatibleGRIWarning,
CTI_SecondsShort
CTI_SecondsShort,
CTI_PleaseWait
};

public static function String GetLocalizedString(
Expand Down Expand Up @@ -50,6 +54,9 @@ public static function String GetLocalizedString(
case CTI_SecondsShort:
return (default.SecondsShort != "" ? default.SecondsShort : default.SecondsShortDefault);
case CTI_PleaseWait:
return (default.PleaseWait != "" ? default.PleaseWait : default.PleaseWaitDefault);
}

return "";
Expand All @@ -62,4 +69,5 @@ defaultproperties
IncompatibleGRIDefault = "Incompatible GRI:"
IncompatibleGRIWarningDefault = "You can enter the game, but the trader may not work correctly.";
SecondsShortDefault = "s"
PleaseWaitDefault = "Please wait"
}
Loading

0 comments on commit 97294a4

Please sign in to comment.