Skip to content

Commit

Permalink
add a patch for inventory and purchase classes
Browse files Browse the repository at this point in the history
  • Loading branch information
GenZmeY committed Jan 4, 2024
1 parent 24911df commit a9bec74
Show file tree
Hide file tree
Showing 12 changed files with 1,233 additions and 62 deletions.
50 changes: 47 additions & 3 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 = 4;
const LatestVersion = 5;

const CfgRemoveItems = class'RemoveItems';
const CfgAddItems = class'AddItems';
Expand All @@ -23,6 +23,7 @@ var private config String UnlockDLC;
var private config bool bPreloadContent;
var private config bool bOfficialWeaponsList;
var private config bool bDisableItemLimitCheck;
var private config bool bApplyPatch;

var private KFGameInfo KFGI;
var private KFGameReplicationInfo KFGRI;
Expand Down Expand Up @@ -111,6 +112,9 @@ private function PreInit()
case 3:
bDisableItemLimitCheck = false;

case 4:
bApplyPatch = false;

case MaxInt:
`Log_Info("Config updated to version" @ LatestVersion);
break;
Expand Down Expand Up @@ -206,6 +210,11 @@ private function PostInit()
}
`Log_Debug("DLCSkinUpdateRequired:" @ String(DLCSkinUpdateRequired.Value));

if (bApplyPatch)
{
ServerPatch();
}

Trader.static.OverwriteTraderItems(KFGRI, WeapDefs, LogLevel);

`Log_Info("Trader items:" @ WeapDefs.Length);
Expand All @@ -226,6 +235,41 @@ private function PostInit()
}
}

private function ServerPatch()
{
local class<KFAutoPurchaseHelper> AutoPurchaseHelper;
local class<KFInventoryManager> InventoryManager;

if (KFGI.KFGFxManagerClass.GetPackageName() != 'CTI')
{
if (Unlocker.static.CustomGFxManager(KFGI))
{
`Log_Warn("Custom KFGFxMoviePlayer_Manager detected:" @ String(KFGI.KFGFxManagerClass) $ ". There may be compatibility issues.");
}

if (KFGameInfo_VersusSurvival(KFGI) != None)
{
KFGI.KFGFxManagerClass = class'CTI_GFxMoviePlayer_Manager_Versus';
}
else
{
KFGI.KFGFxManagerClass = class'CTI_GFxMoviePlayer_Manager';
}
}

AutoPurchaseHelper = class<KFPlayerController>(KFGI.PlayerControllerClass).default.PurchaseHelperClass;
if (AutoPurchaseHelper != class'KFPlayerController'.default.PurchaseHelperClass)
{
`Log_Warn("Custom PurchaseHelperClass detected:" @ String(AutoPurchaseHelper) $ ". There may be compatibility issues.");
}

InventoryManager = class<KFInventoryManager>(KFGI.DefaultPawnClass.default.InventoryManagerClass);
if (InventoryManager != class'KFPawn'.default.InventoryManagerClass)
{
`Log_Warn("Custom InventoryManagerClass detected:" @ String(InventoryManager) $ ". There may be compatibility issues.");
}
}

private function Preload(const out Array<class<KFWeaponDefinition> > Content)
{
local Array<S_PreloadContent> PreloadContent;
Expand Down Expand Up @@ -299,7 +343,7 @@ public function bool CreateRepInfo(Controller C)

if (RepInfo == None) return false;

RepInfo.PrepareSync(Self, KFPlayerController(C), LogLevel, DLCSkinUpdateRequired.Value);
RepInfo.PrepareSync(Self, KFPlayerController(C), LogLevel, DLCSkinUpdateRequired.Value, bApplyPatch);

RepInfos.AddItem(RepInfo);

Expand Down Expand Up @@ -339,4 +383,4 @@ public function bool DestroyRepInfo(Controller C)
DefaultProperties
{
ReadyToSync = false
}
}
284 changes: 284 additions & 0 deletions CTI/Classes/CTI_AutoPurchaseHelper.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
class CTI_AutoPurchaseHelper extends KFAutoPurchaseHelper;

