-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix for v35, custom upgrade menu, split patches up and methods for up…
…grademodels and towermodels
- Loading branch information
silentstorm
committed
Feb 16, 2023
1 parent
f86622c
commit 09145dd
Showing
14 changed files
with
623 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
bin | ||
obj | ||
.vscode | ||
.vscode | ||
SC2ExpansionProject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
}*/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.