Skip to content

Commit

Permalink
Merge branch 'mod' into oni-mod
Browse files Browse the repository at this point in the history
  • Loading branch information
drojf committed Aug 22, 2024
2 parents ff06b12 + 74cf3c0 commit 28f1d49
Show file tree
Hide file tree
Showing 14 changed files with 393 additions and 60 deletions.
62 changes: 56 additions & 6 deletions Assembly-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
<ProjectGuid>{0BA774AA-B2B4-468C-B002-CAA0652C466E}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<LangVersion>7.1</LangVersion>
<AssemblyName>Assembly-CSharp</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
Expand All @@ -26,7 +24,13 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>

<!-- These options are used when building the DLL for use in the mod-->
<PropertyGroup Condition="'$(Configuration)' != 'ScriptCompiler'">
<OutputType>Library</OutputType>
<AssemblyName>Assembly-CSharp</AssemblyName>
</PropertyGroup>
<ItemGroup Condition="'$(Configuration)' != 'ScriptCompiler'">
<Reference Include="UnityEngine">
<HintPath>DLLs\UnityEngine.dll</HintPath>
</Reference>
Expand All @@ -51,8 +55,6 @@
<Reference Include="UnityEngine.UI">
<HintPath>DLLs\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ActiveAnimation.cs" />
<Compile Include="AnimatedAlpha.cs" />
<Compile Include="AnimatedColor.cs" />
Expand Down Expand Up @@ -192,6 +194,7 @@
<Compile Include="BGICompiler.Compiler\BGIParameters.cs" />
<Compile Include="BGICompiler.Compiler\BGItoMG.cs" />
<Compile Include="BGICompiler.Compiler\BGIValue.cs" />
<Compile Include="BGICompiler.Compiler\LoggerWrapper.cs" />
<Compile Include="BGICompiler.Compiler\OperationHandler.cs" />
<Compile Include="BGICompiler.Compiler\OpType.cs" />
<Compile Include="BMFont.cs" />
Expand Down Expand Up @@ -241,6 +244,7 @@
<Compile Include="MOD.Scripts.Core\MODLocalization.cs" />
<Compile Include="MOD.Scripts.Core\MODLocalizationData.cs" />
<Compile Include="MOD.Scripts.Core\MODLogger.cs" />
<Compile Include="MOD.Scripts.Core\MODResolutionMonitor.cs" />
<Compile Include="MOD.Scripts.Core\MODSystem.cs" />
<Compile Include="MOD.Scripts.Core\MODUtility.cs" />
<Compile Include="MOD.Scripts.UI.ChapterJump\MODChapterJumpController.cs" />
Expand Down Expand Up @@ -614,6 +618,52 @@
<Compile Include="UIWidgetContainer.cs" />
<Compile Include="UIWrapContent.cs" />
</ItemGroup>
<ItemGroup />
<!-- End normal DLL items-->