var private CTI_GFxObject_TraderItems CTI_TraderItems;
var private CTI_InventoryManager CTI_IM;

private function CTI_GFxObject_TraderItems GetCTI_TraderItems()
{
if (CTI_TraderItems == None)
{
if (TraderItems == None)
{
GetTraderItems();
}

if (TraderItems != None)
{
CTI_TraderItems = CTI_GFxObject_TraderItems(TraderItems);
}
}

return CTI_TraderItems;
}

private function CTI_InventoryManager GetCTI_IM()
{
if (CTI_IM == None)
{
CTI_IM = CTI_InventoryManager(Pawn.InvManager);
}

return CTI_IM;
}

public function Initialize(optional bool bInitializeOwned = true)
{
Super.Initialize(bInitializeOwned);
GetCTI_IM();
GetCTI_TraderItems();
}

public function bool UpgradeWeapon(int OwnedItemIndex)
{
local int ItemIndex;
local STraderItem DefaultItemInfo;
local SItemInformation ItemInfo;
local int Test1, Test2;

ItemInfo = OwnedItemList[OwnedItemIndex];
DefaultItemInfo = ItemInfo.DefaultItem;

if (ItemInfo.bIsSecondaryAmmo || !CanUpgrade(DefaultItemInfo, Test1, Test2, true))
{
return false;
}

if (GetCTI_IM() == None) return false;

CTI_GetItemIndicesFromArche(ItemIndex, DefaultItemInfo.ClassName);
CTI_IM.CTI_BuyUpgrade(ItemIndex, ItemInfo.ItemUpgradeLevel);
OwnedItemList[OwnedItemIndex].SellPrice = GetAdjustedSellPriceFor(DefaultItemInfo);

if (MyGfxManager != None && MyGfxManager.TraderMenu != None)
{
MyGfxManager.TraderMenu.OwnedItemList = OwnedItemList;
}

return true;
}

public function BoughtAmmo(float AmountPurchased, int Price, EItemType ItemType, optional name ClassName, optional bool bIsSecondaryAmmo)
{
local int ItemIndex;
AddDosh(-Price);

if (ItemType == EIT_Weapon)
{
CTI_GetItemIndicesFromArche(ItemIndex, ClassName);
}

if (GetCTI_IM() == None) return;

CTI_IM.CTI_BuyAmmo(AmountPurchased, ItemType, ItemIndex, bIsSecondaryAmmo);
}

private function float AmmoCostScale()
{
local KFGameReplicationInfo KFGRI;
KFGRI = KFGameReplicationInfo(WorldInfo.GRI);
return KFGRI == None? 1.0f : KFGRI.GameAmmoCostScale;
}

