class HideMut extends Mutator
  config(HideMut);


// =============================================================
struct FunctionRecord
{
  var config string About, Replace, With;
};
var config array<FunctionRecord> List;

var HideMut ref_HideMut;


// var newMainMenuClass class'HideMainMenu';

// =============================================================
event PreBeginPlay()
{
  super.PreBeginPlay();

  ref_HideMut = self;
  default.ref_HideMut = self;

  // remove some annoying messages
  class'WaitingMessage'.default.DoorMessage = "";
  class'WaitingMessage'.default.WeldedShutMessage = "";
  class'WaitingMessage'.default.ZEDTimeActiveMessage = "";

  // CrossbuzzsawBlade sound spam fix
  class'CrossbuzzsawBlade'.default.AmbientSoundRef = "";
  class'FNFALFire'.default.AmbientFireVolume = 0;
  class'CashPickup'.default.TransientSoundVolume = 0.0;
  class'CashPickup'.default.AmbientGlow = 0;
  class'machete'.default.priority = 3;

  // replacing vanilla functions with ours
  replace_Functions();
  replace_LobbyMenu();
  replace_MainMenu();

  // EXPERIMENTAL!!!
  // ReplaceDefaults();
}


final private function replace_LobbyMenu()
{
  class'KFPlayerController'.default.LobbyMenuClassString = string(class'HideLobbyMenu');
  class'KFPlayerController_Story'.default.LobbyMenuClassString = string(class'HideLobbyMenu');
}


// replace main menu with fixed one
final private function replace_MainMenu()
{
  local bool bChan;
  local string newmenuclass;
  local GameEngine GE;

  // our class
  newmenuclass = string(class'HideMainMenu');

  if (class'GameEngine'.default.MainMenuClass != newmenuclass || class'GameEngine'.default.SinglePlayerMenuClass != newmenuclass)
  {
    // change defaults
    class'GameEngine'.default.MainMenuClass = newmenuclass;
    class'GameEngine'.default.SinglePlayerMenuClass = newmenuclass;
    // strange variable, not used anywhere??
    // class'GameEngine'.default.InstantActionMenuClass = class'HideMainMenu';
    // save the config
    // class'GameEngine'.static.StaticSaveConfig();
    bChan = true;
  }

  if (!bChan)
    return;

  // change instanced ones
  foreach AllObjects(class'GameEngine', GE)
  {
    GE.MainMenuClass = class'GameEngine'.default.MainMenuClass;
    GE.SinglePlayerMenuClass = class'GameEngine'.default.SinglePlayerMenuClass;
    // save the config
    // GE.SaveConfig();
  }

  // log(">>> HIDEMUT: MENU class changed to " $ newmenuclass);
}


// replace lot's of bugged functions / add our hacks
final function replace_Functions()
{
  local uFunction A, B;
  local int i;

  for (i = 0; i < List.Length; i++)
  {
    // This removes the need to declare variables for every new class we make.
    DynamicLoadObject(class.outer.name $ "." $ Left(List[i].With,InStr(List[i].With,".")), class'class',true);

    A = class'UFunction'.static.CastFunction(FindObject(List[i].Replace, class'function'));
    B = class'UFunction'.static.CastFunction(FindObject(List[i].With, class'function'));

    if (A == none)
    {
      log("> Failed to process " $ List[i].Replace);
      continue;
    }
    if (B == none)
    {
      log("> Failed to process " $ List[i].With);
      continue;
    }

    A.Script = B.Script;
    log("> Processing " $ List[i].Replace $ "    ---->    " $ List[i].With);
  }
}


// final function ReplaceDefaults()
// {
//   local UClass a, b;

//   a = class'UClass'.static.CastClass(FindObject("KFMod.CrossbuzzsawBlade", class'class'));
//   b = class'UClass'.static.CastClass(FindObject("HideMut.repl_proj_buzzsaw", class'class'));

//   if (A == none)
//   {
//     log("> Failed to process " $ string(a));
//     return;
//   }
//   if (B == none)
//   {
//     log("> Failed to process " $ string(b));
//     return;
//   }

//   a.Defaults = b.Defaults;
//   log("> Processing " $ string(a) $ "    ---->    " $ string(b));
// }


// get our GUIController and open our Daddy menu, which attaches HideMutInteraction and saves it from GC
simulated function tick(float deltaTime)
{
  local PlayerController pc;

  pc = level.getLocalPlayerController();

  if (pc != none)
  {
    GUIController(pc.player.guiController).openMenu(string(class'WhosYourDaddy'));
    GUIController(pc.player.guiController).closeMenu(false);
    // we don't want this running forever, we already did all the work
    disable('tick');
    destroyed();
  }
}


// =============================================================

defaultproperties
{
}