<!--
These options are when building a standalone "Script Compiler" executable,
which is used to compile the game scripts on Github Actions.
NOTE: Visual Studio doesn't properly reload settings when you switch configurations,
so you will need to reload the project when you are changing between "Release" and "ScriptCompiler"
-->
<PropertyGroup Condition="'$(Configuration)' == 'ScriptCompiler'">
<OutputType>Exe</OutputType>
<AssemblyName>HigurashiScriptCompiler</AssemblyName>
<DefineConstants>STANDALONE_SCRIPT_COMPILER</DefineConstants>
<!-- Output and optimization options -->
<OutputPath>bin\ScriptCompiler\</OutputPath>
<DebugSymbols>true</DebugSymbols>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup Condition="'$(Configuration)' == 'ScriptCompiler'">
<Reference Include="System">
<HintPath>DLLs\System.dll</HintPath>
</Reference>
<Reference Include="System.Core">
<HintPath>DLLs\System.Core.dll</HintPath>
</Reference>
<Reference Include="Antlr3.Runtime">
<HintPath>DLLs\Antlr3.Runtime.dll</HintPath>
</Reference>
<Compile Include="AntlrTest\bgitestLexer.cs" />
<Compile Include="AntlrTest\bgitestParser.cs" />
<Compile Include="BGICompiler.Compiler\LoggerWrapper.cs" />
<Compile Include="Assets.Scripts.Core.Buriko\BurikoCommands.cs" />
<Compile Include="Assets.Scripts.Core.Buriko\BurikoMathType.cs" />
<Compile Include="Assets.Scripts.Core.Buriko\BurikoOperations.cs" />
<Compile Include="Assets.Scripts.Core.Buriko\BurikoTextModes.cs" />
<Compile Include="Assets.Scripts.Core.Buriko\BurikoValueType.cs" />
<Compile Include="BGICompiler.Compiler\BGIParameters.cs" />
<Compile Include="BGICompiler.Compiler\BGItoMG.cs" />
<Compile Include="BGICompiler.Compiler\BGIValue.cs" />
<Compile Include="BGICompiler.Compiler\NoUnityScriptCompiler.cs" />
<Compile Include="BGICompiler.Compiler\OperationHandler.cs" />
<Compile Include="BGICompiler.Compiler\OpType.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<!-- End standalone script compiler items -->

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
3 changes: 3 additions & 0 deletions Assembly-CSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
ScriptCompiler|Any CPU = ScriptCompiler|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0BA774AA-B2B4-468C-B002-CAA0652C466E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0BA774AA-B2B4-468C-B002-CAA0652C466E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0BA774AA-B2B4-468C-B002-CAA0652C466E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0BA774AA-B2B4-468C-B002-CAA0652C466E}.Release|Any CPU.Build.0 = Release|Any CPU
{0BA774AA-B2B4-468C-B002-CAA0652C466E}.ScriptCompiler|Any CPU.ActiveCfg = ScriptCompiler|Any CPU
{0BA774AA-B2B4-468C-B002-CAA0652C466E}.ScriptCompiler|Any CPU.Build.0 = ScriptCompiler|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 6 additions & 6 deletions Assets.Scripts.Core.Buriko/BurikoScriptFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2801,8 +2801,8 @@ public BurikoVariable OperationMODGenericCall()
string[] lipSyncParams = callParameters.Split(',');

if(lipSyncParams.Length == 3 &&
float.TryParse(lipSyncParams[0].Trim(), out float thresh1) &&
float.TryParse(lipSyncParams[1].Trim(), out float thresh2) &&
MODUtility.TryParseInvariantCulture(lipSyncParams[0].Trim(), out float thresh1) &&
MODUtility.TryParseInvariantCulture(lipSyncParams[1].Trim(), out float thresh2) &&
bool.TryParse(lipSyncParams[2].Trim(), out bool forceComputedLipsync))
{
GameSystem.Instance.SceneController.MODSetExpressionThresholds(thresh1, thresh2);
Expand All @@ -2816,7 +2816,7 @@ public BurikoVariable OperationMODGenericCall()

case "LipSyncCacheSettings":
string[] lipSyncCacheParams = callParameters.Split(',');
if (lipSyncCacheParams.Length == 1 && int.TryParse(lipSyncCacheParams[0].Trim(), out int maxAge))
if (lipSyncCacheParams.Length == 1 && MODUtility.TryParseInvariantCulture(lipSyncCacheParams[0].Trim(), out int maxAge))
{
MODLipsyncCache.SetMaxTextureAge(maxAge);
}
Expand All @@ -2827,21 +2827,21 @@ public BurikoVariable OperationMODGenericCall()
break;

case "NormalFontWeight":
if(int.TryParse(callParameters, out int normalFontWeightPercent))
if(MODUtility.TryParseInvariantCulture(callParameters, out int normalFontWeightPercent))
{
MODFontAdjuster.SetNormalFontWeight(normalFontWeightPercent / 100.0f);
}
break;

case "BoldFontWeight":
if (int.TryParse(callParameters, out int boldFontWeightPercent))
if (MODUtility.TryParseInvariantCulture(callParameters, out int boldFontWeightPercent))
{
MODFontAdjuster.SetBoldFontWeight(boldFontWeightPercent / 100.0f);
}
break;

case "FaceDilate":
if (int.TryParse(callParameters, out int faceDilate))
if (MODUtility.TryParseInvariantCulture(callParameters, out int faceDilate))
{
MODFontAdjuster.SetFaceDilation(faceDilate / 100.0f);
}
Expand Down
20 changes: 0 additions & 20 deletions Assets.Scripts.Core.State/StateNormal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,26 +191,6 @@ public bool InputHandler()
gameSystem.IsSkipping = !gameSystem.IsSkipping;
}

