Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.41 KB | None | 0 0
  1. state("Croc2", "US")
  2. {
  3.     int CurTribe            : 0xA8C44;
  4.     int CurLevel            : 0xA8C48;
  5.     int CurMap              : 0xA8C4C;
  6.     int CurType             : 0xA8C50;
  7.     int InGameState         : 0xB7880;
  8.     int IsCheatMenuOpen     : 0xB788C;
  9.     bool IsMapLoaded        : 0xB78C4;
  10.     int NewMainState        : 0xB7930;
  11.     int IsNewMainStateValid : 0xB7934;
  12.     int MainState           : 0xB793C;
  13.     uint DFCrystal5PosX     : 0x223D30;
  14.     uint DFCrystal5PosY     : 0x223D34;
  15.     uint DFCrystal5PosZ     : 0x223D38;
  16. }
  17.  
  18. state("Croc2", "EU")
  19. {
  20.     int CurTribe            : 0xA9C44;
  21.     int CurLevel            : 0xA9C48;
  22.     int CurMap              : 0xA9C4C;
  23.     int CurType             : 0xA9C50;
  24.     int InGameState         : 0xBEA70;
  25.     int IsCheatMenuOpen     : 0xBEA7C;
  26.     bool IsMapLoaded        : 0xBEAB4;
  27.     int NewMainState        : 0xBEB20;
  28.     int IsNewMainStateValid : 0xBEB24;
  29.     int MainState           : 0xBEB2C;
  30.     uint DFCrystal5PosX     : 0x22AF20;
  31.     uint DFCrystal5PosY     : 0x22AF24;
  32.     uint DFCrystal5PosZ     : 0x22AF28;
  33. }
  34.  
  35. startup
  36. {
  37.     settings.Add("SplitOnMapChange", false,
  38.         "Split on map change");
  39.     settings.Add("StartOnFirstLevel", false,
  40.         "IL start");
  41.     settings.Add("StartOnHubCheat", false,
  42.         "IW start");
  43.     settings.Add("StartAfterSaveSlotChosen", false,
  44.         "Save slot start");
  45.        
  46.     settings.Add("createui", false, "Last IL time");
  47.  
  48.     // Returns true iff map is "Swap Meet Pete's General Store"
  49.     vars.IsShopMap = new Func<dynamic, bool>(state =>
  50.         state.CurTribe >= 1 && state.CurTribe <= 4 &&
  51.         state.CurLevel == 1 && state.CurMap == 4 && state.CurType == 0);
  52.    
  53.     vars.SetTextComponent = (Action<string, string, bool>)((id, text, create) => {
  54.         var textSettings = timer.Layout.Components.Where(x => x.GetType().Name == "TextComponent").Select(x => x.GetType().GetProperty("Settings").GetValue(x, null));
  55.         var textSetting = textSettings.FirstOrDefault(x => (x.GetType().GetProperty("Text1").GetValue(x, null) as string) == id);
  56.         if (textSetting == null && create)
  57.         {
  58.             var textComponentAssembly = Assembly.LoadFrom("Components\\LiveSplit.Text.dll");
  59.             var textComponent = Activator.CreateInstance(textComponentAssembly.GetType("LiveSplit.UI.Components.TextComponent"), timer);
  60.             timer.Layout.LayoutComponents.Add(new LiveSplit.UI.Components.LayoutComponent("LiveSplit.Text.dll", textComponent as LiveSplit.UI.Components.IComponent));
  61.            
  62.             textSetting = textComponent.GetType().GetProperty("Settings", BindingFlags.Instance | BindingFlags.Public).GetValue(textComponent, null);
  63.             textSetting.GetType().GetProperty("Text1").SetValue(textSetting, id);
  64.         }
  65.        
  66.         if (textSetting != null)
  67.             textSetting.GetType().GetProperty("Text2").SetValue(textSetting, text);
  68.     });
  69. }
  70.  
  71. init
  72. {
  73.     var firstModule = modules.First();
  74.     var baseAddr = firstModule.BaseAddress;
  75.     switch (firstModule.ModuleMemorySize)
  76.     {
  77.         case 0x23A000:
  78.             version = "US";
  79.             vars.AddrSaveSlots      = baseAddr + 0x2040C0;
  80.             vars.AddrCurSaveSlotIdx = baseAddr + 0x2220FC;
  81.             break;
  82.         case 0x242000:
  83.             version = "EU";
  84.             vars.AddrSaveSlots      = baseAddr + 0x20B2B0;
  85.             vars.AddrCurSaveSlotIdx = baseAddr + 0x2292EC;
  86.             break;
  87.     }
  88.    
  89.     vars.TimeAtLoad = new TimeSpan();
  90.     vars.LastILTime = new TimeSpan();
  91.     vars.LastILTimeOld = new TimeSpan();
  92.     vars.FinalFormat = "-";
  93.     vars.SetTextComponent("Last IL time", "-", settings["createui"]);
  94. }
  95.  
  96. update
  97. {
  98.     if ((old.CurTribe != current.CurTribe ||
  99.         old.CurLevel != current.CurLevel ||
  100.         old.CurMap   != current.CurMap   ||
  101.         old.CurType  != current.CurType) &&
  102.         !vars.IsShopMap(old) && !vars.IsShopMap(current))
  103.     {
  104.         vars.TimeAtLoad = timer.CurrentTime.GameTime;
  105.     }
  106.    
  107.     vars.TotalMs = new int();
  108.    
  109.     if (vars.LastILTime != null)
  110.     {
  111.         vars.TotalMs = vars.LastILTime.TotalMilliseconds;
  112.     }
  113.    
  114.     if (vars.TotalMs != 0 && (vars.LastILTimeOld != vars.LastILTime))
  115.     {
  116.         vars.Msec1 = new int();
  117.         vars.Msec10 = new int();
  118.         vars.Msec100 = new int();
  119.         vars.Sec1 = new int();
  120.         vars.Sec10 = new int();
  121.         vars.Min = new int();      
  122.        
  123.         vars.Msec1 = vars.TotalMs % 10;
  124.         vars.TotalMs -= vars.Msec1;
  125.        
  126.         vars.Msec10 = vars.TotalMs % 100;
  127.         vars.TotalMs -= vars.Msec10;
  128.         vars.Msec10 /= 10;
  129.        
  130.         vars.Msec100 = vars.TotalMs % 1000;
  131.         vars.TotalMs -= vars.Msec100;
  132.         vars.Msec100 /= 100;
  133.        
  134.         vars.TotalMs /= 1000;
  135.         vars.Sec1 = (vars.TotalMs % 60) % 10;
  136.         vars.TotalMs -= vars.Sec1;
  137.        
  138.         vars.Sec10 = vars.TotalMs % 60;
  139.         vars.TotalMs -= vars.Sec10;
  140.         vars.Sec10 /= 10;
  141.        
  142.         vars.Min = vars.TotalMs / 60;
  143.        
  144.         vars.FinalFormat =  vars.Min +
  145.                             ":" +
  146.                             vars.Sec10 +
  147.                             vars.Sec1 +
  148.                             "." +
  149.                             vars.Msec100 +
  150.                             vars.Msec10 +
  151.                             vars.Msec1;
  152.                            
  153.         vars.LastILTimeOld = vars.LastILTime;
  154.     }
  155.  
  156.     vars.SetTextComponent("Last IL time", vars.FinalFormat, settings["createui"]);
  157.    
  158.     return version != "";
  159. }
  160.  
  161. start
  162. {
  163.     const int MainState_ChooseSaveSlot =  2;
  164.     const int MainState_Running        = 11;
  165.     const int MainState_LevelSelect    = 18;
  166.  
  167.     // Start when main state is in transition from
  168.     // "level select" or "save slot selection" to "running"
  169.     if (settings["StartAfterSaveSlotChosen"] && (
  170.         current.MainState == MainState_ChooseSaveSlot ||
  171.         current.MainState == MainState_LevelSelect) &&
  172.         current.IsNewMainStateValid != 0 &&
  173.         current.NewMainState == MainState_Running)
  174.     {
  175.         return true;
  176.     }
  177.  
  178.     // The following start condition checks assume the game is running
  179.     // and the current map is an ingame tribe and not a cutscene
  180.     if (current.MainState != MainState_Running ||
  181.         current.CurTribe < 1 || current.CurTribe > 5 || current.CurType == 3)
  182.     {
  183.         return false;
  184.     }
  185.  
  186.     if (settings["StartOnFirstLevel"] && (
  187.         // Current map is a non-village map of Dante's World
  188.         // or a non-village level of the Gobbo tribes
  189.         current.CurTribe == 5 ? current.CurMap > 1 : current.CurLevel > 1))
  190.     {
  191.         return true;
  192.     }
  193.  
  194.     if (settings["StartOnHubCheat"] &&
  195.         // Cheat menu is open while loading a new map
  196.         current.IsCheatMenuOpen != 0 && current.InGameState == 7)
  197.     {
  198.         return true;
  199.     }
  200.    
  201.     vars.TimeAtLoad = timer.CurrentTime.GameTime;
  202.     vars.LastILTime = timer.CurrentTime.GameTime;
  203.     vars.LastILTimeOld = timer.CurrentTime.GameTime;
  204.     vars.FinalFormat = "-";
  205.     vars.SetTextComponent("Last IL time", "-", settings["createui"]);
  206. }
  207.  
  208. split
  209. {
  210.     // Cancel if main state is not "running" or
  211.     // current tribe is not an ingame tribe
  212.     const int MainState_Running = 11;
  213.     if (current.MainState != MainState_Running ||
  214.         current.CurTribe < 1 || current.CurTribe > 5)
  215.     {
  216.         ((IDictionary<string, object>)current).Remove("ProgressList");
  217.         return false;
  218.     }
  219.  
  220.     // Read progress list
  221.     const int SaveSlotSize = 0x2000;
  222.     var addrSaveSlot = vars.AddrSaveSlots +
  223.         memory.ReadValue<int>((IntPtr)vars.AddrCurSaveSlotIdx) * SaveSlotSize;
  224.     current.ProgressList = memory.ReadBytes((IntPtr)addrSaveSlot + 0x2d0, 0xf0);
  225.  
  226.     // Cancel if old progress list is not available
  227.     if (!((IDictionary<string, object>)old).ContainsKey("ProgressList")) return false;
  228.  
  229.     // "Dante's Final Fight": Split when last crystal is placed
  230.     if (current.CurTribe == 4 && current.CurLevel == 2 &&
  231.         current.CurMap == 1 && current.CurType == 1 && (
  232.             old.DFCrystal5PosX != current.DFCrystal5PosX ||
  233.             old.DFCrystal5PosY != current.DFCrystal5PosY ||
  234.             old.DFCrystal5PosZ != current.DFCrystal5PosZ) &&
  235.         current.DFCrystal5PosX == 0x00004358 &&
  236.         current.DFCrystal5PosY == 0x0000315b &&
  237.         current.DFCrystal5PosZ == 0x00004d53)
  238.     {
  239.         vars.LastILTime = timer.CurrentTime.GameTime - vars.TimeAtLoad;
  240.         return true;
  241.     }
  242.  
  243.     // Check whether progress has changed
  244.     for (int tribe = 1; tribe <= 5; ++tribe)
  245.     {
  246.         // Level completed?
  247.         for (int level = 2; level <= 7; ++level)
  248.         {
  249.             int index = (tribe * 10 + level) * 4;
  250.             if (old.ProgressList[index] != current.ProgressList[index])
  251.             {
  252.                 vars.LastILTime = timer.CurrentTime.GameTime - vars.TimeAtLoad;
  253.                 return true;
  254.             }
  255.         }
  256.         // Boss defeated?
  257.         for (int boss = 1; boss <= 2; ++boss)
  258.         {
  259.             int index = (tribe * 10 + boss) * 4 + 1;
  260.             if (old.ProgressList[index] != current.ProgressList[index])
  261.             {
  262.                 vars.LastILTime = timer.CurrentTime.GameTime - vars.TimeAtLoad;
  263.                 return true;
  264.             }
  265.         }
  266.     }
  267.  
  268.     // Split on map change (except when changing from or to shop map)
  269.     if (settings["SplitOnMapChange"] && (
  270.         old.CurTribe != current.CurTribe ||
  271.         old.CurLevel != current.CurLevel ||
  272.         old.CurMap   != current.CurMap   ||
  273.         old.CurType  != current.CurType) &&
  274.         !vars.IsShopMap(old) && !vars.IsShopMap(current))
  275.     {
  276.         return true;
  277.     }
  278. }
  279.  
  280. isLoading
  281. {
  282.     return !current.IsMapLoaded;
  283. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement