Skip to content

Commit

Permalink
Prep for new SPT mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchangelWTF committed Jan 17, 2025
1 parent 6b3f1d4 commit a001eeb
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 21 deletions.
12 changes: 6 additions & 6 deletions Fika.Headless/FikaHeadlessPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ protected void Awake()
new ValidateFormatPatch2().Enable();
new ValidateFormatPatch3().Enable();
new GameWorld_OnGameStarted_Patch().Enable();
new MainMenuController_method_48_Patch().Enable();
new MainMenuControllerClass_method_48_Patch().Enable();
new ConsoleScreen_OnProfileReceive_Patch().Enable();
new Class442_Run_Patch().Enable();
new Player_VisualPass_Patch().Enable();
new IsReflexAvailablePatch().Enable();
new AudioSource_Play_Transpiler().Enable();
new LevelSettings_ApplySettings_Transpiler().Enable();
new LevelSettings_ApplyTreeWindSettings_Transpiler().Enable();
new MainMenuController_method_45_Patch().Enable();
new MainMenuController_method_46_Patch().Enable();
new MainMenuController_method_73_Patch().Enable();
new MainMenuController_method_74_Patch().Enable();
new MainMenuControllerClass_method_45_Patch().Enable();
new MainMenuControllerClass_method_46_Patch().Enable();
new MainMenuControllerClass_method_73_Patch().Enable();
new MainMenuControllerClass_method_74_Patch().Enable();
new LocaleManagerClass_String_0_Patch().Enable();
new TarkovApplication_method_39_Patch().Enable();
// TODO: Fix
Expand Down Expand Up @@ -372,7 +372,7 @@ private IEnumerator BeginFikaStartRaid(StartHeadlessRequest request, ISession se
raidSettings.RaidMode = ERaidMode.Local;
raidSettings.IsPveOffline = true;

MainMenuController mmc = Traverse.Create(tarkovApplication).Field<MainMenuController>("mainMenuController").Value;
MainMenuControllerClass mmc = Traverse.Create(tarkovApplication).Field<MainMenuControllerClass>("mainMenuController").Value;
Traverse mmcTraverse = Traverse.Create(mmc);
mmcTraverse.Field<RaidSettings>("raidSettings_0").Value = raidSettings;
mmcTraverse.Field<RaidSettings>("raidSettings_1").Value = raidSettings;
Expand Down
131 changes: 129 additions & 2 deletions Fika.Headless/Patches/DestroyGraphics/LoadScenePatch.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using BSG.Unity.Wires;
using Diz.Utils;
using EFT.Interactive;
using EFT.UI;
using Fika.Core.Coop.Utils;
using HarmonyLib;
using SPT.Reflection.Patching;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEngine.SceneManagement;
Expand All @@ -22,13 +26,14 @@ static void Postfix(string sceneName, AsyncOperation __result)
{
GameObject tempGameObject = new("SceneModificationHandler");
SceneModificationHandler handler = tempGameObject.AddComponent<SceneModificationHandler>();

handler.StartCoroutine(handler.WaitForSceneLoad(sceneName, __result));
}
}

public class SceneModificationHandler : MonoBehaviour
{
private Mesh EmptySceneMesh = null;

public IEnumerator WaitForSceneLoad(string sceneName, AsyncOperation operation)
{
// Wait for the scene to finish loading
Expand All @@ -37,7 +42,15 @@ public IEnumerator WaitForSceneLoad(string sceneName, AsyncOperation operation)
yield return null;
}

FikaHeadlessPlugin.FikaHeadlessLogger.LogDebug($"Scene {sceneName} is fully loaded.");
if(EmptySceneMesh == null)
{
EmptySceneMesh = new()
{
name = "Fika Headless - empty mesh"
};
}

FikaHeadlessPlugin.FikaHeadlessLogger.LogInfo($"Scene {sceneName} is fully loaded.");

Scene loadedScene = SceneManager.GetSceneByName(sceneName);
if (loadedScene.IsValid())
Expand All @@ -54,6 +67,10 @@ private void ModifyLoadedScene(Scene scene)
{
//Logger.LogInfo($"Inspecting root object: {rootObj.name}");
DestroyRenderers(RootGameObjects);
DestroyAnimationClips(RootGameObjects);
Destroy2DTextures(RootGameObjects);
DestroyLODGroups(RootGameObjects);
DestroyMeshes(RootGameObjects);
}
}

Expand Down Expand Up @@ -129,5 +146,115 @@ private void DestroyRenderers(GameObject prefab)
Destroy(renderer);
}
}

private void DestroyAnimationClips(GameObject prefab)
{
// Get all Animation components in the GameObject hierarchy
Animation[] animations = prefab.GetComponentsInChildren<Animation>(true);
Animator[] animators = prefab.GetComponentsInChildren<Animator>(true);

// Destroy all AnimationClips in Animation components
foreach (Animation animation in animations)
{
foreach (AnimationState state in animation)
{
if (state.clip != null)
{
Destroy(state.clip);
}
}
}

// Destroy all AnimationClips in Animator components
foreach (Animator animator in animators)
{
RuntimeAnimatorController controller = animator.runtimeAnimatorController;
if (controller != null)
{
// Destroy clips in AnimatorOverrideController
if (controller is AnimatorOverrideController overrideController)
{
foreach (var clipPair in overrideController.clips)
{
if (clipPair.overrideClip != null)
{
Destroy(clipPair.overrideClip);
}
}
}

// Destroy all AnimationClips referenced in the RuntimeAnimatorController
AnimationClip[] animationClips = controller.animationClips;
foreach (AnimationClip clip in animationClips)
{
if (clip != null)
{
Destroy(clip);
}
}

// Optionally, destroy the controller itself if no longer needed
Destroy(controller);
}
}
}

