Commit c1512bf1 authored by Adam Leyshon's avatar Adam Leyshon

WIP

parent 46683dae
<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
......@@ -10,6 +10,7 @@ Global
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Release-Local|Any CPU = Release-Local|Any CPU
Debug Local|Any CPU = Debug Local|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
......@@ -18,6 +19,8 @@ Global
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Release|Any CPU.Build.0 = Release|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Release-Local|Any CPU.ActiveCfg = Release-Local|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Release-Local|Any CPU.Build.0 = Release-Local|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Debug Local|Any CPU.ActiveCfg = Debug Local|Any CPU
{1976D016-8918-48C9-A54E-4D9EF7F200B7}.Debug Local|Any CPU.Build.0 = Debug Local|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -36,12 +36,11 @@ namespace Glitterworld_Prime
#region ctor
public DialogPrimeCheckSubscription(Pawn playerNegotiator, ITrader traderPrime)
public DialogPrimeCheckSubscription(Pawn playerNegotiator)
{
forcePause = true;
absorbInputAroundWindow = true;
_player = playerNegotiator;
_trader = traderPrime;
_mapComponent = Utilities.GetMapComponent(_player.Map);
var t = new Thread(DoApiCallsAsync);
......@@ -117,7 +116,7 @@ namespace Glitterworld_Prime
else
{
// Valid subscription.
Find.WindowStack.Add(new DialogPrimeGetData(_player, _trader));
Find.WindowStack.Add(new DialogPrimeGetData(_player));
Close();
}
}
......
......@@ -11,6 +11,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using Glitterworld_Prime.trade_ui;
using RestSharp;
using RimWorld;
using UnityEngine;
......@@ -36,12 +37,11 @@ namespace Glitterworld_Prime
#region ctor
public DialogPrimeGetData(Pawn playerNegotiator, ITrader traderPrime)
public DialogPrimeGetData(Pawn playerNegotiator)
{
forcePause = true;
absorbInputAroundWindow = true;
_player = playerNegotiator;
_trader = traderPrime;
_mapComponent = Utilities.GetMapComponent(_player.Map);
_apiStopwatch = new Stopwatch();
......@@ -136,7 +136,7 @@ namespace Glitterworld_Prime
_mapComponent.HasSentThingListYet = true;
// We're done, close and go to the trade screen.
var dt = new DialogPrimeTrade(_player, _trader);
var dt = new DialogPrimeTradeUI(_player);
Find.WindowStack.Add(dt);
Close();
break;
......
......@@ -86,7 +86,7 @@ namespace Glitterworld_Prime
case DownloadStatus.Complete:
if (!_shouldClose)
{
Find.WindowStack.Add(new DialogPrimeGetData(_player, _trader));
Find.WindowStack.Add(new DialogPrimeGetData(_player));
_shouldClose = true;
Close();
}
......
......@@ -28,7 +28,9 @@ namespace Glitterworld_Prime
private static readonly float ClientVersion = 1.0f;
#if LOCALSERVER
#if DEVSERVER
private static readonly string BaseUrl = "http://127.0.0.1:5000";
#elif LOCALSERVER
private static readonly string BaseUrl = "https://prime-dev.thecodecache.net";
#else
private static readonly string BaseUrl = "https://prime.thecodecache.net";
......@@ -44,6 +46,10 @@ namespace Glitterworld_Prime
{
LogWriter.WriteMessage("Getting API Version");
#if DEBUG
LogWriter.WriteMessage($"API lives at {BaseUrl}");
#endif
var client = CreateRestClient();
var request = new RestRequest($"/v4/{MarketUrl}/application/version", Method.GET);
......
......@@ -47,6 +47,15 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Optimize>true</Optimize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug Local|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>TRACE;DEBUG;DEVSERVER</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<OutputPath>..\Assemblies\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>.\0Harmony.dll</HintPath>
......@@ -62,8 +71,8 @@
<Reference Include="MiniSentrySDK, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\MiniSentrySDK\MiniSentrySDK\bin\Debug\MiniSentrySDK.dll</HintPath>
</Reference>
<Reference Include="RestSharp">
<HintPath>F:\Code\C#\RestSharp\RestSharp\bin\Debug\RestSharp.dll</HintPath>
<Reference Include="RestSharp, Version=105.2.4.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
......@@ -93,17 +102,17 @@
<Compile Include="LogWriter.cs" />
<Compile Include="ObjectDumper.cs" />
<Compile Include="Patches\Translation.cs" />
<Compile Include="SSL\SetupSSL.cs" />
<Compile Include="Tools\DumpThingData.cs" />
<Compile Include="TraderPrime.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TraderKindDef_PrimeTrader.cs" />
<Compile Include="DialogPrimeGetData.cs" />
<Compile Include="Building_PrimeUplink.cs" />
<Compile Include="TradeUtilities.cs" />
<Compile Include="trade_ui\TradeDialog.cs" />
<Compile Include="Utilities.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="..\build.cake">
<Link>build.cake</Link>
......@@ -117,6 +126,7 @@
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
......
#region License
// This file was created by TwistedSoul @ TheCodeCache.net
// You are free to inspect the mod but may not modify or redistribute without my express permission.
// However! If you would like to contribute to GWP please feel free to drop me a message.
//
// Glitterworld Prime, SetupSSL.cs, Created 2019-07-23
#endregion
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Security.Cryptography.X509Certificates;
namespace Glitterworld_Prime.SSL
{
public static class SetupSSL
{
public static void InitSsl()
{
ServicePointManager.ServerCertificateValidationCallback =
(s, certificate, chain, sslPolicyErrors) =>
{
var hashes = new List<string>
{
"b132490b77a86c2948d0bc7e17c75f45fd288e64",
"b1b71f0cb13452537f02e9065b42c8cf209dd43d",
"e6a3b45b062d509b3382282d196efe97d5956ccb",
"dac9024f54d8f6df94935fb1732638ca6ad77c13"
};
if (chain.ChainElements.Count != 3) return false;
foreach (var chainElement in chain.ChainElements)
{
LogWriter.WriteMessage($"Verifying element: {chainElement.Certificate.Subject}");
LogWriter.WriteMessage($"Thumb: {chainElement.Certificate.Thumbprint}");
var hash = chainElement.Certificate.Thumbprint?.ToLower();
if (!hashes.Contains(hash))
{
return false;
}
hashes.Remove(hash);
}
return hashes.Count == 1;
};
}
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -22,6 +22,7 @@ namespace Glitterworld_Prime
private readonly ThingOwner _things;
private readonly TraderKindDefPrimeTrader _traderKind;
private List<Thing> _goods;
private IEnumerable<Thing> _goods1;
#endregion
......@@ -65,7 +66,7 @@ namespace Glitterworld_Prime
public void TryOpenComms(Pawn negotiator)
{
Find.WindowStack.Add(new DialogPrimeCheckSubscription(negotiator, this));
Find.WindowStack.Add(new DialogPrimeCheckSubscription(negotiator));
}
public Faction GetFaction()
......@@ -102,7 +103,10 @@ namespace Glitterworld_Prime
public Faction Faction => Faction.OfAncients;
public IEnumerable<Thing> Goods => _goods;
public IEnumerable<Thing> Goods
{
get { throw new NotImplementedException(); }
}
public int RandomPriceFactorSeed => 0;
......@@ -260,75 +264,12 @@ namespace Glitterworld_Prime
public void AddGoodsFromServer(List<GlitterWorldItem> items)
{
var serverThings = new List<Thing>();
LogWriter.WriteMessage($"Begin parsing goods list. Got {items.Count} items from server.");
// Add Silver
var thing = Utilities.CreateThing("Silver", 1000000);
serverThings.Add(thing);
ServerSideItemData = items;
// Fix errors when there are items but have no quantity in stock.
// Items with zero stock are downloaded because we need the price data.
foreach (var item in items.Where(item => item.Quantity > 0))
try
{
// Create the Thing
thing = Utilities.CreateThing(item.Name, item.Quantity, item.StuffType);
if (thing.def.defName == "Silver") continue;
// Add support for Quality
if (!item.Quality.NullOrEmpty())
if (thing.def.HasComp(typeof(CompQuality)))
{
// Fix some strange errors with the games tale generation by forcing these items not to have any art assigned.
var art = thing.TryGetComp<CompArt>();
if (art != null) ((ThingWithComps) thing).AllComps.Remove(art);
thing.TryGetComp<CompQuality>()
.SetQuality((QualityCategory) Enum.Parse(typeof(QualityCategory), item.Quality),
ArtGenerationContext.Outsider);
}
// Make sure the item has a price.
if (item.CurrentBuyPrice < 0)
{
item.CurrentBuyPrice = thing.MarketValue;
item.CurrentSellPrice = thing.MarketValue;
}
// Make sure changing its "stuff" doesn't reduce its hitpoints.
thing.HitPoints = thing.MaxHitPoints;
// Add support for minified objects.
if (item.MinifiedContainer)
{
var rememberStackSize = thing.stackCount;
thing.stackCount = 1;
thing = thing.MakeMinified();
thing.stackCount = rememberStackSize;
}
serverThings.Add(thing);
}
catch (Exception ex)
{
LogWriter.WriteErrorMessage($"Error parsing item {item.Name}, {ex.Message}");
LogWriter.DumpObjectToLog(ex);
if (ex.InnerException != null) LogWriter.DumpObjectToLog(ex.InnerException);
}
LogWriter.WriteMessage($"Finished parsing goods list. Parsed {serverThings.Count} items from server.");
_goods = serverThings;
}
public void Cleanup()
{
if (_goods.Count <= 0) return;
foreach (var t in _goods) t.Destroy();
ServerSideItemData = null;
}
#endregion
......
......@@ -14,6 +14,7 @@ using System.Linq;
using System.Net;
using System.Reflection;
using Glitterworld_Prime.ApiStructs;
using Glitterworld_Prime.SSL;
using Harmony;
using RimWorld;
using Steamworks;
......@@ -47,7 +48,7 @@ namespace Glitterworld_Prime
internal static void CaptureError(Exception exception)
{
LogWriter.WriteMessage("Not forcing stacktrace");
var e = new SentryEvent(exception);
// Get User ID / Type
......@@ -501,11 +502,10 @@ namespace Glitterworld_Prime
internal static void SetupSsl()
{
// Add workaround to make SSL work in this version of Mono.
ServicePointManager.ServerCertificateValidationCallback =
(s, certificate, chain, sslPolicyErrors) =>
certificate.Issuer == SSLIssuer &&
certificate.Subject == SSLSubject;
#if DEBUG
LogWriter.WriteMessage("Setting up SSL Validation");
#endif
SetupSSL.InitSsl();
}
#endregion
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="RestSharp" version="105.2.3" targetFramework="net35" />
</packages>
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment