Commit bf260fc7 authored by Adam Leyshon's avatar Adam Leyshon
Browse files

Unified code base for B19 and 1.0

No need for separate build profiles either.
Changed many methods that were public to internal.
Added new anti-cheat code that detects things spawned in Debug Mode.
Updated translations.
Updated About.xml to support B19 and 1.0
Added code to detect RimWorld version and set API market accordingly.
parent 44592d7e
......@@ -2,7 +2,10 @@
<ModMetaData>
<name>GlitterWorld Prime [1.0]</name>
<author>TwistedSoul / TheCodeCache.NET</author>
<targetVersion>1.0.0</targetVersion>
<supportedVersions>
<li>1.0</li>
<li>0.19</li>
</supportedVersions>
<url>https://www.thecodecache.net</url>
<description>
Build: @SHAHASH@ \n
......
<project outputDir="F:\Code\C#\GlitterWorld Prime\R1\Assemblies\Confused" baseDir="F:\Code\C#\GlitterWorld Prime\R1\Assemblies" xmlns="http://confuser.codeplex.com">
<module path="Glitterworld Prime.dll">
<rule pattern="true" preset="minimum" inherit="false">
<protection id="constants" />
<protection id="anti debug" />
<protection id="anti ildasm" />
<protection id="ref proxy" />
<protection id="ctrl flow" />
</rule>
</module>
<probePath>E:\Games\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed</probePath>
</project>
\ No newline at end of file
......@@ -5,24 +5,16 @@ VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Glitterworld Prime", "Glitterworld Prime\Glitterworld Prime.csproj", "{1976D016-8918-48C9-A54E-4D9EF7F200B7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6D3468B4-EA3F-4886-BF33-142B8436A96F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug B19|Any CPU = Debug B19|Any CPU
Debug R1|Any CPU = Debug R1|Any CPU
Release B19|Any CPU = Release B19|Any CPU
Release R1|Any CPU = Release R1|Any CPU
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Debug B19|Any CPU.ActiveCfg = Debug B19|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Debug B19|Any CPU.Build.0 = Debug B19|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Debug R1|Any CPU.ActiveCfg = Debug R1|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Debug R1|Any CPU.Build.0 = Debug R1|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Release B19|Any CPU.ActiveCfg = Release B19|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Release B19|Any CPU.Build.0 = Release B19|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Release R1|Any CPU.ActiveCfg = Release R1|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Release R1|Any CPU.Build.0 = Release R1|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -9,7 +9,7 @@ namespace Glitterworld_Prime
{
class Building_PrimeUplink : Building
{
public static bool HasUplink(Map map)
internal static bool HasUplink(Map map)
{
var poweredList = new List<Thing>();
var alllist = map.listerThings.ThingsOfDef(DefDatabase<ThingDef>.GetNamed("PrimeUplink"));
......
......@@ -18,12 +18,6 @@ namespace Glitterworld_Prime
{
public class Building_TradeWithPrime : Building_CommsConsole
{
#region Fields
private const string TxtTradeWithTrader = "TradeWithTraderPawn";
#endregion
#region Methods
public override IEnumerable<FloatMenuOption> GetFloatMenuOptions(Pawn myPawn)
......
......@@ -44,7 +44,7 @@ namespace Glitterworld_Prime
_trader = traderPrime;
_mapComponent = Utilities.GetMapComponent(_player.Map);
var t = new Thread(ApiAsync);
var t = new Thread(DoApiCallsAsync);
t.Start();
}
......@@ -148,7 +148,7 @@ namespace Glitterworld_Prime
select t).Sum(t => t.stackCount);
}
private void ApiAsync()
private void DoApiCallsAsync()
{
// Check API Version
if (!GlitterWorldApi.CheckApiVersion())
......
......@@ -28,7 +28,7 @@ namespace Glitterworld_Prime
private readonly ITrader _trader;
private Stopwatch _apiStopwatch;
private string _downloadMessage = "Sending Supported Thing List";
private string _downloadMessage = "GWPSendingThingList".Translate();
private DownloadStatus _previousStatus;
private DownloadStatus _status;
......@@ -52,7 +52,7 @@ namespace Glitterworld_Prime
else
{
// Send supported things
LogWriter.WriteMessage("Sending Supported Thing List");
LogWriter.WriteMessage("Starting request to server");
_apiStopwatch.Start();
GlitterWorldApi.PutItemListAsync(_mapComponent, PutThingsListComplete_Callback);
}
......@@ -94,7 +94,7 @@ namespace Glitterworld_Prime
if (_previousStatus != DownloadStatus.Incomplete)
{
_previousStatus = DownloadStatus.Incomplete;
_downloadMessage = "Sending Supported Thing List";
_downloadMessage = "GWPSendingThingList".Translate();
}
break;
......@@ -104,7 +104,7 @@ namespace Glitterworld_Prime
{
// Now send the mods
_previousStatus = DownloadStatus.DoneSendingSupportedThings;
_downloadMessage = "Sending Supported Mods";
_downloadMessage = "GWPSendingModList".Translate();
_apiStopwatch = new Stopwatch();
LogWriter.WriteMessage("Starting request to server");
_apiStopwatch.Start();
......@@ -118,7 +118,7 @@ namespace Glitterworld_Prime
{
// Download Goods from Server
_previousStatus = DownloadStatus.DoneSendingMods;
_downloadMessage = "Getting Market Data";
_downloadMessage = "GWPGetMarketData".Translate();
_apiStopwatch = new Stopwatch();
LogWriter.WriteMessage("Starting request to server");
_apiStopwatch.Start();
......@@ -153,7 +153,7 @@ namespace Glitterworld_Prime
Widgets.Label(label, _downloadMessage);
}
public void PutThingsListComplete_Callback(IRestResponse response, RestRequestAsyncHandle handle)
private void PutThingsListComplete_Callback(IRestResponse response, RestRequestAsyncHandle handle)
{
LogWriter.WriteMessage(response.ResponseStatus.ToString());
_apiStopwatch.Stop();
......@@ -168,7 +168,7 @@ namespace Glitterworld_Prime
_status = DownloadStatus.DoneSendingSupportedThings;
}
public void PutModListComplete_Callback(IRestResponse response, RestRequestAsyncHandle handle)
private void PutModListComplete_Callback(IRestResponse response, RestRequestAsyncHandle handle)
{
LogWriter.WriteMessage(response.ResponseStatus.ToString());
_apiStopwatch.Stop();
......@@ -183,7 +183,7 @@ namespace Glitterworld_Prime
_status = DownloadStatus.DoneSendingMods;
}
public void DownloadThingsComplete_Callback(IRestResponse<List<GlitterWorldItem>> response,
private void DownloadThingsComplete_Callback(IRestResponse<List<GlitterWorldItem>> response,
RestRequestAsyncHandle handle)
{
LogWriter.WriteMessage(response.ResponseStatus.ToString());
......
......@@ -309,7 +309,7 @@ namespace Glitterworld_Prime
if (Widgets.ButtonText(rect2, _sorter1.LabelCap, true, false, true))
OpenSorterChangeFloatMenu(sorter1Setter);
// Add secondadry sort drop down menu button
// Add secondary sort drop down menu button
var rect3 = new Rect(rect2.xMax + 10f, 0f, 130f, 27f);
if (Widgets.ButtonText(rect3, _sorter2.LabelCap, true, false, true))
OpenSorterChangeFloatMenu(sorter2Setter);
......@@ -402,8 +402,6 @@ namespace Glitterworld_Prime
var allDefsListForReading = DefDatabase<ThingCategoryDef>.AllDefsListForReading;
for (var i = 0; i < allDefsListForReading.Count; i++)
{
var def = allDefsListForReading[i];
if (def.LabelCap.NullOrEmpty())
......
......@@ -29,22 +29,18 @@ namespace Glitterworld_Prime
private static readonly float ClientVersion = 1.0f;
#if LOCALSERVER
private const string BaseUrl = "http://127.0.0.1:5000";
private static readonly string BaseUrl = "http://127.0.0.1:5000";
#else
private const string BaseUrl = "https://prime.thecodecache.net";
private static readonly string BaseUrl = "https://prime.thecodecache.net";
#endif
#if B19
private const string MarketUrl = "m1";
#else
private const string MarketUrl = "m2";
#endif
internal static string MarketUrl { get; set; }
#endregion
#region Methods
public static bool CheckApiVersion()
internal static bool CheckApiVersion()
{
LogWriter.WriteMessage("Getting API Version");
......@@ -78,7 +74,7 @@ namespace Glitterworld_Prime
}
}
public static bool CheckIsOnline()
internal static bool CheckIsOnline()
{
LogWriter.WriteMessage("Getting Server Status");
......@@ -107,7 +103,7 @@ namespace Glitterworld_Prime
}
}
public static void CheckIsOnlineAsync(Action<IRestResponse, RestRequestAsyncHandle> callback)
internal static void CheckIsOnlineAsync(Action<IRestResponse, RestRequestAsyncHandle> callback)
{
LogWriter.WriteMessage("Getting Server Status Async");
var client = CreateRestClient();
......@@ -115,7 +111,7 @@ namespace Glitterworld_Prime
client.ExecuteAsyncGet(request, callback, "GET");
}
public static bool CheckMaintenanceWindow()
internal static bool CheckMaintenanceWindow()
{
LogWriter.WriteMessage("Getting Maintenance Window");
......@@ -147,7 +143,7 @@ namespace Glitterworld_Prime
}
}
public static void CheckResponseForErrors(IRestResponse response)
internal static void CheckResponseForErrors(IRestResponse response)
{
LogWriter.WriteMessage("HTTP Status: " + response.StatusCode);
......@@ -156,7 +152,7 @@ namespace Glitterworld_Prime
LogWriter.DumpObjectToLog(response);
}
public static void GetServerGoodsAsync(GlitterWorld_MapComponent mapComponent,
internal static void GetServerGoodsAsync(GlitterWorld_MapComponent mapComponent,
Action<IRestResponse<List<GlitterWorldItem>>, RestRequestAsyncHandle> callback)
{
LogWriter.WriteMessage("Getting Market Data");
......@@ -168,7 +164,7 @@ namespace Glitterworld_Prime
callback, "GET");
}
public static GlitterWorldSubscriptionMetadata GetSubscriptionData(Map map)
internal static GlitterWorldSubscriptionMetadata GetSubscriptionData(Map map)
{
LogWriter.WriteMessage("Checking Subscription.");
......@@ -185,7 +181,7 @@ namespace Glitterworld_Prime
return null;
}
public static bool PlaceOrder(string colonyId, int currentTick, List<GlitterWorldOrderItem> thingsSold,
internal static bool PlaceOrder(string colonyId, int currentTick, List<GlitterWorldOrderItem> thingsSold,
List<GlitterWorldOrderItem> thingsOnOrder)
{
LogWriter.WriteMessage("Placing Order");
......@@ -210,7 +206,7 @@ namespace Glitterworld_Prime
return response.StatusCode == HttpStatusCode.OK;
}
public static void GetOrdersAsync(string colonyId, int currentTick,
internal static void GetOrdersAsync(string colonyId, int currentTick,
Action<IRestResponse<GlitterWorldPlacedOrders>, RestRequestAsyncHandle> callback)
{
LogWriter.WriteMessage("Begin list of placed orders");
......@@ -222,7 +218,7 @@ namespace Glitterworld_Prime
client.ExecuteAsyncGet(request, callback, "GET");
}
public static bool UpdateOrderStatus(string colonyId, string orderId, string status)
internal static bool UpdateOrderStatus(string colonyId, string orderId, string status)
{
LogWriter.WriteMessage($"Marking order {orderId} as {status}.");
......@@ -246,7 +242,7 @@ namespace Glitterworld_Prime
return false;
}
public static RestRequestAsyncHandle UpdateOrderStatusAsync(string colonyId, string orderId, string status,
internal static RestRequestAsyncHandle UpdateOrderStatusAsync(string colonyId, string orderId, string status,
Action<IRestResponse, RestRequestAsyncHandle> callback)
{
LogWriter.WriteMessage($"Marking order {orderId} as {status}.");
......@@ -266,8 +262,7 @@ namespace Glitterworld_Prime
return client.ExecuteAsyncPost(request, callback, "POST");
}
public static GlitterWorldDeliveryMetaData GetDeliveryMetaData(string colonyId, string orderId)
internal static GlitterWorldDeliveryMetaData GetDeliveryMetaData(string colonyId, string orderId)
{
LogWriter.WriteMessage($"Downloading order {orderId}");
......@@ -294,7 +289,7 @@ namespace Glitterworld_Prime
return null;
}
public static bool SetSubscriptionData(Map map, GlitterWorldSubscriptionMetadata gsm)
internal static bool SetSubscriptionData(Map map, GlitterWorldSubscriptionMetadata gsm)
{
LogWriter.WriteMessage("Sending Subscription Data");
......@@ -316,7 +311,7 @@ namespace Glitterworld_Prime
return true;
}
public static GlitterWorldIdResponse CreateUserId()
internal static GlitterWorldIdResponse CreateUserId()
{
#if DEBUG
LogWriter.WriteMessage("Getting a User ID from Server");
......@@ -343,19 +338,20 @@ namespace Glitterworld_Prime
return null;
}
public static bool SendColonyMeta(Map map, out int reason)
internal static bool SendColonyMeta(Map map, out int reason)
{
LogWriter.WriteMessage("Sending Colony Metadata");
reason = 0;
var client = CreateRestClient();
var mapComponent = map.GetComponent<GlitterWorld_MapComponent>();
// Send colony metadata.
var cmd = new GlitterWorldColonyMetadata(
Utilities.GetColonyFaction().Name,
Find.World.info.name, Utilities.GetCurrentMapName(map),
Utilities.GetUserType(),
Utilities.GetUserId()
Utilities.GetUserId(),
mapComponent.HasSpawned
);
......@@ -442,8 +438,7 @@ namespace Glitterworld_Prime
request.AddHeader("Accept", "application/json");
}
public static void PutItemListAsync(GlitterWorld_MapComponent mapComponent,
internal static void PutItemListAsync(GlitterWorld_MapComponent mapComponent,
Action<IRestResponse, RestRequestAsyncHandle> callback)
{
LogWriter.WriteMessage("Sending Supported Things Data");
......@@ -458,8 +453,7 @@ namespace Glitterworld_Prime
client.ExecuteAsyncPost(request, callback, "PUT");
}
public static void PutModListAsync(GlitterWorld_MapComponent mapComponent,
internal static void PutModListAsync(GlitterWorld_MapComponent mapComponent,
Action<IRestResponse, RestRequestAsyncHandle> callback)
{
LogWriter.WriteMessage("Sending Mod List Data");
......@@ -475,7 +469,7 @@ namespace Glitterworld_Prime
client.ExecuteAsyncPost(request, callback, "PUT");
}
public static byte[] SerializeAndCompress(ISerializer serializer, object data)
private static byte[] SerializeAndCompress(ISerializer serializer, object data)
{
// Compress the list of mods and send it as a file.
var jsonString = serializer.Serialize(data);
......
......@@ -13,7 +13,7 @@ using System.Collections.Generic;
namespace Glitterworld_Prime.ApiStructs
{
[Serializable]
public class GlitterWorldApiServerMaintenanceWindow
internal class GlitterWorldApiServerMaintenanceWindow
{
#region Properties
......@@ -72,7 +72,7 @@ namespace Glitterworld_Prime.ApiStructs
}
[Serializable]
public class GlitterWorldApiVersionResponse
internal class GlitterWorldApiVersionResponse
{
#region Properties
......@@ -82,17 +82,18 @@ namespace Glitterworld_Prime.ApiStructs
}
[Serializable]
public class GlitterWorldIdResponse
internal class GlitterWorldIdResponse
{
#region Properties
public string Hash { get; set; }
public string ApiCompatible { get;set; }
#endregion
}
[Serializable]
public class GlitterWorldColonyMetadata
internal class GlitterWorldColonyMetadata
{
#region ctor
......@@ -101,13 +102,14 @@ namespace Glitterworld_Prime.ApiStructs
}
public GlitterWorldColonyMetadata(string factionName, string planet, string baseName, string ownerType,
string ownerId)
string ownerId, bool hasSpawned)
{
FactionName = factionName;
Planet = planet;
BaseName = baseName;
OwnerType = ownerType;
OwnerID = ownerId;
HasSpawned = hasSpawned;
}
#endregion
......@@ -124,11 +126,13 @@ namespace Glitterworld_Prime.ApiStructs
public string Hash { get; set; }
public bool HasSpawned { get; set; }
#endregion
}
[Serializable]
public class GlitterWorldSubscriptionMetadata
internal class GlitterWorldSubscriptionMetadata
{
#region ctor
......@@ -154,7 +158,7 @@ namespace Glitterworld_Prime.ApiStructs
}
[Serializable]
public class GlitterWorldPlaceOrderRequest
internal class GlitterWorldPlaceOrderRequest
{
#region Properties
......@@ -168,7 +172,7 @@ namespace Glitterworld_Prime.ApiStructs
}
[Serializable]
public class GlitterWorldPlacedOrders
internal class GlitterWorldPlacedOrders
{
#region Properties
......@@ -178,7 +182,7 @@ namespace Glitterworld_Prime.ApiStructs
}
[Serializable]
public class GlitterWorldOrder
internal class GlitterWorldOrder
{
#region Properties
......@@ -199,7 +203,7 @@ namespace Glitterworld_Prime.ApiStructs
}
[Serializable]
public class GlitterWorldOrderStatus
internal class GlitterWorldOrderStatus
{
#region Properties
......@@ -210,7 +214,7 @@ namespace Glitterworld_Prime.ApiStructs
}
[Serializable]
public class GlitterWorldDeliveryMetaData
internal class GlitterWorldDeliveryMetaData
{
#region Properties
......@@ -231,7 +235,7 @@ namespace Glitterworld_Prime.ApiStructs
}
[Serializable]
public class GlitterWorldSupportedThingList
internal class GlitterWorldSupportedThingList
{
#region ctor
......@@ -256,7 +260,7 @@ namespace Glitterworld_Prime.ApiStructs
/// This class is used for serializing the list of goods to get from the API.
/// </summary>
[Serializable]
public class GlitterWorldRequestItem
internal class GlitterWorldRequestItem
{
#region ctor
......@@ -288,7 +292,7 @@ namespace Glitterworld_Prime.ApiStructs
/// This class is used for serializing the list of mods that this game has.
/// </summary>
[Serializable]
public class GlitterWorldModList
internal class GlitterWorldModList
{
#region ctor
......
......@@ -25,7 +25,7 @@ namespace Glitterworld_Prime
#region ctor
public GlitterWorldDelivery(Map map, GlitterWorldDeliveryMetaData deliveryMetaData)
internal GlitterWorldDelivery(Map map, GlitterWorldDeliveryMetaData deliveryMetaData)
{
_deliveryMetaData = deliveryMetaData;
IsDelivered = false;
......@@ -36,19 +36,19 @@ namespace Glitterworld_Prime
#region Properties
public Map MapOrderWasPlaced { get; set; }
private Map MapOrderWasPlaced { get; set; }
public bool IsDelivered { get; set; }
internal bool IsDelivered { get; private set; }
public List<GlitterWorldOrderItem> ThingsOnOrder => _deliveryMetaData.ThingsBoughtFromGwp;
private List<GlitterWorldOrderItem> ThingsOnOrder => _deliveryMetaData.ThingsBoughtFromGwp;
public List<GlitterWorldOrderItem> ThingsSoldToGwp => _deliveryMetaData.ThingsSoldToGwp;
internal List<GlitterWorldOrderItem> ThingsSoldToGwp => _deliveryMetaData.ThingsSoldToGwp;
public int DeliverOnTick => _deliveryMetaData.DeliveryTick;
private int DeliverOnTick => _deliveryMetaData.DeliveryTick;
public string OrderId => _deliveryMetaData.Hash;
internal string OrderId => _deliveryMetaData.Hash;
public string NewStatus { get; set; }
internal string NewStatus { get; private set; }
#endregion
......
......@@ -7,10 +7,16 @@
#endregion
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Security.Policy;
using Glitterworld_Prime.ApiStructs;
using Harmony;
using RimWorld;
using Verse;
namespace Glitterworld_Prime
......@@ -22,7 +28,7 @@ namespace Glitterworld_Prime
private string _colonyId = "";
private TraderPrime _currentTradeShip;
private bool _initComplete;
private string _hasSpawned = "false";
#endregion
#region ctor
......@@ -36,21 +42,21 @@ namespace Glitterworld_Prime
#region Properties
public string ColonyId
internal string ColonyId
{
get { return _colonyId; }
set { _colonyId = value; }
}
public int SubscriptionExpiry { get; set; }
internal int SubscriptionExpiry { get; set; }
public GlitterWorldSupportedThingList GlitterWorldSupportedThingList { get; private set; }
internal GlitterWorldSupportedThingList GlitterWorldSupportedThingList { get; private set; }
public List<string> ModList { get; private set; }
internal List<string> ModList { get; private set; }
public GlitterWorldOrderTracker OrderTracker { get; private set; }
internal GlitterWorldOrderTracker OrderTracker { get; private set; }
public bool HasSentThingListYet { get; set; }
internal bool HasSentThingListYet { get; set; }
#endregion
......@@ -61,10 +67,11 @@ namespace Glitterworld_Prime
LogWriter.WriteMessage("GlitterWorld Prime saving/loading Colony Metadata");
base.ExposeData();
Scribe_Values.Look(ref _colonyId, "GlitterWorldPrimeColonyID", "", false);
Scribe_Values.Look(ref _hasSpawned, "GlitterWorldPrimeCompatibleApi", "", false);
LogWriter.WriteMessage("GlitterWorld Prime (Save/Load) now using Colony ID: " + _colonyId);
}
public void ResetTradeShip()
internal void ResetTradeShip()