Skip to content

Commit

Permalink
CyberGrind fix, prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydraxous committed Mar 19, 2023
1 parent 3428837 commit aa27826
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 70 deletions.
1 change: 0 additions & 1 deletion Components/InventoryControllerDeployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ private void NewCheckStatus()

public void OpenInventory()
{
Debug.Log("Try open inv");
if (invController.gameObject.activeInHierarchy)
{
return;
Expand Down
38 changes: 32 additions & 6 deletions Components/UFGWeaponManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,21 @@ public List<List<string>> CreateWeaponKeyset(InventoryControllerData invControll
newWeaponKeys.Add(newWeaponKeyList);
}

//Do not disable weaponsinuse if weapons are changed while in cybergrind.
if(LevelCheck.CurrentLevelType != LevelCheck.UKLevelType.Endless || WeaponsInUse == false)
{
WeaponsInUse = (wepCount > 0);
}


return newWeaponKeys;
}

//Gets weapon prefabs from the Data loader and instantiates them into the world and adds them to the gun controllers lists.
public void DeployWeapons(bool firstTime = false)
{

if(!LevelCheck.InLevel())
{
WeaponsInUse = false;
return;
}

string sceneName = SceneManager.GetActiveScene().name;
bool deploy = true;

Expand Down Expand Up @@ -151,6 +154,8 @@ public void DeployWeapons(bool firstTime = false)
//adds weapons to the gun controller
private void AddWeapons()
{
bool weaponsUsed = false;

for (int j = 0; j < customSlots.Count; j++)
{
if (gc.slots.Contains(customSlots[j]))
Expand All @@ -167,14 +172,30 @@ private void AddWeapons()
{
if (!gc.allWeapons.Contains(wep))
{
weaponsUsed = true;
gc.allWeapons.Add(wep);
AddWeaponToFreshnessDict(wep);
}
}

}


if (LevelCheck.CurrentLevelType == LevelCheck.UKLevelType.Endless)
{
if (WeaponsInUse)
{
if (!EndlessGrid.Instance.GetComponent<Collider>().enabled)
{
HudMessageReceiver.Instance.SendHudMessage("You must restart the level after disabling UFG weapons for your score to count.");
weaponsUsed = true;
}
}else if(weaponsUsed)
{
HudMessageReceiver.Instance.SendHudMessage("Warning: having any UFG weapons enabled will prevent your CyberGrind score from being submitted.");
}
}

WeaponsInUse = weaponsUsed;
}

//TODO fix this, for some reason the input on switching to weapons doesn't work past slot 7. No its not because of the keycodes, that was an attempt to fix it. Inspect the GunControl class closer.
Expand Down Expand Up @@ -273,5 +294,10 @@ public static bool AddWeaponToFreshnessDict(GameObject go)

return false;
}

private void OnDestroy()
{
WeaponsInUse = false;
}
}
}
5 changes: 0 additions & 5 deletions Components/UI/InventoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ public InventoryControllerData GetCurrentInventoryData()
}
return new InventoryControllerData(newNodeArray.ToArray(), data.modVersion, data.firstTimeUsingInventory, data.firstTimeModLoaded, data.lecturedAboutVersion);
}

private void OnDestroy()
{
Debug.LogError("INVENTORY DESTROYED.");
}
}

[System.Serializable]
Expand Down
27 changes: 1 addition & 26 deletions Components/UI/InventoryDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public static bool LoadInventoryData()
{
Console.WriteLine("UFG: Inventory data found is for a different version of UFG, rebuilding.");
FirstTimeLoad();
}
UpdateWeaponUsage(inventory);
};
Console.WriteLine("UFG: Inventory data loaded.");
return true;
}catch (System.Exception e)
Expand All @@ -81,35 +80,11 @@ public static bool LoadInventoryData()
}
}

private static void UpdateWeaponUsage(InventoryControllerData data)
{
bool weaponsInUse = false;
for (int x = 0; x < data.slots.Length; x++)
{
for (int y = 0; y < data.slots[x].slotNodes.Length; y++)
{
if (weaponsInUse)
{
break;
}

if (data.slots[x].slotNodes[y].weaponEnabled)
{
weaponsInUse = true;
break;
}
}
}

UltraFunGuns.usedWeapons = weaponsInUse;
}