public function int AddWeaponToOwnedItemList(STraderItem DefaultItem, optional bool bDoNotBuy, optional int OverrideItemUpgradeLevel = INDEX_NONE)
{
local SItemInformation WeaponInfo;
local int ItemIndex, AddedWeaponIndex, OwnedSingleIdx, SingleDualAmmoDiff;
local bool bAddingDual;

WeaponInfo.MagazineCapacity = DefaultItem.MagazineCapacity;
CurrentPerk.ModifyMagSizeAndNumber(None, WeaponInfo.MagazineCapacity, DefaultItem.AssociatedPerkClasses,, DefaultItem.ClassName);

WeaponInfo.MaxSpareAmmo = DefaultItem.MaxSpareAmmo;
CurrentPerk.ModifyMaxSpareAmmoAmount(none, WeaponInfo.MaxSpareAmmo, DefaultItem);
WeaponInfo.MaxSpareAmmo += WeaponInfo.MagazineCapacity;

WeaponInfo.SpareAmmoCount = DefaultItem.InitialSpareMags * DefaultItem.MagazineCapacity;
CurrentPerk.ModifySpareAmmoAmount(none, WeaponInfo.SpareAmmoCount, DefaultItem);
WeaponInfo.SpareAmmoCount += WeaponInfo.MagazineCapacity;

bAddingDual = DefaultItem.SingleClassName != '';
if (bAddingDual)
{
for (OwnedSingleIdx = 0; OwnedSingleIdx < OwnedItemList.Length; ++OwnedSingleIdx)
{
if (OwnedItemList[OwnedSingleIdx].DefaultItem.ClassName != DefaultItem.SingleClassName) continue;

SingleDualAmmoDiff = OwnedItemList[OwnedSingleIdx].SpareAmmoCount - WeaponInfo.SpareAmmoCount;
SingleDualAmmoDiff = Max(0, SingleDualAmmoDiff);

if (WeaponInfo.SpareAmmoCount > OwnedItemList[OwnedSingleIdx].SpareAmmoCount)
{
OwnedItemList[OwnedSingleIdx].SpareAmmoCount = WeaponInfo.SpareAmmoCount;
}
else
{
WeaponInfo.SpareAmmoCount = Min(OwnedItemList[OwnedSingleIdx].SpareAmmoCount, WeaponInfo.MaxSpareAmmo);
}

WeaponInfo.ItemUpgradeLevel = OwnedItemList[OwnedSingleIdx].ItemUpgradeLevel;
break;
}
}

CurrentPerk.MaximizeSpareAmmoAmount(DefaultItem.AssociatedPerkClasses, WeaponInfo.SpareAmmoCount, DefaultItem.MaxSpareAmmo + DefaultItem.MagazineCapacity);

WeaponInfo.SecondaryAmmoCount = DefaultItem.InitialSecondaryAmmo;
CurrentPerk.ModifyMagSizeAndNumber(None, WeaponInfo.MagazineCapacity, DefaultItem.AssociatedPerkClasses, true, DefaultItem.ClassName);
CurrentPerk.ModifySpareAmmoAmount(None, WeaponInfo.SecondaryAmmoCount, DefaultItem, true);

WeaponInfo.MaxSecondaryAmmo = DefaultItem.MaxSecondaryAmmo;
CurrentPerk.ModifyMaxSpareAmmoAmount(None, WeaponInfo.MaxSecondaryAmmo, DefaultItem, true);

WeaponInfo.AmmoPricePerMagazine = AmmoCostScale() * DefaultItem.WeaponDef.default.AmmoPricePerMag;
WeaponInfo.SellPrice = GetAdjustedSellPriceFor(DefaultItem);

WeaponInfo.DefaultItem = DefaultItem;

if (OverrideItemUpgradeLevel > INDEX_NONE)
{
WeaponInfo.ItemUpgradeLevel = OverrideItemUpgradeLevel;
}

AddedWeaponIndex = AddItemByPriority(WeaponInfo);

if (GetCTI_IM() == None) return AddedWeaponIndex;

CTI_GetItemIndicesFromArche(ItemIndex, DefaultItem.ClassName);

if (!bDoNotBuy)
{
CTI_IM.CTI_ServerBuyWeapon(ItemIndex, WeaponInfo.ItemUpgradeLevel);
}
else
{
CTI_IM.CTI_ServerAddTransactionItem(ItemIndex, WeaponInfo.ItemUpgradeLevel);
AddBlocks(CTI_IM.GetWeaponBlocks(DefaultItem, WeaponInfo.ItemUpgradeLevel));
}

if (bAddingDual)
{
CTI_AddTransactionAmmo(ItemIndex, SingleDualAmmoDiff, false);
RemoveWeaponFromOwnedItemList(, DefaultItem.SingleClassName, true);
}

return AddedWeaponIndex;
}

