Skip to content

Commit

Permalink
v0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ArifRios1st committed Oct 8, 2024
1 parent 861b5d7 commit 8f2a3eb
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 46 deletions.
28 changes: 25 additions & 3 deletions AssetStore/StringStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Il2CppTMPro;
using MelonLoader;
using UnityEngine;
using Il2Cpp;
using System.Text.RegularExpressions;

namespace PVZ_Hyper_Fusion.AssetStore
Expand Down Expand Up @@ -59,6 +60,8 @@ public static class StringStore
{@"^2、([^\s]+)","2. {0}"},
{@"^3、([^\s]+)","3. {0}"},
{@"^选择(\d+)","Select {0}"},

{@"^决战([^\s]+)!","Final Battle {0}"},
};

public static Dictionary<string, string> translationString = new Dictionary<string, string>()
Expand Down Expand Up @@ -264,9 +267,6 @@ public static class StringStore
{"迷你游戏","Mini Games"},


{"决战泳池!","Final Battle\n Pool!"},


{"解锁究极樱桃战神,超级大嘴花+樱桃大嘴花","Unlock the Ultimate Cherry War God, Super Big Mouth Flower + Cherry Big Mouth Flower"},
{"解锁究极樱桃机枪,樱桃机枪+超级樱桃射手","Unlock the Ultimate Cherry Machine Gun, Cherry Machine Gun + Super Cherry Shooter"},
{"解锁究极大喷菇,超级大喷菇+超级魅惑菇","Unlock the Ultimate Giant Ejection Mushroom, Super Giant Ejection Mushroom + Super Charm Mushroom"},
Expand Down Expand Up @@ -334,6 +334,28 @@ public static class StringStore
{ "窝草", "Tangle Kelp"},
{ "南瓜", "Pumpkin"},
{ "杨桃", "Starfruit"},

{"我是僵尸!","I am a zombie!"},
{"我也是僵尸!","I'm a zombie too!"},
{"你能吃了它吗!","Can you eat it!"},
{"雷区!","Minefield!"},
{"完全傻了!","Totally stunned!"},
{"卑鄙的低矮植物!","Despicable\nlowly plant!"},
{"QQ弹弹!","QQ bounce!"},
{"当代女大学生!","Modern Female\nCollege Student!"},
{"胆小菇前传!","Prequel of\nthe Scaredy-shroom!"},
{"冰冻关卡!","Frozen Level!"},
{"初见泳池!","First Encounter\nat the Pool!"},
{"三三得九!","Three times three\nequals nine!"},
{"嗯?","Hmm?"},
{"尸愁之路!","Path of the Undead!"},
{"严肃火炬!","Serious Torch!"},
{"你是僵尸","You are a zombie"},
{"你也是僵尸!","You are \na zombie too!"},
{"看星星!","Look at the stars!"},
{"万磁王!","Magneto!"},
{"十面埋伏!","Ambush from\nall sides!"},
{"马奇诺防线!","Maginot Line!"},
};

