-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ClonkAndre/dev
Move dev into main
- Loading branch information
Showing
13 changed files
with
2,887 additions
and
426 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,11 +1,22 @@ | ||
A simple traffic loader for GTA IV. | ||
# Simple Traffic Loader | ||
This is a simple traffic loader for GTA IV which aims to eliminate the famous taxi bug while also delivering some extra features. | ||
|
||
[Download Version 1.1 here](https://www.gtainside.com/gta4/mods/157022-simple-traffic-loader/) | ||
## Features | ||
- Custom vehicle loading groups. | ||
- Manual and automatic vehicle budget overrider. | ||
|
||
Feel free to contribute to this traffic loader. | ||
## Requirements | ||
- [IV-SDK .NET](https://github.com/ClonkAndre/IV-SDK-DotNet) | ||
- [ClonksCodingLib.GTAIV](https://github.com/ClonkAndre/ClonksCodingLib.GTAIV) | ||
|
||
## Other Links | ||
GTAForums: TODO | ||
GTAInside (ONLY OLD VERSION FOR NOW): TODO | ||
LCPDFR.com (ONLY OLD VERSION FOR NOW): TODO | ||
|
||
## How to Contribute | ||
⚠ This project was built using a private SDK. | ||
If you want to contribute on this project, it is recommended to use the Open-Source [IV-SDK](https://github.com/Zolika1351/iv-sdk). | ||
⚠ The 1.0 and 1.1 versions were built using a private SDK. | ||
If you want to work on those versions, it is recommended to use the Open-Source [IV-SDK](https://github.com/Zolika1351/iv-sdk). | ||
|
||
Do you have an idea to improve this mod, or did you happen to run into a bug? Please share your idea or the bug you found in the [issues](https://github.com/ClonkAndre/Simple-Traffic-Loader/issues) page, or even better: feel free to fork and contribute to this project with a [Pull Request](https://github.com/ClonkAndre/Simple-Traffic-Loader/pulls). | ||
|
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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.9.34728.123 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleTrafficLoader", "SimpleTrafficLoader\SimpleTrafficLoader.csproj", "{21A832B6-31FF-4483-9727-6C26632097F3}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{21A832B6-31FF-4483-9727-6C26632097F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{21A832B6-31FF-4483-9727-6C26632097F3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{21A832B6-31FF-4483-9727-6C26632097F3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{21A832B6-31FF-4483-9727-6C26632097F3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {549C0F41-A248-49CF-B404-F7E33E940461} | ||
EndGlobalSection | ||
EndGlobal |
36 changes: 36 additions & 0 deletions
36
SimpleTrafficLoader/SimpleTrafficLoader/Classes/Logging.cs
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,36 @@ | ||
using IVSDKDotNet; | ||
|
||
namespace SimpleTrafficLoader.Classes | ||
{ | ||
internal class Logging | ||
{ | ||
|
||
#if DEBUG | ||
public static bool EnableDebugLogging = true; | ||
#else | ||
public static bool EnableDebugLogging = false; | ||
#endif | ||
|
||
public static void Log(string str, params object[] args) | ||
{ | ||
IVGame.Console.Print(string.Format("[SimpleTrafficLoader] {0}", string.Format(str, args))); | ||
} | ||
public static void LogWarning(string str, params object[] args) | ||
{ | ||
IVGame.Console.PrintWarning(string.Format("[SimpleTrafficLoader] {0}", string.Format(str, args))); | ||
} | ||
public static void LogError(string str, params object[] args) | ||
{ | ||
IVGame.Console.PrintError(string.Format("[SimpleTrafficLoader] {0}", string.Format(str, args))); | ||
} | ||
|
||
public static void LogDebug(string str, params object[] args) | ||
{ | ||
#if DEBUG | ||
if (EnableDebugLogging) | ||
IVGame.Console.Print(string.Format("[SimpleTrafficLoader] [DEBUG] {0}", string.Format(str, args))); | ||
#endif | ||
} | ||
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
SimpleTrafficLoader/SimpleTrafficLoader/Classes/ModSettings.cs
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,36 @@ | ||
using IVSDKDotNet; | ||
using IVSDKDotNet.Attributes; | ||
|
||
namespace SimpleTrafficLoader | ||
{ | ||
[ShowStaticFieldsInInspector()] | ||
internal class ModSettings | ||
{ | ||
|
||
#region Variables | ||
// General | ||
public static bool UnloadAllGroupsWhenModUnloads; | ||
public static int MaxLoadedGroups; | ||
public static string LoadGroupByDefault; | ||
public static bool ForceLoadModels; | ||
|
||
// Budget | ||
public static bool AutomaticallyDetermineVehicleBudget; | ||
public static uint VehicleBudgetOverride; | ||
#endregion | ||
|
||
public static void Load(SettingsFile settings) | ||
{ | ||
// General | ||
UnloadAllGroupsWhenModUnloads = settings.GetBoolean("General", "UnloadAllGroupsWhenModUnloads", true); | ||
MaxLoadedGroups = settings.GetInteger("General", "MaxLoadedGroups", 5); | ||
LoadGroupByDefault = settings.GetValue("General", "LoadGroup", "Default.json"); | ||
ForceLoadModels = settings.GetBoolean("General", "ForceLoadModels", false); | ||
|
||
// Budget | ||
AutomaticallyDetermineVehicleBudget = settings.GetBoolean("Budget", "AutomaticallyDetermineVehicleBudget", true); | ||
uint.TryParse(settings.GetValue("Budget", "VehicleBudgetOverride", "0"), out VehicleBudgetOverride); | ||
} | ||
|
||
} | ||
} |
176 changes: 176 additions & 0 deletions
176
SimpleTrafficLoader/SimpleTrafficLoader/Classes/SpawnGroup.cs
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,176 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using CCL.GTAIV; | ||
|
||
using IVSDKDotNet; | ||
using IVSDKDotNet.Attributes; | ||
using static IVSDKDotNet.Native.Natives; | ||
|
||
namespace SimpleTrafficLoader.Classes | ||
{ | ||
internal class SpawnGroup | ||
{ | ||
|
||
#region Variables | ||
// Details | ||
[ExcludeFromJsonSerialization()] internal Guid ID; | ||
public string GroupName; | ||
[ExcludeFromJsonSerialization()] internal string GroupNameEdit; | ||
|
||
// Control | ||
public bool Disabled; | ||
[ExcludeFromJsonSerialization()] internal bool IsGroupActive; | ||
[ExcludeFromJsonSerialization()] internal bool WasUnloadRequested; | ||
|
||
// Lists | ||
public List<string> TargetIslands; | ||
public List<string> TargetNeighborhoods; | ||
public List<string> ModelsToLoad; | ||
public List<string> LoadPolicies; | ||
[ExcludeFromJsonSerialization()] private List<NativeModel> theNativeModels; | ||
#endregion | ||
|
||
#region Constructor | ||
public SpawnGroup() | ||
{ | ||
// Generate random ID for this group | ||
ID = Guid.NewGuid(); | ||
|
||
// Lists | ||
theNativeModels = new List<NativeModel>(); | ||
} | ||
#endregion | ||
|
||
#region Methods | ||
public void Prepare() | ||
{ | ||
// Generate random ID for this group | ||
if (ID == Guid.Empty) | ||
ID = Guid.NewGuid(); | ||
|
||
GroupNameEdit = GroupName; | ||
|
||
// Check and add models that should be loaded in a seperate list | ||
theNativeModels.Clear(); | ||
|
||
for (int i = 0; i < ModelsToLoad.Count; i++) | ||
{ | ||
string model = ModelsToLoad[i]; | ||
|
||
int modelHash = 0; | ||
|
||
// Check if model name was given or the model hash | ||
if (!int.TryParse(model, out modelHash)) | ||
{ | ||
modelHash = (int)RAGE.AtStringHash(model); | ||
} | ||
|
||
// Check stuff | ||
if (modelHash == 0) | ||
continue; | ||
if (!IS_MODEL_IN_CDIMAGE(modelHash)) | ||
continue; | ||
|
||
// Add model to list | ||
theNativeModels.Add(new NativeModel(modelHash)); | ||
} | ||
} | ||
|
||
public void LoadModels() | ||
{ | ||
if (!CanDoStuff()) | ||
return; | ||
|
||
// If group is unloading then prevent any models of this group from loading | ||
if (WasUnloadRequested) | ||
return; | ||
|
||
// If models are already loaded then return | ||
if (AreAllModelsLoaded()) | ||
return; | ||
|
||
Logging.LogDebug("- - - About to LOAD models of group '{0}'! - - -", GroupName); | ||
|
||
// Load models | ||
for (int i = 0; i < theNativeModels.Count; i++) | ||
{ | ||
NativeModel model = theNativeModels[i]; | ||
|
||
// If model is already loaded then skip | ||
if (model.IsInMemory) | ||
continue; | ||
|
||
// Get model hash | ||
int modelHash = (int)model.Hash; | ||
|
||
// Request/Load this model | ||
if (!ModSettings.ForceLoadModels) | ||
{ | ||
// Load models one-by-one | ||
IVStreaming.ScriptRequestModel(modelHash); | ||
IVStreaming.LoadAllRequestedModels(false); | ||
return; | ||
} | ||
else | ||
{ | ||
// Request model to be loaded instantly | ||
IVStreaming.ScriptRequestModel(modelHash); | ||
} | ||
} | ||
|
||
// Load all requested models instantly | ||
IVStreaming.LoadAllRequestedModels(false); | ||
} | ||
public void UnloadModels() | ||
{ | ||
if (!CanDoStuff()) | ||
return; | ||
|
||
// If models are already unloaded then return | ||
if (!AreAllModelsLoaded()) | ||
return; | ||
|
||
// If unload was already requested then return | ||
if (WasUnloadRequested) | ||
return; | ||
|
||
WasUnloadRequested = true; | ||
|
||
Logging.LogDebug("- - - About to UNLOAD group '{0}'! - - -", GroupName); | ||
|
||
// Mark loaded models as no longer needed | ||
// This might take a few seconds for them to actually get unloaded | ||
for (int i = 0; i < theNativeModels.Count; i++) | ||
{ | ||
NativeModel model = theNativeModels[i]; | ||
|
||
// If model is already unloaded then skip | ||
if (!model.IsInMemory) | ||
continue; | ||
|
||
model.MarkAsNoLongerNeeded(); | ||
} | ||
|
||
IsGroupActive = false; | ||
WasUnloadRequested = false; | ||
} | ||
#endregion | ||
|
||
#region Functions | ||
public bool AreAllModelsLoaded() | ||
{ | ||
if (theNativeModels.Count == 0) | ||
return false; | ||
|
||
return theNativeModels.All(x => x.IsInMemory); | ||
} | ||
public bool CanDoStuff() | ||
{ | ||
return IsGroupActive && theNativeModels.Count != 0; | ||
} | ||
#endregion | ||
|
||
} | ||
} |
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,14 @@ | ||
namespace SimpleTrafficLoader | ||
{ | ||
|
||
public enum Island | ||
{ | ||
Unknown, | ||
Alderney, | ||
Algonquin, | ||
Bohan, | ||
Dukes, | ||
Broker | ||
} | ||
|
||
} |
Oops, something went wrong.