Skip to content

Commit

Permalink
fix for v35, custom upgrade menu, split patches up and methods for up…
Browse files Browse the repository at this point in the history
…grademodels and towermodels
  • Loading branch information
silentstorm committed Feb 16, 2023
1 parent f86622c commit 09145dd
Show file tree
Hide file tree
Showing 14 changed files with 623 additions and 281 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin
obj
.vscode
.vscode
SC2ExpansionProject
98 changes: 98 additions & 0 deletions AssetLoadingPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
namespace SC2ExpansionLoader{
public class PrefabSpriteLoading{
[HarmonyPatch(typeof(Factory.__c__DisplayClass21_0),"_CreateAsync_b__0")]
public class FactoryCreateAsync_Patch{
[HarmonyPrefix]
public static bool Prefix(ref Factory.__c__DisplayClass21_0 __instance,ref UnityDisplayNode prototype){
string towerName=__instance.objectId.guidRef.Split('-')[0];
if(towerName!=null&&TowerTypes.ContainsKey(towerName)){
try{
SC2Tower tower=TowerTypes[towerName];
GameObject gObj=uObject.Instantiate(LoadAsset<GameObject>(__instance.objectId.guidRef,tower.LoadedBundle).Cast<GameObject>(),
__instance.__4__this.DisplayRoot);
gObj.name=__instance.objectId.guidRef;
gObj.transform.position=new(0,0,30000);
gObj.AddComponent<UnityDisplayNode>();
SC2Sound sound=gObj.AddComponent<SC2Sound>();
sound.MaxSelectQuote=tower.MaxSelectQuote;
sound.MaxUpgradeQuote=tower.MaxUpgradeQuote;
if(tower.Behaviours.ContainsKey(gObj.name)){
gObj.AddComponent(tower.Behaviours[gObj.name]);
}
prototype=gObj.GetComponent<UnityDisplayNode>();
__instance.__4__this.active.Add(prototype);
__instance.onComplete.Invoke(prototype);
}catch(Exception error){
Log("Failed to set "+__instance.objectId.guidRef+" up");
string message=error.Message;
message+="@\n"+error.StackTrace;
Log(message,"error");
}
return false;
}
return true;
}
}
[HarmonyPatch(typeof(UnityEngine.U2D.SpriteAtlas),"GetSprite")]
public class SpriteAtlasGetSprite_Patch{
[HarmonyPostfix]
public static void Postfix(string name,ref Sprite __result){
string towerName="";
try{
towerName=name.Split('-')[0];
}catch{}
if(TowerTypes.ContainsKey(towerName)){
try{
Texture2D texture=LoadAsset<Texture2D>(name,TowerTypes[towerName].LoadedBundle).Cast<Texture2D>();
__result=Sprite.Create(texture,new(0,0,texture.width,texture.height),new());
}catch(Exception error){
Log("Failed to set "+name+" up");
string message=error.Message;
message+="@\n"+error.StackTrace;
Log(message,"error");
}
}
}
}

[HarmonyPatch(typeof(AudioFactory),"Start")]
public class AudioFactoryStart_Patch{
[HarmonyPostfix]
public static void Postfix(AudioFactory __instance){
Log("audio");
foreach(string bundlePath in Directory.GetFiles(BundleDir)){
if(bundlePath.EndsWith("clips")){
try{
Log(1);
AssetBundleCreateRequest bundleCreateReq=AssetBundle.LoadFromFileAsync(bundlePath);
Log(bundleCreateReq.isDone);
Log(2);
AssetBundle bundle=bundleCreateReq.assetBundle;
Log(bundle==null);
Log(3);
foreach(var thing in bundle.AllAssetNames()){
Log(thing);
}
Log(4);
AssetBundleRequest bundleReq=bundle.LoadAllAssetsAsync<AudioClip>();
Log(4.1f);
Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppReferenceArray<uObject>assets=bundleReq.allAssets;
Log(5);
foreach(uObject asset in assets){
Log(6);
__instance.RegisterAudioClip(asset.name,asset.Cast<AudioClip>());
Log(7);
}
Log(8);
}catch(Exception error){
Log("Failed to add audio clips from "+bundlePath);
string message=error.Message;
message+="@\n"+error.StackTrace;
Log(message,"error");
}
}
}
}
}
}
}
Binary file added Bundles/ui.protossupgrademenu.bundle
Binary file not shown.
Binary file added Bundles/ui.terranupgrademenu.bundle
Binary file not shown.
9 changes: 8 additions & 1 deletion GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
global using Il2CppAssets.Scripts.Unity.Audio;
global using Il2CppAssets.Scripts.Simulation.Towers.Behaviors.Abilities;
global using Il2CppAssets.Scripts.Unity.UI_New.InGame.TowerSelectionMenu;
global using Il2CppAssets.Main.Scenes;
global using Il2CppAssets.Scripts.Unity.Scenes;
global using Il2CppAssets.Scripts.Unity.Player;
global using Il2CppAssets.Scripts.Models.Profile;
global using MelonLoader.Utils;
Expand All @@ -31,4 +31,11 @@
global using Il2CppAssets.Scripts.Models.GenericBehaviors;
global using Il2CppAssets.Scripts.Models.Towers.Behaviors.Attack.Behaviors;
global using Il2CppAssets.Scripts.Models.Towers.Projectiles.Behaviors;
global using Il2CppAssets.Scripts.Unity.UI_New.InGame;
global using UnityEngine.SceneManagement;
global using UnityEngine.UI;
global using Il2CppNinjaKiwi.Common;
global using Il2CppInterop.Runtime.Attributes;
global using Il2CppAssets.Scripts.Unity.Bridge;
global using Il2Cpp;
namespace SC2ExpansionLoader{}
124 changes: 124 additions & 0 deletions MiscPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
namespace SC2ExpansionLoader{
public class HarmonyPatches{
[HarmonyPatch(typeof(Btd6Player),"CheckForNewParagonPipEvent")]
public class Btd6PlayerCheckForNewParagonPipEvent_Patch{
[HarmonyPrefix]
public static bool Prefix(){
Log("pip");
return false;
}
}
[HarmonyPatch(typeof(ProfileModel),"Validate")]
public class ProfileModelValidate_Patch{
[HarmonyPostfix]
public static void Postfix(ProfileModel __instance){
Log("profile");
foreach(KeyValuePair<string,SC2Tower>sc2tower in TowerTypes){
try{
SC2Tower tower=sc2tower.Value;
__instance.unlockedTowers.Add(tower.Name);
if(tower.Upgradable){
tower.UpgradeModels=tower.GenerateUpgradeModels();
foreach(UpgradeModel upgrade in tower.UpgradeModels){
__instance.acquiredUpgrades.Add(upgrade.name);
}
}
}catch(Exception error){
Log("Failed to add "+sc2tower.Key+" to unlocked towers or upgrades");
string message=error.Message;
message+="@\n"+error.StackTrace;
Log(message,"error");
}
}
}
}
[HarmonyPatch(typeof(TitleScreen),"Start")]
public class TitleScreenStart_Patch{
[HarmonyPostfix]
public static void Postfix(){
Log("title");
try{
gameModel=Game.instance.model;
LocManager=LocalizationManager.Instance;
//mostly suited for protoss warp things
CreateTowerAttackModel=gameModel.GetTowerFromId("EngineerMonkey-100").behaviors.GetModel<AttackModel>().Clone<AttackModel>();
List<Model>createTowerBehav=CreateTowerAttackModel.behaviors.ToList();
createTowerBehav.Remove(createTowerBehav.First(a=>a.GetIl2CppType().Name=="RotateToTargetModel"));
createTowerBehav.GetModel<RandomPositionModel>().minDistance=70;
createTowerBehav.GetModel<RandomPositionModel>().maxDistance=90;
createTowerBehav.GetModel<RandomPositionModel>().idealDistanceWithinTrack=0;
createTowerBehav.GetModel<RandomPositionModel>().useInverted=false;
CreateTowerAttackModel.behaviors=createTowerBehav.ToArray();
CreateTowerAttackModel.weapons[0].projectile.display=new(){guidRef=""};
CreateTowerAttackModel.weapons[0].projectile.behaviors.GetModel<ArriveAtTargetModel>().expireOnArrival=false;
CreateTowerAttackModel.weapons[0].projectile.behaviors.GetModel<ArriveAtTargetModel>().altSpeed=400;
CreateTowerAttackModel.weapons[0].projectile.behaviors.GetModel<DisplayModel>().delayedReveal=1;
CreateTowerAttackModel.weapons[0].projectile.behaviors.GetModel<DisplayModel>().positionOffset=new(0,0,190);
BlankAbilityModel=gameModel.GetTowerFromId("Quincy 4").Cast<TowerModel>().behaviors.
First(a=>a.GetIl2CppType().Name=="AbilityModel").Clone().Cast<AbilityModel>();
BlankAbilityModel.description="AbilityDescription";
BlankAbilityModel.displayName="AbilityDisplayName";
BlankAbilityModel.name="AbilityName";
List<Model>behaviors=BlankAbilityModel.behaviors.ToList();
behaviors.Remove(behaviors.First(a=>a.GetIl2CppType().Name=="TurboModel"));
behaviors.Remove(behaviors.First(a=>a.GetIl2CppType().Name=="CreateEffectOnAbilityModel"));
behaviors.Remove(behaviors.First(a=>a.GetIl2CppType().Name=="CreateSoundOnAbilityModel"));
BlankAbilityModel.behaviors=behaviors.ToArray();
}catch(Exception error){
Log("Failed to create BlankAbilityModel");
string message=error.Message;
message+="@\n"+error.StackTrace;
Log(message,"error");
}
List<TowerModel>towers=gameModel.towers.ToList();
List<TowerDetailsModel>towerSet=gameModel.towerSet.ToList();
List<UpgradeModel>upgrades=gameModel.upgrades.ToList();
List<string>towerNames=new();
try{
foreach(SC2Tower tower in TowerTypes.Values){
towerNames.Add(tower.Name);
tower.TowerModels=tower.GenerateTowerModels();
tower.UpgradeModels=tower.GenerateUpgradeModels();
foreach(TowerModel towerModel in tower.TowerModels){
towers.Add(towerModel);
}
if(tower.AddToShop){
towerSet.Add(tower.ShopDetails());
}
Log(tower.Name+" "+tower.Upgradable);
if(tower.Upgradable){
foreach(UpgradeModel upgrade in tower.UpgradeModels){
Log(upgrade.name);
upgrades.Add(upgrade);
}
}
gameModel.towers=towers.ToArray();
gameModel.towerSet=towerSet.ToArray();
gameModel.upgrades=upgrades.ToArray();
Log("Loaded "+tower.Name);
}
}catch(Exception error){
Log("Failed to add "+towerNames.Last());
string message=error.Message;
message+="@\n"+error.StackTrace;
Log(message,"error");
}
}
}
/*[HarmonyPatch(typeof(Pet),nameof(Pet.Initialise))]
public class petinit{
[HarmonyPrefix]
public static void Prefix(Model modelToUse){
WanderModel wander=modelToUse.Cast<PetModelUnsynced>().behaviors.First(a=>a.GetIl2CppType().Name=="WanderModel").Cast<WanderModel>();
Log("Name "+wander.name+",idletimemax "+wander.IdleTimeMax+",idletimemin "+wander.IdleTimeMin+",innerradius "+wander.InnerRadius+
",outerradius "+wander.OuterRadius+",speed "+wander.Speed+",startattower "+wander.startAtTower+
",stayinarea "+wander.StayInArea+",usesyncedrandom "+wander.useSyncedRandom);
foreach(var thing in wander.MotionCurve){
Log("intangent "+thing.inTangent+",inweight "+thing.inWeight+",outtangent "+thing.outTangent+",outweight "+thing.outWeight+
",tangentmode "+thing.tangentMode+",tangentmodeinternal "+thing.tangentModeInternal+",time "+thing.time+
",value "+thing.value+",weightedmode "+thing.weightedMode);
}
}
}*/
}
}
2 changes: 1 addition & 1 deletion ModHelperData.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace SC2ExpansionLoader{
public static class ModHelperData{
public const string WorksOnVersion="34.3";
public const string Version="2.4.0";
public const string Version="2.5.0";
public const string Name="SC2ExpansionLoader";
public const string Description="Loader for any SC2Expansion mods, this mod adds nothing by itself. Will be automatically downloaded if required";
public const string RepoOwner = "Onixiya";
Expand Down
7 changes: 6 additions & 1 deletion ModMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class ModMain:MelonMod{
private static MelonLogger.Instance mllog;
public static string BundleDir;
public static AttackModel CreateTowerAttackModel;
public static GameModel gameModel;
public static LocalizationManager LocManager;
public static void Log(object thingtolog,string type="msg"){
switch(type){
case"msg":
Expand Down Expand Up @@ -36,7 +38,10 @@ public override void OnInitializeMelon(){
SC2Tower tower=(SC2Tower)Activator.CreateInstance(type);
if(tower.Name!=""){
TowerTypes.Add(tower.Name,tower);
TowerTypes[tower.Name].LoadedBundle=UnityEngine.AssetBundle.LoadFromFileAsync(BundleDir+tower.Name.ToLower()).assetBundle;
tower.LoadedBundle=UnityEngine.AssetBundle.LoadFromFileAsync(BundleDir+tower.Name.ToLower()).assetBundle;
if(tower.TowerFaction==SC2Tower.Faction.NotSet){
Log(tower.Name+"'s faction not set!","warn");
}
}
}catch{}
}
Expand Down
Loading

0 comments on commit 09145dd

Please sign in to comment.