Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Mod Menu, Stuck Sprite fix, and bug fixes #67

Merged
merged 30 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d276ea6
Add tabbed sections in mod options
drojf May 19, 2021
44914d7
Rename "Steam Sync" to "Steam Cloud" in all strings
drojf Jun 13, 2021
6f0dc46
Fix no click sounds on non-radio buttons
drojf Jul 26, 2021
ad4557b
Update comments in MODMenu.cs
drojf Jul 26, 2021
c1eb7b4
Rename "Menu Modes" to "Sub Menus"
drojf Jul 26, 2021
c0ab2c9
Remove linked options
drojf Jul 26, 2021
d6a6c17
Split background and background stretching into two different options
drojf Jul 26, 2021
9d024d6
Simplify background options
drojf Jul 26, 2021
256d143
Separate developer tools from other troubleshooting options and add w…
drojf Jul 26, 2021
e444bd1
Fix GBackgroundSet flag in preset setting/detection
drojf Jul 26, 2021
24a7b7a
Indicate modified preset via "Custom" preset
drojf Jul 26, 2021
7255e6a
Add "Text Window Appearance & Sprite Cropping" setting to mod menu
drojf Jul 26, 2021
e1e9ffb
Rename Presets from ADV->Console and NVL->MangaGamer, and fix preset …
drojf Jul 26, 2021
d5f616e
Rename presets to match actual behavior
drojf Jul 27, 2021
e587233
Set GLipSync when using Console Preset
drojf Jul 27, 2021
1e89fd5
Add preset saving/loading
drojf Jul 27, 2021
817b47f
Fix crash when toggling art sets repeatedly (#54)
drojf Jul 27, 2021
32273fb
Fix both preset & custom preset being highlighted
drojf Jul 28, 2021
ca7083d
Fix wrong preset modified detection for MangaGamer preset
drojf Jul 28, 2021
6c1758a
Add custom preset to preset toggle
drojf Jul 28, 2021
00e1391
Fix toasts being displayed when they shouldn't be
drojf Jul 30, 2021
279a6e4
Add option to not restore preset from memory, allowing you to overwri…
drojf Jul 30, 2021
f2d2a61
Automatically switch to custom preset when preset modified
drojf Jul 30, 2021
4de7bad
Don't show toast if switched to custom preset via UI
drojf Jul 30, 2021
04dfda5
Hide developer tools unless user deliberately shows it
drojf Jul 30, 2021
de907e4
Make sprite cropping depend only on background type and stretch setting
drojf Aug 4, 2021
cf66091
Fix portrait images not being cropped in 4:3 mode
drojf Aug 13, 2021
37b040f
Fix wrong description for sprite style option
drojf Aug 14, 2021
74c247b
Revert sprite position in 4:3 mode
drojf Aug 13, 2021
3f42f27
Fix stuck sprite issue by directly swapping textures (See #45)
drojf Sep 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Assembly-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
<Compile Include="MOD.Scripts.Core\MODUtility.cs" />
<Compile Include="MOD.Scripts.UI.ChapterJump\MODChapterJumpController.cs" />
<Compile Include="MOD.Scripts.UI.Tips\MODTipsController.cs" />
<Compile Include="MOD.Scripts.UI\MODCustomFlagPreset.cs" />
<Compile Include="MOD.Scripts.UI\MODKeyboardShortcuts.cs" />
<Compile Include="MOD.Scripts.UI\MODMainUIController.cs" />
<Compile Include="MOD.Scripts.UI\MODMenu.cs" />
Expand All @@ -254,6 +255,7 @@
<Compile Include="MOD.Scripts.UI\MODSimpleTimer.cs" />
<Compile Include="MOD.Scripts.UI\MODSound.cs" />
<Compile Include="MOD.Scripts.UI\MODStyleManager.cs" />
<Compile Include="MOD.Scripts.UI\MODTabControl.cs" />
<Compile Include="MOD.Scripts.UI\MODToaster.cs" />
<Compile Include="Newtonsoft.Json.Bson\BsonArray.cs" />
<Compile Include="Newtonsoft.Json.Bson\BsonBinaryType.cs" />
Expand Down
8 changes: 4 additions & 4 deletions Assets.Scripts.Core.AssetManagement/AssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public string PathToAssetWithName(string name, PathCascadeList artset)
{
int backgroundSetIndex = BurikoMemory.Instance.GetGlobalFlag("GBackgroundSet").IntValue();

// If force og backgrounds is enabled, always check OGBackgrounds first.
if (backgroundSetIndex == 2)
// If OG backgrounds are enabled, always check OGBackgrounds first.
if (backgroundSetIndex == 1)
{
string filePath = Path.Combine(Path.Combine(assetPath, "OGBackgrounds"), name);
if (File.Exists(filePath))
Expand All @@ -129,8 +129,8 @@ public string PathToAssetWithName(string name, PathCascadeList artset)

foreach (var artSetPath in artset.paths)
{
// If force console backgrounds is enabled, don't check OGBackgrounds
if (backgroundSetIndex == 1 && artSetPath == "OGBackgrounds")
// If console backgrounds are enabled, don't check OGBackgrounds
if (backgroundSetIndex == 0 && artSetPath == "OGBackgrounds")
{
continue;
}
Expand Down
32 changes: 32 additions & 0 deletions Assets.Scripts.Core.Buriko/BurikoMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Assets.Scripts.Core.Buriko.VarTypes;
using MOD.Scripts.Core.Audio;
using MOD.Scripts.Core.Scene;
using MOD.Scripts.UI;
using Newtonsoft.Json;
using Newtonsoft.Json.Bson;
using System;
Expand All @@ -29,6 +30,8 @@ internal class BurikoMemory

private List<string> cgflags = new List<string>();

private MODCustomFlagPreset customFlagPreset = new MODCustomFlagPreset();

private int scopeLevel;

public static BurikoMemory Instance
Expand Down Expand Up @@ -187,6 +190,11 @@ public void ResetScope()
MODSceneController.ClearLayerFilters();
}

public MODCustomFlagPreset GetCustomFlagPresetInstance()
{
return customFlagPreset;
}

public bool SeenCG(string cg)
{
return cgflags.Contains(cg);
Expand Down Expand Up @@ -527,6 +535,25 @@ public void LoadGlobals()
{
readText = jsonSerializer.Deserialize<Dictionary<string, List<int>>>(reader);
}
try
{
using (BsonReader reader = new BsonReader(stream) { CloseInput = false })
{
Dictionary<string, int> deserializedState = jsonSerializer.Deserialize<Dictionary<string, int>>(reader);
if(deserializedState == null)
{
Debug.LogWarning("Failed to load graphics preset state (serializer returned null)! Probably is old global.dat file missing this data.");
}
else
{
customFlagPreset.Flags = deserializedState;
}
}
}
catch(Exception arg)
{
Debug.LogWarning("Failed to load graphics preset state! Exception: " + arg);
}
}
}
catch (Exception arg)
Expand Down Expand Up @@ -574,6 +601,11 @@ public void SaveGlobals()
jsonSerializer.Serialize(jsonWriter, globalFlags);
jsonSerializer.Serialize(jsonWriter, cgflags);
jsonSerializer.Serialize(jsonWriter, readText);
if(customFlagPreset.Enabled)
{
customFlagPreset.SavePresetToMemory();
}
jsonSerializer.Serialize(jsonWriter, customFlagPreset.Flags);
inputBytes = memoryStream.ToArray();
}
}
Expand Down
38 changes: 37 additions & 1 deletion Assets.Scripts.Core.Buriko/BurikoScriptFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2508,6 +2508,9 @@ public BurikoVariable OperationMODDrawCharacter()
bool flag = ReadVariable().BoolValue();
string textureName2 = textureName + "0";
string text = textureName + str;

x = MODRyukishiRevertSpritePosition(textureName, x);

MODSystem.instance.modSceneController.MODLipSyncInvalidateAndGenerateId(character);
if (!MODSystem.instance.modSceneController.MODLipSyncIsEnabled())
{
Expand Down Expand Up @@ -2556,6 +2559,9 @@ public BurikoVariable OperationMODDrawCharacterWithFiltering()
bool flag = ReadVariable().BoolValue();
string textureName2 = textureName + "0";
string text = textureName + str;

x = MODRyukishiRevertSpritePosition(textureName, x);

MODSystem.instance.modSceneController.MODLipSyncInvalidateAndGenerateId(character);
if (!MODSystem.instance.modSceneController.MODLipSyncIsEnabled())
{
Expand Down Expand Up @@ -2769,7 +2775,7 @@ public BurikoVariable OperationMODGenericCall()
case "ShowSetupMenuIfRequired":
if(MODAudioSet.Instance.HasAudioSetsDefined() && !MODAudioSet.Instance.GetCurrentAudioSet(out _))
{
GameSystem.Instance.MainUIController.modMenu.SetMode(ModMenuMode.AudioSetup);
GameSystem.Instance.MainUIController.modMenu.SetSubMenu(ModSubMenu.AudioSetup);
GameSystem.Instance.MainUIController.modMenu.Show();
}
break;
Expand All @@ -2780,5 +2786,35 @@ public BurikoVariable OperationMODGenericCall()
}
return BurikoVariable.Null;
}

/// <summary>
/// This function reverts the x positions of sprites when using 4:3 backgrounds to match the original game
/// In some places, our mod has 'spread out' the sprite positions to better match 16:9 widescreen by setting
/// their X position to 240/-240 instead of 160/-160 (mostly when there are 3 characters on the screen at once).
/// However, when playing in 4:3 mode, this causes the sprites to be more cut-off than they were in the original game.
/// This function attempts to revert this specific case by changing an X of 240/-240 into 160/-160.
/// </summary>
private int MODRyukishiRevertSpritePosition(string path, int x)
{
path = path.ToLower();

if(BurikoMemory.Instance.GetGlobalFlag("GBackgroundSet").IntValue() == 1 && // Using OG Backgrounds AND
BurikoMemory.Instance.GetGlobalFlag("GStretchBackgrounds").IntValue() == 0) // Not stretching backgrounds
{
if (path.StartsWith("sprite/") || path.StartsWith("portrait/")) // is from the sprite or portrait folder
{
if (x == 240)
{
return 160;
}
else if (x == -240)
{
return -160;
}
}
}

return x;
}
}
}
77 changes: 9 additions & 68 deletions Assets.Scripts.Core.Scene/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,15 @@ private void EnsureCorrectlySizedMesh(int width, int height, LayerAlignment alig
bool stretchToFit = false;
if (texturePath != null)
{
ryukishiClamp = isBustShot && Buriko.BurikoMemory.Instance.GetGlobalFlag("GRyukishiMode").IntValue() == 1 && (texturePath.Contains("sprite/") || texturePath.Contains("sprite\\"));
// We want to clamp sprites to 4:3 if you are using the OG backgrounds, and you are not stretching the background
ryukishiClamp = isBustShot &&
Buriko.BurikoMemory.Instance.GetGlobalFlag("GBackgroundSet").IntValue() == 1 && // Using OG Backgrounds AND
Buriko.BurikoMemory.Instance.GetGlobalFlag("GStretchBackgrounds").IntValue() == 0 && // Not stretching backgrounds AND
(texturePath.Contains("sprite/") ||
texturePath.Contains("sprite\\") ||
texturePath.Contains("portrait/") ||
texturePath.Contains("portrait\\")); // Is a sprite or portrait image. I don't think we can rely only on isBustShot, as sometimes non-sprites are drawn with isBustShot

stretchToFit = Buriko.BurikoMemory.Instance.GetGlobalFlag("GStretchBackgrounds").IntValue() == 1 && texturePath.Contains("OGBackgrounds");
}

Expand Down Expand Up @@ -816,72 +824,5 @@ private void Update()
public void MODOnlyRecompile()
{
}

public void MODDrawLayer(string textureName, Texture2D tex2d, int x, int y, int z, Vector2? origin, float alpha, bool isBustshot, int type, float wait, bool isBlocking)
{
cachedIsBustShot = isBustshot;
FinishAll();
if (textureName == string.Empty)
{
HideLayer();
}
else if (tex2d == null)
{
Logger.LogError("Failed to load texture " + textureName);
}
else
{
startRange = 0f;
targetRange = alpha;
targetAlpha = alpha;
meshRenderer.enabled = true;
shaderType = type;
PrimaryName = textureName;
float num = 1f;
if (z > 0)
{
num = 1f - (float)z / 400f;
}
if (z < 0)
{
num = 1f + (float)z / -400f;
}
EnsureCorrectlySizedMesh(
width: tex2d.width, height: tex2d.height,
alignment: ((x != 0 || y != 0) && !isBustshot) ? LayerAlignment.AlignTopleft : LayerAlignment.AlignCenter,
origin: origin,
isBustShot: isBustshot,
finalXOffset: x,
texturePath: null
);
if (primary != null)
{
material.shader = shaderCrossfade;
SetSecondaryTexture(primary);
SetPrimaryTexture(tex2d);
startRange = 1f;
targetRange = 0f;
targetAlpha = 1f;
}
else
{
material.shader = shaderDefault;
if (type == 3)
{
material.shader = shaderMultiply;
}
SetPrimaryTexture(tex2d);
}
SetRange(startRange);
base.transform.localPosition = new Vector3((float)x, 0f - (float)y, (float)Priority * -0.1f);
base.transform.localScale = new Vector3(num, num, 1f);
targetPosition = base.transform.localPosition;
targetScale = base.transform.localScale;
if (Mathf.Approximately(wait, 0f))
{
FinishFade();
}
}
}
}
}
72 changes: 16 additions & 56 deletions Assets.Scripts.Core.Scene/SceneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,14 @@ public void ReloadAllImages()
{
layer.ReloadTexture();
}