// Fullscreen
if (Input.GetKeyDown(KeyCode.F))
{
if (GameSystem.Instance.IsFullscreen)
{
int num14 = PlayerPrefs.GetInt("width");
int num15 = PlayerPrefs.GetInt("height");
if (num14 == 0 || num15 == 0)
{
num14 = 640;
num15 = 480;
}
GameSystem.Instance.DeFullscreen(width: num14, height: num15);
}
else
{
GameSystem.Instance.GoFullscreen();
}
}

// Toggle Language
if (Input.GetKeyDown(KeyCode.L))
{
Expand Down
24 changes: 22 additions & 2 deletions Assets.Scripts.Core/GameSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -897,14 +897,18 @@ private void LateUpdate()
if (screenModeSet == -1)
{
screenModeSet = 0;
string source = "Screen.currentResolution";
fullscreenResolution = Screen.currentResolution;
if (PlayerPrefs.HasKey("fullscreen_width") && PlayerPrefs.HasKey("fullscreen_height") && Screen.fullScreen)
{
source = "PlayerPrefs[fullscreen_width] and [fullscreen_height]";
fullscreenResolution.width = PlayerPrefs.GetInt("fullscreen_width");
fullscreenResolution.height = PlayerPrefs.GetInt("fullscreen_height");
}
Debug.Log("Fullscreen Resolution: " + fullscreenResolution.width + ", " + fullscreenResolution.height);
Debug.Log($"LateUpdate Fullscreen Resolution: [{fullscreenResolution.width}, {fullscreenResolution.height}] Source: [{source}]");
}

MOD.Scripts.Core.MODResolutionMonitor.Update();
}

private bool CheckInitialization()
Expand Down Expand Up @@ -1068,6 +1072,15 @@ public T ChooseJapaneseEnglish<T>(T japanese, T english)
}
}

public bool MODWindowedResolutionValid(int width, int height)
{
Resolution fullScreenResolution = GetFullscreenResolution();
return width > 320 &&
height > 240 &&
width <= fullScreenResolution.width &&
height <= fullScreenResolution.height;
}