internal static void Init()
Expand Down
7 changes: 6 additions & 1 deletion AssetStore/TextureStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ namespace PVZ_Hyper_Fusion.AssetStore
public static class TextureStore
{
internal static Dictionary<string, string> textureDict = new Dictionary<string, string>();
public static List<Texture2D> changedList = new List<Texture2D>();

internal static void Init()
{
FileLoader.LoadTextures();
}

internal static void Reload()
{
textureDict.Clear();
FileLoader.LoadTextures();
}

public static IEnumerator ReplaceTexturesCoroutine()
{
while (true)
Expand Down
22 changes: 14 additions & 8 deletions Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
using Il2CppTMPro;
using PVZ_Hyper_Fusion.AssetStore;

[assembly: MelonInfo(typeof(PVZ_Hyper_Fusion.Core), "PVZ Hyper Fusion", "0.0.1", "arifrios1st", null)]
[assembly: MelonInfo(typeof(PVZ_Hyper_Fusion.Core), "PVZ Hyper Fusion", "0.0.2", "arifrios1st", null)]
[assembly: MelonGame("LanPiaoPiao", "PlantsVsZombiesRH")]

namespace PVZ_Hyper_Fusion
{
public class Core : MelonMod
{
private static DateTime dtStart;
private static DateTime? dtStartToast;
private static string toast_txt;

Expand All @@ -21,6 +22,11 @@ public class Core : MelonMod
object replaceTextureRoutine = null;
#endif

public override void OnEarlyInitializeMelon()
{
dtStart = DateTime.Now;
}

public override void OnInitializeMelon()
{
#if USE_TEXTURE
Expand All @@ -31,17 +37,20 @@ public override void OnInitializeMelon()
#endif
}

#if USE_TEXTURE
public override void OnLateInitializeMelon()
{
dtStart = DateTime.Now;
#if USE_TEXTURE
replaceTextureRoutine = MelonCoroutines.Start(TextureStore.ReplaceTexturesCoroutine());
#endif
}

public override void OnDeinitializeMelon()
{
#if USE_TEXTURE
MelonCoroutines.Stop(replaceTextureRoutine);
}
#endif
}

public static void ShowToast(string message)
{
Expand All @@ -51,16 +60,13 @@ public static void ShowToast(string message)

public override void OnLateUpdate()
{
#if USE_MOD
ModFeatures.OnLateUpdate();
#endif
}

public override void OnGUI()
{
#if USE_MOD

if (ModFeatures.GetActive(ModFeatures.ModType.Help))
if (ModFeatures.GetActive(ModFeatures.ModType.Help) || DateTime.Now - dtStart < new TimeSpan(0, 0, 0, 5))
{
string text = ModFeatures.GetFeatures();
int num = 0;
Expand All @@ -75,7 +81,7 @@ public override void OnGUI()
}
bool flag4 = GUI.Button(new Rect(10f, 30f, (float)num2 * 10f, (float)num * 16f + 15f), text);
}
#endif

if (dtStartToast != null)
{
GUI.Button(new Rect(10f, 10f, 200f, 20f), "\n" + toast_txt + "\n");
Expand Down
4 changes: 2 additions & 2 deletions FileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ internal static void LoadStrings()
if (!Directory.Exists(textureDir))
{
Directory.CreateDirectory(textureDir);
SaveStrings();
DumpJson();
}
try
{
Expand All @@ -49,6 +47,8 @@ internal static void LoadStrings()
}
}
}
SaveStrings();
DumpJson();
}
catch (Exception e)
{
Expand Down
20 changes: 16 additions & 4 deletions ModFeatures.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if USE_MOD
using Il2Cpp;
using Il2Cpp;
using System.Text;
using UnityEngine;
using HarmonyLib;
Expand All @@ -17,6 +16,7 @@ public enum ModType
ColumnPlant,
DeveloperMode,
ReloadStrings,
ReloadTextures,
Help,
}

Expand Down Expand Up @@ -44,6 +44,14 @@ public void ToggleFeature()
Core.ShowToast("Translation String Reloaded!");
return;
}
#endif
#if USE_TEXTURE
if (this.ModType == ModType.ReloadTextures)
{
TextureStore.Reload();
Core.ShowToast("Texture Reloaded!");
return;
}
#endif
IsActive = !IsActive;
if (this.ModType == ModType.Help)
Expand All @@ -55,7 +63,7 @@ public void ToggleFeature()

public override string ToString()
{
if(this.ModType == ModType.ReloadStrings || this.ModType == ModType.Help)
if(this.ModType == ModType.ReloadStrings || this.ModType == ModType.ReloadTextures || this.ModType == ModType.Help )
return string.Format("[{0}]{1}", this.KeyCode.ToString(), this.Name);

return string.Format("[{0}]{1} [{2}]", this.KeyCode.ToString(), this.Name, IsActive ? "ON" : "OFF");
Expand All @@ -64,13 +72,16 @@ public override string ToString()

private static Dictionary<ModType, ModFeature> featureLists = new Dictionary<ModType, ModFeature>()
{
#if USE_MOD
{ModType.UnlimitedSun,new ModFeature("Unlimited Sun",ModType.UnlimitedSun,KeyCode.F1)},
{ModType.NoCooldown,new ModFeature("No Cooldown",ModType.NoCooldown,KeyCode.F2)},
{ModType.NoTakeDamagePlant,new ModFeature("No Take Damage",ModType.NoTakeDamagePlant,KeyCode.F3)},
{ModType.ColumnPlant,new ModFeature("Column Plant",ModType.ColumnPlant,KeyCode.F4)},
{ModType.DeveloperMode,new ModFeature("Developer Mode",ModType.DeveloperMode,KeyCode.F5)},
#endif
#if USE_TRANSLATE
{ModType.ReloadStrings,new ModFeature("Reload Translation String",ModType.ReloadStrings,KeyCode.Home, true)},
{ModType.ReloadTextures,new ModFeature("Reload Texture",ModType.ReloadTextures,KeyCode.End, true)},
#endif
{ModType.Help,new ModFeature("Feature Lists",ModType.Help,KeyCode.Insert, false)},
};
Expand Down Expand Up @@ -124,6 +135,7 @@ public static void OnLateUpdate()
}
}