public function RemoveWeaponFromOwnedItemList(optional int OwnedListIdx = INDEX_NONE, optional name ClassName, optional bool bDoNotSell)
{
local SItemInformation ItemInfo;
local int ItemIndex;
local int SingleOwnedIndex;

if (OwnedListIdx == INDEX_NONE && ClassName != '')
{
for (OwnedListIdx = 0; OwnedListIdx < OwnedItemList.length; ++OwnedListIdx)
{
if (OwnedItemList[OwnedListIdx].DefaultItem.ClassName == ClassName) break;
}
}

if (OwnedListIdx >= OwnedItemList.length) return;

ItemInfo = OwnedItemList[OwnedListIdx];

if (GetCTI_IM() == None) return;

if (!bDoNotSell)
{
CTI_GetItemIndicesFromArche(ItemIndex, ItemInfo.DefaultItem.ClassName);
CTI_IM.CTI_ServerSellWeapon(ItemIndex);
}
else
{
AddBlocks(-CTI_IM.GetDisplayedBlocksRequiredFor(ItemInfo.DefaultItem));
CTI_GetItemIndicesFromArche(ItemIndex, ItemInfo.DefaultItem.ClassName);
CTI_IM.CTI_ServerRemoveTransactionItem(ItemIndex);
}

if (OwnedItemList[OwnedListIdx].bIsSecondaryAmmo)
{
OwnedItemList.Remove(OwnedListIdx, 1);
if (OwnedListIdx - 1 >= 0)
{
OwnedItemList.Remove(OwnedListIdx - 1, 1);
}
}
else if (OwnedItemList[OwnedListIdx].DefaultItem.WeaponDef.static.UsesSecondaryAmmo())
{
if (OwnedListIdx + 1 < OwnedItemList.Length)
{
OwnedItemList.Remove(OwnedListIdx + 1, 1);
OwnedItemList.Remove(OwnedListIdx, 1);
}
}
else
{
OwnedItemList.Remove(OwnedListIdx, 1);
}

if (ItemInfo.DefaultItem.SingleClassName == 'KFWeap_Pistol_9mm' || ItemInfo.DefaultItem.SingleClassName == 'KFWeap_HRG_93R')
{
if (CTI_GetItemIndicesFromArche(ItemIndex, ItemInfo.DefaultItem.SingleClassName))
{
SingleOwnedIndex = AddWeaponToOwnedItemList(CTI_TraderItems.AllItems[ItemIndex], true, ItemInfo.ItemUpgradeLevel);

CTI_AddTransactionAmmo(ItemIndex, ItemInfo.SpareAmmoCount - (ItemInfo.MaxSpareAmmo / 2.0) + ((ItemInfo.MaxSpareAmmo / 2.0) - OwnedItemList[SingleOwnedIndex].SpareAmmoCount), false);
OwnedItemList[SingleOwnedIndex].SpareAmmoCount = ItemInfo.SpareAmmoCount;
}
}

if (MyGfxManager != None && MyGfxManager.TraderMenu != None)
{
MyGfxManager.TraderMenu.OwnedItemList = OwnedItemList;
}
}

public function SetWeaponInformation(KFWeapon KFW)
{
local int i;

GetCTI_TraderItems();

for (i = 0; i < CTI_TraderItems.AllItems.Length; i++)
{
if (KFW.Class.name == CTI_TraderItems.AllItems[i].ClassName)
{
SetWeaponInfo(KFW, CTI_TraderItems.AllItems[i]);
return;
}
}
}

// native private final function AddTransactionAmmo( byte ItemIndex, int Amount, bool bSecondaryAmmo );
private function CTI_AddTransactionAmmo(int ItemIndex, int Amount, bool bSecondaryAmmo); // TODO: impl

private function bool CTI_GetItemIndicesFromArche(out int ItemIndex, name WeaponClassName)
{
local int Index;

if (GetCTI_TraderItems() == None) return false;

Index = CTI_TraderItems.AllItems.Find('ClassName', WeaponClassName);

if (Index == INDEX_NONE) return false;

ItemIndex = Index;

return true;
}

defaultproperties
{

}
Loading

0 comments on commit a9bec74

Please sign in to comment.