// Force Unity to unload unused assets.
// Higuarshi will do this if you play the game normally each time ExecuteActions()
// is called (it appears as "Unloading 7 unused Assets to reduce memory usage." in the log).
// However, if you don't advance the text, it won't ever clean up.
// Eventually, you can run out of memory if this function is repeatedly
// called (for example, constantly toggling art styles)
Resources.UnloadUnusedAssets();
}

private Scene GetActiveScene()
Expand Down Expand Up @@ -839,54 +847,6 @@ public void MODOnlyRecompile()
{
}

public void MODDrawBustshot(int layer, string textureName, Texture2D tex2d, int x, int y, int z, int oldx, int oldy, int oldz, bool move, int priority, int type, float wait, bool isblocking)
{
if (MODSkipImage(textureName))
{
return;
}

Layer layer2 = GetLayer(layer);
while (layer2.FadingOut)
{
layer2.HideLayer();
layer2 = GetLayer(layer);
}
if (!move)
{
oldx = x;
oldy = y;
oldz = z;
}
layer2.MODDrawLayer(textureName, tex2d, oldx, oldy, oldz, null, 1f, /*isBustshot:*/ true, type, wait, isblocking);
layer2.SetPriority(priority);
if (move)
{
layer2.MoveLayer(x, y, z, 1f, 0, wait, isblocking, adjustAlpha: false);
}
iTween.Stop(layer2.gameObject);
if (Mathf.Approximately(wait, 0f))
{
layer2.FinishFade();
}
else
{
layer2.FadeInLayer(wait);
if (isblocking)
{
GameSystem.Instance.AddWait(new Wait(wait, WaitTypes.WaitForMove, layer2.FinishFade));
}
if (layer2.UsingCrossShader() && layer2.gameObject.layer != GetActiveLayerMask())
{
SetLayerActiveOnBothScenes(layer2);
}
else
{
UpdateLayerMask(layer2, priority);
}
}
}

