Skip to content

Commit

Permalink
Merge branch 'simulator'
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyDuchess committed May 13, 2024
2 parents a0f24ee + 88c94be commit cb98f4e
Show file tree
Hide file tree
Showing 37 changed files with 928 additions and 72 deletions.
45 changes: 45 additions & 0 deletions Assets/Scenes/Neighborhood.unity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Scenes/Startup.unity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 42 additions & 39 deletions Assets/Scripts/OpenTS2/Content/DBPF/ObjectDefinitionAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ObjectDefinitionAsset : AbstractAsset
{
// TODO: Person and Template object types seem to use 0x80 as the SG instance id for some reason.
public SemiGlobalAsset SemiGlobal => ContentProvider.Get().GetAsset<SemiGlobalAsset>(new ResourceKey(1, GlobalTGI.GroupID, TypeIDs.SEMIGLOBAL));
public ObjectFunctionsAsset Functions => ContentProvider.Get().GetAsset<ObjectFunctionsAsset>(new ResourceKey(GlobalTGI.InstanceID, GlobalTGI.GroupID, TypeIDs.OBJF));
public string FileName;

public enum FieldNames
Expand Down Expand Up @@ -58,7 +59,7 @@ public enum FieldNames
RoomSortflags,
FunctionSortFlags,
CatalogStringsIDPointer,
IsGlobalSimObj,
GlobalSimObject,
ToolTipNameType,
TemplateVer,
NicenessMultiplier,
Expand All @@ -73,15 +74,15 @@ public enum FieldNames
CatalogPopupID,
IgnoreCurrentModelIndexInIcons,
LevelOffset,
HasShadow,
ShadowType,
NumAttributes,
NumObjArrays,
unused1,
ForSaleFlags,
FrontDirection,
unused2,
MultiTileLeadObj,
ExpansionFlag,
unused3,
MultiTileLeadObject,
ValidEPFlags1,
ValidEPFlags2,
ChairEntryFlags,
TileWidth,
InhibitSuitCopying,
Expand All @@ -91,41 +92,43 @@ public enum FieldNames
ObjModelGUID1,
ObjModelGUID2,
BuildModeSubsort,
unused4,
unused5,
SelectorCategory,
SelectorSubCategory,
FootprintMask,
unused6,
unused7,
ExtendFootprint,
ObjectSize,
unused8,
unused9,
HungerRating,
ComfortRating,
HygieneRating,
BladderRating,
EnergyRating,
FunRating,
RoomRating,
SkillFlags,
RatingHunger,
RatingComfort,
RatingHygiene,
RatingBladder,
RatingEnergy,
RatingFun,
RatingRoom,
RatingSkillFlags,
NumTypeAttributes,
MiscFlags,
unused10,
unused11,
FunctionPointerSubSortAndSubtype,
FunctionSubSort,
DowntownSort,
KeepBuying,
VacationSort,
ResetLotAction,
ObjType3d,
ObjType3D,
CommunitySort,
DreamFlags,
/// <summary>
/// Just indicates the number of fields in the OBJD field array. Don't use for get/set.
/// </summary>
FIELD_COUNT
ThumbnailFlags,
Unused103,
Unused104,
Unused105,
Unused106,
Unused107,
}

// Makes fields a lot easier to serialize and deserialize, and also to set and get from the VM.
public ushort[] Fields = new ushort[(int)FieldNames.FIELD_COUNT];
public ushort[] Fields = new ushort[108];

