2022-07-05 13:09:48 +00:00
|
|
|
class CTI extends Info
|
|
|
|
config(CTI);
|
|
|
|
|
2022-07-18 17:27:51 +00:00
|
|
|
const LatestVersion = 2;
|
2022-07-05 13:09:48 +00:00
|
|
|
|
2022-07-18 17:27:51 +00:00
|
|
|
const CfgRemoveItems = class'RemoveItems';
|
|
|
|
const CfgAddItems = class'AddItems';
|
|
|
|
const CfgOfficialWeapons = class'OfficialWeapons';
|
|
|
|
const Trader = class'Trader';
|
|
|
|
const Unlocker = class'Unlocker';
|
2022-07-05 13:09:48 +00:00
|
|
|
|
2022-07-10 02:49:38 +00:00
|
|
|
struct S_PreloadContent
|
|
|
|
{
|
|
|
|
var class<KFWeaponDefinition> KFWD;
|
|
|
|
var class<KFWeapon> KFWC;
|
|
|
|
var KFWeapon KFW;
|
|
|
|
var KFW_Access KFWA;
|
|
|
|
};
|
|
|
|
|
2022-07-05 13:09:48 +00:00
|
|
|
var private config int Version;
|
|
|
|
var private config E_LogLevel LogLevel;
|
2022-07-18 17:27:51 +00:00
|
|
|
var private config String UnlockDLC;
|
2022-07-08 18:18:58 +00:00
|
|
|
var private config bool bPreloadContent;
|
2022-07-18 17:27:51 +00:00
|
|
|
var private config bool bOfficialWeaponsList;
|
2022-07-05 13:09:48 +00:00
|
|
|
|
|
|
|
var private KFGameInfo KFGI;
|
|
|
|
var private KFGameReplicationInfo KFGRI;
|
|
|
|
|
|
|
|
var private Array<class<KFWeaponDefinition> > RemoveItems;
|
|
|
|
var private Array<class<KFWeaponDefinition> > AddItems;
|
|
|
|
|
|
|
|
var private Array<CTI_RepInfo> RepInfos;
|
|
|
|
|
|
|
|
var private bool ReadyToSync;
|
|
|
|
|
2022-07-10 02:49:38 +00:00
|
|
|
var private Array<S_PreloadContent> PreloadContent;
|
|
|
|
|
2022-07-05 13:09:48 +00:00
|
|
|
public simulated function bool SafeDestroy()
|
|
|
|
{
|
2022-07-18 17:27:51 +00:00
|
|
|
`Log_Trace();
|
2022-07-05 13:09:48 +00:00
|
|
|
|
|
|
|
return (bPendingDelete || bDeleteMe || Destroy());
|
|
|
|
}
|
|
|
|
|
|
|
|
public event PreBeginPlay()
|
|
|
|
{
|
2022-07-18 17:27:51 +00:00
|
|
|
`Log_Trace();
|
2022-07-05 13:09:48 +00:00
|
|
|
|
|
|
|
`Log_Debug("PreBeginPlay readyToSync" @ ReadyToSync);
|
|
|
|
|
|
|
|
if (WorldInfo.NetMode == NM_Client)
|
|
|
|
{
|
|
|
|
`Log_Fatal("NetMode == NM_Client, Destroy...");
|
|
|
|
SafeDestroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Super.PreBeginPlay();
|
|
|
|
|
|
|
|
PreInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public event PostBeginPlay()
|
|
|
|
{
|
2022-07-18 17:27:51 +00:00
|
|
|
`Log_Trace();
|
2022-07-05 13:09:48 +00:00
|
|
|
|
|
|
|
if (bPendingDelete || bDeleteMe) return;
|
|
|
|
|
|
|
|
Super.PostBeginPlay();
|
|
|
|
|
|
|
|
PostInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function PreInit()
|
|
|
|
{
|
2022-07-18 17:27:51 +00:00
|
|
|
`Log_Trace();
|
2022-07-05 13:09:48 +00:00
|
|
|
|
|
|
|
if (Version == `NO_CONFIG)
|
|
|
|
{
|
|
|
|
LogLevel = LL_Info;
|
|
|
|
bPreloadContent = true;
|
2022-07-18 17:27:51 +00:00
|
|
|
UnlockDLC = "False";
|
2022-07-05 13:09:48 +00:00
|
|
|
SaveConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
CfgRemoveItems.static.InitConfig(Version, LatestVersion);
|
|
|
|
CfgAddItems.static.InitConfig(Version, LatestVersion);
|
|
|
|
|
|
|
|
switch (Version)
|
|
|
|
{
|
|
|
|
case `NO_CONFIG:
|
|
|
|
`Log_Info("Config created");
|
2022-07-11 12:56:21 +00:00
|
|
|
|
2022-07-18 17:27:51 +00:00
|
|
|
case 1:
|
|
|
|
bOfficialWeaponsList = false;
|
|
|
|
|
2022-07-05 13:09:48 +00:00
|
|
|
case MaxInt:
|
2022-07-18 17:27:51 +00:00
|
|
|
`Log_Info("Config updated to version" @ LatestVersion);
|
2022-07-05 13:09:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LatestVersion:
|
|
|
|
`Log_Info("Config is up-to-date");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
`Log_Warn("The config version is higher than the current version (are you using an old mutator?)");
|
|
|
|
`Log_Warn("Config version is" @ Version @ "but current version is" @ LatestVersion);
|
|
|
|
`Log_Warn("The config version will be changed to" @ LatestVersion);
|
|
|
|
break;
|
|
|
|
}
|
2022-07-18 17:27:51 +00:00
|
|
|
|
|
|
|
CfgOfficialWeapons.static.Update(bOfficialWeaponsList);
|
2022-07-05 13:09:48 +00:00
|
|
|
|
|
|
|
if (LatestVersion != Version)
|
|
|
|
{
|
|
|
|
Version = LatestVersion;
|
|
|
|
SaveConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LogLevel == LL_WrongLevel)
|
|
|
|
{
|
|
|
|
LogLevel = LL_Info;
|
|
|
|
`Log_Warn("Wrong 'LogLevel', return to default value");
|
|
|
|
SaveConfig();
|
|
|
|
}
|
|
|
|
`Log_Base("LogLevel:" @ LogLevel);
|
|
|
|
|
2022-07-18 17:27:51 +00:00
|
|
|
if (!Unlocker.static.IsValidTypeUnlockDLC(UnlockDLC, LogLevel))
|
|
|
|
{
|
|
|
|
`Log_Warn("Wrong 'UnlockDLC' (" $ UnlockDLC $ "), return to default value (False)");
|
|
|
|
UnlockDLC = "False";
|
|
|
|
SaveConfig();
|
|
|
|
}
|
|
|
|
|
2022-07-05 13:09:48 +00:00
|
|
|
RemoveItems = CfgRemoveItems.static.Load(LogLevel);
|
|
|
|
AddItems = CfgAddItems.static.Load(LogLevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function PostInit()
|
|
|
|
{
|
2022-07-14 06:55:58 +00:00
|
|
|
local CTI_RepInfo RepInfo;
|
2022-07-05 13:09:48 +00:00
|
|
|
|
2022-07-18 17:27:51 +00:00
|
|
|
`Log_Trace();
|
2022-07-05 13:09:48 +00:00
|
|
|
|
|
|
|
if (WorldInfo == None || WorldInfo.Game == None)
|
|
|
|
{
|
|
|
|
SetTimer(1.0f, false, nameof(PostInit));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KFGI = KFGameInfo(WorldInfo.Game);
|
|
|
|
if (KFGI == None)
|
|
|
|
{
|
|
|
|
`Log_Fatal("Incompatible gamemode:" @ WorldInfo.Game);
|
|
|
|
SafeDestroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KFGI.GameReplicationInfo == None)
|
|
|
|
{
|
|
|
|
SetTimer(1.0f, false, nameof(PostInit));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KFGRI = KFGameReplicationInfo(KFGI.GameReplicationInfo);
|
|
|
|
if (KFGRI == None)
|
|
|
|
{
|
|
|
|
`Log_Fatal("Incompatible Replication info:" @ KFGI.GameReplicationInfo);
|
|
|
|
SafeDestroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-18 17:27:51 +00:00
|
|
|
if (Unlocker.static.UnlockDLC(KFGI, KFGRI, UnlockDLC, RemoveItems, AddItems, LogLevel))
|
|
|
|
{
|
|
|
|
`Log_Info("DLC unlocked");
|
|
|
|
}
|
2022-07-05 13:09:48 +00:00
|
|
|
|
|
|
|
if (bPreloadContent)
|
|
|
|
{
|
2022-07-11 00:54:08 +00:00
|
|
|
Preload(AddItems);
|
2022-07-05 13:09:48 +00:00
|
|
|
}
|
|
|
|
|
2022-07-18 17:27:51 +00:00
|
|
|
Trader.static.ModifyTrader(KFGRI, RemoveItems, AddItems, CfgRemoveItems.default.bAll, LogLevel);
|
|
|
|
|
2022-07-05 13:09:48 +00:00
|
|
|
ReadyToSync = true;
|
|
|
|
|
2022-07-14 06:55:58 +00:00
|
|
|
foreach RepInfos(RepInfo)
|
2022-07-05 13:09:48 +00:00
|
|
|
{
|
2022-07-14 06:55:58 +00:00
|
|
|
if (RepInfo.PendingSync)
|
2022-07-05 13:09:48 +00:00
|
|
|
{
|
2022-07-14 06:55:58 +00:00
|
|
|
RepInfo.ServerSync();
|
2022-07-05 13:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 00:54:08 +00:00
|
|
|
private function Preload(Array<class<KFWeaponDefinition> > Content)
|
2022-07-10 02:49:38 +00:00
|
|
|
{
|
2022-07-18 17:27:51 +00:00
|
|
|
local Array<class<KFWeapon> > OfficialWeapons;
|
2022-07-10 02:49:38 +00:00
|
|
|
local S_PreloadContent SPC;
|
|
|
|
|
2022-07-18 17:27:51 +00:00
|
|
|
`Log_Trace();
|
|
|
|
|
|
|
|
OfficialWeapons = Trader.static.GetTraderWeapons();
|
|
|
|
|
2022-07-10 02:49:38 +00:00
|
|
|
foreach Content(SPC.KFWD)
|
|
|
|
{
|
|
|
|
SPC.KFWC = class<KFWeapon> (DynamicLoadObject(SPC.KFWD.default.WeaponClassPath, class'Class'));
|
|
|
|
if (SPC.KFWC != None)
|
|
|
|
{
|
2022-07-18 17:27:51 +00:00
|
|
|
if (OfficialWeapons.Find(SPC.KFWC) != INDEX_NONE)
|
|
|
|
{
|
|
|
|
`Log_Debug("Skip preload:" @ SPC.KFWD.GetPackageName() $ "." $ SPC.KFWD);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-07-10 02:49:38 +00:00
|
|
|
SPC.KFW = KFGI.Spawn(SPC.KFWC);
|
|
|
|
if (SPC.KFW == None)
|
|
|
|
{
|
|
|
|
`Log_Warn("Spawn failed:" @ SPC.KFWD.default.WeaponClassPath);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SPC.KFWA = new (SPC.KFW) class'KFW_Access';
|
|
|
|
if (SPC.KFWA == None)
|
|
|
|
{
|
|
|
|
`Log_Warn("Spawn failed:" @ SPC.KFWD.default.WeaponClassPath @ "KFW_Access");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
PreloadContent.AddItem(SPC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach PreloadContent(SPC)
|
|
|
|
{
|
2022-07-11 00:54:08 +00:00
|
|
|
SPC.KFWA.KFW_StartLoadWeaponContent();
|
2022-07-10 02:49:38 +00:00
|
|
|
}
|
2022-07-18 17:27:51 +00:00
|
|
|
|
|
|
|
`Log_Info("Preloaded" @ PreloadContent.Length @ "weapon models");
|
2022-07-10 02:49:38 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 13:09:48 +00:00
|
|
|
public function NotifyLogin(Controller C)
|
|
|
|
{
|
2022-07-18 17:27:51 +00:00
|
|
|
`Log_Trace();
|
2022-07-05 13:09:48 +00:00
|
|
|
|
2022-08-24 16:26:18 +00:00
|
|
|
if (!CreateRepInfo(C))
|
|
|
|
{
|
|
|
|
`Log_Error("Can't create RepInfo for:" @ C);
|
|
|
|
}
|
2022-07-05 13:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function NotifyLogout(Controller C)
|
|
|
|
{
|
2022-07-18 17:27:51 +00:00
|
|
|
`Log_Trace();
|
2022-07-05 13:09:48 +00:00
|
|
|
|
2022-08-30 06:55:09 +00:00
|
|
|
DestroyRepInfo(C);
|
2022-07-05 13:09:48 +00:00
|
|
|
}
|
|
|
|
|
2022-07-14 06:55:58 +00:00
|
|
|
public function bool CreateRepInfo(Controller C)
|
2022-07-05 13:09:48 +00:00
|
|
|
{
|
2022-07-14 06:55:58 +00:00
|
|
|
local CTI_RepInfo RepInfo;
|
2022-07-05 13:09:48 +00:00
|
|
|
|
2022-07-18 17:27:51 +00:00
|
|
|
`Log_Trace();
|
2022-07-05 13:09:48 +00:00
|
|
|
|
|
|
|
if (C == None) return false;
|
|
|
|
|
2022-07-14 06:55:58 +00:00
|
|
|
RepInfo = Spawn(class'CTI_RepInfo', C);
|
2022-07-05 13:09:48 +00:00
|
|
|
|
2022-07-14 06:55:58 +00:00
|
|
|
if (RepInfo == None) return false;
|
2022-07-05 13:09:48 +00:00
|
|
|
|
2022-07-14 06:55:58 +00:00
|
|
|
RepInfo.PrepareSync(
|
2022-07-05 13:09:48 +00:00
|
|
|
Self,
|
|
|
|
LogLevel,
|
|
|
|
RemoveItems,
|
|
|
|
AddItems,
|
2022-07-11 00:54:08 +00:00
|
|
|
CfgRemoveItems.default.bAll);
|
2022-07-05 13:09:48 +00:00
|
|
|
|
2022-07-14 06:55:58 +00:00
|
|
|
RepInfos.AddItem(RepInfo);
|
2022-07-05 13:09:48 +00:00
|
|
|
|
|
|
|
if (ReadyToSync)
|
|
|
|
{
|
2022-07-14 06:55:58 +00:00
|
|
|
RepInfo.ServerSync();
|
2022-07-05 13:09:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-14 06:55:58 +00:00
|
|
|
RepInfo.PendingSync = true;
|
2022-07-05 13:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-14 06:55:58 +00:00
|
|
|
public function bool DestroyRepInfo(Controller C)
|
2022-07-05 13:09:48 +00:00
|
|
|
{
|
2022-07-14 06:55:58 +00:00
|
|
|
local CTI_RepInfo RepInfo;
|
2022-07-05 13:09:48 +00:00
|
|
|
|
2022-07-18 17:27:51 +00:00
|
|
|
`Log_Trace();
|
2022-07-05 13:09:48 +00:00
|
|
|
|
|
|
|
if (C == None) return false;
|
|
|
|
|
2022-07-14 06:55:58 +00:00
|
|
|
foreach RepInfos(RepInfo)
|
2022-07-05 13:09:48 +00:00
|
|
|
{
|
2022-07-14 06:55:58 +00:00
|
|
|
if (RepInfo.Owner == C)
|
2022-07-05 13:09:48 +00:00
|
|
|
{
|
2022-07-14 06:55:58 +00:00
|
|
|
RepInfos.RemoveItem(RepInfo);
|
2022-08-30 06:55:09 +00:00
|
|
|
RepInfo.SafeDestroy();
|
2022-07-05 13:09:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DefaultProperties
|
|
|
|
{
|
|
|
|
ReadyToSync = false
|
|
|
|
}
|