public static void SaveInventoryData(InventoryControllerData data)
{
inventory = data;
string loadoutData = JsonConvert.SerializeObject(inventory);
File.WriteAllText(loadoutDataPath, loadoutData);
UpdateWeaponUsage(data);
Console.WriteLine("UFG: Inventory data saved.");
}

Expand Down
2 changes: 1 addition & 1 deletion Components/UI/InventoryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void Initialize(InventoryNodeData data, InventorySlot slot, int slotIndex
weaponIcon_Disabled = new Color(73f, 73f, 73f, 255f);
nodeBg_Enabled = new Color(185.0f, 185.0f, 185.0f, 110f);
nodeBg_Disabled = new Color(49.0f, 49.0f, 49.0f, 110f);
Debug.Log(data.weaponKey + " NODE INIT!");
//Debug.Log(data.weaponKey + " NODE INIT!");
this.slotIndexPosition = slotIndex;
this.data = data;
this.slot = slot;
Expand Down
3 changes: 2 additions & 1 deletion Components/Weapons/EggToss/EggSplosion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ private void Awake()
//Eggsplosion casts a sphere to try and find enemies nearby. It then spawns an egg and shoots it at the found enemy.
private void Start()
{
Debug.Log("Eggsplosion!");


RaycastHit[] hits = Physics.SphereCastAll(transform.position, explosionSize, transform.position, Mathf.Infinity);
if (hits.Length > 0)
{
Expand Down
14 changes: 3 additions & 11 deletions Patches/CyberGrindPatch.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using UnityEngine;

Expand All @@ -11,25 +12,16 @@ public class CheatsPatch
[HarmonyPatch(typeof(SteamController), nameof(SteamController.SubmitCyberGrindScore))]
public static class CyberGrindPreventer
{
public static bool Prefix()
public static bool Prefix(SteamController __instance)
{
Debug.Log("ERM CYBERGWIND?");
if(UFGWeaponManager.WeaponsInUse)
{
Debug.Log("UFG: weapons used. Disqualifying cybergrind score.");
return false;
}

return true;
}
}

[HarmonyPatch(typeof(EndlessGrid),"OnEnable")]
public static class CyberWarning
{
public static void Postfix()
{

}
}
}
}
19 changes: 0 additions & 19 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public class UltraFunGuns : BaseUnityPlugin
public UFGWeaponManager gunPatch;
public InventoryControllerDeployer invControllerDeployer;

public static bool usedWeapons = true;

public const string RELEASE_VERSION = "1.1.8-Experimental";
const string GITHUB_URL = "https://api.github.com/repos/Hydraxous/ultrafunguns/tags";

Expand Down Expand Up @@ -55,7 +53,6 @@ private void CheckWeapons()
CanvasController canvas = MonoSingleton<CanvasController>.Instance;
if(!canvas.TryGetComponent<InventoryControllerDeployer>(out invControllerDeployer))
{
usedWeapons = false;
invControllerDeployer = canvas.gameObject.AddComponent<InventoryControllerDeployer>();
}

Expand All @@ -66,7 +63,6 @@ private void CheckWeapons()
GunControl gc = MonoSingleton<GunControl>.Instance;
if (!gc.TryGetComponent<UFGWeaponManager>(out UFGWeaponManager ultraFGPatch))
{
usedWeapons = false;
gunPatch = gc.gameObject.AddComponent<UFGWeaponManager>();
gunPatch.Slot7Key = SLOT_7_KEY.Value;
gunPatch.Slot8Key = SLOT_8_KEY.Value;
Expand Down Expand Up @@ -170,27 +166,12 @@ private bool RegisterAssets()

}

private static void UpdateMajorAssistUsage()
{
if (MonoSingleton<StatsManager>.Instance != null)
{
if (!MonoSingleton<StatsManager>.Instance.majorUsed)
{
MonoSingleton<StatsManager>.Instance.majorUsed = usedWeapons;
}
}
}

private void Update()
{
try
{
if(!InLevel())
{
usedWeapons = false;
}
CheckWeapons();
UpdateMajorAssistUsage();
}
catch(System.Exception e)
{
Expand Down

0 comments on commit aa27826

Please sign in to comment.