private ushort this[FieldNames fieldName]
{
Expand Down Expand Up @@ -239,7 +242,7 @@ public uint ObjectModelGUID
public ushort RoomSortflags { get { return this[FieldNames.RoomSortflags]; } set { this[FieldNames.RoomSortflags] = value; } }
public ushort FunctionSortFlags { get { return this[FieldNames.AspirationFlags]; } set { this[FieldNames.FunctionSortFlags] = value; } }
public ushort CatalogStringsIDPointer { get { return this[FieldNames.CatalogStringsIDPointer]; } set { this[FieldNames.CatalogStringsIDPointer] = value; } }
public ushort IsGlobalSimObj { get { return this[FieldNames.IsGlobalSimObj]; } set { this[FieldNames.IsGlobalSimObj] = value; } }
public ushort GlobalSimObject { get { return this[FieldNames.GlobalSimObject]; } set { this[FieldNames.GlobalSimObject] = value; } }
public ushort ToolTipNameType { get { return this[FieldNames.ToolTipNameType]; } set { this[FieldNames.ToolTipNameType] = value; } }
public ushort TemplateVer { get { return this[FieldNames.TemplateVer]; } set { this[FieldNames.TemplateVer] = value; } }
public ushort NicenessMultiplier { get { return this[FieldNames.NicenessMultiplier]; } set { this[FieldNames.NicenessMultiplier] = value; } }
Expand All @@ -252,34 +255,34 @@ public uint ObjectModelGUID
public ushort CatalogPopupID { get { return this[FieldNames.CatalogPopupID]; } set { this[FieldNames.CatalogPopupID] = value; } }
public ushort IgnoreCurrentModelIndexInIcons { get { return this[FieldNames.IgnoreCurrentModelIndexInIcons]; } set { this[FieldNames.IgnoreCurrentModelIndexInIcons] = value; } }
public ushort LevelOffset { get { return this[FieldNames.LevelOffset]; } set { this[FieldNames.LevelOffset] = value; } }
public ushort HasShadow { get { return this[FieldNames.HasShadow]; } set { this[FieldNames.HasShadow] = value; } }
public ushort ShadowType { get { return this[FieldNames.ShadowType]; } set { this[FieldNames.ShadowType] = value; } }
public ushort NumAttributes { get { return this[FieldNames.NumAttributes]; } set { this[FieldNames.NumAttributes] = value; } }
public ushort NumObjArrays { get { return this[FieldNames.NumObjArrays]; } set { this[FieldNames.NumObjArrays] = value; } }
public ushort FrontDirection { get { return this[FieldNames.FrontDirection]; } set { this[FieldNames.FrontDirection] = value; } }
public ushort MultiTileLeadObj { get { return this[FieldNames.MultiTileLeadObj]; } set { this[FieldNames.MultiTileLeadObj] = value; } }
public ushort ExpansionFlag { get { return this[FieldNames.ExpansionFlag]; } set { this[FieldNames.ExpansionFlag] = value; } }
public ushort MultiTileLeadObject { get { return this[FieldNames.MultiTileLeadObject]; } set { this[FieldNames.MultiTileLeadObject] = value; } }
public ushort ValidEPFlags1 { get { return this[FieldNames.ValidEPFlags1]; } set { this[FieldNames.ValidEPFlags1] = value; } }
public ushort ChairEntryFlags { get { return this[FieldNames.ChairEntryFlags]; } set { this[FieldNames.ChairEntryFlags] = value; } }
public ushort TileWidth { get { return this[FieldNames.TileWidth]; } set { this[FieldNames.TileWidth] = value; } }
public ushort InhibitSuitCopying { get { return this[FieldNames.InhibitSuitCopying]; } set { this[FieldNames.InhibitSuitCopying] = value; } }
public ushort BuildModeType { get { return this[FieldNames.BuildModeType]; } set { this[FieldNames.BuildModeType] = value; } }
public ushort BuildModeSubsort { get { return this[FieldNames.BuildModeSubsort]; } set { this[FieldNames.BuildModeSubsort] = value; } }
public ushort FootprintMask { get { return this[FieldNames.FootprintMask]; } set { this[FieldNames.FootprintMask] = value; } }
public ushort HungerRating { get { return this[FieldNames.HungerRating]; } set { this[FieldNames.HungerRating] = value; } }
public ushort ComfortRating { get { return this[FieldNames.ComfortRating]; } set { this[FieldNames.ComfortRating] = value; } }
public ushort HygieneRating { get { return this[FieldNames.HygieneRating]; } set { this[FieldNames.HygieneRating] = value; } }
public ushort BladderRating { get { return this[FieldNames.BladderRating]; } set { this[FieldNames.BladderRating] = value; } }
public ushort EnergyRating { get { return this[FieldNames.EnergyRating]; } set { this[FieldNames.EnergyRating] = value; } }
public ushort FunRating { get { return this[FieldNames.FunRating]; } set { this[FieldNames.FunRating] = value; } }
public ushort RoomRating { get { return this[FieldNames.RoomRating]; } set { this[FieldNames.RoomRating] = value; } }
public ushort SkillFlags { get { return this[FieldNames.SkillFlags]; } set { this[FieldNames.SkillFlags] = value; } }
public ushort RatingHunger { get { return this[FieldNames.RatingHunger]; } set { this[FieldNames.RatingHunger] = value; } }
public ushort RatingComfort { get { return this[FieldNames.RatingComfort]; } set { this[FieldNames.RatingComfort] = value; } }
public ushort RatingHygiene { get { return this[FieldNames.RatingHygiene]; } set { this[FieldNames.RatingHygiene] = value; } }
public ushort RatingBladder { get { return this[FieldNames.RatingBladder]; } set { this[FieldNames.RatingBladder] = value; } }
public ushort RatingEnergy { get { return this[FieldNames.RatingEnergy]; } set { this[FieldNames.RatingEnergy] = value; } }
public ushort RatingFun { get { return this[FieldNames.RatingFun]; } set { this[FieldNames.RatingFun] = value; } }
public ushort RatingRoom { get { return this[FieldNames.RatingRoom]; } set { this[FieldNames.RatingRoom] = value; } }
public ushort RatingSkillFlags { get { return this[FieldNames.RatingSkillFlags]; } set { this[FieldNames.RatingSkillFlags] = value; } }
public ushort NumTypeAttributes { get { return this[FieldNames.NumTypeAttributes]; } set { this[FieldNames.NumTypeAttributes] = value; } }
public ushort MiscFlags { get { return this[FieldNames.MiscFlags]; } set { this[FieldNames.MiscFlags] = value; } }
public ushort FunctionPointerSubSortAndSubtype { get { return this[FieldNames.FunctionPointerSubSortAndSubtype]; } set { this[FieldNames.FunctionPointerSubSortAndSubtype] = value; } }
public ushort FunctionSubSort { get { return this[FieldNames.FunctionSubSort]; } set { this[FieldNames.FunctionSubSort] = value; } }
public ushort DowntownSort { get { return this[FieldNames.DowntownSort]; } set { this[FieldNames.DowntownSort] = value; } }
public ushort KeepBuying { get { return this[FieldNames.KeepBuying]; } set { this[FieldNames.KeepBuying] = value; } }
public ushort VacationSort { get { return this[FieldNames.VacationSort]; } set { this[FieldNames.VacationSort] = value; } }
public ushort ResetLotAction { get { return this[FieldNames.ResetLotAction]; } set { this[FieldNames.ResetLotAction] = value; } }
public ushort ObjType3d { get { return this[FieldNames.ObjType3d]; } set { this[FieldNames.ObjType3d] = value; } }
public ushort ObjType3D { get { return this[FieldNames.ObjType3D]; } set { this[FieldNames.ObjType3D] = value; } }
public ushort CommunitySort { get { return this[FieldNames.CommunitySort]; } set { this[FieldNames.CommunitySort] = value; } }
public ushort DreamFlags { get { return this[FieldNames.DreamFlags]; } set { this[FieldNames.DreamFlags] = value; } }
}
Expand Down
101 changes: 101 additions & 0 deletions Assets/Scripts/OpenTS2/Content/DBPF/ObjectFunctionsAsset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpenTS2.Content.DBPF
{
public struct ObjectFunction
{
public ushort CheckTree;
public ushort ActionTree;
public static ObjectFunction Default => _default;
private static ObjectFunction _default = new ObjectFunction(0, 0);

public ObjectFunction(ushort actionTree, ushort checkTree)
{
ActionTree = actionTree;
CheckTree = checkTree;
}
}
public class ObjectFunctionsAsset : AbstractAsset
{
public string FileName;

public enum FunctionNames
{
Init,
Main,
Load,
Cleanup,
QueueSkipped,
AllowIntersection,
WallAdjacencyChanged,
RoomChanged,
DynamicMultiTileUpdate,
Placement,
Pickup,
UserPlacement,
UserPickup,
LevelInfoRequest,
ServingSurface,
Portal,
Gardening,
WashHands,
Prep,
Cook,
Surface,
Dispose,
Food,
PickupFromSlot,
WashDish,
EatingSurface,
Sit,
Stand,
Clean,
Repair,
UIEvent,
Restock,
WashClothes,
StartLiveMode,
StopLiveMode,
LinkObjects,
MessageHandler,
PreRoute,
PostRoute,
GoalCheck,
ReactionHandler,
AlongRouteCallback,
Awareness,
Reset,
LookAtTarget,
WalkOver,
UtilityStateChange,
SetModelByType,
GetModelType,
Delete,
UserDelete,
JustMovedIn,
PreventPlaceInSlot,
GlobalAwareness,
ObjectUpdatedByDesignMode
}

public ObjectFunction[] Functions;

public bool HasFunction(FunctionNames function)
{
if ((int)function >= Functions.Length)
return false;
return true;
}

public ObjectFunction GetFunction(FunctionNames function)
{
if (!HasFunction(function))
return ObjectFunction.Default;
return Functions[(int)function];
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/OpenTS2/Content/DBPF/ObjectFunctionsAsset.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Assets/Scripts/OpenTS2/Content/EPManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public int InstalledProducts
}
}

//mask of all products, minus store.
int _installedProducts = 0x3EFFF;
//mask of all products
int _installedProducts = 0x3FFFF;
public EPManager()
{
s_instance = this;
Expand Down
7 changes: 7 additions & 0 deletions Assets/Scripts/OpenTS2/Content/ObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,12 @@ void RegisterObject(ObjectDefinitionAsset objd)
{
_objectByGUID[objd.GUID] = objd;
}

public ObjectDefinitionAsset GetObjectByGUID(uint guid)
{
if (_objectByGUID.TryGetValue(guid, out ObjectDefinitionAsset obj))
return obj;
return null;
}
}
}
1 change: 1 addition & 0 deletions Assets/Scripts/OpenTS2/Files/Formats/DBPF/GroupsTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static class TypeIDs

public const uint LUA_GLOBAL = 0x9012468A;
public const uint LUA_LOCAL = 0x9012468B;
public const uint OBJF = 0x4F424A66;
}
public static class GroupIDs
{
Expand Down
5 changes: 4 additions & 1 deletion Assets/Scripts/OpenTS2/Files/Formats/DBPF/OBJDCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ public override AbstractAsset Deserialize(byte[] bytes, ResourceKey tgi, DBPFFil

reader.Seek(SeekOrigin.Begin, 64);

for(var i=0;i<(int)ObjectDefinitionAsset.FieldNames.FIELD_COUNT;i++)
for(var i=0;i<(int)108;i++)
{
var value = reader.ReadUInt16();
asset.Fields[i] = value;
}

stream.Dispose();
reader.Dispose();

return asset;
}
}
Expand Down
Loading

0 comments on commit cb98f4e

Please sign in to comment.