private void Destroy2DTextures(GameObject prefab)
{
Texture2D[] textures = prefab.GetComponentsInChildren<Texture2D>(true);
// Destroy all AnimationClips in Animation components
foreach (Texture2D texture in textures)
{
if (texture != null)
{
Destroy(texture);
}
}
}

private void DestroyLODGroups(GameObject prefab)
{
LODGroup[] lODGroups = prefab.GetComponentsInChildren<LODGroup>(true);
// Destroy all AnimationClips in Animation components
foreach (LODGroup lod in lODGroups)
{
if (lod != null)
{
Destroy(lod);
}
}
}

private void DestroyMeshes(GameObject prefab)
{
List<MeshFilter> allMeshFilters = GetAllMeshFiltersInChildren(prefab);

foreach (MeshFilter meshFilter in allMeshFilters)
{
if (meshFilter != null)
{
Destroy(meshFilter);
}
}
}

List<MeshFilter> GetAllMeshFiltersInChildren(GameObject parent)
{
List<MeshFilter> meshFilterList = [];

MeshFilter parentMeshFilter = parent.GetComponent<MeshFilter>();
if (parentMeshFilter != null)
{
meshFilterList.Add(parentMeshFilter);
}

foreach (Transform child in parent.transform)
{
meshFilterList.AddRange(GetAllMeshFiltersInChildren(child.gameObject));
}

return meshFilterList;
}

}
}
21 changes: 21 additions & 0 deletions Fika.Headless/Patches/DestroyGraphics/RainFallDrops_Awake_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using SPT.Reflection.Patching;
using UnityEngine;
using System.Reflection;

namespace Fika.Headless.Patches.DestroyGraphics
{
internal class RainFallDrops_Awake_Patch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(RainFallDrops).GetMethod(nameof(RainFallDrops.smethod_0));
}

[PatchPrefix]
public static bool Prefix(int count, ref Mesh __result)
{
__result = new();
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ namespace Fika.Headless.Patches
/// <summary>
/// This patch simulates clicking "Next" by calling the method bound to the event of the button
/// </summary>
internal class MainMenuController_method_45_Patch : ModulePatch
internal class MainMenuControllerClass_method_45_Patch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(MainMenuController).GetMethod(nameof(MainMenuController.method_45));
return typeof(MainMenuControllerClass).GetMethod(nameof(MainMenuControllerClass.method_45));
}

[PatchPrefix]
public static bool Prefix(MainMenuController __instance)
public static bool Prefix(MainMenuControllerClass __instance)
{
__instance.method_77();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ namespace Fika.Headless.Patches
/// <summary>
/// This patch simulates clicking "Next" by calling the method bound to the event of the button
/// </summary>
internal class MainMenuController_method_46_Patch : ModulePatch
internal class MainMenuControllerClass_method_46_Patch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(MainMenuController).GetMethod(nameof(MainMenuController.method_46));
return typeof(MainMenuControllerClass).GetMethod(nameof(MainMenuControllerClass.method_46));
}

[PatchPrefix]
public static bool Prefix(MainMenuController __instance)
public static bool Prefix(MainMenuControllerClass __instance)
{
__instance.method_47();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ namespace Fika.Headless.Patches
/// <summary>
/// This patch skips checking for keys (e.g. Labs)
/// </summary>
public class MainMenuController_method_48_Patch : ModulePatch
public class MainMenuControllerClass_method_48_Patch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(MainMenuController).GetMethod(nameof(MainMenuController.method_48));
return typeof(MainMenuControllerClass).GetMethod(nameof(MainMenuControllerClass.method_48));
}

[PatchPrefix]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ namespace Fika.Headless.Patches
/// <summary>
/// This patch skips a bunch of unneccesary methods
/// </summary>
internal class MainMenuController_method_73_Patch : ModulePatch
internal class MainMenuControllerClass_method_73_Patch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(MainMenuController).GetMethod(nameof(MainMenuController.method_73));
return typeof(MainMenuControllerClass).GetMethod(nameof(MainMenuControllerClass.method_73));
}

[PatchPrefix]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace Fika.Headless.Patches
/// <summary>
/// This patch ensures that the raid settings are skipped if you are playing as a scav
/// </summary>
internal class MainMenuController_method_74_Patch : ModulePatch
internal class MainMenuControllerClass_method_74_Patch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(MainMenuController).GetMethod(nameof(MainMenuController.method_74));
return typeof(MainMenuControllerClass).GetMethod(nameof(MainMenuControllerClass.method_74));
}

[PatchPostfix]
public static void Postfix(MainMenuController __instance, RaidSettings ___raidSettings_0)
public static void Postfix(MainMenuControllerClass __instance, RaidSettings ___raidSettings_0)
{
if (___raidSettings_0.IsScav)
{
Expand Down
Binary file modified References/hollowed.dll
Binary file not shown.
Binary file modified References/spt-common.dll
Binary file not shown.
Binary file modified References/spt-core.dll
Binary file not shown.
Binary file modified References/spt-custom.dll
Binary file not shown.
Binary file modified References/spt-debugging.dll
Binary file not shown.
Binary file modified References/spt-reflection.dll
Binary file not shown.
Binary file modified References/spt-singleplayer.dll
Binary file not shown.

0 comments on commit a001eeb

Please sign in to comment.