public IEnumerator MODDrawLipSync(int character, int audiolayer, string audiofile)
{
ulong coroutineId = MODSystem.instance.modSceneController.MODLipSyncInvalidateAndGenerateId(character);
Expand Down Expand Up @@ -916,13 +876,13 @@ public IEnumerator MODDrawLipSync(int character, int audiolayer, string audiofil
switch (exparray[k])
{
case "2":
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "2", exp2, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp2, coroutineId);
break;
case "1":
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "1", exp3, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp3, coroutineId);
break;
case "0":
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "0", exp4, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp4, coroutineId);
break;
}
}
Expand All @@ -931,9 +891,9 @@ public IEnumerator MODDrawLipSync(int character, int audiolayer, string audiofil
}
else
{
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "0", exp4, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp4, coroutineId);
yield return (object)new WaitForSeconds(0.25f);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "1", exp3, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp3, coroutineId);
yield return (object)new WaitForSeconds(0.25f);
int k = 0;
if (GameSystem.Instance.AudioController.IsVoicePlaying(audiolayer))
Expand All @@ -948,14 +908,14 @@ public IEnumerator MODDrawLipSync(int character, int audiolayer, string audiofil
{
break;
}
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "0", exp4, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp4, coroutineId);
yield return (object)new WaitForSeconds(0.25f);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "1", exp3, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp3, coroutineId);
yield return (object)new WaitForSeconds(0.25f);
}
}
}
MODSystem.instance.modSceneController.MODLipSyncProcess(character, "0", exp4, coroutineId);
MODSystem.instance.modSceneController.MODLipSyncProcess(character, exp4, coroutineId);
}

public void MODLipSyncStart(int character, int audiolayer, string audiofile)
Expand Down
2 changes: 1 addition & 1 deletion Assets.Scripts.UI/MainUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ public void OnGUI()
{
if(BurikoSaveManager.lastSaveError != null)
{
MODMenuSupport.EmergencyModMenu("Error loading save file! Please backup your saves, DISABLE STEAM SYNC, then delete the following save file:", BurikoSaveManager.lastSaveError);
MODMenuSupport.EmergencyModMenu("Error loading save file! Please 1. Backup your saves, 2. DISABLE STEAM CLOUD, 3. Delete the following save file:", BurikoSaveManager.lastSaveError);
return;
}

Expand Down
Loading