Skip to content

Commit

Permalink
Update UserXpMod to 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MoArtis committed Sep 14, 2019
1 parent d7f8cbf commit c0cd7c7
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 65 deletions.
25 changes: 20 additions & 5 deletions Code/ModifiedScripts.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

IMPORTANT :
This file is not up to date. Most of the 1.1 changes are missing.
I need manually retrack them down as I want to put as little WF's code as possible in there.

// ** PlayerInput.cs **
protected override void Start()
{
Expand Down Expand Up @@ -71,11 +76,12 @@ protected void Awake()

protected void Update()
{
if ((Input.GetKeyDown(KeyCode.Escape) || Singleton<GlobalInput>.instance.ButtonDown(GlobalInput.Buttons.Start)) && (!AreAllVideosPlayed || !AreAllLegalScreensPlayed) && _AllowOnePressStartSkip)
{
SkipAllMovies = true;
OnPressSkip();
}
//if ((Input.GetKeyDown(KeyCode.Escape) || Singleton<GlobalInput>.instance.ButtonDown(GlobalInput.Buttons.Start)) && (!AreAllVideosPlayed || !AreAllLegalScreensPlayed) && _AllowOnePressStartSkip)
if (AlreadyDoneDidThat && (Input.GetKeyDown(KeyCode.Escape) || Singleton<GlobalInput>.instance.ButtonDown(GlobalInput.Buttons.Start, GlobalInput.ControllerId.One)) && _AllowOnePressStartSkip)
{
SkipAllMovies = true;
OnPressSkip();
}
}

//New coroutine to avoid some UI bugs when all the intro are skipped on start
Expand Down Expand Up @@ -117,4 +123,13 @@ protected void SetStats()
//Add this just after the line 135
if (_characterStats[i].StatToWatch == PlayerAttributeEnum.Stamina && Mod.UserXpMod.fixMaxStaminaBug)
maxStatLevel = 39;
}