#if USE_MOD
private static class PatchClasses
{
[HarmonyPatch(typeof(CardUI))]
Expand Down Expand Up @@ -255,6 +267,6 @@ private static void Update()
}
}
}
#endif
}
}
#endif
3 changes: 2 additions & 1 deletion PVZ Hyper Fusion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@
<Compile Include="Log.cs" />
<Compile Include="ModFeatures.cs" />
<Compile Include="Patches\Advanture_Btn_Patch.cs" />
<Compile Include="Patches\AlmanacMgrZombie_Patch.cs" />
<Compile Include="Patches\AlmanacMgr_Patch.cs" />
<Compile Include="Patches\Close_Patch.cs" />
<Compile Include="Patches\CustomSettings_Patch.cs" />
Expand All @@ -345,7 +346,7 @@
<Compile Include="Patches\InGameBtn_Patch.cs" />
<Compile Include="Patches\InGameText_Patch.cs" />
<Compile Include="Patches\InGameUIMgr_Patch.cs" />
<Compile Include="Patches\MainMenu_Mgr_Patch.cs" />
<Compile Include="Patches\IZEMgr_Patch.cs" />
<Compile Include="Patches\OptionBtn_Patch.cs" />
<Compile Include="Patches\PauseMenu_Btn_Patch.cs" />
<Compile Include="Patches\SelectYourPlants_Patch.cs" />
Expand Down
49 changes: 49 additions & 0 deletions Patches/AlmanacMgrZombie_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#if USE_TRANSLATE
using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using UnityEngine;
using static Il2Cpp.AlmanacMgr;

namespace PVZ_Hyper_Fusion.Patches
{
[HarmonyPatch(typeof(AlmanacMgrZombie))]
public static class AlmanacMgrZombie_Patch
{
[HarmonyPatch(nameof(AlmanacMgrZombie.InitNameAndInfoFromJson))]
[HarmonyPrefix]
private static bool InitNameAndInfoFromJson(AlmanacMgrZombie __instance)
{
string basePatch = Path.Combine(Core.MOD_DIRECTORY, "PVZ_Hyper_Fusion");
string path = Path.Combine(basePatch, "ZombieStringsTranslate.json");

// Read the JSON content from the file or resources
if (!File.Exists(path)) return true;

string json;
json = File.ReadAllText(path);

TextMeshPro component = __instance.info.GetComponent<TextMeshPro>();
TextMeshPro component2 = __instance.zombieName.GetComponent<TextMeshPro>();
TextMeshPro component3 = __instance.zombieName.transform.GetChild(0).GetComponent<TextMeshPro>();

// Parse the JSON data
AlmanacMgrZombie.ZombieAlmanacData zombieData = JsonUtility.FromJson<AlmanacMgrZombie.ZombieAlmanacData>(json);
foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in zombieData.zombies)
{
if (zombieInfo.theZombieType == __instance.theZombieType)
{
component.text = zombieInfo.info + "\n\n" + zombieInfo.introduce;
component2.text = zombieInfo.name;
component2.autoSizeTextContainer = true;
component3.text = zombieInfo.name;
component3.autoSizeTextContainer = true;
break;
}
}

return false;
}
}
}
#endif
14 changes: 8 additions & 6 deletions Patches/AlmanacMgr_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ namespace PVZ_Hyper_Fusion.Patches
[HarmonyPatch(typeof(AlmanacMgr))]
public static class AlmanacMgr_Patch
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void Start(AlmanacMgr __instance)
[HarmonyPatch(nameof(AlmanacMgr.InitNameAndInfoFromJson))]
[HarmonyPrefix]
private static bool InitNameAndInfoFromJson(AlmanacMgr __instance)
{
string basePatch = Path.Combine(Core.MOD_DIRECTORY, "PVZ_Hyper_Fusion");
string path = Path.Combine(basePatch, "LawnStringsTranslate.json");

string json;

// Read the JSON content from the file or resources
if (!File.Exists(path)) return;
if (!File.Exists(path)) return true;

string json;
json = File.ReadAllText(path);

TextMeshPro component = __instance.info.GetComponent<TextMeshPro>();
Expand All @@ -45,6 +45,8 @@ private static void Start(AlmanacMgr __instance)
break;
}
}

return false;
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions Patches/IZEMgr_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PVZ_Hyper_Fusion.AssetStore;

namespace PVZ_Hyper_Fusion.Patches
{
[HarmonyPatch(typeof(IZEMgr))]
public static class IZEMgr_Patch
{
[HarmonyPatch(nameof(IZEMgr.Start))]
[HarmonyPostfix]
public static void Start(IZEMgr __instance)
{
TextMeshProUGUI[] array = new TextMeshProUGUI[]
{
__instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>(),
__instance.transform.GetChild(0).GetChild(0).GetComponent<TextMeshProUGUI>(),
};
for (int i = 0; i < array.Length; i++)
{
array[i].text = StringStore.TranslateText(array[i].text).Replace("\n", " ");
}
}
}
}
3 changes: 1 addition & 2 deletions Patches/InGameUIMgr_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ private static void Start(InGameUIMgr __instance)
TextMeshProUGUI[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
string oriText = array2[i].text;
array2[i].text = StringStore.TranslateText(array2[i].text);
array2[i].text = StringStore.TranslateText(array2[i].text).Replace("\n", " ");
}
}

Expand Down
Loading

0 comments on commit 8f2a3eb

Please sign in to comment.