public Resolution GetFullscreenResolution(bool useOverride = true, bool doLogging = true)
{
Resolution resolution = new Resolution();
Expand Down Expand Up @@ -1102,7 +1115,14 @@ public Resolution GetFullscreenResolution(bool useOverride = true, bool doLoggin
// If it's bigger than that, then switch over
// Note that this (from what I can tell) gives you the biggest resolution of any of your monitors,
// not just the one the game is running under, so it could *also* be wrong, which is why we check both methods
if (Screen.resolutions.Length > 0)
//
// NOTE: On the Higurashi Rei (Ep9) and Hou+ (Ep10) versions of Unity (2019.4.36), Screen.resolutions doesn't work correctly.
// The unmodded game for Ep9 and Ep10 works correctly on my laptop, implying the 'stock' fullscreen resolution is correct.
// As a result the below "best resolution" code has been disabled for Ep9 and Ep10 (and future chapters too) and the LateUpdate() resolution is used instead.
//
// See: https://github.com/07th-mod/hou-plus/issues/13
const bool doBestResolutionScanning = true;
if (doBestResolutionScanning && Screen.resolutions.Length > 0)
{
int index = 0;
Resolution best = Screen.resolutions[0];
Expand Down
44 changes: 33 additions & 11 deletions Assets.Scripts.UI.Config/ScreenSwitcherButton.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Assets.Scripts.Core;
using MOD.Scripts.Core;
using MOD.Scripts.UI;
using UnityEngine;

namespace Assets.Scripts.UI.Config
Expand All @@ -11,7 +13,7 @@ public class ScreenSwitcherButton : MonoBehaviour

private UIButton button;

private int Height()
private int? Height()
{
// Old resolutions (which the assetbundle button widths are based on) were 640x480, 800x600, and 1024x768
// New resolutions are 1280x720, 1920x1080, and 2560x1440
Expand All @@ -24,8 +26,7 @@ private int Height()
case 1024:
return 1440;
default:
Debug.LogWarning("Found unexpected width button " + Width);
return Mathf.RoundToInt(Width / GameSystem.Instance.AspectRatio);
return null;
}
}

Expand All @@ -34,22 +35,43 @@ private void OnClick()
if (IsFullscreen)
{
GameSystem.Instance.GoFullscreen();
return;
}
else

// Check the button's Width is valid. I've seen error messages where the above Height() switch statement states that Width is 0.
int? maybe_height = Height();
if(maybe_height == null)
{
MODToaster.Show($"Button has invalid width: [{Width}]");
return;
}

int height = maybe_height.Value;
int width = Mathf.RoundToInt(height * GameSystem.Instance.AspectRatio);

// Check the windowed resolution would actually fit in the monitor
if (!GameSystem.Instance.MODWindowedResolutionValid(width, height))
{
int height = Height();
int width = Mathf.RoundToInt(height * GameSystem.Instance.AspectRatio);
GameSystem.Instance.DeFullscreen(width: width, height: height);
PlayerPrefs.SetInt("width", width);
PlayerPrefs.SetInt("height", height);
MODToaster.Show($"Resolution Too Big/Small: [{width}x{height}]");
return;
}

GameSystem.Instance.DeFullscreen(width: width, height: height);
PlayerPrefs.SetInt("width", width);
PlayerPrefs.SetInt("height", height);

// Check if the resolution was set correctly. If not, revert to fullscreen resolution.
// See MODResolutionMonitor for details
MODResolutionMonitor.RevertToFullscreenIfResolutionChangeFails(new ResolutionChangeInfo(width, height, delayBeforeResolutionCheck: 10));

Debug.Log($"Attempted to set Windowed resolution {width}x{height}");
}

private bool ShouldBeDown()
{
if (IsFullscreen)
if (GameSystem.Instance.IsFullscreen)
{
return GameSystem.Instance.IsFullscreen;
return IsFullscreen;
}
return Screen.height == Height();
}
Expand Down
2 changes: 1 addition & 1 deletion BGICompiler.Compiler/BGIParameters.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Antlr.Runtime.Tree;
using Assets.Scripts.Core.Buriko;
using System.Collections.Generic;
using UnityEngine;
using BGICompiler.Compiler.Logger;

namespace BGICompiler.Compiler
{
Expand Down
2 changes: 1 addition & 1 deletion BGICompiler.Compiler/BGItoMG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
using BGICompiler.Compiler.Logger;

namespace BGICompiler.Compiler
{
Expand Down
44 changes: 44 additions & 0 deletions BGICompiler.Compiler/LoggerWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;

namespace BGICompiler.Compiler.Logger
{
class Debug
{
#if STANDALONE_SCRIPT_COMPILER
public static void Log(object message)
{
print($"INFO", message);
}

public static void LogWarning(object message)
{
print("WARN", message);
}

public static void LogError(object message)
{
print("ERROR", message);
}

private static void print(string level, object message)
{
Console.WriteLine($"[{level}] {message}", message);
}
#else
public static void Log(object message)
{
UnityEngine.Debug.Log(message);
}

public static void LogWarning(object message)
{
UnityEngine.Debug.LogWarning(message);
}

public static void LogError(object message)
{
UnityEngine.Debug.Log(message);
}
#endif
}
}
Loading

0 comments on commit 28f1d49

Please sign in to comment.