// ** CinematicManager.cs **
private void Update()
{
if (Mod.UserXpMod.data.allowQuickSkip && (Input.GetKeyDown(KeyCode.Escape) || Singleton<GlobalInput>.instance.ButtonDown(GlobalInput.Buttons.Start, GlobalInput.ControllerId.One)))
{
OnCinematicSkip();
}
}
156 changes: 129 additions & 27 deletions Code/UserXpMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,47 @@
namespace Mod
{
[System.Serializable]
public class ModData
public struct ModData
{
public bool allowSkipSplashScreens;
public bool allowQuickSkip;
public bool startFromMainMenu;

public string interactActionId;
public InputConfig[] playerOneInputConfigs;
public InputConfig[] playerTwoInputConfigs;
public bool forceXInput;
public bool usePS4buttonPrompts;
public bool displayProgressionInfo;

public int vSyncCount;
public int targetFramerate;
public bool useCustomFramelimiter;

public bool displayDamageOnHit;
public Color xpGetTextColor;
public int xpGetTextFontSize;
public Color hitDmgTextColor;
public int hitDmgTextFontSizeMin;
public int hitDmgTextFontSizeMax;

public bool noTutorialInNewGamePlus;

public bool unlockSecretCharactersOnceForAllSave;

public bool fixBooksBug;
public bool fixMaxStaminaBug;

public InputConfig GetInputConfig(int playerId)
{
if (playerId == 0)
{
return playerOneInputConfigs[0];
}
else
{
return playerTwoInputConfigs[0];
}
}
}

[System.Serializable]
Expand Down Expand Up @@ -78,48 +109,64 @@ public class UserXpMod

private static string kbMapXmlTemplate = "<?xml version =\"1.0\" encoding=\"utf-16\"?><KeyboardMap dataVersion=\"2\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://guavaman.com/rewired http://guavaman.com/schemas/rewired/1.1/KeyboardMap.xsd\" xmlns=\"http://guavaman.com/rewired\"><sourceMapId>{26}</sourceMapId><categoryId>{27}</categoryId><layoutId>0</layoutId><name></name><hardwareGuid>00000000-0000-0000-0000-000000000000</hardwareGuid><enabled>true</enabled><buttonMaps><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>1</actionId><elementType>1</elementType><elementIdentifierId>{0}</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>{13}</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3><enabled>true</enabled></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>1</actionId><elementType>1</elementType><elementIdentifierId>{1}</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>1</axisContribution><keyboardKeyCode>{14}</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3><enabled>true</enabled></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>0</actionId><elementType>1</elementType><elementIdentifierId>{2}</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>1</axisContribution><keyboardKeyCode>{15}</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3><enabled>true</enabled></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>0</actionId><elementType>1</elementType><elementIdentifierId>{3}</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>{16}</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3><enabled>true</enabled></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>9</actionId><elementType>1</elementType><elementIdentifierId>{4}</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>{17}</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3><enabled>true</enabled></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>3</actionId><elementType>1</elementType><elementIdentifierId>{5}</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>{18}</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3><enabled>true</enabled></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>4</actionId><elementType>1</elementType><elementIdentifierId>{6}</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>{19}</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3><enabled>true</enabled></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>2</actionId><elementType>1</elementType><elementIdentifierId>{7}</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>{20}</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3><enabled>true</enabled></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>5</actionId><elementType>1</elementType><elementIdentifierId>{8}</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>{21}</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3><enabled>true</enabled></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>6</actionId><elementType>1</elementType><elementIdentifierId>{9}</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>{22}</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3><enabled>true</enabled></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>7</actionId><elementType>1</elementType><elementIdentifierId>{10}</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>{23}</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3><enabled>true</enabled></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>11</actionId><elementType>1</elementType><elementIdentifierId>{11}</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>{24}</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3><enabled>true</enabled></ActionElementMap><ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>12</actionId><elementType>1</elementType><elementIdentifierId>{12}</elementIdentifierId><axisRange>0</axisRange><invert>false</invert><axisContribution>0</axisContribution><keyboardKeyCode>{25}</keyboardKeyCode><modifierKey1>0</modifierKey1><modifierKey2>0</modifierKey2><modifierKey3>0</modifierKey3><enabled>true</enabled></ActionElementMap></buttonMaps></KeyboardMap>";

private static ModData data = null;

public static bool startFromMainMenu { get { LoadModData(); return data.startFromMainMenu; } }
public static ModData data { get { LoadModData(); return _data; } set { _data = value; } }
private static ModData _data;

public static bool allowSkipSplashScreens { get { LoadModData(); return data.allowSkipSplashScreens; } }

public static string interactActionId { get { LoadModData(); return data.interactActionId; } }

public static bool fixBooksBug { get { LoadModData(); return data.fixBooksBug; } }

public static bool fixMaxStaminaBug { get { LoadModData(); return data.fixMaxStaminaBug; } }
public static bool hasData = false;

private static void LoadModData()
{
if (data == null)
if (hasData == false)
{
string modDataJson = File.ReadAllText(".\\ModData.json");
data = JsonUtility.FromJson<ModData>(modDataJson);

if (data.interactActionId == "")
_data.interactActionId = "QuickAttack";

hasData = true;
}
}

public static void ApplyFramerateConfig()
{
LoadModData();

if (hasData == false)
return;

if (data.useCustomFramelimiter)
{
Application.targetFrameRate = -1;
QualitySettings.vSyncCount = 0;
}
else
{
Application.targetFrameRate = data.targetFramerate;
QualitySettings.vSyncCount = data.vSyncCount;
}
}

public static void LoadCustomInputConfig()
{
LoadModData();

if (hasData == false)
return;

if (data.forceXInput)
{
ReInput.configuration.windowsStandalonePrimaryInputSource = Rewired.Platforms.WindowsStandalonePrimaryInputSource.XInput;
}

ReplacePlayerMaps(0, data);
ReplacePlayerMaps(1, data);

//File.WriteAllText(".\\config.txt", string.Concat(
// ReInput.configuration.windowsStandalonePrimaryInputSource, "\n",
// ReInput.configuration.disableNativeInput, "\n",
// ReInput.configuration.useXInput, "\n"
// ));
ReplacePlayerMaps(0);
ReplacePlayerMaps(1);
}

private static void ReplacePlayerMaps(int playerId, ModData inputData)
private static void ReplacePlayerMaps(int playerId)
{
InputConfig inputConfig = data.GetInputConfig(playerId);

Player.ControllerHelper.MapHelper mapHelper = ReInput.players.GetPlayer(playerId).controllers.maps;

//Clear previous maps
Expand All @@ -133,14 +180,14 @@ private static void ReplacePlayerMaps(int playerId, ModData inputData)
if (playerId == 0)
{
args.AddRange(playerOneElementIdentifierIds);
args.AddRange(inputData.playerOneInputConfigs[0].ToKeycodeArray());
}
else
{
args.AddRange(playerTwoElementIdentifierIds);
args.AddRange(inputData.playerTwoInputConfigs[0].ToKeycodeArray());
}

args.AddRange(inputConfig.ToKeycodeArray());

args.Add(playerId + 1);
args.Add(playerId + 1);

Expand All @@ -152,10 +199,65 @@ private static void ReplacePlayerMaps(int playerId, ModData inputData)
{
File.WriteAllText(string.Format(".\\Player{0}-Remap-ERROR.txt", playerId), string.Concat(e.Message, "\n", e.StackTrace));
}
}

private static Dictionary<string, PromptType> actionIdToPromptTypes = new Dictionary<string, PromptType>()
{
{ "Jump", PromptType.A },
{ "QuickAttack", PromptType.X },
{ "HeavyAttack", PromptType.Y },
{ "SpecialAttack", PromptType.B },
{ "Block", PromptType.RTrigger },
{ "Recruit", PromptType.LTrigger },
{ "Start", PromptType.Start },
};

public static PromptType ActionIdToPromptType(string actionId)
{
if (actionIdToPromptTypes.ContainsKey(actionId))
return actionIdToPromptTypes[actionId];
else
return PromptType.X;
}

private static long lastTime = HighResolutionTime.Time;

public static void FrameLimiterUpdate()
{
if (hasData == false || data.useCustomFramelimiter == false || data.targetFramerate <= 0.0) return;

//Controller map
//???
lastTime += TimeSpan.FromSeconds(1.0 / data.targetFramerate).Ticks;

var now = HighResolutionTime.Time;

if (now >= lastTime)
{
lastTime = now;
return;
}
else
{
//System.Threading.SpinWait.SpinUntil(() => { return (HighResolutionTime.Time >= lastTime); });
while (HighResolutionTime.Time < lastTime) { }
}
}

public static bool IsKunioAndRikkiUnlockedOnAnySaveSlot()
{
for (int i = 0; i < 4; i++)
{
List<PersistentData.EventSystemDataValue> eventValues = SaveManager_Main.LoadOrGetDefaultObject($"Slot_{i}_saveKeySlotFinishedEvents", new List<PersistentData.EventSystemDataValue>(), "savefile");
for (int j = 0; j < eventValues.Count; j++)
{
if (eventValues[j].EventName == "Kill Final")
{
if (eventValues[j].TimesFired >= 1)
return true;
}
}
}
return false;
}
}

}
}
15 changes: 14 additions & 1 deletion Data/ModData.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"allowSkipSplashScreens" : true,
"allowQuickSkip" : true,
"startFromMainMenu" : false,
"interactActionId" : "Recruit",
"playerOneInputConfigs" : [
Expand Down Expand Up @@ -33,6 +33,19 @@
}
],
"forceXInput" : false,
"usePS4buttonPrompts" : false,
"displayProgressionInfo" : false,
"vSyncCount" : 1,
"targetFramerate" : -1,
"useCustomFramelimiter" : false,
"displayDamageOnHit" : true,
"xpGetTextColor" : { "r":1,"g":0.8470589,"b":0.4117647,"a":1},
"xpGetTextFontSize" : 85,
"hitDmgTextColor" : {"r":1,"g":1,"b":1,"a":0},
"hitDmgTextFontSizeMin" : 80,
"hitDmgTextFontSizeMax" : 125,
"noTutorialInNewGamePlus" : true,
"unlockSecretCharactersOnceForAllSave" : true,
"fixBooksBug" : true,
"fixMaxStaminaBug" : true
}
Loading

0 comments on commit c0cd7c7

Please sign in to comment.